root / trunk / web / dojo / dojox / widget / FilePicker.js
History | View | Annotate | Download (4.79 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.widget.FilePicker"]){ |
||
9 | dojo._hasResource["dojox.widget.FilePicker"]=true; |
||
10 | dojo.provide("dojox.widget.FilePicker");
|
||
11 | dojo.require("dojox.widget.RollingList");
|
||
12 | dojo.require("dojo.i18n");
|
||
13 | dojo.requireLocalization("dojox.widget","FilePicker",null,"ROOT,ar,ca,cs,da,de,el,es,fi,fr,he,hu,it,ja,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw"); |
||
14 | dojo.declare("dojox.widget._FileInfoPane",[dojox.widget._RollingListPane],{templateString:"",templateString:dojo.cache("dojox.widget","FilePicker/_FileInfoPane.html","<div class=\"dojoxFileInfoPane\">\n\t<table>\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t<td class=\"dojoxFileInfoLabel dojoxFileInfoNameLabel\">${_messages.name}</td>\n\t\t\t\t<td class=\"dojoxFileInfoName\" dojoAttachPoint=\"nameNode\"></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td class=\"dojoxFileInfoLabel dojoxFileInfoPathLabel\">${_messages.path}</td>\n\t\t\t\t<td class=\"dojoxFileInfoPath\" dojoAttachPoint=\"pathNode\"></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td class=\"dojoxFileInfoLabel dojoxFileInfoSizeLabel\">${_messages.size}</td>\n\t\t\t\t<td class=\"dojoxFileInfoSize\" dojoAttachPoint=\"sizeNode\"></td>\n\t\t\t</tr>\n\t\t</tbody>\n\t</table>\n\t<div dojoAttachPoint=\"containerNode\" style=\"display:none;\"></div>\n</div>\n"),postMixInProperties:function(){ |
||
15 | this._messages=dojo.i18n.getLocalization("dojox.widget","FilePicker",this.lang); |
||
16 | this.inherited(arguments); |
||
17 | },onItems:function(){ |
||
18 | var _1=this.store,_2=this.items[0]; |
||
19 | if(!_2){
|
||
20 | this._onError("Load",new Error("No item defined")); |
||
21 | }else{
|
||
22 | this.nameNode.innerHTML=_1.getLabel(_2);
|
||
23 | this.pathNode.innerHTML=_1.getIdentity(_2);
|
||
24 | this.sizeNode.innerHTML=_1.getValue(_2,"size"); |
||
25 | this.parentWidget.scrollIntoView(this); |
||
26 | this.inherited(arguments); |
||
27 | } |
||
28 | }}); |
||
29 | dojo.declare("dojox.widget.FilePicker",dojox.widget.RollingList,{className:"dojoxFilePicker",pathSeparator:"",topDir:"",parentAttr:"parentDir",pathAttr:"path",preloadItems:50,selectDirectories:true,selectFiles:true,_itemsMatch:function(_3,_4){ |
||
30 | if(!_3&&!_4){
|
||
31 | return true; |
||
32 | }else{
|
||
33 | if(!_3||!_4){
|
||
34 | return false; |
||
35 | }else{
|
||
36 | if(_3==_4){
|
||
37 | return true; |
||
38 | }else{
|
||
39 | if(this._isIdentity){ |
||
40 | var _5=[this.store.getIdentity(_3),this.store.getIdentity(_4)]; |
||
41 | dojo.forEach(_5,function(i,_6){
|
||
42 | if(i.lastIndexOf(this.pathSeparator)==(i.length-1)){ |
||
43 | _5[_6]=i.substring(0,i.length-1); |
||
44 | }else{
|
||
45 | } |
||
46 | },this);
|
||
47 | return (_5[0]==_5[1]); |
||
48 | } |
||
49 | } |
||
50 | } |
||
51 | } |
||
52 | return false; |
||
53 | },startup:function(){ |
||
54 | if(this._started){ |
||
55 | return;
|
||
56 | } |
||
57 | this.inherited(arguments); |
||
58 | var _7,_8=this.getChildren()[0]; |
||
59 | var _9=dojo.hitch(this,function(){ |
||
60 | if(_7){
|
||
61 | this.disconnect(_7);
|
||
62 | } |
||
63 | delete _7;
|
||
64 | var _a=_8.items[0]; |
||
65 | if(_a){
|
||
66 | var _b=this.store; |
||
67 | var _c=_b.getValue(_a,this.parentAttr); |
||
68 | var _d=_b.getValue(_a,this.pathAttr); |
||
69 | this.pathSeparator=this.pathSeparator||_b.pathSeparator; |
||
70 | if(!this.pathSeparator){ |
||
71 | this.pathSeparator=_d.substring(_c.length,_c.length+1); |
||
72 | } |
||
73 | if(!this.topDir){ |
||
74 | this.topDir=_c;
|
||
75 | if(this.topDir.lastIndexOf(this.pathSeparator)!=(this.topDir.length-1)){ |
||
76 | this.topDir+=this.pathSeparator; |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 | }); |
||
81 | if(!this.pathSeparator||!this.topDir){ |
||
82 | if(!_8.items){
|
||
83 | _7=this.connect(_8,"onItems",_9); |
||
84 | }else{
|
||
85 | _9(); |
||
86 | } |
||
87 | } |
||
88 | },getChildItems:function(_e){ |
||
89 | var _f=this.inherited(arguments); |
||
90 | if(!_f&&this.store.getValue(_e,"directory")){ |
||
91 | _f=[]; |
||
92 | } |
||
93 | return _f;
|
||
94 | },getMenuItemForItem:function(_10,_11,_12){ |
||
95 | var _13={iconClass:"dojoxDirectoryItemIcon"}; |
||
96 | if(!this.store.getValue(_10,"directory")){ |
||
97 | _13.iconClass="dojoxFileItemIcon";
|
||
98 | var l=this.store.getLabel(_10),idx=l.lastIndexOf("."); |
||
99 | if(idx>=0){ |
||
100 | _13.iconClass+=" dojoxFileItemIcon_"+l.substring(idx+1); |
||
101 | } |
||
102 | if(!this.selectFiles){ |
||
103 | _13.disabled=true;
|
||
104 | } |
||
105 | } |
||
106 | var ret=new dijit.MenuItem(_13); |
||
107 | return ret;
|
||
108 | },getPaneForItem:function(_14,_15,_16){ |
||
109 | var ret=null; |
||
110 | if(!_14||(this.store.isItem(_14)&&this.store.getValue(_14,"directory"))){ |
||
111 | ret=new dojox.widget._RollingListGroupPane({});
|
||
112 | }else{
|
||
113 | if(this.store.isItem(_14)&&!this.store.getValue(_14,"directory")){ |
||
114 | ret=new dojox.widget._FileInfoPane({});
|
||
115 | } |
||
116 | } |
||
117 | return ret;
|
||
118 | },_setPathValueAttr:function(_17,_18,_19){ |
||
119 | if(!_17){
|
||
120 | this.set("value",null); |
||
121 | return;
|
||
122 | } |
||
123 | if(_17.lastIndexOf(this.pathSeparator)==(_17.length-1)){ |
||
124 | _17=_17.substring(0,_17.length-1); |
||
125 | } |
||
126 | this.store.fetchItemByIdentity({identity:_17,onItem:function(v){ |
||
127 | if(_18){
|
||
128 | this._lastExecutedValue=v;
|
||
129 | } |
||
130 | this.set("value",v); |
||
131 | if(_19){
|
||
132 | _19(); |
||
133 | } |
||
134 | },scope:this}); |
||
135 | },_getPathValueAttr:function(val){ |
||
136 | if(!val){
|
||
137 | val=this.value;
|
||
138 | } |
||
139 | if(val&&this.store.isItem(val)){ |
||
140 | return this.store.getValue(val,this.pathAttr); |
||
141 | }else{
|
||
142 | return ""; |
||
143 | } |
||
144 | },_setValue:function(_1a){ |
||
145 | delete this._setInProgress; |
||
146 | var _1b=this.store; |
||
147 | if(_1a&&_1b.isItem(_1a)){
|
||
148 | var _1c=this.store.getValue(_1a,"directory"); |
||
149 | if((_1c&&!this.selectDirectories)||(!_1c&&!this.selectFiles)){ |
||
150 | return;
|
||
151 | } |
||
152 | }else{
|
||
153 | _1a=null;
|
||
154 | } |
||
155 | if(!this._itemsMatch(this.value,_1a)){ |
||
156 | this.value=_1a;
|
||
157 | this._onChange(_1a);
|
||
158 | } |
||
159 | }}); |
||
160 | } |