salix/client/core/src/components/check/check.js

53 lines
1.4 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 {
constructor($element, $scope) {
super($element, $scope);
componentHandler.upgradeElement(this.element.firstChild);
this.mdlElement = this.element.firstChild.MaterialCheckbox;
this.input.addEventListener('change', () => this.onChange());
}
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();
}
2018-02-10 15:18:01 +00:00
}
Controller.$inject = ['$element', '$scope', '$injector'];
ngModule.component('vnCheck', {
template: require('./check.html'),
controller: Controller,
require: {
model: '?ngModel'
},
bindings: {
field: '=?',
label: '@?',
disabled: '<?',
rule: '@?'
}
});