5033108a6189d3b78135a99d88818293211e58f3
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 this.checkboxes
= undefined;
30 var thisControler
= this;
31 this.listing
.onmousedown = function(evt
) {thisControler
.drag(evt
);};
32 this.listing
.onmouseover = function(evt
) {thisControler
.moveRow(evt
);};
33 this.listing
.onmouseup = function(evt
) {thisControler
.drop(evt
);};
34 addListener(this.listing
, 'click', function(evt
) {thisControler
.disableClickAfterDrop(evt
);});
35 addListener(this.listing
, 'click', function(evt
) {thisControler
.selectCBRange(evt
);});
38 this.listing
.ondragstart = function() { window
.event
.returnValue
= false;};
42 FolderDDropControler
.prototype._updateCBIndex = function() {
43 var cbs
= this.listing
.getElementsByTagName('INPUT');
47 for (var i
=0 ; i
< cbs
.length
; i
++) {
49 if (cb
.type
=== 'checkbox') {
50 cb
.position
= index
++;
51 this.checkboxes
[cb
.position
] = cb
;
56 FolderDDropControler
.prototype.drag = function(evt
){
57 var target
= getTargetedObject(evt
);
58 if (target
.nodeName
== "INPUT") return true;
60 var targetRow
= getTargetRow(evt
);
61 targetRow
.style
.backgroundColor
= base_properties
["highLightColor"];
62 this.listing
.style
.cursor
= "move";
63 this.targetRow
= targetRow
;
64 this.lastOverPosition
= targetRow
.pos
;
67 FolderDDropControler
.prototype.moveRow = function(evt
){
68 var targetRow
= this.targetRow
;
69 if (targetRow
!= null) {
71 if (browser
.isIE
) document
.selection
.clear();
72 var overRow
= getTargetRow(evt
);
74 if (overRow
.pos
== targetRow
.pos
) return;
76 if (this.lastOverPosition
< overRow
.pos
) { // move up
77 this.listing
.insertBefore(targetRow
, overRow
.nextSibling
);
78 this.prevDirUp
= true;
79 this.lastOverPosition
= overRow
.pos
;
81 else if (this.lastOverPosition
> overRow
.pos
) { // move down
82 this.listing
.insertBefore(targetRow
, overRow
);
83 this.prevDirUp
= false;
84 this.lastOverPosition
= overRow
.pos
;
88 this.prevDirUp
= false;
89 this.listing
.insertBefore(targetRow
, overRow
);
92 this.prevDirUp
= true;
93 this.listing
.insertBefore(targetRow
, overRow
.nextSibling
);
99 FolderDDropControler
.prototype.drop = function(evt
){
100 var targetRow
= this.targetRow
;
101 if (targetRow
!= null) {
102 targetRow
.style
.backgroundColor
="";
103 this.listing
.style
.cursor
= "";
105 var thisControler
= this;
106 setTimeout(function(){thisControler
.reset();}, 50);
109 if (this.lastOverPosition
!= null) {
110 // get new object position.
112 if (targetRow
.pos
< this.lastOverPosition
&& !this.prevDirUp
)
114 else if (targetRow
.pos
> this.lastOverPosition
&& this.prevDirUp
)
118 var object_id
= targetRow
.getElementsByTagName("INPUT")[0].getAttribute("value");
119 var url
= this.folderUrl
+ "/moveObjectIdToPosition";
120 var form
="object_id=" + object_id
+ "&position:int=" +
121 String(this.lastOverPosition
- 1 + trim
);
123 // reinitialize positions
124 var rows
= this.listing
.getElementsByTagName("TR"), row
;
125 for (var i
= 0 ; i
< rows
.length
; i
++) {
129 row
.className
= "even";
131 row
.className
= "odd";
135 var req
= new XMLHttpRequest();
136 req
.open("POST", url
, true);
137 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
139 var thisControler
= this;
140 setTimeout(function(){thisControler
.reset();}, 50);
145 FolderDDropControler
.prototype.disableClickAfterDrop = function(evt
) {
146 var target
= getTargetedObject(evt
);
148 disablePropagation(evt
);
154 FolderDDropControler
.prototype.selectCBRange = function(evt
) {
158 FolderDDropControler
.prototype.reset = function() {
159 this.targetRow
= null;
160 this.lastOverPosition
= null;
161 this.prevDirUp
= null;
167 DropTarget = function(node
, folderDDControler
) {
168 this.folderDDControler
= folderDDControler
;
169 this.batchSize
= parseInt(document
.getElementById("BatchNavigationSize").innerHTML
);
170 var thisControler
= this;
171 node
.onmouseup = function(evt
){thisControler
.drop(evt
);};
172 node
.onmouseover = function(evt
) {thisControler
.highlightTarget(evt
);};
173 node
.onmouseout = function(evt
) {
174 var target
= getTargetedObject(evt
);
175 if (target
.nodeName
== "A" && target
.className
== "dropPageTarget")
176 target
.className
= "";
180 DropTarget
.prototype.drop = function(evt
) {
181 var target
= getTargetedObject(evt
);
182 if (target
.nodeName
== "A" &&
183 target
.className
!= "previous" &&
184 target
.className
!= "next") {
185 var pageNumber
= parseInt(target
.innerHTML
);
186 var targetRow
= this.folderDDControler
.targetRow
;
187 if ( !isNaN(pageNumber
) && targetRow
) {
188 this.folderDDControler
.reset();
189 var object_id
= targetRow
.getElementsByTagName("INPUT")[0].getAttribute("value");
190 var url
= this.folderDDControler
.folderUrl
+ "/moveObjectIdToPosition";
191 var form
="object_id=" + object_id
+ "&position:int=" + String(this.batchSize
* (pageNumber
-1));
193 var req
= new XMLHttpRequest();
194 req
.open("POST", url
, true);
195 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
197 req
.onreadystatechange = function() {
198 if (req
.readyState
== 4) {
199 switch (req
.status
) {
203 raiseMouseEvent(target
, "click");
206 alert('Error: ' + req
.status
);
214 DropTarget
.prototype.highlightTarget = function(evt
){
215 if (browser
.isIE
) document
.selection
.clear();
216 var target
= getTargetedObject(evt
);
217 if (this.folderDDControler
.targetRow
&&
218 target
.nodeName
== "A" &&
219 target
.className
!= "previous" &&
220 target
.className
!= "next")
221 target
.className
= "dropPageTarget";
227 loadListing = function(evt
) {
228 var target
= getTargetedObject(evt
);
230 disablePropagation(evt
);
231 switch (target
.nodeName
) {
233 var parts
= target
.href
.split('?')
236 if (parts
.length
== 2)
239 var urlParts
= url
.split("/");
240 var url
= urlParts
.slice(0,urlParts
.length
-1).join("/");
241 if (query
.search("template") == -1)
242 query
+= "&template=folder_contents_macros¯o=FolderListing&fragmentId=FolderListing";
243 url
= url
+ "/folder_contents?" + query
;
245 var fi
= new FragmentImporter(url
);
250 if (target
.id
== 'SetSortingAsDefault') {
251 var parent
= target
.parentNode
;
252 var url
= parent
.href
;
253 url
= url
.replace("folder_contents", "folder_sort_control");
254 parent
.parentNode
.removeChild(parent
);
256 var req
= new XMLHttpRequest();
257 req
.open("GET", url
, true);
265 DDFolderUploader = function(dropbox
, uploadUrl
, listing
) {
266 DDFileUploaderBase
.apply(this, [dropbox
, uploadUrl
]);
267 this.listing
= listing
;
268 this.progressBarMaxSize
= listing
.clientWidth
;
271 thead
= thead
.previousSibling
;
272 } while (thead
.tagName
!== 'THEAD')
274 var cells
= thead
.getElementsByTagName('th');
277 for (var i
= 0 ; i
< cells
.length
; i
++) {
279 this.tableSpan
+= cell
.getAttribute('colspan') ? Number(cell
.getAttribute('colspan')) : 1;
281 var lastRow
= listing
.lastChild
;
282 while(lastRow
&& lastRow
.tagName
!== 'TR') {
283 lastRow
= lastRow
.previousSibling
;
285 this.lastRowClassName
= lastRow
? lastRow
.className
: 'even';
288 copyPrototype(DDFolderUploader
, DDFileUploaderBase
);
291 DDFolderUploader
.prototype.createRow = function(file
) {
292 var row
= document
.createElement('tr');
294 row
.className
= this.lastRowClassName
=== 'even' ? 'odd' : 'even';
295 this.lastRowClassName
= row
.className
;
296 var td
= document
.createElement('td');
297 td
.setAttribute('colspan', this.tableSpan
);
298 var relSpan
= document
.createElement('span');
299 relSpan
.style
.position
= 'relative';
300 td
.appendChild(relSpan
);
301 var progressBar
= document
.createElement('span');
302 progressBar
.className
= 'upload-progress';
303 row
.progressBar
= progressBar
;
304 relSpan
.appendChild(progressBar
);
305 var fileNameSpan
= document
.createElement('span');
306 fileNameSpan
.innerHTML
= file
.name
;
307 td
.appendChild(fileNameSpan
);
309 this.listing
.appendChild(row
);
310 this.progressBarMaxSize
= row
.clientWidth
;
314 // Methods about upload
315 DDFolderUploader
.prototype.handleFiles = function(files
) {
317 for (i
= 0; i
< files
.length
; i
++) {
319 row
= this.createRow(file
);
320 this.uploadQueuePush(row
);
324 DDFolderUploader
.prototype.beforeUpload = function(item
) {
325 this.uploadedItem
= item
;
326 this.progressBar
= item
.progressBar
;
329 DDFolderUploader
.prototype.uploadCompleteHandlerCB = function(req
) {
330 var item
= this.uploadedItem
;
331 var row
= getCopyOfNode(req
.responseXML
.documentElement
.firstChild
);
332 row
.className
= item
.className
;
334 if (req
.status
=== 200) {
338 else if(req
.status
=== 201) {
340 this.listing
.replaceChild(row
, item
);
341 this.progressBarMaxSize
= row
.clientWidth
;
345 DDFolderUploader
.prototype.progressHandlerCB = function(progress
) {
346 // 0 <= progress <= 1
347 var size
= this.progressBarMaxSize
* progress
;
348 size
= Math
.round(size
);
349 this.progressBar
.style
.width
= size
+ 'px';