1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-31 16:02:29 +01:00
Sonarr/UI/Cells/ToggleCell.js

56 lines
1.3 KiB
JavaScript
Raw Normal View History

2013-06-22 08:24:24 +02:00
'use strict';
2013-06-09 08:20:38 +02:00
define(
[
'backgrid'
], function (Backgrid) {
return Backgrid.Cell.extend({
className: 'toggle-cell',
events: {
'click': '_onClick'
},
_onClick: function () {
2013-07-10 02:25:15 +02:00
var self = this;
this.$el.tooltip('hide');
var name = this.column.get('name');
this.model.set(name, !this.model.get(name));
2013-07-10 02:25:15 +02:00
this.$('i').addClass('icon-spinner icon-spin');
this.model.save().always(function () {
self.render();
});
},
2013-06-09 08:20:38 +02:00
render: function () {
this.$el.empty();
this.$el.html('<i />');
2013-06-09 08:20:38 +02:00
var name = this.column.get('name');
2013-06-09 08:20:38 +02:00
if (this.model.get(name)) {
this.$('i').addClass(this.column.get('trueClass'));
}
else {
this.$('i').addClass(this.column.get('falseClass'));
}
var tooltip = this.column.get('tooltip');
if (tooltip) {
this.$el.attr('title', tooltip);
2013-07-31 19:14:27 +02:00
this.$el.attr('data-container', 'body');
}
return this;
}
});
2013-06-09 08:20:38 +02:00
});