Merged from 1.7

This commit is contained in:
vyshane 2006-10-19 04:33:56 +00:00
parent ebf75284ee
commit 6f00683e98

View File

@ -80,7 +80,7 @@ section_class.prototype.init_section = function(id, group, config, isDraggable)
section_class.prototype.init_buttons = function() { section_class.prototype.init_buttons = function() {
var commandContainer = this.getEl().childNodes[2]; var commandContainer = this.getEl().childNodes[2];
//clear all but show only button //clear all but show only button
var commandContainerCount = commandContainer.childNodes.length; var commandContainerCount = commandContainer.childNodes.length;
for (var i=(commandContainerCount-1); i>0; i--) { for (var i=(commandContainerCount-1); i>0; i--) {
commandContainer.removeChild(commandContainer.childNodes[i]) commandContainer.removeChild(commandContainer.childNodes[i])
@ -131,7 +131,7 @@ section_class.prototype.process_section = function() {
//find/edit resources //find/edit resources
this.resources_ul = this.content_td.getElementsByTagName('ul')[0]; this.resources_ul = this.content_td.getElementsByTagName('ul')[0];
if (this.resources_ul == null) { if (!this.resources_ul) {
this.resources_ul = document.createElement('ul'); this.resources_ul = document.createElement('ul');
this.resources_ul.className='section'; this.resources_ul.className='section';
this.content_td.insertBefore(this.resources_ul, this.content_td.childNodes[1]); this.content_td.insertBefore(this.resources_ul, this.content_td.childNodes[1]);
@ -170,8 +170,9 @@ section_class.prototype.onDragDrop = function(e, id) {
// get the drag and drop object that was targeted // get the drag and drop object that was targeted
var target = YAHOO.util.DDM.getDDById(id); var target = YAHOO.util.DDM.getDDById(id);
if (this.debug)YAHOO.log("Section dropped on id="+id+" (I am "+this.getEl().id+") x="+YAHOO.util.Dom.getXY(this.getDragEl())); if (this.debug) {
YAHOO.log("Section dropped on id="+id+" (I am "+this.getEl().id+") x="+YAHOO.util.Dom.getXY(this.getDragEl()));
}
this.move_to_section(target); this.move_to_section(target);
//add back to resources group //add back to resources group
@ -191,43 +192,47 @@ section_class.prototype.move_to_section = function(target) {
var found = null; var found = null;
//determine if original is above or below target and adjust loop //determine if original is above or below target and adjust loop
var oIndex=main.get_section_index(this); var oIndex = main.get_section_index(this);
var tIndex=main.get_section_index(target); var tIndex = main.get_section_index(target);
if (this.debug)YAHOO.log("original is at: "+oIndex+" target is at:"+tIndex+" of "+(sectionCount-1));
if (this.debug) {
YAHOO.log("original is at: "+oIndex+" target is at:"+tIndex+" of "+(sectionCount-1));
}
if (oIndex < tIndex) { if (oIndex < tIndex) {
var loopCondition = 'i<sectionCount'; var loopCondition = 'i<sectionCount';
var loopStart = 1; var loopStart = 1;
var loopInc = 'i++'; var loopInc = 'i++';
var loopmodifier = 'i-1'; var loopmodifier = 'i - 1';
} else { } else {
var loopCondition = 'i>0'; var loopCondition = 'i > 0';
var loopStart = sectionCount-1; var loopStart = sectionCount - 1;
var loopInc = 'i--'; var loopInc = 'i--';
var loopmodifier = 'i+1'; var loopmodifier = 'i + 1';
} }
//move on backend //move on backend
main.connect('post','class=section&field=move',null,'id='+this.sectionId+'&value='+(target.sectionId-this.sectionId)); main.connect('post','class=section&field=move',null,'id='+this.sectionId+'&value='
+(target.sectionId-this.sectionId));
//move on front end //move on front end
for (var i=loopStart; eval(loopCondition); eval(loopInc)) { for (var i=loopStart; eval(loopCondition); eval(loopInc)) {
if ((main.sections[i] == this)&& !found) { if ((main.sections[i] == this) && !found) {
//enounter with original node //enounter with original node
if (this.debug)YAHOO.log("Found Original "+main.sections[i].getEl().id); if (this.debug) {
YAHOO.log("Found Original "+main.sections[i].getEl().id);
}
if (main.sections[i] == this) { if (main.sections[i] == this) {
found = true; found = true;
} }
} else if (main.sections[i] == target) { } else if (main.sections[i] == target) {
//encounter with target node //encounter with target node
if (this.debug)YAHOO.log("Found target "+main.sections[i].getEl().id); if (this.debug) {
YAHOO.log("Found target "+main.sections[i].getEl().id);
}
main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]); main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]);
found = false; found = false;
break; break;
} else if (found) { } else if (found) {
//encounter with nodes inbetween //encounter with nodes inbetween
main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]); main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]);
@ -246,35 +251,36 @@ section_class.prototype.swap_with_section = function(sectionIn) {
this.changeId(targetIndex); this.changeId(targetIndex);
sectionIn.changeId(thisIndex); sectionIn.changeId(thisIndex);
if (this.debug)YAHOO.log("Swapping "+this.getEl().id+" with "+sectionIn.getEl().id); if (this.debug) {
YAHOO.log("Swapping "+this.getEl().id+" with "+sectionIn.getEl().id);
}
YAHOO.util.DDM.swapNode(this.getEl(), sectionIn.getEl()); YAHOO.util.DDM.swapNode(this.getEl(), sectionIn.getEl());
} }
section_class.prototype.toggle_hide = function(e,target,superficial) { section_class.prototype.toggle_hide = function(e,target,superficial) {
if (this.hidden) { if (this.hidden) {
YAHOO.util.Dom.removeClass(this.getEl(),'hidden'); YAHOO.util.Dom.removeClass(this.getEl(), 'hidden');
this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show.gif/i,'hide.gif'); this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show.gif/i, 'hide.gif');
this.hidden = false; this.hidden = false;
if (!superficial) { if (!superficial) {
main.connect('post','class=section&field=visible',null,'value=1&id='+this.sectionId); main.connect('post', 'class=section&field=visible', null, 'value=1&id='+this.sectionId);
for (var x=0;x<this.resources.length;x++) { for (var x=0; x<this.resources.length; x++) {
this.resources[x].toggle_hide(null,null,true,this.resources[x].hiddenStored); this.resources[x].toggle_hide(null, null, true, this.resources[x].hiddenStored);
this.resources[x].hiddenStored = null; this.resources[x].hiddenStored = null;
} }
} }
} else { } else {
YAHOO.util.Dom.addClass(this.getEl(),'hidden'); YAHOO.util.Dom.addClass(this.getEl(), 'hidden');
this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide.gif/i,'show.gif'); this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide.gif/i, 'show.gif');
this.hidden = true; this.hidden = true;
if (!superficial) { if (!superficial) {
main.connect('post','class=section&field=visible',null,'value=0&id='+this.sectionId); main.connect('post', 'class=section&field=visible', null, 'value=0&id='+this.sectionId);
for (var x=0;x<this.resources.length;x++) { for (var x=0; x<this.resources.length; x++) {
this.resources[x].hiddenStored = this.resources[x].hidden; this.resources[x].hiddenStored = this.resources[x].hidden;
this.resources[x].toggle_hide(null,null,true,true); this.resources[x].toggle_hide(null, null, true, true);
} }
} }
} }
@ -282,10 +288,10 @@ section_class.prototype.toggle_hide = function(e,target,superficial) {
section_class.prototype.toggle_highlight = function() { section_class.prototype.toggle_highlight = function() {
if (this.highlighted) { if (this.highlighted) {
YAHOO.util.Dom.removeClass(this.getEl(),'current'); YAHOO.util.Dom.removeClass(this.getEl(), 'current');
this.highlighted = false; this.highlighted = false;
} else { } else {
YAHOO.util.Dom.addClass(this.getEl(),'current'); YAHOO.util.Dom.addClass(this.getEl(), 'current');
this.highlighted = true; this.highlighted = true;
} }
} }
@ -297,7 +303,7 @@ section_class.prototype.mk_marker = function() {
} else {//if currently the marker } else {//if currently the marker
main.marker = null; main.marker = null;
main.connect('post','class=course&field=marker',null,'value=0'); main.connect('post', 'class=course&field=marker', null, 'value=0');
this.toggle_highlight(); this.toggle_highlight();
} }
} }
@ -314,12 +320,12 @@ section_class.prototype.changeId = function(newId) {
} }
section_class.prototype.get_resource_index = function(el) { section_class.prototype.get_resource_index = function(el) {
for (var x=0;x<this.resources.length;x++) { for (var x=0; x<this.resources.length; x++) {
if (this.resources[x]==el) { if (this.resources[x] == el) {
return x; return x;
} }
} }
YAHOO.log("Could not find resource to remove "+el.getEl().id,"error"); YAHOO.log("Could not find resource to remove "+el.getEl().id, "error");
return -1; return -1;
} }
@ -327,19 +333,20 @@ section_class.prototype.remove_resource = function(el) {
var resourceCount = this.resources.length; var resourceCount = this.resources.length;
if (resourceCount == 1) { if (resourceCount == 1) {
if (this.resources[0] == el) if (this.resources[0] == el) {
this.resources = new Array(); this.resources = new Array();
}
} else { } else {
var found = false; var found = false;
for (var i=0;i<resourceCount;i++) { for (var i=0; i<resourceCount; i++) {
if (found) { if (found) {
this.resources[i-1] = this.resources[i]; this.resources[i - 1] = this.resources[i];
if (i==resourceCount-1) { if (i == resourceCount - 1) {
this.resources = this.resources.slice(0,-1); this.resources = this.resources.slice(0, -1);
resourceCount--; resourceCount--;
} }
this.resources[i-1].update_index(i-1); this.resources[i - 1].update_index(i - 1);
} else if (this.resources[i]==el) { } else if (this.resources[i] == el) {
found = true; found = true;
} }
} }
@ -347,15 +354,18 @@ section_class.prototype.remove_resource = function(el) {
//remove "text" nodes to keep DOM clean //remove "text" nodes to keep DOM clean
var childIndex = null; var childIndex = null;
var childrenCount = this.resources_ul.childNodes.length; var childrenCount = this.resources_ul.childNodes.length;
for (var i=0;i<childrenCount;i++) for (var i=0; i<childrenCount; i++) {
if (this.resources_ul.childNodes[i] == el.getEl()) if (this.resources_ul.childNodes[i] == el.getEl()) {
childIndex = i; childIndex = i;
if (childIndex > 0 && childIndex < this.resources_ul.childNodes.length) }
this.resources_ul.removeChild(this.resources_ul.childNodes[childIndex-1]); }
YAHOO.log("removing "+el.getEl().id); if (childIndex > 0 && childIndex < this.resources_ul.childNodes.length) {
if (el.getEl().parentNode != null) this.resources_ul.removeChild(this.resources_ul.childNodes[childIndex - 1]);
el.getEl().parentNode.removeChild(el.getEl()); }
YAHOO.log("Removing "+el.getEl().id);
if (el.getEl().parentNode != null) {
el.getEl().parentNode.removeChild(el.getEl());
}
this.write_sequence_list(); this.write_sequence_list();
} }
@ -366,7 +376,7 @@ section_class.prototype.insert_resource = function(el, targetel) {
//update in backend //update in backend
targetId = ''; targetId = '';
if (targetel != null) { if (targetel) {
targetId = targetel.id; targetId = targetel.id;
} }
@ -377,23 +387,23 @@ section_class.prototype.insert_resource = function(el, targetel) {
//if inserting into a hidden resource hide //if inserting into a hidden resource hide
if (this.hidden) { if (this.hidden) {
el.hiddenStored = el.hidden; el.hiddenStored = el.hidden;
el.toggle_hide(null,null,true,true); el.toggle_hide(null, null, true, true);
} else { } else {
if (el.hiddenStored != null) { if (el.hiddenStored != null) {
el.toggle_hide(null,null,true,el.hiddenStored); el.toggle_hide(null, null, true, el.hiddenStored);
el.hiddenStored = null; el.hiddenStored = null;
} }
} }
//update model //update model
if (targetel == null) { if (!targetel) {
this.resources[this.resources.length] = el; this.resources[this.resources.length] = el;
} else { } else {
for (var i=0;i<resourcecount;i++) { for (var i=0; i<resourcecount; i++) {
if (found) { if (found) {
tempStore = this.resources[i]; tempStore = this.resources[i];
this.resources[i] = nextStore; this.resources[i] = nextStore;
nextStore = tempStore; nextStore = tempStore;
if (nextStore != null) if (nextStore != null)
nextStore.update_index(i+1); nextStore.update_index(i+1);
@ -403,18 +413,18 @@ section_class.prototype.insert_resource = function(el, targetel) {
this.resources[i] = el; this.resources[i] = el;
resourcecount++; resourcecount++;
this.resources[i].update_index(i,this.ident); this.resources[i].update_index(i, this.ident);
nextStore.update_index(i+1); nextStore.update_index(i + 1);
} }
} }
} }
//update on frontend //update on frontend
if (targetel != null) { if (targetel) {
this.resources_ul.insertBefore(el.getEl(),targetel.getEl()); this.resources_ul.insertBefore(el.getEl(), targetel.getEl());
this.resources_ul.insertBefore(document.createTextNode(''),targetel.getEl()); this.resources_ul.insertBefore(document.createTextNode(' '), targetel.getEl());
} else { } else {
this.resources_ul.appendChild(el.getEl()); this.resources_ul.appendChild(el.getEl());
this.resources_ul.appendChild(document.createTextNode(" ")); this.resources_ul.appendChild(document.createTextNode(' '));
} }
el.parentObj = this; el.parentObj = this;
} }
@ -422,7 +432,7 @@ section_class.prototype.insert_resource = function(el, targetel) {
section_class.prototype.write_sequence_list = function(toReturn) { section_class.prototype.write_sequence_list = function(toReturn) {
var listOutput = ''; var listOutput = '';
for (var i=0;i<this.resources.length;i++) { for (var i=0; i<this.resources.length; i++) {
listOutput += this.resources[i].id; listOutput += this.resources[i].id;
if (i != (this.resources.length-1)) { if (i != (this.resources.length-1)) {
listOutput += ','; listOutput += ',';
@ -449,20 +459,20 @@ YAHOO.extend(resource_class, YAHOO.util.DDProxy);
resource_class.prototype.debug = false; resource_class.prototype.debug = false;
resource_class.prototype.init_resource = function(id,group,config,parentObj) { resource_class.prototype.init_resource = function(id, group, config, parentObj) {
if (!id) { if (!id) {
YAHOO.log("Init resource, NO ID FOUND!",'error'); YAHOO.log("Init resource, NO ID FOUND!", 'error');
return; return;
} }
this.is = 'resource'; this.is = 'resource';
this.init(id,group,config); this.init(id, group, config);
this.createFrame(); this.createFrame();
this.isTarget = true; this.isTarget = true;
this.id = this.getEl().id.replace(/module-/i,''); this.id = this.getEl().id.replace(/module-/i, '');
this.hidden = false; this.hidden = false;
if (YAHOO.util.Dom.hasClass(this.getEl().getElementsByTagName('a')[0],'dimmed')) { if (YAHOO.util.Dom.hasClass(this.getEl().getElementsByTagName('a')[0], 'dimmed')) {
this.hidden = true; this.hidden = true;
} }
this.hiddenStored = null; this.hiddenStored = null;
@ -482,31 +492,34 @@ resource_class.prototype.init_resource = function(id,group,config,parentObj) {
} }
resource_class.prototype.init_buttons = function() { 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) { if ( commandContainer == null) {
YAHOO.log('Cannot find command container for '+this.getEl().id,'error'); YAHOO.log('Cannot find command container for '+this.getEl().id, 'error');
return; return;
} }
this.commandContainer = commandContainer; this.commandContainer = commandContainer;
//find edit button //find edit button
var updateButton = null; var updateButton = null;
var buttons = commandContainer.getElementsByTagName('a'); var buttons = commandContainer.getElementsByTagName('a');
for (var x=0;x<buttons.length;x++) { for (var x=0; x<buttons.length; x++) {
if (buttons[x].title == main.portal.strings['update']) { if (buttons[x].title == main.portal.strings['update']) {
updateButton = buttons[x]; updateButton = buttons[x];
} }
} }
if (updateButton == null) if (updateButton == null)
YAHOO.log('Cannot find updateButton for '+this.getEl().id,'error'); YAHOO.log('Cannot find updateButton for '+this.getEl().id, 'error');
commandContainer.innerHTML = ''; commandContainer.innerHTML = '';
//add move-handle //add move-handle
var handleRef = main.mk_button('a','/pix/i/move_2d.gif',[['style','cursor:move']],[['height','11'],['width','11'],['hspace','2'],['border','0']]); var handleRef = main.mk_button('a', '/pix/i/move_2d.gif',
YAHOO.util.Dom.generateId(handleRef,'sectionHandle'); [['style', 'cursor:move']], [['height', '11'], ['width', '11'],
['hspace', '2'], ['border', '0']]);
YAHOO.util.Dom.generateId(handleRef, 'sectionHandle');
this.handle = handleRef; this.handle = handleRef;
commandContainer.appendChild(handleRef); commandContainer.appendChild(handleRef);
this.setHandleElId(this.handle.id); this.setHandleElId(this.handle.id);
@ -515,61 +528,63 @@ resource_class.prototype.init_buttons = function() {
commandContainer.appendChild(updateButton); commandContainer.appendChild(updateButton);
//add rest //add rest
var button = main.mk_button('a','/pix/t/delete.gif'); var button = main.mk_button('a', '/pix/t/delete.gif');
YAHOO.util.Event.addListener(button,'click',this.delete_button,this,true); YAHOO.util.Event.addListener(button, 'click', this.delete_button, this, true);
commandContainer.appendChild(button); commandContainer.appendChild(button);
if (this.hidden) { if (this.hidden) {
var button = main.mk_button('a','/pix/t/show.gif'); var button = main.mk_button('a', '/pix/t/show.gif');
} else { } else {
var button = main.mk_button('a','/pix/t/hide.gif'); var button = main.mk_button('a', '/pix/t/hide.gif');
} }
YAHOO.util.Event.addListener(button,'click',this.toggle_hide,this,true); YAHOO.util.Event.addListener(button, 'click', this.toggle_hide, this, true);
commandContainer.appendChild(button); commandContainer.appendChild(button);
this.viewButton = button; this.viewButton = button;
} }
resource_class.prototype.toggle_hide = function(target,e,superficial,force) { resource_class.prototype.toggle_hide = function(target, e, superficial, force) {
if (force != null) { if (force != null) {
if (this.debug)YAHOO.log("Resource "+this.getEl().id+" forced to "+force); if (this.debug) {
YAHOO.log("Resource "+this.getEl().id+" forced to "+force);
}
this.hidden = !force; this.hidden = !force;
} }
if (this.hidden) { if (this.hidden) {
YAHOO.util.Dom.removeClass(this.linkContainer,'dimmed'); YAHOO.util.Dom.removeClass(this.linkContainer, 'dimmed');
this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show.gif/i,'hide.gif'); this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/show.gif/i, 'hide.gif');
this.hidden = false; this.hidden = false;
if (!superficial) { if (!superficial) {
main.connect('post','class=resource&field=visible',null,'value=1&id='+this.id); main.connect('post', 'class=resource&field=visible', null, 'value=1&id='+this.id);
} }
} else { } else {
YAHOO.util.Dom.addClass(this.linkContainer,'dimmed'); YAHOO.util.Dom.addClass(this.linkContainer, 'dimmed');
this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide.gif/i,'show.gif'); this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide.gif/i, 'show.gif');
this.hidden = true; this.hidden = true;
if (!superficial) { if (!superficial) {
main.connect('post','class=resource&field=visible',null,'value=0&id='+this.id); main.connect('post', 'class=resource&field=visible', null, 'value=0&id='+this.id);
} }
} }
} }
resource_class.prototype.delete_button = function() { resource_class.prototype.delete_button = function() {
if (this.debug) { if (this.debug) {
YAHOO.log("Deleting "+this.getEl().id+"from parent "+this.parentObj.getEl().id); YAHOO.log("Deleting "+this.getEl().id+" from parent "+this.parentObj.getEl().id);
} }
if (!confirm(main.getString('deletecheck',main.getString(this.is)+" "+this.id))) { if (!confirm(main.getString('deletecheck', main.getString(this.is)+" "+this.id))) {
return false; return false;
} }
this.getEl().parentNode.removeChild(this.getEl()); this.getEl().parentNode.removeChild(this.getEl());
this.parentObj.remove_resource(this); this.parentObj.remove_resource(this);
main.connect('delete','class=resource&id='+this.id); main.connect('delete', 'class=resource&id='+this.id);
} }
resource_class.prototype.update_index = function(index) { resource_class.prototype.update_index = function(index) {
if (this.debug) { if (this.debug) {
YAHOO.log("update Index for resource "+this.getEl().id+"to"+index); YAHOO.log("Updating Index for resource "+this.getEl().id+" to "+index);
} }
} }