2018-02-10 15:18:01 +00:00
|
|
|
import ngModule from '../../module';
|
2018-02-12 12:16:49 +00:00
|
|
|
import Input from '../../lib/input';
|
|
|
|
import './style.scss';
|
2018-02-10 15:18:01 +00:00
|
|
|
|
2018-02-12 12:16:49 +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) {
|
2018-10-15 09:43:57 +00:00
|
|
|
this._field = value;
|
2018-02-12 12:16:49 +00:00
|
|
|
this.input.checked = value == true;
|
|
|
|
this.mdlUpdate();
|
|
|
|
}
|
|
|
|
get field() {
|
2018-10-15 09:43:57 +00:00
|
|
|
return this._field;
|
2018-02-12 12:16:49 +00:00
|
|
|
}
|
|
|
|
$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
|
|
|
});
|
|
|
|
}
|
2018-02-12 12:16:49 +00:00
|
|
|
}
|
|
|
|
onChange() {
|
2018-10-15 09:43:57 +00:00
|
|
|
this._field = this.input.checked == true;
|
2018-02-12 12:16:49 +00:00
|
|
|
this.$.$applyAsync();
|
|
|
|
}
|
2018-02-10 15:18:01 +00:00
|
|
|
}
|
2018-02-12 12:16:49 +00:00
|
|
|
Controller.$inject = ['$element', '$scope', '$injector'];
|
|
|
|
|
|
|
|
ngModule.component('vnCheck', {
|
|
|
|
template: require('./check.html'),
|
|
|
|
controller: Controller,
|
|
|
|
require: {
|
|
|
|
model: '?ngModel'
|
|
|
|
},
|
|
|
|
bindings: {
|
|
|
|
field: '=?',
|
|
|
|
label: '@?',
|
|
|
|
disabled: '<?',
|
|
|
|
rule: '@?'
|
|
|
|
}
|
|
|
|
});
|