overleaf/services/web/public/coffee/settings/DropboxSettingsManager.coffee

56 lines
1.9 KiB
CoffeeScript
Raw Normal View History

2014-02-12 10:23:40 +00:00
define [
"utils/Modal"
"account/AccountManager"
"underscore"
], (Modal, accountManager, _) ->
_.templateSettings = interpolate : /\{\{(.+?)\}\}/g
POLLING_INTERVAL = 15
ONE_MIN_MILI = 1000*60
USER_LINKED_TEMPLATE = _.template($('#userLinkedToDropboxTemplate').html())
class DropboxSettingsManger
constructor: (@ide)->
setup = _.once =>
@tab = $("#dropboxProjectSettings")
tabLink = $('#manageDropboxSettiingsTabLink').on 'click', (event)=>
@tab.empty()
if !@ide.isAllowedToDoIt "owner"
else if !@project.get('features').dropbox
2014-03-25 13:15:59 +00:00
ga('send', 'event', 'subscription-funnel', 'askToUpgrade', "dropbox")
2014-02-12 10:23:40 +00:00
accountManager.askToUpgrade @ide,
2014-03-20 08:18:15 +00:00
onUpgrade: =>
@checkIfUserIsLinkedToDropbox()
2014-03-25 13:15:59 +00:00
ga('send', 'event', 'subscription-funnel', 'upgraded-free-trial', "dropbox")
2014-02-12 10:23:40 +00:00
else
@checkIfUserIsLinkedToDropbox()
@ide.on "afterJoinProject", (project) =>
@project = project
setup()
checkIfUserIsLinkedToDropbox : =>
@ide.socket.emit "getUserDropboxLinkStatus", @project.get("owner").id, (err, status)=>
if status.registered
@buildLinkedView()
else
@buildNonLinkedView()
buildLinkedView: ->
self = @
run = ->
@ide.socket.emit "getLastTimePollHappned", (err, lastTimePollHappened)=>
milisecondsSinceLastPoll = new Date().getTime() - lastTimePollHappened
roundedMinsSinceLastPoll = Math.round(milisecondsSinceLastPoll / ONE_MIN_MILI)
minsTillNextPoll = POLLING_INTERVAL - roundedMinsSinceLastPoll
percentageLeftTillNextPoll = 100 - ((roundedMinsSinceLastPoll / POLLING_INTERVAL) * 100)
html = $(USER_LINKED_TEMPLATE(minsTillNextPoll:minsTillNextPoll, percentageLeftTillNextPoll:percentageLeftTillNextPoll))
self.tab.empty()
self.tab.append html
setTimeout run, ONE_MIN_MILI
run()
buildNonLinkedView: ->
@tab.append $('#userNotLinkedToDropboxTemplate').html()