MDL-58907 block_myoverview: change URL when tab is selected

We then check if this paramter exists in the URL and if it
does we display the specified tab.
This commit is contained in:
Mark Nelson 2017-06-07 17:37:29 +08:00
parent 4dfb8cf060
commit 0ecb3d7786
3 changed files with 15 additions and 6 deletions

View File

@ -1 +1 @@
define(["jquery","core/ajax","core/custom_interaction_events"],function(a,b,c){var d=function(d){c.define(d,[c.events.activate]),d.on(c.events.activate,"[data-toggle='tab']",function(c){var d={methodname:"core_user_update_user_preferences",args:{preferences:[{type:"block_myoverview_last_tab",value:a(c.currentTarget).data("tabname")}]}};b.call([d])[0].fail(Notification.exception)})};return{registerEventListeners:d}});
define(["jquery","core/ajax","core/custom_interaction_events"],function(a,b,c){var d=function(d){c.define(d,[c.events.activate]),d.on(c.events.activate,"[data-toggle='tab']",function(c){var d=a(c.currentTarget).data("tabname");"function"==typeof window.history.pushState&&window.history.pushState(null,null,"?myoverviewtab="+d);var e={methodname:"core_user_update_user_preferences",args:{preferences:[{type:"block_myoverview_last_tab",value:d}]}};b.call([e])[0].fail(Notification.exception)})};return{registerEventListeners:d}});

View File

@ -31,13 +31,19 @@ define(['jquery', 'core/ajax', 'core/custom_interaction_events'], function($, Aj
var registerEventListeners = function(root) {
CustomEvents.define(root, [CustomEvents.events.activate]);
root.on(CustomEvents.events.activate, "[data-toggle='tab']", function(e) {
var tabname = $(e.currentTarget).data('tabname');
// Bootstrap does not change the URL when using BS tabs, so need to do this here.
// Also check to make sure the browser supports the history API.
if (typeof window.history.pushState === "function") {
window.history.pushState(null, null, '?myoverviewtab=' + tabname);
}
var request = {
methodname: 'core_user_update_user_preferences',
args: {
preferences: [
{
type: 'block_myoverview_last_tab',
value: $(e.currentTarget).data('tabname')
value: tabname
}
]
}

View File

@ -50,10 +50,13 @@ class block_myoverview extends block_base {
return $this->content;
}
// Wasn't set as a user preference so get the site setting.
if (!$tab = get_user_preferences('block_myoverview_last_tab')) {
$config = get_config('block_myoverview');
$tab = $config->defaulttab;
// Check if the tab to select wasn't passed in the URL, if so see if the user has any preference.
if (!$tab = optional_param('myoverviewtab', null, PARAM_ALPHA)) {
// Check if the user has no preference, if so get the site setting.
if (!$tab = get_user_preferences('block_myoverview_last_tab')) {
$config = get_config('block_myoverview');
$tab = $config->defaulttab;
}
}
$renderable = new \block_myoverview\output\main($tab);