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');
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;
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
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);
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
);
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
;
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
);
208 YAHOO
.log("original is at: "+oIndex
+" target is at:"+tIndex
+" of "+(sectionCount
-1));
210 if (oIndex
< tIndex
) {
211 var loopCondition
= 'i<sectionCount';
214 var loopmodifier
= 'i - 1';
216 var loopCondition
= 'i > 0';
217 var loopStart
= sectionCount
- 1;
219 var loopmodifier
= 'i + 1';
223 main
.connect('POST','class=section&field=move',null,'id='+this.sectionId
+'&value='
224 +(target
.sectionId
- this.sectionId
));
227 for (var i
=loopStart
; eval(loopCondition
); eval(loopInc
)) {
229 if ((main
.sections
[i
] == this) && !found
) {
230 //enounter with original node
232 YAHOO
.log("Found Original "+main
.sections
[i
].getEl().id
);
234 if (main
.sections
[i
] == this) {
237 } else if (main
.sections
[i
] == target
) {
238 //encounter with target node
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
)]);
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
) {
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
);
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
);
281 YAHOO
.log("Swapping sections: form not present in one or both sections", "warn");
286 section_class
.prototype.toggle_hide = function(e
,target
,superficial
) {
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');
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;
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');
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;
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);
331 // If currently the marker
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
) {
358 YAHOO
.log("Could not find resource to remove "+el
.getEl().id
, "error");
363 section_class
.prototype.remove_resource = function(el
) {
365 var resourceEl
= el
.getEl();
366 var parentEl
= resourceEl
.parentNode
;
371 var resourceCount
= this.resources
.length
;
373 if (resourceCount
== 1) {
374 if (this.resources
[0] == el
) {
375 this.resources
= new Array();
379 for (var i
=0; i
<resourceCount
; i
++) {
381 this.resources
[i
- 1] = this.resources
[i
];
382 if (i
== resourceCount
- 1) {
383 this.resources
= this.resources
.slice(0, -1);
386 this.resources
[i
- 1].update_index(i
- 1);
387 } else if (this.resources
[i
] == el
) {
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();
408 section_class
.prototype.insert_resource = function(el
, targetel
) {
409 var resourcecount
= this.resources
.length
;
411 var tempStore
= nextStore
= null;
416 targetId
= targetel
.id
;
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
+'§ionId='+this.sectionId
);
424 //if inserting into a hidden resource hide
426 el
.hiddenStored
= el
.hidden
;
427 el
.toggle_hide(null, null, true, true);
429 if (el
.hiddenStored
!= null) {
430 el
.toggle_hide(null, null, true, el
.hiddenStored
);
431 el
.hiddenStored
= null;
436 this.resources
[this.resources
.length
] = el
;
438 for (var i
=0; i
<resourcecount
; i
++) {
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
) {
449 nextStore
= this.resources
[i
];
450 this.resources
[i
] = el
;
453 this.resources
[i
].update_index(i
, this.ident
);
454 nextStore
.update_index(i
+ 1);
460 this.resources_ul
.insertBefore(el
.getEl(), targetel
.getEl());
461 //this.resources_ul.insertBefore(document.createTextNode(' '), targetel.getEl());
463 this.resources_ul
.appendChild(el
.getEl());
464 //this.resources_ul.appendChild(document.createTextNode(' '));
470 section_class
.prototype.write_sequence_list = function(toReturn
) {
473 for (var i
=0; i
<this.resources
.length
; i
++) {
474 listOutput
+= this.resources
[i
].id
;
475 if (i
!= (this.resources
.length
-1)) {
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
) {
502 YAHOO
.log("Init resource, NO ID FOUND!", 'error');
508 this.SEPARATEGROUPS
= 1;
509 this.VISIBLEGROUPS
= 2;
511 this.is
= 'resource';
512 this.init(id
, group
, config
);
514 this.isTarget
= true;
516 this.id
= this.getEl().id
.replace(/module-/i, '');
519 if (YAHOO
.util
.Dom
.hasClass(this.getEl().getElementsByTagName('a')[0], 'dimmed')) {
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;
536 this.parentObj
= parentObj
;
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');
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') {
587 } else if (buttons
[x
].className
== 'editing_moveright') {
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).
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
;
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.
645 var button
= main
.mk_button('a', '/t/show.gif');
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
]]);
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];
675 YAHOO
.log('Could not indent left: spacer image does not exist', 'error');
679 if (spacer
.width
> 20) {
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
);
698 resource_class
.prototype.indent_right = function() {
700 var spacer
= YAHOO
.util
.Dom
.getElementsByClassName('spacer',
701 'img', this.getEl())[0];
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]);
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
);
731 resource_class
.prototype.toggle_hide = function(target
, e
, superficial
, force
) {
734 YAHOO
.log("Resource "+this.getEl().id
+" forced to "+force
);
736 this.hidden
= !force
;
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');
744 main
.connect('POST', 'class=resource&field=visible', null, 'value=1&id='+this.id
);
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');
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() {
763 if (this.groupmode
> 2) {
767 var newtitle
= this.groupButton
.getElementsByTagName('img')[0].title
;
769 switch (this.groupmode
) {
771 newtitle
= main
.portal
.strings
['groupsnone']+' ('+main
.portal
.strings
['clicktochange']+')';
774 newtitle
= main
.portal
.strings
['groupsseparate']+' ('+main
.portal
.strings
['clicktochange']+')';
777 newtitle
= main
.portal
.strings
['groupsvisible']+' ('+main
.portal
.strings
['clicktochange']+')';
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() {
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
))) {
795 this.parentObj
.remove_resource(this);
796 main
.connect('DELETE', 'class=resource&id='+this.id
);
800 resource_class
.prototype.update_index = function(index
) {
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);
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
;
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
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
);
852 this.clear_move_markers(target
);
857 resource_class
.prototype.onDragDrop = function(e
, ids
) {
858 var target
= YAHOO
.util
.DDM
.getBestMatch(ids
);
860 YAHOO
.log('onDragDrop: Target is not valid!', 'error');
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
);
880 resource_class
.prototype.endDrag = function() {
881 // Eliminates default action
884 section_class
.prototype.swap_dates = function(el
){
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
;
895 while(el
.getEl().getElementsByTagName("div")[j
]) {
896 if (el
.getEl().getElementsByTagName("div")[j
].className
== "weekdates") {
903 this.getEl().getElementsByTagName("div")[permi
].innerHTML
= el
.getEl().getElementsByTagName("div")[permj
].innerHTML
;
904 el
.getEl().getElementsByTagName("div")[permj
].innerHTML
= tempdate
;