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) { ...@@ -89,11 +89,7 @@ module.exports = function (grunt) {
expand: true, expand: true,
dest: typo3_js, dest: typo3_js,
flatten: true flatten: true
} },
]
},
jquery_devel: {
files: [
{ {
cwd: 'bower_components/jquery/dist/', cwd: 'bower_components/jquery/dist/',
src: [ src: [
...@@ -115,11 +111,7 @@ module.exports = function (grunt) { ...@@ -115,11 +111,7 @@ module.exports = function (grunt) {
expand: true, expand: true,
dest: typo3_js, dest: typo3_js,
flatten: true flatten: true
} },
]
},
jquery_tablesorter_devel: {
files: [
{ {
cwd: 'bower_components/tablesorter/dist/js/', cwd: 'bower_components/tablesorter/dist/js/',
src: [ src: [
...@@ -194,6 +186,28 @@ module.exports = function (grunt) { ...@@ -194,6 +186,28 @@ module.exports = function (grunt) {
dest: 'css/' 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: { uglify: {
...@@ -285,6 +299,7 @@ module.exports = function (grunt) { ...@@ -285,6 +299,7 @@ module.exports = function (grunt) {
vendor: [ vendor: [
'js/jquery.min.js', 'js/jquery.min.js',
'js/bootstrap.min.js', 'js/bootstrap.min.js',
'js/EventEmitter.min.js',
'js/jqx-all.js', 'js/jqx-all.js',
'js/qfq.debug.js' 'js/qfq.debug.js'
], ],
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
"dependencies": { "dependencies": {
"bootstrap": "~3.3.6", "bootstrap": "~3.3.6",
"jqwidgets": "*", "jqwidgets": "*",
"tablesorter": "jquery.tablesorter#^2.25.6" "tablesorter": "jquery.tablesorter#^2.25.6",
"eventEmitter": "^4.3.0"
} }
} }
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
*/ */
/* global $ */ /* global $ */
/* global EventEmitter */
/* @depend QfqEvents.js */
if (!QfqNS) { var QfqNS = QfqNS || {};
var QfqNS = {};
}
(function (n) { (function (n) {
'use strict'; 'use strict';
...@@ -64,11 +64,15 @@ if (!QfqNS) { ...@@ -64,11 +64,15 @@ if (!QfqNS) {
this.fadeOutDuration = 400; this.fadeOutDuration = 400;
this.timerId = null; this.timerId = null;
this.eventEmitter = new EventEmitter();
this.userOkButtonHandlers = new n.Helper.FunctionList(); this.userOkButtonHandlers = new n.Helper.FunctionList();
this.userCancelButtonHandlers = new n.Helper.FunctionList(); this.userCancelButtonHandlers = new n.Helper.FunctionList();
this.userSaveButtonHandlers = new n.Helper.FunctionList(); this.userSaveButtonHandlers = new n.Helper.FunctionList();
}; };
n.Alert.prototype.on = n.EventEmitter.onMixin;
/** /**
* *
* @private * @private
...@@ -255,19 +259,6 @@ if (!QfqNS) { ...@@ -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 * @param handler
...@@ -276,7 +267,7 @@ if (!QfqNS) { ...@@ -276,7 +267,7 @@ if (!QfqNS) {
*/ */
n.Alert.prototype.okButtonHandler = function (handler) { n.Alert.prototype.okButtonHandler = function (handler) {
this.removeAlert(); this.removeAlert();
this.userOkButtonHandlers.call(this); this.eventEmitter.emitEvent('alert.ok', n.EventEmitter.makePayload(this, null));
}; };
/** /**
...@@ -287,7 +278,7 @@ if (!QfqNS) { ...@@ -287,7 +278,7 @@ if (!QfqNS) {
*/ */
n.Alert.prototype.saveButtonHandler = function (handler) { n.Alert.prototype.saveButtonHandler = function (handler) {
this.removeAlert(); this.removeAlert();
this.userSaveButtonHandlers.call(this); this.eventEmitter.emitEvent('alert.save', n.EventEmitter.makePayload(this, null));
}; };
/** /**
...@@ -298,7 +289,7 @@ if (!QfqNS) { ...@@ -298,7 +289,7 @@ if (!QfqNS) {
*/ */
n.Alert.prototype.cancelButtonHandler = function (handler) { n.Alert.prototype.cancelButtonHandler = function (handler) {
this.removeAlert(); this.removeAlert();
this.userCancelButtonHandlers.call(this); this.eventEmitter.emitEvent('alert.cancel', n.EventEmitter.makePayload(this, null));
}; };
n.Alert.prototype.isShown = function () { n.Alert.prototype.isShown = function () {
......
...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
/* global $ */ /* global $ */
/* global console */ /* global console */
/* global EventEmitter */
/* @depend QfqEvents.js */
var QfqNS = QfqNS || {};
if (!QfqNS) {
var QfqNS = {};
}
(function (n) { (function (n) {
'use strict'; 'use strict';
...@@ -25,8 +27,7 @@ if (!QfqNS) { ...@@ -25,8 +27,7 @@ if (!QfqNS) {
this._tabActiveSelector = '#' + this.tabId + ' .active a[data-toggle="tab"]'; this._tabActiveSelector = '#' + this.tabId + ' .active a[data-toggle="tab"]';
this.tabs = {}; this.tabs = {};
this.currentTab = this.getActiveTabFromDOM(); this.currentTab = this.getActiveTabFromDOM();
this.userTabShowHandlers = new n.Helper.FunctionList(); this.eventEmitter = new EventEmitter();
// Fill this.tabs // Fill this.tabs
this.fillTabInformation(); this.fillTabInformation();
...@@ -35,6 +36,8 @@ if (!QfqNS) { ...@@ -35,6 +36,8 @@ if (!QfqNS) {
this.installTabHandlers(); this.installTabHandlers();
}; };
n.BSTabs.prototype.on = n.EventEmitter.onMixin;
/** /**
* Get active tab from DOM. * Get active tab from DOM.
* *
...@@ -102,9 +105,8 @@ if (!QfqNS) { ...@@ -102,9 +105,8 @@ if (!QfqNS) {
n.Log.debug('Enter: BSTabs.tabShowHandler()'); n.Log.debug('Enter: BSTabs.tabShowHandler()');
this.currentTab = event.target.hash.slice(1); this.currentTab = event.target.hash.slice(1);
var that = this;
n.Log.debug("BSTabs.tabShowHandler(): invoke user handler(s)"); 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()'); n.Log.debug('Exit: BSTabs.tabShowHandler()');
}; };
...@@ -162,15 +164,6 @@ if (!QfqNS) { ...@@ -162,15 +164,6 @@ if (!QfqNS) {
return this.currentTab; 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) { n.BSTabs.prototype.getTabName = function (tabId) {
if (!this.tabs[tabId]) { if (!this.tabs[tabId]) {
console.error("Unable to find tab with id: " + tabId); console.error("Unable to find tab with id: " + tabId);
......
...@@ -4,13 +4,8 @@ ...@@ -4,13 +4,8 @@
/* @depend FormGroup.js */ /* @depend FormGroup.js */
if (!QfqNS) { var QfqNS = QfqNS || {};
var QfqNS = {}; QfqNS.Element = QfqNS.Element || {};
}
if (!QfqNS.Element) {
QfqNS.Element = {};
}
(function (n) { (function (n) {
'use strict'; 'use strict';
......
...@@ -2,13 +2,8 @@ ...@@ -2,13 +2,8 @@
* @author Rafael Ostertag <rafael.ostertag@math.uzh.ch> * @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
*/ */
if (!QfqNS) { var QfqNS = QfqNS || {};
var QfqNS = {}; QfqNS.Element = QfqNS.Element || {};
}
if (!QfqNS.Element) {
QfqNS.Element = {};
}
(function (n) { (function (n) {
'use strict'; 'use strict';
......
...@@ -4,13 +4,8 @@ ...@@ -4,13 +4,8 @@
/* global $ */ /* global $ */
if (!QfqNS) { var QfqNS = QfqNS || {};
var QfqNS = {}; QfqNS.Element = QfqNS.Element || {};
}
if (!QfqNS.Element) {
QfqNS.Element = {};
}
(function (n) { (function (n) {
'use strict'; 'use strict';
......
...@@ -2,13 +2,8 @@ ...@@ -2,13 +2,8 @@
* @author Rafael Ostertag <rafael.ostertag@math.uzh.ch> * @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
*/ */
if (!QfqNS) { var QfqNS = QfqNS || {};
var QfqNS = {}; QfqNS.Element = QfqNS.Element || {};
}
if (!QfqNS.Element) {
QfqNS.Element = {};
}
(function (n) { (function (n) {
'use strict'; 'use strict';
......
...@@ -3,14 +3,8 @@ ...@@ -3,14 +3,8 @@
*/ */
/* global $ */ /* global $ */
var QfqNS = QfqNS || {};
if (!QfqNS) { QfqNS.Element = QfqNS.Element || {};
var QfqNS = {};
}
if (!QfqNS.Element) {
QfqNS.Element = {};
}
(function (n) { (function (n) {
'use strict'; 'use strict';
......
...@@ -2,13 +2,8 @@ ...@@ -2,13 +2,8 @@
* @author Rafael Ostertag <rafael.ostertag@math.uzh.ch> * @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
*/ */
if (!QfqNS) { var QfqNS = QfqNS || {};
var QfqNS = {}; QfqNS.Element = QfqNS.Element || {};
}
if (!QfqNS.Element) {
QfqNS.Element = {};
}
(function (n) { (function (n) {
'use strict'; 'use strict';
......
...@@ -2,14 +2,8 @@ ...@@ -2,14 +2,8 @@
* @author Rafael Ostertag <rafael.ostertag@math.uzh.ch> * @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
*/ */
var QfqNS = QfqNS || {};
if (!QfqNS) { QfqNS.Element = QfqNS.Element || {};
var QfqNS = {};
}
if (!QfqNS.Element) {
QfqNS.Element = {};
}
(function (n) { (function (n) {
'use strict'; 'use strict';
......
...@@ -3,10 +3,12 @@ ...@@ -3,10 +3,12 @@
*/ */
/* global $ */ /* global $ */
/* global EventEmitter */
if (!QfqNS) { /* @depend QfqEvents.js */
var QfqNS = {};
}
var QfqNS = QfqNS || {};
(function (n) { (function (n) {
'use strict'; 'use strict';
...@@ -15,47 +17,12 @@ if (!QfqNS) { ...@@ -15,47 +17,12 @@ if (!QfqNS) {
this.formSelector = formSelector; this.formSelector = formSelector;
this.targetUrl = targetUrl; this.targetUrl = targetUrl;
this.sip = sip; this.sip = sip;
this.eventEmitter = new EventEmitter();
// 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.setupOnChangeHandler(); this.setupOnChangeHandler();
}; };
/** n.FileUpload.prototype.on = n.EventEmitter.onMixin;
* @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);
};
/** /**
* *
...@@ -70,7 +37,7 @@ if (!QfqNS) { ...@@ -70,7 +37,7 @@ if (!QfqNS) {
* @param event * @param event
*/ */
n.FileUpload.prototype.performFileUpload = function (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); var data = this.prepareData(event.target);
...@@ -111,8 +78,12 @@ if (!QfqNS) { ...@@ -111,8 +78,12 @@ if (!QfqNS) {
*/ */
n.FileUpload.prototype.ajaxSuccessHandler = function (uploadTriggeredBy, data, textStatus, jqXHR) { n.FileUpload.prototype.ajaxSuccessHandler = function (uploadTriggeredBy, data, textStatus, jqXHR) {
this.fileUploadSuccessCallbacks.call(uploadTriggeredBy, data, textStatus); var eventData = n.EventEmitter.makePayload(uploadTriggeredBy, data, {
this.fileUploadEndCallbacks.call(uploadTriggeredBy); textStatus: textStatus,
jqXHR: jqXHR
});
this.eventEmitter.emitEvent('fileupload.upload.successful', eventData);
this.eventEmitter.emitEvent('fileupload.ended', eventData);
}; };
/** /**
...@@ -122,8 +93,13 @@ if (!QfqNS) { ...@@ -122,8 +93,13 @@ if (!QfqNS) {
* @param errorThrown * @param errorThrown
*/ */
n.FileUpload.prototype.ajaxErrorHandler = function (uploadTriggeredBy, jqXHR, textStatus, errorThrown) { n.FileUpload.prototype.ajaxErrorHandler = function (uploadTriggeredBy, jqXHR, textStatus, errorThrown) {
this.fileUploadErrorCallbacks.call(uploadTriggeredBy, textStatus, errorThrown); var eventData = n.EventEmitter.makePayload(uploadTriggeredBy, null, {
this.fileUploadEndCallbacks.call(uploadTriggeredBy); textStatus: textStatus,
errorThrown: errorThrown,
jqXHR: jqXHR
});
this.eventEmitter.emitEvent('fileupload.upload.failed', eventData);
this.eventEmitter.emitEvent('fileupload.ended', eventData);
}; };
......
...@@ -3,27 +3,23 @@ ...@@ -3,27 +3,23 @@
*/ */
/* global $ */ /* global $ */
/* global EventEmitter */
/* @depend QfqEvents.js */
if (!QfqNS) { var QfqNS = QfqNS || {};
var QfqNS = {};
}
(function (n) { (function (n) {
'use strict'; 'use strict';
n.Form = function (formId) { n.Form = function (formId) {
this.formId = formId; this.formId = formId;
this.eventEmitter = new EventEmitter();
if (!document.forms[this.formId]) { if (!document.forms[this.formId]) {
throw new Error("Form '" + formId + "' does not exist."); throw new Error("Form '" + formId + "' does not exist.");
} }
this.formChanged = false; 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 = $(document.forms[this.formId]);
this.$form.on("change", this.changeHandler.bind(this)); this.$form.on("change", this.changeHandler.bind(this));
...@@ -32,6 +28,8 @@ if (!QfqNS) { ...@@ -32,6 +28,8 @@ if (!QfqNS) {