Debian Codegraph @

dojox/widget/FilePicker.js

raw symbols SCIP
1 dojo.provide("dojox.widget.FilePicker");
2
3 dojo.require("dojox.widget.RollingList");
4
5 dojo.require("dojo.i18n");
6 dojo.requireLocalization("dojox.widget", "FilePicker");
7
8 dojo.declare("dojox.widget._FileInfoPane",
9 [dojox.widget._RollingListPane], {
10 // summary:
11 // a pane to display the information for the currently-selected
12 // file
13
14 // templateString: String
15 // The template to be used to construct the widget.
16 templateString: dojo.cache("dojox.widget", "FilePicker/_FileInfoPane.html"),
17
18 postMixInProperties: function(){
19 this._messages = dojo.i18n.getLocalization("dojox.widget", "FilePicker", this.lang);
20 this.inherited(arguments);
21 },
22
23 onItems: function(){
24 // summary:
25 // called after a fetch or load - at this point, this.items should be
26 // set and loaded.
27 var store = this.store, item = this.items[0];
28 if(!item){
29 this._onError("Load", new Error("No item defined"));
30 }else{
31 this.nameNode.innerHTML = store.getLabel(item);
32 this.pathNode.innerHTML = store.getIdentity(item);
33 this.sizeNode.innerHTML = store.getValue(item, "size");
34 this.parentWidget.scrollIntoView(this);
35 this.inherited(arguments);
36 }
37 }
38 });
39
40 dojo.declare("dojox.widget.FilePicker", dojox.widget.RollingList, {
41 // summary:
42 // a specialized version of RollingList that handles file information
43 // in a store
44
45 className: "dojoxFilePicker",
46
47 // pathSeparator: String
48 // Our file separator - it will be guessed if not set
49 pathSeparator: "",
50
51 // topDir: String
52 // The top directory string - it will be guessed if not set
53 topDir: "",
54
55 // parentAttr: String
56 // the attribute to read for finding our parent directory
57 parentAttr: "parentDir",
58
59 // pathAttr: String
60 // the attribute to read for getting the full path of our file
61 pathAttr: "path",
62
63 // preloadItems: Boolean|Int
64 // Set this to a sane number - since we expect to mostly be using the
65 // dojox.data.FileStore - which doesn't like loading lots of items
66 // all at once.
67 preloadItems: 50,
68
69 // selectDirectories: Boolean
70 // whether or not we allow selection of directories - that is, whether or
71 // our value can be set to a directory.
72 selectDirectories: true,
73
74 // selectFiles: Boolean
75 // whether or not we allow selection of files - that is, we will disable
76 // the file entries.
77 selectFiles: true,
78
79 _itemsMatch: function(/*item*/ item1, /*item*/ item2){
80 // Summary:
81 // Returns whether or not the two items match - checks ID if
82 // they aren't the exact same object - ignoring trailing slashes
83 if(!item1 && !item2){
84 return true;
85 }else if(!item1 || !item2){
86 return false;
87 }else if(item1 == item2){
88 return true;
89 }else if (this._isIdentity){
90 var iArr = [ this.store.getIdentity(item1), this.store.getIdentity(item2) ];
91 dojo.forEach(iArr, function(i, idx){
92 if(i.lastIndexOf(this.pathSeparator) == (i.length - 1)){
93 iArr[idx] = i.substring(0, i.length - 1);
94 }else{
95 }
96 }, this);
97 return (iArr[0] == iArr[1]);
98 }
99 return false;
100 },
101
102 startup: function(){
103 if(this._started){ return; }
104 this.inherited(arguments);
105 // Figure out our file separator if we don't have it yet
106 var conn, child = this.getChildren()[0];
107 var setSeparator = dojo.hitch(this, function(){
108 if(conn){
109 this.disconnect(conn);
110 }
111 delete conn;
112 var item = child.items[0];
113 if(item){
114 var store = this.store;
115 var parent = store.getValue(item, this.parentAttr);
116 var path = store.getValue(item, this.pathAttr);
117 this.pathSeparator = this.pathSeparator || store.pathSeparator;
118 if(!this.pathSeparator){
119 this.pathSeparator = path.substring(parent.length, parent.length + 1);
120 }
121 if(!this.topDir){
122 this.topDir = parent;
123 if(this.topDir.lastIndexOf(this.pathSeparator) != (this.topDir.length - 1)){
124 this.topDir += this.pathSeparator;
125 }
126 }
127 }
128 });
129 if(!this.pathSeparator || !this.topDir){
130 if(!child.items){
131 conn = this.connect(child, "onItems", setSeparator);
132 }else{
133 setSeparator();
134 }
135 }
136 },
137
138 getChildItems: function(item){
139 var ret = this.inherited(arguments);
140 if(!ret && this.store.getValue(item, "directory")){
141 // It's an empty directory - so pass through an empty array
142 ret = [];
143 }
144 return ret;
145 },
146
147 getMenuItemForItem: function(/*item*/ item, /* dijit/_Contained */ parentPane, /* item[]? */ children){
148 var menuOptions = {iconClass: "dojoxDirectoryItemIcon"};
149 if(!this.store.getValue(item, "directory")){
150 menuOptions.iconClass = "dojoxFileItemIcon";
151 var l = this.store.getLabel(item), idx = l.lastIndexOf(".");
152 if(idx >= 0){
153 menuOptions.iconClass += " dojoxFileItemIcon_" + l.substring(idx + 1);
154 }
155 if(!this.selectFiles){
156 menuOptions.disabled = true;
157 }
158 }
159 var ret = new dijit.MenuItem(menuOptions);
160 return ret;
161 },
162
163 getPaneForItem: function(/*item*/ item, /* dijit/_Contained */ parentPane, /* item[]? */ children){
164 var ret = null;
165 if(!item || (this.store.isItem(item) && this.store.getValue(item, "directory"))){
166 ret = new dojox.widget._RollingListGroupPane({});
167 }else if(this.store.isItem(item) && !this.store.getValue(item, "directory")){
168 ret = new dojox.widget._FileInfoPane({});
169 }
170 return ret;
171 },
172
173 _setPathValueAttr: function(/*String*/ path, /*Boolean?*/ resetLastExec, /*function?*/ onSet){
174 // summary:
175 // sets the value of this widget based off the given path
176 if(!path){
177 this.set("value", null);
178 return;
179 }
180 if(path.lastIndexOf(this.pathSeparator) == (path.length - 1)){
181 path = path.substring(0, path.length - 1);
182 }
183 this.store.fetchItemByIdentity({identity: path,
184 onItem: function(v){
185 if(resetLastExec){
186 this._lastExecutedValue = v;
187 }
188 this.set("value", v);
189 if(onSet){ onSet(); }
190 },
191 scope: this});
192 },
193
194 _getPathValueAttr: function(/*item?*/val){
195 // summary:
196 // returns the path value of the given value (or current value
197 // if not passed a value)
198 if(!val){
199 val = this.value;
200 }
201 if(val && this.store.isItem(val)){
202 return this.store.getValue(val, this.pathAttr);
203 }else{
204 return "";
205 }
206 },
207
208 _setValue: function(/* item */ value){
209 // summary:
210 // internally sets the value and fires onchange
211 delete this._setInProgress;
212 var store = this.store;
213 if(value && store.isItem(value)){
214 var isDirectory = this.store.getValue(value, "directory");
215 if((isDirectory && !this.selectDirectories) ||
216 (!isDirectory && !this.selectFiles)){ return; }
217 }else{
218 value = null;
219 }
220 if(!this._itemsMatch(this.value, value)){
221 this.value = value;
222 this._onChange(value);
223 }
224 }
225 });