From 604c996ca6118274f855652744ecbe221892f697 Mon Sep 17 00:00:00 2001 From: vyshane Date: Tue, 24 Oct 2006 08:07:56 +0000 Subject: [PATCH] AJAX fixes. --- course/format/topics/format.php | 18 +------ course/format/weeks/format.php | 17 +------ course/rest.php | 2 +- course/view.php | 74 +++++++++++++++++++++++---- lib/ajax/ajaxcourse.js | 58 ++++++++++----------- lib/ajax/ajaxlib.php | 89 +++++++++++++-------------------- lib/ajax/block_classes.js | 12 ++--- lib/ajax/section_classes.js | 33 ++++++++---- 8 files changed, 160 insertions(+), 143 deletions(-) diff --git a/course/format/topics/format.php b/course/format/topics/format.php index 8006bf66cb7..d0befec1b82 100644 --- a/course/format/topics/format.php +++ b/course/format/topics/format.php @@ -61,17 +61,6 @@ $strmarkedthistopic = get_string('markedthistopic'); $strmoveup = get_string('moveup'); $strmovedown = get_string('movedown'); - - if (!empty($USER->ajax)){ - - // If user doesnt want AJAX, then 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')); - } } @@ -281,9 +270,4 @@ echo ''; - //create javascript portal code - if (!empty($COURSE->javascriptportal)) { - $COURSE->javascriptportal->print_javascript($course->id); - } - -?> +?> \ No newline at end of file diff --git a/course/format/weeks/format.php b/course/format/weeks/format.php index 88594db4549..bf892240328 100644 --- a/course/format/weeks/format.php +++ b/course/format/weeks/format.php @@ -47,16 +47,6 @@ $strweekshow = get_string('weekshow', '', $strstudents); $strmoveup = get_string('moveup'); $strmovedown = get_string('movedown'); - - if (!empty($USER->ajax)) { - - // If user doesnt want AJAX, then 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')); - } } $context = get_context_instance(CONTEXT_COURSE, $course->id); @@ -275,9 +265,4 @@ echo ''; - //create javascript portal code - if (!empty($COURSE->javascriptportal)) { - $COURSE->javascriptportal->print_javascript($course->id); - } - -?> +?> \ No newline at end of file diff --git a/course/rest.php b/course/rest.php index dd6548b2d07..41fce5d17bd 100644 --- a/course/rest.php +++ b/course/rest.php @@ -179,4 +179,4 @@ switch($_SERVER['REQUEST_METHOD']) { break; } -?> +?> \ No newline at end of file diff --git a/course/view.php b/course/view.php index fb60ea36748..e26c1278266 100644 --- a/course/view.php +++ b/course/view.php @@ -5,6 +5,7 @@ require_once('../config.php'); require_once('lib.php'); require_once($CFG->libdir.'/blocklib.php'); + require_once($CFG->libdir.'/ajax/ajaxlib.php'); $id = optional_param('id', 0, PARAM_INT); $name = optional_param('name', '', PARAM_RAW); @@ -74,12 +75,12 @@ } $PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id); - $pageblocks = blocks_setup($PAGE,BLOCKS_PINNED_BOTH); + $pageblocks = blocks_setup($PAGE, BLOCKS_PINNED_BOTH); + if (!isset($USER->editing)) { $USER->editing = 0; } - if ($PAGE->user_allowed_editing()) { if (($edit == 1) and confirm_sesskey()) { $USER->editing = 1; @@ -112,13 +113,53 @@ $SESSION->fromdiscussion = $CFG->wwwroot .'/course/view.php?id='. $course->id; - if ($course->id == SITEID) { // This course is not a real course. + + if ($course->id == SITEID) { + // This course is not a real course. redirect($CFG->wwwroot .'/'); } - $PAGE->print_header(get_string('course').': %fullname%'); - echo '
'; // course wrapper start + // AJAX-capable course format? + $useajax = false; + $ajaxformatfile = $CFG->dirroot.'/course/format/'.$course->format.'/ajax.php'; + + if (file_exists($ajaxformatfile)) { + require_once($ajaxformatfile); + if ($USER->editing && !empty($USER->ajax) && $CFG->ajaxcapable) { + $useajax = true; + } + } + $meta = ''; + $bodytags = ''; + + if ($useajax) { + $meta = require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_dragdrop', 'yui_connection')); + + if (debugging('', DEBUG_DEVELOPER)) { // Need to detect whether we're using ajax too. + $meta .= require_js(array('yui_logger')); + + $bodytags = 'onLoad = "javascript: + show_logger = function() { + var logreader = new YAHOO.widget.LogReader(); + logreader.newestOnTop = false; + logreader.setTitle(\'Moodle Debug: YUI Log Console\'); + }; + show_logger(); + "'; + } + // Okay, global variable alert. VERY UGLY. We need to create this object + // here before the _print_block() function is called, since + // that function needs to set some stuff in the javascriptportal object. + // Like I said... VERY UGLY. + $COURSE->javascriptportal = new jsportal(); + } + + + $PAGE->print_header(get_string('course').': %fullname%', NULL, $meta, $bodytags); + // Course wrapper start. + echo '
'; + get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); @@ -135,16 +176,31 @@ } } - if (empty($course->modinfo)) { // Course cache was never made + + if (empty($course->modinfo)) { + // Course cache was never made. rebuild_course_cache($course->id); if (! $course = get_record('course', 'id', $course->id) ) { error("That's an invalid course id"); } } - require($CFG->dirroot .'/course/format/'. $course->format .'/format.php'); // Include the actual course format - echo '
'; // content wrapper end + // Include the actual course format. + require($CFG->dirroot .'/course/format/'. $course->format .'/format.php'); + // Content wrapper end. + echo '
'; + + + // Use AJAX? + if ($useajax) { + // At the bottom because we want to process sections and activities + // after the relevant html has been generated. + echo require_js(array('ajaxcourse_blocks', 'ajaxcourse_sections', 'ajaxcourse')); + $COURSE->javascriptportal->print_javascript($course->id); + } + + print_footer(NULL, $course); -?> +?> \ No newline at end of file diff --git a/lib/ajax/ajaxcourse.js b/lib/ajax/ajaxcourse.js index fd0a60262b5..d0d18c6d4a2 100644 --- a/lib/ajax/ajaxcourse.js +++ b/lib/ajax/ajaxcourse.js @@ -6,65 +6,65 @@ //hide content body until done loading (manipulation looks ugly elsewise) -document.getElementById('content').style.display = 'none'; +//document.getElementById('content').style.display = 'none'; -//onload object for handling scripts on page load, this insurses they run in my order +//onload object for handling scripts on page load, this insures they run in my order function onload_class() { this.scripts = new Array(); - this.debug = false; + this.debug = true; } onload_class.prototype.add = function(script) { - if(this.debug)YAHOO.log("onload.add - adding "+script, "junk"); + if (this.debug) { + YAHOO.log("onloadobj.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\n"; + $output .= "\n"; + if ($translatelist[$list[$i]] == '/lib/yui/logger/logger.js') { + // Special case. We need the css. + $output .= ""; + } } else { - echo "\n"; + $output .= "\n"; } } - /* - if (debugging('', DEBUG_DEVELOPER)) { - echo "\n"; - - // Dependencies for the logger. - echo ""; - - // FIXME: Below might get included more than once. - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - ?> - - blocks); $i++) { - $blocksoutput .= "['".$this->blocks[$i][0]."','".$this->blocks[$i][1]."','".$this->blocks[$i][2]."']"; - if ($i != (count($this->blocks)-1)) { + $blocksoutput .= "['".$this->blocks[$i][0]."', + '".$this->blocks[$i][1]."', + '".$this->blocks[$i][2]."']"; + + if ($i != (count($this->blocks) - 1)) { $blocksoutput .= ','; } } - $output .= ""; - echo $output; + if ($return) { + return $output; + } else { + echo $output; + } } -} +} ?> \ No newline at end of file diff --git a/lib/ajax/block_classes.js b/lib/ajax/block_classes.js index 02aec382cdb..d74e6e1c183 100644 --- a/lib/ajax/block_classes.js +++ b/lib/ajax/block_classes.js @@ -1,17 +1,17 @@ -/* +/** * library for ajaxcourse formats, the classes and related functions for drag and drop blocks * * this library requires a 'main' object created in calling document * - * $Id$ - * + * $Id$ */ - //set Drag and Drop to Intersect mode: - YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT; +//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){ diff --git a/lib/ajax/section_classes.js b/lib/ajax/section_classes.js index 7cd6db686c4..d2719c577ce 100755 --- a/lib/ajax/section_classes.js +++ b/lib/ajax/section_classes.js @@ -212,7 +212,7 @@ section_class.prototype.move_to_section = function(target) { //move on backend main.connect('post','class=section&field=move',null,'id='+this.sectionId+'&value=' - +(target.sectionId-this.sectionId)); + +(target.sectionId - this.sectionId)); //move on front end for (var i=loopStart; eval(loopCondition); eval(loopInc)) { @@ -375,14 +375,15 @@ section_class.prototype.insert_resource = function(el, targetel) { var tempStore = nextStore = null; //update in backend - targetId = ''; + var targetId = ''; if (targetel) { targetId = targetel.id; } - + if (this.debug) { + YAHOO.log('id='+el.id+', beforeId='+targetId+', sectionId='+this.sectionId); + } main.connect('post', 'class=resource&field=move', null, - 'id='+el.id+'&beforeId='+targetId - +'§ionId='+this.sectionId); + 'id='+el.id+'&beforeId='+targetId+'§ionId='+this.sectionId); //if inserting into a hidden resource hide if (this.hidden) { @@ -493,7 +494,7 @@ resource_class.prototype.init_resource = function(id, group, config, parentObj) resource_class.prototype.init_buttons = function() { var commandContainer = YAHOO.util.Dom.getElementsByClassName('commands', 'span', this.getEl())[0]; - if ( commandContainer == null) { + if (commandContainer == null) { YAHOO.log('Cannot find command container for '+this.getEl().id, 'error'); return; } @@ -588,7 +589,7 @@ resource_class.prototype.update_index = function(index) { } } -resource_class.prototype.startDrag = function(x, y) { +resource_class.prototype.startDrag = function(x, y) { YAHOO.util.DDM.mode = YAHOO.util.DDM.INTERSECT; //reinitialize dd element @@ -597,6 +598,11 @@ resource_class.prototype.startDrag = function(x, y) { var targets = YAHOO.util.DDM.getRelated(this, true); if (this.debug) { YAHOO.log(this.id + " startDrag "+targets.length + " targets"); + /* + for (var i=0; i