mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
442ae638de
This reverts commit 44a7e598f2fdbd91d18cc340de477ca3d33a1338.
45 lines
1.3 KiB
CoffeeScript
45 lines
1.3 KiB
CoffeeScript
define [
|
|
"base"
|
|
"ide/editor/Document"
|
|
], (App, Document) ->
|
|
App.controller "SavingNotificationController", ["$scope", "$interval", "ide", ($scope, $interval, ide) ->
|
|
setInterval () ->
|
|
pollSavedStatus()
|
|
, 1000
|
|
|
|
$(window).bind 'beforeunload', () =>
|
|
warnAboutUnsavedChanges()
|
|
|
|
$scope.docSavingStatus = {}
|
|
pollSavedStatus = () ->
|
|
oldStatus = $scope.docSavingStatus
|
|
oldUnsavedCount = $scope.docSavingStatusCount
|
|
newStatus = {}
|
|
newUnsavedCount = 0
|
|
|
|
for doc_id, doc of Document.openDocs
|
|
saving = doc.pollSavedStatus()
|
|
if !saving
|
|
newUnsavedCount++
|
|
if oldStatus[doc_id]?
|
|
newStatus[doc_id] = oldStatus[doc_id]
|
|
newStatus[doc_id].unsavedSeconds += 1
|
|
else
|
|
newStatus[doc_id] = {
|
|
unsavedSeconds: 0
|
|
doc: ide.fileTreeManager.findEntityById(doc_id)
|
|
}
|
|
|
|
# for performance, only update the display if the old or new
|
|
# counts of unsaved files are nonzeror. If both old and new
|
|
# unsaved counts are zero then we know we are in a good state
|
|
# and don't need to do anything to the UI.
|
|
if newUnsavedCount or oldUnsavedCount
|
|
$scope.docSavingStatus = newStatus
|
|
$scope.docSavingStatusCount = newUnsavedCount
|
|
$scope.$apply()
|
|
|
|
warnAboutUnsavedChanges = () ->
|
|
if Document.hasUnsavedChanges()
|
|
return "You have unsaved changes. If you leave now they will not be saved."
|
|
]
|