Files
nairobi/app/assets/javascripts/watch_form_changes.js.coffee
Javi Martín cc7e0d586b Reduce local variables usage in CoffeeScript
Local variables are one of the things CoffeeScript doesn't compile to
modern JavaScript automatically: it uses `var` instead of `const` or
`let`.

Besides, using `$this = $(this)` is usually done to reference the
current object in another function where the current object is a
different one. Here we were using it with no clear purpose.
2019-09-11 03:14:17 +02:00

28 lines
731 B
CoffeeScript

"use strict"
App.WatchFormChanges =
forms: ->
return $("form[data-watch-changes]")
msg: ->
return $("[data-watch-form-message]").data("watch-form-message")
hasChanged: ->
App.WatchFormChanges.forms().is ->
$(this).serialize() != $(this).data("watchChanges")
checkChanges: ->
if App.WatchFormChanges.hasChanged()
confirm(App.WatchFormChanges.msg())
else
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 ->
$(this).data("watchChanges", $(this).serialize())