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