AmdaStateProvider.js
2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* Project : AMDA-NG
* Name : AmdaStateProvider.js
* @class amdaDesktop.AmdaStateProvider
* @extends Ext.state.Provider
* @brief Module controlling state storing/restoring at/from Server
* @author Benjamin
* @version $Id: AmdaStateProvider.js 2441 2014-06-27 12:35:22Z elena $
*/
Ext.define('amdaDesktop.AmdaStateProvider', {
extend: 'Ext.state.Provider',
alias: 'widget.stateProvider',
s : {},
constructor : function()
{
var me = this;
this.addEvents('afterrestore,aftersave');
me.callParent(arguments);
},
set : function(name, value)
{
var me = this;
if (typeof value == "undefined" || value === null)
{
me.clear(name);
return;
}
me.callParent(arguments);
this.state[name] = value;
this.s[name] = me.encodeValue(value);
},
get : function(name)
{
return this.state[name];
},
onLoadFinish : function(result, e)
{
var me = this;
if (e.status === true)
{
if (result.error)
{
Ext.Msg.show({title:'State provider - Load error', msg: result.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
}
else
{
var keys = [];
for (var s in result.state) {
if (hasOwnProperty.call(result.state, s))
keys.push(s);
}
var len = keys.length;
for (var i = 0; i < len; i++)
{
if (keys[i] == "_empty_")
continue;
this.state[keys[i]] = me.decodeValue(result.state[keys[i]]);
this.s[keys[i]] = result.state[keys[i]];
}
}
}
else
{
Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
}
me.fireEvent('afterrestore', me);
},
restoreState : function()
{
var me = this;
var o = {};
AmdaAction.loadState(o,this.onLoadFinish,this);
},
clear : function(name)
{
this.clearKey(name);
this.callParent(arguments);
},
clearKey : function(name)
{
if (this.state[name])
this.state[name].remove();
},
onSaveFinish : function(result, e)
{
var me = this;
if (e.status === true)
{
if (result.error)
{
Ext.Msg.show({title:'State provider - Save error', msg: result.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
}
}
else
{
Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
}
me.fireEvent('aftersave', me);
},
saveState : function()
{
var me = this;
AmdaAction.saveState(this.s,this.onSaveFinish,this);
},
saveLastTime : function()
{
var me = this;
var lastTime = {};
lastTime[myDesktopApp.desktop.id + '_wallpaper'] = this.s[myDesktopApp.desktop.id + '_wallpaper'];
lastTime['timeinterval'] = this.s['timeinterval'];
lastTime['timeintervalMining'] = this.s['timeintervalMining'];
AmdaAction.saveState(lastTime,this.onSaveFinish,this);
}
});