/
myvolume.js
145 lines (103 loc) · 3.58 KB
/
myvolume.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
(function($) {
var Router = Backbone.Router.extend({
routes: {
"charts/:id" : "showChart",
"" : "showIndex"
},
showChart: function(chartId) {
console.log("Router::showChart");
if (typeof window._ChartsView === 'undefined') window._ChartsView = new ChartsView(chartId);
},
showIndex: function() {
console.log("Router::showIndex");
if (typeof window._ChartsView === 'undefined') window._ChartsView = new ChartsView;
},
startApp: function() {
//if (typeof window.App === 'undefined') window.App = new
}
});
window._Router = new Router;
var ChartModel = Backbone.Model.extend({
defaults: function() {
return {
active: false
};
},
isInactive: function() {
this.set({ active: false });
},
isActive: function() {
this.set({ active: true });
this.goTo();
},
goTo: function() {
window._Router.navigate( 'charts/'+this.get('id'), true);
}
});
var ChartList = Backbone.Collection.extend({
model: ChartModel,
url: "/charts"
});
window.Charts = new ChartList;
var ChartsView = Backbone.View.extend({
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");
$(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");
window.activeChartModel = Charts.models[0];
window.activeChartModel.isActive();
Charts.each(this.addOne);
}
});
var ChartItemView = Backbone.View.extend({
events: {
"click": "activateChart"
},
initialize: function() {
console.log("ChartItemView::Init");
_.bindAll(this, 'render', "activateChart");
this.model.bind('change', this.render);
},
render: function() {
console.log("ChartItemView::Render");
var template = ich.chart_item_template(this.model.toJSON());
$(this.el).html(template);
var genres = this.model.attributes.genres;
var node = $(this.el).find(".genres");
for (var i = 0; i < genres.length; i++) {
node.append(ich.genre_item_template({ name: genres[i] }));
}
return this;
},
activateChart: function() {
console.log("ChartItemView::activateChart");
window.activeChartModel.isInactive();
window.activeChartModel = this.model;
window.activeChartModel.isActive();
}
});
window.AppView = Backbone.View.extend({
el: $("body"),
initialize: function() {
console.log("AppView::Init");
Backbone.history.start();
}
});
window.App = new AppView;
})(jQuery);