diff -r efd9c589177a -r c0b4a8b5a012 toolkit/javascript/nco/relations.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/toolkit/javascript/nco/relations.js Thu Apr 10 14:20:23 2014 +0200 @@ -0,0 +1,213 @@ +function Relations() { + this.items = {}; +} + +Relations.prototype = { + constructor: Relations, + + /** + * Add an element to the dictionnary under the given name. + * + * @param {String} id: identifier for the item + * @param {Object} element: item to register + * + * @returns {Connector}: inserted element wrapped with a Connector + */ + add: function(id, element) { + return this.items[id] = new Connector(element, id, this); + }, + + remove: function(id) { + + }, + + /** + * Gets the wanted item + * + * @param {String} id: item name + * + * @returns {Connector}: the wanted item, wrapped in a selector + */ + get: function(id) { + return this.items[id]; + }, + + /** + * Executes all the registered actions for a given element and a given event. + * + * First, if the required item is frozen, nothing is executed. + * Then, it checks every observer to see if they are locked, otherwise, their + * action is performed. + * + * @param {String} id: id of the element activated + * @param {String} event: name of the event activated + * @param eventParameters: parameters passed by the event raised + * + * @returns: null + */ + execute: function(id, event, eventParameters) { + var item = this.get(id); + if (!item.isFrozen()) { + var functions = item.listenedEvents[event]; + for(var i =0; i