More cleanups to come from Ed.
This isn't actually working for me right now but he'll fix it now.
This is completely optional and won't affect any other code right now.
* Display the block!
*/
function _print_block() {
+ global $COURSE;
+
// is_empty() includes a call to get_content()
- if ($this->is_empty()) {
+ if ($this->is_empty()&&!($COURSE->javascriptportal)) {
if (empty($this->edit_controls)) {
// No content, no edit controls, so just shut up
return;
// The full treatment, please. Include the title text.
print_side_block($this->_title_html(), $this->content->text, NULL, NULL, $this->content->footer, $this->html_attributes(), $this->title);
}
+
+ //make a record of the block for the ajax course format to use
+ if (!empty($COURSE->javascriptportal)) {
+ $COURSE->javascriptportal->block_add('inst'.$this->instance->id,!$this->instance->visible);
+ }
}
}
}
function _print_block() {
+ global $COURSE;
+
// is_empty() includes a call to get_content()
- if ($this->is_empty()) {
+
+ if ($this->is_empty()&&!($COURSE->javascriptportal)) {
if (empty($this->edit_controls)) {
// No content, no edit controls, so just shut up
return;
} else {
if ($this->hide_header() && empty($this->edit_controls)) {
// Header wants to hide, no edit controls to show, so no header it is
- print_side_block(NULL, '', $this->content->items, $this->content->icons, $this->content->footer, $this->html_attributes());
+ print_side_block(NULL, '', $this->content->items, $this->content->icons,
+ $this->content->footer, $this->html_attributes());
} else {
// The full treatment, please. Include the title text.
- print_side_block($this->_title_html(), '', $this->content->items, $this->content->icons, $this->content->footer, $this->html_attributes(), $this->title);
+ print_side_block($this->_title_html(), '', $this->content->items, $this->content->icons,
+ $this->content->footer, $this->html_attributes(), $this->title);
+ }
+
+ //make a record of the block for the ajax course format to use
+ if (!empty($COURSE->javascriptportal)) {
+ $COURSE->javascriptportal->block_add('inst'.$this->instance->id,!$this->instance->visible);
}
}
}
}
}
-?>
\ No newline at end of file
+?>
--- /dev/null
+/*
+ * Contains Main class and supporting functions for topic ajax course layout
+ */
+
+//hide content body until done loading (manipulation looks ugly elsewise)
+document.getElementById('content').style.display='none';
+
+//onload object for handling scripts on page load, this insurses they run in my order
+function onload_class(){
+ this.scripts = new Array();
+ this.debug = false;
+}
+
+onload_class.prototype.add = function(script){
+ if(this.debug)YAHOO.log("onload.add - adding "+script,"junk");
+ this.scripts[this.scripts.length] = script;
+ }
+
+onload_class.prototype.load = function(){
+ var scriptcount = this.scripts.length;
+ if(this.debug)YAHOO.log("onload.load - loading "+scriptcount+" scripts","info");
+ for(i=0;i<scriptcount;i++)
+ eval(this.scripts[i]);
+ }
+
+var onload = new onload_class();
+
+
+
+//main page object
+function main_class(){
+ this.portal = new php_portal_class();
+
+ this.blocks = new Array();
+ this.sections = new Array();
+
+ this.leftcolumn = null;
+ this.rightcolumn = null;
+ this.adminBlock = null;
+
+ //if you use firefox the firebug extension will show log contents otherwise uncomment to view
+ //this.logview = new YAHOO.widget.LogReader(document.body.appendChild(document.createElement('div')));
+
+
+
+ this.icons = [];
+ this.marker = null;
+
+ //things to process onload
+ onload.add('main.process_document();');
+ onload.add("document.getElementById('content').style.display='block';");
+
+ //connection queue allows xhttp requests to be sent in order
+ this.connectQueue = [];
+ this.connectQueueHead = 0;
+ this.connectQueueConnection = null;
+
+ this.debug = true;
+}
+
+
+main_class.prototype.process_blocks = function(){
+
+ //remove unneeded icons (old school position icons and delete/hide although they will be readded)
+ var rmIconClasses = ['icon up','icon down','icon right','icon left','icon delete','icon hide'];
+ for(var c=0;c<rmIconClasses.length;c++){
+ els = YAHOO.util.Dom.getElementsByClassName(rmIconClasses[c]);
+
+ for(var x=0;x<els.length;x++)
+ els[x].parentNode.removeChild(els[x]);
+ }
+
+ //process the block ids passed from php
+ var blockcount = this.portal.blocks.length;
+ YAHOO.log("main.processBlocks - processing "+blockcount+" blocks","info");
+ for(i=0;i<blockcount;i++){
+ this.blocks[i] = new block_class(this.portal.blocks[i][1],"blocks");
+
+ //put in correct side array also
+ if(this.portal.blocks[i][0] == 'l')
+ main.leftcolumn.add_block(this.blocks[i]);
+ else if(this.portal.blocks[i][0] == 'r')
+ main.rightcolumn.add_block(this.blocks[i]);
+
+ //hide if called for
+ if(this.portal.blocks[i][2] == 1)
+ this.blocks[i].toggle_hide(null,null,true);
+ }
+
+ }
+
+
+main_class.prototype.process_document = function(){
+
+ //process the document to get important containers0
+ YAHOO.log("Processing Document","info");
+ //process columns for blocks
+ this.leftcolumn = new column_class('left-column',"blocks",null,'l');
+ this.rightcolumn = new column_class('right-column',"blocks",null,'r');
+
+ //process sections
+
+ var ct = 0;
+ while(document.getElementById('section-'+ct) != null){
+ this.sections[ct]=new section_class('section-'+ct,"sections",null,ct!=0?true:false);
+ this.sections[ct].addToGroup('resources');
+ ct++;
+ }
+ if(this.debug)YAHOO.log("Processed "+ct+" sections");
+
+ this.adminBlock = YAHOO.util.Dom.getElementsByClassName('block_adminblock')[0];
+ YAHOO.log("admin - "+this.adminBlock.className);
+
+ }
+
+main_class.prototype.mk_safe_for_transport = function(input){
+ return input.replace(/&/i,'_.amp._');
+ }
+
+main_class.prototype.get_block_index = function(el){
+ //return block by id
+ var blockcount = this.blocks.length;
+ for(i=0;i<blockcount;i++)
+ if(this.blocks[i] == el)
+ return i;
+ }
+
+main_class.prototype.get_section_index = function(el){
+ var sectioncount = this.sections.length;
+ for(i=0;i<sectioncount;i++)
+ if(this.sections[i] == el)
+ return i;
+ }
+
+main_class.prototype.mk_button = function(tag,imgSrc,attributes,imgAttributes){
+ //create button and return object
+ var container = document.createElement(tag);
+ container.style.cursor = 'pointer';
+ var image = document.createElement('img');
+ image.setAttribute('src',main.portal.wwwroot+imgSrc);
+ container.appendChild(image);
+
+ if(attributes != null)
+ for(var c=0;c<attributes.length;c++)
+ container.setAttribute(attributes[c][0],attributes[c][1]);
+
+ if(imgAttributes != null)
+ for(var c=0;c<attributes.length;c++)
+ image.setAttribute(imgAttributes[c][0],imgAttributes[c][1]);
+
+ return container;
+ }
+
+main_class.prototype.connect = function(method,urlStub,callback,body){
+ if(this.debug)YAHOO.log("Making "+method+" connection to /course/format/topicsajax/commands.php?courseId="+main.portal.id+"&"+urlStub);
+ if(callback == null){
+ callback = {}
+ }
+ return YAHOO.util.Connect.asyncRequest(method,this.portal.wwwroot+"/course/format/topicsajax/commands.php?courseId="+main.portal.id+"&"+urlStub,callback,body);
+
+
+ }
+
+main_class.prototype.connectQueue_add = function(method,urlStub,callback,body){
+ var Qlength = main.connectQueue.length;
+ main.connectQueue[Qlength] = [];
+ main.connectQueue[Qlength]['method'] = method;
+ main.connectQueue[Qlength]['urlStub'] = urlStub;
+ main.connectQueue[Qlength]['body'] = body;
+
+ if(main.connectQueueConnection == null || !YAHOO.util.Connect.isCallInProgress(main.connectQueueConnection))
+ main.connectQueue_fireNext();
+ }
+
+main_class.prototype.connectQueue_fireNext= function(){
+ var head = main.connectQueueHead;
+ if(head >= main.connectQueue.length)
+ return;
+
+ var callback = {
+ success: function(){
+ main.connectQueue_fireNext();
+ }
+ }
+
+ main.connectQueueConnection = main.connect(main.connectQueue[head]['method'],main.connectQueue[head]['urlStub'],callback,main.connectQueue[head]['body'])
+
+ main.connectQueueHead++;
+ }
+
+main_class.prototype.update_marker = function(newMarker){
+ if(this.marker != null)
+ this.marker.toggle_highlight();
+
+ this.marker = newMarker;
+ this.marker.toggle_highlight();
+
+ this.connect('post','class=course&field=marker',null,'value='+this.marker.sectionId);
+ }
+
+
+
+
+var main = new main_class();
+
+
+function php_portal_class(){
+ //portal to php data
+
+ this.id = null;
+
+ //array of id's of blocks set at end of page load by php
+ this.blocks = new Array();
+ this.imagePath = null;
+
+ //flag for week fomat
+ this.isWeek = false;
+
+ YAHOO.log("instantiated php_portal_class","info");
+}
--- /dev/null
+<?php
+ /*
+ * $Id$
+ *Provide RESTful interface for topics AJAX course formats
+ */
+
+
+ // TODO : ALL GET AND POST should be removed, use the param() functions instead
+
+
+ require_once('../../../config.php');
+ require_once('../../lib.php');
+
+ $courseid = required_param('courseId');
+
+ if (!$course = get_record('course', 'id', $courseid) {
+ error('Course does not exists');
+ }
+
+ //verify user is authorized
+ require_login($course->id);
+
+ if (!isteacher($course->id)){
+ error("Not authorized to edit page!");
+ }
+
+
+ switch($_SERVER['REQUEST_METHOD']){
+
+
+ case POST:
+ switch($_GET['class']){
+ case block: switch($_GET[field]){
+
+ case visible:
+ $dataobject->id = $_POST[instanceId];
+ $dataobject->visible = $_POST[value];
+ update_record('block_instance',$dataobject);
+ break;
+
+ case position:
+ $dataobject->id = $_POST[instanceId];
+ $dataobject->position = $_POST[value];
+ $dataobject->weight = $_POST[weight];
+ update_record('block_instance',$dataobject);
+ //echo("Got ".$_GET['class'].",".$_GET[field]."Posted id=".$dataobject->id." position=".$dataobject->position." weight=".$dataobject->weight);
+ break;
+ }
+ break;
+
+
+ case section: switch($_GET[field]){
+
+ case visible:
+ $dataobject->id = get_field('course_sections','id','course',$course->id,'section',(int)$_POST[id]);
+ $dataobject->visible = $_POST[value];
+ update_record('course_sections',$dataobject);
+ break;
+
+
+ case sequence:
+ $dataobject->id = get_field('course_sections','id','course',$course->id,'section',(int)$_POST[id]);
+ $dataobject->sequence = $_POST[value];
+ update_record('course_sections',$dataobject);
+ break;
+
+ case all:
+ $dataobject->id = get_field('course_sections','id','course',$course->id,'section',(int)$_POST[id]);
+ $dataobject->summary = make_dangerous($_POST[summary]);
+ $dataobject->sequence = $_POST[sequence];
+ $dataobject->visible = $_POST[visible];
+ update_record('course_sections',$dataobject);
+ break;
+
+
+
+ }
+ break;
+
+
+
+
+ case resource: switch($_GET[field]){
+
+ case visible:
+ $dataobject->id = $_POST[id];
+ $dataobject->visible = $_POST[value];
+ update_record('course_modules',$dataobject);
+ break;
+
+ case groupmode:
+ $dataobject->id = $_POST[id];
+ $dataobject->groupmode = $_POST[value];
+ update_record('course_modules',$dataobject);
+ break;
+
+ case section:
+ $dataobject->id = $_POST[id];
+ $dataobject->section = $_POST[value];
+ update_record('course_modules',$dataobject);
+ break;
+
+ }
+ break;
+
+ case course: switch($_GET[field]){
+
+ case marker:
+ $dataobject = NULL;
+ $dataobject->id = $course->id;
+ $dataobject->marker = $_POST[value];
+ update_record('course',$dataobject);
+ break;
+
+
+ }
+ break;
+
+ }
+
+
+ break;
+ case DELETE:
+ switch($_GET['class']){
+ case block:
+ delete_records('block_instance','id',$_GET[instanceId]);
+ break;
+
+ case section:
+ $dataobject->id = get_field('course_sections','id','course',$course->id,'section',(int)$_GET[id]);
+ $dataobject->summary = '';
+ $dataobject->sequence = '';
+ $dataobject->visible = '1';
+ update_record('course_sections',$dataobject);
+ break;
+
+ case resource:
+ delete_records('course_modules','id',$_GET[id]);
+ break;
+
+ }
+ break;
+ }
+
+ function make_dangerous($input){
+ //the compliment to the javascript function 'make_safe'
+ return str_replace("_.amp._","&",$input);
+ }
+?>
--- /dev/null
+<?php
+//
+// Optional course format configuration file
+//
+// This file contains any specific configuration settings for the
+// format.
+//
+// The default blocks layout for this course format:
+ $format['defaultblocks'] = 'participants,activity_modules,search_forums,'.
+ 'admin,course_list:news_items,calendar_upcoming,'.
+ 'recent_activity';
+//
+?>
\ No newline at end of file
--- /dev/null
+<?php // $Id$
+ // Display the whole course as "topics" made of of modules
+ // In fact, this is very similar to the "weeks" format, in that
+ // each "topic" is actually a week. The main difference is that
+ // the dates aren't printed - it's just an aesthetic thing for
+ // courses that aren't so rigidly defined by time.
+ // Included from "view.php"
+
+ require_once($CFG->dirroot.'/mod/forum/lib.php');
+ require_once($CFG->libdir.'/ajax/ajaxlib.php');
+
+
+ $topic = optional_param('topic', -1, PARAM_INT);
+
+
+ // Bounds for block widths
+ define('BLOCK_L_MIN_WIDTH', 100);
+ define('BLOCK_L_MAX_WIDTH', 210);
+ define('BLOCK_R_MIN_WIDTH', 100);
+ define('BLOCK_R_MAX_WIDTH', 210);
+
+ $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
+ BLOCK_L_MAX_WIDTH);
+ $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
+ BLOCK_R_MAX_WIDTH);
+
+ if ($topic != -1) {
+ $displaysection = course_set_display($course->id, $topic);
+ } else {
+ if (isset($USER->display[$course->id])) { // for admins, mostly
+ $displaysection = $USER->display[$course->id];
+ } else {
+ $displaysection = course_set_display($course->id, 0);
+ }
+ }
+
+ if (($marker >=0) && isteacher($course->id) && confirm_sesskey()) {
+ $course->marker = $marker;
+ if (! set_field("course", "marker", $marker, "id", $course->id)) {
+ error("Could not mark that topic for this course");
+ }
+ }
+
+ $streditsummary = get_string('editsummary');
+ $stradd = get_string('add');
+ $stractivities = get_string('activities');
+ $strshowalltopics = get_string('showalltopics');
+ $strtopic = get_string('topic');
+ $strgroups = get_string('groups');
+ $strgroupmy = get_string('groupmy');
+ $editing = $PAGE->user_is_editing();
+
+ if ($editing) {
+ $strstudents = moodle_strtolower($course->students);
+ $strtopichide = get_string('topichide', '', $strstudents);
+ $strtopicshow = get_string('topicshow', '', $strstudents);
+ $strmarkthistopic = get_string('markthistopic');
+ $strmarkedthistopic = get_string('markedthistopic');
+ $strmoveup = get_string('moveup');
+ $strmovedown = get_string('movedown');
+
+ //use temporarily until I figure out how to add a field to the user object
+ $temporary_override = true;
+ if (!empty($USER->use_ajax) || $temporary_override ){
+ /*
+ * if user doesnt want AJAX, than they wont get it,
+ * from here everything detects $COURSE->javascriptportal
+ */
+
+ $COURSE->javascriptportal = new jsportal();
+
+ print_require_js(Array("yui_yahoo","yui_dom","yui_event","yui_dragdrop","yui_connection","ajaxcourse_blocks","ajaxcourse_sections","ajaxcourse_topic"));
+
+ //javascript logging facilities
+ if($CFG->debug)print_require_js(Array("yui_logger"));
+ }
+
+ }
+
+
+/// Layout the whole page as three big columns.
+ echo '<table id="layout-table" cellspacing="0"><tr>';
+
+/// The left column ...
+
+ if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
+ echo '<td width="'.$preferred_width_left.'" id="left-column">';
+ blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
+ echo '</td>';
+ }
+
+/// Start main column
+ echo '<td id="middle-column">';
+
+ print_heading_block(get_string('topicoutline'), 'outline');
+
+ echo '<table class="topics" width="100%">';
+
+/// If currently moving a file then show the current clipboard
+ if (ismoving($course->id)) {
+ $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname)));
+ $strcancel= get_string('cancel');
+ echo '<tr class="clipboard">';
+ echo '<td colspan="3">';
+ echo $stractivityclipboard.' (<a href="mod.php?cancelcopy=true&sesskey='.$USER->sesskey.'">'.$strcancel.'</a>)';
+ echo '</td>';
+ echo '</tr>';
+ }
+
+/// Print Section 0
+
+ $section = 0;
+ $thissection = $sections[$section];
+
+ if ($thissection->summary or $thissection->sequence or isediting($course->id)) {
+ echo '<tr id="section-0" class="section main">';
+ echo '<td class="left side"> </td>';
+ echo '<td class="content">';
+
+ echo '<div class="summary">';
+ $summaryformatoptions->noclean = true;
+ echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
+
+ //Accessibility: added Alt, filled empty Alt-link text.
+ if (isediting($course->id)) {
+ echo '<a title="'.$streditsummary.'" '.
+ ' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
+ ' height="11" width="11" border="0" alt="'.$streditsummary.'" /></a><br /><br />';
+ }
+ echo '</div>';
+
+ print_section($course, $thissection, $mods, $modnamesused);
+
+ if (isediting($course->id)) {
+ print_section_add_menus($course, $section, $modnames);
+ }
+
+ echo '</td>';
+ echo '<td class="right side"> </td>';
+ echo '</tr>';
+ echo '<tr class="section separator"><td colspan="3" class="spacer"></td></tr>';
+ }
+
+
+/// Now all the normal modules by topic
+/// Everything below uses "section" terminology - each "section" is a topic.
+
+ $timenow = time();
+ $section = 1;
+ $sectionmenu = array();
+
+ while ($section <= $course->numsections) {
+
+ if (!empty($sections[$section])) {
+ $thissection = $sections[$section];
+
+ } else {
+ unset($thissection);
+ $thissection->course = $course->id; // Create a new section structure
+ $thissection->section = $section;
+ $thissection->summary = '';
+ $thissection->visible = 1;
+ if (!$thissection->id = insert_record('course_sections', $thissection)) {
+ notify('Error inserting new topic!');
+ }
+ }
+
+ $showsection = (isteacher($course->id) or $thissection->visible or !$course->hiddensections);
+
+ if (!empty($displaysection) and $displaysection != $section) {
+ if ($showsection) {
+ $strsummary = strip_tags(format_string($thissection->summary,true));
+ if (strlen($strsummary) < 57) {
+ $strsummary = ' - '.$strsummary;
+ } else {
+ $strsummary = ' - '.substr($strsummary, 0, 60).'...';
+ }
+ $sectionmenu['topic='.$section] = s($section.$strsummary);
+ }
+ $section++;
+ continue;
+ }
+
+ if ($showsection) {
+
+ $currenttopic = ($course->marker == $section);
+
+ if (!$thissection->visible) {
+ $sectionstyle = ' hidden';
+ } else if ($currenttopic) {
+ $sectionstyle = ' current';
+ } else {
+ $sectionstyle = '';
+ }
+
+ echo '<tr id="section-'.$section.'" class="section main'.$sectionstyle.'">';
+ echo '<td class="left side">'.$section.'</td>';
+
+ echo '<td class="content">';
+ if (!isteacher($course->id) and !$thissection->visible) { // Hidden for students
+ echo get_string('notavailable');
+ } else {
+ echo '<div class="summary">';
+ $summaryformatoptions->noclean = true;
+ echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
+
+ if (isediting($course->id)) {
+ echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
+ '<img src="'.$CFG->pixpath.'/t/edit.gif" border="0" height="11" width="11" alt="'.$streditsummary.'" /></a><br /><br />';
+ }
+ echo '</div>';
+
+ print_section($course, $thissection, $mods, $modnamesused);
+
+ if (isediting($course->id)) {
+ print_section_add_menus($course, $section, $modnames);
+ }
+ }
+ echo '</td>';
+
+ echo '<td class="right side">';
+ if ($displaysection == $section) { // Show the zoom boxes
+ echo '<a href="view.php?id='.$course->id.'&topic=0#section-'.$section.'" title="'.$strshowalltopics.'">'.
+ '<img src="'.$CFG->pixpath.'/i/all.gif" height="25" width="16" border="0" alt="'.$strshowalltopics.'" /></a><br />';
+ } else {
+ $strshowonlytopic = get_string('showonlytopic', '', $section);
+ echo '<a href="view.php?id='.$course->id.'&topic='.$section.'" title="'.$strshowonlytopic.'">'.
+ '<img src="'.$CFG->pixpath.'/i/one.gif" height="16" width="16" border="0" alt="'.$strshowonlytopic.'" /></a><br />';
+ }
+
+ if (isediting($course->id)) {
+ if ($course->marker == $section) { // Show the "light globe" on/off
+ echo '<a href="view.php?id='.$course->id.'&marker=0&sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strmarkedthistopic.'">'.
+ '<img src="'.$CFG->pixpath.'/i/marked.gif" vspace="3" height="16" width="16" border="0" alt="'.$strmarkedthistopic.'" /></a><br />';
+ } else {
+ echo '<a href="view.php?id='.$course->id.'&marker='.$section.'&sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strmarkthistopic.'">'.
+ '<img src="'.$CFG->pixpath.'/i/marker.gif" vspace="3" height="16" width="16" border="0" alt="'.$strmarkthistopic.'" /></a><br />';
+ }
+
+ if ($thissection->visible) { // Show the hide/show eye
+ echo '<a href="view.php?id='.$course->id.'&hide='.$section.'&sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strtopichide.'">'.
+ '<img src="'.$CFG->pixpath.'/i/hide.gif" vspace="3" height="16" width="16" border="0" alt="'.$strtopichide.'" /></a><br />';
+ } else {
+ echo '<a href="view.php?id='.$course->id.'&show='.$section.'&sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strtopicshow.'">'.
+ '<img src="'.$CFG->pixpath.'/i/show.gif" vspace="3" height="16" width="16" border="0" alt="'.$strtopicshow.'" /></a><br />';
+ }
+
+ if ($section > 1) { // Add a arrow to move section up
+ echo '<a href="view.php?id='.$course->id.'&random='.rand(1,10000).'&section='.$section.'&move=-1&sesskey='.$USER->sesskey.'#section-'.($section-1).'" title="'.$strmoveup.'">'.
+ '<img src="'.$CFG->pixpath.'/t/up.gif" vspace="3" height="11" width="11" border="0" alt="'.$strmoveup.'" /></a><br />';
+ }
+
+ if ($section < $course->numsections) { // Add a arrow to move section down
+ echo '<a href="view.php?id='.$course->id.'&random='.rand(1,10000).'&section='.$section.'&move=1&sesskey='.$USER->sesskey.'#section-'.($section+1).'" title="'.$strmovedown.'">'.
+ '<img src="'.$CFG->pixpath.'/t/down.gif" vspace="3" height="11" width="11" border="0" alt="'.$strmovedown.'" /></a><br />';
+ }
+
+ }
+
+ echo '</td></tr>';
+ echo '<tr class="section separator"><td colspan="3" class="spacer"></td></tr>';
+ }
+
+ $section++;
+ }
+ echo '</table>';
+
+ if (!empty($sectionmenu)) {
+ echo '<div align="center" class="jumpmenu">';
+ echo popup_form($CFG->wwwroot.'/course/view.php?id='.$course->id.'&', $sectionmenu,
+ 'sectionmenu', '', get_string('jumpto'), '', '', true);
+ echo '</div>';
+ }
+
+
+ echo '</td>';
+
+ // The right column
+ if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing) {
+ echo '<td width="'.$preferred_width_right.'" id="right-column">';
+ blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
+ echo '</td>';
+ }
+
+ echo '</tr></table>';
+
+ //create javascript portal code
+ if (!empty($COURSE->javascriptportal)) {
+ $COURSE->javascriptportal->print_javascript($course->id);
+ }
+
+?>
--- /dev/null
+<?PHP
+/**
+ * Library functions for using ajax with moodle
+ **/
+
+
+/**
+ *Print require statements for javascript libraries
+ *Takes in an array of either full paths or shortnames and it will translate them to full paths
+ **/
+
+function print_require_js($list){
+ global $CFG;
+
+ //list of shortname to filepath translations
+ $translatelist = Array(
+ "yui_yahoo" => "/lib/yui/yahoo/yahoo.js",
+ "yui_dom" => "/lib/yui/dom/dom.js",
+ "yui_event" => "/lib/yui/event/event.js",
+ "yui_dragdrop" => "/lib/yui/dragdrop/dragdrop.js",
+ "yui_logger" => "/lib/yui/logger/logger.js",
+ "yui_connection" => "/lib/yui/connection/connection.js",
+ "ajaxcourse_blocks" => "/lib/ajax/block_classes.js",
+ "ajaxcourse_sections" => "/lib/ajax/section-resource_classes.js",
+ "ajaxcourse_topic" => "/course/format/topicsajax/ajaxcourse-topics.js",
+ "ajaxcourse_week" => "/course/format/weeksajax/ajaxcourse-weeks.js"
+ );
+
+
+ for ($i=0;$i<count($list);$i++) {
+ if ($translatelist[$list[$i]]) {
+ echo "<script language='JavaScript' type='text/javascript' src='".$CFG->wwwroot.''.$translatelist[$list[$i]]."'></script>\n\r";
+ } else {
+ echo "<script language='JavaScript' type='text/javascript' src='".$CFG->wwwroot.''.$list[$i]."'></script>\n\r";
+ }
+ }
+
+}
+
+//used to create view of document to be passed to javascript on pageload
+class jsportal{
+
+ var $currentblocksection = null;
+ var $blocks = array();
+ var $sections = array();
+
+
+ //takes id of block and adds it
+ function block_add($id,$hidden=false){
+ $hidden_binary = 0;
+
+ if ($hidden) {
+ $hidden_binary = 1;
+ }
+
+ $this->blocks[count($this->blocks)] = Array($this->currentblocksection,$id,$hidden_binary);
+ }
+
+
+ function print_javascript($id) {
+ global $CFG;
+
+ $blocksoutput = '';
+ for ($i=0;$i<count($this->blocks);$i++){
+ $blocksoutput.="['".$this->blocks[$i][0]."','".$this->blocks[$i][1]."','".$this->blocks[$i][2]."']";
+ if ($i != (count($this->blocks)-1)) {
+ $blocksoutput.=",";
+ }
+ }
+
+ $output ="<script language='javascript'>\r";
+ $output .=" main.portal.id = ".$id."\r";
+ $output .=" main.portal.blocks = new Array(".$blocksoutput.");\r";
+ $output .=" main.portal.wwwroot = '".$CFG->wwwroot."';\r";
+ $output .=" onload.load()\r";
+ $output .=" main.process_blocks();\r";
+ $output .="</script>";
+
+ echo $output;
+ }
+
+}
+
+?>
--- /dev/null
+/*
+ * library for ajaxcourse formats, the classes and related functions for drag and drop blocks
+ *
+ * this library requires a 'main' object created in calling document
+ *
+ */
+
+
+ //set Drag and Drop to Intersect mode:
+ YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT;
+
+/*
+ * class for draggable block, extends YAHOO.util.DDProxy
+ */
+function block_class(id,group,config){
+ this.init_block(id,group,config);
+}
+YAHOO.extend(block_class, YAHOO.util.DDProxy);
+
+block_class.prototype.init_block = function(id, sGroup, config){
+ if (!id) { return; }
+
+ //Drag and Drop
+ this.init(id, sGroup, config);
+ this.initFrame();
+ this.createFrame();
+
+ this.is = 'block';
+ this.instanceId = this.getEl().id.replace(/inst/i,'');
+
+
+ this.addInvalidHandleType('a');
+
+ var s = this.getEl().style;
+ s.opacity = 0.76;
+ s.filter = "alpha(opacity=76)";
+
+
+ // specify that this is not currently a drop target
+ this.isTarget = false;
+
+ this.region = YAHOO.util.Region.getRegion(this.getEl());
+
+ this.type = block_class.TYPE;
+
+
+ //DHTML
+ this.viewbutton = null;
+ this.originalClass = this.getEl().className;
+
+ this.init_buttons();
+
+ this.debug = false;
+ }
+
+block_class.prototype.startDrag = function(x, y) {
+ //operates in intersect mode
+ YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT;
+
+ YAHOO.log(this.id + " startDrag");
+
+ var dragEl = this.getDragEl();
+ var clickEl = this.getEl();
+
+ dragEl.innerHTML = clickEl.innerHTML;
+ dragEl.className = clickEl.className;
+ dragEl.style.color = this.DDM.getStyle(clickEl, "color");;
+ dragEl.style.backgroundColor = this.DDM.getStyle(clickEl, "backgroundColor");
+
+ var s = clickEl.style;
+ s.opacity = .1;
+ s.filter = "alpha(opacity=10)";
+
+ var targets = YAHOO.util.DDM.getRelated(this, true);
+ YAHOO.log(targets.length + " targets");
+
+ //restyle side boxes to highlight
+ for (var i=0; i<targets.length; i++) {
+
+ var targetEl = targets[i].getEl();
+
+ targetEl.style.background = "#fefff0";
+ targetEl.opacity = .3;
+ targetEl.filter = "alpha(opacity=30)";
+ }
+ }
+
+block_class.prototype.endDrag = function() {
+ // reset the linked element styles
+ var s = this.getEl().style;
+ s.opacity = 1;
+ s.filter = "alpha(opacity=100)";
+ this.resetTargets();
+ }
+
+block_class.prototype.onDragDrop = function(e, id) {
+ // get the drag and drop object that was targeted
+ var oDD;
+
+ if ("string" == typeof id) {
+ oDD = YAHOO.util.DDM.getDDById(id);
+ } else {
+ oDD = YAHOO.util.DDM.getBestMatch(id);
+ }
+
+ var el = this.getEl();
+
+ YAHOO.log("id="+id+" el = "+e+" x="+YAHOO.util.Dom.getXY(this.getDragEl()));
+
+ //var collisions = this.find_collisions(e,id);
+
+ this.move_block(id);
+ //YAHOO.util.DDM.moveToEl(el, oDD.getEl());
+
+
+
+ this.resetTargets();
+
+ }
+
+block_class.prototype.find_target = function(column){
+ var collisions = column.find_sub_collision(YAHOO.util.Region.getRegion(this.getDragEl()));
+
+ //determine position
+ var insertbefore = null;
+ if(collisions.length == 0)
+ return;
+
+ insertbefore = column.blocks[collisions[0][0]];
+
+ return insertbefore;
+ }
+
+block_class.prototype.resetTargets = function() {
+ // reset the target styles
+ var targets = YAHOO.util.DDM.getRelated(this, true);
+ for (var i=0; i<targets.length; i++) {
+ var targetEl = targets[i].getEl();
+ targetEl.style.background = "";
+ targetEl.opacity = 1;
+ targetEl.filter = "alpha(opacity=100)";
+ }
+ }
+
+block_class.prototype.move_block = function(columnid){
+
+ //var column = YAHOO.util.DDM.getDDById(columnid[0].);
+ column = columnid[0];
+ var inserttarget = this.find_target(column);
+
+ if(this.debug)YAHOO.log("moving "+this.getEl().id+" before "+inserttarget.getEl().id+" - parentNode="+this.getEl().parentNode.id);
+
+
+ //remove from document
+ if(this.getEl().parentNode != null)
+ this.getEl().parentNode.removeChild(this.getEl());
+
+ //insert into correct place
+ if(inserttarget != null ){
+ inserttarget.getEl().parentNode.insertBefore(this.getEl(),inserttarget.getEl());
+
+ }else if(column == main.rightcolumn){//if right side insert before admin block
+ column.getEl().insertBefore(this.getEl(),main.adminBlock);
+
+ }else{
+ column.getEl().appendChild(this.getEl());
+ }
+
+ this.reset_regions();
+
+ //remove block from current array
+ if(main.rightcolumn.has_block(this))
+ main.rightcolumn.remove_block(this);
+
+ else if(main.leftcolumn.has_block(this))
+ main.leftcolumn.remove_block(this);
+
+ //insert into new array
+ column.insert_block(this,inserttarget);
+
+ }
+
+block_class.prototype.reset_regions = function(){
+ var blockcount = main.blocks.length;
+ for(i=0;i<blockcount;i++)
+ main.blocks[i].region = YAHOO.util.Region.getRegion(main.blocks[i].getEl());
+ }
+
+block_class.prototype.init_buttons = function(){
+
+ var viewbutton = main.mk_button('a','/pix/t/hide.gif',[['class','icon hide']]);
+ YAHOO.util.Event.addListener(viewbutton,'click',this.toggle_hide,this,true);
+
+ var deletebutton = main.mk_button('a','/pix/t/delete.gif',[['class','icon delete']]);
+ YAHOO.util.Event.addListener(deletebutton,'click',this.delete_button,this,true);
+
+
+ this.viewbutton = viewbutton;
+
+ buttonCont = YAHOO.util.Dom.getElementsByClassName('commands','div',this.getEl())[0];
+ buttonCont.appendChild(viewbutton);
+ buttonCont.appendChild(deletebutton);
+
+ }
+
+block_class.prototype.toggle_hide = function(e,target,isCosmetic){
+ if(YAHOO.util.Dom.hasClass(this.getEl(),'hidden')){
+ this.getEl().className = this.originalClass;
+ this.viewbutton.childNodes[0].src = this.viewbutton.childNodes[0].src.replace(/show.gif/i,'hide.gif');
+ if(!isCosmetic)main.connect('post','class=block&field=visible',null,'value=1&instanceId='+this.instanceId);
+
+ }else{
+ this.originalClass = this.getEl().className;
+ this.getEl().className = "hidden sideblock";
+ this.viewbutton.childNodes[0].src = this.viewbutton.childNodes[0].src.replace(/hide.gif/i,'show.gif');
+ if(!isCosmetic)main.connect('post','class=block&field=visible',null,'value=0&instanceId='+this.instanceId);
+
+ }
+ }
+
+block_class.prototype.delete_button = function(){
+ //remove from local model
+ if(main.rightcolumn.has_block(this))
+ main.rightcolumn.remove_block(this);
+
+ else if(main.leftcolumn.has_block(this))
+ main.leftcolumn.remove_block(this);
+
+ //remove from remote model
+ main.connect('delete','class=block&instanceId='+this.instanceId);
+
+ //remove from view
+ if(this.debug)YAHOO.log("Deleting "+this.getEl().id);
+ main.blocks[main.get_block_index(this)] = null;
+ this.getEl().parentNode.removeChild(this.getEl());
+
+ }
+
+block_class.prototype.update_index = function(index,columnId){
+ //update via AJAX the db representation of page
+ main.connectQueue_add('post','class=block&field=position',null,'value='+columnId+'&weight='+index+'&instanceId='+this.instanceId);
+ if(this.debug)YAHOO.log("updating position of "+this.getEl().id+" to index "+index+" on column "+columnId);
+ }
+
+
+/*
+ * column class, DD targets
+ */
+
+function column_class(id,group,config,ident){
+ this.init_column(id,group,config,ident);
+}
+YAHOO.extend(column_class, YAHOO.util.DDTarget);
+
+column_class.prototype.init_column = function(id, group,config,ident){
+ if (!id) { return; }
+
+ this.initTarget(id,group,config);
+ this.blocks = new Array();
+ this.ident = ident;
+
+// YAHOO.log("init_column "+id+"-"+el.id);
+ this.region = YAHOO.util.Region.getRegion(id);
+
+ this.debug = false;
+ }
+
+
+column_class.prototype.find_sub_collision = function(dragRegion){
+ //find collisions with sub_elements(blocks), return array of collisions with regions of collision
+ var collisions = new Array();
+ for(i=0;i<this.blocks.length;i++){
+ if(this.debug)YAHOO.log("testing region "+this.blocks[i].region+" against" + dragRegion + "intersect ="+this.blocks[i].region.intersect(dragRegion));
+ var intersect = this.blocks[i].region.intersect(dragRegion);
+ if(intersect != null){
+ index = collisions.length;
+ collisions[index] = new Array();
+ collisions[index][0] = i;
+ collisions[index][1] = this.blocks[i].region.intersect(dragRegion);
+ if(this.debug)YAHOO.log(index+" Collides with "+this.blocks[i].getEl().id+" area" + collisions[index][1].getArea());
+ }
+ }
+ return collisions;
+ }
+
+column_class.prototype.add_block = function(el){
+ this.blocks[this.blocks.length] = el;
+ }
+
+column_class.prototype.insert_block = function(el,targetel){
+ var blockcount = this.blocks.length;
+ var found = false;
+ var tempStore = nextStore = null;
+ for(var i=0;i<blockcount;i++){
+ if(found){
+ tempStore = this.blocks[i];
+ this.blocks[i] = nextStore;
+ nextStore = tempStore;
+
+ if(nextStore != null)
+ nextStore.update_index(i+1,this.ident);
+
+
+ }else if(this.blocks[i] == targetel){
+ found = true;
+ nextStore = this.blocks[i];
+ this.blocks[i] = el;
+ blockcount++;
+
+ this.blocks[i].update_index(i,this.ident);
+ nextStore.update_index(i+1,this.ident);
+ }
+ }
+
+ if(!found){//insert at end
+ this.add_block(el);
+ el.update_index(this.blocks.length,this.ident);
+ }
+ }
+
+column_class.prototype.has_block = function(el){
+ var blockcount = this.blocks.length;
+ for(var i=0;i<blockcount;i++)
+ if(this.blocks[i]==el)
+ return true;
+ return false;
+ }
+
+
+column_class.prototype.remove_block = function(el){
+ var blockcount = this.blocks.length;
+ var found = false;
+ for(var i=0;i<blockcount;i++){
+ if(found){
+ this.blocks[i-1] = this.blocks[i];
+ if(i==blockcount-1){
+ this.blocks = this.blocks.slice(0,-1);
+ blockcount--;
+ }
+ this.blocks[i-1].update_index(i-1,this.ident);
+ }else if(this.blocks[i]==el){
+ found = true;
+ }
+ }
+ }
+
+
+
--- /dev/null
+/*
+ * 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.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;
+ if(isDraggable)this.add_handle();
+ }
+
+ 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();
+
+ this.debug = false;
+ 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;
+
+
+ var deletebutton = main.mk_button('div','/pix/t/delete.gif');
+ YAHOO.util.Event.addListener(deletebutton,'click',this.delete_button,this,true);
+ commandContainer.appendChild(deletebutton);
+
+
+ }
+
+section_class.prototype.delete_button = function(){
+ this.content_td.childNodes[0].data = '';
+
+ if(this.hidden)
+ this.toggle_hide();
+
+ if(this.highlighted)
+ this.toggle_highlight();
+
+ if(this.debug)YAHOO.log('Deleting '+this.getEl().id);
+
+ main.connect('delete','class=section&id='+this.id);
+ for(var i=0;i<this.resources.length;i++)
+ this.resources[i].delete_button();
+ }
+
+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;
+
+
+ //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;
+ if(this.debug)YAHOO.log("Found "+resource_count+" resources in "+this.getEl().id);
+
+ for(var i=0;i<resource_count;i++){
+ var resource = this.resources_ul.getElementsByTagName('li')[i];
+ if(YAHOO.util.Dom.hasClass(resource,'resource'))
+ this.resources[this.resources.length] = new resource_class(resource.id,'resources',null,this);
+ else
+ this.resources[this.resources.length] = new activity_class(resource.id,'resources',null,this);
+ }
+
+ this.summary = YAHOO.util.Dom.getElementsByClassName('summary',null,this.getEl())[0].firstChild.data || '';
+
+
+ }
+
+section_class.prototype.startDrag = function(x, y) {
+ //operates in point mode
+ YAHOO.util.DDM.mode = YAHOO.util.DDM.POINT;
+
+ //remove from resources group temporarily
+ this.removeFromGroup('resources');
+
+ //reinitialize dd element
+ this.getDragEl().innerHTML = '';
+
+ var targets = YAHOO.util.DDM.getRelated(this, true);
+ if(this.debug)YAHOO.log(this.sectionId + " startDrag "+targets.length + " targets");
+
+ }
+
+section_class.prototype.onDragDrop = function(e, id) {
+ // get the drag and drop object that was targeted
+ var target = YAHOO.util.DDM.getDDById(id);
+
+ if(this.debug)YAHOO.log("Section dropped on id="+id+" el = "+this.getEl().id+" x="+YAHOO.util.Dom.getXY(this.getDragEl()));
+
+ this.move_to_section(target);
+
+ //add back to resources group
+ this.addToGroup('resources');
+ }
+section_class.prototype.endDrag = function(){
+ //nessicary to defeat default action
+
+ //add back to resources group
+ this.addToGroup('resources');
+ }
+
+section_class.prototype.move_to_section = function(target){
+ var tempTd = document.createElement('td');
+ var tempStore = null;
+ var sectionCount = main.sections.length;
+ var found = null;
+
+ //determine if original is above or below target and adjust loop
+ var oIndex=main.get_section_index(this);
+ var tIndex=main.get_section_index(target);
+
+ if(this.debug)YAHOO.log("original is at: "+oIndex+" target is at:"+tIndex+" of "+(sectionCount-1));
+
+ if(oIndex < tIndex){
+ var loopCondition = 'i<sectionCount';
+ var loopStart = 1;
+ var loopInc = 'i++';
+ var loopmodifier = 'i-1';
+ }else{
+ var loopCondition = 'i>0';
+ var loopStart = sectionCount-1;
+ var loopInc = 'i--';
+ var loopmodifier = 'i+1';
+ }
+
+ for(var i=loopStart;eval(loopCondition);eval(loopInc)){
+
+ if((main.sections[i] == this)&& !found){
+ //enounter with original node
+ if(this.debug)YAHOO.log("Found Original "+main.sections[i].getEl().id);
+ if(main.sections[i] == this){
+ found = true;
+ }
+
+ }else if(main.sections[i] == target){
+ //encounter with target node
+ if(this.debug)YAHOO.log("Found target "+main.sections[i].getEl().id);
+ main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]);
+ found = false;
+ break;
+
+ }else if(found){
+ //encounter with nodes inbetween
+ main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]);
+ }
+ }
+
+ }
+
+
+section_class.prototype.swap_with_section = function(sectionIn){
+ var tmpStore = null;
+
+ thisIndex = main.get_section_index(this);
+ targetIndex = main.get_section_index(sectionIn);
+ main.sections[targetIndex] = this;
+ main.sections[thisIndex] = sectionIn;
+
+ this.changeId(targetIndex);
+ sectionIn.changeId(thisIndex);
+
+ if(this.debug)YAHOO.log("Swapping "+this.getEl().id+" with "+sectionIn.getEl().id);
+
+ YAHOO.util.DDM.swapNode(this.getEl(),sectionIn.getEl());
+
+
+ }
+
+section_class.prototype.toggle_hide = function(e,target,isCosmetic){
+ if(this.hidden){
+ YAHOO.util.Dom.removeClass(this.getEl(),'hidden');
+ this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show.gif/i,'hide.gif');
+ this.hidden = false;
+
+ if(!isCosmetic)main.connect('post','class=section&field=visible',null,'value=1&id='+this.sectionId);
+ }else{
+ YAHOO.util.Dom.addClass(this.getEl(),'hidden');
+ this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide.gif/i,'show.gif');
+ this.hidden = true;
+
+ if(!isCosmetic)main.connect('post','class=section&field=visible',null,'value=0&id='+this.sectionId);
+ }
+ }
+
+section_class.prototype.toggle_highlight = function(){
+ if(this.highlighted){
+ YAHOO.util.Dom.removeClass(this.getEl(),'current');
+ this.highlighted = false;
+ }else{
+ YAHOO.util.Dom.addClass(this.getEl(),'current');
+ this.highlighted = true;
+ }
+ }
+
+section_class.prototype.mk_marker = function(){
+ if(main.marker != this){
+ main.update_marker(this);
+
+ }else{//if currently the marker
+ main.marker = null;
+
+ main.connect('post','class=course&field=marker',null,'value=0');
+ this.toggle_highlight();
+
+ }
+
+ }
+
+section_class.prototype.changeId = function(newId){
+ this.sectionId = newId;
+ this.numberDisplay.firstChild.data = newId;
+
+ 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))
+
+ if(main.marker == this)
+ main.update_marker(this);
+ }
+
+section_class.prototype.get_resource_index = function(el){
+ for(var x=0;x<this.resources.length;x++)
+ if(this.resources[x]==el)
+ return x;
+ YAHOO.log("Could not find resource to remove "+el.getEl().id,"error");
+ return -1;
+ }
+
+section_class.prototype.remove_resource = function(el){
+ var resourceCount = this.resources.length;
+ if(resourceCount == 1){
+ if(this.resources[0] == el)
+ this.resources = new Array();
+ }else{
+ var found = false;
+ for(var i=0;i<resourceCount;i++){
+ if(found){
+ this.resources[i-1] = this.resources[i];
+ if(i==resourceCount-1){
+ this.resources = this.resources.slice(0,-1);
+ resourceCount--;
+ }
+ this.resources[i-1].update_index(i-1);
+ }else if(this.resources[i]==el){
+ found = true;
+ }
+ }
+ }
+
+
+ //remove "text" nodes to keep DOM clean
+ var childIndex = null;
+ var childrenCount = this.resources_ul.childNodes.length;
+ for(var i=0;i<childrenCount;i++)
+ if(this.resources_ul.childNodes[i] == el.getEl())
+ childIndex = i;
+ if(childIndex > 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;
+
+ if(targetel == null){
+ this.resources[this.resources.length] = el;
+ }else
+ for(var i=0;i<resourcecount;i++){
+ if(found){
+ tempStore = this.resources[i];
+ this.resources[i] = nextStore;
+ nextStore = tempStore;
+
+ if(nextStore != null)
+ nextStore.update_index(i+1);
+
+ }else if(this.resources[i] == targetel){
+ found = true;
+ nextStore = this.resources[i];
+ this.resources[i] = el;
+ resourcecount++;
+
+ this.resources[i].update_index(i,this.ident);
+ nextStore.update_index(i+1);
+ }
+ }
+
+
+ //YAHOO.log("Inserting "+el.getEl().id+" before "+targetel.getEl().id);
+ if(targetel != null){
+ this.resources_ul.insertBefore(el.getEl(),targetel.getEl());
+ this.resources_ul.insertBefore(document.createTextNode(''),targetel.getEl());
+
+ }else{
+ this.resources_ul.appendChild(el.getEl());
+ this.resources_ul.appendChild(document.createTextNode(" "));
+ }
+ el.parentObj = this;
+
+ this.write_sequence_list();
+ main.connect('post','class=resource&field=section',null,'id='+el.id+'&value='+this.sectionId);
+ }
+
+section_class.prototype.write_sequence_list = function(toReturn){
+ var listOutput = '';
+ for(var i=0;i<this.resources.length;i++){
+ listOutput += this.resources[i].id;
+ if(i != (this.resources.length-1))
+ listOutput += ',';
+ }
+
+ if(toReturn)
+ return listOutput;
+
+ main.connect('post','class=section&field=sequence',null,'id='+this.sectionId+'&value='+listOutput);
+ }
+
+
+
+/*
+ * Resource Class extends util.DDProxy
+ */
+
+
+function resource_class(id,group,config,parentObj){
+
+ this.init_resource(id,group,config,parentObj);
+}
+YAHOO.extend(resource_class, YAHOO.util.DDProxy);
+
+resource_class.prototype.init_resource = function(id,group,config,parentObj){
+ if (!id) { return; }
+
+ this.is = 'resource';
+ this.init(id,group,config);
+ this.createFrame();
+ this.isTarget = true;
+
+ this.id = this.getEl().id.replace(/module-/i,'');
+
+ this.hidden = false;
+ if(YAHOO.util.Dom.hasClass(this.getEl().getElementsByTagName('a')[0],'dimmed'))
+ this.hidden = true;
+
+ this.linkContainer = this.getEl().getElementsByTagName('a')[0];
+
+ this.commandContainer = null;
+ this.viewButton = null;
+ this.handle = null;
+ this.init_buttons();
+
+ this.parentObj = parentObj;
+
+ this.debug = false;
+ if(this.debug)YAHOO.log("init_resource "+id+" parent = "+parentObj.getEl().id);
+
+ }
+
+resource_class.prototype.init_buttons = function(){
+ var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands','span',this.getEl())[0];
+ if( commandContainer == null){
+ YAHOO.log('Cannot find command container for '+this.getEl().id,'error');
+ return;
+ }
+
+ this.commandContainer = commandContainer;
+
+ //find edit button
+ var updateButton = null;
+ var buttons = commandContainer.getElementsByTagName('a');
+ for(var x=0;x<buttons.length;x++)
+ if(buttons[x].title == 'Update')
+ updateButton = buttons[x];
+
+ if(updateButton == null)
+ YAHOO.log('Cannot find updateButton for '+this.getEl().id,'error');
+
+ commandContainer.innerHTML = '';
+
+
+ //add move-handle
+ var handleRef = main.mk_button('a','/pix/i/move_2d.gif',[['style','cursor:move']],[['height','11'],['width','11'],['hspace','2'],['border','0']]);
+ YAHOO.util.Dom.generateId(handleRef,'sectionHandle');
+ this.handle = handleRef;
+
+ commandContainer.appendChild(handleRef);
+ this.setHandleElId(this.handle.id);
+
+
+
+ //add edit button back in
+ commandContainer.appendChild(updateButton);
+
+ //add rest
+ var button = main.mk_button('a','/pix/t/delete.gif');
+ YAHOO.util.Event.addListener(button,'click',this.delete_button,this,true);
+ commandContainer.appendChild(button);
+
+ if(this.hidden)
+ var button = main.mk_button('a','/pix/t/show.gif');
+ else
+ var button = main.mk_button('a','/pix/t/hide.gif');
+ YAHOO.util.Event.addListener(button,'click',this.toggle_hide,this,true);
+ commandContainer.appendChild(button);
+ this.viewButton = button;
+
+ }
+
+resource_class.prototype.toggle_hide = function(){
+ if(this.hidden){
+ YAHOO.util.Dom.removeClass(this.linkContainer,'dimmed');
+ this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show.gif/i,'hide.gif');
+ this.hidden = false;
+
+ main.connect('post','class=resource&field=visible',null,'value=1&id='+this.id);
+ }else{
+ YAHOO.util.Dom.addClass(this.linkContainer,'dimmed');
+ this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide.gif/i,'show.gif');
+ this.hidden = true;
+
+ main.connect('post','class=resource&field=visible',null,'value=0&id='+this.id);
+ }
+ }
+
+resource_class.prototype.delete_button = function(){
+ if(this.debug)YAHOO.log("Deleteing "+this.getEl().id+"from parent "+this.parentObj.getEl().id);
+
+ this.getEl().parentNode.removeChild(this.getEl());
+ 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("update Index for resource "+this.getEl().id+"to"+index);
+ }
+
+
+resource_class.prototype.startDrag = function(x, y) {
+ //operates in intersect mode
+ 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.onDragDrop = function(e, ids) {
+ // best fit Id
+ var id=[];
+ for(var i=0;i<ids.length;i++)
+ if(ids[i].is == 'resource')
+ id[id.length] = ids[i];
+
+ if(id.length == 0)
+ id = ids;
+
+
+ // get the drag and drop object that was targeted
+ var target = YAHOO.util.DDM.getBestMatch(id);
+
+ if(this.debug)YAHOO.log("dropped on id="+target+" 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);
+
+ }
+
+ 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){
+ 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)
+ var groupNodeArray = document.getElementById(id).getElementsByTagName('a');
+ var groupNode = groupNodeArray[groupNodeArray.length-1];
+
+ for(var x=0;x<this.groupImages.length;x++){
+ if(main.portal.wwwroot+this.groupImages[x] == groupNode.getElementsByTagName('img')[0].src){
+ return x;
+ }
+ }
+
+ return 0;
+ }
+
+activity_class.prototype.toggle_group = function(){
+ this.currentGroup++;
+ if(this.currentGroup > 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);
+ }
+
// This function prints one group of blocks in a page
// Parameters passed by reference for speed; they are not modified.
function blocks_print_group(&$page, &$pageblocks, $position) {
+ global $COURSE;
if(empty($pageblocks[$position])) {
$pageblocks[$position] = array();
$obj->_add_edit_controls($options);
}
- if(!$instance->visible) {
- if($isediting) {
+ if (!$instance->visible && empty($COURSE->javascriptportal)) {
+ if ($isediting) {
$obj->_print_shadow();
}
- }
- else {
+ } else {
$obj->_print_block();
}
}
- if($page->blocks_default_position() == $position && $page->user_is_editing()) {
+ if ($page->blocks_default_position() == $position && $page->user_is_editing()) {
blocks_print_adminblock($page, $pageblocks);
}