Commit 1f5e4438 authored by Carsten  Rose's avatar Carsten Rose
Browse files

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

parents a4a61875 ea87e722
......@@ -89,11 +89,7 @@ module.exports = function (grunt) {
expand: true,
dest: typo3_js,
flatten: true
}
]
},
jquery_devel: {
files: [
},
{
cwd: 'bower_components/jquery/dist/',
src: [
......@@ -115,11 +111,7 @@ module.exports = function (grunt) {
expand: true,
dest: typo3_js,
flatten: true
}
]
},
jquery_tablesorter_devel: {
files: [
},
{
cwd: 'bower_components/tablesorter/dist/js/',
src: [
......@@ -194,6 +186,28 @@ module.exports = function (grunt) {
dest: 'css/'
}
]
},
eventEmitter: {
files: [
{
cwd: 'bower_components/eventEmitter/',
src: [
'EventEmitter.min.js'
],
expand: true,
dest: typo3_js,
flatten: true
},
{
cwd: 'bower_components/eventEmitter/',
src: [
'EventEmitter.min.js'
],
expand: true,
dest: 'js/',
flatten: true
}
]
}
},
uglify: {
......@@ -285,6 +299,7 @@ module.exports = function (grunt) {
vendor: [
'js/jquery.min.js',
'js/bootstrap.min.js',
'js/EventEmitter.min.js',
'js/jqx-all.js',
'js/qfq.debug.js'
],
......
......@@ -19,6 +19,7 @@
"dependencies": {
"bootstrap": "~3.3.6",
"jqwidgets": "*",
"tablesorter": "jquery.tablesorter#^2.25.6"
"tablesorter": "jquery.tablesorter#^2.25.6",
"eventEmitter": "^4.3.0"
}
}
......@@ -3,10 +3,10 @@
*/
/* global $ */
/* global EventEmitter */
/* @depend QfqEvents.js */
if (!QfqNS) {
var QfqNS = {};
}
var QfqNS = QfqNS || {};
(function (n) {
'use strict';
......@@ -64,11 +64,15 @@ if (!QfqNS) {
this.fadeOutDuration = 400;
this.timerId = null;
this.eventEmitter = new EventEmitter();
this.userOkButtonHandlers = new n.Helper.FunctionList();
this.userCancelButtonHandlers = new n.Helper.FunctionList();
this.userSaveButtonHandlers = new n.Helper.FunctionList();
};
n.Alert.prototype.on = n.EventEmitter.onMixin;
/**
*
* @private
......@@ -255,19 +259,6 @@ if (!QfqNS) {
};
n.Alert.prototype.addOkButtonHandler = function (handler) {
this.userOkButtonHandlers.addFunction(handler);
};
n.Alert.prototype.addCancelButtonHandler = function (handler) {
this.userCancelButtonHandlers.addFunction(handler);
};
n.Alert.prototype.addSaveButtonHandler = function (handler) {
this.userSaveButtonHandlers.addFunction(handler);
};
/**
*
* @param handler
......@@ -276,7 +267,7 @@ if (!QfqNS) {
*/
n.Alert.prototype.okButtonHandler = function (handler) {
this.removeAlert();
this.userOkButtonHandlers.call(this);
this.eventEmitter.emitEvent('alert.ok', n.EventEmitter.makePayload(this, null));
};
/**
......@@ -287,7 +278,7 @@ if (!QfqNS) {
*/
n.Alert.prototype.saveButtonHandler = function (handler) {
this.removeAlert();
this.userSaveButtonHandlers.call(this);
this.eventEmitter.emitEvent('alert.save', n.EventEmitter.makePayload(this, null));
};
/**
......@@ -298,7 +289,7 @@ if (!QfqNS) {
*/
n.Alert.prototype.cancelButtonHandler = function (handler) {
this.removeAlert();
this.userCancelButtonHandlers.call(this);
this.eventEmitter.emitEvent('alert.cancel', n.EventEmitter.makePayload(this, null));
};
n.Alert.prototype.isShown = function () {
......
......@@ -4,10 +4,12 @@
/* global $ */
/* global console */
/* global EventEmitter */
/* @depend QfqEvents.js */
var QfqNS = QfqNS || {};
if (!QfqNS) {
var QfqNS = {};
}
(function (n) {
'use strict';
......@@ -25,8 +27,7 @@ if (!QfqNS) {
this._tabActiveSelector = '#' + this.tabId + ' .active a[data-toggle="tab"]';
this.tabs = {};
this.currentTab = this.getActiveTabFromDOM();
this.userTabShowHandlers = new n.Helper.FunctionList();
this.eventEmitter = new EventEmitter();
// Fill this.tabs
this.fillTabInformation();
......@@ -35,6 +36,8 @@ if (!QfqNS) {
this.installTabHandlers();
};
n.BSTabs.prototype.on = n.EventEmitter.onMixin;
/**
* Get active tab from DOM.
*
......@@ -102,9 +105,8 @@ if (!QfqNS) {
n.Log.debug('Enter: BSTabs.tabShowHandler()');
this.currentTab = event.target.hash.slice(1);
var that = this;
n.Log.debug("BSTabs.tabShowHandler(): invoke user handler(s)");
this.userTabShowHandlers.call(that);
this.eventEmitter.emitEvent('bootstrap.tab.shown', n.EventEmitter.makePayload(this, null));
n.Log.debug('Exit: BSTabs.tabShowHandler()');
};
......@@ -162,15 +164,6 @@ if (!QfqNS) {
return this.currentTab;
};
/**
* Add tab show handler.
*
* @param {function} handler handler function. `this` will be passed as first and only argument to the handler.
*/
n.BSTabs.prototype.addTabShowHandler = function (handler) {
this.userTabShowHandlers.addFunction(handler);
};
n.BSTabs.prototype.getTabName = function (tabId) {
if (!this.tabs[tabId]) {
console.error("Unable to find tab with id: " + tabId);
......
......@@ -4,13 +4,8 @@
/* @depend FormGroup.js */
if (!QfqNS) {
var QfqNS = {};
}
if (!QfqNS.Element) {
QfqNS.Element = {};
}
var QfqNS = QfqNS || {};
QfqNS.Element = QfqNS.Element || {};
(function (n) {
'use strict';
......
......@@ -2,13 +2,8 @@
* @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
*/
if (!QfqNS) {
var QfqNS = {};
}
if (!QfqNS.Element) {
QfqNS.Element = {};
}
var QfqNS = QfqNS || {};
QfqNS.Element = QfqNS.Element || {};
(function (n) {
'use strict';
......
......@@ -4,13 +4,8 @@
/* global $ */
if (!QfqNS) {
var QfqNS = {};
}
if (!QfqNS.Element) {
QfqNS.Element = {};
}
var QfqNS = QfqNS || {};
QfqNS.Element = QfqNS.Element || {};
(function (n) {
'use strict';
......
......@@ -2,13 +2,8 @@
* @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
*/
if (!QfqNS) {
var QfqNS = {};
}
if (!QfqNS.Element) {
QfqNS.Element = {};
}
var QfqNS = QfqNS || {};
QfqNS.Element = QfqNS.Element || {};
(function (n) {
'use strict';
......
......@@ -3,14 +3,8 @@
*/
/* global $ */
if (!QfqNS) {
var QfqNS = {};
}
if (!QfqNS.Element) {
QfqNS.Element = {};
}
var QfqNS = QfqNS || {};
QfqNS.Element = QfqNS.Element || {};
(function (n) {
'use strict';
......
......@@ -2,13 +2,8 @@
* @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
*/
if (!QfqNS) {
var QfqNS = {};
}
if (!QfqNS.Element) {
QfqNS.Element = {};
}
var QfqNS = QfqNS || {};
QfqNS.Element = QfqNS.Element || {};
(function (n) {
'use strict';
......
......@@ -2,14 +2,8 @@
* @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
*/
if (!QfqNS) {
var QfqNS = {};
}
if (!QfqNS.Element) {
QfqNS.Element = {};
}
var QfqNS = QfqNS || {};
QfqNS.Element = QfqNS.Element || {};
(function (n) {
'use strict';
......
......@@ -3,10 +3,12 @@
*/
/* global $ */
/* global EventEmitter */
if (!QfqNS) {
var QfqNS = {};
}
/* @depend QfqEvents.js */
var QfqNS = QfqNS || {};
(function (n) {
'use strict';
......@@ -15,47 +17,12 @@ if (!QfqNS) {
this.formSelector = formSelector;
this.targetUrl = targetUrl;
this.sip = sip;
// TODO: Seriously, I'd like to have an event system.
this.fileUploadStartCallbacks = new n.Helper.FunctionList();
this.fileUploadEndCallbacks = new n.Helper.FunctionList();
this.fileUploadSuccessCallbacks = new n.Helper.FunctionList();
this.fileUploadErrorCallbacks = new n.Helper.FunctionList();
this.eventEmitter = new EventEmitter();
this.setupOnChangeHandler();
};
/**
* @public
* @param handler
*/
n.FileUpload.prototype.addFileUploadStartHandler = function (handler) {
this.fileUploadStartCallbacks.addFunction(handler);
};
/**
* @public
* @param handler
*/
n.FileUpload.prototype.addFileUploadEndHandler = function (handler) {
this.fileUploadEndCallbacks.addFunction(handler);
};
/**
* @public
* @param handler
*/
n.FileUpload.prototype.addFileUploadSuccessHandler = function (handler) {
this.fileUploadSuccessCallbacks.addFunction(handler);
};
/**
* @public
* @param handler
*/
n.FileUpload.prototype.addFileUploadErrorHandler = function (handler) {
this.fileUploadErrorCallbacks.addFunction(handler);
};
n.FileUpload.prototype.on = n.EventEmitter.onMixin;
/**
*
......@@ -70,7 +37,7 @@ if (!QfqNS) {
* @param event
*/
n.FileUpload.prototype.performFileUpload = function (event) {
this.fileUploadStartCallbacks.call(event.target);
this.eventEmitter.emitEvent('fileupload.started', n.EventEmitter.makePayload(event.target, null));
var data = this.prepareData(event.target);
......@@ -111,8 +78,12 @@ if (!QfqNS) {
*/
n.FileUpload.prototype.ajaxSuccessHandler = function (uploadTriggeredBy, data, textStatus, jqXHR) {
this.fileUploadSuccessCallbacks.call(uploadTriggeredBy, data, textStatus);
this.fileUploadEndCallbacks.call(uploadTriggeredBy);
var eventData = n.EventEmitter.makePayload(uploadTriggeredBy, data, {
textStatus: textStatus,
jqXHR: jqXHR
});
this.eventEmitter.emitEvent('fileupload.upload.successful', eventData);
this.eventEmitter.emitEvent('fileupload.ended', eventData);
};
/**
......@@ -122,8 +93,13 @@ if (!QfqNS) {
* @param errorThrown
*/
n.FileUpload.prototype.ajaxErrorHandler = function (uploadTriggeredBy, jqXHR, textStatus, errorThrown) {
this.fileUploadErrorCallbacks.call(uploadTriggeredBy, textStatus, errorThrown);
this.fileUploadEndCallbacks.call(uploadTriggeredBy);
var eventData = n.EventEmitter.makePayload(uploadTriggeredBy, null, {
textStatus: textStatus,
errorThrown: errorThrown,
jqXHR: jqXHR
});
this.eventEmitter.emitEvent('fileupload.upload.failed', eventData);
this.eventEmitter.emitEvent('fileupload.ended', eventData);
};
......
......@@ -3,27 +3,23 @@
*/
/* global $ */
/* global EventEmitter */
/* @depend QfqEvents.js */
if (!QfqNS) {
var QfqNS = {};
}
var QfqNS = QfqNS || {};
(function (n) {
'use strict';
n.Form = function (formId) {
this.formId = formId;
this.eventEmitter = new EventEmitter();
if (!document.forms[this.formId]) {
throw new Error("Form '" + formId + "' does not exist.");
}
this.formChanged = false;
this.userFormChangeHandlers = new QfqNS.Helper.FunctionList();
this.userResetHandlers = new QfqNS.Helper.FunctionList();
this.userSubmitSuccessHandlers = new QfqNS.Helper.FunctionList();
this.userSubmitFailureHandlers = new QfqNS.Helper.FunctionList();
this.$form = $(document.forms[this.formId]);
this.$form.on("change", this.changeHandler.bind(this));
......@@ -32,6 +28,8 @@ if (!QfqNS) {
this.$form.find("input[type=text]").on("input paste", this.changeHandler.bind(this));
};
n.Form.prototype.on = n.EventEmitter.onMixin;
/**
*
* @param event
......@@ -40,23 +38,8 @@ if (!QfqNS) {
*/
n.Form.prototype.changeHandler = function (event) {
this.formChanged = true;
this.userFormChangeHandlers.call(this);
};
n.Form.prototype.addChangeHandler = function (callback) {
this.userFormChangeHandlers.addFunction(callback);
};
n.Form.prototype.addResetHandler = function (callback) {
this.userResetHandlers.addFunction(callback);
};
n.Form.prototype.addSubmitSuccessHandler = function (callback) {
this.userSubmitSuccessHandlers.addFunction(callback);
};
n.Form.prototype.addSubmitFailureHandler = function (callback) {
this.userSubmitFailureHandlers.addFunction(callback);
this.eventEmitter.emitEvent('form.changed', n.EventEmitter.makePayload(this, null));
// REMOVE: this.userFormChangeHandlers.call(this);
};
n.Form.prototype.getFormChanged = function () {
......@@ -65,7 +48,8 @@ if (!QfqNS) {
n.Form.prototype.resetFormChanged = function () {
this.formChanged = false;
this.userResetHandlers.call(this);
this.eventEmitter.emitEvent('form.reset', n.EventEmitter.makePayload(this, null));
// REMOVE: this.userResetHandlers.call(this);
};
n.Form.prototype.submitTo = function (to) {
......@@ -87,7 +71,11 @@ if (!QfqNS) {
* @private
*/
n.Form.prototype.ajaxSuccessHandler = function (data, textStatus, jqXHR) {
this.userSubmitSuccessHandlers.call(this, data, textStatus);
this.eventEmitter.emitEvent('form.submit.successful',
n.EventEmitter.makePayload(this, data, {
textStatus: textStatus,
jqXHR: jqXHR
}));
};
/**
......@@ -96,7 +84,12 @@ if (!QfqNS) {
* @private
*/
n.Form.prototype.submitFailureHandler = function (jqXHR, textStatus, errorThrown) {
this.userSubmitFailureHandlers.call(this, textStatus, jqXHR, errorThrown);
this.eventEmitter.emitEvent('form.submit.failed', n.EventEmitter.makePayload(this, null, {
textStatus: textStatus,
errorThrown: errorThrown,
jqXHR: jqXHR
}));
// REMOVE: this.userSubmitFailureHandlers.call(this, textStatus, jqXHR, errorThrown);
};
})(QfqNS);
......@@ -4,17 +4,16 @@
/* global $ */
if (!QfqNS) {
var QfqNS = {};
}
if (!QfqNS.Helper) {
QfqNS.Helper = {};
}
var QfqNS = QfqNS || {};
QfqNS.Helper = QfqNS.Helper || {};
(function (n) {
'use strict';
/**
* @deprecated
* @constructor
*/
n.FunctionList = function () {
this.functions = [];
};
......
......@@ -4,14 +4,8 @@
/* global $ */
if (!QfqNS) {
var QfqNS = {};
}
if (!QfqNS.Helper) {
QfqNS.Helper = {};
}
var QfqNS = QfqNS || {};
QfqNS.Helper = QfqNS.Helper || {};
(function (n) {
'use strict';
......
......@@ -4,9 +4,7 @@
/* global console */
if (!QfqNS) {
var QfqNS = {};
}
var QfqNS = QfqNS || {};
(function (n) {
'use strict';
......
......@@ -2,9 +2,10 @@
* @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
*/
if (!QfqNS) {
var QfqNS = {};
}
/* @depend QfqEvents.js */
/* global EventEmitter */
var QfqNS = QfqNS || {};
(function (n) {
'use strict';
......@@ -14,10 +15,12 @@ if (!QfqNS) {
this.pageState = location.hash.slice(1);
this.data = null;
this.inPoppingHandler = false;
this.userPopStateHandlers = new n.Helper.FunctionList();
this.eventEmitter = new EventEmitter();
window.addEventListener("popstate", this.popStateHandler.bind(this));
};
n.PageState.prototype.on = n.EventEmitter.onMixin;
/**
*
* @param event
......@@ -34,7 +37,7 @@ if (!QfqNS) {
n.Log.debug("PageState.popStateHandler(): invoke user pop state handler(s)");
this.userPopStateHandlers.call(this);