Updates GraphListView to load GraphList itself, rather than rely on main.
authorDavid Schoonover <dsc@wikimedia.org>
Mon, 16 Jul 2012 19:58:59 +0000 (12:58 -0700)
committerDavid Schoonover <dsc@wikimedia.org>
Mon, 16 Jul 2012 19:58:59 +0000 (12:58 -0700)
src/base/base-model.co
src/graph/graph-list-view.co
src/graph/graph-model.co
src/main-graph-list.co

index 383fc66..68ed48d 100644 (file)
@@ -227,6 +227,25 @@ BaseList = exports.BaseList = Backbone.Collection.extend mixinBase do # {{{
     getIds: ->
         @models.map -> it.id or it.get('id') or it.cid
     
+    url: ->
+        id = @get('id') or @get('slug')
+        if id
+            "#{@urlRoot}/#id.json"
+        else
+            "#{@urlRoot}.json"
+    
+    
+    load: ->
+        @loadCollection()
+    
+    loadCollection: ->
+        @wait()
+        @trigger 'load', this
+        @fetch do
+            success : ~> @unwait(); @trigger 'load-success', this
+            error   : ~> @unwait(); @trigger 'load-error',   this, ...arguments
+        this
+    
     
     ### Serialization
     
index 276b06d..7106aab 100644 (file)
@@ -28,6 +28,17 @@ GraphListView = exports.GraphListView = BaseView.extend do # {{{
         @model = @collection or= new GraphList
         BaseView::initialize ...
         # console.log "#this.initialize!"
+        
+        @collection
+            .once 'load-success', @onLoad, this
+            .load()
+    
+    
+    onLoad: ->
+        console.log "#this.onLoad!"
+        @triggerReady()
+        @isBuilt = false
+        @render()
     
     toTemplateLocals: ->
         locals = BaseView::toTemplateLocals ...
index 7cd5732..f710147 100644 (file)
@@ -426,7 +426,7 @@ GraphList = exports.GraphList = BaseList.extend do # {{{
     
     constructor : function GraphList then BaseList ...
     initialize  : -> BaseList::initialize ...
-    toString: -> @toStringWithIds()
+    toString    : -> @toStringWithIds()
 # }}}
 
 
index 9cc5086..af32459 100644 (file)
@@ -5,22 +5,28 @@
 { Graph, GraphList, GraphListView
 } = require 'limn/graph'
 
+root = do -> this
+
 # instantiates a new GraphListView with the
 # passed in JSON graph_list_data, and then
 # appends the rendered view to the DOM.
 main = (graph_list_data) ->
-    graphs = new GraphList graph_list_data
-    view   = new GraphListView { 'collection': graphs }
+    # graphs = root.graphs = new GraphList graph_list_data
+    # view   = root.view   = new GraphListView { 'collection': graphs }
+    view   = root.view   = new GraphListView
+    graphs = root.graphs = view.collection
     $ '#content .inner' .append view.el
 
 # URL to query for saved graph JSON data.
-graph_list_url = '/graphs.json'
+# graph_list_url = '/graphs.json'
+# 
+# jQuery.ajax do
+#     url : graph_list_url
+#     dataType : 'json'
+#     success : (res) ->
+#         # result will be the returned JSON
+#         # data of all of the saved graphs
+#         jQuery main.bind this, res
+#     error : (err) -> console.error err
 
-jQuery.ajax do
-    url : graph_list_url
-    dataType : 'json'
-    success : (res) ->
-        # result will be the returned JSON
-        # data of all of the saved graphs
-        jQuery main.bind this, res
-    error : (err) -> console.error err
+jQuery main
\ No newline at end of file