diff -r 930e6ee2dca1 -r d0d3a9369f84 web/res/metadataplayer/LdtPlayer-core.js --- a/web/res/metadataplayer/LdtPlayer-core.js Thu Nov 15 13:12:29 2012 +0100 +++ b/web/res/metadataplayer/LdtPlayer-core.js Wed Nov 28 13:19:48 2012 +0100 @@ -124,12 +124,12 @@ } IriSP.Metadataplayer.prototype.loadMetadata = function(_metadataInfo) { + if (_metadataInfo.elementType === "source") { + return _metadataInfo; + } if (typeof _metadataInfo.serializer === "undefined" && typeof _metadataInfo.format !== "undefined") { _metadataInfo.serializer = IriSP.serializers[_metadataInfo.format]; } - if (typeof _metadataInfo.url === "undefined" && typeof _metadataInfo.src !== "undefined") { - _metadataInfo.url = _metadataInfo.src; - } if (typeof _metadataInfo.url !== "undefined" && typeof _metadataInfo.serializer !== "undefined") { return this.sourceManager.remoteSource(_metadataInfo); } else { @@ -235,47 +235,94 @@ /* TODO: Separate Project-specific data from Source */ /* model.js is where data is stored in a standard form, whatever the serializer */ - -IriSP.Model = { +IriSP.Model = (function (ns) { + + function pad(n, x, b) { + b = b || 10; + var s = (x).toString(b); + while (s.length < n) { + s = "0" + s; + } + return s; + } + + function rand16(n) { + return pad(n, Math.floor(Math.random()*Math.pow(16,n)), 16); + } + + var uidbase = rand16(8) + "-" + rand16(4) + "-", uidincrement = Math.floor(Math.random()*0x10000); + + var charsub = [ + [ 'a', 'á', 'à', 'â', 'ä' ], + [ 'c', 'ç' ], + [ 'e', 'é', 'è', 'ê', 'ë' ], + [ 'i', 'í', 'ì', 'î', 'ï' ], + [ 'o', 'ó', 'ò', 'ô', 'ö' ] + ]; + + var removeChars = [ + String.fromCharCode(768), String.fromCharCode(769), String.fromCharCode(770), String.fromCharCode(771), String.fromCharCode(807), + "{", "}", "(", ")", "[", "]", "【", "】", "、", "・", "‥", "。", "「", "」", "『", "』", "〜", ":", "!", "?", " ", + ",", " ", ";", "(", ")", ".", "*", "+", "\\", "?", "|", "{", "}", "[", "]", "^", "#", "/" + ] + +var 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) && _a.playing }).forEach(function(_a) { _a.playing = false; _a.trigger("leave"); + _this.trigger("leave-annotation",_a); }); _this.getAnnotations().filter(function(_a) { return _a.begin <= _time && _a.end > _time && !_a.playing }).forEach(function(_a) { _a.playing = true; _a.trigger("enter"); + _this.trigger("enter-annotation",_a); }); }); } -IriSP.Model.Media.prototype = new IriSP.Model.Element(); +Model.Playable.prototype = new Model.Element(); + +Model.Playable.prototype.getCurrentTime = function() { + return this.currentTime; +} + +Model.Playable.prototype.getVolume = function() { + return this.volume; +} + +Model.Playable.prototype.getPaused = function() { + return this.paused; +} + +Model.Playable.prototype.getMuted = function() { + return this.muted; +} + +Model.Playable.prototype.setCurrentTime = function(_time) { + this.trigger("setcurrenttime",_time); +} + +Model.Playable.prototype.setVolume = function(_vol) { + this.trigger("setvolume",_vol); +} + +Model.Playable.prototype.setMuted = function(_muted) { + this.trigger("setmuted",_muted); +} + +Model.Playable.prototype.play = function() { + this.trigger("setplay"); +} + +Model.Playable.prototype.pause = function() { + this.trigger("setpause"); +} + +Model.Playable.prototype.show = function() {} + +Model.Playable.prototype.hide = function() {} + +/* */ + +Model.Media = function(_id, _source) { + Model.Playable.call(this, _id, _source); + this.elementType = 'media'; + this.duration = new Model.Time(); + this.video = ''; + var _this = this; +} + +Model.Media.prototype = new Model.Playable(); /* Default functions to be overriden by players */ - -IriSP.Model.Media.prototype.getCurrentTime = function() { return new IriSP.Model.Time(0); } - -IriSP.Model.Media.prototype.getVolume = function() { return .5; } - -IriSP.Model.Media.prototype.getPaused = function() { return true; } - -IriSP.Model.Media.prototype.getMuted = function() { return false; } - -IriSP.Model.Media.prototype.setCurrentTime - = IriSP.Model.Media.prototype.setVolume - = IriSP.Model.Media.prototype.setMuted - = IriSP.Model.Media.prototype.play - = IriSP.Model.Media.prototype.pause - = function() {} -IriSP.Model.Media.prototype.setDuration = function(_durationMs) { +Model.Media.prototype.setDuration = function(_durationMs) { this.duration.setMilliseconds(_durationMs); } -IriSP.Model.Media.prototype.getAnnotations = function() { +Model.Media.prototype.getAnnotations = function() { return this.getRelated("annotation"); } -IriSP.Model.Media.prototype.getAnnotationsByTypeTitle = function(_title) { +Model.Media.prototype.getAnnotationsByTypeTitle = function(_title) { var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); if (_annTypes.length) { return this.getAnnotations().filter(function(_annotation) { - return IriSP._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; + return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; }); } else { - return new IriSP.Model.List(this.source.directory) + return new Model.List(this.source.directory) } } /* */ -IriSP.Model.Tag = function(_id, _source) { - IriSP.Model.Element.call(this, _id, _source); +Model.Tag = function(_id, _source) { + Model.Element.call(this, _id, _source); this.elementType = 'tag'; } -IriSP.Model.Tag.prototype = new IriSP.Model.Element(); +Model.Tag.prototype = new Model.Element(); -IriSP.Model.Tag.prototype.getAnnotations = function() { +Model.Tag.prototype.getAnnotations = function() { return this.getRelated("annotation"); } /* */ - -IriSP.Model.AnnotationType = function(_id, _source) { - IriSP.Model.Element.call(this, _id, _source); +Model.AnnotationType = function(_id, _source) { + Model.Element.call(this, _id, _source); this.elementType = 'annotationType'; } -IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element(); +Model.AnnotationType.prototype = new Model.Element(); -IriSP.Model.AnnotationType.prototype.getAnnotations = function() { +Model.AnnotationType.prototype.getAnnotations = function() { return this.getRelated("annotation"); } /* Annotation * */ -IriSP.Model.Annotation = function(_id, _source) { - IriSP.Model.Element.call(this, _id, _source); +Model.Annotation = function(_id, _source) { + Model.Element.call(this, _id, _source); this.elementType = 'annotation'; - this.begin = new IriSP.Model.Time(); - this.end = new IriSP.Model.Time(); + this.begin = new Model.Time(); + this.end = new Model.Time(); + this.tag = new Model.Reference(_source, []); this.playing = false; var _this = this; this.on("click", function() { @@ -776,56 +923,69 @@ }); } -IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null); +Model.Annotation.prototype = new Model.Element(); -IriSP.Model.Annotation.prototype.setBegin = function(_beginMs) { - this.begin.setMilliseconds(_beginMs); +Model.Annotation.prototype.setBegin = function(_beginMs) { + this.begin.setMilliseconds(Math.max(0,_beginMs)); + this.trigger("change-begin"); + if (this.end < this.begin) { + this.setEnd(this.begin); + } } -IriSP.Model.Annotation.prototype.setEnd = function(_beginMs) { - this.end.setMilliseconds(_beginMs); +Model.Annotation.prototype.setEnd = function(_endMs) { + this.end.setMilliseconds(Math.min(_endMs, this.getMedia().duration.milliseconds)); + this.trigger("change-end"); + if (this.end < this.begin) { + this.setBegin(this.end); + } } -IriSP.Model.Annotation.prototype.setMedia = function(_idRef) { +Model.Annotation.prototype.setDuration = function(_durMs) { + this.setEnd(_durMs + this.begin.milliseconds); +} + +Model.Annotation.prototype.setMedia = function(_idRef) { this.setReference("media", _idRef); } -IriSP.Model.Annotation.prototype.getMedia = function() { +Model.Annotation.prototype.getMedia = function() { return this.getReference("media"); } -IriSP.Model.Annotation.prototype.setAnnotationType = function(_idRef) { +Model.Annotation.prototype.setAnnotationType = function(_idRef) { this.setReference("annotationType", _idRef); } -IriSP.Model.Annotation.prototype.getAnnotationType = function() { +Model.Annotation.prototype.getAnnotationType = function() { return this.getReference("annotationType"); } -IriSP.Model.Annotation.prototype.setTags = function(_idRefs) { +Model.Annotation.prototype.setTags = function(_idRefs) { this.setReference("tag", _idRefs); } -IriSP.Model.Annotation.prototype.getTags = function() { +Model.Annotation.prototype.getTags = function() { return this.getReference("tag"); } -IriSP.Model.Annotation.prototype.getTagTexts = function() { +Model.Annotation.prototype.getTagTexts = function() { return this.getTags().getTitles(); } -IriSP.Model.Annotation.prototype.getDuration = function() { - return new IriSP.Model.Time(this.end.milliseconds - this.begin.milliseconds) +Model.Annotation.prototype.getDuration = function() { + return new Model.Time(this.end.milliseconds - this.begin.milliseconds) } /* */ -IriSP.Model.MashedAnnotation = function(_mashup, _annotation) { - IriSP.Model.Element.call(this, _mashup.id + "_" + _annotation.id, _annotation.source); +Model.MashedAnnotation = function(_mashup, _annotation) { + Model.Element.call(this, _mashup.id + "_" + _annotation.id, _annotation.source); this.elementType = 'mashedAnnotation'; this.annotation = _annotation; - this.begin = new IriSP.Model.Time(_mashup.duration); - this.end = new IriSP.Model.Time(_mashup.duration + _annotation.getDuration()); + this.begin = new Model.Time(); + this.end = new Model.Time(); + this.duration = new Model.Time(); this.title = this.annotation.title; this.description = this.annotation.description; this.color = this.annotation.color; @@ -833,100 +993,202 @@ this.on("click", function() { _mashup.setCurrentTime(_this.begin); }); + this.on("enter", function() { + _this.annotation.trigger("enter"); + }); + this.on("leave", function() { + _this.annotation.trigger("leave"); + }); } -IriSP.Model.MashedAnnotation.prototype = new IriSP.Model.Element(null); +Model.MashedAnnotation.prototype = new Model.Element(null); -IriSP.Model.MashedAnnotation.prototype.getMedia = function() { +Model.MashedAnnotation.prototype.getMedia = function() { return this.annotation.getReference("media"); } -IriSP.Model.MashedAnnotation.prototype.getAnnotationType = function() { +Model.MashedAnnotation.prototype.getAnnotationType = function() { return this.annotation.getReference("annotationType"); } -IriSP.Model.MashedAnnotation.prototype.getTags = function() { +Model.MashedAnnotation.prototype.getTags = function() { return this.annotation.getReference("tag"); } -IriSP.Model.MashedAnnotation.prototype.getTagTexts = function() { +Model.MashedAnnotation.prototype.getTagTexts = function() { return this.annotation.getTags().getTitles(); } -IriSP.Model.MashedAnnotation.prototype.getDuration = function() { +Model.MashedAnnotation.prototype.getDuration = function() { return this.annotation.getDuration(); } +Model.MashedAnnotation.prototype.setBegin = function(_begin) { + this.begin.setMilliseconds(_begin); + this.duration.setMilliseconds(this.annotation.getDuration()); + this.end.setMilliseconds(_begin + this.duration); +} + /* */ -IriSP.Model.Mashup = function(_id, _source) { - IriSP.Model.Element.call(this, _id, _source); +Model.Mashup = function(_id, _source) { + Model.Playable.call(this, _id, _source); this.elementType = 'mashup'; - this.duration = new IriSP.Model.Time(); - this.segments = new IriSP.Model.List(_source.directory); - this.medias = new IriSP.Model.List(_source.directory); - var _currentMedia = null; + this.duration = new Model.Time(); + this.segments = new Model.List(_source.directory); + this.loaded = false; var _this = this; - this.on("timeupdate", function(_time) { - _this.getAnnotations().filter(function(_a) { - return (_a.end <= _time || _a.begin > _time) && _a.playing - }).forEach(function(_a) { - _a.playing = false; - _a.trigger("leave"); - }); - _this.getAnnotations().filter(function(_a) { - return _a.begin <= _time && _a.end > _time && !_a.playing - }).forEach(function(_a) { - _a.playing = true; - _a.trigger("enter"); - var _m = _a.getMedia(); - if (_m !== _currentMedia) { - if (_currentMedia) { - _currentMedia.trigger("leave"); - } - _m.trigger("enter"); - _currentMedia = _m; - } - }); + this._updateTimes = function() { + _this.updateTimes(); + _this.trigger("change"); + } + this.on("add", this._updateTimes); + this.on("remove", this._updateTimes); +} + +Model.Mashup.prototype = new Model.Playable(); + +Model.Mashup.prototype.checkLoaded = function() { + var loaded = !!this.segments.length; + this.getMedias().forEach(function(_m) { + loaded = loaded && _m.loaded; + }); + this.loaded = loaded; + if (loaded) { + this.trigger("loadedmetadata"); + } +} + +Model.Mashup.prototype.updateTimes = function() { + var _time = 0; + this.segments.forEach(function(_segment) { + _segment.setBegin(_time); + _time = _segment.end; + }); + this.duration.setMilliseconds(_time); +} + +Model.Mashup.prototype.addAnnotation = function(_annotation, _defer) { + var _mashedAnnotation = new Model.MashedAnnotation(this, _annotation), + _defer = _defer || false; + this.segments.push(_mashedAnnotation); + _annotation.on("change-begin", this._updateTimes); + _annotation.on("change-end", this._updateTimes); + if (!_defer) { + this.trigger("add"); + } +} + +Model.Mashup.prototype.addAnnotationById = function(_elId, _defer) { + var _annotation = this.source.getElement(_elId), + _defer = _defer || false; + if (typeof _annotation !== "undefined") { + this.addAnnotation(_annotation, _defer); + } +} + +Model.Mashup.prototype.addAnnotations = function(_segments) { + var _this = this; + ns._(_segments).forEach(function(_segment) { + _this.addAnnotation(_segment, true); + }); + this.trigger("add"); +} + +Model.Mashup.prototype.addAnnotationsById = function(_segments) { + var _this = this; + ns._(_segments).forEach(function(_segment) { + _this.addAnnotationById(_segment, true); + }); + this.trigger("add"); +} + +Model.Mashup.prototype.removeAnnotation = function(_annotation, _defer) { + var _defer = _defer || false; + _annotation.off("change-begin", this._updateTimes); + _annotation.off("change-end", this._updateTimes); + this.segments.removeId(this.id + "_" + _annotation.id); + if (!_defer) { + this.trigger("remove"); + } +} + +Model.Mashup.prototype.removeAnnotationById = function(_annId, _defer) { + var _defer = _defer || false; + var _annotation = this.source.getElement(_annId); + + if (_annotation) { + this.removeAnnotation(_annotation, _defer); + } + if (!_defer) { + this.trigger("remove"); + } +} + +Model.Mashup.prototype.setAnnotations = function(_segments) { + while (this.segments.length) { + this.removeAnnotation(this.segments[0].annotation, true); + } + this.addAnnotations(_segments); +} + +Model.Mashup.prototype.setAnnotationsById = function(_segments) { + while (this.segments.length) { + this.removeAnnotation(this.segments[0].annotation, true); + } + this.addAnnotationsById(_segments); +} + +Model.Mashup.prototype.hasAnnotation = function(_annotation) { + return !!ns._(this.segments).find(function(_s) { + return _s.annotation === _annotation }); } -IriSP.Model.Mashup.prototype = new IriSP.Model.Element(); +Model.Mashup.prototype.getAnnotation = function(_annotation) { + return ns._(this.segments).find(function(_s) { + return _s.annotation === _annotation + }); +} -IriSP.Model.Mashup.prototype.addSegment = function(_annotation) { - var _mashedAnnotation = new IriSP.Model.MashedAnnotation(this, _annotation); - this.duration.setMilliseconds(_mashedAnnotation.end); - this.segments.push(_mashedAnnotation); - this.medias.push(_annotation.getMedia()); +Model.Mashup.prototype.getAnnotationById = function(_id) { + return ns._(this.segments).find(function(_s) { + return _s.annotation.id === _id + }); +} + +Model.Mashup.prototype.getAnnotations = function() { + return this.segments; } -IriSP.Model.Mashup.prototype.addSegmentById = function(_elId) { - var _annotation = this.source.getElement(_elId); - if (typeof _annotation !== "undefined") { - this.addSegment(_annotation); +Model.Mashup.prototype.getOriginalAnnotations = function() { + var annotations = new Model.List(this.source.directory); + this.segments.forEach(function(_s) { + annotations.push(_s.annotation); + }); + return annotations; +} + +Model.Mashup.prototype.getMedias = function() { + var medias = new Model.List(this.source.directory); + this.segments.forEach(function(_annotation) { + medias.push(_annotation.getMedia()) + }) + return medias; +} + +Model.Mashup.prototype.getAnnotationsByTypeTitle = function(_title) { + var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); + if (_annTypes.length) { + return this.getAnnotations().filter(function(_annotation) { + return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; + }); + } else { + return new Model.List(this.source.directory) } } -IriSP.Model.Mashup.prototype.getAnnotations = function() { - return this.segments; -} - -IriSP.Model.Mashup.prototype.getMedias = function() { - return this.medias; -} - -IriSP.Model.Mashup.prototype.getAnnotationsByTypeTitle = function(_title) { - var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); - if (_annTypes.length) { - return this.getAnnotations().filter(function(_annotation) { - return IriSP._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; - }); - } else { - return new IriSP.Model.List(this.source.directory) - } -} - -IriSP.Model.Mashup.prototype.getAnnotationAtTime = function(_time) { +Model.Mashup.prototype.getAnnotationAtTime = function(_time) { var _list = this.segments.filter(function(_annotation) { return _annotation.begin <= _time && _annotation.end > _time; }); @@ -937,7 +1199,7 @@ } } -IriSP.Model.Mashup.prototype.getMediaAtTime = function(_time) { +Model.Mashup.prototype.getMediaAtTime = function(_time) { var _annotation = this.getAnnotationAtTime(_time); if (typeof _annotation !== "undefined") { return _annotation.getMedia(); @@ -946,30 +1208,15 @@ } } -/* Default functions to be overriden by players */ - -IriSP.Model.Mashup.prototype.getCurrentTime = function() { return new IriSP.Model.Time(0); } - -IriSP.Model.Mashup.prototype.getVolume = function() { return .5; } - -IriSP.Model.Mashup.prototype.getPaused = function() { return true; } - -IriSP.Model.Mashup.prototype.getMuted = function() { return false; } - -IriSP.Model.Mashup.prototype.setCurrentTime - = IriSP.Model.Mashup.prototype.setVolume - = IriSP.Model.Mashup.prototype.setMuted - = IriSP.Model.Mashup.prototype.play - = IriSP.Model.Mashup.prototype.pause - = function() {} - /* */ -IriSP.Model.Source = function(_config) { - this.status = IriSP.Model._SOURCE_STATUS_EMPTY; +Model.Source = function(_config) { + Model.Element.call(this, false, this); + this.status = Model._SOURCE_STATUS_EMPTY; + this.elementType = "source"; if (typeof _config !== "undefined") { var _this = this; - IriSP._(_config).forEach(function(_v, _k) { + ns._(_config).forEach(function(_v, _k) { _this[_k] = _v; }) this.callbackQueue = []; @@ -978,14 +1225,16 @@ } } -IriSP.Model.Source.prototype.addList = function(_listId, _contents) { +Model.Source.prototype = new Model.Element(); + +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] = new Model.List(this.directory); } this.contents[_listId].addElements(_contents); } -IriSP.Model.Source.prototype.getList = function(_listId, _global) { +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) { @@ -996,80 +1245,80 @@ } } -IriSP.Model.Source.prototype.forEach = function(_callback) { +Model.Source.prototype.forEach = function(_callback) { var _this = this; - IriSP._(this.contents).forEach(function(_value, _key) { + ns._(this.contents).forEach(function(_value, _key) { _callback.call(_this, _value, _key); }) } -IriSP.Model.Source.prototype.getElement = function(_elId) { +Model.Source.prototype.getElement = function(_elId) { return this.directory.getElement(_elId); } -IriSP.Model.Source.prototype.get = function() { - this.status = IriSP.Model._SOURCE_STATUS_WAITING; +Model.Source.prototype.get = function() { + this.status = 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) { +Model.Source.prototype.deferCallback = function(_callback) { var _this = this; - IriSP._.defer(function() { + ns._.defer(function() { _callback.call(_this); }); } -IriSP.Model.Source.prototype.handleCallbacks = function() { - this.status = IriSP.Model._SOURCE_STATUS_READY; +Model.Source.prototype.handleCallbacks = function() { + this.status = 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) { +Model.Source.prototype.onLoad = function(_callback) { + if (this.status === Model._SOURCE_STATUS_READY) { this.deferCallback(_callback); } else { this.callbackQueue.push(_callback); } } -IriSP.Model.Source.prototype.serialize = function() { +Model.Source.prototype.serialize = function() { return this.serializer.serialize(this); } -IriSP.Model.Source.prototype.deSerialize = function(_data) { +Model.Source.prototype.deSerialize = function(_data) { this.serializer.deSerialize(_data, this); } -IriSP.Model.Source.prototype.getAnnotations = function(_global) { +Model.Source.prototype.getAnnotations = function(_global) { _global = (typeof _global !== "undefined" && _global); return this.getList("annotation", _global); } -IriSP.Model.Source.prototype.getMedias = function(_global) { +Model.Source.prototype.getMedias = function(_global) { _global = (typeof _global !== "undefined" && _global); return this.getList("media", _global); } -IriSP.Model.Source.prototype.getTags = function(_global) { +Model.Source.prototype.getTags = function(_global) { _global = (typeof _global !== "undefined" && _global); return this.getList("tag", _global); } -IriSP.Model.Source.prototype.getMashups = function(_global) { +Model.Source.prototype.getMashups = function(_global) { _global = (typeof _global !== "undefined" && _global); return this.getList("mashup", _global); } -IriSP.Model.Source.prototype.getAnnotationTypes = function(_global) { +Model.Source.prototype.getAnnotationTypes = function(_global) { _global = (typeof _global !== "undefined" && _global); return this.getList("annotationType", _global); } -IriSP.Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) { +Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) { _global = (typeof _global !== "undefined" && _global); - var _res = new IriSP.Model.List(this.directory), + var _res = new Model.List(this.directory), _annTypes = this.getAnnotationTypes(_global).searchByTitle(_title); _annTypes.forEach(function(_annType) { _res.addElements(_annType.getAnnotations(_global)); @@ -1077,14 +1326,14 @@ return _res; } -IriSP.Model.Source.prototype.getDuration = function() { +Model.Source.prototype.getDuration = function() { var _m = this.currentMedia; if (typeof _m !== "undefined") { return this.currentMedia.duration; } } -IriSP.Model.Source.prototype.getCurrentMedia = function(_opts) { +Model.Source.prototype.getCurrentMedia = function(_opts) { if (typeof this.currentMedia === "undefined") { if (_opts.is_mashup) { var _mashups = this.getMashups(); @@ -1094,14 +1343,14 @@ } else { var _medias = this.getMedias(); if (_medias.length) { - _media = _medias[0]; + this.currentMedia = _medias[0]; } } } return this.currentMedia; } -IriSP.Model.Source.prototype.merge = function(_source) { +Model.Source.prototype.merge = function(_source) { var _this = this; _source.forEach(function(_value, _key) { _this.getList(_key).addElements(_value); @@ -1110,60 +1359,72 @@ /* */ -IriSP.Model.RemoteSource = function(_config) { - IriSP.Model.Source.call(this, _config); +Model.RemoteSource = function(_config) { + Model.Source.call(this, _config); } -IriSP.Model.RemoteSource.prototype = new IriSP.Model.Source(); +Model.RemoteSource.prototype = new 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(); +Model.RemoteSource.prototype.get = function() { + this.status = Model._SOURCE_STATUS_WAITING; + var _this = this, + urlparams = this.url_params || {}, + dataType = (Model.isLocalURL(this.url) ? "json" : "jsonp"); + urlparams.format = dataType; + ns.jQuery.ajax({ + url: this.url, + dataType: dataType, + data: urlparams, + success: function(_result) { + _this.deSerialize(_result); + _this.handleCallbacks(); + } }); } /* */ -IriSP.Model.Directory = function() { +Model.Directory = function() { this.remoteSources = {}; this.elements = {}; } -IriSP.Model.Directory.prototype.remoteSource = function(_properties) { +Model.Directory.prototype.remoteSource = function(_properties) { if (typeof _properties !== "object" || typeof _properties.url === "undefined") { - throw "Error : IriSP.Model.Directory.remoteSource(configuration): configuration.url is undefined"; + throw "Error : Model.Directory.remoteSource(configuration): configuration.url is undefined"; } - var _config = IriSP._({ directory: this }).extend(_properties); - if (typeof this.remoteSources[_properties.url] === "undefined") { - this.remoteSources[_properties.url] = new IriSP.Model.RemoteSource(_config); + var _config = ns._({ directory: this }).extend(_properties); + _config.url_params = _config.url_params || {}; + var _hash = _config.url + "?" + ns.jQuery.param(_config.url_params); + if (typeof this.remoteSources[_hash] === "undefined") { + this.remoteSources[_hash] = new Model.RemoteSource(_config); } - return this.remoteSources[_properties.url]; + return this.remoteSources[_hash]; } -IriSP.Model.Directory.prototype.newLocalSource = function(_properties) { - var _config = IriSP._({ directory: this }).extend(_properties), - _res = new IriSP.Model.Source(_config); +Model.Directory.prototype.newLocalSource = function(_properties) { + var _config = ns._({ directory: this }).extend(_properties), + _res = new Model.Source(_config); return _res; } -IriSP.Model.Directory.prototype.getElement = function(_id) { +Model.Directory.prototype.getElement = function(_id) { return this.elements[_id]; } -IriSP.Model.Directory.prototype.addElement = function(_element) { +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()); +Model.Directory.prototype.getGlobalList = function() { + var _res = new Model.List(this); + _res.addIds(ns._(this.elements).keys()); return _res; } -/* */ +return Model; + +})(IriSP); IriSP.language = 'en'; IriSP.libFiles = { @@ -1222,10 +1483,10 @@ noCss: true, requires: [ "swfObject" ] }, - AutoPlayer: { + AdaptivePlayer: { noCss: true }, - MashupPlayer: { + AutoPlayer: { noCss: true }, AnnotationsList: { @@ -1257,6 +1518,9 @@ }, KnowledgeConcierge: { requires: [ "processing" ] + }, + MultiSegments: { + noCss: true } } @@ -1388,7 +1652,13 @@ } IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() { - return typeof this.annotation_type !== "undefined" && this.annotation_type ? this.media.getAnnotationsByTypeTitle(this.annotation_type) : this.media.getAnnotations(); + if (typeof this.annotation_type === "undefined") { + return this.media.getAnnotations(); + } + if (this.annotation_type.elementType === "annotationType") { + return this.annotation_type.getAnnotations(); + } + return this.media.getAnnotationsByTypeTitle(this.annotation_type); } IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() { @@ -1460,16 +1730,42 @@ } return _res; }, - serializer : function(_data, _source) { - return { + serializer : function(_data, _source, _dest) { + var _res = { id : _data.id, url : _data.video, meta : { - "dc:title" : _data.title, - "dc:description" : _data.description, + "dc:title": _data.title || "", + "dc:description": _data.description || "", + "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), + "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), + "dc:creator" : _data.creator || _source.creator, + "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, "dc:duration" : _data.duration.milliseconds } } + _dest.medias.push(_res); + var _list = { + id: IriSP.Model.getUID(), + meta : { + "dc:title": _data.title || "", + "dc:description": _data.description || "", + "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), + "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), + "dc:creator" : _data.creator || _source.creator, + "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, + "id-ref": _data.id + }, + items: _source.getAnnotationTypes().filter(function(_at) { + return _at.media === _data; + }).map(function(_at) { + return { + "id-ref": _at.id + } + }) + } + _dest.lists.push(_list); + _dest.views[0].contents.push(_data.id); } }, tag : { @@ -1480,13 +1776,19 @@ _res.title = _data.meta["dc:title"]; return _res; }, - serializer : function(_data, _source) { - return { + serializer : function(_data, _source, _dest) { + var _res = { id : _data.id, meta : { - "dc:title" : _data.title + "dc:title": _data.title || "", + "dc:description": _data.description || "", + "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), + "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), + "dc:creator" : _data.creator || _source.creator, + "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, } } + _dest.tags.push(_res); } }, annotationType : { @@ -1497,12 +1799,18 @@ _res.description = _data["dc:description"]; return _res; }, - serializer : function(_data, _source) { - return { + serializer : function(_data, _source, _dest) { + var _res = { id : _data.id, - "dc:title" : _data.title, - "dc:description" : _data.description + "dc:title": _data.title || "", + "dc:description": _data.description || "", + "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), + "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), + "dc:creator" : _data.creator || _source.creator, + "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, } + _dest["annotation-types"].push(_res); + _dest.views[0].annotation_types.push(_data.id); } }, annotation : { @@ -1525,6 +1833,7 @@ _res.setMedia(_data.media); _res.setAnnotationType(_data.meta["id-ref"]); _res.setTags(IriSP._(_data.tags).pluck("id-ref")); + _res.keywords = _res.getTagTexts(); _res.setBegin(_data.begin); _res.setEnd(_data.end); _res.creator = _data.meta["dc:creator"] || ""; @@ -1537,22 +1846,29 @@ } return _res; }, - serializer : function(_data, _source) { - return { + serializer : function(_data, _source, _dest) { + var _color = parseInt(_data.color.replace(/^#/,''),16).toString(); + var _res = { id : _data.id, begin : _data.begin.milliseconds, end : _data.end.milliseconds, content : { - title : _data.title, - description : _data.description, - audio : _data.audio + title : _data.title || "", + description : _data.description || "", + audio : _data.audio, + img: { + src: _data.thumbnail + } }, + color: _color, media : _data.media.id, meta : { - "id-ref" : _data.annotationType.id, - "dc:created" : IriSP.Model.dateToIso(_data.created), - "dc:creator" : _data.creator, - project : _source.projectId + "id-ref" : _data.getAnnotationType().id, + "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), + "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), + "dc:creator" : _data.creator || _source.creator, + "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, +// project : _source.projectId }, tags : IriSP._(_data.tag.id).map(function(_id) { return { @@ -1560,6 +1876,7 @@ } }) } + _dest.annotations.push(_res); } }, mashup : { @@ -1571,41 +1888,64 @@ var _res = new IriSP.Model.Mashup(_data.id, _source); _res.title = _data.meta["dc:title"]; _res.description = _data.meta["dc:description"]; - for (var _i = 0; _i < _data.items.length; _i++) { - _res.addSegmentById(_data.items[_i]); - } + _res.creator = _data.meta["dc:creator"]; + _res.setAnnotationsById(_data.items); return _res; }, - serializer : function(_data, _source) { - return { + serializer : function(_data, _source, _dest) { + var _res = { meta : { - "dc:title": _data.title, - "dc:description": _data.description, + "dc:title": _data.title || "", + "dc:description": _data.description || "", + "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), + "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), + "dc:creator" : _data.creator || _source.creator, + "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, listtype: "mashup" }, items: _data.segments.map(function(_annotation) { - return _id; + return _annotation.annotation.id; }), id: _data.id } + _dest.lists.push(_res); } } }, serialize : function(_source) { - var _res = {}, + var _res = { + meta: { + "dc:creator": _source.creator, + "dc:contributor" : _source.contributor || _source.creator, + "dc:created": IriSP.Model.dateToIso(_source.created), + "dc:modified" : IriSP.Model.dateToIso(_source.modified), + "dc:title": _source.title || "", + "dc:description": _source.description || "", + id: _source.projectId || _source.id + }, + views: [ + { + id: IriSP.Model.getUID(), + contents: [], + annotation_types: [] + } + ], + lists: [], + "annotation-types": [], + medias: [], + tags: [], + annotations: [] + }, _this = this; _source.forEach(function(_list, _typename) { if (typeof _this.types[_typename] !== "undefined") { - _res[_this.types[_typename].serialized_name] = _list.map(function(_el) { - return _this.types[_typename].serializer(_el, _source); + _list.forEach(function(_el) { + _this.types[_typename].serializer(_el, _source, _res); }); } }); return JSON.stringify(_res); }, - loadData : function(_url, _callback) { - IriSP.jQuery.getJSON(_url, _callback) - }, deSerialize : function(_data, _source) { if (typeof _data !== "object" || _data === null) { return; @@ -1649,85 +1989,71 @@ } IriSP.serializers.ldt_annotate = { - types : { - annotation : { - serialized_name : "annotations", - serializer : function(_data, _source) { - var _annType = _data.getAnnotationType(); - return { - begin: _data.begin.milliseconds, - end: _data.end.milliseconds, - content: { - data: _data.description, - audio: _data.audio - }, - tags: _data.getTagTexts(), - media: _data.getMedia().id, - type_title: _annType.title, - type: ( typeof _annType.dont_send_id !== "undefined" && _annType.dont_send_id ? "" : _annType.id ) - } + serializeAnnotation : function(_data, _source) { + var _annType = _data.getAnnotationType(); + return { + begin: _data.begin.milliseconds, + end: _data.end.milliseconds, + content: { + description: _data.description, + title: _data.title, + audio: _data.audio + }, + tags: _data.getTagTexts(), + media: _data.getMedia().id, + type_title: _annType.title, + type: ( typeof _annType.dont_send_id !== "undefined" && _annType.dont_send_id ? "" : _annType.id ), + meta: { + created: _data.created, + creator: _data.creator } } }, + deserializeAnnotation : function(_anndata, _source) { + var _ann = new IriSP.Model.Annotation(_anndata.id, _source); + _ann.description = _anndata.content.description || ""; + _ann.title = _anndata.content.title || ""; + _ann.creator = _anndata.meta.creator || ""; + _ann.created = new Date(_anndata.meta.created); + _ann.setMedia(_anndata.media, _source); + var _anntype = _source.getElement(_anndata.type); + if (!_anntype) { + _anntype = new IriSP.Model.AnnotationType(_anndata.type, _source); + _anntype.title = _anndata.type_title; + _source.getAnnotationTypes().push(_anntype); + } + _ann.setAnnotationType(_anntype.id); + var _tagIds = IriSP._(_anndata.tags).map(function(_title) { + var _tags = _source.getTags(true).searchByTitle(_title, true); + if (_tags.length) { + var _tag = _tags[0]; + } + else { + _tag = new IriSP.Model.Tag(_title.replace(/\W/g,'_'),_source); + _tag.title = _title; + _source.getTags().push(_tag); + } + return _tag.id; + }); + _ann.setTags(_tagIds); + _ann.setBegin(_anndata.begin); + _ann.setEnd(_anndata.end); + if (typeof _anndata.content.audio !== "undefined" && _anndata.content.audio.href) { + _ann.audio = _anndata.content.audio; + } + _source.getAnnotations().push(_ann); + }, serialize : function(_source) { - var _res = {}, - _this = this; - _source.forEach(function(_list, _typename) { - if (typeof _this.types[_typename] !== "undefined") { - _res[_this.types[_typename].serialized_name] = _list.map(function(_el) { - return _this.types[_typename].serializer(_el, _source); - }); - } - }); - _res.meta = { - creator: _source.creator, - created: _source.created - } - return JSON.stringify(_res); + return JSON.stringify(this.serializeAnnotation(_source.getAnnotations()[0], _source)); }, deSerialize : function(_data, _source) { if (typeof _data == "string") { _data = JSON.parse(_data); } + _source.addList('tag', new IriSP.Model.List(_source.directory)); _source.addList('annotationType', new IriSP.Model.List(_source.directory)); _source.addList('annotation', new IriSP.Model.List(_source.directory)); - if (typeof _data.annotations == "object" && _data.annotations && _data.annotations.length) { - var _anndata = _data.annotations[0], - _ann = new IriSP.Model.Annotation(_anndata.id, _source); - _ann.description = _anndata.content.data || ""; - _ann.title = _data.creator || ""; - _ann.created = new Date(_data.meta.created); - _ann.setMedia(_anndata.media, _source); - var _anntypes = _source.getAnnotationTypes(true).searchByTitle(_anndata.type_title); - if (_anntypes.length) { - var _anntype = _anntypes[0]; - } else { - var _anntype = new IriSP.Model.AnnotationType(_anndata.type, _source); - _anntype.title = _anndata.type_title; - _source.getAnnotationTypes().push(_anntype); - } - _ann.setAnnotationType(_anntype.id); - var _tagIds = IriSP._(_anndata.tags).map(function(_title) { - var _tags = _source.getTags(true).searchByTitle(_title); - if (_tags.length) { - var _tag = _tags[0]; - } - else { - _tag = new IriSP.Model.Tag(_title.replace(/\W/g,'_'),_source); - _tag.title = _title; - _source.getTags().push(_tag); - } - return _tag.id; - }); - _ann.setTags(_tagIds); - _ann.setBegin(_anndata.begin); - _ann.setEnd(_anndata.end); - _ann.creator = _data.meta.creator; - if (typeof _anndata.content.audio !== "undefined" && _anndata.content.audio.href) { - _ann.audio = _anndata.content.audio; - } - _source.getAnnotations().push(_ann); - } + this.deserializeAnnotation(_data, _source); } } \ No newline at end of file