Merged from 1.7

This commit is contained in:
vyshane 2006-10-24 08:11:38 +00:00
parent 8e9eebe629
commit 2469f7ea85
4 changed files with 92 additions and 100 deletions

View File

@ -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<scriptcount;i++) {
eval(this.scripts[i]);
if (this.debug) {
YAHOO.log("onloadobj.load - loading "+scriptcount+" scripts", "info");
}
for (i=0; i<scriptcount; i++) {
eval(this.scripts[i]);
}
}
var onload = new onload_class();
var onloadobj = new onload_class();
//main page object
function main_class() {
this.debug = true;
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('header');
this.rightcolumn = null;
this.adminBlock = null;
this.icons = [];
this.marker = null;
//things to process onload
onload.add('main.process_document();');
onload.add("document.getElementById('content').style.display='block';");
onloadobj.add('main.process_document();');
onloadobj.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 read)
//remove unneeded icons (old school position icons and delete/hide
//although they will be read)
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]);
@ -77,7 +77,7 @@ main_class.prototype.process_blocks = function() {
var blockcount = this.portal.blocks.length;
YAHOO.log("main.processBlocks - processing "+blockcount+" blocks", "info");
for (i=0;i<blockcount;i++) {
for (i=0; i<blockcount; i++) {
this.blocks[i] = new block_class(this.portal.blocks[i][1], "blocks");
//put in correct side array also
@ -96,7 +96,7 @@ main_class.prototype.process_blocks = function() {
main_class.prototype.process_document = function() {
//process the document to get important containers0
//process the document to get important containers
YAHOO.log("Processing Document", "info");
//process columns for blocks
@ -106,11 +106,13 @@ main_class.prototype.process_document = function() {
//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] = 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");
if (this.debug) {
YAHOO.log("Processed "+ct+" sections");
}
this.adminBlock = YAHOO.util.Dom.getElementsByClassName('block_adminblock')[0];
YAHOO.log("admin - "+this.adminBlock.className);
@ -166,7 +168,7 @@ main_class.prototype.mk_button = function(tag, imgSrc, attributes, imgAttributes
main_class.prototype.connect = function(method, urlStub, callback, body) {
if(this.debug) {
if (this.debug) {
YAHOO.log("Making "+method+" connection to /course/rest.php?courseId="+main.portal.id+"&"+urlStub);
}
if (callback == null) {
@ -211,7 +213,6 @@ main_class.prototype.update_marker = function(newMarker) {
if (this.marker != null) {
this.marker.toggle_highlight();
}
this.marker = newMarker;
this.marker.toggle_highlight();
@ -219,8 +220,8 @@ main_class.prototype.update_marker = function(newMarker) {
}
main_class.prototype.getString = function(title,variable) {
if(this.portal.strings[title]) {
main_class.prototype.getString = function(title, variable) {
if (this.portal.strings[title]) {
return this.portal.strings[title].replace(/_var_/, variable);
}
}
@ -232,6 +233,7 @@ var main = new main_class();
function php_portal_class() {
//portal to php data
this.id = null;
this.debug = null;
//array of id's of blocks set at end of page load by php
this.blocks = new Array();

View File

@ -5,8 +5,9 @@
* Takes in an array of either full paths or shortnames and it will translate
* them to full paths.
**/
function print_require_js($list) {
function require_js($list) {
global $CFG;
$output = '';
if (!check_browser_version('MSIE', 6.0) && !check_browser_version('Firefox', 1.5)) {
// We still have issues with YUI in other browsers.
@ -29,64 +30,33 @@ function print_require_js($list) {
for ($i=0; $i<count($list); $i++) {
if ($translatelist[$list[$i]]) {
echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist[$list[$i]]."'></script>\n";
$output .= "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist[$list[$i]]."'></script>\n";
if ($translatelist[$list[$i]] == '/lib/yui/logger/logger.js') {
// Special case. We need the css.
$output .= "<link type='text/css' rel='stylesheet' href='{$CFG->wwwroot}/lib/yui/logger/assets/logger.css'>";
}
} else {
echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$list[$i]."'></script>\n";
$output .= "<script type='text/javascript' src='".$CFG->wwwroot.''.$list[$i]."'></script>\n";
}
}
/*
if (debugging('', DEBUG_DEVELOPER)) {
echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist['yui_logger']."'></script>\n";
// Dependencies for the logger.
echo "<link type='text/css' rel='stylesheet' href='{$CFG->wwwroot}/lib/yui/logger/assets/logger.css'>";
// FIXME: Below might get included more than once.
echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist['yui_yahoo']."'></script>\n";
echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist['yui_dom']."'></script>\n";
echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist['yui_event']."'></script>\n";
echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist['yui_dragdrop']."'></script>\n";
?>
<script type="text/javascript">
function showLogger() {
var logcontainer = null;
var logconfig = {
left: "60%",
top: "40px"
};
var logreader = new YAHOO.widget.LogReader(logcontainer, logconfig);
logreader.newestOnTop = false;
logreader.setTitle('Moodle Debug: YUI Log Console');
}
setTimeout(showLogger, 1); // IE does not allow changing HTML
// tables via DOM until they are
// fully rendered.
</script>
<?php
}
*/
return $output;
}
/**
* Used to create view of document to be passed to javascript on pageload.
* Used to create view of document to be passed to JavaScript on pageload.
* We use this class to pass data from PHP to JavaScript.
*/
class jsportal {
var $currentblocksection = null;
var $blocks = array();
var $blocksoutput = '';
var $output = '';
/**
* Takes id of block and adds it
*/
function block_add($id, $hidden=false ){
function block_add($id, $hidden=false){
$hidden_binary = 0;
if ($hidden) {
@ -96,30 +66,39 @@ class jsportal {
}
function print_javascript($id) {
/**
* Prints the JavaScript code needed to set up AJAX for the course.
*/
function print_javascript($courseid, $return=false) {
global $CFG;
$blocksoutput = $output = '';
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 .= "['".$this->blocks[$i][0]."',
'".$this->blocks[$i][1]."',
'".$this->blocks[$i][2]."']";
if ($i != (count($this->blocks) - 1)) {
$blocksoutput .= ',';
}
}
$output .= "<script language='javascript'>\n";
$output .= " main.portal.id = ".$id.";\n";
$output .= " main.portal.blocks = new Array(".$blocksoutput.");\n";
$output .= " main.portal.strings['wwwroot']='".$CFG->wwwroot."';\n";
$output .= " main.portal.id = ".$courseid.";\n";
$output .= " main.portal.blocks = new Array(".$blocksoutput.");\n";
$output .= " main.portal.strings['wwwroot']='".$CFG->wwwroot."';\n";
$output .= " main.portal.strings['update']='".get_string('update')."';\n";
$output .= " main.portal.strings['deletecheck']='".get_string('deletecheck','','_var_')."';\n";
$output .= " main.portal.strings['resource']='".get_string('resource')."';\n";
$output .= " main.portal.strings['activity']='".get_string('activity')."';\n";
$output .= " onload.load();\n";
$output .= " main.portal.strings['deletecheck']='".get_string('deletecheck','','_var_')."';\n";
$output .= " main.portal.strings['resource']='".get_string('resource')."';\n";
$output .= " main.portal.strings['activity']='".get_string('activity')."';\n";
$output .= " onloadobj.load();\n";
$output .= " main.process_blocks();\n";
$output .= "</script>";
echo $output;
if ($return) {
return $output;
} else {
echo $output;
}
}
}
}
?>

View File

@ -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){

View File

@ -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
+'&sectionId='+this.sectionId);
'id='+el.id+'&beforeId='+targetId+'&sectionId='+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<targets.length; i++) {
YAHOO.log('target '+(i+1)+': '+targets[i].id);
}
*/
}
}
@ -629,12 +635,17 @@ resource_class.prototype.onDragOver = function(e, ids) {
resource_class.prototype.onDragOut = function(e, ids) {
var target = YAHOO.util.DDM.getBestMatch(ids);
this.clear_move_markers(target);
if (target) {
this.clear_move_markers(target);
}
}
resource_class.prototype.onDragDrop = function(e, ids) {
resource_class.prototype.onDragDrop = function(e, ids) {YAHOO.log('onDragDrop');
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
@ -668,7 +679,7 @@ 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');
YAHOO.log("Init activity, NO ID FOUND!", 'error');
return;
}
this.is = 'activity';