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.
20 function section_class(id, group, config, isDraggable) {
21 this.init_section(id, group, config, isDraggable);
24 YAHOO.extend(section_class, YAHOO.util.DDProxy);
27 section_class.prototype.debug = false;
30 section_class.prototype.init_section = function(id, group, config, isDraggable) {
37 this.sectionId = null; // Section number. This is NOT the section id from
41 this.initTarget(id, group, config);
42 this.removeFromGroup('sections');
44 this.init(id, group, config);
52 this.numberDisplay = null; // Used to display the section number on the top left
53 // of the section. Not used in all course formats.
55 this.content_div = null;
57 this.highlighted = false;
58 this.showOnly = false;
59 this.resources_ul = null;
60 this.process_section();
62 this.viewButton = null;
63 this.highlightButton = null;
64 this.showOnlyButton = null;
71 YAHOO.log("init_section "+id+" draggable="+isDraggable);
73 if (YAHOO.util.Dom.hasClass(this.getEl(),'hidden')) {
74 this.toggle_hide(null,null,true);
79 section_class.prototype.init_buttons = function() {
80 if (this.sectionId > main.portal.numsections) {
81 // no need to do anything in orphaned sections
85 var commandContainer = YAHOO.util.Dom.getElementsByClassName('right',null,this.getEl())[0];
87 //clear all but show only button
88 var commandContainerCount = commandContainer.childNodes.length;
90 for (var i=(commandContainerCount-1); i>0; i--) {
91 commandContainer.removeChild(commandContainer.childNodes[i])
94 if (main.getString('courseformat', this.sectionId) != "weeks" && this.sectionId > 0) {
95 var highlightbutton = main.mk_button('div', main.portal.icons['marker'], main.getString('marker', this.sectionId));
96 YAHOO.util.Event.addListener(highlightbutton, 'click', this.mk_marker, this, true);
97 commandContainer.appendChild(highlightbutton);
98 this.highlightButton = highlightbutton;
100 if (this.sectionId > 0) {
101 var viewbutton = main.mk_button('div', main.portal.icons['hide'], main.getString('hidesection', this.sectionId),
102 [['title', main.portal.strings['hide'] ]]);
103 YAHOO.util.Event.addListener(viewbutton, 'click', this.toggle_hide, this,true);
104 commandContainer.appendChild(viewbutton);
105 this.viewButton = viewbutton;
110 section_class.prototype.add_handle = function() {
111 var handleRef = main.mk_button('a', main.portal.icons['move_2d'], main.getString('movesection', this.sectionId),
112 [['title', main.portal.strings['move'] ], ['style','cursor:move']]);
114 YAHOO.util.Dom.generateId(handleRef, 'sectionHandle');
116 this.handle = handleRef;
118 this.getEl().childNodes[0].appendChild(handleRef);
119 this.setHandleElId(this.handle.id);
123 section_class.prototype.process_section = function() {
124 this.content_div = YAHOO.util.Dom.getElementsByClassName('content',null,this.getEl())[0];
126 if (YAHOO.util.Dom.hasClass(this.getEl(),'current')) {
127 this.highlighted = true;
131 // Create holder for display number for access later
133 this.numberDisplay = document.createElement('div');
134 this.numberDisplay.innerHTML = this.getEl().childNodes[0].innerHTML;
135 this.getEl().childNodes[0].innerHTML = '';
136 this.getEl().childNodes[0].appendChild(this.numberDisplay);
138 this.sectionId = this.id.replace(/section-/i, ''); // Okay, we will have to change this if we
139 // ever change the id attributes format
142 YAHOO.log("Creating section "+this.getEl().id+" in position "+this.sectionId);
145 // Find/edit resources
146 this.resources_ul = this.content_div.getElementsByTagName('ul')[0];
148 while (this.resources_ul && this.resources_ul.className != 'section img-text') {
150 this.resources_ul = this.content_div.getElementsByTagName('ul')[i]; i++;
152 if (!this.resources_ul) {
153 this.resources_ul = document.createElement('ul');
154 this.resources_ul.className='section';
155 this.content_div.insertBefore(this.resources_ul, this.content_div.lastChild);
157 var resource_count = this.resources_ul.getElementsByTagName('li').length;
159 for (var i=0;i<resource_count;i++) {
160 var resource = this.resources_ul.getElementsByTagName('li')[i];
161 this.resources[this.resources.length] = new resource_class(resource.id, 'resources', null, this);
164 var sum = YAHOO.util.Dom.getElementsByClassName('summary', null, this.getEl());
166 this.summary = sum[0].firstChild.data || '';
168 // orphaned activities
174 section_class.prototype.startDrag = function(x, y) {
175 //operates in point mode
176 YAHOO.util.DDM.mode = YAHOO.util.DDM.POINT;
178 //remove from resources group temporarily
179 this.removeFromGroup('resources');
181 //reinitialize dd element
182 this.getDragEl().innerHTML = '';
184 var targets = YAHOO.util.DDM.getRelated(this, true);
187 YAHOO.log(this.id + " startDrag, "+targets.length + " targets");
192 section_class.prototype.onDragDrop = function(e, id) {
193 // get the drag and drop object that was targeted
194 var target = YAHOO.util.DDM.getDDById(id);
197 YAHOO.log("Section dropped on id="+id+" (I am "+this.getEl().id+") x="
198 +YAHOO.util.Dom.getXY(this.getDragEl()));
200 this.move_to_section(target);
202 //add back to resources group
203 this.addToGroup('resources');
207 section_class.prototype.endDrag = function() {
208 //nessicary to defeat default action
210 //add back to resources group
211 this.addToGroup('resources');
215 section_class.prototype.move_to_section = function(target) {
216 var tempDiv = document.createElement('div');
217 var tempStore = null;
218 var sectionCount = main.sections.length;
221 //determine if original is above or below target and adjust loop
222 var oIndex = main.get_section_index(this);
223 var tIndex = main.get_section_index(target);
234 YAHOO.log("original is at: "+oIndex+" target is at:"+tIndex+" of "+(sectionCount-1));
236 if (oIndex < tIndex) {
237 var loopCondition = 'i<sectionCount';
240 var loopmodifier = 'i - 1';
241 var targetOffset = 0;
243 var loopCondition = 'i > 0';
244 var loopStart = sectionCount - 1;
246 var loopmodifier = 'i + 1';
247 var targetOffset = 1;
251 main.connect('POST','class=section&field=move',null,'id='+this.sectionId+'&value=' + (target.sectionId - targetOffset));
254 for (var i=loopStart; eval(loopCondition); eval(loopInc)) {
256 if ((main.sections[i] == this) && !found) {
257 //encounter with original node
259 YAHOO.log("Found Original "+main.sections[i].getEl().id);
261 if (main.sections[i] == this) {
264 } else if (main.sections[i] == target) {
265 //encounter with target node
267 YAHOO.log("Found target "+main.sections[i].getEl().id);
269 main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]);
270 main.sections[i].swap_dates(main.sections[eval(loopmodifier)]);
274 //encounter with nodes inbetween
275 main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]);
276 main.sections[i].swap_dates(main.sections[eval(loopmodifier)]);
282 section_class.prototype.swap_with_section = function(sectionIn) {
285 var thisIndex = main.get_section_index(this);
286 var targetIndex = main.get_section_index(sectionIn);
287 if (thisIndex == -1) {
291 if (targetIndex == -1) {
296 main.sections[targetIndex] = this;
297 main.sections[thisIndex] = sectionIn;
299 this.changeId(targetIndex);
300 sectionIn.changeId(thisIndex);
303 YAHOO.log("Swapping "+this.getEl().id+" with "+sectionIn.getEl().id);
305 // Swap the sections.
306 YAHOO.util.DDM.swapNode(this.getEl(), sectionIn.getEl());
308 // Sections contain forms to add new resources/activities. These forms
309 // have not been updated to reflect the new positions of the sections that
310 // we have swapped. Let's swap the two sections' forms around.
311 if (this.getEl().getElementsByTagName('form')[0].parentNode
312 && sectionIn.getEl().getElementsByTagName('form')[0].parentNode) {
314 YAHOO.util.DDM.swapNode(this.getEl().getElementsByTagName('form')[0].parentNode,
315 sectionIn.getEl().getElementsByTagName('form')[0].parentNode);
317 YAHOO.log("Swapping sections: form not present in one or both sections", "warn");
322 section_class.prototype.toggle_hide = function(e,target,superficial) {
323 if (this.sectionId > main.portal.numsections) {
324 // no need to do anything in orphaned sections
328 var strhide = main.portal.strings['hide'];
329 var strshow = main.portal.strings['show'];
331 YAHOO.util.Dom.removeClass(this.getEl(), 'hidden');
332 this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show/i, 'hide');
333 this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strshow, strhide);
334 this.viewButton.childNodes[0].title = this.viewButton.childNodes[0].title.replace(strshow, strhide); //IE hack.
335 this.viewButton.title = this.viewButton.title.replace(strshow, strhide);
339 main.connect('POST', 'class=section&field=visible', null, 'value=1&id='+this.sectionId);
340 for (var x=0; x<this.resources.length; x++) {
341 this.resources[x].toggle_hide(null, null, true, this.resources[x].hiddenStored);
342 this.resources[x].hiddenStored = null;
347 YAHOO.util.Dom.addClass(this.getEl(), 'hidden');
348 this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide/i, 'show');
349 this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strhide, strshow);
350 this.viewButton.childNodes[0].title = this.viewButton.childNodes[0].title.replace(strhide, strshow); //IE hack.
351 this.viewButton.title = this.viewButton.title.replace(strhide, strshow);
355 main.connect('POST', 'class=section&field=visible', null, 'value=0&id='+this.sectionId);
356 for (var x=0; x<this.resources.length; x++) {
357 this.resources[x].hiddenStored = this.resources[x].hidden;
358 this.resources[x].toggle_hide(null, null, true, true);
365 section_class.prototype.toggle_highlight = function() {
366 if (this.highlighted) {
367 YAHOO.util.Dom.removeClass(this.getEl(), 'current');
368 this.highlighted = false;
370 YAHOO.util.Dom.addClass(this.getEl(), 'current');
371 this.highlighted = true;
376 section_class.prototype.mk_marker = function() {
377 if (main.marker != this) {
378 main.update_marker(this);
380 // If currently the marker
383 main.connect('POST', 'class=course&field=marker', null, 'value=0');
384 this.toggle_highlight();
389 section_class.prototype.changeId = function(newId) {
390 this.sectionId = newId;
391 this.numberDisplay.firstChild.data = newId;
393 //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))
395 if (main.marker == this) {
396 main.update_marker(this);
401 section_class.prototype.get_resource_index = function(el) {
402 for (var x=0; x<this.resources.length; x++) {
403 if (this.resources[x] == el) {
407 YAHOO.log("Could not find resource to remove "+el.getEl().id, "error");
412 section_class.prototype.remove_resource = function(el) {
414 var resourceEl = el.getEl();
415 var parentEl = resourceEl.parentNode;
420 var resourceCount = this.resources.length;
422 if (resourceCount == 1) {
423 if (this.resources[0] == el) {
424 this.resources = new Array();
428 for (var i=0; i<resourceCount; i++) {
430 this.resources[i - 1] = this.resources[i];
431 if (i == resourceCount - 1) {
432 this.resources = this.resources.slice(0, -1);
435 this.resources[i - 1].update_index(i - 1);
436 } else if (this.resources[i] == el) {
441 // Remove any extra text nodes to keep DOM clean.
442 var kids = parentEl.childNodes;
444 for (var i=0; i<kids.length; i++) {
445 if (kids[i].nodeType == 3) {
446 YAHOO.log('Removed extra text node.');
447 parentEl.removeChild(kids[i]);
450 parentEl.removeChild(resourceEl);
452 this.write_sequence_list();
457 section_class.prototype.insert_resource = function(el, targetel) {
458 var resourcecount = this.resources.length;
460 var tempStore = nextStore = null;
465 targetId = targetel.id;
468 YAHOO.log('id='+el.id+', beforeId='+targetId+', sectionId='+this.sectionId);
470 main.connect('POST', 'class=resource&field=move', null,
471 'id='+el.id+'&beforeId='+targetId+'§ionId='+this.sectionId);
473 //if inserting into a hidden resource hide
475 el.hiddenStored = el.hidden;
476 el.toggle_hide(null, null, true, true);
478 if (el.hiddenStored != null) {
479 el.toggle_hide(null, null, true, el.hiddenStored);
480 el.hiddenStored = null;
485 this.resources[this.resources.length] = el;
487 for (var i=0; i<resourcecount; i++) {
489 tempStore = this.resources[i];
490 this.resources[i] = nextStore;
491 nextStore = tempStore;
493 if (nextStore != null)
494 nextStore.update_index(i+1);
496 } else if (this.resources[i] == targetel) {
498 nextStore = this.resources[i];
499 this.resources[i] = el;
502 this.resources[i].update_index(i, this.ident);
503 nextStore.update_index(i + 1);
509 this.resources_ul.insertBefore(el.getEl(), targetel.getEl());
510 //this.resources_ul.insertBefore(document.createTextNode(' '), targetel.getEl());
512 this.resources_ul.appendChild(el.getEl());
513 //this.resources_ul.appendChild(document.createTextNode(' '));
519 section_class.prototype.write_sequence_list = function(toReturn) {
522 for (var i=0; i<this.resources.length; i++) {
523 listOutput += this.resources[i].id;
524 if (i != (this.resources.length-1)) {
537 * resource_class extends util.DDProxy
539 function resource_class(id,group,config,parentObj) {
540 this.init_resource(id,group,config,parentObj);
543 YAHOO.extend(resource_class, YAHOO.util.DDProxy);
546 resource_class.prototype.debug = false;
549 resource_class.prototype.init_resource = function(id, group, config, parentObj) {
551 YAHOO.log("Init resource, NO ID FOUND!", 'error');
557 this.SEPARATEGROUPS = 1;
558 this.VISIBLEGROUPS = 2;
560 this.is = 'resource';
561 this.init(id, group, config);
563 this.isTarget = true;
565 this.id = this.getEl().id.replace(/module-/i, '');
568 if (YAHOO.util.Dom.hasClass(this.getEl().getElementsByTagName('a')[0], 'dimmed') ||
569 YAHOO.util.Dom.hasClass(this.getEl().getElementsByTagName('div')[0], 'dimmed_text')) {
572 this.hiddenStored = null;
574 this.groupmode = null; // Can be null (i.e. does not apply), 0, 1 or 2.
576 this.linkContainer = this.getEl().getElementsByTagName('a')[0];
577 this.divContainer = this.getEl().getElementsByTagName('div')[0];
579 this.commandContainer = null;
580 this.indentLeftButton = null;
581 this.indentRightButton = null;
582 this.viewButton = null;
583 this.groupButton = null;
587 this.parentObj = parentObj;
590 YAHOO.log("init_resource "+id+" parent = "+parentObj.getEl().id);
596 * The current strategy is to look at the DOM tree to get information on the
597 * resource and it's current mode. This is bad since we are dependant on
598 * the html that is output from serverside logic. Seemingly innocuous changes
599 * like changing the language string for the title of a button will break
600 * our JavaScript here. This is brittle.
602 * First, we clear the buttons container. Then:
603 * We need to add the new-style move handle.
604 * The old style move button (up/down) needs to be removed.
605 * Move left button (if any) needs an event handler.
606 * Move right button (if any) needs an event handler.
607 * Update button stays as it is. Add it back.
608 * Delete button needs an event handler.
609 * Visible button is a toggle. It needs an event handler too.
610 * Group mode button is a toggle. It needs an event handler too.
612 resource_class.prototype.init_buttons = function() {
614 var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands',
615 'span', this.getEl())[0];
617 if (commandContainer == null) {
618 YAHOO.log('Cannot find command container for '+this.getEl().id, 'error');
623 var strgroupsnone = main.portal.strings['groupsnone']+' ('+main.portal.strings['clicktochange']+')';
624 var strgroupsseparate = main.portal.strings['groupsseparate']+' ('+main.portal.strings['clicktochange']+')';
625 var strgroupsvisible = main.portal.strings['groupsvisible']+' ('+main.portal.strings['clicktochange']+')';
627 this.commandContainer = commandContainer;
628 var buttons = commandContainer.getElementsByTagName('a');
630 // Buttons that we might need to add back in.
631 var moveLeft = false;
632 var moveRight = false;
633 var updateButton = null;
634 var assignButton = null;
637 var isrtl = (document.getElementsByTagName("html")[0].dir=="rtl");
639 for (var x=0; x<buttons.length; x++) {
640 if (buttons[x].className == 'editing_moveleft') {
642 } else if (buttons[x].className == 'editing_moveright') {
644 } else if (buttons[x].className == 'editing_update') {
645 updateButton = buttons[x].cloneNode(true);
646 } else if (buttons[x].className == 'editing_assign') {
647 assignButton = buttons[x].cloneNode(true);
648 } else if (buttons[x].className == 'editing_groupsnone') {
649 this.groupmode = this.NOGROUPS;
650 } else if (buttons[x].className == 'editing_groupsseparate') {
651 this.groupmode = this.SEPARATEGROUPS;
652 } else if (buttons[x].className == 'editing_groupsvisible') {
653 this.groupmode = this.VISIBLEGROUPS;
657 if (updateButton == null) {
658 // Update button must always be present.
659 YAHOO.log('Cannot find updateButton for '+this.getEl().id, 'error');
662 // Clear all the buttons.
663 commandContainer.innerHTML = '';
665 // Add move-handle for drag and drop.
666 var handleRef = main.mk_button('a', main.portal.icons['move_2d'], main.portal.strings['move'],
667 [['style', 'cursor:move']], [['class', 'iconsmall']]);
669 YAHOO.util.Dom.generateId(handleRef, 'sectionHandle');
670 this.handle = handleRef;
671 commandContainer.appendChild(handleRef);
672 this.setHandleElId(this.handle.id);
674 // Add indentation buttons if needed (move left, move right).
676 var button = main.mk_button('a', main.portal.icons['backwards'], main.portal.strings['moveleft'],
677 [['class', 'editing_moveleft']], [['class', 'iconsmall']]);
678 YAHOO.util.Event.addListener(button, 'click', this.indent_left, this, true);
679 commandContainer.appendChild(button);
680 this.indentLeftButton = button;
684 var button = main.mk_button('a', main.portal.icons['forwards'], main.portal.strings['moveright'],
685 [['class', 'editing_moveright']], [['class', 'iconsmall']]);
686 YAHOO.util.Event.addListener(button, 'click', this.indent_right, this, true);
687 commandContainer.appendChild(button);
688 this.indentRightButton = button;
691 // Add edit button back in.
692 commandContainer.appendChild(updateButton);
694 // Add the delete button.
695 var button = main.mk_button('a', main.portal.icons['delete'], main.portal.strings['delete'], null, [['class', 'iconsmall']]);
696 YAHOO.util.Event.addListener(button, 'click', this.delete_button, this, true);
697 commandContainer.appendChild(button);
699 // Add the hide or show button.
701 var button = main.mk_button('a', main.portal.icons['show'], main.portal.strings['show'], null, [['class', 'iconsmall']]);
703 var button = main.mk_button('a', main.portal.icons['hide'], main.portal.strings['hide'], null, [['class', 'iconsmall']]);
705 YAHOO.util.Event.addListener(button, 'click', this.toggle_hide, this, true);
706 commandContainer.appendChild(button);
707 this.viewButton = button;
709 // Add the groupmode button if needed.
710 if (this.groupmode != null) {
711 if (this.groupmode == this.NOGROUPS) {
712 var button = main.mk_button('a', main.portal.icons['groupn'], strgroupsnone, null, [['class', 'iconsmall']]);
713 } else if (this.groupmode == this.SEPARATEGROUPS) {
714 var button = main.mk_button('a', main.portal.icons['groups'], strgroupsseparate, null, [['class', 'iconsmall']]);
716 var button = main.mk_button('a', main.portal.icons['groupv'], strgroupsvisible, null, [['class', 'iconsmall']]);
718 YAHOO.util.Event.addListener(button, 'click', this.toggle_groupmode, this, true);
719 commandContainer.appendChild(button);
720 this.groupButton = button;
723 // Add the assign roles button back in
724 if (assignButton != null) {
725 commandContainer.appendChild(assignButton);
730 resource_class.prototype.indent_left = function() {
732 var indentdiv = YAHOO.util.Dom.getElementsByClassName('mod-indent', 'div', this.getEl())[0];
735 YAHOO.log('Could not indent left: intending div does not exist', 'error');
739 var oldindent = indentdiv.classList.toString().match(/mod-indent-(\d{1,})/);
740 if (oldindent && oldindent[1] > 0) {
741 oldindent = oldindent[1];
745 var newindent = parseFloat(oldindent) - 1;
746 YAHOO.util.Dom.replaceClass(indentdiv, 'mod-indent-'+oldindent, 'mod-indent-'+newindent);
747 main.connect('POST', 'class=resource&field=indentleft', null, 'id='+this.id);
749 if (newindent == 0) {
750 // Remove the indent left button as well.
751 var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands',
752 'span', this.getEl())[0];
753 commandContainer.removeChild(this.indentLeftButton);
754 this.indentLeftButton = null;
761 resource_class.prototype.indent_right = function() {
763 var indentdiv = YAHOO.util.Dom.getElementsByClassName('mod-indent', 'div', this.getEl())[0];
766 YAHOO.log('Could not indent left: intending div does not exist', 'error');
770 var oldindent = indentdiv.classList.toString().match(/mod-indent-(\d{1,})/);
771 if (oldindent && oldindent[1] >= 0) {
772 oldindent = oldindent[1];
773 var newindent = parseFloat(oldindent) + 1;
774 YAHOO.util.Dom.replaceClass(indentdiv, 'mod-indent-'+oldindent, 'mod-indent-'+newindent);
776 YAHOO.util.Dom.addClass(indentdiv, 'mod-indent-1');
778 main.connect('POST', 'class=resource&field=indentright', null, 'id='+this.id);
780 if (!this.indentLeftButton) {
781 // Add a indent left button if none is present.
782 var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands', 'span', this.getEl())[0];
783 var button = main.mk_button('a', main.portal.icons['backwards'], main.portal.strings['moveleft'],
784 [['class', 'editing_moveleft']], [['class', 'iconsmall']]);
785 YAHOO.util.Event.addListener(button, 'click', this.indent_left, this, true);
786 commandContainer.insertBefore(button, this.indentRightButton);
787 this.indentLeftButton = button;
794 resource_class.prototype.toggle_hide = function(target, e, superficial, force) {
795 var strhide = main.portal.strings['hide'];
796 var strshow = main.portal.strings['show'];
799 YAHOO.log("Resource "+this.getEl().id+" forced to "+force);
801 this.hidden = !force;
804 YAHOO.util.Dom.removeClass(this.linkContainer, 'dimmed');
805 YAHOO.util.Dom.removeClass(this.divContainer, 'dimmed_text');
806 this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show/i, 'hide');
807 this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strshow, strhide);
808 this.viewButton.title = this.viewButton.title.replace(strshow, strhide);
812 main.connect('POST', 'class=resource&field=visible', null, 'value=1&id='+this.id);
815 YAHOO.util.Dom.addClass(this.linkContainer, 'dimmed');
816 YAHOO.util.Dom.addClass(this.divContainer, 'dimmed_text');
817 this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide/i, 'show');
818 this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strhide, strshow);
819 this.viewButton.title = this.viewButton.title.replace(strhide, strshow);
823 main.connect('POST', 'class=resource&field=visible', null, 'value=0&id='+this.id);
829 resource_class.prototype.groupImages = ['groupn', 'groups', 'groupv'];
832 resource_class.prototype.toggle_groupmode = function() {
834 if (this.groupmode > 2) {
838 var newtitle = this.groupButton.title;
840 switch (this.groupmode) {
842 newtitle = main.portal.strings['groupsnone']+' ('+main.portal.strings['clicktochange']+')';
845 newtitle = main.portal.strings['groupsseparate']+' ('+main.portal.strings['clicktochange']+')';
848 newtitle = main.portal.strings['groupsvisible']+' ('+main.portal.strings['clicktochange']+')';
852 this.groupButton.getElementsByTagName('img')[0].alt = newtitle;
853 this.groupButton.title = newtitle;
855 this.groupButton.getElementsByTagName('img')[0].src = main.portal.icons[this.groupImages[this.groupmode]];
856 main.connect('POST', 'class=resource&field=groupmode', null, 'value='+this.groupmode+'&id='+this.id);
860 resource_class.prototype.delete_button = function() {
862 YAHOO.log("Deleting "+this.getEl().id+" from parent "+this.parentObj.getEl().id);
865 // default fallback to something like 'Resource 42'
866 var modtype = main.getString(this.is);
867 var modname = this.id;
869 // try to get less cryptic instance name from DOM
870 if (YAHOO.util.Dom.hasClass(this.getEl(), 'activity')) {
871 if (YAHOO.util.Dom.hasClass(this.getEl(), 'label')) {
872 // mod_label instance
873 modtype = main.getString('modtype_label');
876 // other mod instance, get the type first
877 matches = new RegExp(/modtype_(\w+)/).exec(this.getEl().className);
878 if (matches[1] && main.hasString('modtype_' + matches[1])) {
879 modtype = main.getString('modtype_' + matches[1]);
881 // look for span.instancename content to get the module instance name from it
882 instancename = YAHOO.util.Selector.query('.instancename', this.getEl(), true);
884 // remove the span.accesshide
885 accesshides = YAHOO.util.Selector.query('.accesshide', instancename);
886 for (x in accesshides) {
887 instancename.removeChild(accesshides[x]);
890 instancenametext = instancename.innerHTML.replace(/<[^>]+>/g, '');
891 // and if anything survived, consider it the instance name
892 if (instancenametext) {
893 modname = instancenametext;
895 // put span.accesshides back
896 for (x in accesshides) {
897 instancename.appendChild(accesshides[x]);
904 modname = "'" + modname + "'";
906 if (!confirm(main.getString('deletecheck', modtype + ' ' + modname))) {
909 this.parentObj.remove_resource(this);
910 main.connect('POST', 'class=resource&action=DELETE&id='+this.id);
914 resource_class.prototype.update_index = function(index) {
916 YAHOO.log("Updating Index for resource "+this.getEl().id+" to "+index);
921 resource_class.prototype.startDrag = function(x, y) {
922 YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT;
924 //reinitialize dd element
925 this.getDragEl().innerHTML = '';
927 var targets = YAHOO.util.DDM.getRelated(this, true);
929 YAHOO.log(this.id + " startDrag "+targets.length + " targets");
934 resource_class.prototype.clear_move_markers = function(target) {
935 if (target.is == 'section') {
936 resources = target.resources;
938 resources = target.parentObj.resources;
940 for (var i=0; i<resources.length; i++) {
941 if (resources[i].getEl() != null) {
942 YAHOO.util.Dom.setStyle(resources[i].getEl().id, 'border', 'none');
948 resource_class.prototype.onDragOver = function(e, ids) {
949 var target = YAHOO.util.DDM.getBestMatch(ids);
951 this.clear_move_markers(target);
953 if (target != this && (target.is == 'resource' || target.is == 'activity')) {
954 // Add a top border to show where the drop will place the resource.
955 YAHOO.util.Dom.setStyle(target.getEl().id, 'border-top', '1px solid #BBB');
956 } else if (target.is == 'section' && target.resources.length > 0) {
957 // We need to have a border at the bottom of the last activity in
959 if (target.resources[target.resources.length - 1].getEl() != null) {
960 YAHOO.util.Dom.setStyle(target.resources[target.resources.length - 1].getEl().id,
961 'border-bottom', '1px solid #BBB');
967 resource_class.prototype.onDragOut = function(e, ids) {
968 var target = YAHOO.util.DDM.getBestMatch(ids);
970 this.clear_move_markers(target);
975 resource_class.prototype.onDragDrop = function(e, ids) {
976 var target = YAHOO.util.DDM.getBestMatch(ids);
978 YAHOO.log('onDragDrop: Target is not valid!', 'error');
982 YAHOO.log("Dropped on section id="+target.sectionId
983 +", el="+this.getEl().id
984 +", x="+YAHOO.util.Dom.getXY( this.getDragEl() ));
986 this.parentObj.remove_resource(this);
988 if (target.is == 'resource' || target.is == 'activity') {
989 target.parentObj.insert_resource(this, target);
990 } else if (target.is == 'section') {
991 target.insert_resource(this);
993 this.clear_move_markers(target);
998 resource_class.prototype.endDrag = function() {
999 // Eliminates default action
1002 section_class.prototype.swap_dates = function(el){
1004 var divs = YAHOO.util.Selector.query('div .weekdates');
1007 divs[div].innerHTML = main.sectiondates[i];