signal-desktop/js/views/whisper_view.js
lilia f764445c86 Remove erroneous license file and headers
We only use GPLV3 around here.

// FREEBIE
2015-09-07 14:58:42 -07:00

54 lines
1.7 KiB
JavaScript

/*
* vim: ts=4:sw=4:expandtab
*/
(function () {
'use strict';
window.Whisper = window.Whisper || {};
Whisper.View = Backbone.View.extend({
constructor: function() {
Backbone.View.apply(this, arguments);
Mustache.parse(_.result(this, 'template'));
},
render_attributes: function() {
return _.result(this.model, 'attributes', {});
},
render_partials: function() {
return Whisper.View.Templates;
},
template: function() {
if (this.templateName) {
return Whisper.View.Templates[this.templateName];
}
return '';
},
render: function() {
var attrs = _.result(this, 'render_attributes', {});
var template = _.result(this, 'template', '');
var partials = _.result(this, 'render_partials', '');
this.$el.html(Mustache.render(template, attrs, partials));
return this;
},
confirm: function(message) {
return new Promise(function(resolve, reject) {
var dialog = new Whisper.ConfirmationDialogView({
message: message,
resolve: resolve,
reject: reject
});
this.$el.append(dialog.el);
}.bind(this));
}
},{
// Class attributes
Templates: (function() {
var templates = {};
$('script[type="text/x-tmpl-mustache"]').each(function(i, el) {
var $el = $(el);
var id = $el.attr('id');
templates[id] = $el.html();
});
return templates;
}())
});
})();