]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/StateProvider.js
1 /* This state provider keeps part of the state inside
4 * We compress (shorten) url using dictionary based compression
5 * i.e. use column separated list instead of url encoded hash:
7 * := indicates string values
8 * :\d+ lookup value in dictionary hash
9 * #v1:=value1:5:=value2:=value3:...
12 Ext
.define('PVE.StateProvider', {
13 extend
: 'Ext.state.LocalStorageProvider',
16 setHV: function(name
, newvalue
, fireEvents
) {
20 var oldtext
= Ext
.encode(me
.UIState
[name
]);
21 var newtext
= Ext
.encode(newvalue
);
22 if (newtext
!= oldtext
) {
24 me
.UIState
[name
] = newvalue
;
25 //console.log("changed old " + name + " " + oldtext);
26 //console.log("changed new " + name + " " + newtext);
28 me
.fireEvent("statechange", me
, name
, { value
: newvalue
});
36 // order is important for notifications
68 'firewall-options': 36,
70 'firewall-aliases': 34,
107 decodeHToken: function(token
) {
112 Ext
.Array
.each(me
.hslist
, function(rec
) {
113 state
[rec
[0]] = rec
[1];
118 // return Ext.urlDecode(token);
120 var items
= token
.split(':');
121 var prefix
= items
.shift();
123 if (prefix
!= me
.hprefix
) {
124 return me
.decodeHToken();
127 Ext
.Array
.each(me
.hslist
, function(rec
) {
128 var value
= items
.shift();
130 if (value
[0] === '=') {
131 value
= decodeURIComponent(value
.slice(1));
133 Ext
.Object
.each(me
.compDict
, function(key
, cv
) {
141 state
[rec
[0]] = value
;
147 encodeHToken: function(state
) {
150 // return Ext.urlEncode(state);
152 var ctoken
= me
.hprefix
;
153 Ext
.Array
.each(me
.hslist
, function(rec
) {
154 var value
= state
[rec
[0]];
155 if (!Ext
.isDefined(value
)) {
158 value
= encodeURIComponent(value
);
162 var comp
= me
.compDict
[value
];
163 if (Ext
.isDefined(comp
)) {
164 ctoken
+= ":" + comp
;
166 ctoken
+= ":=" + value
;
174 constructor: function(config
){
177 me
.callParent([config
]);
179 me
.UIState
= me
.decodeHToken(); // set default
181 var history_change_cb = function(token
) {
182 //console.log("HC " + token);
184 var res
= window
.confirm(gettext('Are you sure you want to navigate away from this page?'));
186 // process text value and close...
189 Ext
.History
.forward();
194 var newstate
= me
.decodeHToken(token
);
195 Ext
.Array
.each(me
.hslist
, function(rec
) {
196 if (typeof newstate
[rec
[0]] == "undefined") {
199 me
.setHV(rec
[0], newstate
[rec
[0]], true);
203 var start_token
= Ext
.History
.getToken();
205 history_change_cb(start_token
);
207 var htext
= me
.encodeHToken(me
.UIState
);
208 Ext
.History
.add(htext
);
211 Ext
.History
.on('change', history_change_cb
);
214 get: function(name
, defaultValue
){
215 /*jslint confusion: true */
219 if (typeof me
.UIState
[name
] != "undefined") {
220 data
= { value
: me
.UIState
[name
] };
222 data
= me
.callParent(arguments
);
223 if (!data
&& name
=== 'GuiCap') {
224 data
= { vms
: {}, storage
: {}, access
: {}, nodes
: {}, dc
: {} };
228 //console.log("GET " + name + " " + Ext.encode(data));
232 clear: function(name
){
235 if (typeof me
.UIState
[name
] != "undefined") {
236 me
.UIState
[name
] = null;
239 me
.callParent(arguments
);
242 set: function(name
, value
, fireevent
){
245 //console.log("SET " + name + " " + Ext.encode(value));
246 if (typeof me
.UIState
[name
] != "undefined") {
247 var newvalue
= value
? value
.value
: null;
248 if (me
.setHV(name
, newvalue
, fireevent
)) {
249 var htext
= me
.encodeHToken(me
.UIState
);
250 Ext
.History
.add(htext
);
253 me
.callParent(arguments
);