]> git.mjollnir.org Git - moodle.git/commitdiff
Merged from 1.7.
authorvyshane <vyshane>
Mon, 20 Nov 2006 09:21:27 +0000 (09:21 +0000)
committervyshane <vyshane>
Mon, 20 Nov 2006 09:21:27 +0000 (09:21 +0000)
lib/ajax/ajaxlib.php
lib/ajax/section_classes.js

index b261f38dddf260ab0506ba51a088e6292e3e12a5..c21a79b6afbb191eca50f478ddcbdafc8dcbd70a 100644 (file)
@@ -108,7 +108,14 @@ class jsportal {
         $output .= "    main.portal.blocks = new Array(".$blocksoutput.");\n";
         $output .= "    main.portal.strings['wwwroot']='".$CFG->wwwroot."';\n";
         $output .= "    main.portal.strings['pixpath']='".$CFG->pixpath."';\n";
+        $output .= "    main.portal.strings['move']='".get_string('move')."';\n";
+        $output .= "    main.portal.strings['moveleft']='".get_string('moveleft')."';\n";
+        $output .= "    main.portal.strings['moveright']='".get_string('moveright')."';\n";
         $output .= "    main.portal.strings['update']='".get_string('update')."';\n";
+        $output .= "    main.portal.strings['groupsnone']='".get_string('groupsnone')."';\n";
+        $output .= "    main.portal.strings['groupsseparate']='".get_string('groupsseparate')."';\n";
+        $output .= "    main.portal.strings['groupsvisible']='".get_string('groupsvisible')."';\n";
+        $output .= "    main.portal.strings['clicktochange']='".get_string('clicktochange')."';\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";
index 13b5c9a16e0142fa943e99e77238f4ca4d13aa50..d7b60984617206724aa5e0134249ea69428c023b 100755 (executable)
@@ -83,6 +83,7 @@ section_class.prototype.init_buttons = function() {
 
     //clear all but show only button
     var commandContainerCount = commandContainer.childNodes.length;
+
     for (var i=(commandContainerCount-1); i>0; i--) {
         commandContainer.removeChild(commandContainer.childNodes[i])
     }
@@ -101,7 +102,9 @@ section_class.prototype.init_buttons = function() {
 
 
 section_class.prototype.add_handle = function() {
-    var handleRef = main.mk_button('a', '/i/move_2d.gif', [['style','cursor:move']]);
+    var handleRef = main.mk_button('a', '/i/move_2d.gif',
+                       [['style','cursor:move'], ['title', main.portal.strings['move']]]);
+
        YAHOO.util.Dom.generateId(handleRef, 'sectionHandle');
 
     this.handle = handleRef;
@@ -144,20 +147,13 @@ section_class.prototype.process_section = function() {
 
     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);
-            if (this.debug) {
-                               YAHOO.log("Found resource");
-                       }
-        } else {
-            this.resources[this.resources.length] = new activity_class(resource.id, 'resources', null, this);
-        }
+               this.resources[this.resources.length] = new resource_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) {   
+section_class.prototype.startDrag = function(x, y) {
     //operates in point mode
     YAHOO.util.DDM.mode = YAHOO.util.DDM.POINT;
 
@@ -316,8 +312,8 @@ section_class.prototype.toggle_highlight = function() {
 section_class.prototype.mk_marker = function() {
     if (main.marker != this) {
         main.update_marker(this);
-
-    } else {//if currently the marker
+    } else {
+               // If currently the marker
         main.marker = null;
 
         main.connect('POST', 'class=course&field=marker', null, 'value=0');
@@ -468,11 +464,11 @@ section_class.prototype.write_sequence_list = function(toReturn) {
 
 
 
+
 /**
  * resource_class extends util.DDProxy
  */
 function resource_class(id,group,config,parentObj) {
-
     this.init_resource(id,group,config,parentObj);
 }
 
@@ -487,6 +483,12 @@ resource_class.prototype.init_resource = function(id, group, config, parentObj)
         YAHOO.log("Init resource, NO ID FOUND!", 'error');
         return; 
     }
+
+       // Some constants.
+       this.NOGROUPS = 0;
+       this.SEPARATEGROUPS = 1;
+       this.VISIBLEGROUPS = 2;
+
     this.is = 'resource';  
     this.init(id, group, config);
     this.createFrame();     
@@ -500,14 +502,17 @@ resource_class.prototype.init_resource = function(id, group, config, parentObj)
        }
     this.hiddenStored = null;
 
+       this.groupmode = null;          // Can be null (i.e. does not apply), 0, 1 or 2.
+
     this.linkContainer = this.getEl().getElementsByTagName('a')[0];
 
     this.commandContainer = null;
     this.viewButton = null;
-    this.handle = null;        
+       this.groupButton = null;
+    this.handle = null;
     this.init_buttons();
 
-    this.parentObj = parentObj;        
+    this.parentObj = parentObj;
 
     if (this.debug) {
                YAHOO.log("init_resource "+id+" parent = "+parentObj.getEl().id);
@@ -515,48 +520,101 @@ resource_class.prototype.init_resource = function(id, group, config, parentObj)
 }
 
 
+/**
+ * The current strategy is to look at the DOM tree to get information on the
+ * resource and it's current mode. This is bad since we are dependant on
+ * the html that is output from serverside logic. Seemingly innocuous changes
+ * like changing the language string for the title of a button will break
+ * our JavaScript here. This is brittle.
+ *
+ * First, we clear the buttons container. Then:
+ *   We need to add the new-style move handle.
+ *   The old style move button (up/down) needs to be removed.
+ *   Move left button (if any) needs an event handler.
+ *   Move right button (if any) needs an event handler.
+ *   Update button stays as it is. Add it back.
+ *   Delete button needs an event handler.
+ *   Visible button is a toggle. It needs an event handler too.
+ *   Group mode button is a toggle. It needs an event handler too.
+ */
 resource_class.prototype.init_buttons = function() {
-    var  commandContainer = YAHOO.util.Dom.getElementsByClassName('commands', 'span', this.getEl())[0];
+
+       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;
     }
+
+       // Language strings.
+       var strgroupsnone = main.portal.strings['groupsnone']+' ('+main.portal.strings['clicktochange']+')';
+       var strgroupsseparate = main.portal.strings['groupsseparate']+' ('+main.portal.strings['clicktochange']+')';
+       var strgroupsvisible = main.portal.strings['groupsvisible']+' ('+main.portal.strings['clicktochange']+')';
+
     this.commandContainer = commandContainer;
+       var buttons = commandContainer.getElementsByTagName('a');
 
-    //find edit button
+    // Buttons that we might need to add back in.
+       var moveLeft = false;
+       var moveRight = false;
     var updateButton = null;
-    var buttons = commandContainer.getElementsByTagName('a');
 
     for (var x=0; x<buttons.length; x++) {
-        if (buttons[x].title == main.portal.strings['update']) {
+               if (buttons[x].title == main.portal.strings['moveleft']) {
+            moveLeft = true;
+        } else if (buttons[x].title == main.portal.strings['moveright']) {
+            moveRight = true;
+        } else if (buttons[x].title == main.portal.strings['update']) {
             updateButton = buttons[x].cloneNode(true);
-        }
+        } else if (buttons[x].title == strgroupsnone) {
+                       this.groupmode = this.NOGROUPS;
+               } else if (buttons[x].title == strgroupsseparate) {
+                       this.groupmode = this.SEPARATEGROUPS;
+               } else if (buttons[x].title == strgroupsvisible) {
+                       this.groupmode = this.VISIBLEGROUPS;
+               }
     }
 
     if (updateButton == null) {
+               // Update button must always be present.
         YAHOO.log('Cannot find updateButton for '+this.getEl().id, 'error');
        }
 
+       // Clear all the buttons.
     commandContainer.innerHTML = '';
 
-    //add move-handle
+    // Add move-handle for drag and drop.
     var handleRef = main.mk_button('a', '/i/move_2d.gif',
-                       [['style', 'cursor:move']], [['height', '11'], ['width', '11'],
-                       ['hspace', '2'], ['border', '0']]);
+                       [['style', 'cursor:move'], ['title', main.portal.strings['move']]],
+                       [['height', '11'], ['width', '11'], ['style', 'margin-right:3px; 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 indentation buttons if needed (move left, move right).
+       if (moveLeft) {
+               var button = main.mk_button('a', '/t/left.gif', [['title', main.portal.strings['moveleft']]]);
+               YAHOO.util.Event.addListener(button, 'click', this.move_left_button, this, true);
+               commandContainer.appendChild(button);
+       }
+       if (moveRight) {
+               var button = main.mk_button('a', '/t/right.gif', [['title', main.portal.strings['moveright']]]);
+               YAHOO.util.Event.addListener(button, 'click', this.move_right_button, this, true);
+               commandContainer.appendChild(button);
+       }
+
+    // Add edit button back in.
+    commandContainer.appendChild(updateButton);
 
-    //add rest
-    var button = main.mk_button('a', '/t/delete.gif');      
+    // Add the delete button.
+    var button = main.mk_button('a', '/t/delete.gif');
     YAHOO.util.Event.addListener(button, 'click', this.delete_button, this, true);
     commandContainer.appendChild(button);
 
+       // Add the hide or show button.
     if (this.hidden) {
         var button = main.mk_button('a', '/t/show.gif');
        } else {
@@ -565,6 +623,20 @@ resource_class.prototype.init_buttons = function() {
     YAHOO.util.Event.addListener(button, 'click', this.toggle_hide, this, true);
     commandContainer.appendChild(button);
     this.viewButton = button;
+
+       // Add the groupmode button if needed.
+       if (this.groupmode != null) {
+               if (this.groupmode == this.NOGROUPS) {
+                       var button = main.mk_button('a', '/t/groupn.gif', [['title', strgroupsnone]]);
+               } else if (this.groupmode == this.SEPARATEGROUPS) {
+                       var button = main.mk_button('a', '/t/groups.gif', [['title', strgroupsseparate]]);
+               } else {
+                       var button = main.mk_button('a', '/t/groupv.gif', [['title', strgroupsvisible]]);
+               }
+           YAHOO.util.Event.addListener(button, 'click', this.toggle_groupmode, this, true);
+           commandContainer.appendChild(button);
+               this.groupButton = button;
+       }
 }    
 
 
@@ -575,7 +647,6 @@ resource_class.prototype.toggle_hide = function(target, e, superficial, force) {
                }
         this.hidden = !force;           
     }
-
     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');
@@ -596,6 +667,19 @@ resource_class.prototype.toggle_hide = function(target, e, superficial, force) {
 }
 
 
+resource_class.prototype.groupImages = ['/t/groupn.gif', '/t/groups.gif', '/t/groupv.gif'];
+
+
+resource_class.prototype.toggle_groupmode = function() {
+    this.groupmode++;
+    if (this.groupmode > 2) {
+        this.groupmode = 0;
+       }
+    this.groupButton.getElementsByTagName('img')[0].src = main.portal.strings['pixpath']+this.groupImages[this.groupmode];
+    main.connect('POST', 'class=resource&field=groupmode', null, 'value='+this.groupmode+'&id='+this.id);
+}
+
+
 resource_class.prototype.delete_button = function() {
     if (this.debug) {
                YAHOO.log("Deleting "+this.getEl().id+" from parent "+this.parentObj.getEl().id);
@@ -693,69 +777,3 @@ resource_class.prototype.onDragDrop = function(e, ids) {YAHOO.log('onDragDrop');
 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) {
-    if (!id) { 
-        YAHOO.log("Init activity, NO ID FOUND!", 'error');
-        return; 
-    }    
-    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 = ['/t/groupn.gif', '/t/groups.gif', '/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) {
-        return;
-    }
-    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);
-}