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);
54 this.numberDisplay = null; // Used to display the section number on the top left
55 // of the section. Not used in all course formats.
57 this.content_td = null;
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;
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', main.getString('marker', this.sectionId));
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', main.getString('hidesection', this.sectionId),
98 [['title', main.portal.strings['hide'] ]]);
99 YAHOO.util.Event.addListener(viewbutton, 'click', this.toggle_hide, this,true);
100 commandContainer.appendChild(viewbutton);
101 this.viewButton = viewbutton;
105 section_class.prototype.add_handle = function() {
106 var handleRef = main.mk_button('a', '/i/move_2d.gif', main.getString('movesection', this.sectionId),
107 [['title', main.portal.strings['move'] ], ['style','cursor:move']]);
109 YAHOO.util.Dom.generateId(handleRef, 'sectionHandle');
111 this.handle = handleRef;
113 this.getEl().childNodes[0].appendChild(handleRef);
114 this.setHandleElId(this.handle.id);
118 section_class.prototype.process_section = function() {
119 this.content_td = this.getEl().childNodes[1];
121 if (YAHOO.util.Dom.hasClass(this.getEl(),'current')) {
122 this.highlighted = true;
126 // Create holder for display number for access later
128 this.numberDisplay = document.createElement('div');
129 this.numberDisplay.innerHTML = this.getEl().childNodes[0].innerHTML;
130 this.getEl().childNodes[0].innerHTML = '';
131 this.getEl().childNodes[0].appendChild(this.numberDisplay);
133 this.sectionId = this.id.replace(/section-/i, ''); // Okay, we will have to change this if we
134 // ever change the id attributes format
137 YAHOO.log("Creating section "+this.getEl().id+" in position "+this.sectionId);
140 // Find/edit resources
141 this.resources_ul = this.content_td.getElementsByTagName('ul')[0];
142 if (!this.resources_ul) {
143 this.resources_ul = document.createElement('ul');
144 this.resources_ul.className='section';
145 this.content_td.insertBefore(this.resources_ul, this.content_td.lastChild);
147 var resource_count = this.resources_ul.getElementsByTagName('li').length;
149 for (var i=0;i<resource_count;i++) {
150 var resource = this.resources_ul.getElementsByTagName('li')[i];
151 this.resources[this.resources.length] = new resource_class(resource.id, 'resources', null, this);
153 this.summary = YAHOO.util.Dom.getElementsByClassName('summary', null, this.getEl())[0].firstChild.data || '';
157 section_class.prototype.startDrag = function(x, y) {
158 //operates in point mode
159 YAHOO.util.DDM.mode = YAHOO.util.DDM.POINT;
161 //remove from resources group temporarily
162 this.removeFromGroup('resources');
164 //reinitialize dd element
165 this.getDragEl().innerHTML = '';
167 var targets = YAHOO.util.DDM.getRelated(this, true);
170 YAHOO.log(this.id + " startDrag, "+targets.length + " targets");
175 section_class.prototype.onDragDrop = function(e, id) {
176 // get the drag and drop object that was targeted
177 var target = YAHOO.util.DDM.getDDById(id);
180 YAHOO.log("Section dropped on id="+id+" (I am "+this.getEl().id+") x="
181 +YAHOO.util.Dom.getXY(this.getDragEl()));
183 this.move_to_section(target);
185 //add back to resources group
186 this.addToGroup('resources');
190 section_class.prototype.endDrag = function() {
191 //nessicary to defeat default action
193 //add back to resources group
194 this.addToGroup('resources');
198 section_class.prototype.move_to_section = function(target) {
199 var tempTd = document.createElement('td');
200 var tempStore = null;
201 var sectionCount = main.sections.length;
204 //determine if original is above or below target and adjust loop
205 var oIndex = main.get_section_index(this);
206 var tIndex = main.get_section_index(target);
209 YAHOO.log("original is at: "+oIndex+" target is at:"+tIndex+" of "+(sectionCount-1));
211 if (oIndex < tIndex) {
212 var loopCondition = 'i<sectionCount';
215 var loopmodifier = 'i - 1';
216 var targetOffset = 0;
218 var loopCondition = 'i > 0';
219 var loopStart = sectionCount - 1;
221 var loopmodifier = 'i + 1';
222 var targetOffset = 1;
226 main.connect('POST','class=section&field=move',null,'id='+this.sectionId+'&value=' + (target.sectionId - targetOffset));
229 for (var i=loopStart; eval(loopCondition); eval(loopInc)) {
231 if ((main.sections[i] == this) && !found) {
232 //enounter with original node
234 YAHOO.log("Found Original "+main.sections[i].getEl().id);
236 if (main.sections[i] == this) {
239 } else if (main.sections[i] == target) {
240 //encounter with target node
242 YAHOO.log("Found target "+main.sections[i].getEl().id);
244 main.sections[i].swap_dates(main.sections[eval(loopmodifier)]);
245 main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]);
249 //encounter with nodes inbetween
250 main.sections[i].swap_dates(main.sections[eval(loopmodifier)]);
251 main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]);
257 section_class.prototype.swap_with_section = function(sectionIn) {
260 thisIndex = main.get_section_index(this);
261 targetIndex = main.get_section_index(sectionIn);
262 main.sections[targetIndex] = this;
263 main.sections[thisIndex] = sectionIn;
265 this.changeId(targetIndex);
266 sectionIn.changeId(thisIndex);
269 YAHOO.log("Swapping "+this.getEl().id+" with "+sectionIn.getEl().id);
271 // Swap the sections.
272 YAHOO.util.DDM.swapNode(this.getEl(), sectionIn.getEl());
274 // Sections contain forms to add new resources/activities. These forms
275 // have not been updated to reflect the new positions of the sections that
276 // we have swapped. Let's swap the two sections' forms around.
277 if (this.getEl().getElementsByTagName('form')[0].parentNode
278 && sectionIn.getEl().getElementsByTagName('form')[0].parentNode) {
280 YAHOO.util.DDM.swapNode(this.getEl().getElementsByTagName('form')[0].parentNode,
281 sectionIn.getEl().getElementsByTagName('form')[0].parentNode);
283 YAHOO.log("Swapping sections: form not present in one or both sections", "warn");
288 section_class.prototype.toggle_hide = function(e,target,superficial) {
289 var strhide = main.portal.strings['hide'];
290 var strshow = main.portal.strings['show'];
292 YAHOO.util.Dom.removeClass(this.getEl(), 'hidden');
293 this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show.gif/i, 'hide.gif');
294 this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strshow, strhide);
295 this.viewButton.childNodes[0].title = this.viewButton.childNodes[0].title.replace(strshow, strhide); //IE hack.
296 this.viewButton.title = this.viewButton.title.replace(strshow, strhide);
300 main.connect('POST', 'class=section&field=visible', null, 'value=1&id='+this.sectionId);
301 for (var x=0; x<this.resources.length; x++) {
302 this.resources[x].toggle_hide(null, null, true, this.resources[x].hiddenStored);
303 this.resources[x].hiddenStored = null;
308 YAHOO.util.Dom.addClass(this.getEl(), 'hidden');
309 this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide.gif/i, 'show.gif');
310 this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strhide, strshow);
311 this.viewButton.childNodes[0].title = this.viewButton.childNodes[0].title.replace(strhide, strshow); //IE hack.
312 this.viewButton.title = this.viewButton.title.replace(strhide, strshow);
316 main.connect('POST', 'class=section&field=visible', null, 'value=0&id='+this.sectionId);
317 for (var x=0; x<this.resources.length; x++) {
318 this.resources[x].hiddenStored = this.resources[x].hidden;
319 this.resources[x].toggle_hide(null, null, true, true);
326 section_class.prototype.toggle_highlight = function() {
327 if (this.highlighted) {
328 YAHOO.util.Dom.removeClass(this.getEl(), 'current');
329 this.highlighted = false;
331 YAHOO.util.Dom.addClass(this.getEl(), 'current');
332 this.highlighted = true;
337 section_class.prototype.mk_marker = function() {
338 if (main.marker != this) {
339 main.update_marker(this);
341 // If currently the marker
344 main.connect('POST', 'class=course&field=marker', null, 'value=0');
345 this.toggle_highlight();
350 section_class.prototype.changeId = function(newId) {
351 this.sectionId = newId;
352 this.numberDisplay.firstChild.data = newId;
354 //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))
356 if (main.marker == this) {
357 main.update_marker(this);
362 section_class.prototype.get_resource_index = function(el) {
363 for (var x=0; x<this.resources.length; x++) {
364 if (this.resources[x] == el) {
368 YAHOO.log("Could not find resource to remove "+el.getEl().id, "error");
373 section_class.prototype.remove_resource = function(el) {
375 var resourceEl = el.getEl();
376 var parentEl = resourceEl.parentNode;
381 var resourceCount = this.resources.length;
383 if (resourceCount == 1) {
384 if (this.resources[0] == el) {
385 this.resources = new Array();
389 for (var i=0; i<resourceCount; i++) {
391 this.resources[i - 1] = this.resources[i];
392 if (i == resourceCount - 1) {
393 this.resources = this.resources.slice(0, -1);
396 this.resources[i - 1].update_index(i - 1);
397 } else if (this.resources[i] == el) {
402 // Remove any extra text nodes to keep DOM clean.
403 var kids = parentEl.childNodes;
405 for (var i=0; i<kids.length; i++) {
406 if (kids[i].nodeType == 3) {
407 YAHOO.log('Removed extra text node.');
408 parentEl.removeChild(kids[i]);
411 parentEl.removeChild(resourceEl);
413 this.write_sequence_list();
418 section_class.prototype.insert_resource = function(el, targetel) {
419 var resourcecount = this.resources.length;
421 var tempStore = nextStore = null;
426 targetId = targetel.id;
429 YAHOO.log('id='+el.id+', beforeId='+targetId+', sectionId='+this.sectionId);
431 main.connect('POST', 'class=resource&field=move', null,
432 'id='+el.id+'&beforeId='+targetId+'§ionId='+this.sectionId);
434 //if inserting into a hidden resource hide
436 el.hiddenStored = el.hidden;
437 el.toggle_hide(null, null, true, true);
439 if (el.hiddenStored != null) {
440 el.toggle_hide(null, null, true, el.hiddenStored);
441 el.hiddenStored = null;
446 this.resources[this.resources.length] = el;
448 for (var i=0; i<resourcecount; i++) {
450 tempStore = this.resources[i];
451 this.resources[i] = nextStore;
452 nextStore = tempStore;
454 if (nextStore != null)
455 nextStore.update_index(i+1);
457 } else if (this.resources[i] == targetel) {
459 nextStore = this.resources[i];
460 this.resources[i] = el;
463 this.resources[i].update_index(i, this.ident);
464 nextStore.update_index(i + 1);
470 this.resources_ul.insertBefore(el.getEl(), targetel.getEl());
471 //this.resources_ul.insertBefore(document.createTextNode(' '), targetel.getEl());
473 this.resources_ul.appendChild(el.getEl());
474 //this.resources_ul.appendChild(document.createTextNode(' '));
480 section_class.prototype.write_sequence_list = function(toReturn) {
483 for (var i=0; i<this.resources.length; i++) {
484 listOutput += this.resources[i].id;
485 if (i != (this.resources.length-1)) {
498 * resource_class extends util.DDProxy
500 function resource_class(id,group,config,parentObj) {
501 this.init_resource(id,group,config,parentObj);
504 YAHOO.extend(resource_class, YAHOO.util.DDProxy);
507 resource_class.prototype.debug = false;
510 resource_class.prototype.init_resource = function(id, group, config, parentObj) {
512 YAHOO.log("Init resource, NO ID FOUND!", 'error');
518 this.SEPARATEGROUPS = 1;
519 this.VISIBLEGROUPS = 2;
521 this.is = 'resource';
522 this.init(id, group, config);
524 this.isTarget = true;
526 this.id = this.getEl().id.replace(/module-/i, '');
529 if (YAHOO.util.Dom.hasClass(this.getEl().getElementsByTagName('a')[0], 'dimmed')) {
532 this.hiddenStored = null;
534 this.groupmode = null; // Can be null (i.e. does not apply), 0, 1 or 2.
536 this.linkContainer = this.getEl().getElementsByTagName('a')[0];
538 this.commandContainer = null;
539 this.indentLeftButton = null;
540 this.indentRightButton = null;
541 this.viewButton = null;
542 this.groupButton = null;
546 this.parentObj = parentObj;
549 YAHOO.log("init_resource "+id+" parent = "+parentObj.getEl().id);
555 * The current strategy is to look at the DOM tree to get information on the
556 * resource and it's current mode. This is bad since we are dependant on
557 * the html that is output from serverside logic. Seemingly innocuous changes
558 * like changing the language string for the title of a button will break
559 * our JavaScript here. This is brittle.
561 * First, we clear the buttons container. Then:
562 * We need to add the new-style move handle.
563 * The old style move button (up/down) needs to be removed.
564 * Move left button (if any) needs an event handler.
565 * Move right button (if any) needs an event handler.
566 * Update button stays as it is. Add it back.
567 * Delete button needs an event handler.
568 * Visible button is a toggle. It needs an event handler too.
569 * Group mode button is a toggle. It needs an event handler too.
571 resource_class.prototype.init_buttons = function() {
573 var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands',
574 'span', this.getEl())[0];
576 if (commandContainer == null) {
577 YAHOO.log('Cannot find command container for '+this.getEl().id, 'error');
582 var strgroupsnone = main.portal.strings['groupsnone']+' ('+main.portal.strings['clicktochange']+')';
583 var strgroupsseparate = main.portal.strings['groupsseparate']+' ('+main.portal.strings['clicktochange']+')';
584 var strgroupsvisible = main.portal.strings['groupsvisible']+' ('+main.portal.strings['clicktochange']+')';
586 this.commandContainer = commandContainer;
587 var buttons = commandContainer.getElementsByTagName('a');
589 // Buttons that we might need to add back in.
590 var moveLeft = false;
591 var moveRight = false;
592 var updateButton = null;
595 var isrtl = (document.getElementsByTagName("html")[0].dir=="rtl");
597 for (var x=0; x<buttons.length; x++) {
598 if (buttons[x].className == 'editing_moveleft') {
600 } else if (buttons[x].className == 'editing_moveright') {
602 } else if (buttons[x].className == 'editing_update') {
603 updateButton = buttons[x].cloneNode(true);
604 } else if (buttons[x].className == 'editing_groupsnone') {
605 this.groupmode = this.NOGROUPS;
606 } else if (buttons[x].className == 'editing_groupsseparate') {
607 this.groupmode = this.SEPARATEGROUPS;
608 } else if (buttons[x].className == 'editing_groupsvisible') {
609 this.groupmode = this.VISIBLEGROUPS;
613 if (updateButton == null) {
614 // Update button must always be present.
615 YAHOO.log('Cannot find updateButton for '+this.getEl().id, 'error');
618 // Clear all the buttons.
619 commandContainer.innerHTML = '';
621 // Add move-handle for drag and drop.
622 var handleRef = main.mk_button('a', '/i/move_2d.gif', main.portal.strings['move'],
623 [['style', 'cursor:move']],
624 [['height', '11'], ['width', '11'], ['style', 'margin-right:3px; border:0;']]);
626 YAHOO.util.Dom.generateId(handleRef, 'sectionHandle');
627 this.handle = handleRef;
628 commandContainer.appendChild(handleRef);
629 this.setHandleElId(this.handle.id);
631 // Add indentation buttons if needed (move left, move right).
633 var button = main.mk_button('a', (isrtl?'/t/right.gif':'/t/left.gif'), main.portal.strings['moveleft'],
634 [['class', 'editing_moveleft']]);
635 YAHOO.util.Event.addListener(button, 'click', this.indent_left, this, true);
636 commandContainer.appendChild(button);
637 this.indentLeftButton = button;
641 var button = main.mk_button('a', (isrtl?'/t/left.gif':'/t/right.gif'), main.portal.strings['moveright'],
642 [['class', 'editing_moveright']]);
643 YAHOO.util.Event.addListener(button, 'click', this.indent_right, this, true);
644 commandContainer.appendChild(button);
645 this.indentRightButton = button;
648 // Add edit button back in.
649 commandContainer.appendChild(updateButton);
651 // Add the delete button.
652 var button = main.mk_button('a', '/t/delete.gif', main.portal.strings['delete']);
653 YAHOO.util.Event.addListener(button, 'click', this.delete_button, this, true);
654 commandContainer.appendChild(button);
656 // Add the hide or show button.
658 var button = main.mk_button('a', '/t/show.gif', main.portal.strings['show']);
660 var button = main.mk_button('a', '/t/hide.gif', main.portal.strings['hide']);
662 YAHOO.util.Event.addListener(button, 'click', this.toggle_hide, this, true);
663 commandContainer.appendChild(button);
664 this.viewButton = button;
666 // Add the groupmode button if needed.
667 if (this.groupmode != null) {
668 if (this.groupmode == this.NOGROUPS) {
669 var button = main.mk_button('a', '/t/groupn.gif', strgroupsnone);
670 } else if (this.groupmode == this.SEPARATEGROUPS) {
671 var button = main.mk_button('a', '/t/groups.gif', strgroupsseparate);
673 var button = main.mk_button('a', '/t/groupv.gif', strgroupsvisible);
675 YAHOO.util.Event.addListener(button, 'click', this.toggle_groupmode, this, true);
676 commandContainer.appendChild(button);
677 this.groupButton = button;
682 resource_class.prototype.indent_left = function() {
684 var spacer = YAHOO.util.Dom.getElementsByClassName('spacer',
685 'img', this.getEl())[0];
688 YAHOO.log('Could not indent left: spacer image does not exist', 'error');
692 if (spacer.width > 20) {
695 // Remove the spacer.
696 resource = this.getEl();
697 resource.removeChild(spacer);
699 // Remove the indent left button as well.
700 var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands',
701 'span', this.getEl())[0];
703 commandContainer.removeChild(this.indentLeftButton);
704 this.indentLeftButton = null;
706 main.connect('POST', 'class=resource&field=indentleft', null, 'id='+this.id);
711 resource_class.prototype.indent_right = function() {
714 var isrtl = (document.getElementsByTagName("html")[0].dir=="rtl");
716 var spacer = YAHOO.util.Dom.getElementsByClassName('spacer',
717 'img', this.getEl())[0];
719 var spacer = document.createElement('img');
721 spacer.setAttribute('src', main.portal.strings['pixpath']+'/spacer.gif');
722 spacer.className = 'spacer';
723 spacer.setAttribute('alt', '');
724 spacer.setAttribute('width', '20');
725 spacer.setAttribute('height', '12');
727 var resource = this.getEl();
728 resource.insertBefore(spacer, resource.childNodes[0]);
732 // Add a indent left button if none is present.
733 var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands',
734 'span', this.getEl())[0];
736 if (!this.indentLeftButton) {
737 var button = main.mk_button('a', (isrtl?'/t/right.gif':'/t/left.gif'), main.portal.strings['moveleft'],
738 [['class', 'editing_moveleft']]);
739 YAHOO.util.Event.addListener(button, 'click', this.indent_left, this, true);
740 commandContainer.insertBefore(button, this.indentRightButton);
741 this.indentLeftButton = button;
743 main.connect('POST', 'class=resource&field=indentright', null, 'id='+this.id);
748 resource_class.prototype.toggle_hide = function(target, e, superficial, force) {
749 var strhide = main.portal.strings['hide'];
750 var strshow = main.portal.strings['show'];
753 YAHOO.log("Resource "+this.getEl().id+" forced to "+force);
755 this.hidden = !force;
758 YAHOO.util.Dom.removeClass(this.linkContainer, 'dimmed');
759 this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show.gif/i, 'hide.gif');
760 this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strshow, strhide);
761 this.viewButton.title = this.viewButton.title.replace(strshow, strhide);
765 main.connect('POST', 'class=resource&field=visible', null, 'value=1&id='+this.id);
768 YAHOO.util.Dom.addClass(this.linkContainer, 'dimmed');
769 this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide.gif/i, 'show.gif');
770 this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strhide, strshow);
771 this.viewButton.title = this.viewButton.title.replace(strhide, strshow);
775 main.connect('POST', 'class=resource&field=visible', null, 'value=0&id='+this.id);
781 resource_class.prototype.groupImages = ['/t/groupn.gif', '/t/groups.gif', '/t/groupv.gif'];
784 resource_class.prototype.toggle_groupmode = function() {
786 if (this.groupmode > 2) {
790 var newtitle = this.groupButton.title;
792 switch (this.groupmode) {
794 newtitle = main.portal.strings['groupsnone']+' ('+main.portal.strings['clicktochange']+')';
797 newtitle = main.portal.strings['groupsseparate']+' ('+main.portal.strings['clicktochange']+')';
800 newtitle = main.portal.strings['groupsvisible']+' ('+main.portal.strings['clicktochange']+')';
804 this.groupButton.getElementsByTagName('img')[0].alt = newtitle;
805 this.groupButton.title = newtitle;
807 this.groupButton.getElementsByTagName('img')[0].src = main.portal.strings['pixpath']+this.groupImages[this.groupmode];
808 main.connect('POST', 'class=resource&field=groupmode', null, 'value='+this.groupmode+'&id='+this.id);
812 resource_class.prototype.delete_button = function() {
814 YAHOO.log("Deleting "+this.getEl().id+" from parent "+this.parentObj.getEl().id);
816 if (!confirm(main.getString('deletecheck', main.getString(this.is)+" "+this.id))) {
819 this.parentObj.remove_resource(this);
820 main.connect('DELETE', 'class=resource&id='+this.id);
824 resource_class.prototype.update_index = function(index) {
826 YAHOO.log("Updating Index for resource "+this.getEl().id+" to "+index);
831 resource_class.prototype.startDrag = function(x, y) {
832 YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT;
834 //reinitialize dd element
835 this.getDragEl().innerHTML = '';
837 var targets = YAHOO.util.DDM.getRelated(this, true);
839 YAHOO.log(this.id + " startDrag "+targets.length + " targets");
844 resource_class.prototype.clear_move_markers = function(target) {
845 if (target.is == 'section') {
846 resources = target.resources;
848 resources = target.parentObj.resources;
850 for (var i=0; i<resources.length; i++) {
851 if (resources[i].getEl() != null) {
852 YAHOO.util.Dom.setStyle(resources[i].getEl().id, 'border', 'none');
858 resource_class.prototype.onDragOver = function(e, ids) {
859 var target = YAHOO.util.DDM.getBestMatch(ids);
861 this.clear_move_markers(target);
863 if (target != this && (target.is == 'resource' || target.is == 'activity')) {
864 // Add a top border to show where the drop will place the resource.
865 YAHOO.util.Dom.setStyle(target.getEl().id, 'border-top', '1px solid #BBB');
866 } else if (target.is == 'section' && target.resources.length > 0) {
867 // We need to have a border at the bottom of the last activity in
869 if (target.resources[target.resources.length - 1].getEl() != null) {
870 YAHOO.util.Dom.setStyle(target.resources[target.resources.length - 1].getEl().id,
871 'border-bottom', '1px solid #BBB');
877 resource_class.prototype.onDragOut = function(e, ids) {
878 var target = YAHOO.util.DDM.getBestMatch(ids);
880 this.clear_move_markers(target);
885 resource_class.prototype.onDragDrop = function(e, ids) {
886 var target = YAHOO.util.DDM.getBestMatch(ids);
888 YAHOO.log('onDragDrop: Target is not valid!', 'error');
892 YAHOO.log("Dropped on section id="+target.sectionId
893 +", el="+this.getEl().id
894 +", x="+YAHOO.util.Dom.getXY( this.getDragEl() ));
896 this.parentObj.remove_resource(this);
898 if (target.is == 'resource' || target.is == 'activity') {
899 target.parentObj.insert_resource(this, target);
900 } else if (target.is == 'section') {
901 target.insert_resource(this);
903 this.clear_move_markers(target);
908 resource_class.prototype.endDrag = function() {
909 // Eliminates default action
912 section_class.prototype.swap_dates = function(el){
914 while(this.getEl().getElementsByTagName("div")[i]) {
915 if (this.getEl().getElementsByTagName("div")[i].className == "weekdates") {
916 var tempdate = this.getEl().getElementsByTagName("div")[i].innerHTML;
923 while(el.getEl().getElementsByTagName("div")[j]) {
924 if (el.getEl().getElementsByTagName("div")[j].className == "weekdates") {
931 this.getEl().getElementsByTagName("div")[permi].innerHTML = el.getEl().getElementsByTagName("div")[permj].innerHTML;
932 el.getEl().getElementsByTagName("div")[permj].innerHTML = tempdate;