/** * library for ajaxcourse formats, the classes and related functions for * sections and resources. * * This library requires a 'main' object created in calling document. * * Drag and drop notes: * * Dropping an activity or resource on a section will always add the activity * or resource at the end of that section. * * Dropping an activity or resource on another activity or resource will * always move the former just above the latter. * * $Id$ */ /** * section_class */ function section_class(id, group, config, isDraggable) { this.init_section(id, group, config, isDraggable); } YAHOO.extend(section_class, YAHOO.util.DDProxy); section_class.prototype.debug = false; section_class.prototype.init_section = function(id, group, config, isDraggable) { if (!id) { return; } this.is = 'section'; this.sectionId = null; // Section number. This is NOT the section id from // the database. if (!isDraggable) { this.initTarget(id, group, config); this.removeFromGroup('sections'); } else { this.init(id, group, config); this.handle = null; } this.createFrame(); this.isTarget = true; this.resources = []; this.numberDisplay = null; // Used to display the section number on the top left // of the section. Not used in all course formats. this.summary = null; this.content_div = null; this.hidden = false; this.highlighted = false; this.showOnly = false; this.resources_ul = null; this.process_section(); this.viewButton = null; this.highlightButton = null; this.showOnlyButton = null; this.init_buttons(); if (isDraggable) { this.add_handle(); } if (this.debug) { YAHOO.log("init_section "+id+" draggable="+isDraggable); } if (YAHOO.util.Dom.hasClass(this.getEl(),'hidden')) { this.toggle_hide(null,null,true); } } section_class.prototype.init_buttons = function() { var commandContainer = YAHOO.util.Dom.getElementsByClassName('right',null,this.getEl())[0]; //clear all but show only button var commandContainerCount = commandContainer.childNodes.length; for (var i=(commandContainerCount-1); i>0; i--) { commandContainer.removeChild(commandContainer.childNodes[i]) } if (!this.isWeekFormat) { var highlightbutton = main.mk_button('div', '/i/marker.gif', main.getString('marker', this.sectionId)); YAHOO.util.Event.addListener(highlightbutton, 'click', this.mk_marker, this, true); commandContainer.appendChild(highlightbutton); this.highlightButton = highlightbutton; } var viewbutton = main.mk_button('div', '/i/hide.gif', main.getString('hidesection', this.sectionId), [['title', main.portal.strings['hide'] ]]); YAHOO.util.Event.addListener(viewbutton, 'click', this.toggle_hide, this,true); commandContainer.appendChild(viewbutton); this.viewButton = viewbutton; } section_class.prototype.add_handle = function() { var handleRef = main.mk_button('a', '/i/move_2d.gif', main.getString('movesection', this.sectionId), [['title', main.portal.strings['move'] ], ['style','cursor:move']]); YAHOO.util.Dom.generateId(handleRef, 'sectionHandle'); this.handle = handleRef; this.getEl().childNodes[0].appendChild(handleRef); this.setHandleElId(this.handle.id); } section_class.prototype.process_section = function() { this.content_div = YAHOO.util.Dom.getElementsByClassName('content',null,this.getEl())[0]; if (YAHOO.util.Dom.hasClass(this.getEl(),'current')) { this.highlighted = true; main.marker = this; } // Create holder for display number for access later this.numberDisplay = document.createElement('div'); this.numberDisplay.innerHTML = this.getEl().childNodes[0].innerHTML; this.getEl().childNodes[0].innerHTML = ''; this.getEl().childNodes[0].appendChild(this.numberDisplay); this.sectionId = this.id.replace(/section-/i, ''); // Okay, we will have to change this if we // ever change the id attributes format // for the sections. if (this.debug) { YAHOO.log("Creating section "+this.getEl().id+" in position "+this.sectionId); } // Find/edit resources this.resources_ul = this.content_div.getElementsByTagName('ul')[0]; if (!this.resources_ul) { this.resources_ul = document.createElement('ul'); this.resources_ul.className='section'; this.content_div.insertBefore(this.resources_ul, this.content_div.lastChild); } var resource_count = this.resources_ul.getElementsByTagName('li').length; for (var i=0;i 2) { this.groupmode = 0; } var newtitle = this.groupButton.title; switch (this.groupmode) { case 0: newtitle = main.portal.strings['groupsnone']+' ('+main.portal.strings['clicktochange']+')'; break; case 1: newtitle = main.portal.strings['groupsseparate']+' ('+main.portal.strings['clicktochange']+')'; break; case 2: newtitle = main.portal.strings['groupsvisible']+' ('+main.portal.strings['clicktochange']+')'; break; } this.groupButton.getElementsByTagName('img')[0].alt = newtitle; this.groupButton.title = newtitle; this.groupButton.getElementsByTagName('img')[0].src = main.portal.strings['pixpath']+this.groupImages[this.groupmode]; main.connect('POST', 'class=resource&field=groupmode', null, 'value='+this.groupmode+'&id='+this.id); } resource_class.prototype.delete_button = function() { if (this.debug) { YAHOO.log("Deleting "+this.getEl().id+" from parent "+this.parentObj.getEl().id); } if (!confirm(main.getString('deletecheck', main.getString(this.is)+" "+this.id))) { return false; } this.parentObj.remove_resource(this); main.connect('DELETE', 'class=resource&id='+this.id); } resource_class.prototype.update_index = function(index) { if (this.debug) { YAHOO.log("Updating Index for resource "+this.getEl().id+" to "+index); } } resource_class.prototype.startDrag = function(x, y) { YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT; //reinitialize dd element this.getDragEl().innerHTML = ''; var targets = YAHOO.util.DDM.getRelated(this, true); if (this.debug) { YAHOO.log(this.id + " startDrag "+targets.length + " targets"); } } resource_class.prototype.clear_move_markers = function(target) { if (target.is == 'section') { resources = target.resources; } else { resources = target.parentObj.resources; } for (var i=0; i 0) { // We need to have a border at the bottom of the last activity in // that section. YAHOO.util.Dom.setStyle(target.resources[target.resources.length - 1].getEl().id, 'border-bottom', '1px solid #BBB'); } } resource_class.prototype.onDragOut = function(e, ids) { var target = YAHOO.util.DDM.getBestMatch(ids); if (target) { this.clear_move_markers(target); } } resource_class.prototype.onDragDrop = function(e, ids) { var target = YAHOO.util.DDM.getBestMatch(ids); if (!target) { YAHOO.log('onDragDrop: Target is not valid!', 'error'); } if (this.debug) { YAHOO.log("Dropped on section id="+target.sectionId +", el="+this.getEl().id +", x="+YAHOO.util.Dom.getXY( this.getDragEl() )); } this.parentObj.remove_resource(this); if (target.is == 'resource' || target.is == 'activity') { target.parentObj.insert_resource(this, target); } else if (target.is == 'section') { target.insert_resource(this); } this.clear_move_markers(target); return; } resource_class.prototype.endDrag = function() { // Eliminates default action } section_class.prototype.swap_dates = function(el){ var i=0; while(this.getEl().getElementsByTagName("div")[i]) { if (this.getEl().getElementsByTagName("div")[i].className == "weekdates") { var tempdate = this.getEl().getElementsByTagName("div")[i].innerHTML; var permi = i; } i++; } var j=0; while(el.getEl().getElementsByTagName("div")[j]) { if (el.getEl().getElementsByTagName("div")[j].className == "weekdates") { var permj = j; } j++; } if(tempdate) { this.getEl().getElementsByTagName("div")[permi].innerHTML = el.getEl().getElementsByTagName("div")[permj].innerHTML; el.getEl().getElementsByTagName("div")[permj].innerHTML = tempdate; } }