mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-01-11 17:58:41 +00:00
prevent unsaved change loss
This commit is contained in:
parent
b0b7d178ea
commit
0fccd49375
|
|
@ -67,6 +67,20 @@ export class AppNotification
|
|||
output.querySelector('.log-msg-title').remove();
|
||||
}
|
||||
|
||||
if (!msg.primaryButton) {
|
||||
output.querySelector('.primary-button').remove();
|
||||
} else {
|
||||
output.querySelector('.primary-button').innerHTML = msg.primaryButton.text;
|
||||
output.querySelector('.primary-button').addEventListener('click', msg.primaryButton.callback);
|
||||
}
|
||||
|
||||
if (!msg.secondaryButton) {
|
||||
output.querySelector('.secondary-button').remove();
|
||||
} else {
|
||||
output.querySelector('.secondary-button').innerHTML = msg.secondaryButton.text;
|
||||
output.querySelector('.secondary-button').addEventListener('click', msg.secondaryButton.callback);
|
||||
}
|
||||
|
||||
tpl.parentNode.appendChild(output);
|
||||
|
||||
const logs = document.getElementsByClassName('log-msg');
|
||||
|
|
|
|||
|
|
@ -35,5 +35,8 @@ export class NotificationMessage
|
|||
|
||||
/** @type {boolean} isSticky */
|
||||
this.isSticky = isSticky;
|
||||
|
||||
this.primaryButton = null;
|
||||
this.secondaryButton = null;
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -340,10 +340,13 @@ export class Request
|
|||
|
||||
for (const p in this.requestHeader) {
|
||||
if (Object.prototype.hasOwnProperty.call(this.requestHeader, p) && this.requestHeader[p] !== '') {
|
||||
if (this.requestHeader[p] !== 'multipart/form-data') {
|
||||
// note: If not excluded for multipart/form-data you need to set the boundary= manually for php which is not wanted
|
||||
this.xhr.setRequestHeader(p, this.requestHeader[p]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.omsApp.logger.log(UriFactory.build(this.uri));
|
||||
window.omsApp.logger.log(this.xhr);
|
||||
|
|
|
|||
|
|
@ -56,6 +56,19 @@ export class Form
|
|||
return this.forms[id];
|
||||
};
|
||||
|
||||
hasChanges()
|
||||
{
|
||||
const length = this.forms.length;
|
||||
|
||||
for (let i = 0; i < length; ++i) {
|
||||
if (this.forms[i].hasChange()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Is form ignored?
|
||||
*
|
||||
|
|
@ -136,6 +149,12 @@ export class Form
|
|||
toBind[i].addEventListener('click', function (event) {
|
||||
self.formActions(self, event, id);
|
||||
});
|
||||
|
||||
if (!this.forms[id].isOnChange()) {
|
||||
toBind[i].addEventListener('change', function (evnt) {
|
||||
window.omsApp.state.hasChanges = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const imgPreviews = this.forms[id].getImagePreviews();
|
||||
|
|
@ -154,6 +173,7 @@ export class Form
|
|||
onChangeContainer.addEventListener('change', function (event)
|
||||
{
|
||||
jsOMS.preventAll(event);
|
||||
window.omsApp.state.hasChanges = true;
|
||||
|
||||
const target = event.target.tagName.toLowerCase();
|
||||
|
||||
|
|
@ -1053,6 +1073,7 @@ export class Form
|
|||
);
|
||||
});
|
||||
|
||||
window.omsApp.state.hasChanges = false;
|
||||
request.send();
|
||||
|
||||
if (form.getFinally() !== null) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
|
||||
import { UriFactory } from '../Uri/UriFactory.js';
|
||||
import { AdvancedInput } from './Component/AdvancedInput.js';
|
||||
import { NotificationLevel } from '../Message/Notification/NotificationLevel.js';
|
||||
import { NotificationMessage } from '../Message/Notification/NotificationMessage.js';
|
||||
import { NotificationType } from '../Message/Notification/NotificationType.js';
|
||||
|
||||
|
||||
/**
|
||||
* UI manager for handling basic ui elements.
|
||||
|
|
@ -100,7 +104,6 @@ export class GeneralUI
|
|||
|
||||
let uri = this.getAttribute('data-href');
|
||||
uri = uri === null ? this.getAttribute('href') : uri;
|
||||
history.pushState({}, null, UriFactory.build(uri));
|
||||
|
||||
if (this.getAttribute('target') === '_blank'
|
||||
|| this.getAttribute(['data-target']) === '_blank'
|
||||
|
|
@ -109,11 +112,19 @@ export class GeneralUI
|
|||
window.open(UriFactory.build(uri), '_blank');
|
||||
} else {
|
||||
// window.location = UriFactory.build(uri);
|
||||
|
||||
fetch(UriFactory.build(uri))
|
||||
.then((response) => response.text())
|
||||
.then((html) => {
|
||||
if (window.omsApp.state.hasChanges) {
|
||||
let message = new NotificationMessage(NotificationLevel.WARNING, 'Unsaved changes', 'Do you want to continue?', true, true);
|
||||
message.primaryButton = {
|
||||
text: 'Yes',
|
||||
style: 'ok',
|
||||
callback: function () {
|
||||
document.documentElement.innerHTML = html;
|
||||
window.omsApp.state.hasChanges = false;
|
||||
this.parentNode.remove();
|
||||
history.pushState({}, null, UriFactory.build(uri));
|
||||
/* This is not working as it reloads the page ?!
|
||||
document.open();
|
||||
document.write(html);
|
||||
|
|
@ -121,6 +132,30 @@ export class GeneralUI
|
|||
*/
|
||||
// @todo: fix memory leak which most likely exists because of continous binding without removing binds
|
||||
window.omsApp.reInit();
|
||||
},
|
||||
};
|
||||
message.secondaryButton = {
|
||||
text: 'No',
|
||||
style: 'error',
|
||||
callback: function () {
|
||||
this.parentNode.remove();
|
||||
},
|
||||
};
|
||||
|
||||
window.omsApp.notifyManager.send(message, NotificationType.APP_NOTIFICATION);
|
||||
} else {
|
||||
document.documentElement.innerHTML = html;
|
||||
window.omsApp.state.hasChanges = false;
|
||||
this.parentNode.remove();
|
||||
history.pushState({}, null, UriFactory.build(uri));
|
||||
/* This is not working as it reloads the page ?!
|
||||
document.open();
|
||||
document.write(html);
|
||||
document.close();
|
||||
*/
|
||||
// @todo: fix memory leak which most likely exists because of continous binding without removing binds
|
||||
window.omsApp.reInit();
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn(error);
|
||||
|
|
|
|||
|
|
@ -56,6 +56,9 @@ export class FormView
|
|||
/** @type {string} action */
|
||||
this.action = '';
|
||||
|
||||
/** @type {bool} hasChanges */
|
||||
this.hasChanges = false;
|
||||
|
||||
this.bind();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user