source: main/trunk/greenstone3/web/interfaces/default_new/js/documentbasket/documentBasketDragDrop.js@ 29852

Last change on this file since 29852 was 29852, checked in by Georgiy Litvinov, 9 years ago

Ckeditor integration commit

  • Property svn:executable set to *
File size: 9.2 KB
Line 
1/* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
2
3function documentBasketDDStack(id, sGroup) {
4 if (id) {
5 this.init(id, sGroup);
6 this.initFrame();
7 }
8}
9
10documentBasketDDStack.prototype = new YAHOO.util.DDTarget();
11
12documentBasketDDPlayer.TYPE = "documentBasketDDPlayer";
13
14/**
15* @class a YAHOO.util.DDFramed implementation. During the drag over event, the
16* dragged element is inserted before the dragged-over element.
17*
18* @extends YAHOO.util.DDProxy
19* @constructor
20* @param {String} id the id of the linked element
21* @param {String} sGroup the group of related DragDrop objects
22*/
23function documentBasketDDPlayer(id, sGroup, bl) {
24 this.initPlayer(id, sGroup);
25 this.documentList = bl;
26
27}
28
29documentBasketDDPlayer.prototype = new YAHOO.util.DDProxy();
30
31documentBasketDDPlayer.prototype.documentList = new Array();
32
33documentBasketDDPlayer.prototype.initPlayer = function(id, sGroup) {
34 if (!id) { return; }
35
36 this.init(id, sGroup);
37 this.initFrame();
38 var s = this.getDragEl().style;
39 s.borderColor = "transparent";
40 // s.backgroundColor = "#cccccc";
41 s.opacity = 0.76;
42 s.filter = "alpha(opacity=76)";
43
44 // specify that this is not currently a drop target
45 this.isTarget = false;
46
47 this.originalStyles = [];
48
49 this.type = documentBasketDDPlayer.TYPE;
50 this.slot = null;
51 this.startPos = YAHOO.util.Dom.getXY( this.getEl() );
52
53}
54
55documentBasketDDPlayer.prototype.startDrag = function(x, y) {
56
57 var dragEl = this.getDragEl();
58 var clickEl = this.getEl();
59
60 dragEl.innerHTML = clickEl.innerHTML;
61 //dragEl.className = clickEl.className;
62 //dragEl.style.color = clickEl.style.color;
63 //dragEl.style.backgroundColor = clickEl.style.backgroundColor;
64 //dragEl.style.visibility = clickEl.style.visibility;
65
66 while (dragEl.hasChildNodes()) {
67 dragEl.removeChild(dragEl.firstChild);
68 }
69
70 var img = document.createElement('img');
71 img.src = gs.imageURLs.pageIcon;
72 dragEl.appendChild(img);
73
74 var added = true;
75
76 var s = clickEl.style;
77 s.opacity = .1;
78 s.filter = "alpha(opacity=10)";
79
80 var targets = YAHOO.util.DDM.getRelated(this, true);
81
82 for (var i=0; i<targets.length; i++) {
83
84 var targetEl = this.getTargetDomRef(targets[i]);
85
86 if (!this.originalStyles[targetEl.id]) {
87 this.originalStyles[targetEl.id] = targetEl.className;
88 }
89
90 targetEl.className = "target";
91 }
92 correctDocumentExpandCollapseButtons();
93};
94
95documentBasketDDPlayer.prototype.getTargetDomRef = function(oDD) {
96 if (oDD.player) {
97 return oDD.player.getEl();
98 } else {
99 return oDD.getEl();
100 }
101};
102
103documentBasketDDPlayer.prototype.endDrag = function(e) {
104 // reset the linked element styles
105 var s = this.getEl().style;
106 s.opacity = 1;
107 s.filter = "alpha(opacity=100)";
108
109 this.resetTargets();
110};
111
112documentBasketDDPlayer.prototype.resetTargets = function() {
113
114 // reset the target styles
115 var targets = YAHOO.util.DDM.getRelated(this, true);
116 for (var i=0; i<targets.length; i++) {
117 var targetEl = this.getTargetDomRef(targets[i]);
118 var oldStyle = this.originalStyles[targetEl.id];
119 if (oldStyle) {
120 targetEl.className = oldStyle;
121 }
122 }
123};
124
125var request_type = "GET";
126var docAddurlPath = gs.xsltParams.library_name + "?a=pr&rt=r&ro=1&s=AddDocument&c=&s1.id=2&o=XML&hhf=[{\"name\":\"Cache-Control\", \"value\":\"no-cache\"}]&s1.item=";
127var docDelurlPath = gs.xsltParams.library_name + "?a=pr&rt=r&ro=1&s=DeleteDocument&c=&o=XML&hhf=[{\"name\":\"Cache-Control\", \"value\":\"no-cache\"}]&s1.item=";
128var postdata = null;
129
130documentBasketDDPlayer.prototype.onDragDrop = function(e, id) {
131
132 // get the drag and drop object that was targeted
133 var oDD;
134 var player = this;
135
136 if ("string" == typeof id) {
137 oDD = YAHOO.util.DDM.getDDById(id);
138 } else {
139 oDD = YAHOO.util.DDM.getBestMatch(id);
140 }
141
142
143 var el = this.getEl();
144
145 // check if the slot has a player in it already
146 if (oDD.player) {
147 // check if the dragged player was already in a slot
148 if (this.slot) {
149 // check to see if the player that is already in the
150 // slot can go to the slot the dragged player is in
151 // YAHOO.util.DDM.isLegalTarget is a new method
152 if ( YAHOO.util.DDM.isLegalTarget(oDD.player, this.slot) ) {
153 YAHOO.util.DDM.moveToEl(oDD.player.getEl(), el);
154 this.slot.player = oDD.player;
155 oDD.player.slot = this.slot;
156 } else {
157 YAHOO.util.Dom.setXY(oDD.player.getEl(), oDD.player.startPos);
158 this.slot.player = null;
159 oDD.player.slot = null
160 }
161 } else {
162 // the player in the slot will be moved to the dragged
163 // players start position
164 //oDD.player.slot = null;
165 //YAHOO.util.DDM.moveToEl(oDD.player.getEl(), el);
166 }
167 }else {
168 // Move the player into the emply slot
169 // I may be moving off a slot so I need to clear the player ref
170 if (this.slot) {
171 this.slot.player = null;
172 }
173 }
174
175 var addurl = docAddurlPath + el.id;
176 var addSuccess = function(o){
177 //alert("HERE!" + o.responseText);
178 var result = o.responseXML;
179 var items = result.getElementsByTagName('item');
180 if (items.length > 0){
181 var item = items[0];
182 var documentbasket = YAHOO.util.Dom.get('documentbasket');
183 var documents = YAHOO.util.Dom.get('documentpages');
184 player.documentList[player.documentList.length]= item;
185
186 var itemID = item.getAttribute('collection')+":"+item.getAttribute('name');
187 var parent =el.parentNode;
188 parent.removeChild(el);
189
190 if (parent !=null && parent.id == "documentbasket"){
191 var root = YAHOO.util.Dom.get(itemID+":root");
192 var section = YAHOO.util.Dom.get(itemID+":section");
193 if(root!=null && root.id.indexOf(itemID) !=-1){
194 parent.removeChild(root);
195 }
196
197 if(section!=null && section.id.indexOf(itemID) !=-1){
198 parent.removeChild(section);
199 }
200 }
201
202
203 if (!YAHOO.util.Dom.get('hideview') && player.documentList.length <13){
204
205 while (documents.hasChildNodes()) {
206 documents.removeChild(documents.firstChild);
207 }
208
209 for (var i =0; i < player.documentList.length; i++ ){
210 var img = document.createElement('img');
211 img.src = gs.imageURLs.pageIcon;
212 documents.appendChild(img);
213 }
214
215 correctBerryExpandCollapseButtons();
216
217 }
218 else{
219
220
221 if (YAHOO.util.Dom.get('hideview')){
222
223 var documentBasket = YAHOO.util.Dom.get('documentbasket');
224 var documents = YAHOO.util.Dom.get('documents');
225 var doclist = YAHOO.util.Dom.get('doclist');
226 var tid = el.id;
227 var documentItem;
228 var documentElement = document.createElement('li');
229 for (var i in player.documentList){
230 documentItem = player.documentList[i];
231 var id = documentItem.getAttribute('collection')+":"+documentItem.getAttribute('name');
232 if (id == tid){
233 var title = documentItem.getAttribute('title');
234 var root_title = documentItem.getAttribute('root_title');
235 if (root_title != ""){
236 root_title +=":";
237 }
238
239 title = root_title+title;
240 if (title.length > 50){
241 title = title.substring(0,20)+" ... "+title.substr(title.length-35,35);
242 }
243
244 documentElement.appendChild(document.createTextNode(title));
245 documentElement.setAttribute("class","documentitem");
246 doclist.appendChild(berryElement);
247 var heightStr = documentBasket.style.height+"";
248 var height =parseInt(heightStr.substring(0,heightStr.length-2)) +18;
249 documentBasket.style.height = height;
250 documents.style.height = height;
251 break;
252 }
253 }
254 }
255
256 }
257 }
258
259 //Makes sure all the documents on the page are up to date
260 dmcheckout();
261 }
262
263 var addFailure = function(o){ alert("Adding document failed" + o); }
264
265
266 var addcallback = {
267 success:addSuccess,
268 failure:addFailure,
269 argument:player
270 }
271
272
273 var delurl = docDelurlPath + el.id;
274 var delSuccess = function(o){
275 var result = o.responseXML;
276 var parent =el.parentNode;
277 var ancestor = parent.parentNode;
278 if (parent == null) return;
279
280 ancestor.removeChild(parent);
281
282 for (var i in player.berryList){
283 var document = player.berryList[i];
284
285 var id = document['collection']+":"+document['name'];
286
287 if (id == el.id){
288 player.documentList.splice(i,1);
289
290 break;
291 }
292
293 }
294
295 if (!parent.hasChildNodes()){
296 var content = YAHOO.util.Dom.get('content');
297 while (content.hasChildNodes()) {
298 content.removeChild(content.firstChild);
299 }
300 content.appendChild(document.createTextNode('Your document basket is empty.'));
301 }
302 var trashbin = YAHOO.util.Dom.get('trashbin');
303 if ( trashbin !=null){
304 trashbin.style.background = "url(\"" + gs.imageURLs.trashFull + "\") 0 0 no-repeat";
305 }
306 }
307
308
309 var delFailure = function(o){ alert("Deletion failed" + o);}
310
311
312 var delcallback = {
313 success:delSuccess,
314 failure:delFailure,
315 argument:player
316 }
317
318 if (id == 'documentbasket'){
319 YAHOO.util.Connect.asyncRequest(request_type , addurl , addcallback);
320 } else {
321 if (id == 'trashbin'){
322 YAHOO.util.Connect.asyncRequest(request_type , delurl , delcallback);
323 }
324 }
325
326 this.resetTargets();
327 this.slot = oDD;
328 this.slot.player = this;
329};
330
331documentBasketDDPlayer.prototype.swap = function(el1, el2) {
332 var dom = YAHOO.util.Dom;
333 var pos1 = dom.getXY(el1);
334 var pos2 = dom.getXY(el2);
335 dom.setXY(el1, pos2);
336 dom.setXY(el2, pos1);
337};
338
339documentBasketDDPlayer.prototype.onDragOver = function(e, id) {};
340
341documentBasketDDPlayer.prototype.onDrag = function(e, id) {};
342
343
344
345
346
Note: See TracBrowser for help on using the repository browser.