1 // (c) Benoît PIN 2006-2007
7 var FolderDDropControler
;
13 function getTargetRow(evt
){
14 var target
= getTargetedObject(evt
);
15 while (target
.nodeName
!= "TR")
16 target
= target
.parentNode
;
20 FolderDDropControler = function(listing
) {
21 this.folderUrl
= document
.getElementById("FolderUrl").innerHTML
;
22 this.targetRow
= null;
23 this.lastOverPosition
= null;
24 this.prevDirUp
= null;
26 this.listing
= listing
;
27 var thisControler
= this;
28 this.listing
.onmousedown = function(evt
) {thisControler
.drag(evt
);};
29 this.listing
.onmouseover = function(evt
) {thisControler
.moveRow(evt
);};
30 this.listing
.onmouseup = function(evt
) {thisControler
.drop(evt
);};
31 this.listing
.onclick = function(evt
) {thisControler
.disableClickAfterDrop(evt
);};
34 this.listing
.ondragstart = function() { window
.event
.returnValue
= false;};
38 FolderDDropControler
.prototype.drag = function(evt
){
39 var target
= getTargetedObject(evt
);
40 if (target
.nodeName
== "INPUT") return true;
42 var targetRow
= getTargetRow(evt
);
43 targetRow
.style
.backgroundColor
= base_properties
["highLightColor"];
44 this.listing
.style
.cursor
= "move";
45 this.targetRow
= targetRow
;
46 this.lastOverPosition
= targetRow
.pos
;
49 FolderDDropControler
.prototype.moveRow = function(evt
){
50 var targetRow
= this.targetRow
;
51 if (targetRow
!= null) {
53 if (browser
.isIE
) document
.selection
.clear();
54 var overRow
= getTargetRow(evt
);
56 if (overRow
.pos
== targetRow
.pos
) return;
58 if (this.lastOverPosition
< overRow
.pos
) { // move up
59 this.listing
.insertBefore(targetRow
, overRow
.nextSibling
);
60 this.prevDirUp
= true;
61 this.lastOverPosition
= overRow
.pos
;
63 else if (this.lastOverPosition
> overRow
.pos
) { // move down
64 this.listing
.insertBefore(targetRow
, overRow
);
65 this.prevDirUp
= false;
66 this.lastOverPosition
= overRow
.pos
;
70 this.prevDirUp
= false;
71 this.listing
.insertBefore(targetRow
, overRow
);
74 this.prevDirUp
= true;
75 this.listing
.insertBefore(targetRow
, overRow
.nextSibling
);
81 FolderDDropControler
.prototype.drop = function(evt
){
82 var targetRow
= this.targetRow
;
83 if (targetRow
!= null) {
84 targetRow
.style
.backgroundColor
="";
85 this.listing
.style
.cursor
= "";
87 var thisControler
= this;
88 setTimeout(function(){thisControler
.reset();}, 50);
91 if (this.lastOverPosition
!= null) {
92 // get new object position.
94 if (targetRow
.pos
< this.lastOverPosition
&& !this.prevDirUp
)
96 else if (targetRow
.pos
> this.lastOverPosition
&& this.prevDirUp
)
100 var object_id
= targetRow
.getElementsByTagName("INPUT")[0].getAttribute("value");
101 var url
= this.folderUrl
+ "/moveObjectIdToPosition";
102 var form
="object_id=" + object_id
+ "&position:int=" +
103 String(this.lastOverPosition
- 1 + trim
);
105 // reinitialize positions
106 var rows
= this.listing
.getElementsByTagName("TR"), row
;
107 for (var i
= 0 ; i
< rows
.length
; i
++) {
111 row
.className
= "even";
113 row
.className
= "odd";
117 var req
= new XMLHttpRequest();
118 req
.open("POST", url
, true);
119 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
121 var thisControler
= this;
122 setTimeout(function(){thisControler
.reset();}, 50);
127 FolderDDropControler
.prototype.disableClickAfterDrop = function(evt
) {
128 var target
= getTargetedObject(evt
);
130 disablePropagation(evt
);
136 FolderDDropControler
.prototype.reset = function() {
137 this.targetRow
= null;
138 this.lastOverPosition
= null;
139 this.prevDirUp
= null;
145 DropTarget = function(node
, folderDDControler
) {
146 this.folderDDControler
= folderDDControler
;
147 this.batchSize
= parseInt(document
.getElementById("BatchNavigationSize").innerHTML
);
148 var thisControler
= this;
149 node
.onmouseup = function(evt
){thisControler
.drop(evt
);};
150 node
.onmouseover = function(evt
) {thisControler
.highlightTarget(evt
);};
151 node
.onmouseout = function(evt
) {
152 var target
= getTargetedObject(evt
);
153 if (target
.nodeName
== "A" && target
.className
== "dropPageTarget")
154 target
.className
= "";
158 DropTarget
.prototype.drop = function(evt
) {
159 var target
= getTargetedObject(evt
);
160 if (target
.nodeName
== "A" &&
161 target
.className
!= "previous" &&
162 target
.className
!= "next") {
163 var pageNumber
= parseInt(target
.innerHTML
);
164 var targetRow
= this.folderDDControler
.targetRow
;
165 if ( !isNaN(pageNumber
) && targetRow
) {
166 this.folderDDControler
.reset();
167 var object_id
= targetRow
.getElementsByTagName("INPUT")[0].getAttribute("value");
168 var url
= this.folderDDControler
.folderUrl
+ "/moveObjectIdToPosition";
169 var form
="object_id=" + object_id
+ "&position:int=" + String(this.batchSize
* (pageNumber
-1));
171 var req
= new XMLHttpRequest();
172 req
.open("POST", url
, true);
173 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
175 req
.onreadystatechange = function() {
176 if (req
.readyState
== 4) {
177 switch (req
.status
) {
181 raiseMouseEvent(target
, "click");
184 alert('Error: ' + req
.status
);
192 DropTarget
.prototype.highlightTarget = function(evt
){
193 if (browser
.isIE
) document
.selection
.clear();
194 var target
= getTargetedObject(evt
);
195 if (this.folderDDControler
.targetRow
&&
196 target
.nodeName
== "A" &&
197 target
.className
!= "previous" &&
198 target
.className
!= "next")
199 target
.className
= "dropPageTarget";
205 loadListing = function(evt
) {
206 var target
= getTargetedObject(evt
);
208 disablePropagation(evt
);
209 switch (target
.nodeName
) {
211 var parts
= target
.href
.split('?')
214 if (parts
.length
== 2)
217 var urlParts
= url
.split("/");
218 var url
= urlParts
.slice(0,urlParts
.length
-1).join("/");
219 if (query
.search("template") == -1)
220 query
+= "&template=folder_contents_macros¯o=FolderListing&fragmentId=FolderListing";
221 url
= url
+ "/folder_contents?" + query
;
223 var fi
= new FragmentImporter(url
);
228 if (target
.id
== 'SetSortingAsDefault') {
229 var parent
= target
.parentNode
;
230 var url
= parent
.href
;
231 url
= url
.replace("folder_contents", "folder_sort_control");
232 parent
.parentNode
.removeChild(parent
);
234 var req
= new XMLHttpRequest();
235 req
.open("GET", url
, true);