Commit 076db686 authored by Rafael Ostertag's avatar Rafael Ostertag
Browse files

Added Namespace functions for QfqNS.Helper namespace.

Do not address namespace with `QfqNS` in Object definitions. Instead, use `n`. This might have screwed up the code. We'll fix as we go along.
parent dbd40587
......@@ -64,9 +64,9 @@ if (!QfqNS) {
this.fadeOutDuration = 400;
this.timerId = null;
this.userOkButtonHandlers = new QfqNS.Helper.FunctionList();
this.userCancelButtonHandlers = new QfqNS.Helper.FunctionList();
this.userSaveButtonHandlers = new QfqNS.Helper.FunctionList();
this.userOkButtonHandlers = new n.Helper.FunctionList();
this.userCancelButtonHandlers = new n.Helper.FunctionList();
this.userSaveButtonHandlers = new n.Helper.FunctionList();
};
/**
......@@ -111,7 +111,7 @@ if (!QfqNS) {
return "alert-danger";
/* jshint -W086 */
default:
QfqNS.Log.warning("Message type '" + this.messageType + "' unknown. Use default type.");
n.Log.warning("Message type '" + this.messageType + "' unknown. Use default type.");
case "info":
return "alert-success";
/* jshint +W086 */
......@@ -181,7 +181,7 @@ if (!QfqNS) {
return buttons;
/* jshint -W086 */
default:
QfqNS.Log.warning("Buttons '" + this.buttons + "' unknown. Use default buttons");
n.Log.warning("Buttons '" + this.buttons + "' unknown. Use default buttons");
case "none":
break;
/* jshint +W086 */
......
......@@ -25,7 +25,7 @@ if (!QfqNS) {
this._tabActiveSelector = '#' + this.tabId + ' .active a[data-toggle="tab"]';
this.tabs = {};
this.currentTab = this.getActiveTabFromDOM();
this.userTabShowHandlers = new QfqNS.Helper.FunctionList();
this.userTabShowHandlers = new n.Helper.FunctionList();
// Fill this.tabs
......@@ -99,13 +99,13 @@ if (!QfqNS) {
* @param event
*/
n.BSTabs.prototype.tabShowHandler = function (event) {
QfqNS.Log.debug('Enter: BSTabs.tabShowHandler()');
n.Log.debug('Enter: BSTabs.tabShowHandler()');
this.currentTab = event.target.hash.slice(1);
var that = this;
QfqNS.Log.debug("BSTabs.tabShowHandler(): invoke user handler(s)");
n.Log.debug("BSTabs.tabShowHandler(): invoke user handler(s)");
this.userTabShowHandlers.call(that);
QfqNS.Log.debug('Exit: BSTabs.tabShowHandler()');
n.Log.debug('Exit: BSTabs.tabShowHandler()');
};
/**
......@@ -187,7 +187,7 @@ if (!QfqNS) {
n.BSTabs.prototype.getContainingTabIdForFormControl = function (formControlName) {
var $formControl = $("[name='" + formControlName + "']");
if ($formControl.length === 0) {
QfqNS.Log.debug("BSTabs.getContainingTabForFormControl(): unable to find form control with name '" + formControlName + "'");
n.Log.debug("BSTabs.getContainingTabForFormControl(): unable to find form control with name '" + formControlName + "'");
return null;
}
......
/**
* @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
*/
/* global $ */
if (!QfqNS) {
var QfqNS = {};
}
if (!QfqNS.Helper) {
QfqNS.Helper = {};
}
(function (n) {
'use strict';
n.showAjaxError = function (jqHXR, textStatus, errorThrown) {
var alert = new QfqNS.Alert("Error:<br> " +
errorThrown, "error");
alert.show();
};
})(QfqNS.Helper);
\ No newline at end of file
......@@ -14,7 +14,7 @@ if (!QfqNS) {
this.pageState = location.hash.slice(1);
this.data = null;
this.inPoppingHandler = false;
this.userPopStateHandlers = new QfqNS.Helper.FunctionList();
this.userPopStateHandlers = new n.Helper.FunctionList();
window.addEventListener("popstate", this.popStateHandler.bind(this));
};
......@@ -26,18 +26,18 @@ if (!QfqNS) {
*/
n.PageState.prototype.popStateHandler = function (event) {
QfqNS.Log.debug("Enter: PageState.popStateHandler()");
n.Log.debug("Enter: PageState.popStateHandler()");
this.inPoppingHandler = true;
this.pageState = location.hash.slice(1);
this.data = window.history.state;
QfqNS.Log.debug("PageState.popStateHandler(): invoke user pop state handler(s)");
n.Log.debug("PageState.popStateHandler(): invoke user pop state handler(s)");
this.userPopStateHandlers.call(this);
this.inPoppingHandler = false;
QfqNS.Log.debug("Exit: PageState.popStateHandler()");
n.Log.debug("Exit: PageState.popStateHandler()");
};
......
......@@ -74,10 +74,7 @@ if (!QfqNS) {
n.QfqForm.prototype.formUpdateHandler = function () {
var that = this;
$.post(this.dataRefreshUrl, this.form.serialize(), "json")
.fail(function (jqXHR, textStatus, errorThrown) {
var alert = new QfqNS.Alert("Error:<br>" + errorThrown, "error");
alert.show();
})
.fail(n.Helper.showAjaxError)
.done(function (data) {
this.handleFormUpdate(data);
}.bind(that));
......@@ -169,7 +166,7 @@ if (!QfqNS) {
alert.addOkButtonHandler(function () {
$.post(that.deleteUrl)
.done(that.ajaxDeleteSuccessDispatcher.bind(that))
.fail(that.ajaxDeleteFailureHandler.bind(that));
.fail(n.Helper.showAjaxError);
});
alert.show();
};
......@@ -316,25 +313,7 @@ if (!QfqNS) {
* @private
*/
n.QfqForm.prototype.submitFailureHandler = function (form, textStatus, jqXHR, errorThrown) {
this.showAjaxError(errorThrown);
};
/**
*
* @param jqXHR
* @param textStatus
* @param errorThrown
*
* @private
*/
n.QfqForm.prototype.ajaxDeleteFailureHandler = function (jqXHR, textStatus, errorThrown) {
this.showAjaxError(errorThrown);
};
n.QfqForm.prototype.showAjaxError = function (errorThrown) {
var alert = new QfqNS.Alert("Error:<br> " +
errorThrown, "error");
alert.show();
n.Helper.showAjaxError(errorThrown);
};
......@@ -531,7 +510,7 @@ if (!QfqNS) {
/**
* @private
* @param event
* @param triggeredBy
*/
n.QfqForm.prototype.startUploadHandler = function (triggeredBy) {
$(triggeredBy).after(
......@@ -541,13 +520,17 @@ if (!QfqNS) {
/**
* @private
* @param event
* @param triggeredBy
*/
n.QfqForm.prototype.endUploadHandler = function (triggeredBy) {
var $siblings = $(triggeredBy).siblings();
$siblings.filter("i").remove();
};
n.QfqForm.prototype.ajaxFileUploadErrorHandler = function (triggeredBy, jqHXR, textStatus, errorThrown) {
n.Helper.showAjaxError(jqHXR, textStatus, errorThrown);
};
/**
* Retrieve SIP as stored in hidden input field.
*
......
......@@ -21,31 +21,31 @@ if (!QfqNS) {
deleteUrl: "typo3conf/ext/qfq/qfq/api/delete.php",
refreshUrl: "typo3conf/ext/qfq/qfq/api/load.php",
fileUploadTo: "typo3conf/ext/qfq/qfq/api/upload.php",
pageState: new QfqNS.PageState()
pageState: new n.PageState()
}, settings
);
try {
this.bsTabs = new QfqNS.BSTabs(this.settings.tabsId);
this.bsTabs = new n.BSTabs(this.settings.tabsId);
var currentState = this.settings.pageState.getPageState();
if (currentState !== "") {
this.bsTabs.activateTab(currentState);
QfqNS.PageTitle.setSubTitle(this.bsTabs.getTabName(currentState));
n.PageTitle.setSubTitle(this.bsTabs.getTabName(currentState));
} else {
this.settings.pageState.setPageState(this.bsTabs.getCurrentTab(), QfqNS.PageTitle.get());
this.settings.pageState.setPageState(this.bsTabs.getCurrentTab(), n.PageTitle.get());
}
this.bsTabs.addTabShowHandler(this.tabShowHandler.bind(this));
this.settings.pageState.addStateActivationHandler(this.popStateHandler.bind(this));
} catch (e) {
QfqNS.Log.message(e.message);
n.Log.message(e.message);
this.bsTabs = null;
}
try {
this.qfqForm = new QfqNS.QfqForm(
this.qfqForm = new n.QfqForm(
this.settings.formId,
this.settings.submitTo,
this.settings.deleteUrl,
......@@ -54,7 +54,7 @@ if (!QfqNS) {
this.qfqForm.setBsTabs(this.bsTabs);
this.qfqForm.destroyFormUserCallbacks.addFunction(this.destroyFormHandler.bind(this));
} catch (e) {
QfqNS.Log.error(e.message);
n.Log.error(e.message);
this.qfqForm = null;
}
};
......@@ -74,20 +74,20 @@ if (!QfqNS) {
// Therefore, we have to make sure, that tabShowHandler() does not save the page state while we're restoring
// a previous state, i.e. we're called because of the popStateHandler() below.
if (this.settings.pageState.inPoppingHandler) {
QfqNS.Log.debug("Prematurely terminating QfqPage.tabShowHandler(): called due to page state" +
n.Log.debug("Prematurely terminating QfqPage.tabShowHandler(): called due to page state" +
" restoration.");
return;
}
var currentTabId = bsTabs.getCurrentTab();
QfqNS.Log.debug('Saving state: ' + currentTabId);
QfqNS.PageTitle.setSubTitle(bsTabs.getTabName(currentTabId));
this.settings.pageState.setPageState(currentTabId, QfqNS.PageTitle.get());
n.Log.debug('Saving state: ' + currentTabId);
n.PageTitle.setSubTitle(bsTabs.getTabName(currentTabId));
this.settings.pageState.setPageState(currentTabId, n.PageTitle.get());
};
n.QfqPage.prototype.popStateHandler = function (pageState) {
this.bsTabs.activateTab(pageState.getPageState());
QfqNS.PageTitle.set(pageState.getPageData());
n.PageTitle.set(pageState.getPageData());
};
})(QfqNS);
\ No newline at end of file
......@@ -42,12 +42,12 @@ if (!QfqNS) {
}
var alert = new QfqNS.Alert("Do you really want to delete the record?", "warning", "yesno");
var alert = new n.Alert("Do you really want to delete the record?", "warning", "yesno");
var that = this;
alert.addOkButtonHandler(function () {
$.post(that.deleteUrl + "?s=" + sip)
.done(that.ajaxDeleteSuccessDispatcher.bind(that, $recordElement))
.fail(that.ajaxDeleteFailureHandler.bind(that));
.fail(n.Helper.showAjaxError);
});
alert.show();
};
......@@ -84,11 +84,11 @@ if (!QfqNS) {
return;
}
if (data.redirect && data.redirect === "no") {
var alert = new QfqNS.Alert("redirect=='no' not allowed", "error");
var alert = new n.Alert("redirect=='no' not allowed", "error");
alert.show();
}
var info = new QfqNS.Alert("Record successfully deleted", "info");
var info = new n.Alert("Record successfully deleted", "info");
info.timeout = 1500;
info.show();
$recordElement.fadeOut(function () {
......@@ -96,12 +96,6 @@ if (!QfqNS) {
});
};
n.QfqRecordList.prototype.ajaxDeleteFailureHandler = function (jqXHR, textStatus, errorThrown) {
var alert = new QfqNS.Alert("Error:<br> " +
errorThrown, "error");
alert.show();
};
n.QfqRecordList.prototype.getRecordElement = function (element) {
return $(element).closest('.' + this.recordClass);
};
......@@ -116,7 +110,7 @@ if (!QfqNS) {
if (!data.message) {
throw Error("Status is 'error' but required 'message' attribute is missing.");
}
var alert = new QfqNS.Alert(data.message, "error");
var alert = new n.Alert(data.message, "error");
alert.show();
};
......
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