comparison src/DML/MainVisBundle/Resources/assets/marionette/modules/ContextModule/ContextModule.50-AppContextManager.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.AppContextManager");
11 logger.setLevel(Logger.DEBUG);
12
13 /**
14 * AppContextManager saves the given app context into the local storage and restores it
15 */
16 ContextModule.AppContextManager = Backbone.Marionette.Object.extend({
17
18 /**
19 * @memberOf App.ContextModule.AppContextManager
20 */
21 initialize: function() {
22 this.defaultSerializedAppContexts = {
23 "": {
24 stateHistory: {
25 currentSerializedState: {
26 musicCollectionGrid: {
27 selectedEntityConfigClientId: "def0",
28 entityConfigs: [
29 {clientId: "def0", parameters: {"library": "CHARM", composer: "Mozart"}},
30 {clientId: "def1", parameters: {"library": "CHARM", composer: "Haydn"}}
31 ],
32 viewConfigs: [
33 {clientId: "def2", parameters: {kind: "list"}},
34 {clientId: "def3", parameters: {kind: "tonic-histogram"}}
35 ],
36 },
37 musicRecordingGrid: {
38 viewConfigs: [
39 {clientId: "def4", parameters: {kind: "properties"}},
40 {clientId: "def5", parameters: {kind: "midi-pitch-histogram"}},
41 ],
42 }
43 }
44 }
45 },
46 "empty": {},
47 };
48 },
49
50 /**
51 * @memberOf App.ContextModule.AppContextManager
52 * @returns {Boolean} true if success, false if there was a problem
53 */
54 saveToStorage: function(appContext) {
55 logger.debug("Saving to storage")
56 return App.DataModule.Storage.setObjCache(ContextModule, "context", appContext.serialize());
57 },
58
59 /**
60 * @memberOf App.ContextModule.AppContextManager
61 * @returns {Boolean} true if success, false if there was an error, and a default was restored
62 */
63 restoreFromStorage: function(appContext, nameOfDefaultIfFailure) {
64 logger.debug("Restoring from storage")
65 var serializedAppContext = App.DataModule.Storage.getObjCache(ContextModule, "context");
66 if (!serializedAppContext) {
67 this.restoreDefault(appContext, nameOfDefaultIfFailure);
68 return false;
69 } else {
70 appContext.unserialize(serializedAppContext);
71 return true;
72 };
73 },
74
75 restoreDefault: function(appContext, nameOfDefault) {
76 var name = nameOfDefault;
77 if (!name) {
78 name = "";
79 }
80 logger.debug("Restoring default");
81 appContext.unserialize(this.defaultSerializedAppContexts[name]);
82 }
83 });
84 });
85 }, Logger);