datahub/src/view.js
rgrp 3a48044a76 [model,refactor][m]: (refs #6, refs #10) get rid of DocumentSet merging its functionality into Dataset.
* In addition fully remove remaining references in models (in getRows and getLength functions) to form of backend (this should have been in previous commit).
2011-11-05 20:20:31 +00:00

42 lines
994 B
JavaScript

this.recline = this.recline || {};
recline.DataTable = Backbone.View.extend({
tagName: "div",
className: "data-table-container",
// template: TODO ???
events: {
},
initialize: function() {
var that = this;
this.model.fetch().then(function() {
that.model.getRows().then(function(rows) {
that._currentRows = rows;
that.render()
});
})
},
toTemplateJSON: function() {
var modelData = this.model.toJSON()
modelData.rows = _.map(this._currentRows, function(row) {
var cellData = _.map(modelData.headers, function(header) {
return {header: header, value: row[header]}
})
return { id: 'xxx', cells: cellData }
})
modelData.notEmpty = ( modelData.headers.length > 0 )
return modelData;
},
render: function() {
var template = $( ".dataTableTemplate:first" ).html()
, htmls = $.mustache(template, this.toTemplateJSON())
;
$(this.el).html(htmls);
return this;
}
});