Skip to content

Commit

Permalink
use moodle core checkboxes take 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Syxton committed Oct 20, 2023
1 parent 53ec48a commit b0cc959
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 51 deletions.
4 changes: 2 additions & 2 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
'request' => $massactionrequest,
'instance_id' => $instanceid,
'return_url' => $returnurl,
'sourcecourseid' => $context->instanceid
'sourcecourseid' => $context->instanceid,
];

$courseselectform = new course_select_form(null, $options);
Expand Down Expand Up @@ -175,7 +175,7 @@
$duplicatetask = new duplicate_task();
$duplicatetask->set_userid($USER->id);
$duplicatetask->set_custom_data(['modules' => $modulerecords, 'sectionnum' => $targetsectionnum,
'courseid' => $targetcourseid]);
'courseid' => $targetcourseid, ]);
manager::queue_adhoc_task($duplicatetask);
redirect($returnurl, get_string('backgroundtaskinformation', 'block_massaction'), null,
notification::NOTIFY_SUCCESS);
Expand Down
4 changes: 2 additions & 2 deletions amd/build/massactionblock.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/massactionblock.min.js.map

Large diffs are not rendered by default.

29 changes: 12 additions & 17 deletions amd/src/massactionblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Log from 'core/log';
import Notification from 'core/notification';
import Pending from 'core/pending';
import {getCurrentCourseEditor} from 'core_courseformat/courseeditor';
import events from "core_course/events";
import {disableStickyFooter} from 'core/sticky-footer';

export const usedMoodleCssClasses = {
ACTIVITY_ITEM: '.activity-item',
Expand All @@ -39,7 +39,6 @@ export const usedMoodleCssClasses = {

export const cssIds = {
BLOCK_CONTENT: 'block-massaction',
BULK_EDITING_DISABLED: 'block-massaction-bulk-editing-disabled',
SELECT_ALL_LINK: 'block-massaction-control-selectall',
DESELECT_ALL_LINK: 'block-massaction-control-deselectall',
HIDE_LINK: 'block-massaction-action-hide',
Expand Down Expand Up @@ -96,21 +95,17 @@ export const init = async() => {
// Initialize the checkbox manager.
checkboxmanager.initCheckboxManager();

// Show block depending on if the moodle bulk editing util has been activated.
editor.stateManager.target.addEventListener(events.stateChanged, (event) => {
// Listen to the event that bulk editing mode has been enabled/disabled.
if (event.detail.action === 'bulk.enabled:updated') {
// Hide/show block content depending on the bulk editing enabled state.
document.getElementById(cssIds.BLOCK_CONTENT)?.classList.toggle('d-none');
document.getElementById(cssIds.BULK_EDITING_DISABLED)?.classList.toggle('d-none');
}
});

// Register click handler for the button in the placeholder text if bulk editing is still disabled.
const enableBulkButton = document.getElementById('block-massaction-enable-bulk-editing');
// Remove the initial disabled attribute which is there to avoid too early clicks by users.
enableBulkButton.disabled = false;
enableBulkButton?.addEventListener('click', () => editor.dispatch('bulkEnable', true));
// Enable bulk editing state.
editor.dispatch('bulkEnable', true);

// Remove sticky footer.
disableStickyFooter();

// Show course module menu by removing the class that hides them.
let elem;
for (elem of document.getElementsByClassName("bulk-hidden")) {
elem.classList.remove("bulk-hidden");
}
return true;
})
.catch(error => Log.debug(error));
Expand Down
4 changes: 2 additions & 2 deletions block_massaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function get_content(): stdClass {
$actions = [];
foreach ($actionicons as $action => $iconpath) {
$actions[] = ['action' => $action, 'icon' => $iconpath,
'actiontext' => get_string('action_' . $action, 'block_massaction')];
'actiontext' => get_string('action_' . $action, 'block_massaction'), ];
}

$this->content->text = $OUTPUT->render_from_template('block_massaction/block_massaction',
Expand All @@ -169,7 +169,7 @@ public function get_content(): stdClass {
'show_moveto_select' => has_capability('moodle/course:manageactivities', $context),
'show_duplicateto_select' => (has_capability('moodle/backup:backuptargetimport', $context) &&
has_capability('moodle/restore:restoretargetimport', $context)),
'sectionselecthelpicon' => $OUTPUT->help_icon('sectionselect', 'block_massaction')
'sectionselecthelpicon' => $OUTPUT->help_icon('sectionselect', 'block_massaction'),
]);
}
return $this->content;
Expand Down
12 changes: 6 additions & 6 deletions classes/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public static function duplicate(array $modules, $sectionnumber = false): void {
$section = $modinfo->get_section_info($duplicatedmod->sectionnum);
} else { // Duplicate to a specific section.
// Verify target.
if (!$section = $DB->get_record('course_sections', array('course' => $courseid, 'section' => $sectionnumber))) {
if (!$section = $DB->get_record('course_sections', ['course' => $courseid, 'section' => $sectionnumber])) {
throw new moodle_exception('sectionnotexist', 'block_massaction');
}
}
Expand Down Expand Up @@ -227,7 +227,7 @@ public static function duplicate_to_course(array $modules, int $targetcourseid,

// Update course format setting to prevent new orphaned sections.
if (isset($targetformatopt['numsections'])) {
update_course((object)array('id' => $targetcourseid, 'numsections' => $targetformatopt['numsections'] + 1));
update_course((object)['id' => $targetcourseid, 'numsections' => $targetformatopt['numsections'] + 1]);
}

// Make sure new sectionnum is set accurately.
Expand All @@ -252,7 +252,7 @@ public static function duplicate_to_course(array $modules, int $targetcourseid,
// Update course format setting to prevent orphaned sections.
$targetformatopt = $targetformat->get_format_options();
if (isset($targetformatopt['numsections']) && $targetformatopt['numsections'] < $srcmaxsectionnum) {
update_course((object)array('id' => $targetcourseid, 'numsections' => $srcmaxsectionnum));
update_course((object)['id' => $targetcourseid, 'numsections' => $srcmaxsectionnum]);
}
}

Expand Down Expand Up @@ -348,7 +348,7 @@ public static function print_deletion_confirmation(array $modules, string $massa
'instance_id' => $instanceid,
'return_url' => $returnurl,
'request' => $massactionrequest,
'del_confirm' => 1
'del_confirm' => 1,
];
$optionsoncancel = ['id' => $cm->course];

Expand Down Expand Up @@ -394,7 +394,7 @@ public static function perform_deletion(array $modules): void {
new moodle_exception('invalidcoursemodule');
}

if (!$DB->get_record('course', array('id' => $cm->course))) {
if (!$DB->get_record('course', ['id' => $cm->course])) {
throw new moodle_exception('invalidcourseid');
}

Expand Down Expand Up @@ -503,7 +503,7 @@ public static function perform_moveto(array $modules, int $target): void {
}

// Verify target.
if (!$section = $DB->get_record('course_sections', array('course' => $cm->course, 'section' => $target))) {
if (!$section = $DB->get_record('course_sections', ['course' => $cm->course, 'section' => $target])) {
throw new moodle_exception('sectionnotexist', 'block_massaction');
}

Expand Down
2 changes: 1 addition & 1 deletion classes/form/course_select_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function definition() {
$limittoenrolled = !empty(get_config('block_massaction', 'limittoenrolled'));
$mform->addElement('course', 'targetcourseid', get_string('choosecoursetoduplicateto', 'block_massaction'),
['limittoenrolled' => $limittoenrolled, 'exclude' => $sourcecourseid,
'requiredcapabilities' => ['moodle/restore:restoretargetimport']]);
'requiredcapabilities' => ['moodle/restore:restoretargetimport'], ]);

$this->add_action_buttons(true, get_string('confirmcourseselect', 'block_massaction'));
}
Expand Down
6 changes: 3 additions & 3 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => [
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
'manager' => CAP_ALLOW,
],
'clonepermissionsfrom' => 'moodle/site:manageblocks'
'clonepermissionsfrom' => 'moodle/site:manageblocks',
],

'block/massaction:sendcontentchangednotifications' => [
Expand All @@ -54,6 +54,6 @@
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
],
'clonepermissionsfrom' => 'moodle/course:manageactivities'
'clonepermissionsfrom' => 'moodle/course:manageactivities',
],
];
2 changes: 0 additions & 2 deletions lang/en/block_massaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
$string['action_showdescription'] = 'Show description';
$string['action_hidedescription'] = 'Hide description';
$string['backgroundtaskinformation'] = 'The action you demanded is being executed in the background. You can continue your work while waiting for it to finish.';
$string['bulkeditingdisabled'] = 'To use this block, you need to enable bulk editing mode.';
$string['choosecoursetoduplicateto'] = 'Choose the course you want to duplicate the selected course modules to';
$string['choosesectiontoduplicateto'] = 'Choose the section you want the selected course modules to be duplicated to.';
$string['choosetargetcourse'] = 'Choose target course';
Expand All @@ -66,7 +65,6 @@
$string['deletecheckconfirm'] = 'Are you sure you want to delete the following module(s)?';
$string['duplicatemaxactivities'] = 'Maximum amount of course modules to duplicate';
$string['duplicatemaxactivities_description'] = 'Maximum amount of course modules which can be duplicated at the same time without running the process as background task. If set to "0" all duplication operations will be run as background task.';
$string['enablebulkediting'] = 'Enable bulk editing';
$string['invalidaction'] = 'Unknown action: {$a}';
$string['invalidmoduleid'] = 'Invalid module ID: {$a}';
$string['invalidcoursemodule'] = 'Invalid course module';
Expand Down
8 changes: 8 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,11 @@
.block-massaction-sectionselectbox form {
max-width: 600px;
}

.course-section-header .bulkselect {
display: none;
}

a[data-inplaceeditablelink] {
display: initial !important;
}
8 changes: 1 addition & 7 deletions templates/block_massaction.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@
"helpicon": "help.gif"
}
}}
<div id="block-massaction-bulk-editing-disabled">
<p>{{#str}} bulkeditingdisabled, block_massaction{{/str}}</p>
<div class="d-flex justify-content-center">
<button id="block-massaction-enable-bulk-editing" class="btn btn-secondary" disabled>{{#str}} enablebulkediting, block_massaction{{/str}}</button>
</div>
</div>
<div id="block-massaction" class="block-massaction d-none" aria-label="{{#str}} pluginname, block_massaction {{/str}}">
<div id="block-massaction" class="block-massaction" aria-label="{{#str}} pluginname, block_massaction {{/str}}">
{{! Only display, if there are any actions available or if we at least can move items }}
{{#actions.0.action}}
<button class="btn btn-link btn-sm" id="block-massaction-control-selectall">
Expand Down
5 changes: 0 additions & 5 deletions tests/behat/actions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ Feature: Check if all the different type of actions of the mass actions block wo
And I click on "Hide" "button" in the "Mass Actions" "block"
Then "Test Activity1" activity should be hidden
And "Test Activity4" activity should be hidden
When I click on "Bulk edit" "button"
And I click on "Test Activity1" "checkbox"
And I click on "Test Activity4" "checkbox"
And I click on "Show" "button" in the "Mass Actions" "block"
Then "Test Activity1" activity should be visible
And "Test Activity4" activity should be visible
When I click on "Bulk edit" "button"
And I click on "Test Activity1" "checkbox"
And I click on "Test Activity4" "checkbox"
And I click on "Make available" "button" in the "Mass Actions" "block"
Expand Down Expand Up @@ -75,13 +73,11 @@ Feature: Check if all the different type of actions of the mass actions block wo
When I am on "Test course" course homepage
Then I should not see "Test page description1"
And I should not see "Test page description4"
When I click on "Bulk edit" "button"
And I click on "Test Activity1" "checkbox"
And I click on "Test Activity4" "checkbox"
And I click on "Show description" "button" in the "Mass Actions" "block"
Then I should see "Test page description1"
And I should see "Test page description4"
When I click on "Bulk edit" "button"
And I click on "Test Activity1" "checkbox"
And I click on "Test Activity4" "checkbox"
And I click on "Hide description" "button" in the "Mass Actions" "block"
Expand Down Expand Up @@ -187,7 +183,6 @@ Feature: Check if all the different type of actions of the mass actions block wo
And I click on "Indent (move right)" "button" in the "Mass Actions" "block"
Then "#section-1 li.modtype_page.indented" "css_element" should exist
Then "#section-4 li.modtype_assign.indented" "css_element" should exist
When I click on "Bulk edit" "button"
And I click on "Test Activity2" "checkbox"
And I click on "Test Activity5" "checkbox"
And I click on "Outdent (move left)" "button" in the "Mass Actions" "block"
Expand Down
1 change: 0 additions & 1 deletion tests/behat/onetopic.feature
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ Feature: Check if in format_onetopic block properly disables the currently not a
And I click on "Indent (move right)" "button" in the "Mass Actions" "block"
Then "#section-4 li.modtype_page.indented" "css_element" should exist
Then "#section-4 li.modtype_assign.indented" "css_element" should exist
When I click on "Bulk edit" "button"
And I click on "Test Activity4" "checkbox"
And I click on "Test Activity5" "checkbox"
And I click on "Outdent (move left)" "button" in the "Mass Actions" "block"
Expand Down
1 change: 0 additions & 1 deletion tests/behat/topcoll.feature
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ Feature: Check if in format_topcoll block properly disables the currently not ac
And I click on "Indent (move right)" "button" in the "Mass Actions" "block"
Then "#section-1 li.modtype_page div.indent-1" "css_element" should exist
Then "#section-4 li.modtype_assign div.indent-1" "css_element" should exist
When I click on "Bulk edit" "button"
And I click on "Test Activity2" "checkbox"
And I click on "Test Activity5" "checkbox"
And I click on "Outdent (move left)" "button" in the "Mass Actions" "block"
Expand Down
2 changes: 1 addition & 1 deletion tests/massaction_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function setUp(): void {
// Generate two modules of each type for each of the 5 sections, so we have 6 modules per section.
$modulerecord = [
'course' => $this->course->id,
'showdescription' => 0
'showdescription' => 0,
];
for ($i = 0; $i < 10; $i++) {
$generator->create_module('assign', $modulerecord, ['section' => floor($i / 2)]);
Expand Down

0 comments on commit b0cc959

Please sign in to comment.