Moved to app confirm dialog.

This commit is contained in:
Martin Edenhofer 2016-08-21 00:27:39 +02:00
parent 7d052439bb
commit b3b060e561
5 changed files with 58 additions and 16 deletions

View file

@ -684,7 +684,7 @@ class App.ControllerModal extends App.Controller
'submit form': 'submit' 'submit form': 'submit'
'click .js-submit:not(.is-disabled)': 'submit' 'click .js-submit:not(.is-disabled)': 'submit'
'click .js-cancel': 'cancel' 'click .js-cancel': 'cancel'
'click .js-close': 'close' 'click .js-close': 'cancel'
className: 'modal fade' className: 'modal fade'
@ -765,6 +765,7 @@ class App.ControllerModal extends App.Controller
'hidden.bs.modal': => 'hidden.bs.modal': =>
@onClosed() @onClosed()
$('.modal').remove() $('.modal').remove()
'dismiss.bs.modal': @onCancel
if @closeOnAnyClick if @closeOnAnyClick
@el.on('click', => @el.on('click', =>

View file

@ -291,6 +291,22 @@ class App.ControllerGenericDestroyConfirm extends App.ControllerModal
@close() @close()
) )
class App.ControllerConfirm extends App.ControllerModal
buttonClose: true
buttonCancel: true
buttonSubmit: 'yes'
buttonClass: 'btn--danger'
head: 'Confirm'
small: true
content: ->
App.i18n.translateContent(@message)
onSubmit: =>
@close()
if @callback
@callback()
class App.ControllerDrox extends App.Controller class App.ControllerDrox extends App.Controller
constructor: (params) -> constructor: (params) ->
super super

View file

@ -36,9 +36,7 @@ class Index extends App.ControllerContent
setMode: (e) => setMode: (e) =>
value = @modeSetting.prop('checked') value = @modeSetting.prop('checked')
if value && !confirm('Sure?') callback = ->
@modeSetting.prop('checked', false)
return value
App.Setting.set('maintenance_mode', value) App.Setting.set('maintenance_mode', value)
App.WebSocket.send( App.WebSocket.send(
event:'maintenance' event:'maintenance'
@ -46,6 +44,16 @@ class Index extends App.ControllerContent
type: 'mode' type: 'mode'
on: value on: value
) )
if value
new App.ControllerConfirm(
message: 'Sure?'
callback: callback
onCancel: =>
@modeSetting.prop('checked', false)
container: @el.closest('.content')
)
return value
callback()
setLogin: (e) => setLogin: (e) =>
value = @loginSetting.prop('checked') value = @loginSetting.prop('checked')

View file

@ -149,6 +149,10 @@
if (this.isShown && this.options.keyboard) { if (this.isShown && this.options.keyboard) {
$(window).on('keydown.dismiss.bs.modal', $.proxy(function (e) { $(window).on('keydown.dismiss.bs.modal', $.proxy(function (e) {
e.which == 27 && this.hide() e.which == 27 && this.hide()
// 2016-08-21: added event to capture esc for cancel
e = $.Event('dismiss.bs.modal')
this.$element.trigger(e)
// -
}, this)) }, this))
} else if (!this.isShown) { } else if (!this.isShown) {
$(window).off('keydown.dismiss.bs.modal') $(window).off('keydown.dismiss.bs.modal')

View file

@ -272,9 +272,15 @@ class MaintenanceTest < TestCase
) )
# check warning # check warning
alert = browser1.switch_to.alert watch_for(
#alert.dismiss() browser: browser1,
alert.accept() css: '#content .modal .modal-header',
value: 'confirm',
)
click(
browser: browser1,
css: '#content .modal .js-submit',
)
watch_for( watch_for(
browser: browser2, browser: browser2,
@ -352,10 +358,17 @@ class MaintenanceTest < TestCase
type: 'on', type: 'on',
no_check: true, no_check: true,
) )
# check warning # check warning
alert = browser1.switch_to.alert watch_for(
#alert.dismiss() browser: browser1,
alert.accept() css: '#content .modal .modal-header',
value: 'confirm',
)
click(
browser: browser1,
css: '#content .modal .js-submit',
)
watch_for( watch_for(
browser: browser2, browser: browser2,