Commit 167deda9 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Save.php: fixed typo

BuildFormBootstrap: fixed typo in class id pills
QfqForm.js: rewrote logic after press 'save'
parent 3c5f6014
......@@ -53,7 +53,7 @@ const SAVE_REDIRECT_URL = 'redirect-url';
const SAVE_FIELD_NAME = 'field-name';
const SAVE_FIELD_MESSAGE = 'field-message';
const ANSWER_STATUS_SUCCESS = 'succes';
const ANSWER_STATUS_SUCCESS = 'success';
const ANSWER_STATUS_ERROR = 'error';
const ANSWER_REDIRECT_CLIENT = 'client';
const ANSWER_REDIRECT_NO = 'no';
......@@ -93,6 +93,6 @@ try {
$answer[SAVE_MESSAGE] = "Generic Exception: " . $e->getMessage();
}
header("Content-Type: application/json");
echo json_encode($answer);
......@@ -145,7 +145,7 @@ class BuildFormBootstrap extends AbstractBuildForm {
$html .= '<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button">more <span class="caret"></span></a>';
}
$html = $this->wrapTag('<ul id="qfqTabs" class="nav nav-pills" role="tablist">', $pillButton . $html);
$html = $this->wrapTag('<ul id="' . $this->getTabId() . '" class="nav nav-pills" role="tablist">', $pillButton . $html);
$html = $this->wrapTag('<div class="col-md-10">', $html);
return $html;
......@@ -161,6 +161,13 @@ class BuildFormBootstrap extends AbstractBuildForm {
return $this->formSpec['name'] . '_' . $id;
}
/**
* @return string
*/
private function getTabId() {
return 'qfqTabs';
}
/**
* Simlute Submit Button: http://www.javascript-coder.com/javascript-form/javascript-form-submit.phtml
*
......@@ -186,7 +193,6 @@ BUTTONS;
return $html;
}
/**
* Builds the complete HTML '<form ...>'-tag
*
......@@ -215,6 +221,9 @@ BUTTONS;
$html .= '</div> <!--class="tab-content" -->'; // <div class="tab-content">
$html .= '<input type="submit" value="Submit">';
$formId = $this->getFormId();
$tabId = $this->getTabId();
$html .= '</form>'; // <form class="form-horizontal" ...
$html .= <<<EOF
<script type="text/javascript">
......@@ -222,25 +231,14 @@ BUTTONS;
'use strict';
QfqNS.Log.level = 0;
var qfqPageState = new QfqNS.PageState();
var qfqPage = new QfqNS.QfqPage({pageState: qfqPageState});
$("#save-button").click(function() {
$.post("typo3conf/ext/qfq/qfq/api/save.php_", $("#$formId").serialize())
.done(function() {
alert("success");
})
.fail(function() {
console.log("failure");
});
});
$("#close-button").click(function() {
window.location="http://nzz.ch";
});
$('[data-toggle="tooltip"]').tooltip();
var qfqPage = new QfqNS.QfqPage({
tabsId: '$tabId',
formId: '$formId',
submitTo: 'typo3conf/ext/qfq/qfq/api/save.php',
deleteUrl: 'typo3conf/ext/qfq/qfq/api/delete.php'
});
})
</script>
EOF;
$html .= '</div>'; // <div class="container-fluid">
......
......@@ -17,6 +17,7 @@ if (!QfqNS) {
this.deleteUrl = deleteUrl;
this.form = new n.Form(this.formId);
this.bsTabs = null;
this.lastButtonPress = null;
this.getSaveButton().addClass("disabled").attr("disabled", "disabled");
......@@ -39,6 +40,7 @@ if (!QfqNS) {
* @private
*/
n.QfqForm.prototype.handleSaveClick = function () {
this.lastButtonPress = "save";
QfqNS.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.
......@@ -50,6 +52,7 @@ if (!QfqNS) {
* @private
*/
n.QfqForm.prototype.handleCloseClick = function () {
this.lastButtonPress = "close";
if (this.form.getFormChanged()) {
var alert = new QfqNS.Alert("You have unsaved changes. Do you want to close?", "warning", "yesnosave");
var that = this;
......@@ -69,6 +72,7 @@ if (!QfqNS) {
* @private
*/
n.QfqForm.prototype.handleNewClick = function () {
this.lastButtonPress = "new";
QfqNS.Log.debug("new click");
};
......@@ -76,6 +80,7 @@ if (!QfqNS) {
* @private
*/
n.QfqForm.prototype.handleDeleteClick = function () {
this.lastButtonPress = "delete";
QfqNS.Log.debug("delete click");
$.post(this.deleteUrl)
.done(this.ajaxDeleteSuccessDispatcher.bind(this))
......@@ -297,10 +302,10 @@ if (!QfqNS) {
QfqNS.Log.debug('Reset form state');
form.resetFormChanged();
if (!data.redirect || data.redirect === "no") {
if (this.lastButtonPress === 'save' || !data.redirect || data.redirect === "no") {
if (data.message) {
var alert = new QfqNS.Alert(data.message);
alert.timeout = 3000;
alert.timeout = 1500;
alert.show();
}
return;
......@@ -311,6 +316,7 @@ if (!QfqNS) {
return;
}
if (data.redirect === "url" || data['redirect-url']) {
window.location = data['redirect-url'];
return;
......
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