| 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 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 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 |
|
| 25 |
|
| 26 |
|
| 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 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
className: "dojoxFilePicker", |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
pathSeparator: "", |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
topDir: "", |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
parentAttr: "parentDir", |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
pathAttr: "path", |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
preloadItems: 50, |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
selectDirectories: true, |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
selectFiles: true, |
| 78 |
|
| 79 |
_itemsMatch: function( item1, item2){ |
| 80 |
|
| 81 |
|
| 82 |
|
| 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 |
|
| 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 |
|
| 142 |
ret = []; |
| 143 |
} |
| 144 |
return ret; |
| 145 |
}, |
| 146 |
|
| 147 |
getMenuItemForItem: function( item, parentPane, 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, parentPane, 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( path, resetLastExec, onSet){ |
| 174 |
|
| 175 |
|
| 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(val){ |
| 195 |
|
| 196 |
|
| 197 |
|
| 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( value){ |
| 209 |
|
| 210 |
|
| 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 |
}); |