Skip to content
Browse files

Updated front-end display to accurately represent how moodle is handl…

…ing things on the backend.
  • Loading branch information...
1 parent 305f223 commit 62cb40326050fff9e4daa149b80851637732d03d cap2501 committed
Showing with 63 additions and 39 deletions.
  1. +63 −39 lib/ajax/section-resource_classes.js
View
102 lib/ajax/section-resource_classes.js
@@ -73,30 +73,9 @@ section_class.prototype.init_buttons = function(){
YAHOO.util.Event.addListener(viewbutton,'click',this.toggle_hide,this,true);
commandContainer.appendChild(viewbutton);
this.viewButton = viewbutton;
-
-
- var deletebutton = main.mk_button('div','/pix/t/delete.gif');
- YAHOO.util.Event.addListener(deletebutton,'click',this.delete_button,this,true);
- commandContainer.appendChild(deletebutton);
-
-
+
}
-section_class.prototype.delete_button = function(){
- this.content_td.childNodes[0].data = '';
-
- if(this.hidden)
- this.toggle_hide();
-
- if(this.highlighted)
- this.toggle_highlight();
-
- if(this.debug)YAHOO.log('Deleting '+this.getEl().id);
-
- main.connect('delete','class=section&id='+this.id);
- for(var i=0;i<this.resources.length;i++)
- this.resources[i].delete_button();
- }
section_class.prototype.add_handle = function(){
var handleRef = main.mk_button('div','/pix/i/move_2d.gif',[['style','cursor:move']]);
@@ -213,6 +192,11 @@ section_class.prototype.move_to_section = function(target){
var loopmodifier = 'i+1';
}
+ //move on backend
+ main.connect('post','class=section&field=move',null,'id='+this.sectionId+'&value='+(target.sectionId-this.sectionId));
+
+
+ //move on front end
for(var i=loopStart;eval(loopCondition);eval(loopInc)){
if((main.sections[i] == this)&& !found){
@@ -234,7 +218,7 @@ section_class.prototype.move_to_section = function(target){
main.sections[i].swap_with_section(main.sections[eval(loopmodifier)]);
}
}
-
+
}
@@ -256,19 +240,32 @@ section_class.prototype.swap_with_section = function(sectionIn){
}
-section_class.prototype.toggle_hide = function(e,target,isCosmetic){
+section_class.prototype.toggle_hide = function(e,target,superficial){
if(this.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.hidden = false;
- if(!isCosmetic)main.connect('post','class=section&field=visible',null,'value=1&id='+this.sectionId);
+ if(!superficial){
+ main.connect('post','class=section&field=visible',null,'value=1&id='+this.sectionId);
+ for(var x=0;x<this.resources.length;x++){
+ this.resources[x].toggle_hide(null,null,true,this.resources[x].hiddenStored);
+ this.resources[x].hiddenStored = null;
+ }
+ }
+
}else{
YAHOO.util.Dom.addClass(this.getEl(),'hidden');
this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide.gif/i,'show.gif');
this.hidden = true;
- if(!isCosmetic)main.connect('post','class=section&field=visible',null,'value=0&id='+this.sectionId);
+ if(!superficial){
+ main.connect('post','class=section&field=visible',null,'value=0&id='+this.sectionId);
+ 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);
+ }
+ }
}
}
@@ -300,7 +297,7 @@ section_class.prototype.changeId = function(newId){
this.sectionId = newId;
this.numberDisplay.firstChild.data = newId;
- main.connectQueue_add('post','class=section&field=all',null,'id='+newId+"&summary="+main.mk_safe_for_transport(this.summary)+"&sequence="+this.write_sequence_list(true)+'&visible='+(this.hidden?0:1))
+ //main.connectQueue_add('post','class=section&field=all',null,'id='+newId+"&summary="+main.mk_safe_for_transport(this.summary)+"&sequence="+this.write_sequence_list(true)+'&visible='+(this.hidden?0:1))
if(main.marker == this)
main.update_marker(this);
@@ -357,6 +354,28 @@ section_class.prototype.insert_resource = function(el,targetel){
var found = false;
var tempStore = nextStore = null;
+ //update in backend
+ targetId='';
+ if(targetel !=null){
+ targetId=targetel.id;
+ }
+
+ main.connect('post','class=resource&field=move',null,'id='+el.id+'&beforeId='+targetId+'&sectionId='+this.sectionId);
+
+
+
+ //if inserting into a hidden resource hide
+ if(this.hidden){
+ el.hiddenStored = el.hidden;
+ el.toggle_hide(null,null,true,true);
+ }else{
+ if(el.hiddenStored != null){
+ el.toggle_hide(null,null,true,el.hiddenStored);
+ el.hiddenStored = null;
+ }
+ }
+
+ //update model
if(targetel == null){
this.resources[this.resources.length] = el;
}else
@@ -380,8 +399,7 @@ section_class.prototype.insert_resource = function(el,targetel){
}
}
-
- //YAHOO.log("Inserting "+el.getEl().id+" before "+targetel.getEl().id);
+ //update on frontend
if(targetel != null){
this.resources_ul.insertBefore(el.getEl(),targetel.getEl());
this.resources_ul.insertBefore(document.createTextNode(''),targetel.getEl());
@@ -390,10 +408,7 @@ section_class.prototype.insert_resource = function(el,targetel){
this.resources_ul.appendChild(el.getEl());
this.resources_ul.appendChild(document.createTextNode(" "));
}
- el.parentObj = this;
-
- this.write_sequence_list();
- main.connect('post','class=resource&field=section',null,'id='+el.id+'&value='+this.sectionId);
+ el.parentObj = this;
}
section_class.prototype.write_sequence_list = function(toReturn){
@@ -407,7 +422,6 @@ section_class.prototype.write_sequence_list = function(toReturn){
if(toReturn)
return listOutput;
- main.connect('post','class=section&field=sequence',null,'id='+this.sectionId+'&sequence='+listOutput);
}
@@ -441,6 +455,7 @@ resource_class.prototype.init_resource = function(id,group,config,parentObj){
this.hidden = false;
if(YAHOO.util.Dom.hasClass(this.getEl().getElementsByTagName('a')[0],'dimmed'))
this.hidden = true;
+ this.hiddenStored = null;
this.linkContainer = this.getEl().getElementsByTagName('a')[0];
@@ -505,19 +520,28 @@ resource_class.prototype.init_buttons = function(){
}
-resource_class.prototype.toggle_hide = function(){
+resource_class.prototype.toggle_hide = function(target,e,superficial,force){
+ if(force != null){
+ if(this.debug)YAHOO.log("Resource "+this.getEl().id+" forced to "+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');
- this.hidden = false;
-
- main.connect('post','class=resource&field=visible',null,'value=1&id='+this.id);
+ this.hidden = false;
+
+ if(!superficial){
+ main.connect('post','class=resource&field=visible',null,'value=1&id='+this.id);
+ }
}else{
YAHOO.util.Dom.addClass(this.linkContainer,'dimmed');
this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/hide.gif/i,'show.gif');
this.hidden = true;
- main.connect('post','class=resource&field=visible',null,'value=0&id='+this.id);
+ if(!superficial){
+ main.connect('post','class=resource&field=visible',null,'value=0&id='+this.id);
+ }
}
}

0 comments on commit 62cb403

Please sign in to comment.
Something went wrong with that request. Please try again.