fix(calendar): Rework confirmation box when dismissing calendar event edition with background click, only if the event is in edition. Rework of #5585. Closes #5720.

This commit is contained in:
smizrahi
2023-04-05 14:13:17 +02:00
parent 2f36fa55fe
commit 6ccd22b511
4 changed files with 54 additions and 106 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -45,7 +45,6 @@
vm.reload = reload;
vm.cancelSearch = cancelSearch;
vm.mode = { search: false, multiple: 0 };
vm.isComponentOpened = false;
this.$onInit = function() {
@@ -162,40 +161,6 @@
openComponent($event, task, 'task');
}
function eventHash(data) {
var hash = 0, i, chr, json;
json = JSON.stringify({
type: data.type,
status: data.status,
selected: data.selected,
repeat: data.repeat,
pid: data.pid,
destinationCalendar: data.destinationCalendar,
delta: data.delta,
classification: data.classification,
isNew: data.isNew,
categories: data.categories,
alarm: data.alarm,
type: data.type,
summary: data.summary,
status: data.status,
organizer: data.organizer,
location: data.location,
isAllDay: data.isAllDay,
comment: data.comment,
attendees: data.attendees
});
if (json.length === 0) return hash;
for (i = 0; i < json.length; i++) {
chr = json.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0;
}
return hash;
}
function openComponent($event, component, type) {
if (component.viewable) {
var promise = $q.when();
@@ -205,48 +170,11 @@
component = Calendar.$get(component.pid).$getComponent(component.id, component.occurrenceId);
promise = component.$futureComponentData;
}
var originalDataHash = eventHash(component);
promise.then(function() {
// UI/Templates/SchedulerUI/UIxAppointmentViewTemplate.wox or
// UI/Templates/SchedulerUI/UIxTaskViewTemplate.wox
var templateUrl = 'UIx' + type.capitalize() + 'ViewTemplate';
if (vm.isComponentOpened) { // Prevent opening a new modal if there is already one opened (multiple clicks)
return;
}
// TODO: Improve Angular implementation
var originalCancel = $mdDialog.cancel;
var originalDestroy = $mdDialog.destroy;
var originalShow = $mdDialog.show;
$mdDialog.show = function(p) {
vm.isComponentOpened = true;
$mdDialog.cancel = function () {
var newDataHash = eventHash(component);
vm.isComponentOpened = false;
if (originalDataHash === newDataHash) {
$mdDialog.cancel = originalCancel;
return originalCancel();
} else if (confirm(l('You have modified data unsaved. Do you want to close popup and loose data ?'))) {
$mdDialog.cancel = originalCancel;
return originalCancel();
}
};
$mdDialog.destroy = function () {
vm.isComponentOpened = false;
$mdDialog.cancel = originalCancel;
$mdDialog.destroy = originalDestroy;
return originalDestroy();
};
return originalShow(p);
};
$mdDialog.show({
parent: angular.element(document.body),
@@ -280,36 +208,6 @@
// UI/Templates/SchedulerUI/UIxTaskEditorTemplate.wox
var templateUrl = 'UIx' + type.capitalize() + 'EditorTemplate';
if (vm.isComponentOpened) { // Prevent opening a new modal if there is already one opened (multiple clicks)
return;
}
// TODO: Improve Angular implementation
var originalCancel = $mdDialog.cancel;
var originalDestroy = $mdDialog.destroy;
var originalDataHash = eventHash(component);
vm.isComponentOpened = true;
$mdDialog.cancel = function() {
var newDataHash = eventHash(component);
vm.isComponentOpened = false;
if (originalDataHash === newDataHash) {
$mdDialog.cancel = originalCancel;
return originalCancel();
} else if (confirm(l('You have modified data unsaved. Do you want to close popup and loose data ?'))) {
$mdDialog.cancel = originalCancel;
return originalCancel();
}
};
$mdDialog.destroy = function () {
vm.isComponentOpened = false;
$mdDialog.cancel = originalCancel;
$mdDialog.destroy = originalDestroy;
return originalDestroy();
};
return $mdDialog.show({
parent: angular.element(document.body),
targetEvent: $event,

View File

@@ -23,6 +23,10 @@
$mdDialog.hide();
};
this.changed = function (d) {
console.log(d);
};
this.highPriority = function () {
return (this.component &&
this.component.priority &&
@@ -217,6 +221,7 @@
this.showRecurrenceEditor = this.component.$hasCustomRepeat;
this.showAttendeesEditor = this.component.attendees && this.component.attendees.length;
this.isFullscreen = false;
this.originalModalCancel = $mdDialog.cancel;
if (this.component.type == 'appointment') {
this.component.initAttendees();
@@ -246,8 +251,44 @@
dayStartTime = parseInt(Preferences.defaults.SOGoDayStartTime);
dayEndTime = parseInt(Preferences.defaults.SOGoDayEndTime);
this.originalHash = this.hash(this.component);
$mdDialog.cancel = function () {
if (vm.originalHash === vm.hash(vm.component) || confirm(l('You have modified data unsaved. Do you want to close popup and loose data ?'))) {
$mdDialog.cancel = vm.originalModalCancel;
return vm.originalModalCancel();
}
};
};
this.hash = function (data) {
var hash = 0, i, chr, json;
json = JSON.stringify({
repeat: data.repeat,
pid: data.pid,
destinationCalendar: data.destinationCalendar,
classification: data.classification,
categories: data.categories,
alarm: data.alarm,
summary: data.summary,
status: data.status,
organizer: data.organizer,
location: data.location,
isAllDay: data.isAllDay,
comment: data.comment,
attendees: data.attendees
});
if (json.length === 0) return hash;
for (i = 0; i < json.length; i++) {
chr = json.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0;
}
return hash;
}
this.addAttachUrl = function () {
var i = this.component.addAttachUrl('');
focus('attachUrl_' + i);
@@ -280,10 +321,10 @@
};
this.destinationCalendars = function () {
if (this.component.isNew)
if (this.component && this.component.isNew)
// New component, return all writable calendars
return Calendar.$findAll(null, true);
else if (this.component.isErasable)
else if (this.component && this.component.isErasable)
// Movable component, return all writable calendars including current one
return Calendar.$findAll(null, true, this.component.pid);
else
@@ -494,6 +535,7 @@
.then(function(data) {
$rootScope.$emit('calendars:list');
Preferences.getAlarms();
$mdDialog.cancel = vm.originalModalCancel;
$mdDialog.hide();
}, function(response) {
if (response.status == CalendarSettings.ConflictHTTPErrorCode)
@@ -511,6 +553,14 @@
};
this.cancel = function (form) {
if (vm.originalHash === vm.hash(vm.component) || confirm(l('You have modified data unsaved. Do you want to close popup and loose data ?'))) {
$mdDialog.cancel = vm.originalModalCancel;
} else {
return;
}
$mdDialog.hide();
this.reset(form);
if (this.component.isNew) {
// Cancelling the creation of a component