]> git.mjollnir.org Git - moodle.git/commitdiff
Further centralising of course AJAX and cleanup of code formatting, names etc
authormoodler <moodler>
Sat, 23 Sep 2006 14:03:48 +0000 (14:03 +0000)
committermoodler <moodler>
Sat, 23 Sep 2006 14:03:48 +0000 (14:03 +0000)
course/format/topics/ajaxcourse-topics.js [deleted file]
course/format/topics/format.php
lib/ajax/ajaxcourse.js [new file with mode: 0644]
lib/ajax/ajaxlib.php

diff --git a/course/format/topics/ajaxcourse-topics.js b/course/format/topics/ajaxcourse-topics.js
deleted file mode 100644 (file)
index 3a9ca55..0000000
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * 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('header'); 
-
-    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.strings['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/rest.php?courseId="+main.portal.id+"&"+urlStub);
-        if(callback == null){
-            callback = {}
-        }
-        return YAHOO.util.Connect.asyncRequest(method,this.portal.strings['wwwroot']+"/course/rest.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;
-
-       //strings    
-    this.strings = [];
-       
-    YAHOO.log("instantiated php_portal_class","info");
-}
-
-
-
-
index 7ad4215f9d9e1f22d894c959207ed462afcd3e02..1017d93faa6472730f617e0042869d77ef3d04a5 100644 (file)
@@ -70,7 +70,7 @@
             $COURSE->javascriptportal = new jsportal();
 
             print_require_js(array('yui_yahoo','yui_dom','yui_event','yui_dragdrop', 'yui_connection',
-                                   'ajaxcourse_blocks','ajaxcourse_sections','ajaxcourse_topic'));
+                                   'ajaxcourse_blocks','ajaxcourse_sections','ajaxcourse'));
             
             //javascript logging facilities
             if (debugging())  {
diff --git a/lib/ajax/ajaxcourse.js b/lib/ajax/ajaxcourse.js
new file mode 100644 (file)
index 0000000..88b5f71
--- /dev/null
@@ -0,0 +1,231 @@
+/*
+ * Contains Main class and supporting functions for topic ajax course layout
+ *
+ * $Id$
+ */
+
+
+//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('header'); 
+
+    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.strings['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/rest.php?courseId="+main.portal.id+"&"+urlStub);
+
+    if (callback == null) {
+        callback = {}
+    }
+    return YAHOO.util.Connect.asyncRequest(method,this.portal.strings['wwwroot']+"/course/rest.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;
+
+    //strings    
+    this.strings = [];
+
+    YAHOO.log("instantiated php_portal_class","info");
+}
index 7024f2edd76b2756709825d4d24daff1a2cb2823..608ff81dd054aa963d1ade20b3d6efc8edbd6d05 100644 (file)
@@ -1,80 +1,78 @@
-<?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.php",
-        "ajaxcourse_sections" => "/lib/ajax/section_classes.php",
-        "ajaxcourse_topic" => "/course/format/topics/ajaxcourse-topics.js",
-        "ajaxcourse_week" => "/course/format/weeks/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{
-    
+<?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.php',
+            'ajaxcourse_sections' => '/lib/ajax/section_classes.php',
+            'ajaxcourse' => '/lib/ajax/ajaxcourse.js'
+            );
+
+
+    for ($i=0;$i<count($list);$i++) {
+        if ($translatelist[$list[$i]]) {
+            echo "<script type='text/javascript' src='".$CFG->wwwroot.''.$translatelist[$list[$i]]."'></script>\n\r";
+        } else {
+            echo "<script 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 $blocks = array();
     var $blocksoutput = '';
     var $output = '';
 
-    
+
     //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);
+
+        if ($hidden) {
+            $hidden_binary = 1;
+        }
+
+        $this->blocks[count($this->blocks)] = array($this->currentblocksection,$id,$hidden_binary);
     }
-    
-        
+
+
     function print_javascript($id){
+        global $CFG;
+
         $blocksoutput = $output = '';
-        for($i=0;$i<count($this->blocks);$i++){
+        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))
+            if ($i != (count($this->blocks)-1)) {
                 $blocksoutput.=",";
-        }        
-        
-        global $CFG;       
+            }
+        }
+
         $output .="<script language='javascript'>\r";
         $output .="    main.portal.id = ".$id."\r";
         $output .="     main.portal.blocks = new Array(".$blocksoutput.");\r";        
         $output .="     main.portal.strings['wwwroot']='".$CFG->wwwroot."';\r";        
         $output .="     main.portal.strings['update']='".get_string('update')."';\r";  
         $output .="     onload.load()\r";
-        $output .="     main.process_blocks();\r";        
+        $output .="     main.process_blocks();\r";
         $output .="</script>";
         echo $output;
     }
-    
-   }   
-    
+}
+
 ?>