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