Commit 1f95b485 authored by Rafael Ostertag's avatar Rafael Ostertag
Browse files

Delete Button: When user confirms deletion of record, all buttons will be...

Delete Button: When user confirms deletion of record, all buttons will be disabled and form removed.
parent c95eacfb
...@@ -18,6 +18,7 @@ if (!QfqNS) { ...@@ -18,6 +18,7 @@ if (!QfqNS) {
this.form = new n.Form(this.formId); this.form = new n.Form(this.formId);
this.bsTabs = null; this.bsTabs = null;
this.lastButtonPress = null; this.lastButtonPress = null;
this.destroyFormUserCallbacks = new n.Helper.FunctionList();
this.getSaveButton().addClass("disabled").attr("disabled", "disabled"); this.getSaveButton().addClass("disabled").attr("disabled", "disabled");
...@@ -36,6 +37,36 @@ if (!QfqNS) { ...@@ -36,6 +37,36 @@ if (!QfqNS) {
this.bsTabs = bsTabs; this.bsTabs = bsTabs;
}; };
/**
*
* @param $button
* @param enabled {boolean}
*
* @private
*/
n.QfqForm.prototype.setButtonEnabled = function ($button, enabled) {
if (!$button) {
n.Log.error("QfqForm#setButtonEnabled(): no button provided.");
return;
}
if (!enabled) {
$button.addClass("disabled");
$button.attr("disabled", "disabled");
} else {
$button.removeClass("disabled");
$button.removeAttr("disabled");
}
};
/**
* @private
*/
n.QfqForm.prototype.destroyFormAndSetText = function (text) {
this.form = null;
$('#' + this.formId).replaceWith($("<p>").append(text));
this.destroyFormUserCallbacks.call();
};
/** /**
* @private * @private
*/ */
...@@ -124,6 +155,12 @@ if (!QfqNS) { ...@@ -124,6 +155,12 @@ if (!QfqNS) {
* @private * @private
*/ */
n.QfqForm.prototype.handleDeleteSuccess = function (data) { n.QfqForm.prototype.handleDeleteSuccess = function (data) {
this.setButtonEnabled(this.getCloseButton(), false);
this.setButtonEnabled(this.getDeleteButton(), false);
this.setButtonEnabled(this.getSaveButton(), false);
this.setButtonEnabled(this.getNewButton(), false);
this.destroyFormAndSetText("Record has been deleted!");
if (!data.redirect || data.redirect === "client") { if (!data.redirect || data.redirect === "client") {
window.history.back(); window.history.back();
return; return;
......
...@@ -45,12 +45,21 @@ if (!QfqNS) { ...@@ -45,12 +45,21 @@ if (!QfqNS) {
try { try {
this.qfqForm = new QfqNS.QfqForm(this.settings.formId, this.settings.submitTo, this.settings.deleteUrl); this.qfqForm = new QfqNS.QfqForm(this.settings.formId, this.settings.submitTo, this.settings.deleteUrl);
this.qfqForm.setBsTabs(this.bsTabs); this.qfqForm.setBsTabs(this.bsTabs);
this.qfqForm.destroyFormUserCallbacks.addFunction(this.destroyFormHandler.bind(this));
} catch (e) { } catch (e) {
QfqNS.Log.error(e.message); QfqNS.Log.error(e.message);
this.qfqForm = null; this.qfqForm = null;
} }
}; };
/**
* @private
*/
n.QfqPage.prototype.destroyFormHandler = function () {
this.settings.qfqForm = null;
$('#' + this.settings.tabsId).remove();
};
n.QfqPage.prototype.tabShowHandler = function (bsTabs) { n.QfqPage.prototype.tabShowHandler = function (bsTabs) {
// tabShowHandler will be called every time the tab will be shown, regardless of whether or not this happens // tabShowHandler will be called every time the tab will be shown, regardless of whether or not this happens
// because of BSTabs.activateTab() or user interaction. // because of BSTabs.activateTab() or user interaction.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment