| 1 |
/**
|
| 2 |
* Expand subdirectories withing filebrowser, using http requests to the server
|
| 3 |
* This code is very dependant on the exact HTML of the table it works upon.
|
| 4 |
* The trigger should be the first cell, and should contain an anchor referencing
|
| 5 |
* the file URL, and an empty tag where the +/- symbol can be displayed
|
| 6 |
*
|
| 7 |
* @author dman
|
| 8 |
* $Id: filebrowser.js,v 1.1.2.2 2006/09/23 01:01:42 dman Exp $
|
| 9 |
*/
|
| 10 |
|
| 11 |
if (isJsEnabled()) {
|
| 12 |
addLoadEvent(filebrowserAutoAttach);
|
| 13 |
}
|
| 14 |
|
| 15 |
/**
|
| 16 |
* Attaches the expand behaviour to the filebrowser row.
|
| 17 |
*/
|
| 18 |
function filebrowserAutoAttach() {
|
| 19 |
filebrowserAutoAttachTo('span');
|
| 20 |
filebrowserAutoAttachTo('td');
|
| 21 |
}
|
| 22 |
|
| 23 |
function filebrowserAutoAttachTo(tagName) {
|
| 24 |
var cells = document.getElementsByTagName(tagName);
|
| 25 |
if(!cells)return;
|
| 26 |
for (var i = 0; cell = cells[i]; i++) {
|
| 27 |
if(!cell) continue
|
| 28 |
marker = cell.firstChild;
|
| 29 |
if(marker)marker = marker.nextSibling;
|
| 30 |
if(marker && ! hasClass(marker, 'expando')){ marker = 0 }
|
| 31 |
|
| 32 |
if (hasClass(cell, 'fileBrowserExpand')) {
|
| 33 |
cell.onclick = expand_filebrowser;
|
| 34 |
if(marker){
|
| 35 |
marker.innerHTML = '+';
|
| 36 |
marker.setAttribute('title','expand');
|
| 37 |
} // else alert("No Marker ... "+cell.outerHTML)
|
| 38 |
}
|
| 39 |
if (hasClass(cell, 'fileBrowserContract')) {
|
| 40 |
cell.onclick = contract_filebrowser;
|
| 41 |
if(marker){
|
| 42 |
marker.innerHTML = '-';
|
| 43 |
marker.setAttribute('title','contract');
|
| 44 |
}
|
| 45 |
}
|
| 46 |
if (hasClass(cell, 'fileBrowserUp')) {
|
| 47 |
cell.onclick = shiftup_filebrowser;
|
| 48 |
if(marker){
|
| 49 |
marker.innerHTML = '^';
|
| 50 |
marker.setAttribute('title','up');
|
| 51 |
}
|
| 52 |
}
|
| 53 |
if (hasClass(cell, 'fileBrowserToggle')) {
|
| 54 |
cell.onclick = toggle_filebrowser;
|
| 55 |
}
|
| 56 |
}
|
| 57 |
}
|
| 58 |
|
| 59 |
|
| 60 |
/**
|
| 61 |
* Event handler. ID the context, set a progress bar and make the request
|
| 62 |
*/
|
| 63 |
function expand_filebrowser(trigger){
|
| 64 |
trigger = trigger? trigger : this;
|
| 65 |
if(trigger.target){trigger=trigger.target;}
|
| 66 |
// work up to the td this click came from. That's the trigger we hinge on.
|
| 67 |
while ((trigger.nodeName!='TD')&&(trigger.nodeName!='SPAN')&&(trigger=trigger.parentNode)){;}
|
| 68 |
|
| 69 |
var link = trigger.firstChild;
|
| 70 |
var uri = link.getAttribute('href')+'&d='+new Date();
|
| 71 |
// date suffix avoids some abberant http request caching
|
| 72 |
|
| 73 |
var row = trigger.parentNode;
|
| 74 |
var rowid = trigger.id + '_row';
|
| 75 |
row.id = rowid;
|
| 76 |
wrapperid = trigger.id+'_content';
|
| 77 |
|
| 78 |
if($(wrapperid)) contract_filebrowser(trigger); // remove an old one?
|
| 79 |
|
| 80 |
// Create space to put the new stuff into
|
| 81 |
// This is done differently for LIs vs TRs
|
| 82 |
switch(row.nodeName){
|
| 83 |
case 'LI' :
|
| 84 |
wrapper = document.createElement('div');
|
| 85 |
row.appendChild(wrapper);
|
| 86 |
break;
|
| 87 |
case 'TR' :
|
| 88 |
tr = document.createElement('tr');
|
| 89 |
tr.setAttribute('id',trigger.id+'_content_row')
|
| 90 |
if(after = row.nextSibling)
|
| 91 |
row.parentNode.insertBefore(tr,after);
|
| 92 |
else
|
| 93 |
row.parentNode.appendChild(tr);
|
| 94 |
td = document.createElement('td');
|
| 95 |
tr.appendChild(td);
|
| 96 |
// layout goes hoopy if I depend too much on accurate colspans in IE
|
| 97 |
wrapper = document.createElement('td');
|
| 98 |
wrapper.setAttribute('colSpan',row.childNodes.length-1);
|
| 99 |
tr.appendChild(wrapper);
|
| 100 |
break;
|
| 101 |
}
|
| 102 |
|
| 103 |
wrapper.setAttribute('id',wrapperid);
|
| 104 |
|
| 105 |
trigger.progress = add_progress_bar(wrapper);
|
| 106 |
wrapper.trigger = trigger;
|
| 107 |
|
| 108 |
// window.open(uri,'new');
|
| 109 |
trigger.onclick = null; // prevent double-click
|
| 110 |
HTTPGet(uri, display_subdirectory, wrapperid)
|
| 111 |
}
|
| 112 |
|
| 113 |
function add_progress_bar(wrapper){
|
| 114 |
wrapper.progress = new progressBar('uploadprogress');
|
| 115 |
wrapper.progress.setProgress(-1, '');
|
| 116 |
wrapper.progress.element.style.width = '100%';
|
| 117 |
wrapper.progress.element.style.height = wrapper.offsetHeight/2 +'px';
|
| 118 |
wrapper.style.height = '10px';
|
| 119 |
wrapper.appendChild(wrapper.progress.element);
|
| 120 |
return wrapper.progress;
|
| 121 |
}
|
| 122 |
|
| 123 |
/**
|
| 124 |
* Content has arrived, place it inline
|
| 125 |
*/
|
| 126 |
function display_subdirectory(response, handle, wrapperid){
|
| 127 |
wrapper = $(wrapperid)
|
| 128 |
if(!wrapper){alert("No "+wrapperid+" to put directory listing in.\nSomething went wrong with the formatting.");return;}
|
| 129 |
if(wrapper.progress)
|
| 130 |
removeNode(wrapper.progress.element);
|
| 131 |
wrapper.progress = null;
|
| 132 |
wrapper.style.height = 'auto'; // needed to allow it to expand again
|
| 133 |
try{
|
| 134 |
if(response) wrapper.innerHTML = response;
|
| 135 |
else alert("Bad (null) response from request")
|
| 136 |
} catch(e) {
|
| 137 |
clipboardData.setData("Text", response);
|
| 138 |
alert( "Unable to insert response in the document. The returned HTML may not be valid to put there.\nThe problem HTML was copied to clipboard for reference." );
|
| 139 |
}
|
| 140 |
|
| 141 |
if(wrapper.trigger){
|
| 142 |
wrapper.trigger.className = 'fileBrowserContract list_expander';
|
| 143 |
}
|
| 144 |
|
| 145 |
// Need to do this again to apply events to the new markup
|
| 146 |
filebrowserAutoAttach();
|
| 147 |
if(typeof(toggleTreeAutoAttach)=='function')toggleTreeAutoAttach();
|
| 148 |
return;
|
| 149 |
}
|
| 150 |
|
| 151 |
/**
|
| 152 |
* Event handler for clicking '-' - remove the subdir content and toggle action back to 'expand'
|
| 153 |
*/
|
| 154 |
function contract_filebrowser(trigger){
|
| 155 |
trigger = trigger? trigger : this;
|
| 156 |
if(trigger.target){trigger=trigger.target;}
|
| 157 |
while ((trigger.nodeName!='TD')&&(trigger.nodeName!='SPAN')&&(trigger=trigger.parentNode)){;}
|
| 158 |
var row = trigger.parentNode;
|
| 159 |
|
| 160 |
if(wrapper = $(trigger.id+'_content')) // li version
|
| 161 |
wrapper.parentNode.removeChild(wrapper);
|
| 162 |
|
| 163 |
if(wrapper = $(trigger.id+'_content_row')) // table version
|
| 164 |
wrapper.parentNode.removeChild(wrapper);
|
| 165 |
|
| 166 |
trigger.className = 'fileBrowserExpand list_expander';
|
| 167 |
filebrowserAutoAttach()
|
| 168 |
}
|
| 169 |
|
| 170 |
function toggle_filebrowser(trigger){
|
| 171 |
trigger = trigger? trigger : this;
|
| 172 |
if(trigger.target){trigger=trigger.target;}
|
| 173 |
// work up to the tr, and down to the first td (in case trigger was launched from another cell)
|
| 174 |
while ((trigger.nodeName!='TR')&&(trigger.nodeName!='LI')&&(trigger=trigger.parentNode)){;}
|
| 175 |
// now scan the current row to find the right trigger that holds the expando code
|
| 176 |
expando = trigger.firstChild;
|
| 177 |
while (expando){
|
| 178 |
if (hasClass(expando, 'fileBrowserExpand')) {expand_filebrowser(expando)}
|
| 179 |
else if (hasClass(expando, 'fileBrowserContract')) {contract_filebrowser(expando)}
|
| 180 |
expando = expando.nextSibling;
|
| 181 |
}
|
| 182 |
}
|
| 183 |
|
| 184 |
/**
|
| 185 |
* Tricky. Replace the container of the trigger with a list of this items parents.
|
| 186 |
*/
|
| 187 |
function shiftup_filebrowser(trigger){
|
| 188 |
trigger = trigger? trigger : this;
|
| 189 |
if(trigger.target){trigger=trigger.target;}
|
| 190 |
while ((trigger.nodeName!='TD')&&(trigger=trigger.parentNode)){;}
|
| 191 |
var link = trigger.firstChild;
|
| 192 |
var uri = link.getAttribute('href')+'&d='+new Date();
|
| 193 |
|
| 194 |
// Now find current containing table
|
| 195 |
var container = trigger;
|
| 196 |
while ((container.nodeName!='TABLE')&&(container=container.parentNode)){;}
|
| 197 |
container=container.parentNode;
|
| 198 |
wrapperid = container.getAttribute('id');
|
| 199 |
if(! wrapperid){
|
| 200 |
wrapperid = 'up-target'
|
| 201 |
container.setAttribute('id',wrapperid);
|
| 202 |
}
|
| 203 |
|
| 204 |
p = new progressBar('uploadprogress');
|
| 205 |
p.setProgress(-1, '');
|
| 206 |
p.element.style.width = '100%';
|
| 207 |
container.appendChild(p.element);
|
| 208 |
container.progress = p;
|
| 209 |
|
| 210 |
trigger.onclick = null; // prevent double-click
|
| 211 |
HTTPGet(uri, display_subdirectory, wrapperid)
|
| 212 |
}
|
| 213 |
|