Files
nairobi/app/assets/javascripts/watch_form_changes.js.coffee
Javi Martín b27855c1cf Use double quotes in CoffeeScript files
As we do in the rest of the application.

Note we cannot add a rule enforcing double quotes because CoffeeScript
Lint does not have such rule.
2019-03-06 11:41:21 +01:00

31 lines
842 B
CoffeeScript

App.WatchFormChanges =
forms: ->
return $("form[data-watch-changes]")
msg: ->
if($("[data-watch-form-message]").length)
return $("[data-watch-form-message]").data("watch-form-message")
checkChanges: (event) ->
changes = false
App.WatchFormChanges.forms().each ->
form = $(this)
if form.serialize() != form.data("watchChanges")
changes = true
if changes
return confirm(App.WatchFormChanges.msg())
else
return true
initialize: ->
if App.WatchFormChanges.forms().length == 0 || App.WatchFormChanges.msg() == undefined
return
$(document).off("page:before-change").on("page:before-change", (e) -> App.WatchFormChanges.checkChanges(e))
App.WatchFormChanges.forms().each ->
form = $(this)
form.data("watchChanges", form.serialize())
false