Files
grecia/app/assets/javascripts/watch_form_changes.js.coffee
Javi Martín 457ec11e6d Remove unnecessary return false statements
The `initialize` functions don't need to return anything, since their
returned value is never used.

Returning false is a common practice in jQuery to stop an event, but in
plain JavaScript methods it doesn't have any side effects.
2019-09-11 01:56:27 +02:00

29 lines
818 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: ->
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", -> App.WatchFormChanges.checkChanges())
App.WatchFormChanges.forms().each ->
form = $(this)
form.data("watchChanges", form.serialize())