diff -r 693c282aa4e9 -r b58eda0ce5df src/obsolete-files/model-namespaced.js --- a/src/obsolete-files/model-namespaced.js Wed Sep 05 11:03:20 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,877 +0,0 @@ -/* model.js is where data is stored in a standard form, whatever the serializer */ - -IriSP.Model = { - _SOURCE_STATUS_EMPTY : 0, - _SOURCE_STATUS_WAITING : 1, - _SOURCE_STATUS_READY : 2, - _ID_AUTO_INCREMENT : 0, - _ID_BASE : (function(_d) { - function pad(n){return n<10 ? '0'+n : n} - function fillrand(n) { - var _res = '' - for (var i=0; i _time; - }); - if (_list.length) { - return _list[0]; - } else { - return undefined; - } -} - -IriSP.Model.Mashup.prototype.getMediaAtTime = function(_time) { - var _annotation = this.getAnnotationAtTime(_time); - if (typeof _annotation !== "undefined") { - return _annotation.getMedia(); - } else { - return undefined; - } -} - -/* */ - -IriSP.Model.Source = function(_config) { - this.status = IriSP.Model._SOURCE_STATUS_EMPTY; - if (typeof _config !== "undefined") { - var _this = this; - IriSP._(_config).forEach(function(_v, _k) { - _this[_k] = _v; - }) - this.callbackQueue = []; - this.contents = {}; - if (typeof this.namespace === "undefined") { - this.namespace = "metadataplayer"; - } else { - if (typeof this.namespaceUrl === "undefined" && typeof this.url !== "undefined") { - var _matches = this.url.match(/(^[^?&]+|[^?&][a-zA-Z0-9_%=?]+)/g), - _url = _matches[0]; - if (_matches.length > 1) { - _matches = IriSP._(_matches.slice(1)).reject(function(_txt) { - return /\?$/.test(_txt); - }); - } - if (_matches.length > 0) { - _url += '?' + _matches.join('&'); - } - this.namespaceUrl = _url; - } - } - if (typeof this.namespaceUrl === "undefined") { - this.namespaceUrl = "http://ldt.iri.centrepompidou.fr/"; - } - this.directory.addNamespace(this.namespace, this.namespaceUrl); - this.get(); - } -} - -IriSP.Model.Source.prototype.getNamespaced = function(_id) { - var _tab = _id.split(':'); - if (_tab.length > 1) { - return { - namespace : _tab[0], - name : _tab[1], - fullname : _id - } - } else { - return { - namespace : this.namespace, - name : _id, - fullname : this.namespace + ':' + _id - } - } -} - -IriSP.Model.Source.prototype.unNamespace = function(_id) { - if (typeof _id !== "undefined") { - return _id.replace(this.namespace + ':', ''); - } -} - -IriSP.Model.Source.prototype.addList = function(_listId, _contents) { - if (typeof this.contents[_listId] === "undefined") { - this.contents[_listId] = new IriSP.Model.List(this.directory); - } - this.contents[_listId].addElements(_contents); -} - -IriSP.Model.Source.prototype.getList = function(_listId, _global) { - _global = (typeof _global !== "undefined" && _global); - if (_global || typeof this.contents[_listId] === "undefined") { - return this.directory.getGlobalList().filter(function(_e) { - return (_e.elementType === _listId); - }); - } else { - return this.contents[_listId]; - } -} - -IriSP.Model.Source.prototype.forEach = function(_callback) { - var _this = this; - IriSP._(this.contents).forEach(function(_value, _key) { - _callback.call(_this, _value, _key); - }) -} - -IriSP.Model.Source.prototype.getElement = function(_elId) { - return this.directory.getElement(this.getNamespaced(_elId).fullname); -} - -IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) { - if (typeof _idRef !== "undefined") { - this.currentMedia = this.getElement(_idRef); - } -} - -IriSP.Model.Source.prototype.setDefaultCurrentMedia = function() { - if (typeof this.currentMedia === "undefined" && this.getMedias().length) { - this.currentMedia = this.getMedias()[0]; - } -} - -IriSP.Model.Source.prototype.listNamespaces = function(_excludeSelf) { - var _this = this, - _nsls = [], - _excludeSelf = (typeof _excludeSelf !== "undefined" && _excludeSelf); - this.forEach(function(_list) { - IriSP._(_list).forEach(function(_el) { - var _ns = _el.id.replace(/:.*$/,''); - if (IriSP._(_nsls).indexOf(_ns) === -1 && (!_excludeSelf || _ns !== _this.namespace)) { - _nsls.push(_ns); - } - }) - }); - return _nsls; -} - -IriSP.Model.Source.prototype.get = function() { - this.status = IriSP.Model._SOURCE_STATUS_WAITING; - this.handleCallbacks(); -} - -/* We defer the callbacks calls so they execute after the queue is cleared */ -IriSP.Model.Source.prototype.deferCallback = function(_callback) { - var _this = this; - IriSP._.defer(function() { - _callback.call(_this); - }); -} - -IriSP.Model.Source.prototype.handleCallbacks = function() { - this.status = IriSP.Model._SOURCE_STATUS_READY; - while (this.callbackQueue.length) { - this.deferCallback(this.callbackQueue.splice(0,1)[0]); - } -} -IriSP.Model.Source.prototype.onLoad = function(_callback) { - if (this.status === IriSP.Model._SOURCE_STATUS_READY) { - this.deferCallback(_callback); - } else { - this.callbackQueue.push(_callback); - } -} - -IriSP.Model.Source.prototype.serialize = function() { - return this.serializer.serialize(this); -} - -IriSP.Model.Source.prototype.deSerialize = function(_data) { - this.serializer.deSerialize(_data, this); -} - -IriSP.Model.Source.prototype.getAnnotations = function(_global) { - _global = (typeof _global !== "undefined" && _global); - return this.getList("annotation", _global); -} - -IriSP.Model.Source.prototype.getMedias = function(_global) { - _global = (typeof _global !== "undefined" && _global); - return this.getList("media", _global); -} - -IriSP.Model.Source.prototype.getTags = function(_global) { - _global = (typeof _global !== "undefined" && _global); - return this.getList("tag", _global); -} - -IriSP.Model.Source.prototype.getMashups = function(_global) { - _global = (typeof _global !== "undefined" && _global); - return this.getList("mashup", _global); -} - -IriSP.Model.Source.prototype.getAnnotationTypes = function(_global) { - _global = (typeof _global !== "undefined" && _global); - return this.getList("annotationType", _global); -} - -IriSP.Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) { - _global = (typeof _global !== "undefined" && _global); - var _res = new IriSP.Model.List(this.directory), - _annTypes = this.getAnnotationTypes(_global).searchByTitle(_title); - _annTypes.forEach(function(_annType) { - _res.addElements(_annType.getAnnotations(_global)); - }) - return _res; -} - -IriSP.Model.Source.prototype.getDuration = function() { - var _m = this.currentMedia; - if (typeof _m !== "undefined") { - return this.currentMedia.duration; - } -} - -IriSP.Model.Source.prototype.merge = function(_source) { - var _this = this; - _source.forEach(function(_value, _key) { - _this.getList(_key).addElements(_value); - }); -} - -/* */ - -IriSP.Model.RemoteSource = function(_config) { - IriSP.Model.Source.call(this, _config); -} - -IriSP.Model.RemoteSource.prototype = new IriSP.Model.Source(); - -IriSP.Model.RemoteSource.prototype.get = function() { - this.status = IriSP.Model._SOURCE_STATUS_WAITING; - var _this = this; - this.serializer.loadData(this.url, function(_result) { - _this.deSerialize(_result); - _this.handleCallbacks(); - }); -} - -/* */ - -IriSP.Model.Directory = function() { - this.remoteSources = {}; - this.elements = {}; - this.namespaces = {}; -} - -IriSP.Model.Directory.prototype.addNamespace = function(_namespace, _url) { - this.namespaces[_namespace] = _url; -} - -IriSP.Model.Directory.prototype.remoteSource = function(_properties) { - var _config = IriSP._({ directory: this }).extend(_properties); - if (typeof this.remoteSources[_properties.url] === "undefined") { - this.remoteSources[_properties.url] = new IriSP.Model.RemoteSource(_config); - } - return this.remoteSources[_properties.url]; -} - -IriSP.Model.Directory.prototype.newLocalSource = function(_properties) { - var _config = IriSP._({ directory: this }).extend(_properties), - _res = new IriSP.Model.Source(_config); - return _res; -} - -IriSP.Model.Directory.prototype.getElement = function(_id) { - return this.elements[_id]; -} - -IriSP.Model.Directory.prototype.addElement = function(_element) { - this.elements[_element.id] = _element; -} - -IriSP.Model.Directory.prototype.getGlobalList = function() { - var _res = new IriSP.Model.List(this); - _res.addIds(IriSP._(this.elements).keys()); - return _res; -} - -/* */