MDL-53638 mod_feedback: JS confirmation of deleting item
This commit is contained in:
Vendored
+1
@@ -0,0 +1 @@
|
||||
define(["jquery","core/ajax","core/str","core/notification"],function(a,b,c,d){var e={deleteItem:function(b){b.preventDefault(),c.get_strings([{key:"confirmation",component:"admin"},{key:"confirmdeleteitem",component:"mod_feedback"},{key:"yes",component:"moodle"},{key:"no",component:"moodle"}]).done(function(c){d.confirm(c[0],c[1],c[2],c[3],a.proxy(function(){window.location=a(this).attr("href")},b.currentTarget))})},setup:function(){a("body").delegate('[data-action="delete"]',"click",e.deleteItem)}};return{setup:e.setup}});
|
||||
@@ -0,0 +1,61 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Edit items in feedback module
|
||||
*
|
||||
* @module mod_feedback/edit
|
||||
* @package mod_feedback
|
||||
* @copyright 2016 Marina Glancy
|
||||
*/
|
||||
define(['jquery', 'core/ajax', 'core/str', 'core/notification'],
|
||||
function($, ajax, str, notification) {
|
||||
var manager = {
|
||||
deleteItem: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
str.get_strings([
|
||||
{
|
||||
key: 'confirmation',
|
||||
component: 'admin'
|
||||
},
|
||||
{
|
||||
key: 'confirmdeleteitem',
|
||||
component: 'mod_feedback'
|
||||
},
|
||||
{
|
||||
key: 'yes',
|
||||
component: 'moodle'
|
||||
},
|
||||
{
|
||||
key: 'no',
|
||||
component: 'moodle'
|
||||
}
|
||||
]).done(function(s) {
|
||||
notification.confirm(s[0], s[1], s[2], s[3], $.proxy(function() {
|
||||
window.location = $(this).attr('href');
|
||||
}, e.currentTarget));
|
||||
});
|
||||
},
|
||||
|
||||
setup: function() {
|
||||
$('body').delegate('[data-action="delete"]', 'click', manager.deleteItem);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
setup: manager.setup
|
||||
};
|
||||
});
|
||||
@@ -545,7 +545,7 @@ class mod_feedback_complete_form extends moodleform {
|
||||
* Displays the form
|
||||
*/
|
||||
public function display() {
|
||||
global $OUTPUT;
|
||||
global $OUTPUT, $PAGE;
|
||||
// Finalize the form definition if not yet done.
|
||||
if (!$this->_definition_finalized) {
|
||||
$this->_definition_finalized = true;
|
||||
@@ -575,5 +575,9 @@ class mod_feedback_complete_form extends moodleform {
|
||||
}
|
||||
|
||||
$this->_form->display();
|
||||
|
||||
if ($this->mode == self::MODE_EDIT) {
|
||||
$PAGE->requires->js_call_amd('mod_feedback/edit', 'setup');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* deletes an item of the feedback
|
||||
*
|
||||
* @author Andreas Grabs
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
* @package mod_feedback
|
||||
*/
|
||||
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
$deleteitem = required_param('deleteitem', PARAM_INT);
|
||||
$item = $DB->get_record('feedback_item', array('id' => $deleteitem), '*', MUST_EXIST);
|
||||
list($course, $cm) = get_course_and_cm_from_instance($item->feedback, 'feedback');
|
||||
|
||||
$PAGE->set_url('/mod/feedback/delete_item.php', array('deleteitem' => $deleteitem));
|
||||
|
||||
require_login($course, false, $cm);
|
||||
$context = context_module::instance($cm->id);
|
||||
require_capability('mod/feedback:edititems', $context);
|
||||
$feedback = $PAGE->activityrecord;
|
||||
|
||||
$editurl = new moodle_url('/mod/feedback/edit.php', array('id' => $cm->id));
|
||||
|
||||
// Process item deletion.
|
||||
if (optional_param('confirm', 0, PARAM_BOOL) && confirm_sesskey()) {
|
||||
feedback_delete_item($deleteitem);
|
||||
redirect($editurl);
|
||||
}
|
||||
|
||||
/// Print the page header
|
||||
$strfeedbacks = get_string("modulenameplural", "feedback");
|
||||
$strfeedback = get_string("modulename", "feedback");
|
||||
|
||||
$PAGE->navbar->add(get_string('delete_item', 'feedback'));
|
||||
$PAGE->set_heading($course->fullname);
|
||||
$PAGE->set_title($feedback->name);
|
||||
echo $OUTPUT->header();
|
||||
|
||||
/// Print the main part of the page
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
echo $OUTPUT->heading(format_string($feedback->name));
|
||||
echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal');
|
||||
$continueurl = new moodle_url($PAGE->url, array('confirm' => 1, 'sesskey' => sesskey()));
|
||||
echo $OUTPUT->confirm(get_string('confirmdeleteitem', 'feedback'), $continueurl, $editurl);
|
||||
echo $OUTPUT->box_end();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
|
||||
+16
-4
@@ -36,6 +36,7 @@ if (($formdata = data_submitted()) AND !confirm_sesskey()) {
|
||||
|
||||
$do_show = optional_param('do_show', 'edit', PARAM_ALPHA);
|
||||
$switchitemrequired = optional_param('switchitemrequired', false, PARAM_INT);
|
||||
$deleteitem = optional_param('deleteitem', false, PARAM_INT);
|
||||
|
||||
$current_tab = $do_show;
|
||||
|
||||
@@ -50,10 +51,21 @@ $feedback = $PAGE->activityrecord;
|
||||
$feedbackstructure = new mod_feedback_structure($feedback, $cm);
|
||||
|
||||
if ($switchitemrequired) {
|
||||
$item = $DB->get_record('feedback_item', array('id'=>$switchitemrequired));
|
||||
@feedback_switch_item_required($item);
|
||||
redirect($url->out(false));
|
||||
exit;
|
||||
require_sesskey();
|
||||
$items = $feedbackstructure->get_items();
|
||||
if (isset($items[$switchitemrequired])) {
|
||||
feedback_switch_item_required($items[$switchitemrequired]);
|
||||
}
|
||||
redirect($url);
|
||||
}
|
||||
|
||||
if ($deleteitem) {
|
||||
require_sesskey();
|
||||
$items = $feedbackstructure->get_items();
|
||||
if (isset($items[$deleteitem])) {
|
||||
feedback_delete_item($deleteitem);
|
||||
}
|
||||
redirect($url);
|
||||
}
|
||||
|
||||
// Process the create template form.
|
||||
|
||||
@@ -227,9 +227,9 @@ abstract class feedback_item_base {
|
||||
$buttontitle = get_string('switch_item_to_required', 'feedback');
|
||||
$buttonimg = 'notrequired';
|
||||
}
|
||||
$url = new moodle_url('/mod/feedback/edit.php', array('id' => $cm->id, 'do_show' => 'edit'));
|
||||
$actions['required'] = new action_menu_link_secondary(
|
||||
new moodle_url($url, array('switchitemrequired' => $item->id)),
|
||||
new moodle_url('/mod/feedback/edit.php', array('id' => $cm->id,
|
||||
'switchitemrequired' => $item->id, 'sesskey' => sesskey())),
|
||||
new pix_icon($buttonimg, $buttontitle, 'feedback', array('class' => 'iconsmall', 'title' => '')),
|
||||
$buttontitle,
|
||||
array('class' => 'editing_togglerequired', 'data-action' => 'togglerequired')
|
||||
@@ -238,7 +238,7 @@ abstract class feedback_item_base {
|
||||
|
||||
$strdelete = get_string('delete_item', 'feedback');
|
||||
$actions['delete'] = new action_menu_link_secondary(
|
||||
new moodle_url('/mod/feedback/delete_item.php', array('deleteitem' => $item->id)),
|
||||
new moodle_url('/mod/feedback/edit.php', array('id' => $cm->id, 'deleteitem' => $item->id, 'sesskey' => sesskey())),
|
||||
new pix_icon('t/delete', $strdelete, 'moodle', array('class' => 'iconsmall', 'title' => '')),
|
||||
$strdelete,
|
||||
array('class' => 'editing_delete', 'data-action' => 'delete')
|
||||
@@ -308,7 +308,7 @@ class feedback_item_pagebreak extends feedback_item_base {
|
||||
$actions = array();
|
||||
$strdelete = get_string('delete_pagebreak', 'feedback');
|
||||
$actions['delete'] = new action_menu_link_secondary(
|
||||
new moodle_url('/mod/feedback/delete_item.php', array('deleteitem' => $item->id)),
|
||||
new moodle_url('/mod/feedback/edit.php', array('id' => $cm->id, 'deleteitem' => $item->id, 'sesskey' => sesskey())),
|
||||
new pix_icon('t/delete', $strdelete, 'moodle', array('class' => 'iconsmall', 'title' => '')),
|
||||
$strdelete,
|
||||
array('class' => 'editing_delete', 'data-action' => 'delete')
|
||||
|
||||
Reference in New Issue
Block a user