summaryrefslogtreecommitdiff
path: root/assets/js/core
diff options
context:
space:
mode:
Diffstat (limited to 'assets/js/core')
-rw-r--r--assets/js/core/modal.js40
1 files changed, 37 insertions, 3 deletions
diff --git a/assets/js/core/modal.js b/assets/js/core/modal.js
index e7f2c2ff..dc656efa 100644
--- a/assets/js/core/modal.js
+++ b/assets/js/core/modal.js
@@ -1,18 +1,42 @@
(function () {
var isOpen = false;
+ var isFormDirty = false;
+
+ function closeIfDirty() {
+ if (isFormDirty == false) {
+ return true;
+ }
+
+ return window.confirm($("body").data("js-modal-close-msg").replace(/\\n/g,"\n"));
+ }
function onOverlayClick(e) {
if (e.target.matches('#modal-overlay')) {
- e.stopPropagation();
- e.preventDefault();
- destroy();
+ if (closeIfDirty()) {
+ e.stopPropagation();
+ e.preventDefault();
+ destroy();
+ }
}
}
+ function onBeforeUnload(e) {
+ // Cancel the event as stated by the standard.
+ e.preventDefault();
+
+ // Chrome requires returnValue to be set.
+ e.returnValue = '';
+ }
+
function onCloseButtonClick() {
KB.trigger('modal.close');
}
+ function onFormChange() {
+ isFormDirty = true;
+ window.addEventListener('beforeunload', onBeforeUnload, false);
+ }
+
function onFormSubmit() {
KB.trigger('modal.loading');
submitForm();
@@ -51,6 +75,7 @@
function afterRendering() {
var formElement = KB.find('#modal-content form');
if (formElement) {
+ formElement.on('change', onFormChange, false);
formElement.on('submit', onFormSubmit, false);
}
@@ -65,6 +90,13 @@
_KB.tagAutoComplete();
_KB.get('Task').onPopoverOpened();
+ if (formElement) {
+ $('.form-date').datepicker('option', 'onSelect', onFormChange);
+ $('.form-datetime').datepicker('option', 'onSelect', onFormChange);
+ $(".color-picker").on('change', onFormChange);
+ $(".tag-autocomplete").on('change', onFormChange);
+ }
+
KB.trigger('modal.afterRender');
}
@@ -122,6 +154,8 @@
function destroy() {
isOpen = false;
+ isFormDirty = false;
+ window.removeEventListener('beforeunload', onBeforeUnload, false);
var overlayElement = KB.find('#modal-overlay');
if (overlayElement) {