Moodle

After using AJAX to drag and drop a section, new activities are in wrong place

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.7
  • Fix Version/s: 1.7.1, 1.8
  • Component/s: AJAX
  • Labels:
    None
  • Environment:
    hosted on apache, windows 2k3, php 5.1.1, browser firefox 1.5.0.8
  • Affected Branches:
    MOODLE_17_STABLE
  • Fixed Branches:
    MOODLE_17_STABLE, MOODLE_18_STABLE

Description

First, I move a topic section in a topics format course to another location by drag and drop, then I create a new activity or resource in it, then i find that the new activity/resource is in the old location of the topic section.

Activity

Hide
Matt Gibson added a comment -

I should add that the server is using apache with mod_expires commands added to make it cache everything except text and html, so javascript is cached too. Not wise enough to know if this is relevant or not

Show
Matt Gibson added a comment - I should add that the server is using apache with mod_expires commands added to make it cache everything except text and html, so javascript is cached too. Not wise enough to know if this is relevant or not
Hide
Andrew Walker added a comment -

Hi,

I think this is because the select boxes that do the add resource/activity stuff contain things like the section number. The values in these forms relate to the sections as they are when the page is loaded. They don't get updated as the sections are dragged around the page. Hence if you dragged section 1 to section 10 and then tried to add a resource to it the form - which is now in section 10 - still thinks it's in section 1 (so when you create your resource that's where it gets put)

I think the easiest way to solve this (well certainly the way that uses least code ) may be to get the parent div of the select boxes in the two sections being swapped and swap these over too.

This could be done by modifying section_class.prototype.swap_with_section in lib/ajax/section_classes.js as follows

section_class.prototype.swap_with_section = function(sectionIn) {
var tmpStore = null;

thisIndex = main.get_section_index(this);
targetIndex = main.get_section_index(sectionIn);
main.sections[targetIndex] = this;
main.sections[thisIndex] = sectionIn;

this.changeId(targetIndex);
sectionIn.changeId(thisIndex);

if (this.debug) { YAHOO.log("Swapping "+this.getEl().id+" with "+sectionIn.getEl().id); }

YAHOO.util.DDM.swapNode(this.getEl(), sectionIn.getEl());
// swap the forms around so adding a resource/activity into a section that has moved still works
// question: are we always sure we'll have a form in the section or is it worth testing whether whatever.getEl().getElementsByTagName('form')[0] actually matches an element?
YAHOO.util.DDM.swapNode(this.getEl().getElementsByTagName('form')[0].parentNode, sectionIn.getEl().getElementsByTagName('form')[0].parentNode);
}

I'm not sure if there would be any performance issues with the extra DOM mangling this does? It seems to make things react fractionally slower here. Though my machine isn't massively powerful and even then the difference I'm seeing isn't really that noticable.

Comments?

Show
Andrew Walker added a comment - Hi, I think this is because the select boxes that do the add resource/activity stuff contain things like the section number. The values in these forms relate to the sections as they are when the page is loaded. They don't get updated as the sections are dragged around the page. Hence if you dragged section 1 to section 10 and then tried to add a resource to it the form - which is now in section 10 - still thinks it's in section 1 (so when you create your resource that's where it gets put) I think the easiest way to solve this (well certainly the way that uses least code ) may be to get the parent div of the select boxes in the two sections being swapped and swap these over too. This could be done by modifying section_class.prototype.swap_with_section in lib/ajax/section_classes.js as follows section_class.prototype.swap_with_section = function(sectionIn) { var tmpStore = null; thisIndex = main.get_section_index(this); targetIndex = main.get_section_index(sectionIn); main.sections[targetIndex] = this; main.sections[thisIndex] = sectionIn; this.changeId(targetIndex); sectionIn.changeId(thisIndex); if (this.debug) { YAHOO.log("Swapping "+this.getEl().id+" with "+sectionIn.getEl().id); } YAHOO.util.DDM.swapNode(this.getEl(), sectionIn.getEl()); // swap the forms around so adding a resource/activity into a section that has moved still works // question: are we always sure we'll have a form in the section or is it worth testing whether whatever.getEl().getElementsByTagName('form')[0] actually matches an element? YAHOO.util.DDM.swapNode(this.getEl().getElementsByTagName('form')[0].parentNode, sectionIn.getEl().getElementsByTagName('form')[0].parentNode); } I'm not sure if there would be any performance issues with the extra DOM mangling this does? It seems to make things react fractionally slower here. Though my machine isn't massively powerful and even then the difference I'm seeing isn't really that noticable. Comments?
Hide
Vy-Shane Sin Fat added a comment -

I don't notice any performance issues from here. I've checked in the fix. Thanks Andrew

Show
Vy-Shane Sin Fat added a comment - I don't notice any performance issues from here. I've checked in the fix. Thanks Andrew

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: