src/js/serializers/ldt-serializer.js
changeset 1072 ac1eacb3aa33
parent 1069 2409cb4cebaf
--- a/src/js/serializers/ldt-serializer.js	Sun Nov 12 22:07:33 2017 +0100
+++ b/src/js/serializers/ldt-serializer.js	Wed Sep 04 17:32:50 2024 +0200
@@ -1,10 +1,7 @@
 /* Start ldt-serializer.js */
+import _ from "lodash";
 
-if (typeof IriSP.serializers === "undefined") {
-    IriSP.serializers = {};
-}
-
-IriSP.serializers.ldt = {
+const ldt = function(IriSP) { return {
     types :  {
         media : {
             serialized_name : "medias",
@@ -151,7 +148,7 @@
                 _res.content = _data.content;
                 _res.setMedia(_data.media);
                 _res.setAnnotationType(_data.meta["id-ref"]);
-                _res.setTags(IriSP._(_data.tags).pluck("id-ref"));
+                _res.setTags(_(_data.tags).map("id-ref"));
                 _res.keywords = _res.getTagTexts();
                 _res.setBegin(_data.begin);
                 _res.setEnd(_data.end);
@@ -171,7 +168,7 @@
                     id : _data.id,
                     begin : _data.begin.milliseconds,
                     end : _data.end.milliseconds,
-                    content : IriSP._.defaults(
+                    content : _.defaults(
                         {},
                         {
                             title : _data.title,
@@ -199,13 +196,13 @@
                     }
                 };
                 if (_source.regenerateTags) {
-                    _res.tags = IriSP._(_data.keywords).map(function(_kw) {
+                    _res.tags = _(_data.keywords).map(function(_kw) {
                         return {
                             "id-ref": _source.__keywords[_kw.toLowerCase()].id
                         };
                     });
                 } else {
-                    _res.tags = IriSP._(_data.tag.id).map(function(_id) {
+                    _res.tags = _(_data.tag.id).map(function(_id) {
                        return {
                            "id-ref" : _id
                        };
@@ -276,7 +273,7 @@
         if (_source.regenerateTags) {
             _source.__keywords = {};
             _source.getAnnotations().forEach(function(a) {
-                IriSP._(a.keywords).each(function(kw) {
+                _(a.keywords).each(function(kw) {
                     var lkw = kw.toLowerCase();
                     if (typeof _source.__keywords[lkw] === "undefined") {
                         _source.__keywords[lkw] = {
@@ -287,7 +284,7 @@
                     }
                 });
             });
-            IriSP._(_source.__keywords).each(function(kw) {
+            _(_source.__keywords).each(function(kw) {
                 _this.types.tag.serializer(kw, _source, _res);
             });
         }
@@ -304,7 +301,7 @@
         if (typeof _data !== "object" || _data === null) {
             return;
         }
-        IriSP._(this.types).forEach(function(_type, _typename) {
+        _(this.types).forEach(function(_type, _typename) {
             var _listdata = _data[_type.serialized_name],
                 _list = new IriSP.Model.List(_source.directory);
             if (typeof _listdata !== "undefined" && _listdata !== null) {
@@ -339,6 +336,8 @@
             _source.currentMedia = _source.getElement(_data.meta.main_media["id-ref"]);
         }
     }
-};
+}};
+
+export default ldt;
 
 /* End of LDT Platform Serializer */