669d3ecd |
1 | <?php // $Id$ |
2 | |
3 | /// Javascript file run through PHP so we can control it better |
4 | |
5 | $nomoodlecookie = true; |
6 | |
7 | include('../../config.php'); |
8 | |
9 | $lifetime = '86400'; |
10 | |
11 | @header('Content-type: text/javascript'); |
12 | @header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT'); |
13 | @header('Cache-control: max-age='.$lifetime); |
14 | @header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .'GMT'); |
15 | @header('Pragma: '); |
16 | ?> |
0a0bb380 |
17 | /* |
18 | * library for ajaxcourse formats, the classes and related functions for sections and resources |
19 | * this library requires a 'main' object created in calling document |
20 | */ |
d4df8fdc |
21 | |
22 | |
0a0bb380 |
23 | function section_class(id,group,config,isDraggable){ |
24 | this.init_section(id,group,config,isDraggable); |
25 | } |
26 | YAHOO.extend(section_class, YAHOO.util.DDProxy); |
27 | |
d4df8fdc |
28 | section_class.prototype.debug = false; |
29 | |
30 | section_class.prototype.init_section = function(id, group,config,isDraggable){ |
31 | if (!id) { return; } |
32 | |
33 | this.is = 'section'; |
34 | this.sectionId = null; |
35 | |
36 | |
37 | if(!isDraggable){ |
38 | this.initTarget(id,group,config); |
39 | this.removeFromGroup('sections'); |
40 | }else{ |
41 | this.init(id,group,config); |
42 | this.handle = null; |
43 | } |
44 | |
45 | this.createFrame(); |
46 | this.isTarget = true; |
47 | |
48 | this.resources = []; |
49 | this.numberDisplay = null; |
50 | this.summary = null; |
51 | this.content_td = null; |
52 | this.hidden = false; |
53 | this.highlighted = false; |
54 | this.showOnly = false; |
55 | this.resources_ul = null; |
56 | this.process_section(); |
57 | |
58 | this.viewButton = null; |
59 | this.highlightButton = null; |
60 | this.showOnlyButton = null; |
61 | this.init_buttons(); |
62 | |
63 | if(isDraggable)this.add_handle(); |
64 | |
65 | if(this.debug)YAHOO.log("init_section "+id+" draggable="+isDraggable); |
66 | |
67 | |
68 | if(YAHOO.util.Dom.hasClass(this.getEl(),'hidden')) |
69 | this.toggle_hide(null,null,true); |
70 | |
0a0bb380 |
71 | } |
d4df8fdc |
72 | |
73 | section_class.prototype.init_buttons = function(){ |
74 | var commandContainer = this.getEl().childNodes[2]; |
75 | |
76 | //clear all but show only button |
77 | var commandContainerCount = commandContainer.childNodes.length; |
78 | for(var i=(commandContainerCount-1);i>0;i--) |
79 | commandContainer.removeChild(commandContainer.childNodes[i]) |
80 | |
81 | |
82 | if(!this.isWeekFormat){ |
83 | var highlightbutton = main.mk_button('div','/pix/i/marker.gif'); |
84 | YAHOO.util.Event.addListener(highlightbutton,'click',this.mk_marker,this,true); |
85 | commandContainer.appendChild(highlightbutton); |
86 | this.highlightButton = highlightbutton; |
87 | } |
88 | var viewbutton = main.mk_button('div','/pix/i/hide.gif'); |
89 | YAHOO.util.Event.addListener(viewbutton,'click',this.toggle_hide,this,true); |
90 | commandContainer.appendChild(viewbutton); |
91 | this.viewButton = viewbutton; |
62cb4032 |
92 | |
0a0bb380 |
93 | } |
94 | |
eba88175 |
95 | |
d4df8fdc |
96 | section_class.prototype.add_handle = function(){ |
97 | var handleRef = main.mk_button('div','/pix/i/move_2d.gif',[['style','cursor:move']]); |
98 | YAHOO.util.Dom.generateId(handleRef,'sectionHandle'); |
eba88175 |
99 | |
d4df8fdc |
100 | this.handle = handleRef; |
101 | |
102 | this.getEl().childNodes[0].appendChild(handleRef); |
103 | this.setHandleElId(this.handle.id); |
0a0bb380 |
104 | } |
d4df8fdc |
105 | |
106 | |
107 | section_class.prototype.process_section = function(){ |
108 | this.content_td = this.getEl().childNodes[1]; |
109 | |
110 | |
111 | if(YAHOO.util.Dom.hasClass(this.getEl(),'current')){ |
112 | this.highlighted = true; |
113 | main.marker = this; |
114 | } |
115 | |
116 | |
117 | //create holder for display number for access later |
118 | |
119 | this.numberDisplay = document.createElement('div'); |
120 | this.numberDisplay.innerHTML = this.getEl().childNodes[0].innerHTML; |
121 | this.getEl().childNodes[0].innerHTML = ''; |
122 | this.getEl().childNodes[0].appendChild(this.numberDisplay); |
123 | |
124 | this.sectionId = this.numberDisplay.innerHTML; |
125 | |
126 | if(this.debug)YAHOO.log("Creating section "+this.getEl().id+" in position "+this.sectionId); |
127 | //find/edit resources |
128 | |
129 | this.resources_ul = this.content_td.getElementsByTagName('ul')[0]; |
130 | if(this.resources_ul == null){ |
131 | this.resources_ul = document.createElement('ul'); |
132 | this.resources_ul.className='section'; |
133 | this.content_td.insertBefore(this.resources_ul,this.content_td.childNodes[1]); |
eba88175 |
134 | } |
d4df8fdc |
135 | |
136 | var resource_count = this.resources_ul.getElementsByTagName('li').length; |
137 | |
138 | |
139 | for(var i=0;i<resource_count;i++){ |
140 | var resource = this.resources_ul.getElementsByTagName('li')[i]; |
141 | if(YAHOO.util.Dom.hasClass(resource,'resource')){ |
142 | this.resources[this.resources.length] = new resource_class(resource.id,'resources',null,this); |
143 | if(this.debug)YAHOO.log("Found resource"); |
144 | }else{ |
145 | this.resources[this.resources.length] = new activity_class(resource.id,'resources',null,this); |
146 | } |
147 | } |
eba88175 |
148 | |
d4df8fdc |
149 | this.summary = YAHOO.util.Dom.getElementsByClassName('summary',null,this.getEl())[0].firstChild.data || ''; |
eba88175 |
150 | |
d4df8fdc |
151 | |
152 | } |
153 | |
0a0bb380 |
154 | section_class.prototype.startDrag = function(x, y) { |
155 | //operates in point mode |
156 | YAHOO.util.DDM.mode = YAHOO.util.DDM.POINT; |
d4df8fdc |
157 | |
0a0bb380 |
158 | //remove from resources group temporarily |
159 | this.removeFromGroup('resources'); |
d4df8fdc |
160 | |
0a0bb380 |
161 | //reinitialize dd element |
162 | this.getDragEl().innerHTML = ''; |
d4df8fdc |
163 | |
0a0bb380 |
164 | var targets = YAHOO.util.DDM.getRelated(this, true); |
165 | if(this.debug)YAHOO.log(this.sectionId + " startDrag "+targets.length + " targets"); |
166 | |
d4df8fdc |
167 | } |
0a0bb380 |
168 | |
169 | section_class.prototype.onDragDrop = function(e, id) { |
170 | // get the drag and drop object that was targeted |
171 | var target = YAHOO.util.DDM.getDDById(id); |
172 | |
173 | if(this.debug)YAHOO.log("Section dropped on id="+id+" el = "+this.getEl().id+" x="+YAHOO.util.Dom.getXY(this.getDragEl())); |
d4df8fdc |
174 | |
0a0bb380 |
175 | this.move_to_section(target); |
d4df8fdc |
176 | |
177 | //add back to resources group |
0a0bb380 |
178 | this.addToGroup('resources'); |
d4df8fdc |
179 | } |
0a0bb380 |
180 | section_class.prototype.endDrag = function(){ |
d4df8fdc |
181 | //nessicary to defeat default action |
182 | |
183 | //add back to resources group |
0a0bb380 |
184 | this.addToGroup('resources'); |
d4df8fdc |
185 | } |
186 | |
0a0bb380 |
187 | section_class.prototype.move_to_section = function(target){ |
d4df8fdc |
188 | var tempTd = document.createElement('td'); |
189 | var tempStore = null; |
190 | var sectionCount = main.sections.length; |
191 | var found = null; |
192 | |
193 | //determine if original is above or below target and adjust loop |
194 | var oIndex=main.get_section_index(this); |
195 | var tIndex=main.get_section_index(target); |
196 | |
197 | if(this.debug)YAHOO.log("original is at: "+oIndex+" target is at:"+tIndex+" of "+(sectionCount-1)); |
198 | |
199 | if(oIndex < tIndex){ |
200 | var loopCondition = 'i<sectionCount'; |
201 | var loopStart = 1; |
202 | var loopInc = 'i++'; |
203 | var loopmodifier = 'i-1'; |
204 | }else{ |
205 | var loopCondition = 'i>0'; |
206 | var loopStart = sectionCount-1; |
207 | var loopInc = 'i--'; |
208 | var loopmodifier = 'i+1'; |
209 | } |
210 | |
62cb4032 |
211 | //move on backend |
212 | main.connect('post','class=section&field=move',null,'id='+this.sectionId+'&value='+(target.sectionId-this.sectionId)); |
213 | |
214 | |
215 | //move on front end |
d4df8fdc |
216 | for(var i=loopStart;eval(loopCondition);eval(loopInc)){ |
217 | |
218 | if((main.sections[i] == this)&& !found){ |
219 | //enounter with original node |
220 | if(this.debug)YAHOO.log("Found Original "+main.sections[i].getEl().id); |
221 | if(main.sections[i] == this){ |
222 | found = true; |
223 | } |
224 | |
225 | }else if(main.sections[i] == target){ |
226 | //encounter with target node |
227 | if(this.debug)YAHOO.log("Found target "+main.sections[i].getEl().id); |
228 | main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]); |
229 | found = false; |
230 | break; |
231 | |
232 | }else if(found){ |
233 | //encounter with nodes inbetween |
234 | main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]); |
235 | } |
236 | } |
62cb4032 |
237 | |
0a0bb380 |
238 | } |
d4df8fdc |
239 | |
240 | |
0a0bb380 |
241 | section_class.prototype.swap_with_section = function(sectionIn){ |
d4df8fdc |
242 | var tmpStore = null; |
243 | |
244 | thisIndex = main.get_section_index(this); |
245 | targetIndex = main.get_section_index(sectionIn); |
246 | main.sections[targetIndex] = this; |
247 | main.sections[thisIndex] = sectionIn; |
248 | |
249 | this.changeId(targetIndex); |
250 | sectionIn.changeId(thisIndex); |
251 | |
252 | if(this.debug)YAHOO.log("Swapping "+this.getEl().id+" with "+sectionIn.getEl().id); |
253 | |
254 | YAHOO.util.DDM.swapNode(this.getEl(),sectionIn.getEl()); |
255 | |
256 | |
257 | } |
0a0bb380 |
258 | |
62cb4032 |
259 | section_class.prototype.toggle_hide = function(e,target,superficial){ |
d4df8fdc |
260 | if(this.hidden){ |
261 | YAHOO.util.Dom.removeClass(this.getEl(),'hidden'); |
262 | this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show.gif/i,'hide.gif'); |
263 | this.hidden = false; |
264 | |
62cb4032 |
265 | if(!superficial){ |
266 | main.connect('post','class=section&field=visible',null,'value=1&id='+this.sectionId); |
267 | for(var x=0;x<this.resources.length;x++){ |
268 | this.resources[x].toggle_hide(null,null,true,this.resources[x].hiddenStored); |
269 | this.resources[x].hiddenStored = null; |
270 | } |
271 | } |
272 | |
d4df8fdc |
273 | }else{ |
274 | YAHOO.util.Dom.addClass(this.getEl(),'hidden'); |
275 | this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide.gif/i,'show.gif'); |
276 | this.hidden = true; |
277 | |
62cb4032 |
278 | if(!superficial){ |
279 | main.connect('post','class=section&field=visible',null,'value=0&id='+this.sectionId); |
280 | for(var x=0;x<this.resources.length;x++){ |
281 | this.resources[x].hiddenStored = this.resources[x].hidden; |
282 | this.resources[x].toggle_hide(null,null,true,true); |
283 | } |
284 | } |
d4df8fdc |
285 | } |
0a0bb380 |
286 | } |
287 | |
288 | section_class.prototype.toggle_highlight = function(){ |
d4df8fdc |
289 | if(this.highlighted){ |
290 | YAHOO.util.Dom.removeClass(this.getEl(),'current'); |
291 | this.highlighted = false; |
292 | }else{ |
293 | YAHOO.util.Dom.addClass(this.getEl(),'current'); |
294 | this.highlighted = true; |
295 | } |
296 | } |
297 | |
0a0bb380 |
298 | section_class.prototype.mk_marker = function(){ |
d4df8fdc |
299 | if(main.marker != this){ |
300 | main.update_marker(this); |
301 | |
302 | }else{//if currently the marker |
303 | main.marker = null; |
304 | |
305 | main.connect('post','class=course&field=marker',null,'value=0'); |
306 | this.toggle_highlight(); |
307 | |
308 | } |
309 | |
310 | } |
311 | |
0a0bb380 |
312 | section_class.prototype.changeId = function(newId){ |
d4df8fdc |
313 | this.sectionId = newId; |
314 | this.numberDisplay.firstChild.data = newId; |
315 | |
62cb4032 |
316 | //main.connectQueue_add('post','class=section&field=all',null,'id='+newId+"&summary="+main.mk_safe_for_transport(this.summary)+"&sequence="+this.write_sequence_list(true)+'&visible='+(this.hidden?0:1)) |
d4df8fdc |
317 | |
318 | if(main.marker == this) |
319 | main.update_marker(this); |
320 | } |
0a0bb380 |
321 | |
322 | section_class.prototype.get_resource_index = function(el){ |
d4df8fdc |
323 | for(var x=0;x<this.resources.length;x++) |
324 | if(this.resources[x]==el) |
325 | return x; |
326 | YAHOO.log("Could not find resource to remove "+el.getEl().id,"error"); |
327 | return -1; |
328 | } |
329 | |
0a0bb380 |
330 | section_class.prototype.remove_resource = function(el){ |
d4df8fdc |
331 | var resourceCount = this.resources.length; |
332 | if(resourceCount == 1){ |
333 | if(this.resources[0] == el) |
334 | this.resources = new Array(); |
335 | }else{ |
336 | var found = false; |
337 | for(var i=0;i<resourceCount;i++){ |
338 | if(found){ |
339 | this.resources[i-1] = this.resources[i]; |
340 | if(i==resourceCount-1){ |
341 | this.resources = this.resources.slice(0,-1); |
342 | resourceCount--; |
343 | } |
344 | this.resources[i-1].update_index(i-1); |
345 | }else if(this.resources[i]==el){ |
346 | found = true; |
0a0bb380 |
347 | } |
348 | } |
349 | } |
d4df8fdc |
350 | |
351 | |
352 | //remove "text" nodes to keep DOM clean |
353 | var childIndex = null; |
354 | var childrenCount = this.resources_ul.childNodes.length; |
355 | for(var i=0;i<childrenCount;i++) |
356 | if(this.resources_ul.childNodes[i] == el.getEl()) |
357 | childIndex = i; |
358 | if(childIndex > 0 && childIndex < this.resources_ul.childNodes.length) |
359 | this.resources_ul.removeChild(this.resources_ul.childNodes[childIndex-1]); |
360 | YAHOO.log("removing "+el.getEl().id); |
361 | if(el.getEl().parentNode != null) |
362 | el.getEl().parentNode.removeChild(el.getEl()); |
363 | |
364 | this.write_sequence_list(); |
365 | |
366 | } |
367 | |
0a0bb380 |
368 | section_class.prototype.insert_resource = function(el,targetel){ |
d4df8fdc |
369 | var resourcecount = this.resources.length; |
370 | var found = false; |
371 | var tempStore = nextStore = null; |
372 | |
62cb4032 |
373 | //update in backend |
374 | targetId=''; |
375 | if(targetel !=null){ |
376 | targetId=targetel.id; |
377 | } |
378 | |
379 | main.connect('post','class=resource&field=move',null,'id='+el.id+'&beforeId='+targetId+'§ionId='+this.sectionId); |
380 | |
381 | |
382 | |
383 | //if inserting into a hidden resource hide |
384 | if(this.hidden){ |
385 | el.hiddenStored = el.hidden; |
386 | el.toggle_hide(null,null,true,true); |
387 | }else{ |
388 | if(el.hiddenStored != null){ |
389 | el.toggle_hide(null,null,true,el.hiddenStored); |
390 | el.hiddenStored = null; |
391 | } |
392 | } |
393 | |
394 | //update model |
d4df8fdc |
395 | if(targetel == null){ |
396 | this.resources[this.resources.length] = el; |
397 | }else |
398 | for(var i=0;i<resourcecount;i++){ |
399 | if(found){ |
400 | tempStore = this.resources[i]; |
401 | this.resources[i] = nextStore; |
402 | nextStore = tempStore; |
403 | |
404 | if(nextStore != null) |
405 | nextStore.update_index(i+1); |
406 | |
407 | }else if(this.resources[i] == targetel){ |
408 | found = true; |
409 | nextStore = this.resources[i]; |
410 | this.resources[i] = el; |
411 | resourcecount++; |
412 | |
413 | this.resources[i].update_index(i,this.ident); |
0a0bb380 |
414 | nextStore.update_index(i+1); |
d4df8fdc |
415 | } |
416 | } |
0a0bb380 |
417 | |
62cb4032 |
418 | //update on frontend |
d4df8fdc |
419 | if(targetel != null){ |
420 | this.resources_ul.insertBefore(el.getEl(),targetel.getEl()); |
421 | this.resources_ul.insertBefore(document.createTextNode(''),targetel.getEl()); |
422 | |
423 | }else{ |
424 | this.resources_ul.appendChild(el.getEl()); |
425 | this.resources_ul.appendChild(document.createTextNode(" ")); |
426 | } |
62cb4032 |
427 | el.parentObj = this; |
0a0bb380 |
428 | } |
d4df8fdc |
429 | |
0a0bb380 |
430 | section_class.prototype.write_sequence_list = function(toReturn){ |
d4df8fdc |
431 | var listOutput = ''; |
432 | for(var i=0;i<this.resources.length;i++){ |
433 | listOutput += this.resources[i].id; |
434 | if(i != (this.resources.length-1)) |
435 | listOutput += ','; |
436 | } |
437 | |
438 | if(toReturn) |
439 | return listOutput; |
440 | |
d4df8fdc |
441 | } |
442 | |
443 | |
444 | |
0a0bb380 |
445 | /* |
446 | * Resource Class extends util.DDProxy |
447 | */ |
d4df8fdc |
448 | |
0a0bb380 |
449 | |
450 | function resource_class(id,group,config,parentObj){ |
451 | |
452 | this.init_resource(id,group,config,parentObj); |
453 | } |
454 | YAHOO.extend(resource_class, YAHOO.util.DDProxy); |
455 | |
d4df8fdc |
456 | resource_class.prototype.debug = true; |
457 | |
0a0bb380 |
458 | resource_class.prototype.init_resource = function(id,group,config,parentObj){ |
d4df8fdc |
459 | if (!id) { |
460 | YAHOO.log("Init resource, NO ID FOUND!",'error'); |
461 | return; |
462 | } |
463 | |
464 | this.is = 'resource'; |
465 | this.init(id,group,config); |
466 | this.createFrame(); |
467 | this.isTarget = true; |
468 | |
469 | this.id = this.getEl().id.replace(/module-/i,''); |
470 | |
471 | this.hidden = false; |
472 | if(YAHOO.util.Dom.hasClass(this.getEl().getElementsByTagName('a')[0],'dimmed')) |
473 | this.hidden = true; |
62cb4032 |
474 | this.hiddenStored = null; |
eba88175 |
475 | |
d4df8fdc |
476 | this.linkContainer = this.getEl().getElementsByTagName('a')[0]; |
477 | |
478 | this.commandContainer = null; |
479 | this.viewButton = null; |
480 | this.handle = null; |
481 | this.init_buttons(); |
482 | |
483 | this.parentObj = parentObj; |
eba88175 |
484 | |
d4df8fdc |
485 | if(this.debug)YAHOO.log("init_resource "+id+" parent = "+parentObj.getEl().id); |
0a0bb380 |
486 | |
487 | } |
d4df8fdc |
488 | |
0a0bb380 |
489 | resource_class.prototype.init_buttons = function(){ |
d4df8fdc |
490 | var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands','span',this.getEl())[0]; |
491 | if( commandContainer == null){ |
492 | YAHOO.log('Cannot find command container for '+this.getEl().id,'error'); |
493 | return; |
494 | } |
495 | |
496 | this.commandContainer = commandContainer; |
497 | |
498 | //find edit button |
499 | var updateButton = null; |
500 | var buttons = commandContainer.getElementsByTagName('a'); |
669d3ecd |
501 | for (var x=0;x<buttons.length;x++) { |
e78a3505 |
502 | if (buttons[x].title == main.portal.strings['update']) { |
d4df8fdc |
503 | updateButton = buttons[x]; |
669d3ecd |
504 | } |
505 | } |
d4df8fdc |
506 | |
507 | if(updateButton == null) |
0a0bb380 |
508 | YAHOO.log('Cannot find updateButton for '+this.getEl().id,'error'); |
d4df8fdc |
509 | |
510 | commandContainer.innerHTML = ''; |
511 | |
512 | |
513 | //add move-handle |
514 | var handleRef = main.mk_button('a','/pix/i/move_2d.gif',[['style','cursor:move']],[['height','11'],['width','11'],['hspace','2'],['border','0']]); |
515 | YAHOO.util.Dom.generateId(handleRef,'sectionHandle'); |
516 | this.handle = handleRef; |
517 | |
518 | commandContainer.appendChild(handleRef); |
519 | this.setHandleElId(this.handle.id); |
520 | |
521 | |
522 | |
523 | //add edit button back in |
524 | commandContainer.appendChild(updateButton); |
525 | |
526 | //add rest |
527 | var button = main.mk_button('a','/pix/t/delete.gif'); |
528 | YAHOO.util.Event.addListener(button,'click',this.delete_button,this,true); |
529 | commandContainer.appendChild(button); |
530 | |
531 | if(this.hidden) |
532 | var button = main.mk_button('a','/pix/t/show.gif'); |
533 | else |
534 | var button = main.mk_button('a','/pix/t/hide.gif'); |
535 | YAHOO.util.Event.addListener(button,'click',this.toggle_hide,this,true); |
536 | commandContainer.appendChild(button); |
537 | this.viewButton = button; |
538 | |
539 | } |
540 | |
62cb4032 |
541 | resource_class.prototype.toggle_hide = function(target,e,superficial,force){ |
542 | if(force != null){ |
543 | if(this.debug)YAHOO.log("Resource "+this.getEl().id+" forced to "+force); |
544 | this.hidden = !force; |
545 | } |
546 | |
d4df8fdc |
547 | if(this.hidden){ |
548 | YAHOO.util.Dom.removeClass(this.linkContainer,'dimmed'); |
549 | this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show.gif/i,'hide.gif'); |
62cb4032 |
550 | this.hidden = false; |
551 | |
552 | if(!superficial){ |
553 | main.connect('post','class=resource&field=visible',null,'value=1&id='+this.id); |
554 | } |
d4df8fdc |
555 | }else{ |
556 | YAHOO.util.Dom.addClass(this.linkContainer,'dimmed'); |
557 | this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide.gif/i,'show.gif'); |
558 | this.hidden = true; |
559 | |
62cb4032 |
560 | if(!superficial){ |
561 | main.connect('post','class=resource&field=visible',null,'value=0&id='+this.id); |
562 | } |
d4df8fdc |
563 | } |
0a0bb380 |
564 | } |
565 | |
566 | resource_class.prototype.delete_button = function(){ |
d4df8fdc |
567 | if(this.debug)YAHOO.log("Deleteing "+this.getEl().id+"from parent "+this.parentObj.getEl().id); |
568 | |
1752e584 |
569 | if(!confirm('Are you sure you wish to delete this '+this.is+"?")){ |
570 | return false; |
571 | } |
572 | |
d4df8fdc |
573 | this.getEl().parentNode.removeChild(this.getEl()); |
574 | this.parentObj.remove_resource(this); |
575 | |
576 | main.connect('delete','class=resource&id='+this.id); |
577 | } |
578 | |
0a0bb380 |
579 | resource_class.prototype.update_index = function(index){ |
d4df8fdc |
580 | if(this.debug)YAHOO.log("update Index for resource "+this.getEl().id+"to"+index); |
581 | } |
582 | |
583 | |
0a0bb380 |
584 | resource_class.prototype.startDrag = function(x, y) { |
585 | //operates in intersect mode |
586 | YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT; |
d4df8fdc |
587 | |
0a0bb380 |
588 | //reinitialize dd element |
589 | this.getDragEl().innerHTML = ''; |
d4df8fdc |
590 | |
0a0bb380 |
591 | var targets = YAHOO.util.DDM.getRelated(this, true); |
592 | if(this.debug)YAHOO.log(this.id + " startDrag "+targets.length + " targets"); |
d4df8fdc |
593 | |
594 | } |
0a0bb380 |
595 | |
596 | resource_class.prototype.onDragDrop = function(e, ids) { |
597 | // best fit Id |
598 | var id=[]; |
599 | for(var i=0;i<ids.length;i++) |
d4df8fdc |
600 | if(ids[i].is == 'resource') |
601 | id[id.length] = ids[i]; |
0a0bb380 |
602 | |
603 | if(id.length == 0) |
d4df8fdc |
604 | id = ids; |
605 | |
606 | |
0a0bb380 |
607 | // get the drag and drop object that was targeted |
608 | var target = YAHOO.util.DDM.getBestMatch(id); |
609 | |
610 | if(this.debug)YAHOO.log("dropped on id="+target+" el = "+this.getEl().id+" x="+YAHOO.util.Dom.getXY(this.getDragEl())); |
d4df8fdc |
611 | |
0a0bb380 |
612 | this.parentObj.remove_resource(this); |
613 | |
614 | if(target.is == 'resource'||target.is == 'activity'){ |
615 | target.parentObj.insert_resource(this,target); |
d4df8fdc |
616 | |
0a0bb380 |
617 | }else if(target.is =='section'){ |
618 | target.insert_resource(this); |
d4df8fdc |
619 | |
0a0bb380 |
620 | } |
621 | |
622 | return; |
d4df8fdc |
623 | } |
0a0bb380 |
624 | |
625 | resource_class.prototype.endDrag = function() { |
d4df8fdc |
626 | //eliminates default action |
627 | } |
628 | |
0a0bb380 |
629 | /* |
630 | * activity Class extends resource class |
631 | */ |
d4df8fdc |
632 | |
633 | |
0a0bb380 |
634 | function activity_class(id,group,config,parentObj){ |
635 | this.init_activity(id,group,config,parentObj); |
636 | } |
637 | YAHOO.extend(activity_class, resource_class); |
638 | |
639 | activity_class.prototype.init_activity = function(id,group,config,parentObj){ |
d4df8fdc |
640 | if (!id) { |
641 | YAHOO.log("Init activity, NO ID FOUND!",'error'); |
642 | return; |
643 | } |
644 | |
645 | this.is = 'activity'; |
646 | this.currentGroup = this.get_current_group(id); |
647 | |
648 | this.init_resource(id,group,config,parentObj); |
649 | |
650 | this.groupButton= null; |
651 | this.init_activity_button(); |
652 | |
653 | if(this.debug)YAHOO.log("--init_activity "+id); |
654 | |
655 | } |
656 | |
0a0bb380 |
657 | activity_class.prototype.groupImages = ['/pix/t/groupn.gif','/pix/t/groups.gif','/pix/t/groupv.gif']; |
d4df8fdc |
658 | |
0a0bb380 |
659 | activity_class.prototype.init_activity_button = function(){ |
d4df8fdc |
660 | var button = main.mk_button('a',this.groupImages[this.currentGroup]); |
661 | YAHOO.util.Event.addListener(button,'click',this.toggle_group,this,true); |
662 | this.commandContainer.appendChild(button); |
663 | this.groupButton = button; |
664 | } |
0a0bb380 |
665 | |
666 | activity_class.prototype.get_current_group = function(id){ |
d4df8fdc |
667 | if(document.getElementById(id) == null){ |
668 | return; |
669 | } |
670 | |
671 | var groupNodeArray = document.getElementById(id).getElementsByTagName('a'); |
672 | var groupNode = groupNodeArray[groupNodeArray.length-1]; |
673 | |
674 | for(var x=0;x<this.groupImages.length;x++){ |
675 | if(main.portal.wwwroot+this.groupImages[x] == groupNode.getElementsByTagName('img')[0].src){ |
0a0bb380 |
676 | return x; |
677 | } |
d4df8fdc |
678 | } |
679 | |
680 | return 0; |
0a0bb380 |
681 | } |
d4df8fdc |
682 | |
0a0bb380 |
683 | activity_class.prototype.toggle_group = function(){ |
d4df8fdc |
684 | this.currentGroup++; |
685 | if(this.currentGroup > 2) |
686 | this.currentGroup = 0; |
687 | |
688 | this.groupButton.getElementsByTagName('img')[0].src = main.portal.wwwroot + this.groupImages[this.currentGroup]; |
689 | |
690 | main.connect('post','class=resource&field=groupmode',null,'value='+this.currentGroup+'&id='+this.id); |
691 | } |
669d3ecd |
692 | |