History

Add links to enable docs without reloading the app

Thibaut committed 11 years ago

Commit 200dd0b1 parent e97b8d45 files · +56 −13Browse files

Showing the changes to assets/javascripts (4 of 5 files). Show all

Unified · Split

4 files
  1. assets/javascripts/app/app.coffee +20 −5
  2. assets/javascripts/collections/collection.coffee +4 −0
  3. assets/javascripts/templates/sidebar_tmpl.coffee +4 −1
  4. assets/javascripts/views/sidebar/doc_list.coffee +11 −4
assets/javascripts/app/app.coffee+20−5
@@ -77,11 +77,7 @@ · 76 unmodified lines
77 return77 return
78 78
79 start: ->79 start: ->
80 for doc in @docs.all()80 @initDoc(doc) for doc in @docs.all()
81 @entries.add doc.toEntry()
82 @entries.add type.toEntry() for type in doc.types.all()
83 @entries.add doc.entries.all()
84
85 @db = new app.DB()81 @db = new app.DB()
86 @trigger 'ready'82 @trigger 'ready'
87 @router.start()83 @router.start()
@@ -90,6 +86,25 @@ · 2 unmodified lines
90 @removeEvent 'ready bootError'86 @removeEvent 'ready bootError'
91 return87 return
92 88
89 initDoc: (doc) ->
90 @entries.add doc.toEntry()
91 @entries.add type.toEntry() for type in doc.types.all()
92 @entries.add doc.entries.all()
93 return
94
95 enableDoc: (doc, _onSuccess, onError) ->
96 onSuccess = =>
97 @disabledDocs.remove(doc)
98 @docs.add(doc)
99 @docs.sort()
100 @initDoc(doc)
101 @settings.setDocs(doc.slug for doc in @docs.all())
102 _onSuccess()
103 return
104
105 doc.load onSuccess, onError, writeCache: true
106 return
107
93 welcomeBack: ->108 welcomeBack: ->
94 visitCount = @settings.get('count')109 visitCount = @settings.get('count')
95 @settings.set 'count', ++visitCount110 @settings.set 'count', ++visitCount
assets/javascripts/collections/collection.coffee+4−0
@@ -21,6 +21,10 @@ class app.Collection · 20 unmodified lines
21 @models.push new (@model())(object)21 @models.push new (@model())(object)
22 return22 return
23 23
24 remove: (model) ->
25 @models.splice @models.indexOf(model), 1
26 return
27
24 size: ->28 size: ->
25 @models.length29 @models.length
26 30
assets/javascripts/templates/sidebar_tmpl.coffee+4−1
@@ -4,7 +4,10 @@ templates.sidebarDoc = (doc, options = {}) -> · 3 unmodified lines
4 link = """<a href="#{doc.fullPath()}" class="_list-item _icon-#{doc.slug} """4 link = """<a href="#{doc.fullPath()}" class="_list-item _icon-#{doc.slug} """
5 link += if options.disabled then '_list-disabled' else '_list-dir'5 link += if options.disabled then '_list-disabled' else '_list-dir'
6 link += """" data-slug="#{doc.slug}">"""6 link += """" data-slug="#{doc.slug}">"""
7 link += """<span class="_list-arrow"></span>""" unless options.disabled7 if options.disabled
8 link += """<span class="_list-enable" data-enable="#{doc.slug}">Enable</span>"""
9 else
10 link += """<span class="_list-arrow"></span>"""
8 link += """<span class="_list-count">#{doc.version}</span>""" if doc.version11 link += """<span class="_list-count">#{doc.version}</span>""" if doc.version
9 link + "#{doc.name}</a>"12 link + "#{doc.name}</a>"
10 13
assets/javascripts/views/sidebar/doc_list.coffee+11−4
@@ -123,17 +123,24 @@ class app.views.DocList extends app.View · 122 unmodified lines
123 $.scrollTo @find("a[href='#{model.fullPath()}']"), null, 'top', margin: 0123 $.scrollTo @find("a[href='#{model.fullPath()}']"), null, 'top', margin: 0
124 return124 return
125 125
126 onClick: (event) =>126 toggleDisabled: ->
127 return unless @disabledTitle and $.hasChild @disabledTitle, event.target
128 $.stopEvent(event)
129
130 if @disabledTitle.classList.contains('open-title')127 if @disabledTitle.classList.contains('open-title')
131 @removeDisabledList()128 @removeDisabledList()
132 app.settings.set 'hideDisabled', true129 app.settings.set 'hideDisabled', true
133 else130 else
134 @appendDisabledList()131 @appendDisabledList()
135 app.settings.set 'hideDisabled', false132 app.settings.set 'hideDisabled', false
133 return
136 134
135 onClick: (event) =>
136 if @disabledTitle and $.hasChild(@disabledTitle, event.target)
137 $.stopEvent(event)
138 @toggleDisabled()
139 else if slug = event.target.getAttribute('data-enable')
140 $.stopEvent(event)
141 doc = app.disabledDocs.findBy('slug', slug)
142 app.enableDoc(doc, @render, @render)
143 return
137 144
138 afterRoute: (route, context) =>145 afterRoute: (route, context) =>
139 if context.init146 if context.init