Current Path : /var/www/ljmtc/cbt/lib/amd/build/ |
Current File : /var/www/ljmtc/cbt/lib/amd/build/paged_content_factory.min.js.map |
{"version":3,"sources":["../src/paged_content_factory.js"],"names":["define","$","Templates","Notification","PagedContent","PagedContentEvents","PubSub","Ajax","TEMPLATES","PAGED_CONTENT","DEFAULT","ITEMS_PER_PAGE_SINGLE","ITEMS_PER_PAGE_ARRAY","MAX_PAGES","getDefaultTemplateContext","pagingbar","pagingdropdown","skipjs","ignorecontrolwhileloading","controlplacementbottom","getDefaultPagingBarTemplateContext","showitemsperpageselector","itemsperpage","previous","next","activepagenumber","hidecontrolonsinglepage","pages","calculateNumberOfPages","numberOfItems","itemsPerPage","numberOfPages","partial","buildPagingBarTemplateContextKnownLength","isArray","context","i","page","number","active","push","barsize","buildItemsPerPagePagingBarContext","map","num","value","activeItems","filter","item","length","buildPagingBarTemplateContextUnknownLength","buildPagingBarTemplateContext","buildPagingDropdownTemplateContext","config","options","totalItems","lastIncrease","maxPages","hasOwnProperty","itemCount","option","itemcount","content","buildTemplateContext","ignoreControlWhileLoading","controlPlacementBottom","hideControlOnSinglePage","arialabels","ariaLabels","dropdown","createWithTotalAndLimit","renderPagesContentCallback","deferred","Deferred","templateContext","render","then","html","js","id","attr","eventNamespace","container","init","registerEvents","resolve","fail","exception","reject","promise","generateLimitHandler","persistentLimitKey","callback","limit","call","methodname","args","preferences","type","namespace","subscribe","SET_ITEMS_PER_PAGE_LIMIT","create","createWithLimit","createFromStaticList","contentItems","renderContentCallback","pagesData","contentToRender","forEach","pageData","begin","offset","end","items","slice","createFromAjax","resetLastPageNumber","lastPageNumber","publish","ALL_ITEMS_LOADED"],"mappings":"AAsBAA,OAAM,8BACN,CACI,QADJ,CAEI,gBAFJ,CAGI,mBAHJ,CAII,oBAJJ,CAKI,2BALJ,CAMI,aANJ,CAOI,WAPJ,CADM,CAUN,SACIC,CADJ,CAEIC,CAFJ,CAGIC,CAHJ,CAIIC,CAJJ,CAKIC,CALJ,CAMIC,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AOqB,CAAAA,CAAuB,CAACzC,CAAD,CAAgBC,CAAhB,CAA8B,SAAS6E,CAAT,CAAoB,CAC5E,GAAIC,CAAAA,CAAe,CAAG,EAAtB,CACAD,CAAS,CAACE,OAAV,CAAkB,SAASC,CAAT,CAAmB,IAC7BC,CAAAA,CAAK,CAAGD,CAAQ,CAACE,MADY,CAE7BC,CAAG,CAAGH,CAAQ,CAACjB,KAAT,CAAiBkB,CAAK,CAAGD,CAAQ,CAACjB,KAAlC,CAA0ChE,CAFnB,CAG7BqF,CAAK,CAAGT,CAAY,CAACU,KAAb,CAAmBJ,CAAnB,CAA0BE,CAA1B,CAHqB,CAIjCL,CAAe,CAACpE,IAAhB,CAAqB0E,CAArB,CACH,CALD,EAOA,MAAOR,CAAAA,CAAqB,CAACE,CAAD,CAC/B,CAV6B,CAU3BvD,CAV2B,CAWjC,CAsDM,CAMH+D,cAAc,CAAE9C,CANb,CAOH+C,mBAAmB,CApDG,QAAtBA,CAAAA,mBAAsB,CAAStC,CAAT,CAAauC,CAAb,CAA6B,CACnDhH,CAAM,CAACiH,OAAP,CAAexC,CAAE,CAAG1E,CAAkB,CAACmH,gBAAvC,CAAyDF,CAAzD,CACH,CA2CM,CASV,CA3hBK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Factory to create a paged content widget.\n *\n * @module core/paged_content_factory\n * @copyright 2018 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(\n[\n 'jquery',\n 'core/templates',\n 'core/notification',\n 'core/paged_content',\n 'core/paged_content_events',\n 'core/pubsub',\n 'core/ajax'\n],\nfunction(\n $,\n Templates,\n Notification,\n PagedContent,\n PagedContentEvents,\n PubSub,\n Ajax\n) {\n var TEMPLATES = {\n PAGED_CONTENT: 'core/paged_content'\n };\n\n var DEFAULT = {\n ITEMS_PER_PAGE_SINGLE: 25,\n ITEMS_PER_PAGE_ARRAY: [25, 50, 100, 0],\n MAX_PAGES: 3\n };\n\n /**\n * Get the default context to render the paged content mustache\n * template.\n *\n * @return {object}\n */\n var getDefaultTemplateContext = function() {\n return {\n pagingbar: false,\n pagingdropdown: false,\n skipjs: true,\n ignorecontrolwhileloading: true,\n controlplacementbottom: false\n };\n };\n\n /**\n * Get the default context to render the paging bar mustache template.\n *\n * @return {object}\n */\n var getDefaultPagingBarTemplateContext = function() {\n return {\n showitemsperpageselector: false,\n itemsperpage: 35,\n previous: true,\n next: true,\n activepagenumber: 1,\n hidecontrolonsinglepage: true,\n pages: []\n };\n };\n\n /**\n * Calculate the number of pages required for the given number of items and\n * how many of each item should appear on a page.\n *\n * @param {Number} numberOfItems How many items in total.\n * @param {Number} itemsPerPage How many items will be shown per page.\n * @return {Number} The number of pages required.\n */\n var calculateNumberOfPages = function(numberOfItems, itemsPerPage) {\n var numberOfPages = 1;\n\n if (numberOfItems > 0) {\n var partial = numberOfItems % itemsPerPage;\n\n if (partial) {\n numberOfItems -= partial;\n numberOfPages = (numberOfItems / itemsPerPage) + 1;\n } else {\n numberOfPages = numberOfItems / itemsPerPage;\n }\n }\n\n return numberOfPages;\n };\n\n /**\n * Build the context for the paging bar template when we have a known number\n * of items.\n *\n * @param {Number} numberOfItems How many items in total.\n * @param {Number} itemsPerPage How many items will be shown per page.\n * @return {object} Mustache template\n */\n var buildPagingBarTemplateContextKnownLength = function(numberOfItems, itemsPerPage) {\n if (itemsPerPage === null) {\n itemsPerPage = DEFAULT.ITEMS_PER_PAGE_SINGLE;\n }\n\n if ($.isArray(itemsPerPage)) {\n // If we're given a total number of pages then we don't support a variable\n // set of items per page so just use the first one.\n itemsPerPage = itemsPerPage[0];\n }\n\n var context = getDefaultPagingBarTemplateContext();\n context.itemsperpage = itemsPerPage;\n var numberOfPages = calculateNumberOfPages(numberOfItems, itemsPerPage);\n\n for (var i = 1; i <= numberOfPages; i++) {\n var page = {\n number: i,\n page: \"\" + i,\n };\n\n // Make the first page active by default.\n if (i === 1) {\n page.active = true;\n }\n\n context.pages.push(page);\n }\n\n context.barsize = 10;\n return context;\n };\n\n /**\n * Convert the itemsPerPage value into a format applicable for the mustache template.\n * The given value can be either a single integer or an array of integers / objects.\n *\n * E.g.\n * In: [5, 10]\n * out: [{value: 5, active: true}, {value: 10, active: false}]\n *\n * In: [5, {value: 10, active: true}]\n * Out: [{value: 5, active: false}, {value: 10, active: true}]\n *\n * In: [{value: 5, active: false}, {value: 10, active: true}]\n * Out: [{value: 5, active: false}, {value: 10, active: true}]\n *\n * @param {int|int[]} itemsPerPage Options for number of items per page.\n * @return {int|array}\n */\n var buildItemsPerPagePagingBarContext = function(itemsPerPage) {\n var context = [];\n\n if ($.isArray(itemsPerPage)) {\n // Convert the array into a format accepted by the template.\n context = itemsPerPage.map(function(num) {\n if (typeof num === 'number') {\n // If the item is just a plain number then convert it into\n // an object with value and active keys.\n return {\n value: num,\n active: false\n };\n } else {\n // Otherwise we assume the caller has specified things correctly.\n return num;\n }\n });\n\n var activeItems = context.filter(function(item) {\n return item.active;\n });\n\n // Default the first item to active if one hasn't been specified.\n if (!activeItems.length) {\n context[0].active = true;\n }\n } else {\n // Convert the integer into a format accepted by the template.\n context = [{value: itemsPerPage, active: true}];\n }\n\n return context;\n };\n\n /**\n * Build the context for the paging bar template when we have an unknown\n * number of items.\n *\n * @param {Number} itemsPerPage How many items will be shown per page.\n * @return {object} Mustache template\n */\n var buildPagingBarTemplateContextUnknownLength = function(itemsPerPage) {\n if (itemsPerPage === null) {\n itemsPerPage = DEFAULT.ITEMS_PER_PAGE_ARRAY;\n }\n\n var context = getDefaultPagingBarTemplateContext();\n context.itemsperpage = buildItemsPerPagePagingBarContext(itemsPerPage);\n // Only display the items per page selector if there is more than one to choose from.\n context.showitemsperpageselector = $.isArray(itemsPerPage) && itemsPerPage.length > 1;\n\n return context;\n };\n\n /**\n * Build the context to render the paging bar template with based on the number\n * of pages to show.\n *\n * @param {int|null} numberOfItems How many items are there total.\n * @param {int|null} itemsPerPage How many items will be shown per page.\n * @return {object} The template context.\n */\n var buildPagingBarTemplateContext = function(numberOfItems, itemsPerPage) {\n if (numberOfItems) {\n return buildPagingBarTemplateContextKnownLength(numberOfItems, itemsPerPage);\n } else {\n return buildPagingBarTemplateContextUnknownLength(itemsPerPage);\n }\n };\n\n /**\n * Build the context to render the paging dropdown template based on the number\n * of pages to show and items per page.\n *\n * This control is rendered with a gradual increase of the items per page to\n * limit the number of pages in the dropdown. Each page will show twice as much\n * as the previous page (except for the first two pages).\n *\n * By default there will only be 4 pages shown (including the \"All\" option) unless\n * a different number of pages is defined using the maxPages config value.\n *\n * For example:\n * Items per page = 25\n * Would render a dropdown will 4 options:\n * 25\n * 50\n * 100\n * All\n *\n * @param {Number} itemsPerPage How many items will be shown per page.\n * @param {object} config Configuration options provided by the client.\n * @return {object} The template context.\n */\n var buildPagingDropdownTemplateContext = function(itemsPerPage, config) {\n if (itemsPerPage === null) {\n itemsPerPage = DEFAULT.ITEMS_PER_PAGE_SINGLE;\n }\n\n if ($.isArray(itemsPerPage)) {\n // If we're given an array for the items per page, rather than a number,\n // then just use that as the options for the dropdown.\n return {\n options: itemsPerPage\n };\n }\n\n var context = {\n options: []\n };\n\n var totalItems = 0;\n var lastIncrease = 0;\n var maxPages = DEFAULT.MAX_PAGES;\n\n if (config.hasOwnProperty('maxPages')) {\n maxPages = config.maxPages;\n }\n\n for (var i = 1; i <= maxPages; i++) {\n var itemCount = 0;\n\n if (i <= 2) {\n itemCount = itemsPerPage;\n lastIncrease = itemsPerPage;\n } else {\n lastIncrease = lastIncrease * 2;\n itemCount = lastIncrease;\n }\n\n totalItems += itemCount;\n var option = {\n itemcount: itemCount,\n content: totalItems\n };\n\n // Make the first option active by default.\n if (i === 1) {\n option.active = true;\n }\n\n context.options.push(option);\n }\n\n return context;\n };\n\n /**\n * Build the context to render the paged content template with based on the number\n * of pages to show, items per page, and configuration option.\n *\n * By default the code will render a paging bar for the paging controls unless\n * otherwise specified in the provided config.\n *\n * @param {int|null} numberOfItems Total number of items.\n * @param {int|null|array} itemsPerPage How many items will be shown per page.\n * @param {object} config Configuration options provided by the client.\n * @return {object} The template context.\n */\n var buildTemplateContext = function(numberOfItems, itemsPerPage, config) {\n var context = getDefaultTemplateContext();\n\n if (config.hasOwnProperty('ignoreControlWhileLoading')) {\n context.ignorecontrolwhileloading = config.ignoreControlWhileLoading;\n }\n\n if (config.hasOwnProperty('controlPlacementBottom')) {\n context.controlplacementbottom = config.controlPlacementBottom;\n }\n\n if (config.hasOwnProperty('hideControlOnSinglePage')) {\n context.hidecontrolonsinglepage = config.hideControlOnSinglePage;\n }\n\n if (config.hasOwnProperty('ariaLabels')) {\n context.arialabels = config.ariaLabels;\n }\n\n if (config.hasOwnProperty('dropdown') && config.dropdown) {\n context.pagingdropdown = buildPagingDropdownTemplateContext(itemsPerPage, config);\n } else {\n context.pagingbar = buildPagingBarTemplateContext(numberOfItems, itemsPerPage);\n }\n\n return context;\n };\n\n /**\n * Create a paged content widget where the complete list of items is not loaded\n * up front but will instead be loaded by an ajax request (or similar).\n *\n * The client code must provide a callback function which loads and renders the\n * items for each page. See PagedContent.init for more details.\n *\n * The function will return a deferred that is resolved with a jQuery object\n * for the HTML content and a string for the JavaScript.\n *\n * The current list of configuration options available are:\n * dropdown {bool} True to render the page control as a dropdown (paging bar is default).\n * maxPages {Number} The maximum number of pages to show in the dropdown (only works with dropdown option)\n * ignoreControlWhileLoading {bool} Disable the pagination controls while loading a page (default to true)\n * controlPlacementBottom {bool} Render controls under paged content (default to false)\n *\n * @param {function} renderPagesContentCallback Callback for loading and rendering the items.\n * @param {object} config Configuration options provided by the client.\n * @return {promise} Resolved with jQuery HTML and string JS.\n */\n var create = function(renderPagesContentCallback, config) {\n return createWithTotalAndLimit(null, null, renderPagesContentCallback, config);\n };\n\n /**\n * Create a paged content widget where the complete list of items is not loaded\n * up front but will instead be loaded by an ajax request (or similar).\n *\n * The client code must provide a callback function which loads and renders the\n * items for each page. See PagedContent.init for more details.\n *\n * The function will return a deferred that is resolved with a jQuery object\n * for the HTML content and a string for the JavaScript.\n *\n * The current list of configuration options available are:\n * dropdown {bool} True to render the page control as a dropdown (paging bar is default).\n * maxPages {Number} The maximum number of pages to show in the dropdown (only works with dropdown option)\n * ignoreControlWhileLoading {bool} Disable the pagination controls while loading a page (default to true)\n * controlPlacementBottom {bool} Render controls under paged content (default to false)\n *\n * @param {int|array|null} itemsPerPage How many items will be shown per page.\n * @param {function} renderPagesContentCallback Callback for loading and rendering the items.\n * @param {object} config Configuration options provided by the client.\n * @return {promise} Resolved with jQuery HTML and string JS.\n */\n var createWithLimit = function(itemsPerPage, renderPagesContentCallback, config) {\n return createWithTotalAndLimit(null, itemsPerPage, renderPagesContentCallback, config);\n };\n\n /**\n * Create a paged content widget where the complete list of items is not loaded\n * up front but will instead be loaded by an ajax request (or similar).\n *\n * The client code must provide a callback function which loads and renders the\n * items for each page. See PagedContent.init for more details.\n *\n * The function will return a deferred that is resolved with a jQuery object\n * for the HTML content and a string for the JavaScript.\n *\n * The current list of configuration options available are:\n * dropdown {bool} True to render the page control as a dropdown (paging bar is default).\n * maxPages {Number} The maximum number of pages to show in the dropdown (only works with dropdown option)\n * ignoreControlWhileLoading {bool} Disable the pagination controls while loading a page (default to true)\n * controlPlacementBottom {bool} Render controls under paged content (default to false)\n *\n * @param {int|null} numberOfItems How many items are there in total.\n * @param {int|array|null} itemsPerPage How many items will be shown per page.\n * @param {function} renderPagesContentCallback Callback for loading and rendering the items.\n * @param {object} config Configuration options provided by the client.\n * @return {promise} Resolved with jQuery HTML and string JS.\n */\n var createWithTotalAndLimit = function(numberOfItems, itemsPerPage, renderPagesContentCallback, config) {\n config = config || {};\n\n var deferred = $.Deferred();\n var templateContext = buildTemplateContext(numberOfItems, itemsPerPage, config);\n\n Templates.render(TEMPLATES.PAGED_CONTENT, templateContext)\n .then(function(html, js) {\n html = $(html);\n var id = html.attr('id');\n\n // Set the id to the custom namespace provided\n if (config.hasOwnProperty('eventNamespace')) {\n id = config.eventNamespace;\n }\n\n var container = html;\n\n PagedContent.init(container, renderPagesContentCallback, id);\n\n registerEvents(id, config);\n\n deferred.resolve(html, js);\n return;\n })\n .fail(function(exception) {\n deferred.reject(exception);\n })\n .fail(Notification.exception);\n\n return deferred.promise();\n };\n\n /**\n * Create a paged content widget where the complete list of items is loaded\n * up front.\n *\n * The client code must provide a callback function which renders the\n * items for each page. The callback will be provided with an array where each\n * value in the array is a the list of items to render for the page.\n *\n * The function will return a deferred that is resolved with a jQuery object\n * for the HTML content and a string for the JavaScript.\n *\n * The current list of configuration options available are:\n * dropdown {bool} True to render the page control as a dropdown (paging bar is default).\n * maxPages {Number} The maximum number of pages to show in the dropdown (only works with dropdown option)\n * ignoreControlWhileLoading {bool} Disable the pagination controls while loading a page (default to true)\n * controlPlacementBottom {bool} Render controls under paged content (default to false)\n *\n * @param {array} contentItems The list of items to paginate.\n * @param {Number} itemsPerPage How many items will be shown per page.\n * @param {function} renderContentCallback Callback for rendering the items for the page.\n * @param {object} config Configuration options provided by the client.\n * @return {promise} Resolved with jQuery HTML and string JS.\n */\n var createFromStaticList = function(contentItems, itemsPerPage, renderContentCallback, config) {\n if (typeof config == 'undefined') {\n config = {};\n }\n\n var numberOfItems = contentItems.length;\n return createWithTotalAndLimit(numberOfItems, itemsPerPage, function(pagesData) {\n var contentToRender = [];\n pagesData.forEach(function(pageData) {\n var begin = pageData.offset;\n var end = pageData.limit ? begin + pageData.limit : numberOfItems;\n var items = contentItems.slice(begin, end);\n contentToRender.push(items);\n });\n\n return renderContentCallback(contentToRender);\n }, config);\n };\n\n /**\n * Reset the last page number for the generated paged-content\n * This is used when we need a way to update the last page number outside of the getters callback\n *\n * @param {String} id ID of the paged content container\n * @param {Int} lastPageNumber The last page number\n */\n var resetLastPageNumber = function(id, lastPageNumber) {\n PubSub.publish(id + PagedContentEvents.ALL_ITEMS_LOADED, lastPageNumber);\n };\n\n /**\n * Generate the callback handler for the page limit persistence functionality\n *\n * @param {String} persistentLimitKey\n * @return {callback}\n */\n var generateLimitHandler = function(persistentLimitKey) {\n var callback = function(limit) {\n var args = {\n preferences: [\n {\n type: persistentLimitKey,\n value: limit\n }\n ]\n };\n\n var request = {\n methodname: 'core_user_update_user_preferences',\n args: args\n };\n\n Ajax.call([request]);\n };\n\n return callback;\n };\n\n /**\n * Set up any events based on config key values\n *\n * @param {string} namespace The namespace for this component\n * @param {object} config Config options passed to the factory\n */\n var registerEvents = function(namespace, config) {\n if (config.hasOwnProperty('persistentLimitKey')) {\n PubSub.subscribe(namespace + PagedContentEvents.SET_ITEMS_PER_PAGE_LIMIT,\n generateLimitHandler(config.persistentLimitKey));\n }\n };\n\n return {\n create: create,\n createWithLimit: createWithLimit,\n createWithTotalAndLimit: createWithTotalAndLimit,\n createFromStaticList: createFromStaticList,\n // Backwards compatibility just in case anyone was using this.\n createFromAjax: createWithTotalAndLimit,\n resetLastPageNumber: resetLastPageNumber\n };\n});\n"],"file":"paged_content_factory.min.js"}