|
|
@@ -4,32 +4,26 @@ class app.views.OfflinePage extends app.View
|
|
|
@events:
|
|
|
click: 'onClick'
|
|
|
|
|
|
- @elements:
|
|
|
- list: '_._docs'
|
|
|
-
|
|
|
deactivate: ->
|
|
|
if super
|
|
|
@empty()
|
|
|
return
|
|
|
|
|
|
render: ->
|
|
|
- @html @tmpl('offlinePage')
|
|
|
- @refreshElements()
|
|
|
- app.docs.each(@renderDoc)
|
|
|
+ app.docs.getDownloadStatuses (statuses) =>
|
|
|
+ html = ''
|
|
|
+ html += @renderDoc(doc, statuses[doc.slug]) for doc in app.docs.all()
|
|
|
+ @html @tmpl('offlinePage', html)
|
|
|
+ return
|
|
|
return
|
|
|
|
|
|
- renderDoc: (doc) =>
|
|
|
- doc.getDownloadStatus (status) =>
|
|
|
- html = app.templates.render('offlineDocContent', doc, status)
|
|
|
- el = @docEl(doc)
|
|
|
- el.className = ''
|
|
|
- el.innerHTML = html
|
|
|
- return
|
|
|
+ renderDoc: (doc, status) ->
|
|
|
+ app.templates.render('offlineDoc', doc, status)
|
|
|
|
|
|
getTitle: ->
|
|
|
'Offline'
|
|
|
|
|
|
- getDoc: (el) ->
|
|
|
+ docByEl: (el) ->
|
|
|
el = el.parentNode until slug = el.getAttribute('data-slug')
|
|
|
app.docs.findBy('slug', slug)
|
|
|
|
|
|
@@ -48,16 +42,18 @@ class app.views.OfflinePage extends app.View
|
|
|
|
|
|
if action
|
|
|
$.stopEvent(event)
|
|
|
- doc = @getDoc(event.target)
|
|
|
+ doc = @docByEl(event.target)
|
|
|
doc[action](@onDownloadSuccess.bind(@, doc), @onDownloadError.bind(@, doc))
|
|
|
@docEl(doc).classList.add("#{action}ing")
|
|
|
return
|
|
|
|
|
|
onDownloadSuccess: (doc) ->
|
|
|
- @renderDoc(doc)
|
|
|
+ doc.getDownloadStatus (status) =>
|
|
|
+ @docEl(doc).outerHTML = @renderDoc(doc, status)
|
|
|
return
|
|
|
|
|
|
onDownloadError: (doc) ->
|
|
|
el = @docEl(doc)
|
|
|
el.className = ''
|
|
|
el.classList.add('error')
|
|
|
+ return
|