Commit 02fb2d00 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Merge remote-tracking branch 'origin/raos_work' into crose_work

parents 1c8c7c34 2ad45f16
......@@ -34,7 +34,7 @@ Close Button
------------
* User presses the Close button
1. Form not modified by user: Client redirects to previous page.
1. Form modified by user: Ask User 'You have unsaved changes. Do you want to close?'
1. Form modified by user: Ask User 'You have unsaved changes. Do you want to save first?'
* Yes: Client redirects to previous page.
* No: Client stays on current page.
* Save & Close:
......
......@@ -39,6 +39,7 @@ var QfqNS = QfqNS || {};
*
* {
* label: <button label>,
* focus: true | false,
* eventName: <eventname>
* }
*
......@@ -139,8 +140,11 @@ var QfqNS = QfqNS || {};
$buttons = $("<div>").addClass("alert-buttons");
}
$buttons.append($("<a>").append(buttonConfiguration.label)
.addClass("btn btn-default")
var focus = buttonConfiguration.focus ? buttonConfiguration.focus : false;
$buttons.append($("<button>").append(buttonConfiguration.label)
.attr('type', 'button')
.addClass("btn btn-default" + (focus ? " wants-focus" : ""))
.click(buttonConfiguration, this.buttonHandler.bind(this)));
}
......@@ -173,6 +177,7 @@ var QfqNS = QfqNS || {};
$alertContainer.append(this.$alertDiv);
this.$alertDiv.slideDown(this.fadeInDuration, this.afterFadeIn.bind(this));
this.$alertDiv.find(".wants-focus").focus();
this.shown = true;
......
......@@ -29,7 +29,7 @@ var QfqNS = QfqNS || {};
event.preventDefault();
var alert = new n.Alert("Do you want to delete the file?",
"warning",
[{label: "OK", eventName: "ok"}, {label: "Cancel", eventName: "cancel"}]);
[{label: "OK", eventName: "ok"}, {label: "Cancel", eventName: "cancel", focus: true}]);
alert.on('alert.ok', function () {
this.performFileDelete(event);
}.bind(this));
......
......@@ -85,7 +85,9 @@ var QfqNS = QfqNS || {};
$("input").keyup(function (event) {
if (event.which === 13) {
if (this.form.formChanged) {
this.getSaveButton().trigger("click");
this.lastButtonPress = "save&close";
n.Log.debug("save&close click");
this.submit();
}
event.preventDefault();
}
......@@ -278,9 +280,6 @@ var QfqNS = QfqNS || {};
n.QfqForm.prototype.handleSaveClick = function () {
this.lastButtonPress = "save";
n.Log.debug("save click");
// First, remove all validation states, in case a previous submit has set a validation state, thus we're not
// stockpiling them.
this.clearAllValidationStates();
this.submit();
};
......@@ -290,16 +289,18 @@ var QfqNS = QfqNS || {};
n.QfqForm.prototype.handleCloseClick = function () {
this.lastButtonPress = "close";
if (this.form.getFormChanged()) {
var alert = new n.Alert("You have unsaved changes. Do you want to close?", "warning",
[{label: "Yes", eventName: "ok"}, {label: "No", eventName: "no"}, {
label: "Save & Close",
eventName: "save"
var alert = new n.Alert("You have unsaved changes. Do you want to save first?", "warning",
[
{label: "Yes", eventName: "yes"},
{label: "No", eventName: "no", focus: true},
{
label: "Cancel", eventName: "cancel"
}]);
var that = this;
alert.on('alert.save', function () {
alert.on('alert.yes', function () {
that.submit();
});
alert.on('alert.ok', function () {
alert.on('alert.no', function () {
window.history.back();
});
alert.show();
......@@ -325,6 +326,9 @@ var QfqNS = QfqNS || {};
alert.show();
return;
}
// First, remove all validation states, in case a previous submit has set a validation state, thus we're not
// stockpiling them.
this.clearAllValidationStates();
this.form.submitTo(this.submitTo);
};
......@@ -336,20 +340,20 @@ var QfqNS = QfqNS || {};
this.lastButtonPress = "new";
if (this.form.getFormChanged()) {
var alert = new n.Alert("You have unsaved changes. Do you want to close?", "warning",
var alert = new n.Alert("You have unsaved changes. Do you want to save first?", "warning",
[
{label: "Yes", eventName: "ok"},
{label: "No", eventName: "cancel"},
{label: "Save & Close", eventName: "save"}
{label: "Yes", eventName: "yes", focus: true},
{label: "No", eventName: "no"},
{label: "Cancel", eventName: "cancel"}
]);
var that = this;
alert.on('alert.save', function () {
that.submit();
});
alert.on('alert.ok', function () {
alert.on('alert.no', function () {
var anchorTarget = that.getNewButtonTarget();
window.location = anchorTarget;
});
alert.on('alert.yes', function () {
that.submit();
});
alert.show();
} else {
var anchorTarget = this.getNewButtonTarget();
......@@ -367,7 +371,7 @@ var QfqNS = QfqNS || {};
var alert = new n.Alert("Do you really want to delete the record?", "warning",
[
{label: "Yes", eventName: "ok"},
{label: "No", eventName: "cancel"}
{label: "No", eventName: "cancel", focus: true}
]);
var that = this;
alert.on('alert.ok', function () {
......@@ -570,6 +574,9 @@ var QfqNS = QfqNS || {};
form.resetFormChanged();
switch (this.lastButtonPress) {
case 'save&close':
window.history.back();
break;
case 'save':
if (data.message) {
var alert = new n.Alert(data.message);
......@@ -658,11 +665,13 @@ var QfqNS = QfqNS || {};
$formGroup.removeClass("has-warning");
$formGroup.removeClass("has-error");
$formGroup.removeClass("has-success");
$formGroup.removeClass("has-danger");
};
n.QfqForm.prototype.clearAllValidationStates = function () {
$('.has-warning,.has-error,.has-success').removeClass("has-warning has-error has-success");
$('.has-warning,.has-error,.has-success,.has-danger').removeClass("has-warning has-error has-success" +
" has-danger");
$('[data-qfq=validation-message]').remove();
};
......
......@@ -43,7 +43,7 @@ var QfqNS = QfqNS || {};
var alert = new n.Alert("Do you really want to delete the record?", "warning",
[
{label: "Yes", eventName: "ok"},
{label: "No", eventName: "cancel"}
{label: "No", eventName: "cancel", focus: true}
]);
var that = this;
alert.on('alert.ok', function () {
......
......@@ -23,7 +23,7 @@
<script>
$(function () {
$('#showalert1').click(function () {
var alert = new QfqNS.Alert("This is alert 1", 'error', [{label: "OK", eventName: "ok"},
var alert = new QfqNS.Alert("This is alert 1", 'error', [{label: "OK", eventName: "ok", focus: true},
{label: "Cancel", eventName: "cancel"}]);
alert.on('alert.ok', function () {
console.log("OK button alert 1");
......
......@@ -656,7 +656,7 @@
<div class="col-md-6">
<div class="uploaded-file "><span class="uploaded-file-name">john.doe.png</span>
<button class="delete-file" data-sip="filedeletesip"
name="trash-picture:1"><span
name="trash-picture:1" type="button"><span
class="glyphicon glyphicon-trash"></span></button>
</div>
<input id="fileupload" name="picture:1" disabled="disabled" class="hidden" type="file"
......
......@@ -13,9 +13,7 @@ class Alert {
-getAlertClassbasedOnMessageTyp()
-getButtons()
-makeAlertContainerSingleton()
-okButtonHandler()
-removeAlert()
-saveButtonHandler()
-buttonHandler()
}
class EventEmitter
......@@ -82,6 +80,7 @@ class PageTitle <<static>> {
class QfqForm {
+getSip()
+isFormChanged()
+submit()
-ajaxDeleteSuccessDispatcher()
-applyElementConfiguration()
......
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