Add links to install/update/uninstall all docs

pull/165/head
Thibaut 10 years ago
parent aee7ab1fa7
commit 95f81055ad

@ -1,5 +1,12 @@
app.templates.offlinePage = (docs) -> """ app.templates.offlinePage = (docs) -> """
<h1 class="_lined-heading">Offline Documentation</h1> <h1 class="_lined-heading">Offline Documentation</h1>
<div class="_docs-tools">
<div class="_docs-links">
<a class="_docs-link" data-action-all="install">Install all</a><a class="_docs-link" data-action-all="update">Update all</a><a class="_docs-link" data-action-all="uninstall">Uninstall all</a>
</div>
</div>
<table class="_docs"> <table class="_docs">
<tr> <tr>
<th>Documentation</th> <th>Documentation</th>
@ -53,7 +60,7 @@ app.templates.offlineDoc = (doc, status) ->
else if outdated else if outdated
""" """
<td>Outdated</td> <td>Outdated</td>
<td><a data-action="install">Update</a> - <a data-action="uninstall">Uninstall</a></td> <td><a data-action="update">Update</a> - <a data-action="uninstall">Uninstall</a></td>
""" """
else else
""" """

@ -18,6 +18,7 @@ class app.views.OfflinePage extends app.View
html = '' html = ''
html += @renderDoc(doc, statuses[doc.slug]) for doc in app.docs.all() html += @renderDoc(doc, statuses[doc.slug]) for doc in app.docs.all()
@html @tmpl('offlinePage', html) @html @tmpl('offlinePage', html)
@refreshLinks()
return return
return return
@ -27,6 +28,11 @@ class app.views.OfflinePage extends app.View
getTitle: -> getTitle: ->
'Offline' 'Offline'
refreshLinks: ->
for action in ['install', 'update', 'uninstall']
@find("a[data-action-all='#{action}']").classList[if @find("a[data-action='#{action}']") then 'add' else 'remove']('_show')
return
docByEl: (el) -> docByEl: (el) ->
el = el.parentNode until slug = el.getAttribute('data-slug') el = el.parentNode until slug = el.getAttribute('data-slug')
app.docs.findBy('slug', slug) app.docs.findBy('slug', slug)
@ -43,14 +49,19 @@ class app.views.OfflinePage extends app.View
if action = target.getAttribute('data-action') if action = target.getAttribute('data-action')
$.stopEvent(event) $.stopEvent(event)
doc = @docByEl(target) doc = @docByEl(target)
action = 'install' if action is 'update'
doc[action](@onInstallSuccess.bind(@, doc), @onInstallError.bind(@, doc)) doc[action](@onInstallSuccess.bind(@, doc), @onInstallError.bind(@, doc))
target.parentNode.innerHTML = "#{target.textContent.replace(/e$/, '')}ing…" target.parentNode.innerHTML = "#{target.textContent.replace(/e$/, '')}ing…"
else if action = target.getAttribute('data-action-all')
$.stopEvent(event)
link.click() for link in @findAll("a[data-action='#{action}']")
return return
onInstallSuccess: (doc) -> onInstallSuccess: (doc) ->
doc.getInstallStatus (status) => doc.getInstallStatus (status) =>
@docEl(doc).outerHTML = @renderDoc(doc, status) @docEl(doc).outerHTML = @renderDoc(doc, status)
$.highlight @docEl(doc), className: '_highlight' $.highlight @docEl(doc), className: '_highlight'
@refreshLinks()
return return
onInstallError: (doc) -> onInstallError: (doc) ->

@ -269,6 +269,24 @@
._docs-size { text-align: right; } ._docs-size { text-align: right; }
._docs-tools { overflow: hidden; }
._docs-links {
float: right;
padding: .375rem .125rem;
@extend %box;
}
._docs-link {
display: none;
vertical-align: top;
padding: 0 .75rem;
cursor: pointer;
&._show { display: inline-block; }
&._show ~ &._show { border-left: 1px solid $boxBorder; }
}
// //
// News // News
// //

Loading…
Cancel
Save