Skip to content

Commit

Permalink
MDL-81745 mod_feedback: Refactor edit amd module
Browse files Browse the repository at this point in the history
  • Loading branch information
roland04 committed Nov 18, 2024
1 parent 269a8a8 commit 53c89cb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 45 deletions.
2 changes: 1 addition & 1 deletion mod/feedback/amd/build/edit.min.js

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

2 changes: 1 addition & 1 deletion mod/feedback/amd/build/edit.min.js.map

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

89 changes: 50 additions & 39 deletions mod/feedback/amd/src/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,59 @@
*
* @module mod_feedback/edit
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'core/ajax', 'core/str', 'core/notification'],
function($, ajax, str, notification) {
var manager = {
deleteItem: function(e) {
e.preventDefault();
var targetUrl = $(e.currentTarget).attr('href');

str.get_strings([
{
key: 'confirmation',
component: 'admin'
},
{
key: 'confirmdeleteitem',
component: 'mod_feedback'
},
{
key: 'yes',
component: 'moodle'
},
{
key: 'no',
component: 'moodle'
}
])
.then(function(s) {
notification.confirm(s[0], s[1], s[2], s[3], function() {
window.location = targetUrl;
});
"use strict";

return;
})
.catch();
},
import {prefetchStrings} from 'core/prefetch';
import {getStrings} from 'core/str';
import Notification from 'core/notification';

setup: function() {
$('body').delegate('[data-action="delete"]', 'click', manager.deleteItem);
const Selectors = {
deleteQuestionButton: '[data-action="delete"]',
};

let initialized = false;

/**
* Initialise editor and all it's modules
*/
export const init = () => {
// Ensure we only add our listeners once (can be called multiple times).
if (initialized) {
return;
}

prefetchStrings('core', [
'yes',
'no',
]);
prefetchStrings('admin', [
'confirmation',
]);
prefetchStrings('mod_feedback', [
'confirmdeleteitem',
]);

document.addEventListener('click', async event => {

// Delete question.
const deleteButton = event.target.closest(Selectors.deleteQuestionButton);
if (deleteButton) {
event.preventDefault();
const confirmationStrings = await getStrings([
{key: 'confirmation', component: 'admin'},
{key: 'confirmdeleteitem', component: 'mod_feedback'},
{key: 'yes', component: 'core'},
{key: 'no', component: 'core'},
]);
Notification.confirm(...confirmationStrings, () => {
window.location = deleteButton.getAttribute('href');
});
return;
}
};
});

return {
setup: manager.setup
};
});
initialized = true;
};
4 changes: 0 additions & 4 deletions mod/feedback/classes/complete_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,5 @@ public function display() {
}

$this->_form->display();

if ($this->mode == self::MODE_EDIT) {
$PAGE->requires->js_call_amd('mod_feedback/edit', 'setup');
}
}
}
1 change: 1 addition & 0 deletions mod/feedback/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
'description' => ''
]);
$PAGE->add_body_class('limitedwidth');
$PAGE->requires->js_call_amd('mod_feedback/edit', 'init');

//Adding the javascript module for the items dragdrop.
if (count($feedbackitems) > 1) {
Expand Down

0 comments on commit 53c89cb

Please sign in to comment.