/[drupal]/contributions/modules/webfm/js/webfm.js
ViewVC logotype

Contents of /contributions/modules/webfm/js/webfm.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.32 - (show annotations) (download) (as text)
Thu Sep 17 23:30:48 2009 UTC (2 months, 1 week ago) by cweagans
Branch: MAIN
CVS Tags: HEAD
Changes since 1.31: +2 -2 lines
File MIME type: text/javascript
#554574 by castawaybcn, Niels Hackius: Use more appropriate icons for OpenOffice files.
1 /* $Id: webfm.js,v 1.31 2009/08/19 15:30:45 robmilne Exp $ */
2
3 /* namespace */
4 function Webfm() {}
5
6 /*
7 ** Global variables
8 */
9 //Translation possible by changing the array values (DO NOT ALTER KEYS!)
10 Webfm.js_msg = [];
11 Webfm.js_msg["mkdir"] = Drupal.t("Create New Dir");
12 Webfm.js_msg["file"] = Drupal.t("file");
13 Webfm.js_msg["dir"] = Drupal.t("directory");
14 Webfm.js_msg["u_file"] = Drupal.t("File");
15 Webfm.js_msg["u_dir"] = Drupal.t("Directory");
16 Webfm.js_msg["tree"] = Drupal.t("");
17 Webfm.js_msg["work"] = Drupal.t("Working... please wait");
18 Webfm.js_msg["refresh"] = Drupal.t("refresh");
19 Webfm.js_msg["sort"] = Drupal.t("sort by this column");
20 Webfm.js_msg["new-dir"] = Drupal.t("Create New Folder");
21 Webfm.js_msg["add-2-db"] = Drupal.t("Add files in this folder to database");
22 Webfm.js_msg["r-add-2-db"] = Drupal.t("Recursive add files to database");
23 Webfm.js_msg["column1"] = Drupal.t("Name");
24 Webfm.js_msg["column2"] = Drupal.t("Modified");
25 Webfm.js_msg["column3"] = Drupal.t("Size");
26 Webfm.js_msg["column4"] = Drupal.t("Owner");
27 Webfm.js_msg["attach-title"] = Drupal.t("Attached Files");
28 Webfm.js_msg["meta-title"] = Drupal.t("File Meta Data");
29 Webfm.js_msg["search-title"] = Drupal.t("File Search");
30 Webfm.js_msg["debug-title"] = Drupal.t("WebFM Debug");
31 Webfm.js_msg["cache-title"] = Drupal.t("Directory Cache");
32 Webfm.js_msg["search-cur"] = Drupal.t("Search current directory (see listing breadcrumb trail)");
33 Webfm.js_msg["no-match"] = Drupal.t("No match found");
34 Webfm.js_msg["search"] = Drupal.t("Search");
35 Webfm.js_msg["submit"] = Drupal.t("Submit");
36 Webfm.js_msg["reset"] = Drupal.t("Reset");
37 Webfm.js_msg["clear"] = Drupal.t("Clear");
38 Webfm.js_msg["cancel"] = Drupal.t("Cancel");
39 Webfm.js_msg["close"] = Drupal.t("Close");
40 Webfm.js_msg["resize"] = Drupal.t("Resize");
41 Webfm.js_msg["replace"] = Drupal.t("Replace and Version original copy of ");
42 Webfm.js_msg["replace-del"] = Drupal.t("Replace and Delete original copy of ");
43 Webfm.js_msg["no-replace"] = Drupal.t("Version new copy of ");
44 Webfm.js_msg["cache"] = Drupal.t("Cache Content");
45 Webfm.js_msg["curdir-undef"] = Drupal.t("current directory undefined");
46 Webfm.js_msg["ajax-err"] = Drupal.t("server is unreachable");
47 Webfm.js_msg["move-err"] = Drupal.t("move operation fail");
48 Webfm.js_msg["len-err"] = Drupal.t("Too long");
49 Webfm.js_msg["confirm-del0"] = Drupal.t("Do you want to delete the ");
50 Webfm.js_msg["confirm-del1"] = Drupal.t(" and all its contents");
51 Webfm.js_msg["confirm-det"] = Drupal.t("Do you want to detach ");
52 Webfm.js_msg["confirm-dbrem0"] = Drupal.t("Do you want to remove ");
53 Webfm.js_msg["confirm-dbrem1"] = Drupal.t(" from the database?\n All metadata and attachments for this file will be lost");
54 Webfm.js_msg["enum_local"] = Drupal.t("Do you want to add all files of this directory into the database?");
55 Webfm.js_msg["enum_recur"] = Drupal.t("Do you want to add all files of this directory and sub-directories into the database?");
56 Webfm.js_msg["file-dwld"] = Drupal.t("download file");
57 Webfm.js_msg["no-file-dwld"] = Drupal.t("file not in database");
58 Webfm.js_msg["inserted"] = Drupal.t(" files inserted into db");
59 Webfm.js_msg["not-inserted"] = Drupal.t(" files failed to insert into db");
60 Webfm.js_msg["metadata"] = Drupal.t("Metadata");
61 Webfm.js_msg["fix_input"] = Drupal.t("correct input");
62 Webfm.js_msg["perm"] = Drupal.t("File Permissions");
63
64 Webfm.meta_msg = [];
65 Webfm.meta_msg["fid"] = Drupal.t("fid");
66 Webfm.meta_msg["uid"] = Drupal.t("uid");
67 Webfm.meta_msg["uname"] = Drupal.t("file owner");
68 Webfm.meta_msg["name"] = Drupal.t("name");
69 Webfm.meta_msg["title"] = Drupal.t("title");
70 Webfm.meta_msg["desc"] = Drupal.t("description");
71 Webfm.meta_msg["lang"] = Drupal.t("language");
72 Webfm.meta_msg["pub"] = Drupal.t("publisher");
73 Webfm.meta_msg["format"] = Drupal.t("format");
74 Webfm.meta_msg["ver"] = Drupal.t("version");
75 Webfm.meta_msg["type"] = Drupal.t("image type");
76 Webfm.meta_msg["width"] = Drupal.t("width");
77 Webfm.meta_msg["height"] = Drupal.t("height");
78 Webfm.meta_msg["dl_cnt"] = Drupal.t("downloads");
79 Webfm.meta_msg["link"] = Drupal.t("link");
80
81 Webfm.perm_msg = [];
82 Webfm.perm_msg["pub_view"] = Drupal.t("Public download");
83 Webfm.perm_msg["rol_view"] = Drupal.t("Role View/Download");
84 Webfm.perm_msg["rol_att"] = Drupal.t("Role Attach");
85 Webfm.perm_msg["rol_full"] = Drupal.t("Role Full Access");
86
87 Webfm.menu_msg = [];
88 Webfm.menu_msg["mkdir"] = Drupal.t("Create Subdirectory");
89 Webfm.menu_msg["rmdir"] = Drupal.t("Delete Directory");
90 Webfm.menu_msg["rm"] = Drupal.t("Delete File");
91 Webfm.menu_msg["rendir"] = Drupal.t("Rename Directory");
92 Webfm.menu_msg["search"] = Drupal.t("Search Directory");
93 Webfm.menu_msg["ren"] = Drupal.t("Rename File");
94 Webfm.menu_msg["meta"] = Drupal.t("File meta data");
95 Webfm.menu_msg["att"] = Drupal.t("Attach to Node");
96 Webfm.menu_msg["det"] = Drupal.t("Detach from Node");
97 Webfm.menu_msg["dwnld"] = Drupal.t("Download as file");
98 Webfm.menu_msg["view"] = Drupal.t("View file");
99 Webfm.menu_msg["enum"] = Drupal.t("Add file to database");
100 Webfm.menu_msg["denum"] = Drupal.t("Remove file from database");
101 Webfm.menu_msg["perm"] = Drupal.t("File permissions");
102 Webfm.menu_msg["clip"] = Drupal.t("Copy link to clipboard");
103 Webfm.menu_msg["paste"] = Drupal.t("Paste link in editor window");
104 //Do not translate any code below this line
105
106 Webfm.current = null;
107
108 Webfm.dragCont = null;
109 Webfm.metaCont = null;
110 Webfm.contextCont = null;
111 Webfm.searchCont = null;
112 Webfm.debugCont = null
113 Webfm.viewCont = null;
114
115 Webfm.dragStart = null;
116 Webfm.dragging = false;
117 Webfm.oldOnContextMenu = null;
118
119 Webfm.activeDropCont = null;
120 Webfm.dropContainers = [];
121 Webfm.attachContainer = null;
122
123 Webfm.browser = null;
124 Webfm.menuHT = null;
125 Webfm.metadataHT = null;
126 Webfm.dirTreeObj = null;
127 Webfm.dirListObj = null;
128 Webfm.attachObj = null;
129 Webfm.alrtObj = null;
130 Webfm.contextMenuObj = null;
131 Webfm.progressObj = null;
132 Webfm.dbgObj = null;
133 Webfm.metaObj = null;
134 Webfm.searchObj = null;
135 Webfm.permObj = null;
136 Webfm.permKey = null;
137 Webfm.permHT = null;
138 Webfm.permInfoHT = null;
139
140 Webfm.renameActive = null;
141 Webfm.admin = false;
142
143 Webfm.zindex = 1000;
144 Webfm.scrollVal = null; // freeze scroll
145
146 Webfm.eventListeners = [];
147
148 //Name of node edit form hidden field where attached node list is populated by js
149 Webfm.attachFormInput = "edit-attachlist";
150
151 Webfm.icons = {
152 epdf:"pdf", ephp:"php", ephps:"php", ephp4:"php", ephp5:"php", eswf:"swf",
153 esfa:"swf", exls:"xls", eods:"xls", edoc:"doc", ertf:"doc", eodt:"doc", eodd:"doc", ezip:"zip", erar:"zip",
154 egz:"zip", e7z:"zip", etxt:"doc", echm:"hlp", ehlp:"hlp", enfo:"nfo",
155 expi:"xpi", ec:"c", eh:"h", emp3:"mp3", ewav:"mp3", esnd:"mp3", einc:"cod",
156 esql:"sql", edbf:"sql", ediz:"nfo", eion:"nfo", emod:"mp3", es3m:"mp3",
157 eavi:"avi", empg:"avi", empeg:"avi", ewma:"mp3", ewmv:"avi", edwg:"dwg",
158 ejpg:"i", ejpeg:"i", egif:"i", epng:"i", etiff:"i", ebmp:"i", eico:"i",
159 eai:"ai", eskp:"skp", emov:"qt", epps:"pps", eppt:"pps"
160 };
161
162 Webfm.lastarea = null;
163
164 /*
165 ** Functions
166 */
167 if (Drupal.jsEnabled) {
168 $(window).load(webfmLayout);
169 }
170
171 /**
172 * Remember last used textarea for inserting file hrefs.
173 */
174 function webfmSetlast(){
175 Webfm.lastarea = this;
176 }
177
178 /**
179 * Determine browser
180 */
181 Webfm.browserDetect = function() {
182 this.isIE = false;
183 this.isOP = false;
184 var b = navigator.userAgent.toLowerCase();
185 if (b.indexOf("msie") >= 0) {
186 this.isIE = true;
187 }
188 if (b.indexOf("opera") >= 0) {
189 this.isOP = true;
190 }
191 }
192
193 /**
194 * Hashtable (used by directory listing cache and metadata)
195 */
196 Webfm.ht = function() {
197 this.flush();
198 }
199
200 Webfm.ht.prototype.put = function(key, value) {
201 if((key == null) || (value == null))
202 throw "NullPointerException {" + key + "},{" + value + "}";
203
204 this.hash[key] = value;
205 }
206
207 Webfm.ht.prototype.get = function(key) {
208 return this.hash[key];
209 }
210
211 Webfm.ht.prototype.containsKey = function(key) {
212 for(var i in this.hash) {
213 if (i == key && this.hash[i] != null) {
214 return true;
215 }
216 }
217 return false;
218 }
219
220 Webfm.ht.prototype.remove = function(key) {
221 if(this.hash[key]) {
222 this.hash[key] = null;
223 return true;
224 }
225 return false;
226 }
227
228 Webfm.ht.prototype.dump = function() {
229 var values = new Array();
230 for (var i in this.hash) {
231 if (this.hash[i] != null)
232 values.push(this.hash[i]);
233 }
234 return values;
235 }
236
237 Webfm.ht.prototype.flush = function() {
238 this.hash = new Array();
239 }
240
241 /**
242 * Hashable Hashtable (used by menus)
243 */
244 Webfm.hht = function() {
245 this.flush();
246 }
247
248 Webfm.hht.prototype.put = function(key, obj) {
249 if((key == null) || (obj == null))
250 throw "NullPointerException {" + key + "},{" + obj + "}";
251
252 if(this.hash[key] == null) {
253 this.keys[this.keys.length] = key;
254 this.hash[key] = new Array();
255 }
256
257 // append new object to array
258 this.hash[key].push(obj);
259 }
260
261 Webfm.hht.prototype.get = function(key) {
262 return this.hash[key];
263 }
264
265 Webfm.hht.prototype.remove = function(key) {
266 if(this.hash[key]) {
267 this.hash[key] = null;
268 return true;
269 }
270 return false;
271 }
272
273 Webfm.hht.prototype.removeSub = function(key, subkey) {
274 if(this.hash[key][subkey]) {
275 this.hash[key][subkey] = null;
276 return true;
277 }
278 return false;
279 }
280
281 Webfm.hht.prototype.flush = function() {
282 this.hash = new Array();
283 this.keys = new Array();
284 }
285
286 //Webfm.metaElement objects have description/edit/max_size params
287 Webfm.metaElement = function(desc, edit, size) {
288 this.desc = desc;
289 this.edit = edit;
290 this.size = size;
291 }
292
293 /**
294 * Create Web File Manager at 'webfm' id anchor
295 * ..or at node-edit 'webfm-inline' id anchor
296 */
297 function webfmLayout() {
298 // Initialize textarea for pasting file hrefs with the most often used
299 // in case we try to paste before a textarea or -field was focussed.
300 Webfm.lastarea = document.getElementById('edit-body');
301 if (!Webfm.lastarea) {
302 Webfm.lastarea = document.getElementById('edit-comment');
303 }
304 // Tell textareas and text fields to remember which one was last focussed.
305 textareas = document.getElementsByTagName('textarea');
306 i = textareas.length;
307 while( i-- ) {
308 textareas[i].onfocus = webfmSetlast;
309 }
310 textfields = document.getElementsByTagName('input');
311 i = textfields.length;
312 while( i-- ) {
313 if (textfields[i].type=='text') {
314 textfields[i].onfocus = webfmSetlast;
315 }
316 }
317
318 var layoutDiv = '';
319 layoutDiv = Webfm.$('webfm');
320
321 if(layoutDiv) {
322 Webfm.commonInterface(layoutDiv);
323
324 //first param forces trees refresh
325 //second param forces list refresh
326 Webfm.dirTreeObj.fetch(true, true);
327 } else {
328 layoutDiv = Webfm.$('webfm-inline');
329
330 if(layoutDiv) {
331 Webfm.commonInterface(layoutDiv);
332
333 //Add attach-list menu and attach option to listing menu
334 try {
335 Webfm.menuHT.put('file', new Webfm.menuElement(Webfm.menu_msg["att"], Webfm.menuAttach, Webfm.menuFidVal));
336 Webfm.menuHT.put('det', new Webfm.menuElement(Webfm.menu_msg["meta"], Webfm.menuGetMeta, ''));
337 Webfm.menuHT.put('det', new Webfm.menuElement(Webfm.menu_msg["det"], Webfm.menuDetach, ''));
338 Webfm.menuHT.put('det', new Webfm.menuElement(Webfm.menu_msg["paste"], Webfm.menuPasteHref, ''));
339 } catch(err) {
340 alert("Menu Create err\n" + err);
341 }
342
343 // attach-list anchored to 'webfm-attach' div in webfm_form_alter()
344 Webfm.attachObj = new Webfm.attach('webfm-attach');
345 Webfm.attachObj.fetch();
346
347 Webfm.dirTreeObj.fetch(true, true);
348 }
349 }
350 }
351
352 Webfm.commonInterface = function(parent) {
353 Webfm.browser = new Webfm.browserDetect();
354
355 //create the popup container for file/dir object draggables
356 Webfm.dragCont = new Webfm.popup("webfm-dragCont");
357
358 //create the popup container for image view
359 Webfm.viewCont = new Webfm.popup("webfm-viewCont");
360
361 //create context menu popup
362 Webfm.oldOnContextMenu = document.body.oncontextmenu;
363 Webfm.contextCont = new Webfm.popup("webfm-cxtCont");
364 Webfm.contextMenuObj = new Webfm.context(Webfm.contextCont);
365
366 //create metadata popup
367 Webfm.metaCont = new Webfm.popup("webfm-paneCont");
368 Webfm.metaObj = new Webfm.metadata(Webfm.metaCont, 440, 420);
369
370 //create file permissions popup
371 Webfm.permCont = new Webfm.popup("webfm-permCont");
372 Webfm.permObj = new Webfm.perm(Webfm.permCont, 300, 200);
373
374 //create search popup
375 Webfm.searchCont = new Webfm.popup("webfm-searchCont");
376 Webfm.searchObj = new Webfm.search(Webfm.searchCont, 280, 200);
377
378 //create debug popup
379 Webfm.debugCont = new Webfm.popup("webfm-debugCont");
380 Webfm.dbgObj = new Webfm.debug(Webfm.debugCont, 800, 400);
381
382 //build menu hashtable
383 //global to allow external functions to push new menu elements into the menu array
384 Webfm.menuHT = new Webfm.hht();
385 try {
386 Webfm.menuHT.put('root', new Webfm.menuElement(Webfm.menu_msg["mkdir"], Webfm.menuMkdir, Webfm.menuAdmin));
387 Webfm.menuHT.put('root', new Webfm.menuElement(Webfm.menu_msg["search"], Webfm.menuSearch, ''));
388
389 Webfm.menuHT.put('dir', new Webfm.menuElement(Webfm.menu_msg["mkdir"], Webfm.menuMkdir, Webfm.menuAdmin));
390 Webfm.menuHT.put('dir', new Webfm.menuElement(Webfm.menu_msg["rmdir"], Webfm.menuRemove, Webfm.menuAdmin));
391 Webfm.menuHT.put('dir', new Webfm.menuElement(Webfm.menu_msg["rendir"], Webfm.menuRename, Webfm.menuAdmin));
392 Webfm.menuHT.put('dir', new Webfm.menuElement(Webfm.menu_msg["search"], Webfm.menuSearch, ''));
393
394 Webfm.menuHT.put('file', new Webfm.menuElement(Webfm.menu_msg["rm"], Webfm.menuRemove, Webfm.menuFileUid));
395 Webfm.menuHT.put('file', new Webfm.menuElement(Webfm.menu_msg["ren"], Webfm.menuRename, Webfm.menuRenFileUid));
396 Webfm.menuHT.put('file', new Webfm.menuElement(Webfm.menu_msg["meta"], Webfm.menuGetMeta, Webfm.menuFidVal));
397 Webfm.menuHT.put('file', new Webfm.menuElement(Webfm.menu_msg["view"], Webfm.menuView, ''));
398 Webfm.menuHT.put('file', new Webfm.menuElement(Webfm.menu_msg["dwnld"], Webfm.menuDownload, Webfm.menuFidVal));
399 Webfm.menuHT.put('file', new Webfm.menuElement(Webfm.menu_msg["enum"], Webfm.menuInsert, Webfm.menuAdminNoFidVal));
400 Webfm.menuHT.put('file', new Webfm.menuElement(Webfm.menu_msg["denum"], Webfm.menuDbRem, Webfm.menuAdminFidVal));
401 Webfm.menuHT.put('file', new Webfm.menuElement(Webfm.menu_msg["perm"], Webfm.menuGetPerm, Webfm.menuFilePerm));
402 Webfm.menuHT.put('file', new Webfm.menuElement(Webfm.menu_msg["paste"], Webfm.menuPasteHref, ''));
403 Webfm.menuHT.put('file', new Webfm.menuElement(Webfm.menu_msg["clip"], Webfm.menuPutLinkInClipboard, ''))
404 } catch(err) {
405 alert("Menu Create err\n" + err);
406 }
407
408 //build metadata hashtable
409 //Webfm.metaElement objects have description/edit/max_size properties
410 Webfm.metadataHT = new Webfm.ht();
411 Webfm.metadataHT.put('id',new Webfm.metaElement(Webfm.meta_msg["fid"], false,0 ));
412 Webfm.metadataHT.put('u', new Webfm.metaElement(Webfm.meta_msg["uid"], true, 10 ));
413 Webfm.metadataHT.put('un',new Webfm.metaElement(Webfm.meta_msg["uname"], false,0 ));
414 Webfm.metadataHT.put('n', new Webfm.metaElement(Webfm.meta_msg["name"], false,0 ));
415 Webfm.metadataHT.put('t', new Webfm.metaElement(Webfm.meta_msg["title"], true, 255));
416 Webfm.metadataHT.put('d', new Webfm.metaElement(Webfm.meta_msg["desc"], true, 256));
417 Webfm.metadataHT.put('l', new Webfm.metaElement(Webfm.meta_msg["lang"], true, 16 ));
418 Webfm.metadataHT.put('p', new Webfm.metaElement(Webfm.meta_msg["pub"], true, 255));
419 Webfm.metadataHT.put('f', new Webfm.metaElement(Webfm.meta_msg["format"],true, 255));
420 Webfm.metadataHT.put('v', new Webfm.metaElement(Webfm.meta_msg["ver"], false,0 ));
421 Webfm.metadataHT.put('i', new Webfm.metaElement(Webfm.meta_msg["type"], false,0 ));
422 Webfm.metadataHT.put('w', new Webfm.metaElement(Webfm.meta_msg["width"], false,0 ));
423 Webfm.metadataHT.put('h', new Webfm.metaElement(Webfm.meta_msg["height"],false,0 ));
424 Webfm.metadataHT.put('c', new Webfm.metaElement(Webfm.meta_msg["dl_cnt"],false,0 ));
425 Webfm.metadataHT.put('lk', new Webfm.metaElement(Webfm.meta_msg["link"], false,0 ));
426
427 //build permissions hashtable
428 //key is permission bit, value is string
429 Webfm.permInfoHT = new Webfm.ht();
430 Webfm.permInfoHT.put("id", Webfm.meta_msg["fid"]);
431 Webfm.permInfoHT.put("u", Webfm.meta_msg["uid"]);
432 Webfm.permInfoHT.put("n", Webfm.meta_msg["name"]);
433 Webfm.permKey = new Array('1', '2', '4', '8');
434 Webfm.permHT = new Webfm.ht();
435 Webfm.permHT.put('1', Webfm.perm_msg["pub_view"]);
436 Webfm.permHT.put('2', Webfm.perm_msg["rol_view"]);
437 Webfm.permHT.put('4', Webfm.perm_msg["rol_att"] );
438 Webfm.permHT.put('8', Webfm.perm_msg["rol_full"]);
439
440 var layout_cont = Webfm.ce('div');
441 Webfm.alrtObj = new Webfm.alert(layout_cont, 'webfm-alert');
442
443 //Container for tree(s)
444 var elTreeDiv = Webfm.ce('div');
445 elTreeDiv.setAttribute('id', 'webfm-tree'); //css id
446 layout_cont.appendChild(elTreeDiv);
447 Webfm.dirTreeObj = new Webfm.treeBuilder(elTreeDiv, Webfm.menuHT.get('root'), Webfm.menuHT.get('dir'));
448
449 //progress indicator
450 Webfm.progressObj = new Webfm.progress(layout_cont, 'webfm-progress');
451
452 //Directory Listing
453 Webfm.dirListObj = new Webfm.list(layout_cont, 'webfm-dirlist', 'file', 'narrow', true, Webfm.menuHT.get('dir'), Webfm.menuHT.get('file'));
454
455 //insert trees, listing, search, metadata, progress and alert divs before upload fset built in php
456 parent.insertBefore(layout_cont, parent.firstChild);
457 // parent.appendChild(layout_cont); //If upload desired to be placed above browser
458
459 webfmUploadAutoAttach();
460 }
461
462 //Attaches the upload behaviour to the upload form (borrowed jquery).
463 function webfmUploadAutoAttach(){
464 $('input.webfmupload').each(function () {
465 var uri = this.value;
466 var button = 'wfmatt-button';
467 var wrapper = 'wfmatt-wrapper';
468 var hide = 'wfmatt-hide';
469 var upload = new Webfm.jsUpload(uri, button, wrapper, hide);
470 });
471 }
472
473 /**
474 * Webfm.jsUpload constructor
475 * 1st param is upload iframe url
476 * 2nd param is id of redirected button object)
477 * 3rd param is id of container of html repainted by ajax
478 * 4th param is id of upload input field
479 * TODO: fix progress throbber
480 */
481 Webfm.jsUpload = function(uri, button, wrapper, hide) {
482 // Note: these elements are replaced after an upload, so we re-select them
483 // everytime they are needed.
484 this.button = '#'+ button;
485 this.wrapper = '#'+ wrapper;
486 this.hide = '#'+ hide;
487 Drupal.redirectFormButton(uri, $(this.button).get(0), this);
488 }
489
490 //Handler for the form redirection submission.
491 Webfm.jsUpload.prototype.onsubmit = function () {
492 Webfm.progressObj.show(Webfm.js_msg["work"], "blue");
493 var hide = this.hide;
494 $(hide).fadeOut('slow');
495 }
496
497 //Handler for the form redirection completion.
498 Webfm.jsUpload.prototype.oncomplete = function (data) {
499 // Remove old form
500 Drupal.freezeHeight(); // Avoid unnecessary scrolling
501 $(this.wrapper).html('');
502
503 // Place HTML into temporary div
504 var div = document.createElement('div');
505 $(div).html(data['html']);
506 $(this.wrapper).append(div);
507
508 //div with id='replace-options' present only in case of file overwrite
509 this.confirm = Webfm.$('replace-options');
510 if(this.confirm) {
511 var hide = this.hide;
512 $(hide).fadeOut('slow');
513 var cp = this;
514 this.confirm.id = 'replace-options';
515 var replaceButton = Webfm.ce('input');
516 replaceButton.setAttribute('type', 'button');
517 replaceButton.setAttribute('value', Webfm.js_msg["submit"]);
518 var listener = Webfm.eventListenerAdd(Webfm.eventListeners, replaceButton, "click", function(e) { cp.submit(); Webfm.stopEvent(e); });
519 this.confirm.appendChild(replaceButton);
520 this.confirm.file = data['file'];
521 } else {
522 $(this.hide, div).fadeIn('slow');
523 webfmUploadAutoAttach();
524 }
525
526 Drupal.unfreezeHeight();
527 Webfm.progressObj.hide();
528
529 Webfm.dirListObj.refresh();
530 if(typeof Webfm.$('webfm-inline') != 'undefined') {
531 // attach file to node if inside node-edit
532 if(typeof data['fid'] != 'undefined') {
533 Webfm.menuAttach(null, data['fid']);
534 }
535 }
536 }
537
538 //Handler for the form redirection error.
539 Webfm.jsUpload.prototype.onerror = function (error) {
540 alert('An error occurred:\n\n'+ error);
541 Webfm.progressObj.hide();
542 if(this.confirm)
543 Webfm.clearNodeById('replace-options');
544 // Undo hide
545 $(this.hide).css({
546 position: 'static',
547 left: '0px'
548 });
549 }
550
551 Webfm.jsUpload.prototype.submit = function () {
552 var inputs = [];
553 inputs = this.confirm.getElementsByTagName('input');
554 var selection = '';
555 for(var i = 0; i < inputs.length; i++) {
556 if(inputs[i].checked == true) {
557 selection = i;
558 break;
559 }
560 }
561 if(typeof selection != 'undefined') {
562 var url = Webfm.ajaxUrl();
563 Webfm.progressObj.show(Webfm.js_msg["work"], "blue");
564 var postObj = { action:encodeURIComponent("version"), param0:encodeURIComponent(selection), param1:encodeURIComponent(this.confirm.file)};
565 Webfm.HTTPPost(url, this.callback, this, postObj);
566 }
567 }
568
569 Webfm.jsUpload.prototype.callback = function(string, xmlhttp, cp) {
570 Webfm.progressObj.hide();
571 // Remove overwrite radios
572 var parent = cp.confirm.parentNode;
573 parent.removeChild(parent.firstChild);
574 var hide = cp.hide;
575 if (xmlhttp.status == 200) {
576 var result = Drupal.parseJson(string);
577
578 if(result.status) {
579 Webfm.dirListObj.refresh();
580 }
581 cp.confirm.style.display = 'none';
582 // Insert ajax feedback before upload form
583 var elDiv = Webfm.ce('div');
584 if(result.status) {
585 elDiv.className = 'upload-msg';
586 } else {
587 elDiv.className = 'upload-msg-err';
588 }
589 elDiv.appendChild(Webfm.ctn(result.data['msg']));
590 $(hide).before($(elDiv));
591
592 // Undo hide
593 Webfm.dbgObj.dbg("hide:", Webfm.dump(hide));
594 $(hide).css({ display: 'block' });
595 webfmUploadAutoAttach();
596
597 if(typeof Webfm.$('webfm-inline') != 'undefined') {
598 // attach file to node if inside node-edit
599 if(typeof result.data['fid'] != 'undefined') {
600 Webfm.menuAttach(null, result.data['fid']);
601 }
602 }
603 } else {
604 Webfm.alrtObj.msg(Webfm.js_msg["ajax-err"]);
605 }
606 }
607
608 /**
609 * Webfm.list constructor
610 * 1st param is object to append this list object to
611 * 2nd param is base id of listing (multiple listing objects must have unique ids)
612 * 3rd param is base id of file rows of table
613 * 4th param sets styling for listing
614 * 5th param enables drag and drop
615 * 6th param is directory menu array
616 * 7th param is file menu array
617 */
618 Webfm.list = function(parent, id, type, class_name, dd_enable, dir_menu, file_menu) {
619 var wl = this;
620 this.id = id;
621 this.type = type;
622 this.dd_enable = dd_enable;
623 this.url = Webfm.ajaxUrl();
624 this.sc_n = 0;
625 this.sc_m = 0;
626 this.sc_s = 0;
627 this.content = '';
628 this.iconDir = getWebfmIconDir();
629 this.dir_menu = dir_menu;
630 this.file_menu = file_menu;
631 //directory cache hashtable (key= directory path, val= directory contents)
632 this.cache = new Webfm.ht();
633 this.eventListeners = []
634
635 var node = Webfm.ce("div");
636 node.setAttribute('id', this.id);
637 node.className = class_name;
638 this.obj = node;
639
640 var elTable = Webfm.ce('table');
641 var elTableBody = Webfm.ce('tbody');
642 // elTableBody.setAttribute('id', this.id + 'body');
643 this.body = elTableBody;
644
645 // First Row
646 var elTr = Webfm.ce('tr');
647 elTr.setAttribute('id','webfm-top-tr');
648
649 // Refresh Icon
650 var elTd = Webfm.ce('td');
651 elTd.className = 'navi';
652 var elA = Webfm.ce('a');
653 elA.setAttribute('href', '#');
654 elA.setAttribute('title', Webfm.js_msg["refresh"]);
655 var elImg = Webfm.ce('img');
656 elImg.setAttribute('src', this.iconDir+ '/r.gif');
657 elImg.setAttribute('alt', Webfm.js_msg["refresh"]);
658 elA.appendChild(elImg);
659 elTd.appendChild(elA);
660 elTr.appendChild(elTd);
661 var listener = Webfm.eventListenerAdd(Webfm.eventListeners, elA, "click", function(e) { wl.refresh(Webfm.current);Webfm.stopEvent(e); });
662
663 // Breadcrumb trail
664 var elTd = Webfm.ce('td');
665 elTd.colSpan = getWebfmOwnerColumn() ? 4 : 3
666 elTd.setAttribute('id','webfm-bcrumb-td');
667 elTd.setAttribute('class','navi');
668 // Build breadcrumb trail inside span
669 var elSpan = Webfm.ce('span');
670 elSpan.setAttribute('id', this.id + 'bcrumb');
671 elTd.appendChild(elSpan);
672 elTr.appendChild(elTd);
673
674 elTableBody.appendChild(elTr);
675
676 // Second Row
677 var elTr = Webfm.ce('tr');
678 this.secondRow = elTr;
679
680 // icon column
681 var elTd = Webfm.ce('td');
682 elTd.className = 'head';
683 elTr.appendChild(elTd);
684
685 // Sort dir/files column
686 var elTd = Webfm.ce('td');
687 elTd.className = 'head';
688 var elA = Webfm.ce('a');
689 elA.setAttribute('href', '#');
690 elA.setAttribute('title', Webfm.js_msg["sort"]);
691 var listener = Webfm.eventListenerAdd(Webfm.eventListeners, elA, "click", function(e) { wl.sc_n^=1;wl.loadList("n");wl.sortIcon(e,wl.sc_n);Webfm.stopEvent(e); });
692
693 var elImg = Webfm.ce('img');
694 elImg.setAttribute('alt', Webfm.js_msg["sort"]);
695 elImg.setAttribute('src', this.iconDir + '/down.gif');
696 elA.appendChild(elImg);
697 elA.appendChild(Webfm.ctn(Webfm.js_msg["column1"]));
698 elTd.appendChild(elA);
699 elTr.appendChild(elTd);
700
701 // date/time column
702 var elTd = Webfm.ce('td');
703 elTd.className = 'head';
704 var elA = Webfm.ce('a');
705 elA.setAttribute('href', '#');
706 var listener = Webfm.eventListenerAdd(Webfm.eventListeners, elA, "click", function(e) { wl.sc_m^=1;wl.loadList("m");wl.sortIcon(e,wl.sc_m);Webfm.stopEvent(e); });
707
708 var elImg = Webfm.ce('img');
709 elImg.setAttribute('alt', Webfm.js_msg["sort"]);
710 elImg.setAttribute('src', this.iconDir + '/down.gif');
711 elA.appendChild(elImg);
712 elA.appendChild(Webfm.ctn(Webfm.js_msg["column2"]));
713 elTd.appendChild(elA);
714 elTr.appendChild(elTd);
715
716 // size column
717 var elTd = Webfm.ce('td');
718 elTd.className = 'head';
719 var elA = Webfm.ce('a');
720 elA.setAttribute('href', '#');
721 var listener = Webfm.eventListenerAdd(Webfm.eventListeners, elA, "click", function(e) { wl.sc_s^=1;wl.loadList("s");wl.sortIcon(e,wl.sc_s);Webfm.stopEvent(e); });
722
723 var elImg = Webfm.ce('img');
724 elImg.setAttribute('alt', Webfm.js_msg["sort"]);
725 elImg.setAttribute('src', this.iconDir + '/down.gif');
726 elA.appendChild(elImg);
727 elA.appendChild(Webfm.ctn(Webfm.js_msg["column3"]));
728 elTd.appendChild(elA);
729 elTr.appendChild(elTd);
730
731 // owner column
732 if(getWebfmOwnerColumn()) {
733 var elTd = Webfm.ce('td');
734 elTd.className = 'head';
735 var elA = Webfm.ce('a');
736 elA.setAttribute('href', '#');
737 var listener = Webfm.eventListenerAdd(Webfm.eventListeners, elA, "click", function(e) { wl.sc_o^=1;wl.loadList("o");wl.sortIcon(e,wl.sc_o);Webfm.stopEvent(e); });
738
739 var elImg = Webfm.ce('img');
740 elImg.setAttribute('alt', Webfm.js_msg["sort"]);
741 elImg.setAttribute('src', this.iconDir + '/down.gif');
742 elA.appendChild(elImg);
743 elA.appendChild(Webfm.ctn(Webfm.js_msg["column4"]));
744 elTd.appendChild(elA);
745 elTr.appendChild(elTd);
746 }
747
748 elTableBody.appendChild(elTr);
749
750 elTable.appendChild(elTableBody);
751 node.appendChild(elTable);
752 parent.appendChild(node);
753 }
754
755 Webfm.list.prototype.bcrumb = function() {
756 var cp = this;
757 Webfm.clearNodeById(this.id + 'bcrumb');
758 elSpan = Webfm.$(this.id + 'bcrumb');
759 var pth = [];
760 for(var i = 0; i < this.content.bcrumb.length - 1; i++) {
761 pth.push(this.content.bcrumb[i]);
762 elSpan.appendChild(Webfm.ctn(" / "));
763 // No breadcrumb link necessary for current directory
764 var elA = Webfm.ce('a');
765 elA.setAttribute('href', '#');
766 // join previous loop iterations to create path for title
767 elA.setAttribute('title', "/" + pth.join("/"));
768 elA.appendChild(Webfm.ctn(this.content.bcrumb[i]));
769 //IE fix
770 var listener = Webfm.eventListenerAdd(Webfm.eventListeners, elA, "click", function(e) { cp.selectBC(e);Webfm.stopEvent(e); });
771 elSpan.appendChild(elA);
772 }
773 elSpan.appendChild(Webfm.ctn(" / "));
774 elSpan.appendChild(Webfm.ctn(this.content.bcrumb[i]));
775 }
776
777 Webfm.list.prototype.selectBC = function(event) {
778 var el = event.target||window.event.srcElement;
779 Webfm.selectDir(el.title);
780 }
781
782 Webfm.list.prototype.sortIcon = function(event, up_down) {
783 var el = event.target||window.event.srcElement;
784 if(el.firstChild) {
785 el.firstChild.src = this.iconDir + '/' + (up_down?"up":"down") + '.gif';
786 }
787 }
788
789 Webfm.list.prototype.refresh = function(path, rename_dir) {
790 if(path == null)
791 path = Webfm.current;
792 this.cache.remove(path);
793 if(typeof rename_dir != 'undefined') {
794 this.rename_dir = rename_dir;
795 }
796 this.fetch(path);
797 }
798
799 Webfm.list.prototype.fetch = function(curr_dir) {
800 Webfm.alrtObj.msg();
801 if(curr_dir || (curr_dir = Webfm.current)) {
802 Webfm.progressObj.show(Webfm.js_msg["work"], "blue");
803 //update current dir if specific dir selected
804 Webfm.current = curr_dir;
805 Webfm.dbgObj.dbg('fetch: ', curr_dir);
806
807 if(this.cache.containsKey(Webfm.current)) {
808 Webfm.dbgObj.dbg('cache hit: ', Webfm.current);
809 this.content = this.cache.get(Webfm.current);
810 this.bcrumb();
811 this.loadList();
812 var uploadpath = Webfm.$('edit-webfmuploadpath');
813 if(uploadpath) {
814 uploadpath.value = Webfm.current;
815 }
816 Webfm.progressObj.hide();
817 } else {
818 Webfm.admin = false;
819 var postObj = { action:encodeURIComponent("read"), param0:encodeURIComponent(curr_dir) };
820 Webfm.HTTPPost(this.url, this.callback, this, postObj);
821 }
822 } else {
823 Webfm.dbgObj.dbg(Webfm.js_msg["curdir-undef"]);
824 }
825 }
826
827 Webfm.list.prototype.callback = function(string, xmlhttp, cp) {
828 Webfm.progressObj.hide();
829 if (xmlhttp.status == 200) {
830 cp.content = Drupal.parseJson(string);
831 if(cp.content.status) {
832 cp.cache.put(cp.content.current, cp.content);
833 //Sets client permissions - server will always validate any action
834 Webfm.admin = cp.content.admin;
835
836 cp.bcrumb();
837 cp.loadList("n");
838
839 // Insert current directory path into upload form
840 var uploadpath = Webfm.$('edit-webfmuploadpath');
841 if(uploadpath) {
842 uploadpath.value = cp.content.current;
843 Webfm.dbgObj.dbg('uploadpath: ', uploadpath.value);
844 }
845 Webfm.current = cp.content.current;
846 cp.adminCtl(Webfm.admin);
847
848 if(cp.rename_dir) {
849 var found = false;
850 for(var i = 0; i < Webfm.dirListObj.dirrows.length; i++) {
851 if(cp.dirrows[i].clickObj.title == "/" + cp.rename_dir) {
852 found = true;
853 break;
854 }
855 }
856 if(found)
857 Webfm.menuRename(cp.dirrows[i]);
858 }
859 } else {
860 Webfm.alrtObj.str_arr(cp.content.data);
861 }
862 } else {
863 Webfm.alrtObj.msg(Webfm.js_msg["ajax-err"]);
864 }
865 }
866
867 //build admin icons for create dir and file db insertion
868 //maintain 4 column table
869 Webfm.list.prototype.adminCtl = function(admin) {
870 col_span = getWebfmOwnerColumn() ? 4 : 3
871 if(admin) {
872 if(Webfm.$('webfm-bcrumb-td').colSpan == col_span) {
873 var wl = this;
874 Webfm.$('webfm-bcrumb-td').colSpan = col_span - 1;
875 // Create New Directory and allow db insertions
876 var elTd = Webfm.ce('td');
877 var elSpan = Webfm.ce('span');
878 elSpan.id = this.id + "-ctls";
879
880 var elA = Webfm.ce('a');
881 elA.title = Webfm.js_msg["new-dir"];
882 var elImg = Webfm.ce('img');
883 elImg.setAttribute('alt', Webfm.js_msg["new-dir"]);
884 elImg.setAttribute('src', this.iconDir + '/dn.gif');
885 elA.appendChild(elImg);
886 var listener = Webfm.eventListenerAdd(Webfm.eventListeners, elA, "click", function(e) { Webfm.stopEvent(e);wl.mkdir(); });
887 var listener = Webfm.eventListenerAdd(Webfm.eventListeners, elA, "mouseover", function(e) { wl.hover(e, true, 0); });
888 var listener = Webfm.eventListenerAdd(Webfm.eventListeners, elA, "mouseout", function(e) { wl.hover(e, false, 0); });
889 elSpan.appendChild(elA);
890
891 var elA = Webfm.ce('a');
892 elA.title = Webfm.js_msg["add-2-db"];
893 var elImg = Webfm.ce('img');
894 elImg.setAttribute('alt', Webfm.js_msg["add-2-db"]);
895 elImg.setAttribute('src', this.iconDir + '/add_loc.gif');
896 elA.appendChild(elImg);
897 var listener = Webfm.eventListenerAdd(Webfm.eventListeners, elA, "click", function(e) { Webfm.stopEvent(e);wl.enumLocal(); });
898 var listener = Webfm.eventListenerAdd(Webfm.eventListeners, elA, "mouseover", function(e) { wl.hover(e, true); });
899 var listener = Webfm.eventListenerAdd(Webfm.eventListeners, elA, "mouseout", function(e) { wl.hover(e, false); });
900 elSpan.appendChild(elA);
901
902 var elA = Webfm.ce('a');
903 elA.title = Webfm.js_msg["r-add-2-db"];
904 var elImg = Webfm.ce('img');
905 elImg.setAttribute('alt', Webfm.js_msg["r-add-2-db"]);
906 elImg.setAttribute('src', this.iconDir + '/add_recur.gif');
907 elA.appendChild(elImg);
908