Browse Source

Add links to enable docs without reloading the app

Thibaut 10 years ago
parent
commit
200dd0b43f

+ 20 - 5
assets/javascripts/app/app.coffee

@@ -77,11 +77,7 @@
     return
 
   start: ->
-    for doc in @docs.all()
-      @entries.add doc.toEntry()
-      @entries.add type.toEntry() for type in doc.types.all()
-      @entries.add doc.entries.all()
-
+    @initDoc(doc) for doc in @docs.all()
     @db = new app.DB()
     @trigger 'ready'
     @router.start()
@@ -90,6 +86,25 @@
     @removeEvent 'ready bootError'
     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: ->
     visitCount = @settings.get('count')
     @settings.set 'count', ++visitCount

+ 4 - 0
assets/javascripts/collections/collection.coffee

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

+ 4 - 1
assets/javascripts/templates/sidebar_tmpl.coffee

@@ -4,7 +4,10 @@ templates.sidebarDoc = (doc, options = {}) ->
   link  = """<a href="#{doc.fullPath()}" class="_list-item _icon-#{doc.slug} """
   link += if options.disabled then '_list-disabled' else '_list-dir'
   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 +  "#{doc.name}</a>"
 

+ 11 - 4
assets/javascripts/views/sidebar/doc_list.coffee

@@ -123,17 +123,24 @@ class app.views.DocList extends app.View
     $.scrollTo @find("a[href='#{model.fullPath()}']"), null, 'top', margin: 0
     return
 
-  onClick: (event) =>
-    return unless @disabledTitle and $.hasChild @disabledTitle, event.target
-    $.stopEvent(event)
-
+  toggleDisabled: ->
     if @disabledTitle.classList.contains('open-title')
       @removeDisabledList()
       app.settings.set 'hideDisabled', true
     else
       @appendDisabledList()
       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) =>
     if context.init

+ 17 - 3
assets/stylesheets/components/_sidebar.scss

@@ -109,11 +109,9 @@
   }
 }
 
-._list-count {
+._list-count, ._list-enable {
   float: right;
   font-size: .75rem;
-  color: $textColorLighter;
-  pointer-events: none;
 
   .focus > &,
   .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
 //