/** * 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_td = 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 = this.getEl().childNodes[2]; //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', '/pix/i/marker.gif'); YAHOO.util.Event.addListener(highlightbutton, 'click', this.mk_marker, this, true); commandContainer.appendChild(highlightbutton); this.highlightButton = highlightbutton; } var viewbutton = main.mk_button('div', '/pix/i/hide.gif'); 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', '/pix/i/move_2d.gif', [['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_td = this.getEl().childNodes[1]; 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_td.getElementsByTagName('ul')[0]; if (this.resources_ul == null) { this.resources_ul = document.createElement('ul'); this.resources_ul.className='section'; this.content_td.insertBefore(this.resources_ul, this.content_td.childNodes[1]); } var resource_count = this.resources_ul.getElementsByTagName('li').length; for (var i=0;i 0 && childIndex < this.resources_ul.childNodes.length) this.resources_ul.removeChild(this.resources_ul.childNodes[childIndex-1]); YAHOO.log("removing "+el.getEl().id); if (el.getEl().parentNode != null) el.getEl().parentNode.removeChild(el.getEl()); this.write_sequence_list(); } section_class.prototype.insert_resource = function(el, targetel) { var resourcecount = this.resources.length; var found = false; var tempStore = nextStore = null; //update in backend targetId = ''; if (targetel != null) { targetId = targetel.id; } main.connect('post', 'class=resource&field=move', null, 'id='+el.id+'&beforeId='+targetId +'§ionId='+this.sectionId); //if inserting into a hidden resource hide if (this.hidden) { el.hiddenStored = el.hidden; el.toggle_hide(null,null,true,true); } else { if (el.hiddenStored != null) { el.toggle_hide(null,null,true,el.hiddenStored); el.hiddenStored = null; } } //update model if (targetel == null) { this.resources[this.resources.length] = el; } else { 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); this.clear_move_markers(target); } resource_class.prototype.onDragDrop = function(e, ids) { var target = YAHOO.util.DDM.getBestMatch(ids); 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 } /** * activity_class extends resource class */ function activity_class(id, group, config, parentObj) { this.init_activity(id, group, config, parentObj); } YAHOO.extend(activity_class, resource_class); activity_class.prototype.init_activity = function(id, group, config, parentObj) { if (!id) { YAHOO.log("Init activity, NO ID FOUND!",'error'); return; } this.is = 'activity'; this.currentGroup = this.get_current_group(id); this.init_resource(id, group, config, parentObj); this.groupButton= null; this.init_activity_button(); if (this.debug) { YAHOO.log("--init_activity "+id); } } activity_class.prototype.groupImages = ['/pix/t/groupn.gif', '/pix/t/groups.gif', '/pix/t/groupv.gif']; activity_class.prototype.init_activity_button = function() { var button = main.mk_button('a',this.groupImages[this.currentGroup]); YAHOO.util.Event.addListener(button,'click',this.toggle_group,this,true); this.commandContainer.appendChild(button); this.groupButton = button; } activity_class.prototype.get_current_group = function(id) { if (document.getElementById(id) == null) { return; } var groupNodeArray = document.getElementById(id).getElementsByTagName('a'); var groupNode = groupNodeArray[groupNodeArray.length-1]; for (var x=0;x 2) { this.currentGroup = 0; } this.groupButton.getElementsByTagName('img')[0].src = main.portal.wwwroot + this.groupImages[this.currentGroup]; main.connect('post', 'class=resource&field=groupmode', null, 'value='+this.currentGroup+'&id='+this.id); }