]> git.mjollnir.org Git - moodle.git/commitdiff
Merged from 1.7.
authorvyshane <vyshane>
Tue, 17 Oct 2006 04:00:57 +0000 (04:00 +0000)
committervyshane <vyshane>
Tue, 17 Oct 2006 04:00:57 +0000 (04:00 +0000)
lib/ajax/section_classes.js

index 1616a00ad34814cecb58057fbb358ecab998cb80..b08bd8272d08e4e4122b129604ee212a2c8c929f 100755 (executable)
@@ -4,6 +4,14 @@
  *
  * This library requires a 'main' object created in calling document.
  *
+ * Drag and drop notes:
+ *
+ *   Dropping an activity or resource on a section will always add the activity
+ *   or resource at the end of that section.
+ *
+ *   Dropping an activity or resource on another activity or resource will
+ *   always move the former just above the latter.
+ *
  * $Id$
  */
 
@@ -128,19 +136,19 @@ section_class.prototype.process_section = function() {
         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;
 
     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");
+            if (this.debug) {
+                               YAHOO.log("Found resource");
+                       }
         } 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 || '';
 }
 
@@ -267,7 +275,7 @@ section_class.prototype.toggle_hide = function(e,target,superficial) {
             for (var x=0;x<this.resources.length;x++) {
                 this.resources[x].hiddenStored = this.resources[x].hidden;                                
                 this.resources[x].toggle_hide(null,null,true,true);
-            }             
+            }
         }
     }
 }
@@ -376,7 +384,6 @@ section_class.prototype.insert_resource = function(el, targetel) {
             el.hiddenStored = null;                
         }
     }
-
     //update model
     if (targetel == null) {
         this.resources[this.resources.length] = el;
@@ -401,7 +408,6 @@ section_class.prototype.insert_resource = function(el, targetel) {
             }                              
         }
        }
-       
     //update on frontend 
     if (targetel != null) { 
         this.resources_ul.insertBefore(el.getEl(),targetel.getEl());
@@ -568,11 +574,10 @@ resource_class.prototype.update_index = function(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 = '';
+       this.getDragEl().innerHTML = '';
 
     var targets = YAHOO.util.DDM.getRelated(this, true);
     if (this.debug) {
@@ -580,36 +585,54 @@ resource_class.prototype.startDrag = function(x, y) {
        }
 }
 
-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];
-               }
+resource_class.prototype.clear_move_markers = function(target) {
+       if (target.is == 'section') {
+               resources = target.resources;
+       } else {
+               resources = target.parentObj.resources;
+       }
+       for (var i=0; i<resources.length; i++) {
+               YAHOO.util.Dom.setStyle(resources[i].getEl().id, 'border', 'none');
        }
-    if (id.length == 0) {
-        id = ids;
+}
+
+resource_class.prototype.onDragOver = function(e, ids) {
+       var target = YAHOO.util.DDM.getBestMatch(ids);
+       
+       this.clear_move_markers(target);
+       
+       if (target != this && (target.is == 'resource' || target.is == 'activity')) {
+               // Add a top border to show where the drop will place the resource.
+               YAHOO.util.Dom.setStyle(target.getEl().id, 'border-top', '1px solid #BBB');
+       } else if (target.is == 'section' && target.resources.length > 0) {
+               // We need to have a border at the bottom of the last activity in
+               // that section.
+               YAHOO.util.Dom.setStyle(target.resources[target.resources.length - 1].getEl().id,
+                                                               'border-bottom', '1px solid #BBB');
        }
+}
 
-    // get the drag and drop object that was targeted
-    var target = YAHOO.util.DDM.getBestMatch(id);
+resource_class.prototype.onDragOut = function(e, ids) {
+       var target = YAHOO.util.DDM.getBestMatch(ids);
+       this.clear_move_markers(target);
+}
 
+resource_class.prototype.onDragDrop = function(e, ids) {
+       var target = YAHOO.util.DDM.getBestMatch(ids);
+       
     if (this.debug) {
                YAHOO.log("Dropped on section id="+target.sectionId
                                                +", el="+this.getEl().id
                                                +", x="+YAHOO.util.Dom.getXY( this.getDragEl() ));
        }
-/*     var oldid = this.parentObj.id;
-       this.previousId = oldid.replace(/section-/i, '');*/
     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);
+               target.insert_resource(this);
     }
+       this.clear_move_markers(target);
     return;
 }
 
@@ -618,28 +641,24 @@ resource_class.prototype.endDrag = function() {
 }
 
 
-
 /**
  * activity_class extends resource class
  */
-function activity_class(id,group,config,parentObj) {
-    this.init_activity(id,group,config,parentObj);
+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) {
+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.init_resource(id, group, config, parentObj);
     this.groupButton= null;
     this.init_activity_button();
 
@@ -648,7 +667,7 @@ activity_class.prototype.init_activity = function(id,group,config,parentObj) {
        }
 }
 
-activity_class.prototype.groupImages = ['/pix/t/groupn.gif','/pix/t/groups.gif','/pix/t/groupv.gif'];    
+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]); 
@@ -661,7 +680,6 @@ 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];
 
@@ -680,5 +698,5 @@ activity_class.prototype.toggle_group = function() {
        }
     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);
+    main.connect('post', 'class=resource&field=groupmode', null, 'value='+this.currentGroup+'&id='+this.id);
 }