Skip to content

Commit

Permalink
MDL-71914 mod_feedback: Add tertiary nav in feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Dias committed Oct 26, 2021
1 parent 10b7bad commit 773051b
Show file tree
Hide file tree
Showing 41 changed files with 1,630 additions and 255 deletions.
2 changes: 2 additions & 0 deletions mod/feedback/amd/build/createtemplate.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mod/feedback/amd/build/createtemplate.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions mod/feedback/amd/build/usetemplate.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mod/feedback/amd/build/usetemplate.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions mod/feedback/amd/src/createtemplate.js
@@ -0,0 +1,70 @@
// 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/>.

/**
* Javascript module for saving a new template.
*
* @module mod_feedback/createtemplate
* @copyright 2021 Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

import ModalForm from 'core_form/modalform';
import Notification from 'core/notification';
import {get_string as getString} from 'core/str';
import {add as addToast} from 'core/toast';

const selectors = {
modaltrigger: '[data-action="createtemplate"]',
};

/**
* Initialize module
*/
export const init = () => {
const trigger = document.querySelector(selectors.modaltrigger);

trigger.addEventListener('click', event => {
event.preventDefault();
const ele = event.currentTarget;

const modalForm = new ModalForm({
modalConfig: {
title: getString('save_as_new_template', 'mod_feedback'),
},
formClass: 'mod_feedback\\form\\create_template_form',
args: {
id: ele.dataset.dataid
},
saveButtonText: getString('save', 'core')
});

// Show a toast notification when the form is submitted.
modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, event => {
if (event.detail.result) {
getString('template_saved', 'feedback').then(addToast).catch();
} else {
getString('saving_failed', 'feedback').then(string => {
return Notification.addNotification({
type: 'error',
message: string
});
}).catch();
}
});

modalForm.show();
});
};
67 changes: 67 additions & 0 deletions mod/feedback/amd/src/usetemplate.js
@@ -0,0 +1,67 @@
// 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/>.

/**
* Javascript module for using an existing template
*
* @module mod_feedback/usetemplate
* @copyright 2021 Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

import ModalForm from 'core_form/modalform';
import Notification from 'core/notification';
import {get_string as getString} from 'core/str';

const selectors = {
modaltrigger: '[data-action="usetemplate"]',
};

/**
* Initialize module
*/
export const init = () => {
const trigger = document.querySelector(selectors.modaltrigger);

trigger.addEventListener('click', event => {
event.preventDefault();

const modalForm = new ModalForm({
modalConfig: {
title: getString('use_this_template', 'mod_feedback'),
},
formClass: 'mod_feedback\\form\\use_template_form',
args: {
id: trigger.getAttribute('data-dataid'),
templateid: trigger.getAttribute('data-templateid')
},
saveButtonText: getString('save', 'core')
});

// Show a toast notification when the form is submitted.
modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, event => {
if (event.detail.result) {
window.location.assign(event.detail.url);
} else {
Notification.addNotification({
type: 'error',
message: getString('saving_failed', 'mod_feedback')
});
}
});

modalForm.show();
});
};
8 changes: 3 additions & 5 deletions mod/feedback/analysis.php
Expand Up @@ -49,11 +49,9 @@
$PAGE->set_heading($course->fullname);
$PAGE->set_title($feedback->name);
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($feedback->name));

/// print the tabs
require('tabs.php');

if (!$PAGE->has_secondary_navigation()) {
echo $OUTPUT->heading(format_string($feedback->name));
}

//get the groupid
$mygroupid = groups_get_activity_group($cm, true);
Expand Down
7 changes: 3 additions & 4 deletions mod/feedback/analysis_course.php
Expand Up @@ -71,10 +71,9 @@
$PAGE->set_heading($course->fullname);
$PAGE->set_title($feedback->name);
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($feedback->name));

/// print the tabs
require('tabs.php');
if (!$PAGE->has_secondary_navigation()) {
echo $OUTPUT->heading(format_string($feedback->name));
}

//get the groupid
//lstgroupid is the choosen id
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/classes/completion.php
Expand Up @@ -713,7 +713,7 @@ public function process_page($gopage, $gopreviouspage = false) {

if ($this->form->is_cancelled()) {
// Form was cancelled - return to the course page.
$urltogo = course_get_url($this->courseid ?: $this->feedback->course);
$urltogo = new moodle_url('/mod/feedback/view.php', ['id' => $this->get_cm()->id]);
} else if ($this->form->is_submitted() &&
($this->form->is_validated() || $gopreviouspage)) {
// Form was submitted (skip validation for "Previous page" button).
Expand Down
115 changes: 115 additions & 0 deletions mod/feedback/classes/form/create_template_form.php
@@ -0,0 +1,115 @@
<?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/>.

namespace mod_feedback\form;

use core_form\dynamic_form;
use moodle_url;
use context;
use context_module;
use context_system;

/**
* Prints the create new template form
*
* @copyright 2021 Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package mod_feedback
*/
class create_template_form extends dynamic_form {
/**
* Define the form
*/
public function definition() {
$mform =& $this->_form;

$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);

$mform->addElement('text',
'templatename',
get_string('name', 'feedback'),
['maxlength' => '200', 'size' => '50']);
$mform->setType('templatename', PARAM_TEXT);

if (has_capability('mod/feedback:createpublictemplate', context_system::instance())) {
$mform->addElement('checkbox',
'ispublic', '',
get_string('public', 'feedback'));
}
}

/**
* Returns context where this form is used
*
* @return context
*/
protected function get_context_for_dynamic_submission(): context {
$id = $this->optional_param('id', null, PARAM_INT);
list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
return context_module::instance($cm->id);
}

/**
* Checks if current user has access to this form, otherwise throws exception
*
* @throws \moodle_exception User does not have capability to access the form
*/
protected function check_access_for_dynamic_submission(): void {
$context = $this->get_context_for_dynamic_submission();
if (!has_capability('mod/feedback:edititems', $context) ||
!(has_capability('mod/feedback:createprivatetemplate', $context) ||
has_capability('mod/feedback:createpublictemplate', $context))) {
throw new \moodle_exception('nocapabilitytousethisservice');
}
}

/**
* Process the form submission, used if form was submitted via AJAX
*
* @return array Returns whether a new template was created.
*/
public function process_dynamic_submission(): array {
global $PAGE;
$formdata = $this->get_data();
$ispublic = !empty($formdata->ispublic) ? 1 : 0;
$result = feedback_save_as_template($PAGE->activityrecord, $formdata->templatename, $ispublic);
return [
'result' => $result,
];
}

/**
* Load in existing data as form defaults
*/
public function set_data_for_dynamic_submission(): void {
$this->set_data((object)[
'id' => $this->optional_param('id', null, PARAM_INT),
]);
}

/**
* Returns url to set in $PAGE->set_url() when form is being rendered or submitted via AJAX
*
* @return moodle_url
*/
protected function get_page_url_for_dynamic_submission(): moodle_url {
$params = [
'id' => $this->optional_param('id', null, PARAM_INT),
];
return new moodle_url('/mod/feedback/edit.php', $params);
}
}

0 comments on commit 773051b

Please sign in to comment.