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
;
249 thead
= thead
.previousSibling
;
250 } while (thead
.tagName
!== 'THEAD')
252 var cells
= thead
.getElementsByTagName('th');
255 for (var i
= 0 ; i
< cells
.length
; i
++) {
257 this.tableSpan
+= cell
.getAttribute('colspan') ? Number(cell
.getAttribute('colspan')) : 1;
259 var lastRow
= listing
.lastChild
;
260 while(lastRow
&& lastRow
.tagName
!== 'TR') {
261 lastRow
= lastRow
.previousSibling
;
263 this.lastRowClassName
= lastRow
? lastRow
.className
: 'even';
266 copyPrototype(DDFolderUploader
, DDFileUploaderBase
);
269 DDFolderUploader
.prototype.createRow = function(file
) {
270 var row
= document
.createElement('tr');
272 row
.className
= this.lastRowClassName
=== 'even' ? 'odd' : 'even';
273 this.lastRowClassName
= row
.className
;
274 var td
= document
.createElement('td');
275 td
.setAttribute('colspan', this.tableSpan
);
276 td
.innerHTML
= file
.name
;
278 this.listing
.appendChild(row
);
282 // Methods about upload
283 DDFolderUploader
.prototype.handleFiles = function(files
) {
285 for (i
= 0; i
< files
.length
; i
++) {
287 row
= this.createRow(file
);
288 this.uploadQueuePush(row
);
292 DDFolderUploader
.prototype.beforeUpload = function(item
) {
293 // To be implemented by decendant.
296 DDFolderUploader
.prototype.uploadCompleteHandlerCB = function(req
) {
297 // To be implemented by descendant.
300 DDFolderUploader
.prototype.progressHandlerCB = function(progress
) {
301 // To be implemented by descendant.
302 // 0 <= progress <= 1