diff src/DML/MainVisBundle/Resources/assets/marionette/modules/ContextModule/ContextModule.21-StateBookmarkCollection.js @ 0:493bcb69166c

added public content
author Daniel Wolff
date Tue, 09 Feb 2016 20:54:02 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/DML/MainVisBundle/Resources/assets/marionette/modules/ContextModule/ContextModule.21-StateBookmarkCollection.js	Tue Feb 09 20:54:02 2016 +0100
@@ -0,0 +1,40 @@
+"use strict";
+
+App.module("ContextModule", function(ContextModule, App, Backbone, Marionette, $, _, Logger) {
+
+    // Define private variables
+    var logger = null;
+
+    ContextModule.addInitializer(function(options){
+        
+        logger = Logger.get("ContextModule.StateBookmarkCollection");
+        logger.setLevel(Logger.WARN);
+        
+        /**
+         * StateBookmarkCollection is needed to store bookmarks for the states
+         */
+        ContextModule.StateBookmarkCollection = Backbone.Collection.extend({
+            model: ContextModule.StateBookmark,
+            
+            serialize: function() {
+                return this.map(function(model){ return model.serialize(); });
+            },
+            
+            unserialize: function(serializedModels) {
+                var fixedSerializedModels = serializedModels;
+                if (!_.isArray(serializedModels)) {
+                    logger.warn("StateBookmarkCollection::unserialize called for not an array: ", serializedModels);
+                    fixedSerializedModels = [];
+                }
+                if (!_.isEqual(fixedSerializedModels, this.serialize())) {
+                    var modelArray = [];
+                    for (var i = 0; i < fixedSerializedModels.length; i++) {
+                        var model = new this.model();
+                        modelArray.push(model.unserialize(fixedSerializedModels[i]));
+                    }
+                    this.reset(modelArray);
+                }
+            }
+        });
+    });
+}, Logger);