Radarr/src/UI/Cells/NzbDroneCell.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

2015-02-03 01:18:45 +00:00
var Backgrid = require('backgrid');
var Backbone = require('backbone');
module.exports = Backgrid.Cell.extend({
2015-02-13 21:04:39 +00:00
2015-02-03 01:18:45 +00:00
_originalInit : Backgrid.Cell.prototype.initialize,
2015-02-13 21:04:39 +00:00
initialize : function() {
2015-02-03 01:18:45 +00:00
this._originalInit.apply(this, arguments);
this.cellValue = this._getValue();
2015-02-13 21:04:39 +00:00
2015-02-03 01:18:45 +00:00
this.listenTo(this.model, 'change', this._refresh);
2015-02-13 21:04:39 +00:00
if (this._onEdit) {
this.listenTo(this.model, 'backgrid:edit', function(model, column, cell, editor) {
if (column.get('name') === this.column.get('name')) {
2015-02-03 01:18:45 +00:00
this._onEdit(model, column, cell, editor);
2013-07-18 02:09:34 +00:00
}
2015-02-03 01:18:45 +00:00
});
}
},
2015-02-13 21:04:39 +00:00
_refresh : function() {
2015-02-03 01:18:45 +00:00
this.cellValue = this._getValue();
this.render();
},
2015-02-13 21:04:39 +00:00
_getValue : function() {
2015-02-03 01:18:45 +00:00
var cellValue = this.column.get('cellValue');
2015-02-13 21:04:39 +00:00
if (cellValue) {
if (cellValue === 'this') {
2015-02-03 01:18:45 +00:00
return this.model;
}
else {
return this.model.get(cellValue);
}
2015-02-03 01:18:45 +00:00
}
2015-02-13 21:04:39 +00:00
2015-02-03 01:18:45 +00:00
var name = this.column.get('name');
2015-02-13 21:04:39 +00:00
if (name === 'this') {
2015-02-03 01:18:45 +00:00
return this.model;
}
2015-02-13 21:04:39 +00:00
2015-02-03 01:18:45 +00:00
var value = this.model.get(name);
2015-02-13 21:04:39 +00:00
if (!value) {
2015-02-03 01:18:45 +00:00
return undefined;
}
2015-02-13 21:04:39 +00:00
//if not a model
if (!value.get && typeof value === 'object') {
2015-02-03 01:18:45 +00:00
value = new Backbone.Model(value);
}
2015-02-13 21:04:39 +00:00
2015-02-03 01:18:45 +00:00
return value;
}
});