We have a custom implementation to avoid doble submissions which causes some custom problems 😌 This commit should fix the following three specs spec/features/comments/legislation_annotations_spec.rb:367 spec/features/comments/legislation_questions_spec.rb:333 spec/features/custom/probe_option_comments_spec.rb:298 One of the custom problems comes from ajax:success[1] not being triggered, instead only ajax:complete seems to be triggered We should remove this custom implementation and use the standard solution provided in rails[2] [1] https://github.com/AyuntamientoMadrid/consul/blob/master/app/assets/java scripts/prevent_double_submission.js.coffee#L28 [2] https://stackoverflow.com/questions/9570912/how-to-disable-a-form-submit -button-a-l%C3%A0-ruby-on-rails-way/9572893#9572893
39 lines
1.2 KiB
CoffeeScript
39 lines
1.2 KiB
CoffeeScript
App.PreventDoubleSubmission =
|
|
disable_buttons: (buttons) ->
|
|
setTimeout ->
|
|
buttons.each ->
|
|
button = $(this)
|
|
unless button.hasClass('disabled')
|
|
loading = button.data('loading') ? '...'
|
|
button.addClass('disabled').attr('disabled', 'disabled')
|
|
button.data('text', button.val())
|
|
button.val(loading)
|
|
, 1
|
|
|
|
reset_buttons: (buttons) ->
|
|
buttons.each ->
|
|
button = $(this)
|
|
if button.hasClass('disabled')
|
|
button_text = button.data('text')
|
|
button.removeClass('disabled').attr('disabled', null)
|
|
if button_text
|
|
button.val(button_text)
|
|
button.data('text', null)
|
|
|
|
initialize: ->
|
|
$('form').on('submit', (event) ->
|
|
unless event.target.id == "new_officing_voter" ||
|
|
event.target.id == "admin_download_emails"
|
|
|
|
buttons = $(this).find(':button, :submit')
|
|
App.PreventDoubleSubmission.disable_buttons(buttons)
|
|
).on('ajax:success', (event) ->
|
|
unless event.target.id == "new_officing_voter" ||
|
|
event.target.id == "admin_download_emails"
|
|
|
|
buttons = $(this).find(':button, :submit')
|
|
App.PreventDoubleSubmission.reset_buttons(buttons)
|
|
)
|
|
|
|
false
|