You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
devdocs/assets/javascripts/views/layout/settings.coffee

81 lines
1.8 KiB

class app.views.Settings extends app.View
SIDEBAR_HIDDEN_LAYOUT = '_sidebar-hidden'
@el: '._settings'
@elements:
sidebar: '._sidebar'
saveBtn: 'button[type="submit"]'
backBtn: 'button[data-back]'
@events:
change: 'onChange'
submit: 'onSubmit'
click: 'onClick'
@shortcuts:
enter: 'onEnter'
init: ->
@addSubview @docPicker = new app.views.DocPicker
return
activate: ->
if super
@render()
document.body.classList.remove(SIDEBAR_HIDDEN_LAYOUT)
app.appCache?.on 'progress', @onAppCacheProgress
return
deactivate: ->
if super
@resetClass()
@docPicker.detach()
document.body.classList.add(SIDEBAR_HIDDEN_LAYOUT) if app.settings.hasLayout(SIDEBAR_HIDDEN_LAYOUT)
app.appCache?.off 'progress', @onAppCacheProgress
return
render: ->
@docPicker.appendTo @sidebar
@refreshElements()
@addClass '_in'
return
save: ->
unless @saving
@saving = true
docs = @docPicker.getSelectedDocs()
app.settings.setDocs(docs)
@saveBtn.textContent = if app.appCache then 'Downloading\u2026' else 'Saving\u2026'
disabledDocs = new app.collections.Docs(doc for doc in app.docs.all() when docs.indexOf(doc.slug) is -1)
disabledDocs.uninstall ->
app.db.migrate()
app.reload()
return
onChange: =>
@addClass('_dirty')
return
onEnter: =>
@save()
return
onSubmit: (event) =>
event.preventDefault()
@save()
return
onClick: (event) =>
return if event.which isnt 1
if event.target is @backBtn
$.stopEvent(event)
app.router.show '/'
return
onAppCacheProgress: (event) =>
if event.lengthComputable
percentage = Math.round event.loaded * 100 / event.total
@saveBtn.textContent = "Downloading\u2026 (#{percentage}%)"
return