Skip to content

Commit

Permalink
Fix all other user_preference_allow_ajax_update calls #772205
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarshallou committed May 20, 2024
1 parent 8f48487 commit 5bda004
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
25 changes: 25 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1595,3 +1595,28 @@ function mod_oublog_core_calendar_provide_event_action(calendar_event $event, \c
true
);
}

/**
* Gets plugin prefs.
*
* @return array List of prefs that can be set by AJAX
*/
function mod_oublog_user_preferences(): array {
return [
'~^oublog_accordion_.*_open$~' => [
'isregex' => true,
'type' => PARAM_INT,
'null' => NULL_NOT_ALLOWED,
'default' => '0',
'permissioncallback' => [core_user::class, 'is_current_user'],
],
'~^mod_oublog_hidestatsform_.*$~' => [
'isregex' => true,
'type' => PARAM_INT,
'null' => NULL_NOT_ALLOWED,
'default' => '0',
'choices' => [0, 1],
'permissioncallback' => [core_user::class, 'is_current_user'],
],
];
}
8 changes: 6 additions & 2 deletions module.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,19 @@ M.mod_oublog.init_showhide = function(Y, name, curpref) {
showinfo.addClass('oublog_displaynone');
form.removeClass('oublog_displaynone');
if (!Y.one('body').hasClass('notloggedin')) {
M.util.set_user_preference('mod_oublog_hidestatsform_' + name, 0);
require(['core_user/repository'], (userRepository) => {
userRepository.setUserPreference('mod_oublog_hidestatsform_' + name, 0);
});
}
curpref = 0;
} else {
hideinfo.addClass('oublog_displaynone');
showinfo.removeClass('oublog_displaynone');
form.addClass('oublog_displaynone');
if (!Y.one('body').hasClass('notloggedin')) {
M.util.set_user_preference('mod_oublog_hidestatsform_' + name, 1);
require(['core_user/repository'], (userRepository) => {
userRepository.setUserPreference('mod_oublog_hidestatsform_' + name, 1);
});
}
curpref = 1;
}
Expand Down
1 change: 0 additions & 1 deletion renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,6 @@ public function render_stats_view($name, $maintitle, $content, $subtitle = '', $
$plushide = '';
}
// Setup Javascript for stats view.
user_preference_allow_ajax_update("mod_oublog_hidestatsform_$name", PARAM_BOOL);
$PAGE->requires->js('/mod/oublog/module.js');
$module = array ('name' => 'mod_oublog');
$module['fullpath'] = '/mod/oublog/module.js';
Expand Down
4 changes: 3 additions & 1 deletion yui/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ YUI.add('moodle-mod_oublog-accordion', function(Y) {
tab.content.addClass('oublog-accordion-open');
tab.state = 1;
if (!Y.one('body').hasClass('notloggedin')) {
M.util.set_user_preference('oublog_accordion_' + tab.container_class + '_open', tab.number);
require(['core_user/repository'], (userRepository) => {
userRepository.setUserPreference('oublog_accordion_' + tab.container_class + '_open', tab.number);
});
}
},
// Init an 'accordion' style widget - ul with two divs in each li (title,content).
Expand Down

0 comments on commit 5bda004

Please sign in to comment.