equal
deleted
inserted
replaced
84 */ |
84 */ |
85 IriSP.Model.List = function(_directory) { |
85 IriSP.Model.List = function(_directory) { |
86 Array.call(this); |
86 Array.call(this); |
87 this.directory = _directory; |
87 this.directory = _directory; |
88 this.idIndex = []; |
88 this.idIndex = []; |
|
89 this.__events = {}; |
89 if (typeof _directory == "undefined") { |
90 if (typeof _directory == "undefined") { |
90 console.trace(); |
91 console.trace(); |
91 throw "Error : new IriSP.Model.List(directory): directory is undefined"; |
92 throw "Error : new IriSP.Model.List(directory): directory is undefined"; |
92 } |
93 } |
93 } |
94 } |
254 IriSP.Model.List.prototype.removeElements = function(_list, _deleteFromDirectory) { |
255 IriSP.Model.List.prototype.removeElements = function(_list, _deleteFromDirectory) { |
255 var _deleteFromDirectory = _deleteFromDirectory || false, |
256 var _deleteFromDirectory = _deleteFromDirectory || false, |
256 _this = this; |
257 _this = this; |
257 IriSP._(_list).forEach(function(_el) { |
258 IriSP._(_list).forEach(function(_el) { |
258 _this.removeElement(_el); |
259 _this.removeElement(_el); |
|
260 }); |
|
261 } |
|
262 |
|
263 IriSP.Model.List.prototype.on = function(_event, _callback) { |
|
264 if (typeof this.__events[_event] === "undefined") { |
|
265 this.__events[_event] = []; |
|
266 } |
|
267 this.__events[_event].push(_callback); |
|
268 } |
|
269 |
|
270 IriSP.Model.List.prototype.trigger = function(_event, _data) { |
|
271 var _list = this; |
|
272 IriSP._(this.__events[_event]).each(function(_callback) { |
|
273 _callback.call(_list, _data); |
259 }); |
274 }); |
260 } |
275 } |
261 |
276 |
262 /* A simple time management object, that helps converting millisecs to seconds and strings, |
277 /* A simple time management object, that helps converting millisecs to seconds and strings, |
263 * without the clumsiness of the original Date object. |
278 * without the clumsiness of the original Date object. |
381 } |
396 } |
382 this.source = _source; |
397 this.source = _source; |
383 this.id = _id; |
398 this.id = _id; |
384 this.title = ""; |
399 this.title = ""; |
385 this.description = ""; |
400 this.description = ""; |
|
401 this.__events = {} |
386 this.source.directory.addElement(this); |
402 this.source.directory.addElement(this); |
387 } |
403 } |
388 |
404 |
389 IriSP.Model.Element.prototype.toString = function() { |
405 IriSP.Model.Element.prototype.toString = function() { |
390 return this.elementType + (this.elementType !== 'element' ? ', id=' + this.id + ', title="' + this.title + '"' : ''); |
406 return this.elementType + (this.elementType !== 'element' ? ', id=' + this.id + ', title="' + this.title + '"' : ''); |
404 _global = (typeof _global !== "undefined" && _global); |
420 _global = (typeof _global !== "undefined" && _global); |
405 var _this = this; |
421 var _this = this; |
406 return this.source.getList(_elementType, _global).filter(function(_el) { |
422 return this.source.getList(_elementType, _global).filter(function(_el) { |
407 var _ref = _el[_this.elementType]; |
423 var _ref = _el[_this.elementType]; |
408 return _ref.isOrHasId(_this.id); |
424 return _ref.isOrHasId(_this.id); |
|
425 }); |
|
426 } |
|
427 |
|
428 IriSP.Model.Element.prototype.on = function(_event, _callback) { |
|
429 if (typeof this.__events[_event] === "undefined") { |
|
430 this.__events[_event] = []; |
|
431 } |
|
432 this.__events[_event].push(_callback); |
|
433 } |
|
434 |
|
435 IriSP.Model.Element.prototype.trigger = function(_event, _data) { |
|
436 var _element = this; |
|
437 IriSP._(this.__events[_event]).each(function(_callback) { |
|
438 _callback.call(_element, _data); |
409 }); |
439 }); |
410 } |
440 } |
411 |
441 |
412 /* */ |
442 /* */ |
413 |
443 |