overleaf/services/web/public/coffee/history/HistoryManager.coffee

66 lines
1.8 KiB
CoffeeScript
Raw Normal View History

2014-02-12 10:23:40 +00:00
define [
"history/VersionListView"
"history/VersionList"
"history/HistoryView"
"account/AccountManager"
"libs/backbone"
], (VersionListView, VersionList, HistoryView, AccountManager) ->
HistoryManager = class
templates:
historyPanel: $("#historyPanelTemplate").html()
constructor: (ide, options) ->
@ide = ide
@ide.on "afterJoinProject", (project) =>
if !@inited
@inited = true
@project = project
@historyPanel = $(@templates.historyPanel)
@ide.tabManager.addTab
id: "history"
name: "History"
content: @historyPanel
after: "code"
onShown: () => @showHistoryArea()
lock: true
@view = new HistoryView
el : @historyPanel
manager : this
@view.render()
@versionList = new VersionList
@versionListView = new VersionListView(
collection : @versionList,
el : @view.$("#versionListArea")
)
showHistoryArea: ->
if @project.get("features").versioning
@view.setHistoryAreaToDisplayHistory()
@versionList.fetchNewVersions()
@versionListView.loadUntilFull()
else
@view.setHistoryAreaToDisplayEnableVersioning()
enableVersioning: ->
ga('send', 'event', 'subscription-funnel', 'askToUpgrade', "history")
2014-02-12 10:23:40 +00:00
AccountManager.askToUpgrade @ide,
onUpgrade: () =>
ga('send', 'event', 'subscription-funnel', 'upgraded-free-trial', "history")
2014-02-12 10:23:40 +00:00
@showHistoryArea()
takeSnapshot: (message, callback = (error) ->) ->
$.ajax
type : "POST"
url : "/project/#{@project.id}/snapshot"
data :
message: message
_csrf: csrfToken
dataType: "json"
success : (data, status, xhr) =>
@versionList.fetchNewVersions()
callback()
error : (data, status, xhr) =>
callback(new Error("takeSnapshot returned with error: #{status}"))
return HistoryManager