adding current groupid to grade_export class - soon to be used in plugins
[moodle-pu.git] / lib / ajax / section_classes.js
blob9c0add90776c56c9280f2d9ac3de4b1bd8aceaae
1 /**
2 * library for ajaxcourse formats, the classes and related functions for
3 * sections and resources.
5 * This library requires a 'main' object created in calling document.
7 * Drag and drop notes:
9 * Dropping an activity or resource on a section will always add the activity
10 * or resource at the end of that section.
12 * Dropping an activity or resource on another activity or resource will
13 * always move the former just above the latter.
15 * $Id$
19 /**
20 * section_class
22 function section_class(id, group, config, isDraggable) {
23 this.init_section(id, group, config, isDraggable);
26 YAHOO.extend(section_class, YAHOO.util.DDProxy);
29 section_class.prototype.debug = false;
32 section_class.prototype.init_section = function(id, group, config, isDraggable) {
34 if (!id) {
35 return;
38 this.is = 'section';
39 this.sectionId = null; // Section number. This is NOT the section id from
40 // the database.
42 if (!isDraggable) {
43 this.initTarget(id, group, config);
44 this.removeFromGroup('sections');
45 } else {
46 this.init(id, group, config);
47 this.handle = null;
50 this.createFrame();
51 this.isTarget = true;
53 this.resources = [];
54 this.numberDisplay = null; // Used to display the section number on the top left
55 // of the section. Not used in all course formats.
56 this.summary = null;
57 this.content_td = null;
58 this.hidden = false;
59 this.highlighted = false;
60 this.showOnly = false;
61 this.resources_ul = null;
62 this.process_section();
64 this.viewButton = null;
65 this.highlightButton = null;
66 this.showOnlyButton = null;
67 this.init_buttons();
69 if (isDraggable) {
70 this.add_handle();
72 if (this.debug) {
73 YAHOO.log("init_section "+id+" draggable="+isDraggable);
75 if (YAHOO.util.Dom.hasClass(this.getEl(),'hidden')) {
76 this.toggle_hide(null,null,true);
81 section_class.prototype.init_buttons = function() {
82 var commandContainer = this.getEl().childNodes[2];
84 //clear all but show only button
85 var commandContainerCount = commandContainer.childNodes.length;
87 for (var i=(commandContainerCount-1); i>0; i--) {
88 commandContainer.removeChild(commandContainer.childNodes[i])
91 if (!this.isWeekFormat) {
92 var highlightbutton = main.mk_button('div', '/i/marker.gif');
93 YAHOO.util.Event.addListener(highlightbutton, 'click', this.mk_marker, this, true);
94 commandContainer.appendChild(highlightbutton);
95 this.highlightButton = highlightbutton;
97 var viewbutton = main.mk_button('div', '/i/hide.gif');
98 YAHOO.util.Event.addListener(viewbutton, 'click', this.toggle_hide, this,true);
99 commandContainer.appendChild(viewbutton);
100 this.viewButton = viewbutton;
104 section_class.prototype.add_handle = function() {
105 var handleRef = main.mk_button('a', '/i/move_2d.gif',
106 [['style','cursor:move'], ['title', main.portal.strings['move']]]);
108 YAHOO.util.Dom.generateId(handleRef, 'sectionHandle');
110 this.handle = handleRef;
112 this.getEl().childNodes[0].appendChild(handleRef);
113 this.setHandleElId(this.handle.id);
117 section_class.prototype.process_section = function() {
118 this.content_td = this.getEl().childNodes[1];
120 if (YAHOO.util.Dom.hasClass(this.getEl(),'current')) {
121 this.highlighted = true;
122 main.marker = this;
125 // Create holder for display number for access later
127 this.numberDisplay = document.createElement('div');
128 this.numberDisplay.innerHTML = this.getEl().childNodes[0].innerHTML;
129 this.getEl().childNodes[0].innerHTML = '';
130 this.getEl().childNodes[0].appendChild(this.numberDisplay);
132 this.sectionId = this.id.replace(/section-/i, ''); // Okay, we will have to change this if we
133 // ever change the id attributes format
134 // for the sections.
135 if (this.debug) {
136 YAHOO.log("Creating section "+this.getEl().id+" in position "+this.sectionId);
139 // Find/edit resources
140 this.resources_ul = this.content_td.getElementsByTagName('ul')[0];
141 if (!this.resources_ul) {
142 this.resources_ul = document.createElement('ul');
143 this.resources_ul.className='section';
144 this.content_td.insertBefore(this.resources_ul, this.content_td.lastChild);
146 var resource_count = this.resources_ul.getElementsByTagName('li').length;
148 for (var i=0;i<resource_count;i++) {
149 var resource = this.resources_ul.getElementsByTagName('li')[i];
150 this.resources[this.resources.length] = new resource_class(resource.id, 'resources', null, this);
152 this.summary = YAHOO.util.Dom.getElementsByClassName('summary', null, this.getEl())[0].firstChild.data || '';
156 section_class.prototype.startDrag = function(x, y) {
157 //operates in point mode
158 YAHOO.util.DDM.mode = YAHOO.util.DDM.POINT;
160 //remove from resources group temporarily
161 this.removeFromGroup('resources');
163 //reinitialize dd element
164 this.getDragEl().innerHTML = '';
166 var targets = YAHOO.util.DDM.getRelated(this, true);
168 if (this.debug) {
169 YAHOO.log(this.id + " startDrag, "+targets.length + " targets");
174 section_class.prototype.onDragDrop = function(e, id) {
175 // get the drag and drop object that was targeted
176 var target = YAHOO.util.DDM.getDDById(id);
178 if (this.debug) {
179 YAHOO.log("Section dropped on id="+id+" (I am "+this.getEl().id+") x="
180 +YAHOO.util.Dom.getXY(this.getDragEl()));
182 this.move_to_section(target);
184 //add back to resources group
185 this.addToGroup('resources');
189 section_class.prototype.endDrag = function() {
190 //nessicary to defeat default action
192 //add back to resources group
193 this.addToGroup('resources');
197 section_class.prototype.move_to_section = function(target) {
198 var tempTd = document.createElement('td');
199 var tempStore = null;
200 var sectionCount = main.sections.length;
201 var found = null;
203 //determine if original is above or below target and adjust loop
204 var oIndex = main.get_section_index(this);
205 var tIndex = main.get_section_index(target);
207 if (this.debug) {
208 YAHOO.log("original is at: "+oIndex+" target is at:"+tIndex+" of "+(sectionCount-1));
210 if (oIndex < tIndex) {
211 var loopCondition = 'i<sectionCount';
212 var loopStart = 1;
213 var loopInc = 'i++';
214 var loopmodifier = 'i - 1';
215 } else {
216 var loopCondition = 'i > 0';
217 var loopStart = sectionCount - 1;
218 var loopInc = 'i--';
219 var loopmodifier = 'i + 1';
222 //move on backend
223 main.connect('POST','class=section&field=move',null,'id='+this.sectionId+'&value='
224 +(target.sectionId - this.sectionId));
226 //move on front end
227 for (var i=loopStart; eval(loopCondition); eval(loopInc)) {
229 if ((main.sections[i] == this) && !found) {
230 //enounter with original node
231 if (this.debug) {
232 YAHOO.log("Found Original "+main.sections[i].getEl().id);
234 if (main.sections[i] == this) {
235 found = true;
237 } else if (main.sections[i] == target) {
238 //encounter with target node
239 if (this.debug) {
240 YAHOO.log("Found target "+main.sections[i].getEl().id);
242 main.sections[i].swap_dates(main.sections[eval(loopmodifier)]);
243 main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]);
244 found = false;
245 break;
246 } else if (found) {
247 //encounter with nodes inbetween
248 main.sections[i].swap_dates(main.sections[eval(loopmodifier)]);
249 main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]);
255 section_class.prototype.swap_with_section = function(sectionIn) {
256 var tmpStore = null;
258 thisIndex = main.get_section_index(this);
259 targetIndex = main.get_section_index(sectionIn);
260 main.sections[targetIndex] = this;
261 main.sections[thisIndex] = sectionIn;
263 this.changeId(targetIndex);
264 sectionIn.changeId(thisIndex);
266 if (this.debug) {
267 YAHOO.log("Swapping "+this.getEl().id+" with "+sectionIn.getEl().id);
269 // Swap the sections.
270 YAHOO.util.DDM.swapNode(this.getEl(), sectionIn.getEl());
272 // Sections contain forms to add new resources/activities. These forms
273 // have not been updated to reflect the new positions of the sections that
274 // we have swapped. Let's swap the two sections' forms around.
275 if (this.getEl().getElementsByTagName('form')[0].parentNode
276 && sectionIn.getEl().getElementsByTagName('form')[0].parentNode) {
278 YAHOO.util.DDM.swapNode(this.getEl().getElementsByTagName('form')[0].parentNode,
279 sectionIn.getEl().getElementsByTagName('form')[0].parentNode);
280 } else {
281 YAHOO.log("Swapping sections: form not present in one or both sections", "warn");
286 section_class.prototype.toggle_hide = function(e,target,superficial) {
287 if (this.hidden) {
288 YAHOO.util.Dom.removeClass(this.getEl(), 'hidden');
289 this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show.gif/i, 'hide.gif');
290 this.hidden = false;
292 if (!superficial) {
293 main.connect('POST', 'class=section&field=visible', null, 'value=1&id='+this.sectionId);
294 for (var x=0; x<this.resources.length; x++) {
295 this.resources[x].toggle_hide(null, null, true, this.resources[x].hiddenStored);
296 this.resources[x].hiddenStored = null;
300 } else {
301 YAHOO.util.Dom.addClass(this.getEl(), 'hidden');
302 this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide.gif/i, 'show.gif');
303 this.hidden = true;
305 if (!superficial) {
306 main.connect('POST', 'class=section&field=visible', null, 'value=0&id='+this.sectionId);
307 for (var x=0; x<this.resources.length; x++) {
308 this.resources[x].hiddenStored = this.resources[x].hidden;
309 this.resources[x].toggle_hide(null, null, true, true);
316 section_class.prototype.toggle_highlight = function() {
317 if (this.highlighted) {
318 YAHOO.util.Dom.removeClass(this.getEl(), 'current');
319 this.highlighted = false;
320 } else {
321 YAHOO.util.Dom.addClass(this.getEl(), 'current');
322 this.highlighted = true;
327 section_class.prototype.mk_marker = function() {
328 if (main.marker != this) {
329 main.update_marker(this);
330 } else {
331 // If currently the marker
332 main.marker = null;
334 main.connect('POST', 'class=course&field=marker', null, 'value=0');
335 this.toggle_highlight();
340 section_class.prototype.changeId = function(newId) {
341 this.sectionId = newId;
342 this.numberDisplay.firstChild.data = newId;
344 //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))
346 if (main.marker == this) {
347 main.update_marker(this);
352 section_class.prototype.get_resource_index = function(el) {
353 for (var x=0; x<this.resources.length; x++) {
354 if (this.resources[x] == el) {
355 return x;
358 YAHOO.log("Could not find resource to remove "+el.getEl().id, "error");
359 return -1;
363 section_class.prototype.remove_resource = function(el) {
365 var resourceEl = el.getEl();
366 var parentEl = resourceEl.parentNode;
367 if (!parentEl) {
368 return false;
371 var resourceCount = this.resources.length;
373 if (resourceCount == 1) {
374 if (this.resources[0] == el) {
375 this.resources = new Array();
377 } else {
378 var found = false;
379 for (var i=0; i<resourceCount; i++) {
380 if (found) {
381 this.resources[i - 1] = this.resources[i];
382 if (i == resourceCount - 1) {
383 this.resources = this.resources.slice(0, -1);
384 resourceCount--;
386 this.resources[i - 1].update_index(i - 1);
387 } else if (this.resources[i] == el) {
388 found = true;
392 // Remove any extra text nodes to keep DOM clean.
393 var kids = parentEl.childNodes;
395 for (var i=0; i<kids.length; i++) {
396 if (kids[i].nodeType == 3) {
397 YAHOO.log('Removed extra text node.');
398 parentEl.removeChild(kids[i]);
401 parentEl.removeChild(resourceEl);
403 this.write_sequence_list();
404 return true;
408 section_class.prototype.insert_resource = function(el, targetel) {
409 var resourcecount = this.resources.length;
410 var found = false;
411 var tempStore = nextStore = null;
413 //update in backend
414 var targetId = '';
415 if (targetel) {
416 targetId = targetel.id;
418 if (this.debug) {
419 YAHOO.log('id='+el.id+', beforeId='+targetId+', sectionId='+this.sectionId);
421 main.connect('POST', 'class=resource&field=move', null,
422 'id='+el.id+'&beforeId='+targetId+'&sectionId='+this.sectionId);
424 //if inserting into a hidden resource hide
425 if (this.hidden) {
426 el.hiddenStored = el.hidden;
427 el.toggle_hide(null, null, true, true);
428 } else {
429 if (el.hiddenStored != null) {
430 el.toggle_hide(null, null, true, el.hiddenStored);
431 el.hiddenStored = null;
434 //update model
435 if (!targetel) {
436 this.resources[this.resources.length] = el;
437 } else {
438 for (var i=0; i<resourcecount; i++) {
439 if (found) {
440 tempStore = this.resources[i];
441 this.resources[i] = nextStore;
442 nextStore = tempStore;
444 if (nextStore != null)
445 nextStore.update_index(i+1);
447 } else if (this.resources[i] == targetel) {
448 found = true;
449 nextStore = this.resources[i];
450 this.resources[i] = el;
451 resourcecount++;
453 this.resources[i].update_index(i, this.ident);
454 nextStore.update_index(i + 1);
458 //update on frontend
459 if (targetel) {
460 this.resources_ul.insertBefore(el.getEl(), targetel.getEl());
461 //this.resources_ul.insertBefore(document.createTextNode(' '), targetel.getEl());
462 } else {
463 this.resources_ul.appendChild(el.getEl());
464 //this.resources_ul.appendChild(document.createTextNode(' '));
466 el.parentObj = this;
470 section_class.prototype.write_sequence_list = function(toReturn) {
471 var listOutput = '';
473 for (var i=0; i<this.resources.length; i++) {
474 listOutput += this.resources[i].id;
475 if (i != (this.resources.length-1)) {
476 listOutput += ',';
479 if (toReturn) {
480 return listOutput;
488 * resource_class extends util.DDProxy
490 function resource_class(id,group,config,parentObj) {
491 this.init_resource(id,group,config,parentObj);
494 YAHOO.extend(resource_class, YAHOO.util.DDProxy);
497 resource_class.prototype.debug = false;
500 resource_class.prototype.init_resource = function(id, group, config, parentObj) {
501 if (!id) {
502 YAHOO.log("Init resource, NO ID FOUND!", 'error');
503 return;
506 // Some constants.
507 this.NOGROUPS = 0;
508 this.SEPARATEGROUPS = 1;
509 this.VISIBLEGROUPS = 2;
511 this.is = 'resource';
512 this.init(id, group, config);
513 this.createFrame();
514 this.isTarget = true;
516 this.id = this.getEl().id.replace(/module-/i, '');
518 this.hidden = false;
519 if (YAHOO.util.Dom.hasClass(this.getEl().getElementsByTagName('a')[0], 'dimmed')) {
520 this.hidden = true;
522 this.hiddenStored = null;
524 this.groupmode = null; // Can be null (i.e. does not apply), 0, 1 or 2.
526 this.linkContainer = this.getEl().getElementsByTagName('a')[0];
528 this.commandContainer = null;
529 this.indentLeftButton = null;
530 this.indentRightButton = null;
531 this.viewButton = null;
532 this.groupButton = null;
533 this.handle = null;
534 this.init_buttons();
536 this.parentObj = parentObj;
538 if (this.debug) {
539 YAHOO.log("init_resource "+id+" parent = "+parentObj.getEl().id);
545 * The current strategy is to look at the DOM tree to get information on the
546 * resource and it's current mode. This is bad since we are dependant on
547 * the html that is output from serverside logic. Seemingly innocuous changes
548 * like changing the language string for the title of a button will break
549 * our JavaScript here. This is brittle.
551 * First, we clear the buttons container. Then:
552 * We need to add the new-style move handle.
553 * The old style move button (up/down) needs to be removed.
554 * Move left button (if any) needs an event handler.
555 * Move right button (if any) needs an event handler.
556 * Update button stays as it is. Add it back.
557 * Delete button needs an event handler.
558 * Visible button is a toggle. It needs an event handler too.
559 * Group mode button is a toggle. It needs an event handler too.
561 resource_class.prototype.init_buttons = function() {
563 var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands',
564 'span', this.getEl())[0];
566 if (commandContainer == null) {
567 YAHOO.log('Cannot find command container for '+this.getEl().id, 'error');
568 return;
571 // Language strings.
572 var strgroupsnone = main.portal.strings['groupsnone']+' ('+main.portal.strings['clicktochange']+')';
573 var strgroupsseparate = main.portal.strings['groupsseparate']+' ('+main.portal.strings['clicktochange']+')';
574 var strgroupsvisible = main.portal.strings['groupsvisible']+' ('+main.portal.strings['clicktochange']+')';
576 this.commandContainer = commandContainer;
577 var buttons = commandContainer.getElementsByTagName('a');
579 // Buttons that we might need to add back in.
580 var moveLeft = false;
581 var moveRight = false;
582 var updateButton = null;
584 for (var x=0; x<buttons.length; x++) {
585 if (buttons[x].className == 'editing_moveleft') {
586 moveLeft = true;
587 } else if (buttons[x].className == 'editing_moveright') {
588 moveRight = true;
589 } else if (buttons[x].className == 'editing_update') {
590 updateButton = buttons[x].cloneNode(true);
591 } else if (buttons[x].className == 'editing_groupsnone') {
592 this.groupmode = this.NOGROUPS;
593 } else if (buttons[x].className == 'editing_groupsseparate') {
594 this.groupmode = this.SEPARATEGROUPS;
595 } else if (buttons[x].className == 'editing_groupsvisible') {
596 this.groupmode = this.VISIBLEGROUPS;
600 if (updateButton == null) {
601 // Update button must always be present.
602 YAHOO.log('Cannot find updateButton for '+this.getEl().id, 'error');
605 // Clear all the buttons.
606 commandContainer.innerHTML = '';
608 // Add move-handle for drag and drop.
609 var handleRef = main.mk_button('a', '/i/move_2d.gif',
610 [['style', 'cursor:move'], ['title', main.portal.strings['move']]],
611 [['height', '11'], ['width', '11'], ['style', 'margin-right:3px; border:0;']]);
613 YAHOO.util.Dom.generateId(handleRef, 'sectionHandle');
614 this.handle = handleRef;
615 commandContainer.appendChild(handleRef);
616 this.setHandleElId(this.handle.id);
618 // Add indentation buttons if needed (move left, move right).
619 if (moveLeft) {
620 var button = main.mk_button('a', '/t/left.gif', [['title', main.portal.strings['moveleft']],
621 ['class', 'editing_moveleft']]);
622 YAHOO.util.Event.addListener(button, 'click', this.indent_left, this, true);
623 commandContainer.appendChild(button);
624 this.indentLeftButton = button;
627 if (moveRight) {
628 var button = main.mk_button('a', '/t/right.gif', [['title', main.portal.strings['moveright']],
629 ['class', 'editing_moveright']]);
630 YAHOO.util.Event.addListener(button, 'click', this.indent_right, this, true);
631 commandContainer.appendChild(button);
632 this.indentRightButton = button;
635 // Add edit button back in.
636 commandContainer.appendChild(updateButton);
638 // Add the delete button.
639 var button = main.mk_button('a', '/t/delete.gif');
640 YAHOO.util.Event.addListener(button, 'click', this.delete_button, this, true);
641 commandContainer.appendChild(button);
643 // Add the hide or show button.
644 if (this.hidden) {
645 var button = main.mk_button('a', '/t/show.gif');
646 } else {
647 var button = main.mk_button('a', '/t/hide.gif');
649 YAHOO.util.Event.addListener(button, 'click', this.toggle_hide, this, true);
650 commandContainer.appendChild(button);
651 this.viewButton = button;
653 // Add the groupmode button if needed.
654 if (this.groupmode != null) {
655 if (this.groupmode == this.NOGROUPS) {
656 var button = main.mk_button('a', '/t/groupn.gif', [['title', strgroupsnone]]);
657 } else if (this.groupmode == this.SEPARATEGROUPS) {
658 var button = main.mk_button('a', '/t/groups.gif', [['title', strgroupsseparate]]);
659 } else {
660 var button = main.mk_button('a', '/t/groupv.gif', [['title', strgroupsvisible]]);
662 YAHOO.util.Event.addListener(button, 'click', this.toggle_groupmode, this, true);
663 commandContainer.appendChild(button);
664 this.groupButton = button;
669 resource_class.prototype.indent_left = function() {
671 var spacer = YAHOO.util.Dom.getElementsByClassName('spacer',
672 'img', this.getEl())[0];
673 if (!spacer) {
674 if (this.debug) {
675 YAHOO.log('Could not indent left: spacer image does not exist', 'error');
677 return false;
679 if (spacer.width > 20) {
680 spacer.width -= 20;
681 } else {
682 // Remove the spacer.
683 resource = this.getEl();
684 resource.removeChild(spacer);
686 // Remove the indent left button as well.
687 var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands',
688 'span', this.getEl())[0];
690 commandContainer.removeChild(this.indentLeftButton);
691 this.indentLeftButton = null;
693 main.connect('POST', 'class=resource&field=indentleft', null, 'id='+this.id);
694 return true;
698 resource_class.prototype.indent_right = function() {
700 var spacer = YAHOO.util.Dom.getElementsByClassName('spacer',
701 'img', this.getEl())[0];
702 if (!spacer) {
703 var spacer = document.createElement('img');
705 spacer.setAttribute('src', main.portal.strings['pixpath']+'/spacer.gif');
706 spacer.className = 'spacer';
707 spacer.setAttribute('width', '20');
708 spacer.setAttribute('height', '12');
710 var resource = this.getEl();
711 resource.insertBefore(spacer, resource.childNodes[0]);
712 } else {
713 spacer.width += 20;
715 // Add a indent left button if none is present.
716 var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands',
717 'span', this.getEl())[0];
719 if (!this.indentLeftButton) {
720 var button = main.mk_button('a', '/t/left.gif', [['title', main.portal.strings['moveleft']],
721 ['class', 'editing_moveleft']]);
722 YAHOO.util.Event.addListener(button, 'click', this.indent_left, this, true);
723 commandContainer.insertBefore(button, this.indentRightButton);
724 this.indentLeftButton = button;
726 main.connect('POST', 'class=resource&field=indentright', null, 'id='+this.id);
727 return true;
731 resource_class.prototype.toggle_hide = function(target, e, superficial, force) {
732 if (force != null) {
733 if (this.debug) {
734 YAHOO.log("Resource "+this.getEl().id+" forced to "+force);
736 this.hidden = !force;
738 if (this.hidden) {
739 YAHOO.util.Dom.removeClass(this.linkContainer, 'dimmed');
740 this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show.gif/i, 'hide.gif');
741 this.hidden = false;
743 if (!superficial) {
744 main.connect('POST', 'class=resource&field=visible', null, 'value=1&id='+this.id);
746 } else {
747 YAHOO.util.Dom.addClass(this.linkContainer, 'dimmed');
748 this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide.gif/i, 'show.gif');
749 this.hidden = true;
751 if (!superficial) {
752 main.connect('POST', 'class=resource&field=visible', null, 'value=0&id='+this.id);
758 resource_class.prototype.groupImages = ['/t/groupn.gif', '/t/groups.gif', '/t/groupv.gif'];
761 resource_class.prototype.toggle_groupmode = function() {
762 this.groupmode++;
763 if (this.groupmode > 2) {
764 this.groupmode = 0;
767 var newtitle = this.groupButton.getElementsByTagName('img')[0].title;
769 switch (this.groupmode) {
770 case 0:
771 newtitle = main.portal.strings['groupsnone']+' ('+main.portal.strings['clicktochange']+')';
772 break;
773 case 1:
774 newtitle = main.portal.strings['groupsseparate']+' ('+main.portal.strings['clicktochange']+')';
775 break;
776 case 2:
777 newtitle = main.portal.strings['groupsvisible']+' ('+main.portal.strings['clicktochange']+')';
778 break;
781 this.groupButton.getElementsByTagName('img')[0].title = newtitle;
783 this.groupButton.getElementsByTagName('img')[0].src = main.portal.strings['pixpath']+this.groupImages[this.groupmode];
784 main.connect('POST', 'class=resource&field=groupmode', null, 'value='+this.groupmode+'&id='+this.id);
788 resource_class.prototype.delete_button = function() {
789 if (this.debug) {
790 YAHOO.log("Deleting "+this.getEl().id+" from parent "+this.parentObj.getEl().id);
792 if (!confirm(main.getString('deletecheck', main.getString(this.is)+" "+this.id))) {
793 return false;
795 this.parentObj.remove_resource(this);
796 main.connect('DELETE', 'class=resource&id='+this.id);
800 resource_class.prototype.update_index = function(index) {
801 if (this.debug) {
802 YAHOO.log("Updating Index for resource "+this.getEl().id+" to "+index);
807 resource_class.prototype.startDrag = function(x, y) {
808 YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT;
810 //reinitialize dd element
811 this.getDragEl().innerHTML = '';
813 var targets = YAHOO.util.DDM.getRelated(this, true);
814 if (this.debug) {
815 YAHOO.log(this.id + " startDrag "+targets.length + " targets");
820 resource_class.prototype.clear_move_markers = function(target) {
821 if (target.is == 'section') {
822 resources = target.resources;
823 } else {
824 resources = target.parentObj.resources;
826 for (var i=0; i<resources.length; i++) {
827 YAHOO.util.Dom.setStyle(resources[i].getEl().id, 'border', 'none');
832 resource_class.prototype.onDragOver = function(e, ids) {
833 var target = YAHOO.util.DDM.getBestMatch(ids);
835 this.clear_move_markers(target);
837 if (target != this && (target.is == 'resource' || target.is == 'activity')) {
838 // Add a top border to show where the drop will place the resource.
839 YAHOO.util.Dom.setStyle(target.getEl().id, 'border-top', '1px solid #BBB');
840 } else if (target.is == 'section' && target.resources.length > 0) {
841 // We need to have a border at the bottom of the last activity in
842 // that section.
843 YAHOO.util.Dom.setStyle(target.resources[target.resources.length - 1].getEl().id,
844 'border-bottom', '1px solid #BBB');
849 resource_class.prototype.onDragOut = function(e, ids) {
850 var target = YAHOO.util.DDM.getBestMatch(ids);
851 if (target) {
852 this.clear_move_markers(target);
857 resource_class.prototype.onDragDrop = function(e, ids) {
858 var target = YAHOO.util.DDM.getBestMatch(ids);
859 if (!target) {
860 YAHOO.log('onDragDrop: Target is not valid!', 'error');
863 if (this.debug) {
864 YAHOO.log("Dropped on section id="+target.sectionId
865 +", el="+this.getEl().id
866 +", x="+YAHOO.util.Dom.getXY( this.getDragEl() ));
868 this.parentObj.remove_resource(this);
870 if (target.is == 'resource' || target.is == 'activity') {
871 target.parentObj.insert_resource(this, target);
872 } else if (target.is == 'section') {
873 target.insert_resource(this);
875 this.clear_move_markers(target);
876 return;
880 resource_class.prototype.endDrag = function() {
881 // Eliminates default action
884 section_class.prototype.swap_dates = function(el){
885 var i=0;
886 while(this.getEl().getElementsByTagName("div")[i]) {
887 if (this.getEl().getElementsByTagName("div")[i].className == "weekdates") {
888 var tempdate = this.getEl().getElementsByTagName("div")[i].innerHTML;
889 var permi = i;
891 i++;
894 var j=0;
895 while(el.getEl().getElementsByTagName("div")[j]) {
896 if (el.getEl().getElementsByTagName("div")[j].className == "weekdates") {
897 var permj = j;
899 j++;
902 if(tempdate) {
903 this.getEl().getElementsByTagName("div")[permi].innerHTML = el.getEl().getElementsByTagName("div")[permj].innerHTML;
904 el.getEl().getElementsByTagName("div")[permj].innerHTML = tempdate;