source: main/trunk/greenstone3/web/interfaces/default/js/documentbasket/documentBasketDragDrop.js@ 36086

Last change on this file since 36086 was 36086, checked in by kjdon, 2 years ago

making js/documentbasket more self contained - don't use things from berrybasket anymore. ygDD stuff copied in here, and correctBerryExpandCollapseButtons which was used from berrybasket.js copied in here too.

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