2020-10-02 15:10:00 +00:00
|
|
|
var dom = require('../lib/dom');
|
|
|
|
var dispose = require('../lib/dispose');
|
|
|
|
var _ = require('underscore');
|
|
|
|
var kd = require('../lib/koDom');
|
|
|
|
var AbstractWidget = require('./AbstractWidget');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switch - A bi-state Switch widget
|
|
|
|
*/
|
|
|
|
function Switch(field) {
|
2021-03-02 12:27:08 +00:00
|
|
|
AbstractWidget.call(this, field, {defaultTextColor: '#2CB0AF'});
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
dispose.makeDisposable(Switch);
|
|
|
|
_.extend(Switch.prototype, AbstractWidget.prototype);
|
|
|
|
|
|
|
|
Switch.prototype.buildConfigDom = function() {
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
Switch.prototype.buildDom = function(row) {
|
|
|
|
var value = row[this.field.colId()];
|
|
|
|
return dom('div.field_clip',
|
|
|
|
dom('div.widget_switch',
|
|
|
|
kd.toggleClass('switch_on', value),
|
|
|
|
kd.toggleClass('switch_transition', row._isRealChange),
|
|
|
|
dom('div.switch_slider'),
|
|
|
|
dom('div.switch_circle'),
|
|
|
|
dom.on('click', () => {
|
|
|
|
if (!this.field.column().isRealFormula()) {
|
|
|
|
value.setAndSave(!value.peek());
|
|
|
|
}
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Switch;
|