2018-02-10 15:18:01 +00:00
|
|
|
import ngModule from '../../module';
|
2019-10-18 19:36:30 +00:00
|
|
|
import FormInput from '../form-input';
|
2019-06-06 11:59:11 +00:00
|
|
|
import './style.scss';
|
2018-02-10 15:18:01 +00:00
|
|
|
|
2017-06-28 11:12:01 +00:00
|
|
|
/**
|
2019-09-06 06:07:46 +00:00
|
|
|
* Multicheck component for checking all form instances at once
|
2018-05-08 07:55:45 +00:00
|
|
|
* @param {SmallInt} checkAll Primary input-check state: 0 -> uncheck, 1 -> checked
|
|
|
|
* @param {Array} data List of options shown in drop-down
|
2017-06-28 11:12:01 +00:00
|
|
|
* @param {Array} models Elements to check / unCheck
|
|
|
|
*/
|
2019-10-18 19:36:30 +00:00
|
|
|
export default class MultiCheck extends FormInput {
|
2018-05-18 12:59:56 +00:00
|
|
|
constructor($element, $scope) {
|
|
|
|
super($element, $scope);
|
2020-07-30 14:05:48 +00:00
|
|
|
this.checkAll = false;
|
2019-04-30 07:19:40 +00:00
|
|
|
this._checked = false;
|
2018-05-08 07:55:45 +00:00
|
|
|
this.checkField = 'checked';
|
2019-04-30 06:00:27 +00:00
|
|
|
this.isIntermediate = false;
|
2020-09-01 13:13:33 +00:00
|
|
|
this.mayusEnabled = false;
|
|
|
|
this.window.addEventListener('keydown', event => {
|
|
|
|
if (event.key === 'Shift')
|
|
|
|
this.mayusEnabled = true;
|
|
|
|
});
|
|
|
|
this.window.addEventListener('keyup', event => {
|
|
|
|
if (event.key === 'Shift')
|
|
|
|
this.mayusEnabled = false;
|
|
|
|
});
|
|
|
|
this.window.addEventListener('selectstart', event => {
|
|
|
|
if (this.mayusEnabled)
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
2017-06-28 11:12:01 +00:00
|
|
|
}
|
2017-10-04 11:27:39 +00:00
|
|
|
|
2019-04-30 06:00:27 +00:00
|
|
|
/**
|
|
|
|
* Gets array model instance
|
|
|
|
*
|
|
|
|
* @return {ArrayModel} - Array model instance
|
|
|
|
*/
|
|
|
|
get model() {
|
|
|
|
return this._model;
|
2017-06-26 08:52:22 +00:00
|
|
|
}
|
2017-10-04 11:27:39 +00:00
|
|
|
|
2019-04-30 06:00:27 +00:00
|
|
|
/**
|
|
|
|
* Sets the array model instance
|
2020-09-01 13:13:33 +00:00
|
|
|
* Changes indeterminate property for
|
2019-04-30 06:00:27 +00:00
|
|
|
* the check component
|
|
|
|
*
|
|
|
|
* @param {ArrayModel} value - Array model instance
|
|
|
|
*/
|
|
|
|
set model(value) {
|
|
|
|
this._model = value;
|
|
|
|
|
|
|
|
if (value) {
|
2020-09-01 13:13:33 +00:00
|
|
|
value.on('rowChange', row => {
|
|
|
|
this.isIndeterminate = !this.areAllUnchecked() && !this.areAllChecked();
|
|
|
|
|
|
|
|
if (this.mayusEnabled) {
|
|
|
|
this.currentSelection = row.obj.$orgIndex;
|
|
|
|
|
|
|
|
if (this.lastSelection != undefined && this.currentSelection != undefined)
|
|
|
|
this.setSelection(row.value, this.lastSelection, this.currentSelection);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.lastSelection = row.obj.$orgIndex;
|
2019-04-30 07:19:40 +00:00
|
|
|
|
|
|
|
if (this.areAllChecked())
|
2019-04-30 06:00:27 +00:00
|
|
|
this._checked = true;
|
2019-04-30 07:19:40 +00:00
|
|
|
else if (!this.areAllChecked())
|
|
|
|
this._checked = false;
|
2019-04-30 06:00:27 +00:00
|
|
|
});
|
2019-04-30 09:20:37 +00:00
|
|
|
|
|
|
|
value.on('dataChange', () => {
|
|
|
|
if (this.checked) this.toggle();
|
|
|
|
});
|
2019-04-30 06:00:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-01 13:13:33 +00:00
|
|
|
setSelection(value, from, to) {
|
|
|
|
let start = from;
|
|
|
|
let end = to;
|
|
|
|
|
|
|
|
if (from > to) {
|
|
|
|
start = to;
|
|
|
|
end = from;
|
|
|
|
}
|
|
|
|
|
|
|
|
const data = this.model.data;
|
|
|
|
for (let i = start; i <= end; i++)
|
|
|
|
data[i].checked = value;
|
|
|
|
}
|
|
|
|
|
2019-04-30 07:19:40 +00:00
|
|
|
/**
|
|
|
|
* 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.checkAll = value;
|
|
|
|
|
|
|
|
this.toggle();
|
2020-06-30 07:37:09 +00:00
|
|
|
this.emit('change', value);
|
2022-04-13 06:15:47 +00:00
|
|
|
|
|
|
|
if (!value)
|
|
|
|
this.checkedDummyCount = null;
|
2019-04-30 07:19:40 +00:00
|
|
|
}
|
|
|
|
|
2019-04-30 06:00:27 +00:00
|
|
|
/**
|
|
|
|
* Returns a bolean result for
|
|
|
|
* checked instances
|
|
|
|
*
|
|
|
|
* @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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-30 07:19:40 +00:00
|
|
|
* Returns a bolean result for
|
|
|
|
* checked instances
|
|
|
|
*
|
|
|
|
* @return {Boolean} - False if all instances are checked
|
2019-04-30 06:00:27 +00:00
|
|
|
*/
|
2019-04-30 07:19:40 +00:00
|
|
|
areAllUnchecked() {
|
|
|
|
if (!this.model || !this.model.data) return;
|
|
|
|
|
|
|
|
const data = this.model.data;
|
|
|
|
return data.every(item => {
|
|
|
|
return item[this.checkField] === false;
|
|
|
|
});
|
2017-06-26 08:52:22 +00:00
|
|
|
}
|
2017-10-04 11:27:39 +00:00
|
|
|
|
2022-04-12 12:40:25 +00:00
|
|
|
countRows() {
|
|
|
|
if (!this.model || !this.model.data) return;
|
|
|
|
const data = this.model.data;
|
|
|
|
const params = {
|
|
|
|
filter: {
|
|
|
|
where: this.model.userParams,
|
|
|
|
limit: null
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-04-19 12:12:31 +00:00
|
|
|
this.rows = data.length;
|
|
|
|
|
2022-04-12 12:40:25 +00:00
|
|
|
this.$http.get(this.model.url, {params})
|
|
|
|
.then(res => {
|
2022-04-19 12:12:31 +00:00
|
|
|
this.AllRowsCount = res.data.length;
|
|
|
|
this.AllRowsText = this.$t('SelectAllRows', {
|
|
|
|
rows: this.AllRowsCount
|
2022-04-12 12:40:25 +00:00
|
|
|
});
|
|
|
|
});
|
2022-04-13 06:15:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
checkDummy() {
|
|
|
|
if (this.checkedDummyCount)
|
|
|
|
return this.checkedDummyCount = null;
|
|
|
|
|
2022-04-19 12:12:31 +00:00
|
|
|
this.checkedDummyCount = this.AllRowsCount;
|
2022-04-12 12:40:25 +00:00
|
|
|
}
|
|
|
|
|
2019-04-30 06:00:27 +00:00
|
|
|
/**
|
2019-04-30 07:19:40 +00:00
|
|
|
* Toggles checked property on
|
|
|
|
* all instances
|
2019-04-30 06:00:27 +00:00
|
|
|
*/
|
2019-04-30 07:19:40 +00:00
|
|
|
toggle() {
|
2019-04-30 06:00:27 +00:00
|
|
|
const data = this.model.data;
|
|
|
|
if (!data) return;
|
2021-11-11 15:38:41 +00:00
|
|
|
for (let el of data)
|
2019-04-30 07:19:40 +00:00
|
|
|
el[this.checkField] = this.checkAll;
|
2017-10-19 12:13:28 +00:00
|
|
|
}
|
2017-06-26 08:52:22 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 15:46:06 +00:00
|
|
|
ngModule.vnComponent('vnMultiCheck', {
|
2017-06-26 08:52:22 +00:00
|
|
|
template: require('./multi-check.html'),
|
|
|
|
controller: MultiCheck,
|
|
|
|
bindings: {
|
2019-04-30 06:00:27 +00:00
|
|
|
model: '<',
|
2021-10-25 15:18:57 +00:00
|
|
|
checkField: '@?',
|
2018-05-18 12:59:56 +00:00
|
|
|
checkAll: '=?',
|
2021-11-11 15:38:41 +00:00
|
|
|
checked: '=?',
|
2022-04-12 12:40:25 +00:00
|
|
|
disabled: '<?',
|
2022-04-13 06:15:47 +00:00
|
|
|
checkDummyEnabled: '<?',
|
|
|
|
checkedDummyCount: '=?'
|
2017-06-26 08:52:22 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|