Skip to content

Commit

Permalink
fix(calendar): Add confirmation box when dismissing calendar event ed…
Browse files Browse the repository at this point in the history
…ition with background click, only if the event is in edition. Fixes #5585
  • Loading branch information
WoodySlum committed Mar 22, 2023
1 parent f5ed10b commit bb4a88b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 32 deletions.
2 changes: 1 addition & 1 deletion UI/WebServerResources/js/Scheduler.services.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion UI/WebServerResources/js/Scheduler.services.js.map

Large diffs are not rendered by default.

86 changes: 56 additions & 30 deletions UI/WebServerResources/js/Scheduler/CalendarListController.js
Expand Up @@ -45,6 +45,7 @@
vm.reload = reload;
vm.cancelSearch = cancelSearch;
vm.mode = { search: false, multiple: 0 };
vm.isComponentOpened = false;


this.$onInit = function() {
Expand Down Expand Up @@ -161,36 +162,6 @@
openComponent($event, task, 'task');
}

function openComponent($event, component, type) {
if (component.viewable) {
var promise = $q.when();

// Load component before opening dialog
if (angular.isUndefined(component.$futureComponentData)) {
component = Calendar.$get(component.pid).$getComponent(component.id, component.occurrenceId);
promise = component.$futureComponentData;
}

promise.then(function() {
// UI/Templates/SchedulerUI/UIxAppointmentViewTemplate.wox or
// UI/Templates/SchedulerUI/UIxTaskViewTemplate.wox
var templateUrl = 'UIx' + type.capitalize() + 'ViewTemplate';
$mdDialog.show({
parent: angular.element(document.body),
targetEvent: $event,
clickOutsideToClose: true,
escapeToClose: true,
templateUrl: templateUrl,
controller: 'ComponentController',
controllerAs: 'editor',
locals: {
stateComponent: component
}
});
});
}
}

function eventHash(data) {
var hash = 0, i, chr, json;
json = JSON.stringify({
Expand Down Expand Up @@ -225,6 +196,61 @@
return hash;
}

function openComponent($event, component, type) {
if (component.viewable) {
var promise = $q.when();

// Load component before opening dialog
if (angular.isUndefined(component.$futureComponentData)) {
component = Calendar.$get(component.pid).$getComponent(component.id, component.occurrenceId);
promise = component.$futureComponentData;
}

if (vm.isComponentOpened) { // Prevent opening a new modal if there is already one opened (multiple clicks)
return;
}

if ('appointment' === type) {
// TODO: Improve Angular implementation
var originalCancel = $mdDialog.cancel;
var originalDataHash = eventHash(component);
vm.isComponentOpened = true;

$mdDialog.cancel = () => {
var newDataHash = eventHash(component);

if (originalDataHash === newDataHash) {
originalCancel();
$mdDialog.cancel = originalCancel;
vm.isComponentOpened = false;
} else if (confirm(l('You have modified data unsaved. Do you want to close popup and loose data ?'))) {
originalCancel();
$mdDialog.cancel = originalCancel;
vm.isComponentOpened = false;
}
};
}

promise.then(function() {
// UI/Templates/SchedulerUI/UIxAppointmentViewTemplate.wox or
// UI/Templates/SchedulerUI/UIxTaskViewTemplate.wox
var templateUrl = 'UIx' + type.capitalize() + 'ViewTemplate';
$mdDialog.show({
parent: angular.element(document.body),
targetEvent: $event,
clickOutsideToClose: true,
escapeToClose: true,
templateUrl: templateUrl,
controller: 'ComponentController',
controllerAs: 'editor',
locals: {
stateComponent: component
}
});
});
}
}

function newComponent($event, type, baseComponent) {
var component;

Expand Down

0 comments on commit bb4a88b

Please sign in to comment.