Adapted to REST API Changes
authorveltr
Tue, 06 Nov 2012 10:59:57 +0100
changeset 979 ff62016e051d
parent 977 934a7b13a2ca
child 980 9ee8c00ae5b7
Adapted to REST API Changes
src/js/serializers/ldt_annotate.js
src/widgets/AutoPlayer.js
src/widgets/CreateAnnotation.js
src/widgets/PopcornPlayer.js
--- a/src/js/serializers/ldt_annotate.js	Mon Nov 05 19:03:10 2012 +0100
+++ b/src/js/serializers/ldt_annotate.js	Tue Nov 06 10:59:57 2012 +0100
@@ -25,14 +25,42 @@
             }
         }
     },
+    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 _this = this
-            _res = {
-                "objects": _source.getAnnotations().map(function(_annotation) {
-                    return _this.serializeAnnotation(_annotation, _source);
-                })
-            };
-        return JSON.stringify(_res);
+        return JSON.stringify(this.serializeAnnotation(_source.getAnnotations()[0], _source));
     },
     deSerialize : function(_data, _source) {
         if (typeof _data == "string") {
@@ -42,39 +70,6 @@
         _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));
-        IriSP._(_data.objects).each(function(_anndata) {
-            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);
-        });
+        this.deserializeAnnotation(_data, _source);
     }
 }
\ No newline at end of file
--- a/src/widgets/AutoPlayer.js	Mon Nov 05 19:03:10 2012 +0100
+++ b/src/widgets/AutoPlayer.js	Tue Nov 06 10:59:57 2012 +0100
@@ -46,7 +46,8 @@
     
     for (var i = 0; i < _types.length; i++) {
         if (_types[i].regexp.test(this.video)) {
-            _opts.type =  _types[i].type
+            _opts.type =  _types[i].type;
+            break;
         }
     }
     
--- a/src/widgets/CreateAnnotation.js	Mon Nov 05 19:03:10 2012 +0100
+++ b/src/widgets/CreateAnnotation.js	Tue Nov 06 10:59:57 2012 +0100
@@ -43,7 +43,7 @@
     annotation_type: "Contributions",
     api_serializer: "ldt_annotate",
     api_endpoint_template: "",
-    api_method: "PUT",
+    api_method: "POST",
     after_send_timeout: 0,
     close_after_send: false,
 }
--- a/src/widgets/PopcornPlayer.js	Mon Nov 05 19:03:10 2012 +0100
+++ b/src/widgets/PopcornPlayer.js	Tue Nov 06 10:59:57 2012 +0100
@@ -11,6 +11,7 @@
 }
 
 IriSP.Widgets.PopcornPlayer.prototype.draw = function() {
+
     
     if (typeof this.video === "undefined") {
         this.video = this.media.video;