Simplify code to check form changes
This commit is contained in:
@@ -6,22 +6,21 @@ App.WatchFormChanges =
|
|||||||
if($("[data-watch-form-message]").length)
|
if($("[data-watch-form-message]").length)
|
||||||
return $("[data-watch-form-message]").data("watch-form-message")
|
return $("[data-watch-form-message]").data("watch-form-message")
|
||||||
|
|
||||||
|
hasChanged: ->
|
||||||
|
App.WatchFormChanges.forms().is ->
|
||||||
|
$(this).serialize() != $(this).data("watchChanges")
|
||||||
|
|
||||||
checkChanges: ->
|
checkChanges: ->
|
||||||
changes = false
|
if App.WatchFormChanges.hasChanged()
|
||||||
App.WatchFormChanges.forms().each ->
|
confirm(App.WatchFormChanges.msg())
|
||||||
form = $(this)
|
|
||||||
if form.serialize() != form.data("watchChanges")
|
|
||||||
changes = true
|
|
||||||
if changes
|
|
||||||
return confirm(App.WatchFormChanges.msg())
|
|
||||||
else
|
else
|
||||||
return true
|
true
|
||||||
|
|
||||||
initialize: ->
|
initialize: ->
|
||||||
if App.WatchFormChanges.forms().length == 0 || App.WatchFormChanges.msg() == undefined
|
if App.WatchFormChanges.forms().length == 0 || App.WatchFormChanges.msg() == undefined
|
||||||
return
|
return
|
||||||
|
|
||||||
$(document).off("page:before-change").on("page:before-change", -> App.WatchFormChanges.checkChanges())
|
$(document).off("page:before-change").on("page:before-change", App.WatchFormChanges.checkChanges)
|
||||||
|
|
||||||
App.WatchFormChanges.forms().each ->
|
App.WatchFormChanges.forms().each ->
|
||||||
form = $(this)
|
form = $(this)
|
||||||
|
|||||||
Reference in New Issue
Block a user