Keep action links consistent

This commit is contained in:
Mark Nelson 2016-02-20 17:12:32 +08:00
parent 43d20c0d1b
commit d848bc73e8
2 changed files with 60 additions and 58 deletions

View file

@ -197,12 +197,12 @@ class edit_form extends \moodleform {
// Place the ordering arrows. // Place the ordering arrows.
// Only display the move up arrow if it is not the first. // Only display the move up arrow if it is not the first.
if ($page->pagenumber > 1) { if ($page->pagenumber > 1) {
$url = new \moodle_url($editlink, $editlinkparams + array('moveup' => $page->id)); $url = new \moodle_url($editlink, $editlinkparams + array('action' => 'pmoveup', 'aid' => $page->id));
$mform->addElement('html', $OUTPUT->action_icon($url, new \pix_icon('t/up', get_string('moveup')))); $mform->addElement('html', $OUTPUT->action_icon($url, new \pix_icon('t/up', get_string('moveup'))));
} }
// Only display the move down arrow if it is not the last. // Only display the move down arrow if it is not the last.
if ($page->pagenumber < $this->numpages) { if ($page->pagenumber < $this->numpages) {
$url = new \moodle_url($editlink, $editlinkparams + array('movedown' => $page->id)); $url = new \moodle_url($editlink, $editlinkparams + array('action' => 'pmovedown', 'aid' => $page->id));
$mform->addElement('html', $OUTPUT->action_icon($url, new \pix_icon('t/down', get_string('movedown')))); $mform->addElement('html', $OUTPUT->action_icon($url, new \pix_icon('t/down', get_string('movedown'))));
} }
@ -256,20 +256,22 @@ class edit_form extends \moodleform {
'action' => 'edit')); 'action' => 'edit'));
$icons = $OUTPUT->action_icon($link, new \pix_icon('t/edit', get_string('edit'))); $icons = $OUTPUT->action_icon($link, new \pix_icon('t/edit', get_string('edit')));
// Link to delete the element. // Link to delete the element.
$link = new \moodle_url($editlink, $editlinkparams + array('id' => $element->id, $link = new \moodle_url($editlink, $editlinkparams + array('action' => 'deleteelement',
'deleteelement' => $element->id)); 'aid' => $element->id));
$icons .= $OUTPUT->action_icon($link, new \pix_icon('t/delete', get_string('delete'))); $icons .= $OUTPUT->action_icon($link, new \pix_icon('t/delete', get_string('delete')));
// Now display any moving arrows if they are needed. // Now display any moving arrows if they are needed.
if ($numelements > 1) { if ($numelements > 1) {
// Only display the move up arrow if it is not the first. // Only display the move up arrow if it is not the first.
$moveicons = ''; $moveicons = '';
if ($element->sequence > 1) { if ($element->sequence > 1) {
$url = new \moodle_url($editlink, $editlinkparams + array('emoveup' => $element->id)); $url = new \moodle_url($editlink, $editlinkparams + array('action' => 'emoveup',
'aid' => $element->id));
$moveicons .= $OUTPUT->action_icon($url, new \pix_icon('t/up', get_string('moveup'))); $moveicons .= $OUTPUT->action_icon($url, new \pix_icon('t/up', get_string('moveup')));
} }
// Only display the move down arrow if it is not the last. // Only display the move down arrow if it is not the last.
if ($element->sequence < $numelements) { if ($element->sequence < $numelements) {
$url = new \moodle_url($editlink, $editlinkparams + array('emovedown' => $element->id)); $url = new \moodle_url($editlink, $editlinkparams + array('action' => 'emovedown',
'aid' => $element->id));
$moveicons .= $OUTPUT->action_icon($url, new \pix_icon('t/down', get_string('movedown'))); $moveicons .= $OUTPUT->action_icon($url, new \pix_icon('t/down', get_string('movedown')));
} }
$icons .= $moveicons; $icons .= $moveicons;
@ -289,7 +291,7 @@ class edit_form extends \moodleform {
// Add option to delete this page if there is more than one page. // Add option to delete this page if there is more than one page.
if ($this->numpages > 1) { if ($this->numpages > 1) {
// Link to delete the element. // Link to delete the element.
$deletelink = new \moodle_url($editlink, $editlinkparams + array('deletepage' => $page->id)); $deletelink = new \moodle_url($editlink, $editlinkparams + array('action' => 'deletepage', 'aid' => $page->id));
$deletelink = \html_writer::tag('a', get_string('deletecertpage', 'customcert'), array('href' => $deletelink->out(false), 'class' => 'deletebutton')); $deletelink = \html_writer::tag('a', get_string('deletecertpage', 'customcert'), array('href' => $deletelink->out(false), 'class' => 'deletebutton'));
$mform->addElement('html', \html_writer::tag('div', $deletelink, array('class' => 'deletebutton'))); $mform->addElement('html', \html_writer::tag('div', $deletelink, array('class' => 'deletebutton')));
} }

102
edit.php
View file

@ -25,12 +25,10 @@
require_once('../../config.php'); require_once('../../config.php');
$tid = optional_param('tid', 0, PARAM_INT); $tid = optional_param('tid', 0, PARAM_INT);
$moveup = optional_param('moveup', 0, PARAM_INT); $action = optional_param('action', '', PARAM_ALPHA);
$movedown = optional_param('movedown', 0, PARAM_INT); if ($action) {
$emoveup = optional_param('emoveup', 0, PARAM_INT); $actionid = required_param('aid', PARAM_INT);
$emovedown = optional_param('emovedown', 0, PARAM_INT); }
$deleteelement = optional_param('deleteelement', 0, PARAM_INT);
$deletepage = optional_param('deletepage', 0, PARAM_INT);
$confirm = optional_param('confirm', 0, PARAM_INT); $confirm = optional_param('confirm', 0, PARAM_INT);
// Edit an existing template. // Edit an existing template.
@ -78,51 +76,53 @@ if ($tid && $DB->count_records('customcert_templates', array('contextid' => CONT
$deleting = false; $deleting = false;
if ($tid) { if ($tid) {
// Check if they are moving a custom certificate page. switch ($action) {
if ((!empty($moveup)) || (!empty($movedown))) { case 'pmoveup' :
// Check if we are moving a page up. $template->move_page_up($actionid);
if (!empty($moveup)) { break;
$template->move_page_up($moveup); case 'pmovedown' :
} else { // Must be moving a page down. $template->move_page_down($actionid);
$template->move_page_down($movedown); break;
} case 'emoveup' :
} else if ((!empty($emoveup)) || (!empty($emovedown))) { // Check if we are moving a custom certificate element. $template->move_element_up($actionid);
// Check if we are moving an element up. break;
if (!empty($emoveup)) { case 'emovedown' :
$template->move_element_up($emoveup); $template->move_element_down($actionid);
} else { // Must be moving a element down. break;
$template->move_element_down($emovedown); case 'deletepage' :
} if (!empty($confirm)) { // Check they have confirmed the deletion.
} else if (!empty($deletepage)) { // Check if we are deleting a page. $template->delete_page($actionid);
if (!empty($confirm)) { // Check they have confirmed the deletion. } else {
$template->delete_page($deletepage); // Set deletion flag to true.
} else { $deleting = true;
// Set deletion flag to true. // Create the message.
$deleting = true; $message = get_string('deletepageconfirm', 'customcert');
// Create the message. // Create the link options.
$message = get_string('deletepageconfirm', 'customcert'); $nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
// Create the link options. $yesurl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid,
$nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid)); 'action' => 'deletepage',
$yesurl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid, 'aid' => $actionid,
'deletepage' => $deletepage, 'confirm' => 1,
'confirm' => 1, 'sesskey' => sesskey()));
'sesskey' => sesskey())); }
} break;
} else if (!empty($deleteelement)) { // Check if we are deleting an element. case 'deleteelement' :
if (!empty($confirm)) { // Check they have confirmed the deletion. if (!empty($confirm)) { // Check they have confirmed the deletion.
$template->delete_element($deleteelement); $template->delete_element($actionid);
} else { } else {
// Set deletion flag to true. // Set deletion flag to true.
$deleting = true; $deleting = true;
// Create the message. // Create the message.
$message = get_string('deleteelementconfirm', 'customcert'); $message = get_string('deleteelementconfirm', 'customcert');
// Create the link options. // Create the link options.
$nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid)); $nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
$yesurl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid, $yesurl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid,
'deleteelement' => $deleteelement, 'action' => 'deleteelement',
'confirm' => 1, 'aid' => $actionid,
'sesskey' => sesskey())); 'confirm' => 1,
} 'sesskey' => sesskey()));
}
break;
} }
} }