Restructure actions and events

This commit is contained in:
Dennis Eichhorn 2017-04-14 14:03:03 +02:00
parent 4735f7cef5
commit 0756f7e3e1
2 changed files with 9 additions and 8 deletions

View File

@ -113,7 +113,7 @@
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Event.EventManager.prototype.trigger = function (group, id)
jsOMS.Event.EventManager.prototype.trigger = function (group, id, data)
{
id = typeof id !== 'undefined' ? id : 0;
@ -126,7 +126,7 @@
}
if (!this.hasOutstanding(group)) {
this.callbacks[group].func();
this.callbacks[group].func(data);
if (this.callbacks[group].remove) {
this.detach(group);

View File

@ -75,10 +75,10 @@
actionLength = listeners[i].action.length;
for (let j = 1; j < actionLength; j++) {
this.app.eventManager.attach(e.id + listeners[i].action[j - 1].type, function ()
this.app.eventManager.attach(e.id + listeners[i].action[j - 1].type, function (data)
{
// todo: how to pass result from previous action to next action?!
self.runAction(e, listeners[i].action[j]);
self.runAction(e, listeners[i].action[j], data);
}, false, true);
// todo: handle onload action right after registering everything. this will be used for onload api calls in order to get content such as lists or models. Maybe in the main application after registering a invoke('onload') should be called if the application wants to execute the onload elements
// todo: right now one event type can only exist once... needs fixing!!!
@ -104,21 +104,22 @@
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.ActionManager.prototype.runAction = function (e, action)
jsOMS.UI.ActionManager.prototype.runAction = function (e, action, data)
{
const self = this;
console.log(action.type);
console.log(this.actions);
if (!this.actions.hasOwnProperty(action.type)) {
console.log('Undefined action ' + action.type);
return;
}
this.actions[action.type](action, function ()
action.data = data;
this.actions[action.type](action, function (data)
{
self.app.eventManager.trigger(e.id + action.type, e.id);
self.app.eventManager.trigger(e.id + action.type, e.id, data);
});
};