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.
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.
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) {
39 this.sectionId = null; // Section number. This is NOT the section id from
43 this.initTarget(id, group, config);
44 this.removeFromGroup('sections');
46 this.init(id, group, config);
50 this.isTimelineFormat = false;
51 if (YAHOO.util.Dom.hasClass(this.getEl().parentNode,'timeline') || YAHOO.util.Dom.hasClass(this.getEl().parentNode.parentNode,'timeline')) {
52 this.isTimelineFormat = true;
55 this.isWeekFormat = false;
56 if (YAHOO.util.Dom.hasClass(this.getEl().parentNode,'weeks') || YAHOO.util.Dom.hasClass(this.getEl().parentNode.parentNode,'weeks')) {
57 this.isWeekFormat = true;
64 this.numberDisplay = null; // Used to display the section number on the top left
65 // of the section. Not used in all course formats.
67 this.content_td = null;
69 this.highlighted = false;
70 this.showOnly = false;
71 this.resources_ul = null;
72 this.process_section();
74 this.viewButton = null;
75 this.highlightButton = null;
76 this.showOnlyButton = null;
83 YAHOO.log("init_section "+id+" draggable="+isDraggable);
85 if (YAHOO.util.Dom.hasClass(this.getEl(),'hidden')) {
86 this.toggle_hide(null,null,true);
91 section_class.prototype.init_buttons = function() {
92 var commandContainer = YAHOO.util.Dom.getElementsByClassName('right',null,this.getEl())[0];
94 //clear all but show only button
95 var commandContainerCount = commandContainer.childNodes.length;
97 for (var i=(commandContainerCount-1); i>0; i--) {
98 commandContainer.removeChild(commandContainer.childNodes[i])
101 if (main.getString('courseformat', this.sectionId) != "weeks" && this.sectionId > 0) {
102 var highlightbutton = main.mk_button('div', '/i/marker.gif', main.getString('marker', this.sectionId));
103 YAHOO.util.Event.addListener(highlightbutton, 'click', this.mk_marker, this, true);
104 commandContainer.appendChild(highlightbutton);
105 this.highlightButton = highlightbutton;
108 if (this.sectionId > 0 ) {
109 var viewbutton = main.mk_button('div', '/i/hide.gif', main.getString('hidesection', this.sectionId), [['title', main.portal.strings['hide'] ]]);
110 YAHOO.util.Event.addListener(viewbutton, 'click', this.toggle_hide, this,true);
111 commandContainer.appendChild(viewbutton);
112 this.viewButton = viewbutton;
117 section_class.prototype.add_handle = function() {
118 var handleRef = main.mk_button('a', '/i/move_2d.gif', main.getString('movesection', this.sectionId),
119 [['title', main.portal.strings['move'] ], ['style','cursor:move']]);
121 YAHOO.util.Dom.generateId(handleRef, 'sectionHandle');
123 this.handle = handleRef;
125 this.getEl().childNodes[0].appendChild(handleRef);
126 this.setHandleElId(this.handle.id);
130 section_class.prototype.process_section = function() {
131 this.content_td = this.getEl().childNodes[1];
133 if (YAHOO.util.Dom.hasClass(this.getEl(),'current')) {
134 this.highlighted = true;
138 // Create holder for display number for access later
140 this.numberDisplay = document.createElement('div');
141 this.numberDisplay.innerHTML = this.getEl().childNodes[0].innerHTML;
142 this.getEl().childNodes[0].innerHTML = '';
143 this.getEl().childNodes[0].appendChild(this.numberDisplay);
145 this.sectionId = this.id.replace(/section-/i, ''); // Okay, we will have to change this if we
146 // ever change the id attributes format
149 YAHOO.log("Creating section "+this.getEl().id+" in position "+this.sectionId);
152 // Find/edit resources
153 this.resources_ul = this.content_td.getElementsByTagName('ul')[0];
155 while (this.resources_ul && this.resources_ul.className != 'section img-text') {
156 this.resources_ul = this.content_td.getElementsByTagName('ul')[i];
160 if (!this.resources_ul) {
161 this.resources_ul = document.createElement('ul');
162 this.resources_ul.className='section';
163 this.content_td.insertBefore(this.resources_ul, this.content_td.lastChild);
165 var resource_count = this.resources_ul.getElementsByTagName('li').length;
167 for (var i=0;i<resource_count;i++) {
168 var resource = this.resources_ul.getElementsByTagName('li')[i];
169 this.resources[this.resources.length] = new resource_class(resource.id, 'resources', null, this);
171 this.summary = YAHOO.util.Dom.getElementsByClassName('summary', null, this.getEl())[0].firstChild.data || '';
175 section_class.prototype.startDrag = function(x, y) {
176 //operates in point mode
177 YAHOO.util.DDM.mode = YAHOO.util.DDM.POINT;
179 //remove from resources group temporarily
180 this.removeFromGroup('resources');
182 //reinitialize dd element
183 this.getDragEl().innerHTML = '';
185 var targets = YAHOO.util.DDM.getRelated(this, true);
188 YAHOO.log(this.id + " startDrag, "+targets.length + " targets");
193 section_class.prototype.onDragDrop = function(e, id) {
194 // get the drag and drop object that was targeted
195 var target = YAHOO.util.DDM.getDDById(id);
198 YAHOO.log("Section dropped on id="+id+" (I am "+this.getEl().id+") x="
199 +YAHOO.util.Dom.getXY(this.getDragEl()));
201 this.move_to_section(target);
203 //add back to resources group
204 this.addToGroup('resources');
208 section_class.prototype.endDrag = function() {
209 //nessicary to defeat default action
211 //add back to resources group
212 this.addToGroup('resources');
216 section_class.prototype.move_to_section = function(target) {
217 var tempTd = document.createElement('td');
218 var tempStore = null;
219 var sectionCount = main.sections.length;
222 //determine if original is above or below target and adjust loop
223 var oIndex = main.get_section_index(this);
224 var tIndex = main.get_section_index(target);
227 YAHOO.log("original is at: "+oIndex+" target is at:"+tIndex+" of "+(sectionCount-1));
229 if (oIndex < tIndex) {
230 var loopCondition = 'i<sectionCount';
233 var loopmodifier = 'i - 1';
234 var targetOffset = 0;
236 var loopCondition = 'i > 0';
237 var loopStart = sectionCount - 1;
239 var loopmodifier = 'i + 1';
240 var targetOffset = 1;
243 if (this.isTimelineFormat && oIndex < tIndex) {
244 var targetOffset = 1;
245 } else if (this.isTimelineFormat && oIndex > tIndex) {
246 var targetOffset = 0;
250 main.connect('POST','class=section&field=move',null,'id='+this.sectionId+'&value=' + (target.sectionId - targetOffset));
253 for (var i=loopStart; eval(loopCondition); eval(loopInc)) {
255 if ((main.sections[i] == this) && !found) {
256 //encounter with original node
258 YAHOO.log("Found Original "+main.sections[i].getEl().id);
260 if (main.sections[i] == this) {
263 } else if (main.sections[i] == target) {
264 //encounter with target node
266 YAHOO.log("Found target "+main.sections[i].getEl().id);
268 main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]);
269 main.sections[i].swap_dates(main.sections[eval(loopmodifier)]);
273 //encounter with nodes inbetween
274 main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]);
275 main.sections[i].swap_dates(main.sections[eval(loopmodifier)]);
281 section_class.prototype.swap_with_section = function(sectionIn) {
284 thisIndex = main.get_section_index(this);
285 targetIndex = main.get_section_index(sectionIn);
286 main.sections[targetIndex] = this;
287 main.sections[thisIndex] = sectionIn;
289 this.changeId(targetIndex);
290 sectionIn.changeId(thisIndex);
293 YAHOO.log("Swapping "+this.getEl().id+" with "+sectionIn.getEl().id);
295 // Swap the sections.
296 YAHOO.util.DDM.swapNode(this.getEl(), sectionIn.getEl());
298 // Sections contain forms to add new resources/activities. These forms
299 // have not been updated to reflect the new positions of the sections that
300 // we have swapped. Let's swap the two sections' forms around.
301 if (this.getEl().getElementsByTagName('form')[0].parentNode
302 && sectionIn.getEl().getElementsByTagName('form')[0].parentNode) {
304 YAHOO.util.DDM.swapNode(this.getEl().getElementsByTagName('form')[0].parentNode,
305 sectionIn.getEl().getElementsByTagName('form')[0].parentNode);
307 YAHOO.log("Swapping sections: form not present in one or both sections", "warn");
312 section_class.prototype.toggle_hide = function(e,target,superficial) {
313 var strhide = main.portal.strings['hide'];
314 var strshow = main.portal.strings['show'];
316 YAHOO.util.Dom.removeClass(this.getEl(), 'hidden');
317 this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show.gif/i, 'hide.gif');
318 this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strshow, strhide);
319 this.viewButton.childNodes[0].title = this.viewButton.childNodes[0].title.replace(strshow, strhide); //IE hack.
320 this.viewButton.title = this.viewButton.title.replace(strshow, strhide);
324 main.connect('POST', 'class=section&field=visible', null, 'value=1&id='+this.sectionId);
325 for (var x=0; x<this.resources.length; x++) {
326 this.resources[x].toggle_hide(null, null, true, this.resources[x].hiddenStored);
327 this.resources[x].hiddenStored = null;
332 YAHOO.util.Dom.addClass(this.getEl(), 'hidden');
333 this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide.gif/i, 'show.gif');
334 this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strhide, strshow);
335 this.viewButton.childNodes[0].title = this.viewButton.childNodes[0].title.replace(strhide, strshow); //IE hack.
336 this.viewButton.title = this.viewButton.title.replace(strhide, strshow);
340 main.connect('POST', 'class=section&field=visible', null, 'value=0&id='+this.sectionId);
341 for (var x=0; x<this.resources.length; x++) {
342 this.resources[x].hiddenStored = this.resources[x].hidden;
343 this.resources[x].toggle_hide(null, null, true, true);
350 section_class.prototype.toggle_highlight = function() {
351 if (this.highlighted) {
352 YAHOO.util.Dom.removeClass(this.getEl(), 'current');
353 this.highlighted = false;
355 YAHOO.util.Dom.addClass(this.getEl(), 'current');
356 this.highlighted = true;
361 section_class.prototype.mk_marker = function() {
362 if (main.marker != this) {
363 main.update_marker(this);
365 // If currently the marker
368 main.connect('POST', 'class=course&field=marker', null, 'value=0');
369 this.toggle_highlight();
374 section_class.prototype.changeId = function(newId) {
375 this.sectionId = newId;
376 this.numberDisplay.firstChild.data = newId;
378 //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))
380 if (main.marker == this) {
381 main.update_marker(this);
386 section_class.prototype.get_resource_index = function(el) {
387 for (var x=0; x<this.resources.length; x++) {
388 if (this.resources[x] == el) {
392 YAHOO.log("Could not find resource to remove "+el.getEl().id, "error");
397 section_class.prototype.remove_resource = function(el) {
399 var resourceEl = el.getEl();
400 var parentEl = resourceEl.parentNode;
405 var resourceCount = this.resources.length;
407 if (resourceCount == 1) {
408 if (this.resources[0] == el) {
409 this.resources = new Array();
413 for (var i=0; i<resourceCount; i++) {
415 this.resources[i - 1] = this.resources[i];
416 if (i == resourceCount - 1) {
417 this.resources = this.resources.slice(0, -1);
420 this.resources[i - 1].update_index(i - 1);
421 } else if (this.resources[i] == el) {
426 // Remove any extra text nodes to keep DOM clean.
427 var kids = parentEl.childNodes;
429 for (var i=0; i<kids.length; i++) {
430 if (kids[i].nodeType == 3) {
431 YAHOO.log('Removed extra text node.');
432 parentEl.removeChild(kids[i]);
435 parentEl.removeChild(resourceEl);
437 this.write_sequence_list();
442 section_class.prototype.insert_resource = function(el, targetel) {
443 var resourcecount = this.resources.length;
445 var tempStore = nextStore = null;
450 targetId = targetel.id;
453 YAHOO.log('id='+el.id+', beforeId='+targetId+', sectionId='+this.sectionId);
455 main.connect('POST', 'class=resource&field=move', null,
456 'id='+el.id+'&beforeId='+targetId+'§ionId='+this.sectionId);
458 //if inserting into a hidden resource hide
460 el.hiddenStored = el.hidden;
461 el.toggle_hide(null, null, true, true);
463 if (el.hiddenStored != null) {
464 el.toggle_hide(null, null, true, el.hiddenStored);
465 el.hiddenStored = null;
470 this.resources[this.resources.length] = el;
472 for (var i=0; i<resourcecount; i++) {
474 tempStore = this.resources[i];
475 this.resources[i] = nextStore;
476 nextStore = tempStore;
478 if (nextStore != null)
479 nextStore.update_index(i+1);
481 } else if (this.resources[i] == targetel) {
483 nextStore = this.resources[i];
484 this.resources[i] = el;
487 this.resources[i].update_index(i, this.ident);
488 nextStore.update_index(i + 1);
494 this.resources_ul.insertBefore(el.getEl(), targetel.getEl());
495 //this.resources_ul.insertBefore(document.createTextNode(' '), targetel.getEl());
497 this.resources_ul.appendChild(el.getEl());
498 //this.resources_ul.appendChild(document.createTextNode(' '));
504 section_class.prototype.write_sequence_list = function(toReturn) {
507 for (var i=0; i<this.resources.length; i++) {
508 listOutput += this.resources[i].id;
509 if (i != (this.resources.length-1)) {
522 * resource_class extends util.DDProxy
524 function resource_class(id,group,config,parentObj) {
525 this.init_resource(id,group,config,parentObj);
528 YAHOO.extend(resource_class, YAHOO.util.DDProxy);
531 resource_class.prototype.debug = false;
534 resource_class.prototype.init_resource = function(id, group, config, parentObj) {
536 YAHOO.log("Init resource, NO ID FOUND!", 'error');
542 this.SEPARATEGROUPS = 1;
543 this.VISIBLEGROUPS = 2;
545 this.is = 'resource';
546 this.init(id, group, config);
548 this.isTarget = true;
550 this.id = this.getEl().id.replace(/module-/i, '');
553 if (YAHOO.util.Dom.hasClass(this.getEl().getElementsByTagName('a')[0], 'dimmed') ||
554 YAHOO.util.Dom.hasClass(this.getEl().getElementsByTagName('span')[0], 'dimmed_text')) {
557 this.hiddenStored = null;
559 this.groupmode = null; // Can be null (i.e. does not apply), 0, 1 or 2.
561 // Check for label first
562 firstspan = this.getEl().getElementsByTagName('span')[0];
563 if (firstspan.className == 'label' || firstspan.className == 'dimmed_text') {
564 this.linkContainer = firstspan;
566 this.linkContainer = this.getEl().getElementsByTagName('a')[0];
569 this.commandContainer = null;
570 this.indentLeftButton = null;
571 this.indentRightButton = null;
572 this.viewButton = null;
573 this.groupButton = null;
577 this.parentObj = parentObj;
580 YAHOO.log("init_resource "+id+" parent = "+parentObj.getEl().id);
586 * The current strategy is to look at the DOM tree to get information on the
587 * resource and it's current mode. This is bad since we are dependant on
588 * the html that is output from serverside logic. Seemingly innocuous changes
589 * like changing the language string for the title of a button will break
590 * our JavaScript here. This is brittle.
592 * First, we clear the buttons container. Then:
593 * We need to add the new-style move handle.
594 * The old style move button (up/down) needs to be removed.
595 * Move left button (if any) needs an event handler.
596 * Move right button (if any) needs an event handler.
597 * Update button stays as it is. Add it back.
598 * Delete button needs an event handler.
599 * Visible button is a toggle. It needs an event handler too.
600 * Group mode button is a toggle. It needs an event handler too.
602 resource_class.prototype.init_buttons = function() {
604 var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands',
605 'span', this.getEl())[0];
607 if (commandContainer == null) {
608 YAHOO.log('Cannot find command container for '+this.getEl().id, 'error');
613 var strgroupsnone = main.portal.strings['groupsnone']+' ('+main.portal.strings['clicktochange']+')';
614 var strgroupsseparate = main.portal.strings['groupsseparate']+' ('+main.portal.strings['clicktochange']+')';
615 var strgroupsvisible = main.portal.strings['groupsvisible']+' ('+main.portal.strings['clicktochange']+')';
617 this.commandContainer = commandContainer;
618 var buttons = commandContainer.getElementsByTagName('a');
620 // Buttons that we might need to add back in.
621 var moveLeft = false;
622 var moveRight = false;
623 var updateButton = null;
626 var isrtl = (document.getElementsByTagName("html")[0].dir=="rtl");
628 for (var x=0; x<buttons.length; x++) {
629 if (buttons[x].className == 'editing_moveleft') {
631 } else if (buttons[x].className == 'editing_moveright') {
633 } else if (buttons[x].className == 'editing_update') {
634 updateButton = buttons[x].cloneNode(true);
635 } else if (buttons[x].className == 'editing_groupsnone') {
636 this.groupmode = this.NOGROUPS;
637 } else if (buttons[x].className == 'editing_groupsseparate') {
638 this.groupmode = this.SEPARATEGROUPS;
639 } else if (buttons[x].className == 'editing_groupsvisible') {
640 this.groupmode = this.VISIBLEGROUPS;
644 if (updateButton == null) {
645 // Update button must always be present.
646 YAHOO.log('Cannot find updateButton for '+this.getEl().id, 'error');
649 // Clear all the buttons.
650 commandContainer.innerHTML = '';
652 // Add move-handle for drag and drop.
653 var handleRef = main.mk_button('a', '/i/move_2d.gif', main.portal.strings['move'],
654 [['style', 'cursor:move']],
655 [['height', '11'], ['width', '11'], ['style', 'margin-right:3px; border:0;']]);
657 YAHOO.util.Dom.generateId(handleRef, 'sectionHandle');
658 this.handle = handleRef;
659 commandContainer.appendChild(handleRef);
660 this.setHandleElId(this.handle.id);
662 // Add indentation buttons if needed (move left, move right).
664 var button = main.mk_button('a', (isrtl?'/t/right.gif':'/t/left.gif'), main.portal.strings['moveleft'],
665 [['class', 'editing_moveleft']]);
666 YAHOO.util.Event.addListener(button, 'click', this.indent_left, this, true);
667 commandContainer.appendChild(button);
668 this.indentLeftButton = button;
672 var button = main.mk_button('a', (isrtl?'/t/left.gif':'/t/right.gif'), main.portal.strings['moveright'],
673 [['class', 'editing_moveright']]);
674 YAHOO.util.Event.addListener(button, 'click', this.indent_right, this, true);
675 commandContainer.appendChild(button);
676 this.indentRightButton = button;
679 // Add edit button back in.
680 commandContainer.appendChild(updateButton);
682 // Add the delete button.
683 var button = main.mk_button('a', '/t/delete.gif', main.portal.strings['delete']);
684 YAHOO.util.Event.addListener(button, 'click', this.delete_button, this, true);
685 commandContainer.appendChild(button);
687 // Add the hide or show button.
689 var button = main.mk_button('a', '/t/show.gif', main.portal.strings['show']);
691 var button = main.mk_button('a', '/t/hide.gif', main.portal.strings['hide']);
693 YAHOO.util.Event.addListener(button, 'click', this.toggle_hide, this, true);
694 commandContainer.appendChild(button);
695 this.viewButton = button;
697 // Add the groupmode button if needed.
698 if (this.groupmode != null) {
699 if (this.groupmode == this.NOGROUPS) {
700 var button = main.mk_button('a', '/t/groupn.gif', strgroupsnone);
701 } else if (this.groupmode == this.SEPARATEGROUPS) {
702 var button = main.mk_button('a', '/t/groups.gif', strgroupsseparate);
704 var button = main.mk_button('a', '/t/groupv.gif', strgroupsvisible);
706 YAHOO.util.Event.addListener(button, 'click', this.toggle_groupmode, this, true);
707 commandContainer.appendChild(button);
708 this.groupButton = button;
713 resource_class.prototype.indent_left = function() {
715 var spacer = YAHOO.util.Dom.getElementsByClassName('spacer',
716 'img', this.getEl())[0];
719 YAHOO.log('Could not indent left: spacer image does not exist', 'error');
723 if (spacer.width > 20) {
726 // Remove the spacer.
727 resource = this.getEl();
728 resource.removeChild(spacer);
730 // Remove the indent left button as well.
731 var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands',
732 'span', this.getEl())[0];
734 commandContainer.removeChild(this.indentLeftButton);
735 this.indentLeftButton = null;
737 main.connect('POST', 'class=resource&field=indentleft', null, 'id='+this.id);
742 resource_class.prototype.indent_right = function() {
745 var isrtl = (document.getElementsByTagName("html")[0].dir=="rtl");
747 var spacer = YAHOO.util.Dom.getElementsByClassName('spacer',
748 'img', this.getEl())[0];
750 var spacer = document.createElement('img');
752 spacer.setAttribute('src', main.portal.strings['pixpath']+'/spacer.gif');
753 spacer.className = 'spacer';
754 spacer.setAttribute('alt', '');
755 spacer.setAttribute('width', '20');
756 spacer.setAttribute('height', '12');
758 var resource = this.getEl();
759 resource.insertBefore(spacer, resource.childNodes[0]);
763 // Add a indent left button if none is present.
764 var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands',
765 'span', this.getEl())[0];
767 if (!this.indentLeftButton) {
768 var button = main.mk_button('a', (isrtl?'/t/right.gif':'/t/left.gif'), main.portal.strings['moveleft'],
769 [['class', 'editing_moveleft']]);
770 YAHOO.util.Event.addListener(button, 'click', this.indent_left, this, true);
771 commandContainer.insertBefore(button, this.indentRightButton);
772 this.indentLeftButton = button;
774 main.connect('POST', 'class=resource&field=indentright', null, 'id='+this.id);
779 resource_class.prototype.toggle_hide = function(target, e, superficial, force) {
780 var strhide = main.portal.strings['hide'];
781 var strshow = main.portal.strings['show'];
784 YAHOO.log("Resource "+this.getEl().id+" forced to "+force);
786 this.hidden = !force;
789 YAHOO.util.Dom.removeClass(this.linkContainer, 'dimmed');
791 if (YAHOO.util.Dom.hasClass(this.linkContainer, 'dimmed_text')) {
792 YAHOO.util.Dom.removeClass(this.linkContainer, 'dimmed_text');
793 YAHOO.util.Dom.addClass(this.linkContainer, 'label');
795 this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show.gif/i, 'hide.gif');
796 this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strshow, strhide);
797 this.viewButton.title = this.viewButton.title.replace(strshow, strhide);
801 main.connect('POST', 'class=resource&field=visible', null, 'value=1&id='+this.id);
804 YAHOO.util.Dom.addClass(this.linkContainer, 'dimmed');
806 if (YAHOO.util.Dom.hasClass(this.linkContainer, 'label')) {
807 YAHOO.util.Dom.addClass(this.linkContainer, 'dimmed_text');
808 YAHOO.util.Dom.removeClass(this.linkContainer, 'label');
810 this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide.gif/i, 'show.gif');
811 this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strhide, strshow);
812 this.viewButton.title = this.viewButton.title.replace(strhide, strshow);
816 main.connect('POST', 'class=resource&field=visible', null, 'value=0&id='+this.id);
822 resource_class.prototype.groupImages = ['/t/groupn.gif', '/t/groups.gif', '/t/groupv.gif'];
825 resource_class.prototype.toggle_groupmode = function() {
827 if (this.groupmode > 2) {
831 var newtitle = this.groupButton.title;
833 switch (this.groupmode) {
835 newtitle = main.portal.strings['groupsnone']+' ('+main.portal.strings['clicktochange']+')';
838 newtitle = main.portal.strings['groupsseparate']+' ('+main.portal.strings['clicktochange']+')';
841 newtitle = main.portal.strings['groupsvisible']+' ('+main.portal.strings['clicktochange']+')';
845 this.groupButton.getElementsByTagName('img')[0].alt = newtitle;
846 this.groupButton.title = newtitle;
848 this.groupButton.getElementsByTagName('img')[0].src = main.portal.strings['pixpath']+this.groupImages[this.groupmode];
849 main.connect('POST', 'class=resource&field=groupmode', null, 'value='+this.groupmode+'&id='+this.id);
853 resource_class.prototype.delete_button = function() {
855 YAHOO.log("Deleting "+this.getEl().id+" from parent "+this.parentObj.getEl().id);
857 if (!confirm(main.getString('deletecheck', main.getString(this.is)+" "+this.id))) {
860 this.parentObj.remove_resource(this);
861 main.connect('POST', 'class=resource&action=DELETE&id='+this.id);
865 resource_class.prototype.update_index = function(index) {
867 YAHOO.log("Updating Index for resource "+this.getEl().id+" to "+index);
872 resource_class.prototype.startDrag = function(x, y) {
873 YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT;
875 //reinitialize dd element
876 this.getDragEl().innerHTML = '';
878 var targets = YAHOO.util.DDM.getRelated(this, true);
880 YAHOO.log(this.id + " startDrag "+targets.length + " targets");
885 resource_class.prototype.clear_move_markers = function(target) {
886 if (target.is == 'section') {
887 resources = target.resources;
889 resources = target.parentObj.resources;
891 for (var i=0; i<resources.length; i++) {
892 if (resources[i].getEl() != null) {
893 YAHOO.util.Dom.setStyle(resources[i].getEl().id, 'border', 'none');
899 resource_class.prototype.onDragOver = function(e, ids) {
900 var target = YAHOO.util.DDM.getBestMatch(ids);
902 this.clear_move_markers(target);
904 if (target != this && (target.is == 'resource' || target.is == 'activity')) {
905 // Add a top border to show where the drop will place the resource.
906 YAHOO.util.Dom.setStyle(target.getEl().id, 'border-top', '1px solid #BBB');
907 } else if (target.is == 'section' && target.resources.length > 0) {
908 // We need to have a border at the bottom of the last activity in
910 if (target.resources[target.resources.length - 1].getEl() != null) {
911 YAHOO.util.Dom.setStyle(target.resources[target.resources.length - 1].getEl().id,
912 'border-bottom', '1px solid #BBB');
918 resource_class.prototype.onDragOut = function(e, ids) {
919 var target = YAHOO.util.DDM.getBestMatch(ids);
921 this.clear_move_markers(target);
926 resource_class.prototype.onDragDrop = function(e, ids) {
927 var target = YAHOO.util.DDM.getBestMatch(ids);
929 YAHOO.log('onDragDrop: Target is not valid!', 'error');
933 YAHOO.log("Dropped on section id="+target.sectionId
934 +", el="+this.getEl().id
935 +", x="+YAHOO.util.Dom.getXY( this.getDragEl() ));
937 this.parentObj.remove_resource(this);
939 if (target.is == 'resource' || target.is == 'activity') {
940 target.parentObj.insert_resource(this, target);
941 } else if (target.is == 'section') {
942 target.insert_resource(this);
944 this.clear_move_markers(target);
949 resource_class.prototype.endDrag = function() {
950 // Eliminates default action
953 section_class.prototype.swap_dates = function(el){
955 var divs = YAHOO.util.Selector.query('div .weekdates');
958 divs[div].innerHTML = main.sectiondates[i];