Merge branch 'MDL-63793-master' of git://github.com/peterRd/moodle
This commit is contained in:
@@ -44,8 +44,10 @@ function(
|
||||
* @param {function} renderPagesContentCallback (optional) A callback function to render a
|
||||
* content page. See core/paged_content_pages for
|
||||
* more defails.
|
||||
* @param {string} namespaceOverride (optional) Provide a unique namespace override. If none provided defaults
|
||||
* to generate html's id
|
||||
*/
|
||||
var init = function(root, renderPagesContentCallback) {
|
||||
var init = function(root, renderPagesContentCallback, namespaceOverride) {
|
||||
root = $(root);
|
||||
var pagesContainer = root.find(Pages.rootSelector);
|
||||
var pagingBarContainer = root.find(PagingBar.rootSelector);
|
||||
@@ -53,6 +55,11 @@ function(
|
||||
var pagingBarLimitSelectorContainer = root.find(PagingBarLimitSelector.rootSelector);
|
||||
var id = root.attr('id');
|
||||
|
||||
// Set the id to the custom namespace provided
|
||||
if (namespaceOverride) {
|
||||
id = namespaceOverride;
|
||||
}
|
||||
|
||||
Pages.init(pagesContainer, id, renderPagesContentCallback);
|
||||
|
||||
if (pagingBarContainer.length) {
|
||||
|
||||
@@ -27,7 +27,8 @@ define(
|
||||
'core/notification',
|
||||
'core/paged_content',
|
||||
'core/paged_content_events',
|
||||
'core/pubsub'
|
||||
'core/pubsub',
|
||||
'core/ajax'
|
||||
],
|
||||
function(
|
||||
$,
|
||||
@@ -35,7 +36,8 @@ function(
|
||||
Notification,
|
||||
PagedContent,
|
||||
PagedContentEvents,
|
||||
PubSub
|
||||
PubSub,
|
||||
Ajax
|
||||
) {
|
||||
var TEMPLATES = {
|
||||
PAGED_CONTENT: 'core/paged_content'
|
||||
@@ -425,10 +427,18 @@ function(
|
||||
Templates.render(TEMPLATES.PAGED_CONTENT, templateContext)
|
||||
.then(function(html, js) {
|
||||
html = $(html);
|
||||
var id = html.attr('id');
|
||||
|
||||
// Set the id to the custom namespace provided
|
||||
if (config.hasOwnProperty('eventNamespace')) {
|
||||
id = config.eventNamespace;
|
||||
}
|
||||
|
||||
var container = html;
|
||||
|
||||
PagedContent.init(container, renderPagesContentCallback);
|
||||
PagedContent.init(container, renderPagesContentCallback, id);
|
||||
|
||||
registerEvents(id, config);
|
||||
|
||||
deferred.resolve(html, js);
|
||||
return;
|
||||
@@ -494,6 +504,47 @@ function(
|
||||
PubSub.publish(id + PagedContentEvents.ALL_ITEMS_LOADED, lastPageNumber);
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate the callback handler for the page limit persistence functionality
|
||||
*
|
||||
* @param {String} persistentLimitKey
|
||||
* @return {callback}
|
||||
*/
|
||||
var generateLimitHandler = function(persistentLimitKey) {
|
||||
var callback = function(limit) {
|
||||
var args = {
|
||||
preferences: [
|
||||
{
|
||||
type: persistentLimitKey,
|
||||
value: limit
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var request = {
|
||||
methodname: 'core_user_update_user_preferences',
|
||||
args: args
|
||||
};
|
||||
|
||||
Ajax.call([request]);
|
||||
};
|
||||
|
||||
return callback;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set up any events based on config key values
|
||||
*
|
||||
* @param {string} namespace The namespace for this component
|
||||
* @param {object} config Config options passed to the factory
|
||||
*/
|
||||
var registerEvents = function(namespace, config) {
|
||||
if (config.hasOwnProperty('persistentLimitKey')) {
|
||||
PubSub.subscribe(namespace + PagedContentEvents.SET_ITEMS_PER_PAGE_LIMIT,
|
||||
generateLimitHandler(config.persistentLimitKey));
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
create: create,
|
||||
createWithLimit: createWithLimit,
|
||||
|
||||
Reference in New Issue
Block a user