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