mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-24316 ajax course edit now works with orphaned activities
This commit is contained in:
parent
46b2346b57
commit
e8b32e2bfa
@ -62,6 +62,7 @@ function main_class() {
|
||||
this.courseformat = null;
|
||||
this.marker = null;
|
||||
this.numsections = null;
|
||||
this.lastsection = null; // real last section num including unavailable
|
||||
|
||||
//things to process onload
|
||||
onloadobj.add('main.process_document();');
|
||||
@ -118,11 +119,11 @@ main_class.prototype.process_document = function() {
|
||||
//process sections
|
||||
//var ct = 0;
|
||||
//while (document.getElementById('section-'+ct) != null) {
|
||||
var maxct = this.portal.numsections;
|
||||
this.courseformat = this.portal.courseformat;
|
||||
for(var ct=0; ct <= maxct; ct++){
|
||||
for(var ct=0; ct <= this.portal.lastsection; ct++){
|
||||
if (document.getElementById('section-'+ct) != null) {
|
||||
this.sections[ct] = new section_class('section-'+ct, "sections", null, ct!=0?true:false);
|
||||
var dragable = ((ct > 0) && (ct <= this.portal.numsections));
|
||||
this.sections[ct] = new section_class('section-'+ct, "sections", null, dragable);
|
||||
this.sections[ct].addToGroup('resources');
|
||||
if (ct > 0) {
|
||||
var sectiontitle = YAHOO.util.Selector.query('#section-'+ct+' h3.weekdates')[0];
|
||||
@ -130,6 +131,8 @@ main_class.prototype.process_document = function() {
|
||||
this.sectiondates[ct] = sectiontitle.innerHTML;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.sections[ct] = null;
|
||||
}
|
||||
//ct++;
|
||||
}
|
||||
@ -165,6 +168,7 @@ main_class.prototype.get_section_index = function(el) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
main_class.prototype.mk_button = function(tag, imgSrc, text, attributes, imgAttributes) {
|
||||
|
@ -118,7 +118,7 @@ class jsportal {
|
||||
* Prints the JavaScript code needed to set up AJAX for the course.
|
||||
*/
|
||||
function print_javascript($courseid, $return=false) {
|
||||
global $CFG, $USER, $OUTPUT, $COURSE;
|
||||
global $CFG, $USER, $OUTPUT, $COURSE, $DB;
|
||||
|
||||
$blocksoutput = $output = '';
|
||||
for ($i=0; $i<count($this->blocks); $i++) {
|
||||
@ -138,6 +138,7 @@ class jsportal {
|
||||
$output .= " main.portal.strings['marker']='".get_string('markthistopic', '', '_var_')."';\n";
|
||||
$output .= " main.portal.strings['marked']='".get_string('markedthistopic', '', '_var_')."';\n";
|
||||
$output .= " main.portal.numsections = ".$COURSE->numsections.";\n";
|
||||
$output .= " main.portal.lastsection = ".$DB->get_field_sql("SELECT MAX(section) FROM {course_sections} WHERE course = ?", array($courseid)).";\n"; // needed for orphaned activities in unavailable sections
|
||||
$output .= " main.portal.strings['hide']='".get_string('hide')."';\n";
|
||||
$output .= " main.portal.strings['hidesection']='".get_string('hidesection', '', '_var_')."';\n";
|
||||
$output .= " main.portal.strings['show']='".get_string('show')."';\n";
|
||||
|
@ -77,6 +77,11 @@ section_class.prototype.init_section = function(id, group, config, isDraggable)
|
||||
|
||||
|
||||
section_class.prototype.init_buttons = function() {
|
||||
if (this.sectionId > main.portal.numsections) {
|
||||
// no need to do anything in orphaned sections
|
||||
return;
|
||||
}
|
||||
|
||||
var commandContainer = YAHOO.util.Dom.getElementsByClassName('right',null,this.getEl())[0];
|
||||
|
||||
//clear all but show only button
|
||||
@ -150,7 +155,14 @@ section_class.prototype.process_section = function() {
|
||||
var resource = this.resources_ul.getElementsByTagName('li')[i];
|
||||
this.resources[this.resources.length] = new resource_class(resource.id, 'resources', null, this);
|
||||
}
|
||||
this.summary = YAHOO.util.Dom.getElementsByClassName('summary', null, this.getEl())[0].firstChild.data || '';
|
||||
|
||||
var sum = YAHOO.util.Dom.getElementsByClassName('summary', null, this.getEl());
|
||||
if (sum[0]) {
|
||||
this.summary = sum[0].firstChild.data || '';
|
||||
} else {
|
||||
// orphaned activities
|
||||
this.summary = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -205,6 +217,14 @@ section_class.prototype.move_to_section = function(target) {
|
||||
var oIndex = main.get_section_index(this);
|
||||
var tIndex = main.get_section_index(target);
|
||||
|
||||
if (oIndex == -1) {
|
||||
// source must exist
|
||||
return;
|
||||
}
|
||||
if (tIndex == -1) {
|
||||
// target must exist
|
||||
return;
|
||||
}
|
||||
if (this.debug) {
|
||||
YAHOO.log("original is at: "+oIndex+" target is at:"+tIndex+" of "+(sectionCount-1));
|
||||
}
|
||||
@ -257,8 +277,17 @@ section_class.prototype.move_to_section = function(target) {
|
||||
section_class.prototype.swap_with_section = function(sectionIn) {
|
||||
var tmpStore = null;
|
||||
|
||||
thisIndex = main.get_section_index(this);
|
||||
targetIndex = main.get_section_index(sectionIn);
|
||||
var thisIndex = main.get_section_index(this);
|
||||
var targetIndex = main.get_section_index(sectionIn);
|
||||
if (thisIndex == -1) {
|
||||
// source must exist
|
||||
return;
|
||||
}
|
||||
if (targetIndex == -1) {
|
||||
// target must exist
|
||||
return;
|
||||
}
|
||||
|
||||
main.sections[targetIndex] = this;
|
||||
main.sections[thisIndex] = sectionIn;
|
||||
|
||||
@ -286,6 +315,11 @@ section_class.prototype.swap_with_section = function(sectionIn) {
|
||||
|
||||
|
||||
section_class.prototype.toggle_hide = function(e,target,superficial) {
|
||||
if (this.sectionId > main.portal.numsections) {
|
||||
// no need to do anything in orphaned sections
|
||||
return;
|
||||
}
|
||||
|
||||
var strhide = main.portal.strings['hide'];
|
||||
var strshow = main.portal.strings['show'];
|
||||
if (this.hidden) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user