1781-zoneHoliday #994

Merged
joan merged 49 commits from 1781-zoneHoliday into dev 2022-08-03 06:41:31 +00:00
2 changed files with 32 additions and 31 deletions
Showing only changes of commit dd65f4a468 - Show all commits

View File

@ -202,7 +202,8 @@
vn-id="excludeDialog" vn-id="excludeDialog"
on-response="$ctrl.onExcludeResponse($response)" on-response="$ctrl.onExcludeResponse($response)"
message="{{$ctrl.isNew ? 'Exclusion' : 'Edit exclusion'}}" message="{{$ctrl.isNew ? 'Exclusion' : 'Edit exclusion'}}"
on-open="$ctrl.onSearch($params)"> on-open="$ctrl.onSearch($params)"
on-close="$ctrl.resetExclusions()">
<tpl-body> <tpl-body>
<vn-date-picker <vn-date-picker
label="Day" label="Day"

View File

@ -7,8 +7,8 @@ class Controller extends Section {
super($element, $); super($element, $);
this.vnWeekDays = vnWeekDays; this.vnWeekDays = vnWeekDays;
this.editMode = 'exclude'; this.editMode = 'exclude';
this.exclusions = null; this.exclusions = [];
this.exclusionsGeo = null; this.exclusionsGeo = [];
} }
$onInit() { $onInit() {
@ -64,28 +64,31 @@ class Controller extends Section {
onSelection(days, type, weekday, events, exclusions, exclusionsGeo) { onSelection(days, type, weekday, events, exclusions, exclusionsGeo) {
if (this.editMode == 'include') { if (this.editMode == 'include') {
if (events.length) if (events.length)
this.editInclusion(events[0]); return this.editInclusion(events[0]);
else return this.createInclusion(type, days, weekday);
this.createInclusion(type, days, weekday); }
} else {
if (this.editMode == 'exclude') {
if (exclusionsGeo.length) { if (exclusionsGeo.length) {
this.exclusionsGeo = exclusionsGeo; this.exclusionsGeo = exclusionsGeo;
this.editExclusion(); return this.editExclusion();
} else if (exclusions.length) { }
if (exclusions.length) {
this.exclusions = exclusions; this.exclusions = exclusions;
this.editExclusion(); return this.editExclusion();
} else }
this.createExclusion(days); return this.createExclusion(days);
} }
} }
editExclusion() { editExclusion() {
this.isNew = false; this.isNew = false;
if (this.exclusionsGeo && this.exclusionsGeo.length) {
if (this.exclusionsGeo.length) {
this.excludeSelected = angular.copy(this.exclusionsGeo[0]); this.excludeSelected = angular.copy(this.exclusionsGeo[0]);
this.excludeSelected.type = 'specificLocations'; this.excludeSelected.type = 'specificLocations';
} }
if (this.exclusions && this.exclusions.length) { if (this.exclusions.length) {
this.excludeSelected = angular.copy(this.exclusions[0]); this.excludeSelected = angular.copy(this.exclusions[0]);
this.excludeSelected.type = 'all'; this.excludeSelected.type = 'all';
} }
@ -179,14 +182,12 @@ class Controller extends Section {
case 'accept': { case 'accept': {
if (type == 'all') if (type == 'all')
return this.exclusionCreate(); return this.exclusionCreate();
else return this.exclusionGeoCreate();
return this.exclusionGeoCreate();
} }
case 'delete': case 'delete':
if (type == 'all') if (type == 'all')
return this.exclusionDelete(this.exclusions); return this.exclusionDelete(this.exclusions);
if (type == 'specificLocations') return this.exclusionGeoDelete(this.exclusionsGeo);
return this.exclusionGeoDelete(this.exclusionsGeo);
} }
} }
@ -214,12 +215,10 @@ class Controller extends Section {
if (this.isNew) if (this.isNew)
req = this.$http.post(this.exclusionsPath, [{dated}]); req = this.$http.post(this.exclusionsPath, [{dated}]);
else if (!this.isNew)
req = this.$http.put(`${this.exclusionsPath}/${excludeSelected.id}`, {dated}); req = this.$http.put(`${this.exclusionsPath}/${excludeSelected.id}`, {dated});
return req.then(() => { return req.then(() => {
this.excludeSelected = null;
this.isNew = null;
this.refresh(); this.refresh();
}); });
} }
@ -268,46 +267,47 @@ class Controller extends Section {
} }
} }
return req.then(() => { return req.then(() => {
this.excludeSelected = null;
this.isNew = null;
this.refresh(); this.refresh();
}); });
} }
exclusionDelete(exclusions) { exclusionDelete(exclusions) {
let reqs = []; const reqs = [];
for (let exclusion of exclusions) { for (let exclusion of exclusions) {
if (!exclusion.id) continue; if (!exclusion.id) continue;
let path = `${this.exclusionsPath}/${exclusion.id}`; const path = `${this.exclusionsPath}/${exclusion.id}`;
reqs.push(this.$http.delete(path)); reqs.push(this.$http.delete(path));
} }
this.$q.all(reqs) this.$q.all(reqs)
.then(() => { .then(() => {
this.excludeSelected = null;
this.exclusions = null;
this.refresh(); this.refresh();
}); });
} }
exclusionGeoDelete(exclusionsGeo) { exclusionGeoDelete(exclusionsGeo) {
let reqs = []; const reqs = [];
for (let exclusionGeo of exclusionsGeo) { for (let exclusionGeo of exclusionsGeo) {
if (!exclusionGeo.id) continue; if (!exclusionGeo.id) continue;
let path = `${this.exclusionsPath}/${exclusionGeo.zoneExclusionFk}`; const path = `${this.exclusionsPath}/${exclusionGeo.zoneExclusionFk}`;
reqs.push(this.$http.delete(path)); reqs.push(this.$http.delete(path));
} }
this.$q.all(reqs) this.$q.all(reqs)
.then(() => { .then(() => {
this.excludeSelected = null;
this.exclusionsGeo = null;
this.refresh(); this.refresh();
}); });
} }
resetExclusions() {
this.excludeSelected = null;
this.isNew = null;
this.exclusions = [];
this.exclusionsGeo = [];
}
set excludeSearch(value) { set excludeSearch(value) {
this._excludeSearch = value; this._excludeSearch = value;
if (!value) this.onSearch(); if (!value) this.onSearch();