Commit bb15e252 authored by Rafael Ostertag's avatar Rafael Ostertag
Browse files

Handle errors received from the server when using the `new` button gracefully.

parent 2883642d
......@@ -191,7 +191,6 @@ var QfqNS = QfqNS || {};
*/
n.QfqForm.prototype.handleNewClick = function (event) {
event.preventDefault();
var anchorTarget = event.delegateTarget.getAttribute("href");
this.lastButtonPress = "new";
if (this.form.getFormChanged()) {
......@@ -199,12 +198,15 @@ var QfqNS = QfqNS || {};
var that = this;
alert.on('alert.save', function () {
that.form.submitTo(that.submitTo);
window.location = anchorTarget;
});
alert.on('alert.ok', function () {
var anchorTarget = that.getNewButtonTarget();
window.location = anchorTarget;
});
alert.show();
} else {
var anchorTarget = this.getNewButtonTarget();
window.location = anchorTarget;
}
n.Log.debug("new click");
};
......@@ -416,18 +418,25 @@ var QfqNS = QfqNS || {};
n.Log.debug('Reset form state');
form.resetFormChanged();
if (this.lastButtonPress === 'save' || !data.redirect || data.redirect === "no") {
if (data.message) {
var alert = new n.Alert(data.message);
alert.timeout = 1500;
alert.show();
}
// do we have to update the HTML Form?
if (data['form-update']) {
this.applyElementConfiguration(data['form-update']);
}
return;
switch (this.lastButtonPress) {
case 'save':
if (!data.redirect || data.redirect === "no") {
if (data.message) {
var alert = new n.Alert(data.message);
alert.timeout = 1500;
alert.show();
}
// do we have to update the HTML Form?
if (data['form-update']) {
this.applyElementConfiguration(data['form-update']);
}
}
return;
case 'new':
var target = this.getNewButtonTarget();
window.location = this.getNewButtonTarget();
return;
}
if (data.redirect === "client") {
......@@ -443,6 +452,10 @@ var QfqNS = QfqNS || {};
};
n.QfqForm.prototype.getNewButtonTarget = function () {
return $('#form-new-button').attr('href');
};
n.QfqForm.prototype.getFormGroupByControlName = function (formControlName) {
var $formControl = $("[name='" + formControlName + "']");
if ($formControl.length === 0) {
......
......@@ -91,8 +91,8 @@
class="glyphicon glyphicon-trash"></span></button>
</div>
<div class="btn-group" role="group">
<button id="new-button" type="button" class="btn btn-default navbar-btn"><span
class="glyphicon glyphicon-plus"></span></button>
<a id="form-new-button" href="http://www.wikipedia.org" class="btn btn-default navbar-btn"><span
class="glyphicon glyphicon-plus"></span></a>
</div>
</div>
</div>
......
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