d427939092dc4b4e382aec5fbe7e2988a5ee95d8
1 // (c) BenoƮt PIN 2006-2007
7 var FolderDDropControler
;
14 function getTargetRow(evt
){
15 var target
= getTargetedObject(evt
);
16 while (target
.nodeName
!= "TR")
17 target
= target
.parentNode
;
21 FolderDDropControler = function(listing
) {
22 this.folderUrl
= document
.getElementById("FolderUrl").innerHTML
;
23 this.targetRow
= null;
24 this.lastOverPosition
= null;
25 this.prevDirUp
= null;
27 this.listing
= listing
;
28 var thisControler
= this;
29 this.listing
.onmousedown = function(evt
) {thisControler
.drag(evt
);};
30 this.listing
.onmouseover = function(evt
) {thisControler
.moveRow(evt
);};
31 this.listing
.onmouseup = function(evt
) {thisControler
.drop(evt
);};
32 this.listing
.onclick = function(evt
) {thisControler
.disableClickAfterDrop(evt
);};
35 this.listing
.ondragstart = function() { window
.event
.returnValue
= false;};
39 FolderDDropControler
.prototype.drag = function(evt
){
40 var target
= getTargetedObject(evt
);
41 if (target
.nodeName
== "INPUT") return true;
43 var targetRow
= getTargetRow(evt
);
44 targetRow
.style
.backgroundColor
= base_properties
["highLightColor"];
45 this.listing
.style
.cursor
= "move";
46 this.targetRow
= targetRow
;
47 this.lastOverPosition
= targetRow
.pos
;
50 FolderDDropControler
.prototype.moveRow = function(evt
){
51 var targetRow
= this.targetRow
;
52 if (targetRow
!= null) {
54 if (browser
.isIE
) document
.selection
.clear();
55 var overRow
= getTargetRow(evt
);
57 if (overRow
.pos
== targetRow
.pos
) return;
59 if (this.lastOverPosition
< overRow
.pos
) { // move up
60 this.listing
.insertBefore(targetRow
, overRow
.nextSibling
);
61 this.prevDirUp
= true;
62 this.lastOverPosition
= overRow
.pos
;
64 else if (this.lastOverPosition
> overRow
.pos
) { // move down
65 this.listing
.insertBefore(targetRow
, overRow
);
66 this.prevDirUp
= false;
67 this.lastOverPosition
= overRow
.pos
;
71 this.prevDirUp
= false;
72 this.listing
.insertBefore(targetRow
, overRow
);
75 this.prevDirUp
= true;
76 this.listing
.insertBefore(targetRow
, overRow
.nextSibling
);
82 FolderDDropControler
.prototype.drop = function(evt
){
83 var targetRow
= this.targetRow
;
84 if (targetRow
!= null) {
85 targetRow
.style
.backgroundColor
="";
86 this.listing
.style
.cursor
= "";
88 var thisControler
= this;
89 setTimeout(function(){thisControler
.reset();}, 50);
92 if (this.lastOverPosition
!= null) {
93 // get new object position.
95 if (targetRow
.pos
< this.lastOverPosition
&& !this.prevDirUp
)
97 else if (targetRow
.pos
> this.lastOverPosition
&& this.prevDirUp
)
101 var object_id
= targetRow
.getElementsByTagName("INPUT")[0].getAttribute("value");
102 var url
= this.folderUrl
+ "/moveObjectIdToPosition";
103 var form
="object_id=" + object_id
+ "&position:int=" +
104 String(this.lastOverPosition
- 1 + trim
);
106 // reinitialize positions
107 var rows
= this.listing
.getElementsByTagName("TR"), row
;
108 for (var i
= 0 ; i
< rows
.length
; i
++) {
112 row
.className
= "even";
114 row
.className
= "odd";
118 var req
= new XMLHttpRequest();
119 req
.open("POST", url
, true);
120 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
122 var thisControler
= this;
123 setTimeout(function(){thisControler
.reset();}, 50);
128 FolderDDropControler
.prototype.disableClickAfterDrop = function(evt
) {
129 var target
= getTargetedObject(evt
);
131 disablePropagation(evt
);
137 FolderDDropControler
.prototype.reset = function() {
138 this.targetRow
= null;
139 this.lastOverPosition
= null;
140 this.prevDirUp
= null;
146 DropTarget = function(node
, folderDDControler
) {
147 this.folderDDControler
= folderDDControler
;
148 this.batchSize
= parseInt(document
.getElementById("BatchNavigationSize").innerHTML
);
149 var thisControler
= this;
150 node
.onmouseup = function(evt
){thisControler
.drop(evt
);};
151 node
.onmouseover = function(evt
) {thisControler
.highlightTarget(evt
);};
152 node
.onmouseout = function(evt
) {
153 var target
= getTargetedObject(evt
);
154 if (target
.nodeName
== "A" && target
.className
== "dropPageTarget")
155 target
.className
= "";
159 DropTarget
.prototype.drop = function(evt
) {
160 var target
= getTargetedObject(evt
);
161 if (target
.nodeName
== "A" &&
162 target
.className
!= "previous" &&
163 target
.className
!= "next") {
164 var pageNumber
= parseInt(target
.innerHTML
);
165 var targetRow
= this.folderDDControler
.targetRow
;
166 if ( !isNaN(pageNumber
) && targetRow
) {
167 this.folderDDControler
.reset();
168 var object_id
= targetRow
.getElementsByTagName("INPUT")[0].getAttribute("value");
169 var url
= this.folderDDControler
.folderUrl
+ "/moveObjectIdToPosition";
170 var form
="object_id=" + object_id
+ "&position:int=" + String(this.batchSize
* (pageNumber
-1));
172 var req
= new XMLHttpRequest();
173 req
.open("POST", url
, true);
174 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
176 req
.onreadystatechange = function() {
177 if (req
.readyState
== 4) {
178 switch (req
.status
) {
182 raiseMouseEvent(target
, "click");
185 alert('Error: ' + req
.status
);
193 DropTarget
.prototype.highlightTarget = function(evt
){
194 if (browser
.isIE
) document
.selection
.clear();
195 var target
= getTargetedObject(evt
);
196 if (this.folderDDControler
.targetRow
&&
197 target
.nodeName
== "A" &&
198 target
.className
!= "previous" &&
199 target
.className
!= "next")
200 target
.className
= "dropPageTarget";
206 loadListing = function(evt
) {
207 var target
= getTargetedObject(evt
);
209 disablePropagation(evt
);
210 switch (target
.nodeName
) {
212 var parts
= target
.href
.split('?')
215 if (parts
.length
== 2)
218 var urlParts
= url
.split("/");
219 var url
= urlParts
.slice(0,urlParts
.length
-1).join("/");
220 if (query
.search("template") == -1)
221 query
+= "&template=folder_contents_macros¯o=FolderListing&fragmentId=FolderListing";
222 url
= url
+ "/folder_contents?" + query
;
224 var fi
= new FragmentImporter(url
);
229 if (target
.id
== 'SetSortingAsDefault') {
230 var parent
= target
.parentNode
;
231 var url
= parent
.href
;
232 url
= url
.replace("folder_contents", "folder_sort_control");
233 parent
.parentNode
.removeChild(parent
);
235 var req
= new XMLHttpRequest();
236 req
.open("GET", url
, true);
244 DDFolderUploader = function(dropbox
, uploadUrl
, listing
) {
245 DDFileUploaderBase
.apply(this, [dropbox
, uploadUrl
]);
246 this.listing
= listing
;
247 this.progressBarMaxSize
= listing
.clientWidth
;
250 thead
= thead
.previousSibling
;
251 } while (thead
.tagName
!== 'THEAD')
253 var cells
= thead
.getElementsByTagName('th');
256 for (var i
= 0 ; i
< cells
.length
; i
++) {
258 this.tableSpan
+= cell
.getAttribute('colspan') ? Number(cell
.getAttribute('colspan')) : 1;
260 var lastRow
= listing
.lastChild
;
261 while(lastRow
&& lastRow
.tagName
!== 'TR') {
262 lastRow
= lastRow
.previousSibling
;
264 this.lastRowClassName
= lastRow
? lastRow
.className
: 'even';
267 copyPrototype(DDFolderUploader
, DDFileUploaderBase
);
270 DDFolderUploader
.prototype.createRow = function(file
) {
271 var row
= document
.createElement('tr');
273 row
.className
= this.lastRowClassName
=== 'even' ? 'odd' : 'even';
274 this.lastRowClassName
= row
.className
;
275 var td
= document
.createElement('td');
276 td
.setAttribute('colspan', this.tableSpan
);
277 var relSpan
= document
.createElement('span');
278 relSpan
.style
.position
= 'relative';
279 td
.appendChild(relSpan
);
280 var progressBar
= document
.createElement('span');
281 progressBar
.className
= 'upload-progress';
282 row
.progressBar
= progressBar
;
283 relSpan
.appendChild(progressBar
);
284 var fileNameSpan
= document
.createElement('span');
285 fileNameSpan
.innerHTML
= file
.name
;
286 td
.appendChild(fileNameSpan
);
288 this.listing
.appendChild(row
);
289 this.progressBarMaxSize
= row
.clientWidth
;
293 // Methods about upload
294 DDFolderUploader
.prototype.handleFiles = function(files
) {
296 for (i
= 0; i
< files
.length
; i
++) {
298 row
= this.createRow(file
);
299 this.uploadQueuePush(row
);
303 DDFolderUploader
.prototype.beforeUpload = function(item
) {
304 this.uploadedItem
= item
;
305 this.progressBar
= item
.progressBar
;
308 DDFolderUploader
.prototype.uploadCompleteHandlerCB = function(req
) {
309 var item
= this.uploadedItem
;
310 var row
= getCopyOfNode(req
.responseXML
.documentElement
.firstChild
);
311 row
.className
= item
.className
;
313 if (req
.status
=== 200) {
317 else if(req
.status
=== 201) {
319 this.listing
.replaceChild(row
, item
);
320 this.progressBarMaxSize
= row
.clientWidth
;
324 DDFolderUploader
.prototype.progressHandlerCB = function(progress
) {
325 // 0 <= progress <= 1
326 var size
= this.progressBarMaxSize
* progress
;
327 size
= Math
.round(size
);
328 this.progressBar
.style
.width
= size
+ 'px';