2013-06-22 08:24:24 +02:00
|
|
|
'use strict';
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
define(
|
|
|
|
[
|
|
|
|
'backgrid'
|
|
|
|
], function (Backgrid) {
|
|
|
|
return Backgrid.Cell.extend({
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
_originalInit: Backgrid.Cell.prototype.initialize,
|
2013-06-09 22:51:32 +02:00
|
|
|
|
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
initialize: function () {
|
|
|
|
this._originalInit.apply(this, arguments);
|
|
|
|
this.cellValue = this._getValue();
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
this.listenTo(this.model, 'change', this._refresh);
|
|
|
|
},
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
_refresh: function () {
|
|
|
|
this.cellValue = this._getValue();
|
|
|
|
this.render();
|
|
|
|
},
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
_getValue: function () {
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-07-18 04:09:34 +02:00
|
|
|
var cellValue = this.column.get('cellValue');
|
|
|
|
|
|
|
|
if (cellValue) {
|
|
|
|
if (cellValue === 'this') {
|
|
|
|
return this.model;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
var name = this.column.get('name');
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
if (name === 'this') {
|
|
|
|
return this.model;
|
|
|
|
}
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
var value = this.model.get(name);
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
if (!value) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2013-06-10 04:10:15 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
//if not a model
|
|
|
|
if (!value.get && typeof value === 'object') {
|
|
|
|
value = new Backbone.Model(value);
|
|
|
|
}
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
return value;
|
|
|
|
}
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
});
|
2013-06-09 22:51:32 +02:00
|
|
|
});
|