propagate check value to multicheck component for intermediate value #1305
gitea/salix/dev There was a failure building this commit
Details
gitea/salix/dev There was a failure building this commit
Details
This commit is contained in:
parent
6b6faff383
commit
a572130b6c
|
@ -1 +1,5 @@
|
||||||
<vn-check field="$ctrl.checkAll"></vn-check>
|
<vn-check field="$ctrl.checked"
|
||||||
|
intermediate="$ctrl.isIntermediate"
|
||||||
|
vn-tooltip="Check all"
|
||||||
|
tooltip-position="up">
|
||||||
|
</vn-check>
|
|
@ -12,21 +12,74 @@ export default class MultiCheck extends Input {
|
||||||
super($element, $scope);
|
super($element, $scope);
|
||||||
this._checkAll = false;
|
this._checkAll = false;
|
||||||
this.checkField = 'checked';
|
this.checkField = 'checked';
|
||||||
|
this.isIntermediate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
get checkAll() {
|
/**
|
||||||
return this._checkAll;
|
* Gets array model instance
|
||||||
|
*
|
||||||
|
* @return {ArrayModel} - Array model instance
|
||||||
|
*/
|
||||||
|
get model() {
|
||||||
|
return this._model;
|
||||||
}
|
}
|
||||||
|
|
||||||
set checkAll(value) {
|
/**
|
||||||
this._checkAll = value;
|
* Sets the array model instance
|
||||||
this.switchChecks();
|
* Changes intermediate property for
|
||||||
|
* the check component
|
||||||
|
*
|
||||||
|
* @param {ArrayModel} value - Array model instance
|
||||||
|
*/
|
||||||
|
set model(value) {
|
||||||
|
this._model = value;
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
value.on('rowChange', () => {
|
||||||
|
this.isIntermediate = this.allChecked && !this.areAllChecked();
|
||||||
|
if (this.isIntermediate)
|
||||||
|
this._checked = undefined;
|
||||||
|
else if (this.areAllChecked())
|
||||||
|
this._checked = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switchChecks() {
|
/**
|
||||||
if (!this.data) return;
|
* Returns a bolean result for
|
||||||
this.data.forEach(el => {
|
* checked instances
|
||||||
el[this.checkField] = this._checkAll;
|
*
|
||||||
|
* @return {Boolean} - True if all instances are checked
|
||||||
|
*/
|
||||||
|
areAllChecked() {
|
||||||
|
if (!this.model || !this.model.data) return;
|
||||||
|
|
||||||
|
const data = this.model.data;
|
||||||
|
return data.every(item => {
|
||||||
|
return item[this.checkField] === true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets current check state
|
||||||
|
*/
|
||||||
|
get checked() {
|
||||||
|
return this._checked;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets current check state
|
||||||
|
*
|
||||||
|
* @param {Boolean} value - Checkbox state [undefined, true, false]
|
||||||
|
*/
|
||||||
|
set checked(value) {
|
||||||
|
this._checked = value;
|
||||||
|
this.allChecked = value;
|
||||||
|
|
||||||
|
const data = this.model.data;
|
||||||
|
if (!data) return;
|
||||||
|
data.forEach(el => {
|
||||||
|
el[this.checkField] = value;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +88,7 @@ ngModule.component('vnMultiCheck', {
|
||||||
template: require('./multi-check.html'),
|
template: require('./multi-check.html'),
|
||||||
controller: MultiCheck,
|
controller: MultiCheck,
|
||||||
bindings: {
|
bindings: {
|
||||||
data: '=',
|
model: '<',
|
||||||
checkField: '<?',
|
checkField: '<?',
|
||||||
checkAll: '=?',
|
checkAll: '=?',
|
||||||
disabled: '<?'
|
disabled: '<?'
|
||||||
|
|
|
@ -41,4 +41,5 @@ Has delivery: Hay reparto
|
||||||
Loading: Cargando
|
Loading: Cargando
|
||||||
Fields to show: Campos a mostrar
|
Fields to show: Campos a mostrar
|
||||||
Create new one: Crear nuevo
|
Create new one: Crear nuevo
|
||||||
Toggle: Desplegar/Plegar
|
Toggle: Desplegar/Plegar
|
||||||
|
Check all: Seleccionar todo
|
|
@ -30,7 +30,7 @@
|
||||||
<vn-tr>
|
<vn-tr>
|
||||||
<vn-th shrink>
|
<vn-th shrink>
|
||||||
<vn-multi-check
|
<vn-multi-check
|
||||||
data="$ctrl.tickets">
|
model="model">
|
||||||
</vn-multi-check>
|
</vn-multi-check>
|
||||||
</vn-th>
|
</vn-th>
|
||||||
<vn-th>Order</vn-th>
|
<vn-th>Order</vn-th>
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
<vn-tr>
|
<vn-tr>
|
||||||
<vn-th shrink>
|
<vn-th shrink>
|
||||||
<vn-multi-check
|
<vn-multi-check
|
||||||
data="tickets">
|
model="model">
|
||||||
</vn-multi-check>
|
</vn-multi-check>
|
||||||
</vn-th>
|
</vn-th>
|
||||||
<vn-th></vn-th>
|
<vn-th></vn-th>
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
<vn-tr>
|
<vn-tr>
|
||||||
<vn-th shrink>
|
<vn-th shrink>
|
||||||
<vn-multi-check
|
<vn-multi-check
|
||||||
data="$ctrl.sales">
|
model="model">
|
||||||
</vn-multi-check>
|
</vn-multi-check>
|
||||||
</vn-th>
|
</vn-th>
|
||||||
<vn-th shrink></vn-th>
|
<vn-th shrink></vn-th>
|
||||||
|
|
Loading…
Reference in New Issue