2013-06-22 09:24:24 +03:00
|
|
|
'use strict';
|
2013-06-09 09:20:38 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
define(
|
|
|
|
[
|
|
|
|
'backgrid'
|
|
|
|
], function (Backgrid) {
|
|
|
|
return Backgrid.Cell.extend({
|
2013-06-09 09:21:32 +03:00
|
|
|
|
2013-07-10 08:02:51 +03:00
|
|
|
className: 'toggle-cell',
|
2013-06-09 09:21:32 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
events: {
|
|
|
|
'click': '_onClick'
|
|
|
|
},
|
2013-06-09 09:21:32 +03:00
|
|
|
|
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
_onClick: function () {
|
2013-07-26 05:09:17 +03:00
|
|
|
|
2013-07-10 03:25:15 +03:00
|
|
|
var self = this;
|
|
|
|
|
2013-07-26 05:09:17 +03:00
|
|
|
this.$el.tooltip('hide');
|
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
var name = this.column.get('name');
|
|
|
|
this.model.set(name, !this.model.get(name));
|
2013-06-09 09:21:32 +03:00
|
|
|
|
2013-07-10 03:25:15 +03:00
|
|
|
this.$('i').addClass('icon-spinner icon-spin');
|
|
|
|
|
2013-07-26 05:09:17 +03:00
|
|
|
this.model.save().always(function () {
|
|
|
|
self.render();
|
|
|
|
});
|
2013-06-25 02:41:59 +03:00
|
|
|
},
|
2013-06-09 09:20:38 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
render: function () {
|
|
|
|
this.$el.empty();
|
|
|
|
this.$el.html('<i />');
|
2013-06-09 09:20:38 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
var name = this.column.get('name');
|
2013-06-09 09:20:38 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
if (this.model.get(name)) {
|
|
|
|
this.$('i').addClass(this.column.get('trueClass'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.$('i').addClass(this.column.get('falseClass'));
|
|
|
|
}
|
2013-07-09 18:41:42 +03:00
|
|
|
|
|
|
|
var tooltip = this.column.get('tooltip');
|
|
|
|
|
|
|
|
if (tooltip) {
|
2013-07-26 05:09:17 +03:00
|
|
|
this.$el.attr('title', tooltip);
|
2013-07-09 18:41:42 +03:00
|
|
|
}
|
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
return this;
|
2013-06-09 09:21:32 +03:00
|
|
|
}
|
2013-06-25 02:41:59 +03:00
|
|
|
});
|
2013-06-09 09:20:38 +03:00
|
|
|
});
|