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