*
* 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$
*/
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 || '';
}
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);
- }
+ }
}
}
}
el.hiddenStored = null;
}
}
-
//update model
if (targetel == null) {
this.resources[this.resources.length] = el;
}
}
}
-
//update on frontend
if (targetel != null) {
this.resources_ul.insertBefore(el.getEl(),targetel.getEl());
}
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) {
}
}
-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;
}
}
-
/**
* 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();
}
}
-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]);
if (document.getElementById(id) == null) {
return;
}
-
var groupNodeArray = document.getElementById(id).getElementsByTagName('a');
var groupNode = groupNodeArray[groupNodeArray.length-1];
}
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);
}