/
categories_view.js
64 lines (51 loc) · 1.36 KB
/
categories_view.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
var $ = require('jquery');
var cdb = require('cartodb.js');
cdb.admin = require('cdb.admin');
var Backbone = require('backbone');
/**
* Categories view.
*
* Select a category of the data library
*
*/
module.exports = cdb.core.View.extend({
initialize: function() {
this.router = this.options.router;
this.localStorage = this.options.localStorage;
// TODO: Get categories using an API.
this.collection = new Backbone.Collection();
this.template = cdb.templates.getTemplate('new_dashboard/views/categories');
this._initBinds();
},
render: function() {
this.clearSubViews();
var currentCategory = this.router.model.get('category');
var categories = this.collection.models;
this.$el.html(
this.template({
currentCategory: currentCategory,
categories: categories
})
);
this._initViews();
return this;
},
_initBinds: function() {
this.router.model.bind('change:category', this.render, this);
this.add_related_model(this.router.model);
},
_initViews: function() {
// Tipsys?
var self = this;
this.$('.Categories-option[data-title]').each(function(i,el){
self.addView(
new cdb.common.TipsyTooltip({
el: $(el),
title: function(e) {
return $(this).attr('data-title')
}
})
)
});
},
});