2014-07-08 07:02:26 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
"ide/editor/Document"
|
|
|
|
], (App, Document) ->
|
|
|
|
App.controller "SavingNotificationController", ["$scope", "$interval", "ide", ($scope, $interval, ide) ->
|
2015-01-22 12:00:56 -05:00
|
|
|
setInterval () ->
|
2014-07-08 07:02:26 -04:00
|
|
|
pollSavedStatus()
|
|
|
|
, 1000
|
|
|
|
|
|
|
|
$(window).bind 'beforeunload', () =>
|
|
|
|
warnAboutUnsavedChanges()
|
|
|
|
|
|
|
|
$scope.docSavingStatus = {}
|
|
|
|
pollSavedStatus = () ->
|
|
|
|
oldStatus = $scope.docSavingStatus
|
2015-01-22 12:00:56 -05:00
|
|
|
newStatus = {}
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
for doc_id, doc of Document.openDocs
|
|
|
|
saving = doc.pollSavedStatus()
|
|
|
|
if !saving
|
|
|
|
if oldStatus[doc_id]?
|
2015-01-22 12:00:56 -05:00
|
|
|
newStatus[doc_id] = oldStatus[doc_id]
|
|
|
|
newStatus[doc_id].unsavedSeconds += 1
|
2014-07-08 07:02:26 -04:00
|
|
|
else
|
2015-01-22 12:00:56 -05:00
|
|
|
newStatus[doc_id] = {
|
2014-07-08 07:02:26 -04:00
|
|
|
unsavedSeconds: 0
|
|
|
|
doc: ide.fileTreeManager.findEntityById(doc_id)
|
|
|
|
}
|
|
|
|
|
2015-01-22 12:00:56 -05:00
|
|
|
if _.size(newStatus) or _.size(oldStatus)
|
|
|
|
$scope.docSavingStatus = newStatus
|
|
|
|
$scope.$apply()
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
warnAboutUnsavedChanges = () ->
|
|
|
|
if Document.hasUnsavedChanges()
|
|
|
|
return "You have unsaved changes. If you leave now they will not be saved."
|
2015-01-22 12:00:56 -05:00
|
|
|
]
|