annotate 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
rev   line source
Daniel@0 1 "use strict";
Daniel@0 2
Daniel@0 3 App.module("ContextModule", function(ContextModule, App, Backbone, Marionette, $, _, Logger) {
Daniel@0 4
Daniel@0 5 // Define private variables
Daniel@0 6 var logger = null;
Daniel@0 7
Daniel@0 8 ContextModule.addInitializer(function(options){
Daniel@0 9
Daniel@0 10 logger = Logger.get("ContextModule.StateBookmarkCollection");
Daniel@0 11 logger.setLevel(Logger.WARN);
Daniel@0 12
Daniel@0 13 /**
Daniel@0 14 * StateBookmarkCollection is needed to store bookmarks for the states
Daniel@0 15 */
Daniel@0 16 ContextModule.StateBookmarkCollection = Backbone.Collection.extend({
Daniel@0 17 model: ContextModule.StateBookmark,
Daniel@0 18
Daniel@0 19 serialize: function() {
Daniel@0 20 return this.map(function(model){ return model.serialize(); });
Daniel@0 21 },
Daniel@0 22
Daniel@0 23 unserialize: function(serializedModels) {
Daniel@0 24 var fixedSerializedModels = serializedModels;
Daniel@0 25 if (!_.isArray(serializedModels)) {
Daniel@0 26 logger.warn("StateBookmarkCollection::unserialize called for not an array: ", serializedModels);
Daniel@0 27 fixedSerializedModels = [];
Daniel@0 28 }
Daniel@0 29 if (!_.isEqual(fixedSerializedModels, this.serialize())) {
Daniel@0 30 var modelArray = [];
Daniel@0 31 for (var i = 0; i < fixedSerializedModels.length; i++) {
Daniel@0 32 var model = new this.model();
Daniel@0 33 modelArray.push(model.unserialize(fixedSerializedModels[i]));
Daniel@0 34 }
Daniel@0 35 this.reset(modelArray);
Daniel@0 36 }
Daniel@0 37 }
Daniel@0 38 });
Daniel@0 39 });
Daniel@0 40 }, Logger);