root / trunk / web / dojo / dojox / storage / FlashStorageProvider.js
History | View | Annotate | Download (5.36 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.storage.FlashStorageProvider"]){ |
||
9 | dojo._hasResource["dojox.storage.FlashStorageProvider"]=true; |
||
10 | dojo.provide("dojox.storage.FlashStorageProvider");
|
||
11 | dojo.require("dojox.flash");
|
||
12 | dojo.require("dojox.storage.manager");
|
||
13 | dojo.require("dojox.storage.Provider");
|
||
14 | dojo.declare("dojox.storage.FlashStorageProvider",dojox.storage.Provider,{initialized:false,_available:null,_statusHandler:null,_flashReady:false,_pageReady:false,initialize:function(){ |
||
15 | if(dojo.config["disableFlashStorage"]==true){ |
||
16 | return;
|
||
17 | } |
||
18 | dojox.flash.addLoadedListener(dojo.hitch(this,function(){ |
||
19 | this._flashReady=true; |
||
20 | if(this._flashReady&&this._pageReady){ |
||
21 | this._loaded();
|
||
22 | } |
||
23 | })); |
||
24 | var _1=dojo.moduleUrl("dojox","storage/Storage.swf").toString(); |
||
25 | dojox.flash.setSwf(_1,false);
|
||
26 | dojo.connect(dojo,"loaded",this,function(){ |
||
27 | this._pageReady=true; |
||
28 | if(this._flashReady&&this._pageReady){ |
||
29 | this._loaded();
|
||
30 | } |
||
31 | }); |
||
32 | },setFlushDelay:function(_2){ |
||
33 | if(_2===null||typeof _2==="undefined"||isNaN(_2)){ |
||
34 | throw new Error("Invalid argunment: "+_2); |
||
35 | } |
||
36 | dojox.flash.comm.setFlushDelay(String(_2)); |
||
37 | },getFlushDelay:function(){ |
||
38 | return Number(dojox.flash.comm.getFlushDelay());
|
||
39 | },flush:function(_3){ |
||
40 | if(_3==null||typeof _3=="undefined"){ |
||
41 | _3=dojox.storage.DEFAULT_NAMESPACE; |
||
42 | } |
||
43 | dojox.flash.comm.flush(_3); |
||
44 | },isAvailable:function(){ |
||
45 | return (this._available=!dojo.config["disableFlashStorage"]); |
||
46 | },put:function(_4,_5,_6,_7){ |
||
47 | if(!this.isValidKey(_4)){ |
||
48 | throw new Error("Invalid key given: "+_4); |
||
49 | } |
||
50 | if(!_7){
|
||
51 | _7=dojox.storage.DEFAULT_NAMESPACE; |
||
52 | } |
||
53 | if(!this.isValidKey(_7)){ |
||
54 | throw new Error("Invalid namespace given: "+_7); |
||
55 | } |
||
56 | this._statusHandler=_6;
|
||
57 | if(dojo.isString(_5)){
|
||
58 | _5="string:"+_5;
|
||
59 | }else{
|
||
60 | _5=dojo.toJson(_5); |
||
61 | } |
||
62 | dojox.flash.comm.put(_4,_5,_7); |
||
63 | },putMultiple:function(_8,_9,_a,_b){ |
||
64 | if(!this.isValidKeyArray(_8)||!_9 instanceof Array||_8.length!=_9.length){ |
||
65 | throw new Error("Invalid arguments: keys = ["+_8+"], values = ["+_9+"]"); |
||
66 | } |
||
67 | if(!_b){
|
||
68 | _b=dojox.storage.DEFAULT_NAMESPACE; |
||
69 | } |
||
70 | if(!this.isValidKey(_b)){ |
||
71 | throw new Error("Invalid namespace given: "+_b); |
||
72 | } |
||
73 | this._statusHandler=_a;
|
||
74 | var _c=_8.join(","); |
||
75 | var _d=[];
|
||
76 | for(var i=0;i<_9.length;i++){ |
||
77 | if(dojo.isString(_9[i])){
|
||
78 | _9[i]="string:"+_9[i];
|
||
79 | }else{
|
||
80 | _9[i]=dojo.toJson(_9[i]); |
||
81 | } |
||
82 | _d[i]=_9[i].length; |
||
83 | } |
||
84 | var _e=_9.join(""); |
||
85 | var _f=_d.join(","); |
||
86 | dojox.flash.comm.putMultiple(_c,_e,_f,_b); |
||
87 | },get:function(key,_10){ |
||
88 | if(!this.isValidKey(key)){ |
||
89 | throw new Error("Invalid key given: "+key); |
||
90 | } |
||
91 | if(!_10){
|
||
92 | _10=dojox.storage.DEFAULT_NAMESPACE; |
||
93 | } |
||
94 | if(!this.isValidKey(_10)){ |
||
95 | throw new Error("Invalid namespace given: "+_10); |
||
96 | } |
||
97 | var _11=dojox.flash.comm.get(key,_10);
|
||
98 | if(_11==""){ |
||
99 | return null; |
||
100 | } |
||
101 | return this._destringify(_11); |
||
102 | },getMultiple:function(_12,_13){ |
||
103 | if(!this.isValidKeyArray(_12)){ |
||
104 | throw new ("Invalid key array given: "+_12); |
||
105 | } |
||
106 | if(!_13){
|
||
107 | _13=dojox.storage.DEFAULT_NAMESPACE; |
||
108 | } |
||
109 | if(!this.isValidKey(_13)){ |
||
110 | throw new Error("Invalid namespace given: "+_13); |
||
111 | } |
||
112 | var _14=_12.join(","); |
||
113 | var _15=dojox.flash.comm.getMultiple(_14,_13);
|
||
114 | var _16=eval("("+_15+")"); |
||
115 | for(var i=0;i<_16.length;i++){ |
||
116 | _16[i]=(_16[i]=="")?null:this._destringify(_16[i]); |
||
117 | } |
||
118 | return _16;
|
||
119 | },_destringify:function(_17){ |
||
120 | if(dojo.isString(_17)&&(/^string:/.test(_17))){ |
||
121 | _17=_17.substring("string:".length);
|
||
122 | }else{
|
||
123 | _17=dojo.fromJson(_17); |
||
124 | } |
||
125 | return _17;
|
||
126 | },getKeys:function(_18){ |
||
127 | if(!_18){
|
||
128 | _18=dojox.storage.DEFAULT_NAMESPACE; |
||
129 | } |
||
130 | if(!this.isValidKey(_18)){ |
||
131 | throw new Error("Invalid namespace given: "+_18); |
||
132 | } |
||
133 | var _19=dojox.flash.comm.getKeys(_18);
|
||
134 | if(_19==null||_19=="null"){ |
||
135 | _19="";
|
||
136 | } |
||
137 | _19=_19.split(",");
|
||
138 | _19.sort(); |
||
139 | return _19;
|
||
140 | },getNamespaces:function(){ |
||
141 | var _1a=dojox.flash.comm.getNamespaces();
|
||
142 | if(_1a==null||_1a=="null"){ |
||
143 | _1a=dojox.storage.DEFAULT_NAMESPACE; |
||
144 | } |
||
145 | _1a=_1a.split(",");
|
||
146 | _1a.sort(); |
||
147 | return _1a;
|
||
148 | },clear:function(_1b){ |
||
149 | if(!_1b){
|
||
150 | _1b=dojox.storage.DEFAULT_NAMESPACE; |
||
151 | } |
||
152 | if(!this.isValidKey(_1b)){ |
||
153 | throw new Error("Invalid namespace given: "+_1b); |
||
154 | } |
||
155 | dojox.flash.comm.clear(_1b); |
||
156 | },remove:function(key,_1c){ |
||
157 | if(!_1c){
|
||
158 | _1c=dojox.storage.DEFAULT_NAMESPACE; |
||
159 | } |
||
160 | if(!this.isValidKey(_1c)){ |
||
161 | throw new Error("Invalid namespace given: "+_1c); |
||
162 | } |
||
163 | dojox.flash.comm.remove(key,_1c); |
||
164 | },removeMultiple:function(_1d,_1e){ |
||
165 | if(!this.isValidKeyArray(_1d)){ |
||
166 | dojo.raise("Invalid key array given: "+_1d);
|
||
167 | } |
||
168 | if(!_1e){
|
||
169 | _1e=dojox.storage.DEFAULT_NAMESPACE; |
||
170 | } |
||
171 | if(!this.isValidKey(_1e)){ |
||
172 | throw new Error("Invalid namespace given: "+_1e); |
||
173 | } |
||
174 | var _1f=_1d.join(","); |
||
175 | dojox.flash.comm.removeMultiple(_1f,_1e); |
||
176 | },isPermanent:function(){ |
||
177 | return true; |
||
178 | },getMaximumSize:function(){ |
||
179 | return dojox.storage.SIZE_NO_LIMIT;
|
||
180 | },hasSettingsUI:function(){ |
||
181 | return true; |
||
182 | },showSettingsUI:function(){ |
||
183 | dojox.flash.comm.showSettings(); |
||
184 | dojox.flash.obj.setVisible(true);
|
||
185 | dojox.flash.obj.center(); |
||
186 | },hideSettingsUI:function(){ |
||
187 | dojox.flash.obj.setVisible(false);
|
||
188 | if(dojo.isFunction(dojox.storage.onHideSettingsUI)){
|
||
189 | dojox.storage.onHideSettingsUI.call(null);
|
||
190 | } |
||
191 | },getResourceList:function(){ |
||
192 | return [];
|
||
193 | },_loaded:function(){ |
||
194 | this._allNamespaces=this.getNamespaces(); |
||
195 | this.initialized=true; |
||
196 | dojox.storage.manager.loaded(); |
||
197 | },_onStatus:function(_20,key,_21){ |
||
198 | var ds=dojox.storage;
|
||
199 | var dfo=dojox.flash.obj;
|
||
200 | if(_20==ds.PENDING){
|
||
201 | dfo.center(); |
||
202 | dfo.setVisible(true);
|
||
203 | }else{
|
||
204 | dfo.setVisible(false);
|
||
205 | } |
||
206 | if(ds._statusHandler){
|
||
207 | ds._statusHandler.call(null,_20,key,null,_21); |
||
208 | } |
||
209 | }}); |
||
210 | dojox.storage.manager.register("dojox.storage.FlashStorageProvider",new dojox.storage.FlashStorageProvider()); |
||
211 | } |