Skip to content

Commit

Permalink
MDL-46428 course: Remove confirm when duplicating
Browse files Browse the repository at this point in the history
A confirm dialog is given when Javascript is off but not when it is on.
This aligns the two so that they neither have a confirm when duplicating
an activity.
  • Loading branch information
Syxton committed Sep 4, 2014
1 parent 457f818 commit 60df678
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 105 deletions.
2 changes: 2 additions & 0 deletions course/format/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Overview of this plugin type at http://docs.moodle.org/dev/Course_formats
=== 2.8 ===
* The activity chooser now uses M.course.format.get_sectionwrapperclass()
to determine the section selector, rather than a hard-coded `li.section`.
* Activity duplication in /course/modduplicate.php is deprecated and is now done in /course/mod.php. Deprecated calls will be honored by
redirecting to /course/mod.php for 3rd party plugin support.

=== 2.7 ===
* The ->testedbrowsers array no longer needs to be defined in supports_ajax().
Expand Down
39 changes: 6 additions & 33 deletions course/mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,41 +79,16 @@
redirect("$CFG->wwwroot/course/modedit.php?update=$update&return=$returntomod&sr=$sectionreturn");

} else if (!empty($duplicate)) {
$cm = get_coursemodule_from_id('', $duplicate, 0, true, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_id('', $duplicate, 0, true, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);

require_login($course, false, $cm);
$coursecontext = context_course::instance($course->id);
$modcontext = context_module::instance($cm->id);
require_capability('moodle/course:manageactivities', $coursecontext);

if (!$confirm or !confirm_sesskey()) {
$PAGE->set_title(get_string('duplicate'));
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add(get_string('duplicatinga', 'core', format_string($cm->name)));
$PAGE->set_pagelayout('incourse');

$a = new stdClass();
$a->modtype = get_string('modulename', $cm->modname);
$a->modname = format_string($cm->name);
$a->modid = $cm->id;
require_capability('moodle/course:manageactivities', $modcontext);

echo $OUTPUT->header();
echo $OUTPUT->confirm(
get_string('duplicateconfirm', 'core', $a),
new single_button(
new moodle_url('/course/modduplicate.php', array(
'cmid' => $cm->id, 'course' => $course->id, 'sr' => $sectionreturn)),
get_string('continue'),
'post'),
new single_button(
course_get_url($course, $cm->sectionnum, array('sr' => $sectionreturn)),
get_string('cancel'),
'get')
);
echo $OUTPUT->footer();
die();
}
// Duplicate the module.
$newcm = duplicate_module($course, $cm);
redirect(course_get_url($course, $cm->sectionnum, array('sr' => $sectionreturn)));

} else if (!empty($delete)) {
$cm = get_coursemodule_from_id('', $delete, 0, true, MUST_EXIST);
Expand Down Expand Up @@ -298,5 +273,3 @@
} else {
print_error('unknowaction');
}


56 changes: 8 additions & 48 deletions course/modduplicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,61 +23,21 @@
*
* @package core
* @subpackage course
* @deprecated Moodle 2.8 MDL-46428 - Now redirects to mod.php.
* @copyright 2011 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(dirname(dirname(__FILE__)) . '/config.php');

$cmid = required_param('cmid', PARAM_INT);
$courseid = required_param('course', PARAM_INT);
$courseid = optional_param('course', PARAM_INT);
$sectionreturn = optional_param('sr', null, PARAM_INT);

$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$cm = get_coursemodule_from_id('', $cmid, $course->id, true, MUST_EXIST);
$cmcontext = context_module::instance($cm->id);
$context = context_course::instance($courseid);
$section = $DB->get_record('course_sections', array('id' => $cm->section, 'course' => $cm->course));
debugging('Please use moodle_url(\'/course/mod.php\', array(\'duplicate\' => $cmid
, \'id\' => $courseid, \'sesskey\' => sesskey(), \'sr\' => $sectionreturn)))
instead of new moodle_url(\'/course/modduplicate.php\', array(\'cmid\' => $cmid
, \'course\' => $courseid, \'sr\' => $sectionreturn))', DEBUG_DEVELOPER);

require_login($course);
require_sesskey();
require_capability('moodle/course:manageactivities', $context);
// Require both target import caps to be able to duplicate, see course_get_cm_edit_actions()
require_capability('moodle/backup:backuptargetimport', $context);
require_capability('moodle/restore:restoretargetimport', $context);

$PAGE->set_title(get_string('duplicate'));
$PAGE->set_heading($course->fullname);
$PAGE->set_url(new moodle_url('/course/modduplicate.php', array('cmid' => $cm->id, 'courseid' => $course->id)));
$PAGE->set_pagelayout('incourse');

$output = $PAGE->get_renderer('core', 'backup');

// Duplicate the module.
$newcm = duplicate_module($course, $cm);

echo $output->header();

$a = new stdClass();
$a->modtype = get_string('modulename', $cm->modname);
$a->modname = format_string($cm->name);

if (!empty($newcm)) {
echo $output->confirm(
get_string('duplicatesuccess', 'core', $a),
new single_button(
new moodle_url('/course/modedit.php', array('update' => $newcm->id, 'sr' => $sectionreturn)),
get_string('duplicatecontedit'),
'get'),
new single_button(
course_get_url($course, $cm->sectionnum, array('sr' => $sectionreturn)),
get_string('duplicatecontcourse'),
'get')
);

} else {
echo $output->notification(get_string('duplicatesuccess', 'core', $a), 'notifysuccess');
echo $output->continue_button(course_get_url($course, $cm->sectionnum, array('sr' => $sectionreturn)));
}

echo $output->footer();
redirect(new moodle_url('/course/mod.php', array('duplicate' => $cmid, 'id' => $courseid,
'sesskey' => sesskey(), 'sr' => $sectionreturn)));
34 changes: 15 additions & 19 deletions course/tests/behat/behat_course.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,6 @@ public function i_duplicate_activity($activityname) {
$steps[] = new Given('I open "' . $activity . '" actions menu');
}
$steps[] = new Given('I click on "' . get_string('duplicate') . '" "link" in the "' . $activity . '" activity');
if (!$this->running_javascript()) {
$steps[] = new Given('I press "' . get_string('continue') .'"');
$steps[] = new Given('I press "' . get_string('duplicatecontcourse') .'"');
}
return $steps;
}

Expand All @@ -752,35 +748,35 @@ public function i_duplicate_activity_editing_the_new_copy_with($activityname, Ta
$activity = $this->escape($activityname);
$activityliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($activityname);

if ($this->running_javascript()) {
$steps[] = new Given('I duplicate "' . $activity . '" activity');
$steps[] = new Given('I duplicate "' . $activity . '" activity');

// Determine the future new activity xpath from the former one.
$duplicatedxpath = "//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')]" .
"[contains(., $activityliteral)]/following-sibling::li";
$duplicatedactionsmenuxpath = $duplicatedxpath . "/descendant::a[@role='menuitem']";

if ($this->running_javascript()) {
// We wait until the AJAX request finishes and the section is visible again.
$hiddenlightboxxpath = "//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')][contains(., $activityliteral)]" .
$hiddenlightboxxpath = "//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')]" .
"[contains(., $activityliteral)]" .
"/ancestor::li[contains(concat(' ', normalize-space(@class), ' '), ' section ')]" .
"/descendant::div[contains(concat(' ', @class, ' '), ' lightbox ')][contains(@style, 'display: none')]";

$steps[] = new Given('I wait until the page is ready');
$steps[] = new Given('I wait until "' . $this->escape($hiddenlightboxxpath) .'" "xpath_element" exists');

// Close the original activity actions menu.
$steps[] = new Given('I close "' . $activity . '" actions menu');

// Determine the future new activity xpath from the former one.
$duplicatedxpath = "//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')][contains(., $activityliteral)]" .
"/following-sibling::li";
$duplicatedactionsmenuxpath = $duplicatedxpath . "/descendant::a[@role='menuitem']";

// The next sibling of the former activity will be the duplicated one, so we click on it from it's xpath as, at
// this point, it don't even exists in the DOM (the steps are executed when we return them).
$steps[] = new Given('I click on "' . $this->escape($duplicatedactionsmenuxpath) . '" "xpath_element"');

// We force the xpath as otherwise mink tries to interact with the former one.
$steps[] = new Given('I click on "' . get_string('editsettings') . '" "link" in the "' . $this->escape($duplicatedxpath) . '" "xpath_element"');
} else {
$steps[] = new Given('I click on "' . get_string('duplicate') . '" "link" in the "' . $activity . '" activity');
$steps[] = new Given('I press "' . get_string('continue') .'"');
$steps[] = new Given('I press "' . get_string('duplicatecontedit') . '"');
}

// We force the xpath as otherwise mink tries to interact with the former one.
$steps[] = new Given('I click on "' . get_string('editsettings') . '" "link" in the "' .
$this->escape($duplicatedxpath) . '" "xpath_element"');

$steps[] = new Given('I set the following fields to these values:', $data);
$steps[] = new Given('I press "' . get_string('savechangesandreturntocourse') . '"');
return $steps;
Expand Down
5 changes: 0 additions & 5 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,6 @@
$string['doyouagree'] = 'Have you read these conditions and understood them?';
$string['droptoupload'] = 'Drop files here to upload';
$string['duplicate'] = 'Duplicate';
$string['duplicateconfirm'] = 'Are you sure you want to duplicate {$a->modtype} \'{$a->modname}\' ?';
$string['duplicatecontcourse'] = 'Return to the course';
$string['duplicatecontedit'] = 'Edit the new copy';
$string['duplicatesuccess'] = '{$a->modtype} \'{$a->modname}\' has been duplicated successfully';
$string['duplicatinga'] = 'Duplicating: {$a}';
$string['edhelpaspellpath'] = 'To use spell-checking within the editor, you MUST have <strong>aspell 0.50</strong> or later installed on your server, and you must specify the correct path to access the aspell binary. On Unix/Linux systems, this path is usually <strong>/usr/bin/aspell</strong>, but it might be something else.';
$string['edhelpbgcolor'] = 'Define the edit area\'s background color.<br />Valid values are, for example: #FFFFFF or white';
$string['edhelpcleanword'] = 'This setting enables or disables Word-specific format filtering.';
Expand Down

0 comments on commit 60df678

Please sign in to comment.