diff --git a/javascript/src/QfqForm.js b/javascript/src/QfqForm.js index 22f61b8883fc644abcf7b757b7f213894f2d23e9..db1784c689814ef69426c54aeb9da8e1f9c8e020 100644 --- a/javascript/src/QfqForm.js +++ b/javascript/src/QfqForm.js @@ -12,6 +12,16 @@ var QfqNS = QfqNS || {}; 'use strict'; // TODO: This object is getting too big. Start refactoring. + /** + * Represents a QFQ Form. + * + * @param formId {string} value of the form's id attribute + * @param submitTo {string} url where data will be submitted to + * @param deleteUrl {string} url to call upon record deletion + * @param dataRefreshUrl {string} url where to fetch new element values from + * @param fileUploadTo {string} url used for file uploads + * @constructor + */ n.QfqForm = function (formId, submitTo, deleteUrl, dataRefreshUrl, fileUploadTo) { this.formId = formId; this.submitTo = submitTo; @@ -181,7 +191,6 @@ var QfqNS = QfqNS || {}; */ n.QfqForm.prototype.handleNewClick = function (event) { event.preventDefault(); - var anchorTarget = event.target.getAttribute("href"); this.lastButtonPress = "new"; if (this.form.getFormChanged()) { @@ -189,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"); }; @@ -406,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") { @@ -433,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) { diff --git a/mockup/personmock.html b/mockup/personmock.html index edc72d8ebe53d857e9b5e02dcfadc5115695285f..85f27ce49c8402675cea8c90b77d76835bc96019 100644 --- a/mockup/personmock.html +++ b/mockup/personmock.html @@ -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>