67:311b37063c1d
Anton Shestakov <av6@dwimlabs.net>, Fri, 05 Feb 2016 16:46:59 +0800
mention provisioning in docs

next change 140:2e975ca4302e
previous change 48:a09a4fec2716

static/js/framework/views/base.js

Permissions: -rw-r--r--

Other formats: Feeds:
var CollectionView = Backbone.View.extend({
appendItem: function() {},
updateItem: function() {},
removeItem: function() {},
clear: function() {},
repopulate: function() {
this.clear();
this.collection.each(this.appendItem, this);
},
bindCollection: function() {
this.repopulate();
this.collection
.on('add', this.appendItem, this)
.on('change', this.updateItem, this)
.on('remove', this.removeItem, this)
.on('reset', this.repopulate, this);
},
unbindCollection: function() {
this.collection.off(null, null, this);
},
compileTemplates: function(templates) {
this.templates = {};
_.each(templates, function(template, name) {
this.templates[name] = _.template(template);
}, this);
}
});
var Displayer = Backbone.View.extend({
render: function(text) {
this.$el.text(text);
return this;
}
});
var CollectionCounterView = CollectionView.extend({
initialize: function(options) {
if ('plurals' in options) {
this.makeTitle = function(n) {
return n + ' ' + options.plurals[n == 1 ? 0 : 1];
};
}
this.bindCollection();
},
appendItem: function() {
this.repopulate();
},
removeItem: function() {
this.repopulate();
},
repopulate: function() {
this.$el.html(this.makeTitle(this.collection.models.length));
},
makeTitle: function(n) {
return n;
}
});