Skip to content

Commit

Permalink
starting backbone
Browse files Browse the repository at this point in the history
  • Loading branch information
angiep committed Nov 21, 2011
1 parent b54dbb8 commit cc2c1ed
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/views/home/index.html.erb
@@ -0,0 +1 @@
<div id="charts"></div>
89 changes: 89 additions & 0 deletions public/javascripts/myvolume.js
@@ -0,0 +1,89 @@
(function($) {

window.ChartModel = Backbone.Model.extend({

defaults: function() {
return {
active: false
};
},

isInactive: function() {
this.set({ active: false });
},

isActive: function() {
this.set({ active: true });
}

});

window.ChartList = Backbone.Collection.extend({

model: ChartModel,
url: "/charts"

});

window.Charts = new ChartList;

window.ChartsView = Backbone.View.extend({
//template: _.template($("chart-template").html()),
el: $("#charts"),

initialize: function() {
console.log("ChartsView::Init");
_.bindAll(this, "render", "addOne", "addAll");
Charts.bind("reset", this.addAll, this);
Charts.fetch();

this.render();
},

render: function() {
console.log("ChartsView::Render");
console.log(this);
$(this.el).html("<div class='chart_list'></div>");
return this;
},

addOne: function(result) {
console.log("ChartsView::addOne");
var chart = new ChartItemView({model: result});
$(this.el).append(chart.render().el);
},

addAll: function() {
console.log("ChartsView::addAll");
Charts.each(this.addOne);
}

});

window.ChartItemView = Backbone.View.extend({
initialize: function() {
console.log("ChartItemView::Init");
_.bindAll(this, 'render');
Charts.bind("change", this.render, this);
},

render: function() {
console.log("ChartItemView::Render");
$(this.el).html("<div class='chart'>" + "lolol" + "</div>");
return this;
}

});

window.AppView = Backbone.View.extend({
el: $("body"),

initialize: function() {
console.log("AppView yay");
var view = new ChartsView();
}
});

window.App = new AppView;

})(jQuery);

0 comments on commit cc2c1ed

Please sign in to comment.