/* * library for ajaxcourse formats, the classes and related functions for sections and resources * this library requires a 'main' object created in calling document */ 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; 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; 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('div','/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.numberDisplay.innerHTML; 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 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); }