From cac8708d0b8543df200a37dd5b75ac8d14aedb93 Mon Sep 17 00:00:00 2001 From: Gareth J Barnard Date: Mon, 11 Feb 2013 14:07:35 +0000 Subject: [PATCH] MDL_34798 format_topics and format_weeks: Adjust section names when moving up. --- course/format/topics/format.js | 10 ++++++++-- course/format/weeks/format.js | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/course/format/topics/format.js b/course/format/topics/format.js index 71e87972308..172d1d9e9c5 100644 --- a/course/format/topics/format.js +++ b/course/format/topics/format.js @@ -40,7 +40,7 @@ M.course.format.swap_sections = function(Y, node1, node2) { }; var sectionlist = Y.Node.all('.'+CSS.COURSECONTENT+' '+M.course.format.get_section_selector(Y)); - // Swap menus + // Swap menus. sectionlist.item(node1).one('.'+CSS.SECTIONADDMENUS).swap(sectionlist.item(node2).one('.'+CSS.SECTIONADDMENUS)); } @@ -59,7 +59,13 @@ M.course.format.process_sections = function(Y, sectionlist, response, sectionfro }; if (response.action == 'move') { - // update titles in all affected sections + // If moving up swap around 'sectionfrom' and 'sectionto' so the that loop operates. + if (sectionfrom > sectionto) { + var temp = sectionto; + sectionto = sectionfrom; + sectionfrom = temp; + } + // Update titles in all affected sections. for (var i = sectionfrom; i <= sectionto; i++) { sectionlist.item(i).one('.'+CSS.SECTIONNAME).setContent(response.sectiontitles[i]); } diff --git a/course/format/weeks/format.js b/course/format/weeks/format.js index 28ec82a2b4f..64337026d43 100644 --- a/course/format/weeks/format.js +++ b/course/format/weeks/format.js @@ -40,7 +40,7 @@ M.course.format.swap_sections = function(Y, node1, node2) { }; var sectionlist = Y.Node.all('.'+CSS.COURSECONTENT+' '+M.course.format.get_section_selector(Y)); - // Swap menus + // Swap menus. sectionlist.item(node1).one('.'+CSS.SECTIONADDMENUS).swap(sectionlist.item(node2).one('.'+CSS.SECTIONADDMENUS)); } @@ -59,7 +59,13 @@ M.course.format.process_sections = function(Y, sectionlist, response, sectionfro }; if (response.action == 'move') { - // update titles in all affected sections + // If moving up swap around 'sectionfrom' and 'sectionto' so the that loop operates. + if (sectionfrom > sectionto) { + var temp = sectionto; + sectionto = sectionfrom; + sectionfrom = temp; + } + // Update titles in all affected sections. for (var i = sectionfrom; i <= sectionto; i++) { sectionlist.item(i).one('.'+CSS.SECTIONNAME).setContent(response.sectiontitles[i]); }