提交 e9aa7ecd 编写于 作者: M Mathieu

Extract the confirm call in its own, overridable method in rails_ujs

上级 8d93107b
* Extract the `confirm` call in its own, overridable method in `rails_ujs`.
Example :
Rails.confirm = function(message, element) {
return (my_bootstrap_modal_confirm(message));
}
*Mathieu Mahé*
* Enable select tag helper to mark `prompt` option as `selected` and/or `disabled` for `required`
field. Example:
......
......@@ -5,6 +5,10 @@
Rails.handleConfirm = (e) ->
stopEverything(e) unless allowAction(this)
# Default confirm dialog, may be overridden with custom confirm dialog in Rails.confirm
Rails.confirm = (message, element) ->
confirm(message)
# For 'data-confirm' attribute:
# - Fires `confirm` event
# - Shows the confirmation dialog
......@@ -20,7 +24,7 @@ allowAction = (element) ->
answer = false
if fire(element, 'confirm')
try answer = confirm(message)
try answer = Rails.confirm(message, element)
callback = fire(element, 'confirm:complete', [answer])
answer and callback
......@@ -314,3 +314,29 @@ asyncTest('clicking on the children of a disabled button should not trigger a co
start()
}, 50)
})
asyncTest('clicking on a link with data-confirm attribute with custom confirm handler. Confirm yes.', 7, function() {
var message, element
// redefine confirm function so we can make sure it's not called
window.confirm = function(msg) {
ok(false, 'confirm dialog should not be called')
}
// custom auto-confirm:
Rails.confirm = function(msg, elem) { message = msg; element = elem; return true }
$('a[data-confirm]')
.bindNative('confirm:complete', function(e, data) {
App.assertCallbackInvoked('confirm:complete')
ok(data == true, 'confirm:complete passes in confirm answer (true)')
})
.bindNative('ajax:success', function(e, data, status, xhr) {
App.assertCallbackInvoked('ajax:success')
App.assertRequestPath(data, '/echo')
App.assertGetRequest(data)
equal(message, 'Are you absolutely sure?')
equal(element, $('a[data-confirm]').get(0))
start()
})
.triggerNative('click')
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册