src/js/serializers/PlatformAnnotateSerializer.js
branchnew-model
changeset 904 510ebab76fa3
child 908 f56199193fad
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/js/serializers/PlatformAnnotateSerializer.js	Fri May 18 18:23:51 2012 +0200
@@ -0,0 +1,43 @@
+/* Used when Putting annotations on the platform */
+
+if (typeof IriSP.serializers === "undefined") {
+    IriSP.serializers = {}
+}
+
+IriSP.serializers.ldt_annotate = {
+    types :  {
+        annotation : {
+            serialized_name : "annotations",
+            serializer : function(_data, _source) {
+                return {
+                    begin: _data.begin.milliseconds,
+                    end: _data.end.milliseconds,
+                    content: {
+                        data: _data.description
+                    },
+                    tags: _data.getTagTexts(),
+                    media: _source.unNamespace(_data.getMedia().id),
+                    title: _data.title,
+                    type_title: _data.getAnnotationType().title,
+                    type: _source.unNamespace(_data.getAnnotationType().id)
+                }
+            }
+        }
+    },
+    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);
+    }
+}
\ No newline at end of file