Add links to enable docs without reloading the app

pull/165/head
Thibaut 10 years ago
parent e97b8d463d
commit 200dd0b43f

@ -77,11 +77,7 @@
return return
start: -> start: ->
for doc in @docs.all() @initDoc(doc) for doc in @docs.all()
@entries.add doc.toEntry()
@entries.add type.toEntry() for type in doc.types.all()
@entries.add doc.entries.all()
@db = new app.DB() @db = new app.DB()
@trigger 'ready' @trigger 'ready'
@router.start() @router.start()
@ -90,6 +86,25 @@
@removeEvent 'ready bootError' @removeEvent 'ready bootError'
return return
initDoc: (doc) ->
@entries.add doc.toEntry()
@entries.add type.toEntry() for type in doc.types.all()
@entries.add doc.entries.all()
return
enableDoc: (doc, _onSuccess, onError) ->
onSuccess = =>
@disabledDocs.remove(doc)
@docs.add(doc)
@docs.sort()
@initDoc(doc)
@settings.setDocs(doc.slug for doc in @docs.all())
_onSuccess()
return
doc.load onSuccess, onError, writeCache: true
return
welcomeBack: -> welcomeBack: ->
visitCount = @settings.get('count') visitCount = @settings.get('count')
@settings.set 'count', ++visitCount @settings.set 'count', ++visitCount

@ -21,6 +21,10 @@ class app.Collection
@models.push new (@model())(object) @models.push new (@model())(object)
return return
remove: (model) ->
@models.splice @models.indexOf(model), 1
return
size: -> size: ->
@models.length @models.length

@ -4,7 +4,10 @@ templates.sidebarDoc = (doc, options = {}) ->
link = """<a href="#{doc.fullPath()}" class="_list-item _icon-#{doc.slug} """ link = """<a href="#{doc.fullPath()}" class="_list-item _icon-#{doc.slug} """
link += if options.disabled then '_list-disabled' else '_list-dir' link += if options.disabled then '_list-disabled' else '_list-dir'
link += """" data-slug="#{doc.slug}">""" link += """" data-slug="#{doc.slug}">"""
link += """<span class="_list-arrow"></span>""" unless options.disabled if options.disabled
link += """<span class="_list-enable" data-enable="#{doc.slug}">Enable</span>"""
else
link += """<span class="_list-arrow"></span>"""
link += """<span class="_list-count">#{doc.version}</span>""" if doc.version link += """<span class="_list-count">#{doc.version}</span>""" if doc.version
link + "#{doc.name}</a>" link + "#{doc.name}</a>"

@ -123,17 +123,24 @@ class app.views.DocList extends app.View
$.scrollTo @find("a[href='#{model.fullPath()}']"), null, 'top', margin: 0 $.scrollTo @find("a[href='#{model.fullPath()}']"), null, 'top', margin: 0
return return
onClick: (event) => toggleDisabled: ->
return unless @disabledTitle and $.hasChild @disabledTitle, event.target
$.stopEvent(event)
if @disabledTitle.classList.contains('open-title') if @disabledTitle.classList.contains('open-title')
@removeDisabledList() @removeDisabledList()
app.settings.set 'hideDisabled', true app.settings.set 'hideDisabled', true
else else
@appendDisabledList() @appendDisabledList()
app.settings.set 'hideDisabled', false app.settings.set 'hideDisabled', false
return
onClick: (event) =>
if @disabledTitle and $.hasChild(@disabledTitle, event.target)
$.stopEvent(event)
@toggleDisabled()
else if slug = event.target.getAttribute('data-enable')
$.stopEvent(event)
doc = app.disabledDocs.findBy('slug', slug)
app.enableDoc(doc, @render, @render)
return
afterRoute: (route, context) => afterRoute: (route, context) =>
if context.init if context.init

@ -109,11 +109,9 @@
} }
} }
._list-count { ._list-count, ._list-enable {
float: right; float: right;
font-size: .75rem; font-size: .75rem;
color: $textColorLighter;
pointer-events: none;
.focus > &, .focus > &,
.active > & { .active > & {
@ -121,6 +119,22 @@
} }
} }
._list-count {
color: $textColorLighter;
pointer-events: none;
._list-disabled:hover > & { display: none; }
}
._list-enable {
display: none;
color: $linkColor;
cursor: pointer;
&:hover { text-decoration: underline; }
._list-disabled:hover > & { display: block; }
}
// //
// List hierarchy // List hierarchy
// //

Loading…
Cancel
Save