salix/front/core/components/check/check.js

57 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-02-10 15:18:01 +00:00
import ngModule from '../../module';
import Input from '../../lib/input';
import './style.scss';
2018-02-10 15:18:01 +00:00
export default class Controller extends Input {
2018-12-12 08:36:45 +00:00
constructor($element, $scope, $attrs) {
super($element, $scope);
componentHandler.upgradeElement(this.element.firstChild);
this.mdlElement = this.element.firstChild.MaterialCheckbox;
this.input.addEventListener('change', () => this.onChange());
this.hasInfo = Boolean($attrs.info);
this.info = $attrs.info || null;
}
set field(value) {
this._field = value;
this.input.checked = value == true;
this.mdlUpdate();
}
get field() {
return this._field;
}
$onInit() {
if (this.model) {
this.model.$render = () => {
this.input.checked = this.model.$viewValue || false;
this.mdlUpdate();
};
this.$element.on('blur keyup change', () => {
this.$.$evalAsync(() => {
this.model.$setViewValue(this.input.checked);
});
2018-02-10 15:18:01 +00:00
});
}
}
onChange() {
this._field = this.input.checked == true;
this.$.$applyAsync();
2019-01-21 10:45:53 +00:00
this.emit('change');
}
2018-02-10 15:18:01 +00:00
}
2018-12-12 08:36:45 +00:00
Controller.$inject = ['$element', '$scope', '$attrs'];
ngModule.component('vnCheck', {
template: require('./check.html'),
controller: Controller,
require: {
model: '?ngModel'
},
bindings: {
field: '=?',
2019-01-21 10:45:53 +00:00
onChange: '&?',
label: '@?',
disabled: '<?',
rule: '@?'
}
});