From e5c3d51174d1f6fbe6e65bb183ec230b6ec57209 Mon Sep 17 00:00:00 2001 From: David Schoonover Date: Mon, 16 Jul 2012 12:58:59 -0700 Subject: [PATCH] Updates GraphListView to load GraphList itself, rather than rely on main. --- src/base/base-model.co | 19 +++++++++++++++++++ src/graph/graph-list-view.co | 11 +++++++++++ src/graph/graph-model.co | 2 +- src/main-graph-list.co | 28 +++++++++++++++++----------- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/base/base-model.co b/src/base/base-model.co index 383fc66..68ed48d 100644 --- a/src/base/base-model.co +++ b/src/base/base-model.co @@ -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 diff --git a/src/graph/graph-list-view.co b/src/graph/graph-list-view.co index 276b06d..7106aab 100644 --- a/src/graph/graph-list-view.co +++ b/src/graph/graph-list-view.co @@ -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 ... diff --git a/src/graph/graph-model.co b/src/graph/graph-model.co index 7cd5732..f710147 100644 --- a/src/graph/graph-model.co +++ b/src/graph/graph-model.co @@ -426,7 +426,7 @@ GraphList = exports.GraphList = BaseList.extend do # {{{ constructor : function GraphList then BaseList ... initialize : -> BaseList::initialize ... - toString: -> @toStringWithIds() + toString : -> @toStringWithIds() # }}} diff --git a/src/main-graph-list.co b/src/main-graph-list.co index 9cc5086..af32459 100644 --- a/src/main-graph-list.co +++ b/src/main-graph-list.co @@ -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 -- 1.7.0.4