334 /* IriSP.Model.Reference handles references between elements |
334 /* IriSP.Model.Reference handles references between elements |
335 */ |
335 */ |
336 |
336 |
337 IriSP.Model.Reference = function(_source, _idRef) { |
337 IriSP.Model.Reference = function(_source, _idRef) { |
338 this.source = _source; |
338 this.source = _source; |
|
339 this.id = _idRef; |
339 if (typeof _idRef === "object") { |
340 if (typeof _idRef === "object") { |
340 this.isList = true; |
341 this.isList = true; |
341 this.id = IriSP._(_idRef).map(function(_id) { |
|
342 return _source.getNamespaced(_id).fullname; |
|
343 }); |
|
344 } else { |
342 } else { |
345 this.isList = false; |
343 this.isList = false; |
346 this.id = _source.getNamespaced(_idRef).fullname; |
|
347 } |
344 } |
348 this.refresh(); |
345 this.refresh(); |
349 } |
346 } |
350 |
347 |
351 IriSP.Model.Reference.prototype.refresh = function() { |
348 IriSP.Model.Reference.prototype.refresh = function() { |
382 } |
379 } |
383 if (typeof _id === "undefined" || !_id) { |
380 if (typeof _id === "undefined" || !_id) { |
384 _id = IriSP.Model.getUID(); |
381 _id = IriSP.Model.getUID(); |
385 } |
382 } |
386 this.source = _source; |
383 this.source = _source; |
387 this.namespacedId = _source.getNamespaced(_id) |
384 this.id = _id; |
388 this.id = this.namespacedId.fullname; |
|
389 this.title = ""; |
385 this.title = ""; |
390 this.description = ""; |
386 this.description = ""; |
391 this.source.directory.addElement(this); |
387 this.source.directory.addElement(this); |
392 } |
388 } |
393 |
389 |
523 } |
519 } |
524 |
520 |
525 /* */ |
521 /* */ |
526 |
522 |
527 IriSP.Model.MashedAnnotation = function(_mashup, _annotation) { |
523 IriSP.Model.MashedAnnotation = function(_mashup, _annotation) { |
528 IriSP.Model.Element.call(this, _mashup.namespacedId.name + "_" + _annotation.namespacedId.name, _annotation.source); |
524 IriSP.Model.Element.call(this, _mashup.id + "_" + _annotation.id, _annotation.source); |
529 this.elementType = 'mashedAnnotation'; |
525 this.elementType = 'mashedAnnotation'; |
530 this.annotation = _annotation; |
526 this.annotation = _annotation; |
531 this.begin = new IriSP.Model.Time(_mashup.duration); |
527 this.begin = new IriSP.Model.Time(_mashup.duration); |
532 this.end = new IriSP.Model.Time(_mashup.duration + _annotation.getDuration()); |
528 this.end = new IriSP.Model.Time(_mashup.duration + _annotation.getDuration()); |
533 this.title = this.annotation.title; |
529 this.title = this.annotation.title; |
627 IriSP._(_config).forEach(function(_v, _k) { |
623 IriSP._(_config).forEach(function(_v, _k) { |
628 _this[_k] = _v; |
624 _this[_k] = _v; |
629 }) |
625 }) |
630 this.callbackQueue = []; |
626 this.callbackQueue = []; |
631 this.contents = {}; |
627 this.contents = {}; |
632 if (typeof this.namespace === "undefined") { |
|
633 this.namespace = "metadataplayer"; |
|
634 } else { |
|
635 if (typeof this.namespaceUrl === "undefined" && typeof this.url !== "undefined") { |
|
636 var _matches = this.url.match(/(^[^?&]+|[^?&][a-zA-Z0-9_%=?]+)/g), |
|
637 _url = _matches[0]; |
|
638 if (_matches.length > 1) { |
|
639 _matches = IriSP._(_matches.slice(1)).reject(function(_txt) { |
|
640 return /\?$/.test(_txt); |
|
641 }); |
|
642 } |
|
643 if (_matches.length > 0) { |
|
644 _url += '?' + _matches.join('&'); |
|
645 } |
|
646 this.namespaceUrl = _url; |
|
647 } |
|
648 } |
|
649 if (typeof this.namespaceUrl === "undefined") { |
|
650 this.namespaceUrl = "http://ldt.iri.centrepompidou.fr/"; |
|
651 } |
|
652 this.directory.addNamespace(this.namespace, this.namespaceUrl); |
|
653 this.get(); |
628 this.get(); |
654 } |
|
655 } |
|
656 |
|
657 IriSP.Model.Source.prototype.getNamespaced = function(_id) { |
|
658 var _tab = _id.split(':'); |
|
659 if (_tab.length > 1) { |
|
660 return { |
|
661 namespace : _tab[0], |
|
662 name : _tab[1], |
|
663 fullname : _id |
|
664 } |
|
665 } else { |
|
666 return { |
|
667 namespace : this.namespace, |
|
668 name : _id, |
|
669 fullname : this.namespace + ':' + _id |
|
670 } |
|
671 } |
|
672 } |
|
673 |
|
674 IriSP.Model.Source.prototype.unNamespace = function(_id) { |
|
675 if (typeof _id !== "undefined") { |
|
676 return _id.replace(this.namespace + ':', ''); |
|
677 } |
629 } |
678 } |
630 } |
679 |
631 |
680 IriSP.Model.Source.prototype.addList = function(_listId, _contents) { |
632 IriSP.Model.Source.prototype.addList = function(_listId, _contents) { |
681 if (typeof this.contents[_listId] === "undefined") { |
633 if (typeof this.contents[_listId] === "undefined") { |
701 _callback.call(_this, _value, _key); |
653 _callback.call(_this, _value, _key); |
702 }) |
654 }) |
703 } |
655 } |
704 |
656 |
705 IriSP.Model.Source.prototype.getElement = function(_elId) { |
657 IriSP.Model.Source.prototype.getElement = function(_elId) { |
706 return this.directory.getElement(this.getNamespaced(_elId).fullname); |
658 return this.directory.getElement(_elId); |
707 } |
659 } |
708 |
660 |
709 IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) { |
661 IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) { |
710 if (typeof _idRef !== "undefined") { |
662 if (typeof _idRef !== "undefined") { |
711 this.currentMedia = this.getElement(_idRef); |
663 this.currentMedia = this.getElement(_idRef); |
714 |
666 |
715 IriSP.Model.Source.prototype.setDefaultCurrentMedia = function() { |
667 IriSP.Model.Source.prototype.setDefaultCurrentMedia = function() { |
716 if (typeof this.currentMedia === "undefined" && this.getMedias().length) { |
668 if (typeof this.currentMedia === "undefined" && this.getMedias().length) { |
717 this.currentMedia = this.getMedias()[0]; |
669 this.currentMedia = this.getMedias()[0]; |
718 } |
670 } |
719 } |
|
720 |
|
721 IriSP.Model.Source.prototype.listNamespaces = function(_excludeSelf) { |
|
722 var _this = this, |
|
723 _nsls = [], |
|
724 _excludeSelf = (typeof _excludeSelf !== "undefined" && _excludeSelf); |
|
725 this.forEach(function(_list) { |
|
726 IriSP._(_list).forEach(function(_el) { |
|
727 var _ns = _el.id.replace(/:.*$/,''); |
|
728 if (IriSP._(_nsls).indexOf(_ns) === -1 && (!_excludeSelf || _ns !== _this.namespace)) { |
|
729 _nsls.push(_ns); |
|
730 } |
|
731 }) |
|
732 }); |
|
733 return _nsls; |
|
734 } |
671 } |
735 |
672 |
736 IriSP.Model.Source.prototype.get = function() { |
673 IriSP.Model.Source.prototype.get = function() { |
737 this.status = IriSP.Model._SOURCE_STATUS_WAITING; |
674 this.status = IriSP.Model._SOURCE_STATUS_WAITING; |
738 this.handleCallbacks(); |
675 this.handleCallbacks(); |
837 /* */ |
774 /* */ |
838 |
775 |
839 IriSP.Model.Directory = function() { |
776 IriSP.Model.Directory = function() { |
840 this.remoteSources = {}; |
777 this.remoteSources = {}; |
841 this.elements = {}; |
778 this.elements = {}; |
842 this.namespaces = {}; |
|
843 } |
|
844 |
|
845 IriSP.Model.Directory.prototype.addNamespace = function(_namespace, _url) { |
|
846 this.namespaces[_namespace] = _url; |
|
847 } |
779 } |
848 |
780 |
849 IriSP.Model.Directory.prototype.remoteSource = function(_properties) { |
781 IriSP.Model.Directory.prototype.remoteSource = function(_properties) { |
850 var _config = IriSP._({ directory: this }).extend(_properties); |
782 var _config = IriSP._({ directory: this }).extend(_properties); |
851 if (typeof this.remoteSources[_properties.url] === "undefined") { |
783 if (typeof this.remoteSources[_properties.url] === "undefined") { |