1 // (c) BenoƮt PIN 2006-2007
7 function getTargetRow(evt
){
8 var target
= getTargetedObject(evt
);
9 while (target
.nodeName
!= "TR")
10 target
= target
.parentNode
;
14 function FolderDDropControler(listing
) {
15 this.folderUrl
= document
.getElementById("FolderUrl").innerHTML
;
16 this.targetRow
= null;
17 this.lastOverPosition
= null;
18 this.prevDirUp
= null;
20 this.listing
= listing
;
21 var thisControler
= this;
22 this.listing
.onmousedown = function(evt
) {thisControler
.drag(evt
);};
23 this.listing
.onmouseover = function(evt
) {thisControler
.moveRow(evt
);};
24 this.listing
.onmouseup = function(evt
) {thisControler
.drop(evt
);};
25 this.listing
.onclick = function(evt
) {thisControler
.disableClickAfterDrop(evt
);};
28 this.listing
.ondragstart = function() { window
.event
.returnValue
= false;};
32 FolderDDropControler
.prototype.drag = function(evt
){
33 var target
= getTargetedObject(evt
);
34 if (target
.nodeName
== "INPUT") return true;
36 var targetRow
= getTargetRow(evt
);
37 targetRow
.style
.backgroundColor
= base_properties
["highLightColor"];
38 this.listing
.style
.cursor
= "move";
39 this.targetRow
= targetRow
;
40 this.lastOverPosition
= targetRow
.pos
;
43 FolderDDropControler
.prototype.moveRow = function(evt
){
44 var targetRow
= this.targetRow
;
45 if (targetRow
!= null) {
47 if (browser
.isIE
) document
.selection
.clear();
48 var overRow
= getTargetRow(evt
);
50 if (overRow
.pos
== targetRow
.pos
) return;
52 if (this.lastOverPosition
< overRow
.pos
) { // move up
53 this.listing
.insertBefore(targetRow
, overRow
.nextSibling
);
54 this.prevDirUp
= true;
55 this.lastOverPosition
= overRow
.pos
;
57 else if (this.lastOverPosition
> overRow
.pos
) { // move down
58 this.listing
.insertBefore(targetRow
, overRow
);
59 this.prevDirUp
= false;
60 this.lastOverPosition
= overRow
.pos
;
64 this.prevDirUp
= false;
65 this.listing
.insertBefore(targetRow
, overRow
);
68 this.prevDirUp
= true;
69 this.listing
.insertBefore(targetRow
, overRow
.nextSibling
);
75 FolderDDropControler
.prototype.drop = function(evt
){
76 var targetRow
= this.targetRow
;
77 if (targetRow
!= null) {
78 targetRow
.style
.backgroundColor
="";
79 this.listing
.style
.cursor
= "";
81 var thisControler
= this;
82 setTimeout(function(){thisControler
.reset();}, 50);
85 if (this.lastOverPosition
!= null) {
86 // get new object position.
88 if (targetRow
.pos
< this.lastOverPosition
&& !this.prevDirUp
)
90 else if (targetRow
.pos
> this.lastOverPosition
&& this.prevDirUp
)
94 var object_id
= targetRow
.getElementsByTagName("INPUT")[0].getAttribute("value");
95 var url
= this.folderUrl
+ "/moveObjectIdToPosition";
96 var form
="object_id=" + object_id
+ "&position:int=" +
97 String(this.lastOverPosition
- 1 + trim
);
99 // reinitialize positions
100 var rows
= this.listing
.getElementsByTagName("TR"), row
;
101 for (var i
= 0 ; i
< rows
.length
; i
++) {
105 row
.className
= "even";
107 row
.className
= "odd";
111 var req
= new XMLHttpRequest();
112 req
.open("POST", url
, true);
113 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
115 var thisControler
= this;
116 setTimeout(function(){thisControler
.reset();}, 50);
121 FolderDDropControler
.prototype.disableClickAfterDrop = function(evt
) {
122 var target
= getTargetedObject(evt
);
124 disablePropagation(evt
);
130 FolderDDropControler
.prototype.reset = function() {
131 this.targetRow
= null;
132 this.lastOverPosition
= null;
133 this.prevDirUp
= null;
139 function DropTarget(node
, folderDDControler
) {
140 this.folderDDControler
= folderDDControler
;
141 this.batchSize
= parseInt(document
.getElementById("BatchNavigationSize").innerHTML
);
142 var thisControler
= this;
143 node
.onmouseup = function(evt
){thisControler
.drop(evt
);};
144 node
.onmouseover = function(evt
) {thisControler
.highlightTarget(evt
);};
145 node
.onmouseout = function(evt
) {
146 var target
= getTargetedObject(evt
);
147 if (target
.nodeName
== "A" && target
.className
== "dropPageTarget")
148 target
.className
= "";
152 DropTarget
.prototype.drop = function(evt
) {
153 var target
= getTargetedObject(evt
);
154 if (target
.nodeName
== "A" &&
155 target
.className
!= "previous" &&
156 target
.className
!= "next") {
157 var pageNumber
= parseInt(target
.innerHTML
);
158 var targetRow
= this.folderDDControler
.targetRow
;
159 if ( !isNaN(pageNumber
) && targetRow
) {
160 this.folderDDControler
.reset();
161 var object_id
= targetRow
.getElementsByTagName("INPUT")[0].getAttribute("value");
162 var url
= this.folderDDControler
.folderUrl
+ "/moveObjectIdToPosition";
163 var form
="object_id=" + object_id
+ "&position:int=" + String(this.batchSize
* (pageNumber
-1));
165 var req
= new XMLHttpRequest();
166 req
.open("POST", url
, true);
167 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
169 req
.onreadystatechange = function() {
170 if (req
.readyState
== 4) {
171 switch (req
.status
) {
175 raiseMouseEvent(target
, "click");
178 alert('Error: ' + req
.status
);
186 DropTarget
.prototype.highlightTarget = function(evt
){
187 if (browser
.isIE
) document
.selection
.clear();
188 var target
= getTargetedObject(evt
);
189 if (this.folderDDControler
.targetRow
&&
190 target
.nodeName
== "A" &&
191 target
.className
!= "previous" &&
192 target
.className
!= "next")
193 target
.className
= "dropPageTarget";
199 function loadListing(evt
) {
200 var target
= getTargetedObject(evt
);
202 disablePropagation(evt
);
203 switch (target
.nodeName
) {
205 var parts
= target
.href
.split('?')
208 if (parts
.length
== 2)
211 var urlParts
= url
.split("/");
212 var url
= urlParts
.slice(0,urlParts
.length
-1).join("/");
213 if (query
.search("template") == -1)
214 query
+= "&template=folder_contents_macros¯o=FolderListing&fragmentId=FolderListing";
215 url
= url
+ "/folder_contents?" + query
;
217 var fi
= new FragmentImporter(url
);
222 if (target
.id
== 'SetSortingAsDefault') {
223 var parent
= target
.parentNode
;
224 var url
= parent
.href
;
225 url
= url
.replace("folder_contents", "folder_sort_control");
226 parent
.parentNode
.removeChild(parent
);
228 var req
= new XMLHttpRequest();
229 req
.open("GET", url
, true);