2014-04-07 07:55:57 -04:00
|
|
|
define [
|
|
|
|
], () ->
|
|
|
|
class SavingAreaManager
|
|
|
|
$el: $('#saving-area')
|
|
|
|
|
|
|
|
constructor: (@ide) ->
|
|
|
|
@unsavedSeconds = 0
|
|
|
|
setInterval () =>
|
|
|
|
@pollSavedStatus()
|
|
|
|
, 1000
|
|
|
|
|
|
|
|
$(window).bind 'beforeunload', () =>
|
|
|
|
@warnAboutUnsavedChanges()
|
|
|
|
|
|
|
|
pollSavedStatus: () ->
|
2014-04-08 05:51:22 -04:00
|
|
|
doc = @ide.editor.document
|
|
|
|
return if !doc?
|
|
|
|
saved = doc.pollSavedStatus()
|
2014-04-07 07:55:57 -04:00
|
|
|
if saved
|
|
|
|
@unsavedSeconds = 0
|
|
|
|
else
|
|
|
|
@unsavedSeconds += 1
|
|
|
|
|
|
|
|
if @unsavedSeconds >= 4
|
|
|
|
$("#savingProblems").text("Saving... (#{@unsavedSeconds} seconds of unsaved changes)")
|
|
|
|
$("#savingProblems").show()
|
|
|
|
else
|
|
|
|
$("#savingProblems").hide()
|
|
|
|
|
|
|
|
warnAboutUnsavedChanges: () ->
|
|
|
|
if @ide.editor.hasUnsavedChanges()
|
|
|
|
return "You have unsaved changes. If you leave now they will not be saved."
|