mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
Merge branch 'MDL-62859' of https://github.com/paulholden/moodle
This commit is contained in:
commit
59cd47c02f
@ -1,10 +1,10 @@
|
||||
define("block_myoverview/repository",["exports","core/ajax","core/notification"],(function(_exports,_ajax,Notification){var obj;
|
||||
define("block_myoverview/repository",["exports","core/ajax"],(function(_exports,_ajax){var obj;
|
||||
/**
|
||||
* A javascript module to retrieve enrolled coruses from the server.
|
||||
*
|
||||
* @module block_myoverview/repository
|
||||
* @copyright 2018 Bas Brands <base@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.updateUserPreferences=_exports.setFavouriteCourses=_exports.getEnrolledCoursesByTimeline=void 0,_ajax=(obj=_ajax)&&obj.__esModule?obj:{default:obj},Notification=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(Notification);_exports.getEnrolledCoursesByTimeline=args=>{const request={methodname:"core_course_get_enrolled_courses_by_timeline_classification",args:args};return _ajax.default.call([request])[0]};_exports.setFavouriteCourses=args=>{const request={methodname:"core_course_set_favourite_courses",args:args};return _ajax.default.call([request])[0]};_exports.updateUserPreferences=args=>{const request={methodname:"core_user_update_user_preferences",args:args};_ajax.default.call([request])[0].fail(Notification.exception)}}));
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.setFavouriteCourses=_exports.getEnrolledCoursesByTimeline=void 0,_ajax=(obj=_ajax)&&obj.__esModule?obj:{default:obj};_exports.getEnrolledCoursesByTimeline=args=>{const request={methodname:"core_course_get_enrolled_courses_by_timeline_classification",args:args};return _ajax.default.call([request])[0]};_exports.setFavouriteCourses=args=>{const request={methodname:"core_course_set_favourite_courses",args:args};return _ajax.default.call([request])[0]}}));
|
||||
|
||||
//# sourceMappingURL=repository.min.js.map
|
@ -1 +1 @@
|
||||
{"version":3,"file":"repository.min.js","sources":["../src/repository.js"],"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 * A javascript module to retrieve enrolled coruses from the server.\n *\n * @module block_myoverview/repository\n * @copyright 2018 Bas Brands <base@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\nimport * as Notification from 'core/notification';\n\n/**\n * Retrieve a list of enrolled courses.\n *\n * Valid args are:\n * string classification future, inprogress, past\n * int limit number of records to retreive\n * int Offset offset for pagination\n * int sort sort by lastaccess or name\n *\n * @method getEnrolledCoursesByTimeline\n * @param {object} args The request arguments\n * @return {promise} Resolved with an array of courses\n */\nexport const getEnrolledCoursesByTimeline = args => {\n const request = {\n methodname: 'core_course_get_enrolled_courses_by_timeline_classification',\n args: args\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Set the favourite state on a list of courses.\n *\n * Valid args are:\n * Array courses list of course id numbers.\n *\n * @param {Object} args Arguments send to the webservice.\n * @return {Promise} Resolve with warnings.\n */\nexport const setFavouriteCourses = args => {\n const request = {\n methodname: 'core_course_set_favourite_courses',\n args: args\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Update the user preferences.\n *\n * @param {Object} args Arguments send to the webservice.\n *\n * Sample args:\n * {\n * preferences: [\n * {\n * type: 'block_example_user_sort_preference'\n * value: 'title'\n * }\n * ]\n * }\n */\nexport const updateUserPreferences = args => {\n const request = {\n methodname: 'core_user_update_user_preferences',\n args: args\n };\n\n Ajax.call([request])[0]\n .fail(Notification.exception);\n};\n"],"names":["args","request","methodname","Ajax","call","fail","Notification","exception"],"mappings":";;;;;;;2rCAuC4CA,aAClCC,QAAU,CACZC,WAAY,8DACZF,KAAMA,aAGHG,cAAKC,KAAK,CAACH,UAAU,iCAYGD,aACzBC,QAAU,CACZC,WAAY,oCACZF,KAAMA,aAGHG,cAAKC,KAAK,CAACH,UAAU,mCAkBKD,aAC3BC,QAAU,CACZC,WAAY,oCACZF,KAAMA,oBAGLI,KAAK,CAACH,UAAU,GAChBI,KAAKC,aAAaC"}
|
||||
{"version":3,"file":"repository.min.js","sources":["../src/repository.js"],"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 * A javascript module to retrieve enrolled coruses from the server.\n *\n * @module block_myoverview/repository\n * @copyright 2018 Bas Brands <base@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n/**\n * Retrieve a list of enrolled courses.\n *\n * Valid args are:\n * string classification future, inprogress, past\n * int limit number of records to retreive\n * int Offset offset for pagination\n * int sort sort by lastaccess or name\n *\n * @method getEnrolledCoursesByTimeline\n * @param {object} args The request arguments\n * @return {promise} Resolved with an array of courses\n */\nexport const getEnrolledCoursesByTimeline = args => {\n const request = {\n methodname: 'core_course_get_enrolled_courses_by_timeline_classification',\n args: args\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Set the favourite state on a list of courses.\n *\n * Valid args are:\n * Array courses list of course id numbers.\n *\n * @param {Object} args Arguments send to the webservice.\n * @return {Promise} Resolve with warnings.\n */\nexport const setFavouriteCourses = args => {\n const request = {\n methodname: 'core_course_set_favourite_courses',\n args: args\n };\n\n return Ajax.call([request])[0];\n};\n"],"names":["args","request","methodname","Ajax","call"],"mappings":";;;;;;;iOAsC4CA,aAClCC,QAAU,CACZC,WAAY,8DACZF,KAAMA,aAGHG,cAAKC,KAAK,CAACH,UAAU,iCAYGD,aACzBC,QAAU,CACZC,WAAY,oCACZF,KAAMA,aAGHG,cAAKC,KAAK,CAACH,UAAU"}
|
4
blocks/myoverview/amd/build/view.min.js
vendored
4
blocks/myoverview/amd/build/view.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
4
blocks/myoverview/amd/build/view_nav.min.js
vendored
4
blocks/myoverview/amd/build/view_nav.min.js
vendored
@ -1,9 +1,9 @@
|
||||
define("block_myoverview/view_nav",["exports","jquery","core/custom_interaction_events","block_myoverview/repository","block_myoverview/view","block_myoverview/selectors"],(function(_exports,_jquery,CustomEvents,Repository,View,_selectors){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
|
||||
define("block_myoverview/view_nav",["exports","jquery","core/custom_interaction_events","core/notification","core_user/repository","block_myoverview/view","block_myoverview/selectors"],(function(_exports,_jquery,CustomEvents,_notification,_repository,View,_selectors){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
|
||||
/**
|
||||
* Manage the timeline view navigation for the overview block.
|
||||
*
|
||||
* @copyright 2018 Bas Brands <bas@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),CustomEvents=_interopRequireWildcard(CustomEvents),Repository=_interopRequireWildcard(Repository),View=_interopRequireWildcard(View),_selectors=_interopRequireDefault(_selectors);const updatePreferences=(filter,value)=>{let type=null;type="display"===filter?"block_myoverview_user_view_preference":"sort"===filter?"block_myoverview_user_sort_preference":"customfieldvalue"===filter?"block_myoverview_user_grouping_customfieldvalue_preference":"block_myoverview_user_grouping_preference",Repository.updateUserPreferences({preferences:[{type:type,value:value}]})};_exports.init=root=>{(root=>{const Selector=root.find(_selectors.default.FILTERS);CustomEvents.define(Selector,[CustomEvents.events.activate]),Selector.on(CustomEvents.events.activate,_selectors.default.FILTER_OPTION,((e,data)=>{const option=(0,_jquery.default)(e.target);if(option.hasClass("active"))return;const filter=option.attr("data-filter"),pref=option.attr("data-pref"),customfieldvalue=option.attr("data-customfieldvalue");root.find(_selectors.default.courseView.region).attr("data-"+filter,option.attr("data-value")),updatePreferences(filter,pref),customfieldvalue&&(root.find(_selectors.default.courseView.region).attr("data-customfieldvalue",customfieldvalue),updatePreferences("customfieldvalue",customfieldvalue));const page=document.querySelector(_selectors.default.region.selectBlock),input=page.querySelector(_selectors.default.region.searchInput);if(""!==input.value){const clearIcon=page.querySelector(_selectors.default.region.clearIcon);input.value="",View.clearSearch(clearIcon,root)}else View.init(root);data.originalEvent.preventDefault()})),Selector.on(CustomEvents.events.activate,_selectors.default.DISPLAY_OPTION,((e,data)=>{const option=(0,_jquery.default)(e.target);if(option.hasClass("active"))return;const filter=option.attr("data-display-option"),pref=option.attr("data-pref");root.find(_selectors.default.courseView.region).attr("data-display",option.attr("data-value")),updatePreferences(filter,pref),View.reset(root),data.originalEvent.preventDefault()}))})(root=(0,_jquery.default)(root))}}));
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),CustomEvents=_interopRequireWildcard(CustomEvents),_notification=_interopRequireDefault(_notification),View=_interopRequireWildcard(View),_selectors=_interopRequireDefault(_selectors);const updatePreferences=(filter,value)=>{let type=null;return type="display"===filter?"block_myoverview_user_view_preference":"sort"===filter?"block_myoverview_user_sort_preference":"customfieldvalue"===filter?"block_myoverview_user_grouping_customfieldvalue_preference":"block_myoverview_user_grouping_preference",(0,_repository.setUserPreference)(type,value).catch(_notification.default.exception)};_exports.init=root=>{(root=>{const Selector=root.find(_selectors.default.FILTERS);CustomEvents.define(Selector,[CustomEvents.events.activate]),Selector.on(CustomEvents.events.activate,_selectors.default.FILTER_OPTION,((e,data)=>{const option=(0,_jquery.default)(e.target);if(option.hasClass("active"))return;const filter=option.attr("data-filter"),pref=option.attr("data-pref"),customfieldvalue=option.attr("data-customfieldvalue");root.find(_selectors.default.courseView.region).attr("data-"+filter,option.attr("data-value")),updatePreferences(filter,pref),customfieldvalue&&(root.find(_selectors.default.courseView.region).attr("data-customfieldvalue",customfieldvalue),updatePreferences("customfieldvalue",customfieldvalue));const page=document.querySelector(_selectors.default.region.selectBlock),input=page.querySelector(_selectors.default.region.searchInput);if(""!==input.value){const clearIcon=page.querySelector(_selectors.default.region.clearIcon);input.value="",View.clearSearch(clearIcon,root)}else View.init(root);data.originalEvent.preventDefault()})),Selector.on(CustomEvents.events.activate,_selectors.default.DISPLAY_OPTION,((e,data)=>{const option=(0,_jquery.default)(e.target);if(option.hasClass("active"))return;const filter=option.attr("data-display-option"),pref=option.attr("data-pref");root.find(_selectors.default.courseView.region).attr("data-display",option.attr("data-value")),updatePreferences(filter,pref),View.reset(root),data.originalEvent.preventDefault()}))})(root=(0,_jquery.default)(root))}}));
|
||||
|
||||
//# sourceMappingURL=view_nav.min.js.map
|
File diff suppressed because one or more lines are too long
@ -22,7 +22,6 @@
|
||||
*/
|
||||
|
||||
import Ajax from 'core/ajax';
|
||||
import * as Notification from 'core/notification';
|
||||
|
||||
/**
|
||||
* Retrieve a list of enrolled courses.
|
||||
@ -63,28 +62,3 @@ export const setFavouriteCourses = args => {
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the user preferences.
|
||||
*
|
||||
* @param {Object} args Arguments send to the webservice.
|
||||
*
|
||||
* Sample args:
|
||||
* {
|
||||
* preferences: [
|
||||
* {
|
||||
* type: 'block_example_user_sort_preference'
|
||||
* value: 'title'
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
export const updateUserPreferences = args => {
|
||||
const request = {
|
||||
methodname: 'core_user_update_user_preferences',
|
||||
args: args
|
||||
};
|
||||
|
||||
Ajax.call([request])[0]
|
||||
.fail(Notification.exception);
|
||||
};
|
||||
|
@ -32,6 +32,7 @@ import SELECTORS from 'block_myoverview/selectors';
|
||||
import * as PagedContentEvents from 'core/paged_content_events';
|
||||
import * as Aria from 'core/aria';
|
||||
import {debounce} from 'core/utils';
|
||||
import {setUserPreference} from 'core_user/repository';
|
||||
|
||||
const TEMPLATES = {
|
||||
COURSES_CARDS: 'block_myoverview/view-cards',
|
||||
@ -343,14 +344,9 @@ const setCourseHiddenState = (courseId, status) => {
|
||||
if (status === false) {
|
||||
status = null;
|
||||
}
|
||||
return Repository.updateUserPreferences({
|
||||
preferences: [
|
||||
{
|
||||
type: 'block_myoverview_hidden_course_' + courseId,
|
||||
value: status
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
return setUserPreference(`block_myoverview_hidden_course_${courseId}`, status)
|
||||
.catch(Notification.exception);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -22,7 +22,8 @@
|
||||
|
||||
import $ from 'jquery';
|
||||
import * as CustomEvents from 'core/custom_interaction_events';
|
||||
import * as Repository from 'block_myoverview/repository';
|
||||
import Notification from 'core/notification';
|
||||
import {setUserPreference} from 'core_user/repository';
|
||||
import * as View from 'block_myoverview/view';
|
||||
import SELECTORS from 'block_myoverview/selectors';
|
||||
|
||||
@ -31,6 +32,7 @@ import SELECTORS from 'block_myoverview/selectors';
|
||||
*
|
||||
* @param {String} filter The type of filter: display/sort/grouping.
|
||||
* @param {String} value The current preferred value.
|
||||
* @return {Promise}
|
||||
*/
|
||||
const updatePreferences = (filter, value) => {
|
||||
let type = null;
|
||||
@ -44,14 +46,8 @@ const updatePreferences = (filter, value) => {
|
||||
type = 'block_myoverview_user_grouping_preference';
|
||||
}
|
||||
|
||||
Repository.updateUserPreferences({
|
||||
preferences: [
|
||||
{
|
||||
type: type,
|
||||
value: value
|
||||
}
|
||||
]
|
||||
});
|
||||
return setUserPreference(type, value)
|
||||
.catch(Notification.exception);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1,11 +1,11 @@
|
||||
define("block_online_users/change_user_visibility",["exports","core/str","core/notification","core_user/repository"],(function(_exports,_str,_notification,_repository){var obj;
|
||||
/**
|
||||
* A javascript module that handles the change of the user's visibility in the
|
||||
* online users block.
|
||||
*
|
||||
* @module block_online_users/change_user_visibility
|
||||
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define("block_online_users/change_user_visibility",["jquery","core/ajax","core/str","core/notification"],(function($,Ajax,Str,Notification){var SELECTORS_CHANGE_VISIBILITY_LINK="#change-user-visibility",SELECTORS_CHANGE_VISIBILITY_ICON="#change-user-visibility .icon",oppositeAction=function(action){return"show"==action?"hide":"show"},changeVisibilityLinkAttr=function(action){getTitle(action).then((function(title){$(SELECTORS_CHANGE_VISIBILITY_LINK).attr({"data-action":action,title:title})})).catch(Notification.exception)},changeVisibilityIconAttr=function(action){var icon=$(SELECTORS_CHANGE_VISIBILITY_ICON);getTitle(action).then((function(title){$(icon).attr({title:title,"aria-label":title}),icon.is("img")?$(icon).attr({src:M.util.image_url("t/"+action),alt:title}):($(icon).addClass(getIconClass(action)),$(icon).removeClass(getIconClass(oppositeAction(action))))})).catch(Notification.exception)},getIconClass=function(action){return"show"==action?"fa-eye-slash":"fa-eye"},getTitle=function(action){return Str.get_string("online_status:"+action,"block_online_users")};return{init:function(){$(SELECTORS_CHANGE_VISIBILITY_LINK).on("click",(function(e){e.preventDefault(),function(action,userid){var request={methodname:"core_user_set_user_preferences",args:{preferences:[{name:"block_online_users_uservisibility",value:"show"==action?1:0,userid:userid}]}};Ajax.call([request])[0].then((function(data){if(data.saved){var newAction=oppositeAction(action);changeVisibilityLinkAttr(newAction),changeVisibilityIconAttr(newAction)}})).catch(Notification.exception)}($(this).attr("data-action"),$(this).attr("data-userid"))}))}}}));
|
||||
* A javascript module that handles the change of the user's visibility in the
|
||||
* online users block.
|
||||
*
|
||||
* @module block_online_users/change_user_visibility
|
||||
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_notification=(obj=_notification)&&obj.__esModule?obj:{default:obj};const SELECTORS_CHANGE_VISIBILITY_LINK="#change-user-visibility",SELECTORS_CHANGE_VISIBILITY_ICON="#change-user-visibility .icon",oppositeAction=action=>"show"==action?"hide":"show",changeVisibilityLinkAttr=action=>getTitle(action).then((title=>{const link=document.querySelector(SELECTORS_CHANGE_VISIBILITY_LINK);return link.dataset.action=action,link.title=title,link})),changeVisibilityIconAttr=action=>getTitle(action).then((title=>{const icon=document.querySelector(SELECTORS_CHANGE_VISIBILITY_ICON);return icon.setAttribute("title",title),icon.setAttribute("aria-label",title),icon.closest("img")?(icon.setAttribute("src",M.util.image_url("t/".concat(action))),icon.setAttribute("alt",title)):(icon.classList.add(getIconClass(action)),icon.classList.remove(getIconClass(oppositeAction(action)))),title})),getIconClass=action=>"show"==action?"fa-eye-slash":"fa-eye",getTitle=action=>(0,_str.get_string)("online_status:".concat(action),"block_online_users");_exports.init=()=>{document.addEventListener("click",(e=>{const link=e.target.closest(SELECTORS_CHANGE_VISIBILITY_LINK);var action,userid;link&&(e.preventDefault(),action=link.dataset.action,userid=link.dataset.userid,(0,_repository.setUserPreference)("block_online_users_uservisibility","show"==action?1:0,userid).then((data=>{if(data.saved){const newAction=oppositeAction(action);changeVisibilityLinkAttr(newAction),changeVisibilityIconAttr(newAction)}return data})).catch(_notification.default.exception))}))}}));
|
||||
|
||||
//# sourceMappingURL=change_user_visibility.min.js.map
|
File diff suppressed because one or more lines are too long
@ -21,150 +21,134 @@
|
||||
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define(['jquery', 'core/ajax', 'core/str', 'core/notification'],
|
||||
function($, Ajax, Str, Notification) {
|
||||
|
||||
/**
|
||||
* Selectors.
|
||||
*
|
||||
* @access private
|
||||
* @type {Object}
|
||||
*/
|
||||
var SELECTORS = {
|
||||
CHANGE_VISIBILITY_LINK: '#change-user-visibility',
|
||||
CHANGE_VISIBILITY_ICON: '#change-user-visibility .icon'
|
||||
};
|
||||
import {get_string as getString} from 'core/str';
|
||||
import Notification from 'core/notification';
|
||||
import {setUserPreference} from 'core_user/repository';
|
||||
|
||||
/**
|
||||
* Change user visibility in the online users block.
|
||||
*
|
||||
* @method changeVisibility
|
||||
* @param {String} action
|
||||
* @param {String} userid
|
||||
* @private
|
||||
*/
|
||||
var changeVisibility = function(action, userid) {
|
||||
/**
|
||||
* Selectors.
|
||||
*
|
||||
* @access private
|
||||
* @type {Object}
|
||||
*/
|
||||
const SELECTORS = {
|
||||
CHANGE_VISIBILITY_LINK: '#change-user-visibility',
|
||||
CHANGE_VISIBILITY_ICON: '#change-user-visibility .icon',
|
||||
};
|
||||
|
||||
var value = action == "show" ? 1 : 0;
|
||||
var preferences = [{
|
||||
'name': 'block_online_users_uservisibility',
|
||||
'value': value,
|
||||
'userid': userid
|
||||
}];
|
||||
/**
|
||||
* Change user visibility in the online users block.
|
||||
*
|
||||
* @method changeVisibility
|
||||
* @param {String} action
|
||||
* @param {String} userid
|
||||
* @returns {Promise}
|
||||
* @private
|
||||
*/
|
||||
const changeVisibility = (action, userid) => setUserPreference(
|
||||
'block_online_users_uservisibility',
|
||||
action == "show" ? 1 : 0,
|
||||
userid,
|
||||
)
|
||||
.then((data) => {
|
||||
if (data.saved) {
|
||||
const newAction = oppositeAction(action);
|
||||
changeVisibilityLinkAttr(newAction);
|
||||
changeVisibilityIconAttr(newAction);
|
||||
}
|
||||
return data;
|
||||
}).catch(Notification.exception);
|
||||
|
||||
var request = {
|
||||
methodname: 'core_user_set_user_preferences',
|
||||
args: {
|
||||
preferences: preferences
|
||||
}
|
||||
};
|
||||
Ajax.call([request])[0].then(function(data) {
|
||||
if (data.saved) {
|
||||
var newAction = oppositeAction(action);
|
||||
changeVisibilityLinkAttr(newAction);
|
||||
changeVisibilityIconAttr(newAction);
|
||||
}
|
||||
return;
|
||||
}).catch(Notification.exception);
|
||||
};
|
||||
/**
|
||||
* Get the opposite action.
|
||||
*
|
||||
* @method oppositeAction
|
||||
* @param {String} action
|
||||
* @return {String}
|
||||
* @private
|
||||
*/
|
||||
const oppositeAction = (action) => action == 'show' ? 'hide' : 'show';
|
||||
|
||||
/**
|
||||
* Get the opposite action.
|
||||
*
|
||||
* @method oppositeAction
|
||||
* @param {String} action
|
||||
* @return {String}
|
||||
* @private
|
||||
*/
|
||||
var oppositeAction = function(action) {
|
||||
return action == 'show' ? 'hide' : 'show';
|
||||
};
|
||||
/**
|
||||
* Change the attribute values of the user visibility link in the online users block.
|
||||
*
|
||||
* @method changeVisibilityLinkAttr
|
||||
* @param {String} action
|
||||
* @returns {Promise}
|
||||
* @private
|
||||
*/
|
||||
const changeVisibilityLinkAttr = (action) => getTitle(action)
|
||||
.then((title) => {
|
||||
const link = document.querySelector(SELECTORS.CHANGE_VISIBILITY_LINK);
|
||||
link.dataset.action = action;
|
||||
link.title = title;
|
||||
return link;
|
||||
});
|
||||
|
||||
/**
|
||||
* Change the attribute values of the user visibility link in the online users block.
|
||||
*
|
||||
* @method changeVisibilityLinkAttr
|
||||
* @param {String} action
|
||||
* @private
|
||||
*/
|
||||
var changeVisibilityLinkAttr = function(action) {
|
||||
getTitle(action).then(function(title) {
|
||||
$(SELECTORS.CHANGE_VISIBILITY_LINK).attr({
|
||||
'data-action': action,
|
||||
'title': title
|
||||
});
|
||||
return;
|
||||
}).catch(Notification.exception);
|
||||
};
|
||||
/**
|
||||
* Change the attribute values of the user visibility icon in the online users block.
|
||||
*
|
||||
* @method changeVisibilityIconAttr
|
||||
* @param {String} action
|
||||
* @returns {Promise}
|
||||
* @private
|
||||
*/
|
||||
const changeVisibilityIconAttr = (action) => getTitle(action)
|
||||
.then((title) => {
|
||||
const icon = document.querySelector(SELECTORS.CHANGE_VISIBILITY_ICON);
|
||||
|
||||
/**
|
||||
* Change the attribute values of the user visibility icon in the online users block.
|
||||
*
|
||||
* @method changeVisibilityIconAttr
|
||||
* @param {String} action
|
||||
* @private
|
||||
*/
|
||||
var changeVisibilityIconAttr = function(action) {
|
||||
var icon = $(SELECTORS.CHANGE_VISIBILITY_ICON);
|
||||
getTitle(action).then(function(title) {
|
||||
// Add the proper title to the icon.
|
||||
$(icon).attr({
|
||||
'title': title,
|
||||
'aria-label': title
|
||||
});
|
||||
// Add the proper title to the icon.
|
||||
icon.setAttribute('title', title);
|
||||
icon.setAttribute('aria-label', title);
|
||||
|
||||
if (icon.closest("img")) {
|
||||
// If the icon is an image.
|
||||
if (icon.is("img")) {
|
||||
$(icon).attr({
|
||||
'src': M.util.image_url('t/' + action),
|
||||
'alt': title
|
||||
});
|
||||
} else {
|
||||
// Add the new icon class and remove the old one.
|
||||
$(icon).addClass(getIconClass(action));
|
||||
$(icon).removeClass(getIconClass(oppositeAction(action)));
|
||||
}
|
||||
return;
|
||||
}).catch(Notification.exception);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the proper class for the user visibility icon in the online users block.
|
||||
*
|
||||
* @method getIconClass
|
||||
* @param {String} action
|
||||
* @return {String}
|
||||
* @private
|
||||
*/
|
||||
var getIconClass = function(action) {
|
||||
return action == 'show' ? 'fa-eye-slash' : 'fa-eye';
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the title description of the user visibility link in the online users block.
|
||||
*
|
||||
* @method getTitle
|
||||
* @param {String} action
|
||||
* @return {object} jQuery promise
|
||||
* @private
|
||||
*/
|
||||
var getTitle = function(action) {
|
||||
return Str.get_string('online_status:' + action, 'block_online_users');
|
||||
};
|
||||
|
||||
return {
|
||||
// Public variables and functions.
|
||||
/**
|
||||
* Initialise change user visibility function.
|
||||
*
|
||||
* @method init
|
||||
*/
|
||||
init: function() {
|
||||
$(SELECTORS.CHANGE_VISIBILITY_LINK).on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var action = ($(this).attr('data-action'));
|
||||
var userid = ($(this).attr('data-userid'));
|
||||
changeVisibility(action, userid);
|
||||
});
|
||||
icon.setAttribute('src', M.util.image_url(`t/${action}`));
|
||||
icon.setAttribute('alt', title);
|
||||
} else {
|
||||
// Add the new icon class and remove the old one.
|
||||
icon.classList.add(getIconClass(action));
|
||||
icon.classList.remove(getIconClass(oppositeAction(action)));
|
||||
}
|
||||
};
|
||||
});
|
||||
return title;
|
||||
});
|
||||
|
||||
/**
|
||||
* Get the proper class for the user visibility icon in the online users block.
|
||||
*
|
||||
* @method getIconClass
|
||||
* @param {String} action
|
||||
* @return {String}
|
||||
* @private
|
||||
*/
|
||||
const getIconClass = (action) => (action == 'show') ? 'fa-eye-slash' : 'fa-eye';
|
||||
|
||||
/**
|
||||
* Get the title description of the user visibility link in the online users block.
|
||||
*
|
||||
* @method getTitle
|
||||
* @param {String} action
|
||||
* @return {object} jQuery promise
|
||||
* @private
|
||||
*/
|
||||
const getTitle = (action) => getString(`online_status:${action}`, 'block_online_users');
|
||||
|
||||
/**
|
||||
* Initialise change user visibility function.
|
||||
*
|
||||
* @method init
|
||||
*/
|
||||
export const init = () => {
|
||||
document.addEventListener('click', (e) => {
|
||||
const link = e.target.closest(SELECTORS.CHANGE_VISIBILITY_LINK);
|
||||
if (!link) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
changeVisibility(
|
||||
link.dataset.action,
|
||||
link.dataset.userid,
|
||||
);
|
||||
});
|
||||
};
|
||||
|
12
blocks/timeline/amd/build/view_nav.min.js
vendored
12
blocks/timeline/amd/build/view_nav.min.js
vendored
@ -1,9 +1,9 @@
|
||||
define("block_timeline/view_nav",["exports","jquery","core/custom_interaction_events","block_timeline/view","core/notification","core/utils","core_user/repository"],(function(_exports,_jquery,CustomEvents,View,Notification,Utils,UserRepository){var obj;
|
||||
/**
|
||||
* Manage the timeline view navigation for the timeline block.
|
||||
*
|
||||
* @copyright 2018 Ryan Wyllie <ryan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define("block_timeline/view_nav",["jquery","core/custom_interaction_events","block_timeline/view","core/ajax","core/notification","core/utils"],(function($,CustomEvents,View,Ajax,Notification,Utils){var SELECTORS_TIMELINE_DAY_FILTER='[data-region="day-filter"]',SELECTORS_TIMELINE_DAY_FILTER_OPTION="[data-from]",SELECTORS_TIMELINE_VIEW_SELECTOR='[data-region="view-selector"]',SELECTORS_DATA_DAYS_OFFSET="[data-days-offset]",SELECTORS_TIMELINE_SEARCH_INPUT='[data-action="search"]',SELECTORS_TIMELINE_SEARCH_CLEAR_ICON='[data-action="clearsearch"]',SELECTORS_NO_COURSES_EMPTY_MESSAGE='[data-region="no-courses-empty-message"]',updateUserPreferences=function(type,value){var request={methodname:"core_user_update_user_preferences",args:{preferences:[{type:type,value:value}]}};Ajax.call([request])[0].fail(Notification.exception)};const activeSearchState=(clearSearchIcon,timelineViewRoot)=>{clearSearchIcon.removeClass("d-none"),View.reset(timelineViewRoot)},clearSearchState=(clearSearchIcon,timelineViewRoot)=>{clearSearchIcon.addClass("d-none"),View.reset(timelineViewRoot)};return{init:function(root,timelineViewRoot){(function(root,timelineViewRoot){var viewSelector=root.find(SELECTORS_TIMELINE_VIEW_SELECTOR);viewSelector.on("shown shown.bs.tab",(function(e){View.shown(timelineViewRoot),$(e.target).removeClass("active")})),CustomEvents.define(viewSelector,[CustomEvents.events.activate]),viewSelector.on(CustomEvents.events.activate,"[data-toggle='tab']",(function(e){var filtername=$(e.currentTarget).data("filtername");updateUserPreferences("block_timeline_user_sort_preference",filtername)}))})(root=$(root),timelineViewRoot),root.find(SELECTORS_NO_COURSES_EMPTY_MESSAGE).length||(function(root,timelineViewRoot){var timelineDaySelectorContainer=root.find(SELECTORS_TIMELINE_DAY_FILTER);CustomEvents.define(timelineDaySelectorContainer,[CustomEvents.events.activate]),timelineDaySelectorContainer.on(CustomEvents.events.activate,SELECTORS_TIMELINE_DAY_FILTER_OPTION,(function(e,data){var filtername=$(e.currentTarget).data("filtername");updateUserPreferences("block_timeline_user_filter_preference",filtername);var option=$(e.target).closest(SELECTORS_TIMELINE_DAY_FILTER_OPTION);if("true"!=option.attr("aria-current")){var daysOffset=option.attr("data-from"),daysLimit=option.attr("data-to"),elementsWithDaysOffset=root.find(SELECTORS_DATA_DAYS_OFFSET);elementsWithDaysOffset.attr("data-days-offset",daysOffset),null!=daysLimit?elementsWithDaysOffset.attr("data-days-limit",daysLimit):elementsWithDaysOffset.removeAttr("data-days-limit"),"overdue"===option.attr("data-filtername")?elementsWithDaysOffset.attr("data-filter-overdue",!0):elementsWithDaysOffset.removeAttr("data-filter-overdue"),View.reset(timelineViewRoot),data.originalEvent.preventDefault()}}))}(root,timelineViewRoot),((root,timelineViewRoot)=>{const searchInput=root.find(SELECTORS_TIMELINE_SEARCH_INPUT),clearSearchIcon=root.find(SELECTORS_TIMELINE_SEARCH_CLEAR_ICON);searchInput.on("input",Utils.debounce((()=>{""!==searchInput.val()?activeSearchState(clearSearchIcon,timelineViewRoot):clearSearchState(clearSearchIcon,timelineViewRoot)}),1e3)),clearSearchIcon.on("click",(()=>{searchInput.val(""),clearSearchState(clearSearchIcon,timelineViewRoot),searchInput.focus()}))})(root,timelineViewRoot))}}}));
|
||||
* Manage the timeline view navigation for the timeline block.
|
||||
*
|
||||
* @copyright 2018 Ryan Wyllie <ryan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=(obj=_jquery)&&obj.__esModule?obj:{default:obj},CustomEvents=_interopRequireWildcard(CustomEvents),View=_interopRequireWildcard(View),Notification=_interopRequireWildcard(Notification),Utils=_interopRequireWildcard(Utils),UserRepository=_interopRequireWildcard(UserRepository);const SELECTORS_TIMELINE_DAY_FILTER='[data-region="day-filter"]',SELECTORS_TIMELINE_DAY_FILTER_OPTION="[data-from]",SELECTORS_TIMELINE_VIEW_SELECTOR='[data-region="view-selector"]',SELECTORS_DATA_DAYS_OFFSET="[data-days-offset]",SELECTORS_TIMELINE_SEARCH_INPUT='[data-action="search"]',SELECTORS_TIMELINE_SEARCH_CLEAR_ICON='[data-action="clearsearch"]',SELECTORS_NO_COURSES_EMPTY_MESSAGE='[data-region="no-courses-empty-message"]',activeSearchState=(clearSearchIcon,timelineViewRoot)=>{clearSearchIcon.removeClass("d-none"),View.reset(timelineViewRoot)},clearSearchState=(clearSearchIcon,timelineViewRoot)=>{clearSearchIcon.addClass("d-none"),View.reset(timelineViewRoot)};_exports.init=function(root,timelineViewRoot){(function(root,timelineViewRoot){const viewSelector=root.find(SELECTORS_TIMELINE_VIEW_SELECTOR);viewSelector.on("shown shown.bs.tab",(function(e){View.shown(timelineViewRoot),(0,_jquery.default)(e.target).removeClass("active")})),CustomEvents.define(viewSelector,[CustomEvents.events.activate]),viewSelector.on(CustomEvents.events.activate,"[data-toggle='tab']",(function(e){var filtername=(0,_jquery.default)(e.currentTarget).data("filtername");UserRepository.setUserPreference("block_timeline_user_sort_preference",filtername).catch(Notification.exception)}))})(root=(0,_jquery.default)(root),timelineViewRoot),root.find(SELECTORS_NO_COURSES_EMPTY_MESSAGE).length||(function(root,timelineViewRoot){const timelineDaySelectorContainer=root.find(SELECTORS_TIMELINE_DAY_FILTER);CustomEvents.define(timelineDaySelectorContainer,[CustomEvents.events.activate]),timelineDaySelectorContainer.on(CustomEvents.events.activate,SELECTORS_TIMELINE_DAY_FILTER_OPTION,(function(e,data){var filtername=(0,_jquery.default)(e.currentTarget).data("filtername");UserRepository.setUserPreference("block_timeline_user_filter_preference",filtername).catch(Notification.exception);var option=(0,_jquery.default)(e.target).closest(SELECTORS_TIMELINE_DAY_FILTER_OPTION);if("true"!=option.attr("aria-current")){var daysOffset=option.attr("data-from"),daysLimit=option.attr("data-to"),elementsWithDaysOffset=root.find(SELECTORS_DATA_DAYS_OFFSET);elementsWithDaysOffset.attr("data-days-offset",daysOffset),null!=daysLimit?elementsWithDaysOffset.attr("data-days-limit",daysLimit):elementsWithDaysOffset.removeAttr("data-days-limit"),"overdue"===option.attr("data-filtername")?elementsWithDaysOffset.attr("data-filter-overdue",!0):elementsWithDaysOffset.removeAttr("data-filter-overdue"),View.reset(timelineViewRoot),data.originalEvent.preventDefault()}}))}(root,timelineViewRoot),((root,timelineViewRoot)=>{const searchInput=root.find(SELECTORS_TIMELINE_SEARCH_INPUT),clearSearchIcon=root.find(SELECTORS_TIMELINE_SEARCH_CLEAR_ICON);searchInput.on("input",Utils.debounce((()=>{""!==searchInput.val()?activeSearchState(clearSearchIcon,timelineViewRoot):clearSearchState(clearSearchIcon,timelineViewRoot)}),1e3)),clearSearchIcon.on("click",(()=>{searchInput.val(""),clearSearchState(clearSearchIcon,timelineViewRoot),searchInput.focus()}))})(root,timelineViewRoot))}}));
|
||||
|
||||
//# sourceMappingURL=view_nav.min.js.map
|
File diff suppressed because one or more lines are too long
@ -20,207 +20,170 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
define(
|
||||
[
|
||||
'jquery',
|
||||
'core/custom_interaction_events',
|
||||
'block_timeline/view',
|
||||
'core/ajax',
|
||||
'core/notification',
|
||||
'core/utils'
|
||||
],
|
||||
function(
|
||||
$,
|
||||
CustomEvents,
|
||||
View,
|
||||
Ajax,
|
||||
Notification,
|
||||
Utils
|
||||
) {
|
||||
import $ from 'jquery';
|
||||
import * as CustomEvents from 'core/custom_interaction_events';
|
||||
import * as View from 'block_timeline/view';
|
||||
import * as Notification from 'core/notification';
|
||||
import * as Utils from 'core/utils';
|
||||
import * as UserRepository from 'core_user/repository';
|
||||
|
||||
var SELECTORS = {
|
||||
TIMELINE_DAY_FILTER: '[data-region="day-filter"]',
|
||||
TIMELINE_DAY_FILTER_OPTION: '[data-from]',
|
||||
TIMELINE_VIEW_SELECTOR: '[data-region="view-selector"]',
|
||||
DATA_DAYS_OFFSET: '[data-days-offset]',
|
||||
DATA_DAYS_LIMIT: '[data-days-limit]',
|
||||
TIMELINE_SEARCH_INPUT: '[data-action="search"]',
|
||||
TIMELINE_SEARCH_CLEAR_ICON: '[data-action="clearsearch"]',
|
||||
NO_COURSES_EMPTY_MESSAGE: '[data-region="no-courses-empty-message"]',
|
||||
};
|
||||
const SELECTORS = {
|
||||
TIMELINE_DAY_FILTER: '[data-region="day-filter"]',
|
||||
TIMELINE_DAY_FILTER_OPTION: '[data-from]',
|
||||
TIMELINE_VIEW_SELECTOR: '[data-region="view-selector"]',
|
||||
DATA_DAYS_OFFSET: '[data-days-offset]',
|
||||
DATA_DAYS_LIMIT: '[data-days-limit]',
|
||||
TIMELINE_SEARCH_INPUT: '[data-action="search"]',
|
||||
TIMELINE_SEARCH_CLEAR_ICON: '[data-action="clearsearch"]',
|
||||
NO_COURSES_EMPTY_MESSAGE: '[data-region="no-courses-empty-message"]',
|
||||
};
|
||||
|
||||
/**
|
||||
* Generic handler to persist user preferences
|
||||
*
|
||||
* @param {string} type The name of the attribute you're updating
|
||||
* @param {string} value The value of the attribute you're updating
|
||||
*/
|
||||
var updateUserPreferences = function(type, value) {
|
||||
var request = {
|
||||
methodname: 'core_user_update_user_preferences',
|
||||
args: {
|
||||
preferences: [
|
||||
{
|
||||
type: type,
|
||||
value: value
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Event listener for the day selector ("Next 7 days", "Next 30 days", etc).
|
||||
*
|
||||
* @param {object} root The root element for the timeline block
|
||||
* @param {object} timelineViewRoot The root element for the timeline view
|
||||
*/
|
||||
const registerTimelineDaySelector = function(root, timelineViewRoot) {
|
||||
const timelineDaySelectorContainer = root.find(SELECTORS.TIMELINE_DAY_FILTER);
|
||||
|
||||
Ajax.call([request])[0]
|
||||
.fail(Notification.exception);
|
||||
};
|
||||
|
||||
/**
|
||||
* Event listener for the day selector ("Next 7 days", "Next 30 days", etc).
|
||||
*
|
||||
* @param {object} root The root element for the timeline block
|
||||
* @param {object} timelineViewRoot The root element for the timeline view
|
||||
*/
|
||||
var registerTimelineDaySelector = function(root, timelineViewRoot) {
|
||||
var timelineDaySelectorContainer = root.find(SELECTORS.TIMELINE_DAY_FILTER);
|
||||
|
||||
CustomEvents.define(timelineDaySelectorContainer, [CustomEvents.events.activate]);
|
||||
timelineDaySelectorContainer.on(
|
||||
CustomEvents.events.activate,
|
||||
SELECTORS.TIMELINE_DAY_FILTER_OPTION,
|
||||
function(e, data) {
|
||||
// Update the user preference
|
||||
var filtername = $(e.currentTarget).data('filtername');
|
||||
var type = 'block_timeline_user_filter_preference';
|
||||
updateUserPreferences(type, filtername);
|
||||
|
||||
var option = $(e.target).closest(SELECTORS.TIMELINE_DAY_FILTER_OPTION);
|
||||
|
||||
if (option.attr('aria-current') == 'true') {
|
||||
// If it's already active then we don't need to do anything.
|
||||
return;
|
||||
}
|
||||
|
||||
var daysOffset = option.attr('data-from');
|
||||
var daysLimit = option.attr('data-to');
|
||||
var elementsWithDaysOffset = root.find(SELECTORS.DATA_DAYS_OFFSET);
|
||||
|
||||
elementsWithDaysOffset.attr('data-days-offset', daysOffset);
|
||||
|
||||
if (daysLimit != undefined) {
|
||||
elementsWithDaysOffset.attr('data-days-limit', daysLimit);
|
||||
} else {
|
||||
elementsWithDaysOffset.removeAttr('data-days-limit');
|
||||
}
|
||||
|
||||
if (option.attr('data-filtername') === 'overdue') {
|
||||
elementsWithDaysOffset.attr('data-filter-overdue', true);
|
||||
} else {
|
||||
elementsWithDaysOffset.removeAttr('data-filter-overdue');
|
||||
}
|
||||
|
||||
// Reset the views to reinitialise the event lists now that we've
|
||||
// updated the day limits.
|
||||
View.reset(timelineViewRoot);
|
||||
|
||||
data.originalEvent.preventDefault();
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Event listener for the "sort" button in the timeline navigation that allows for
|
||||
* changing between the timeline dates and courses views.
|
||||
*
|
||||
* On a view change we tell the timeline view module that the view has been shown
|
||||
* so that it can handle how to display the appropriate view.
|
||||
*
|
||||
* @param {object} root The root element for the timeline block
|
||||
* @param {object} timelineViewRoot The root element for the timeline view
|
||||
*/
|
||||
var registerViewSelector = function(root, timelineViewRoot) {
|
||||
var viewSelector = root.find(SELECTORS.TIMELINE_VIEW_SELECTOR);
|
||||
|
||||
// Listen for when the user changes tab so that we can show the first set of courses
|
||||
// and load their events when they request the sort by courses view for the first time.
|
||||
viewSelector.on('shown shown.bs.tab', function(e) {
|
||||
View.shown(timelineViewRoot);
|
||||
$(e.target).removeClass('active');
|
||||
});
|
||||
|
||||
|
||||
// Event selector for user_sort
|
||||
CustomEvents.define(viewSelector, [CustomEvents.events.activate]);
|
||||
viewSelector.on(CustomEvents.events.activate, "[data-toggle='tab']", function(e) {
|
||||
CustomEvents.define(timelineDaySelectorContainer, [CustomEvents.events.activate]);
|
||||
timelineDaySelectorContainer.on(
|
||||
CustomEvents.events.activate,
|
||||
SELECTORS.TIMELINE_DAY_FILTER_OPTION,
|
||||
function(e, data) {
|
||||
// Update the user preference
|
||||
var filtername = $(e.currentTarget).data('filtername');
|
||||
var type = 'block_timeline_user_sort_preference';
|
||||
updateUserPreferences(type, filtername);
|
||||
});
|
||||
};
|
||||
var type = 'block_timeline_user_filter_preference';
|
||||
UserRepository.setUserPreference(type, filtername)
|
||||
.catch(Notification.exception);
|
||||
|
||||
/**
|
||||
* Event listener for the "search" input field in the timeline navigation that allows for
|
||||
* searching the activity name, course name and activity type.
|
||||
*
|
||||
* @param {object} root The root element for the timeline block
|
||||
* @param {object} timelineViewRoot The root element for the timeline view
|
||||
*/
|
||||
const registerSearch = (root, timelineViewRoot) => {
|
||||
const searchInput = root.find(SELECTORS.TIMELINE_SEARCH_INPUT);
|
||||
const clearSearchIcon = root.find(SELECTORS.TIMELINE_SEARCH_CLEAR_ICON);
|
||||
searchInput.on('input', Utils.debounce(() => {
|
||||
if (searchInput.val() !== '') {
|
||||
activeSearchState(clearSearchIcon, timelineViewRoot);
|
||||
} else {
|
||||
clearSearchState(clearSearchIcon, timelineViewRoot);
|
||||
var option = $(e.target).closest(SELECTORS.TIMELINE_DAY_FILTER_OPTION);
|
||||
|
||||
if (option.attr('aria-current') == 'true') {
|
||||
// If it's already active then we don't need to do anything.
|
||||
return;
|
||||
}
|
||||
}, 1000));
|
||||
clearSearchIcon.on('click', () => {
|
||||
searchInput.val('');
|
||||
clearSearchState(clearSearchIcon, timelineViewRoot);
|
||||
searchInput.focus();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the clear search icon.
|
||||
*
|
||||
* @param {object} clearSearchIcon Clear search icon element.
|
||||
* @param {object} timelineViewRoot The root element for the timeline view
|
||||
*/
|
||||
const activeSearchState = (clearSearchIcon, timelineViewRoot) => {
|
||||
clearSearchIcon.removeClass('d-none');
|
||||
View.reset(timelineViewRoot);
|
||||
};
|
||||
var daysOffset = option.attr('data-from');
|
||||
var daysLimit = option.attr('data-to');
|
||||
var elementsWithDaysOffset = root.find(SELECTORS.DATA_DAYS_OFFSET);
|
||||
|
||||
/**
|
||||
* Hide the clear search icon.
|
||||
*
|
||||
* @param {object} clearSearchIcon Clear search icon element.
|
||||
* @param {object} timelineViewRoot The root element for the timeline view
|
||||
*/
|
||||
const clearSearchState = (clearSearchIcon, timelineViewRoot) => {
|
||||
clearSearchIcon.addClass('d-none');
|
||||
View.reset(timelineViewRoot);
|
||||
};
|
||||
elementsWithDaysOffset.attr('data-days-offset', daysOffset);
|
||||
|
||||
/**
|
||||
* Initialise the timeline view navigation by adding event listeners to
|
||||
* the navigation elements.
|
||||
*
|
||||
* @param {object} root The root element for the timeline block
|
||||
* @param {object} timelineViewRoot The root element for the timeline view
|
||||
*/
|
||||
var init = function(root, timelineViewRoot) {
|
||||
root = $(root);
|
||||
if (daysLimit != undefined) {
|
||||
elementsWithDaysOffset.attr('data-days-limit', daysLimit);
|
||||
} else {
|
||||
elementsWithDaysOffset.removeAttr('data-days-limit');
|
||||
}
|
||||
|
||||
registerViewSelector(root, timelineViewRoot);
|
||||
if (option.attr('data-filtername') === 'overdue') {
|
||||
elementsWithDaysOffset.attr('data-filter-overdue', true);
|
||||
} else {
|
||||
elementsWithDaysOffset.removeAttr('data-filter-overdue');
|
||||
}
|
||||
|
||||
// Only need to handle filtering if the user is actively enrolled in a course.
|
||||
if (!root.find(SELECTORS.NO_COURSES_EMPTY_MESSAGE).length) {
|
||||
registerTimelineDaySelector(root, timelineViewRoot);
|
||||
registerSearch(root, timelineViewRoot);
|
||||
// Reset the views to reinitialise the event lists now that we've
|
||||
// updated the day limits.
|
||||
View.reset(timelineViewRoot);
|
||||
|
||||
data.originalEvent.preventDefault();
|
||||
}
|
||||
};
|
||||
);
|
||||
};
|
||||
|
||||
return {
|
||||
init: init
|
||||
};
|
||||
});
|
||||
/**
|
||||
* Event listener for the "sort" button in the timeline navigation that allows for
|
||||
* changing between the timeline dates and courses views.
|
||||
*
|
||||
* On a view change we tell the timeline view module that the view has been shown
|
||||
* so that it can handle how to display the appropriate view.
|
||||
*
|
||||
* @param {object} root The root element for the timeline block
|
||||
* @param {object} timelineViewRoot The root element for the timeline view
|
||||
*/
|
||||
const registerViewSelector = function(root, timelineViewRoot) {
|
||||
const viewSelector = root.find(SELECTORS.TIMELINE_VIEW_SELECTOR);
|
||||
|
||||
// Listen for when the user changes tab so that we can show the first set of courses
|
||||
// and load their events when they request the sort by courses view for the first time.
|
||||
viewSelector.on('shown shown.bs.tab', function(e) {
|
||||
View.shown(timelineViewRoot);
|
||||
$(e.target).removeClass('active');
|
||||
});
|
||||
|
||||
|
||||
// Event selector for user_sort
|
||||
CustomEvents.define(viewSelector, [CustomEvents.events.activate]);
|
||||
viewSelector.on(CustomEvents.events.activate, "[data-toggle='tab']", function(e) {
|
||||
var filtername = $(e.currentTarget).data('filtername');
|
||||
var type = 'block_timeline_user_sort_preference';
|
||||
UserRepository.setUserPreference(type, filtername)
|
||||
.catch(Notification.exception);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Event listener for the "search" input field in the timeline navigation that allows for
|
||||
* searching the activity name, course name and activity type.
|
||||
*
|
||||
* @param {object} root The root element for the timeline block
|
||||
* @param {object} timelineViewRoot The root element for the timeline view
|
||||
*/
|
||||
const registerSearch = (root, timelineViewRoot) => {
|
||||
const searchInput = root.find(SELECTORS.TIMELINE_SEARCH_INPUT);
|
||||
const clearSearchIcon = root.find(SELECTORS.TIMELINE_SEARCH_CLEAR_ICON);
|
||||
searchInput.on('input', Utils.debounce(() => {
|
||||
if (searchInput.val() !== '') {
|
||||
activeSearchState(clearSearchIcon, timelineViewRoot);
|
||||
} else {
|
||||
clearSearchState(clearSearchIcon, timelineViewRoot);
|
||||
}
|
||||
}, 1000));
|
||||
clearSearchIcon.on('click', () => {
|
||||
searchInput.val('');
|
||||
clearSearchState(clearSearchIcon, timelineViewRoot);
|
||||
searchInput.focus();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the clear search icon.
|
||||
*
|
||||
* @param {object} clearSearchIcon Clear search icon element.
|
||||
* @param {object} timelineViewRoot The root element for the timeline view
|
||||
*/
|
||||
const activeSearchState = (clearSearchIcon, timelineViewRoot) => {
|
||||
clearSearchIcon.removeClass('d-none');
|
||||
View.reset(timelineViewRoot);
|
||||
};
|
||||
|
||||
/**
|
||||
* Hide the clear search icon.
|
||||
*
|
||||
* @param {object} clearSearchIcon Clear search icon element.
|
||||
* @param {object} timelineViewRoot The root element for the timeline view
|
||||
*/
|
||||
const clearSearchState = (clearSearchIcon, timelineViewRoot) => {
|
||||
clearSearchIcon.addClass('d-none');
|
||||
View.reset(timelineViewRoot);
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialise the timeline view navigation by adding event listeners to
|
||||
* the navigation elements.
|
||||
*
|
||||
* @param {jQuery|HTMLElement} root The root element for the timeline block
|
||||
* @param {object} timelineViewRoot The root element for the timeline view
|
||||
*/
|
||||
export const init = function(root, timelineViewRoot) {
|
||||
root = $(root);
|
||||
|
||||
registerViewSelector(root, timelineViewRoot);
|
||||
|
||||
// Only need to handle filtering if the user is actively enrolled in a course.
|
||||
if (!root.find(SELECTORS.NO_COURSES_EMPTY_MESSAGE).length) {
|
||||
registerTimelineDaySelector(root, timelineViewRoot);
|
||||
registerSearch(root, timelineViewRoot);
|
||||
}
|
||||
};
|
||||
|
4
contentbank/amd/build/sort.min.js
vendored
4
contentbank/amd/build/sort.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -24,8 +24,8 @@
|
||||
import selectors from './selectors';
|
||||
import {get_string as getString} from 'core/str';
|
||||
import Prefetch from 'core/prefetch';
|
||||
import Ajax from 'core/ajax';
|
||||
import Notification from 'core/notification';
|
||||
import {setUserPreference} from 'core_user/repository';
|
||||
|
||||
/**
|
||||
* Set up the contentbank views.
|
||||
@ -168,19 +168,8 @@ const setViewListPreference = function(viewList) {
|
||||
viewList = null;
|
||||
}
|
||||
|
||||
const request = {
|
||||
methodname: 'core_user_update_user_preferences',
|
||||
args: {
|
||||
preferences: [
|
||||
{
|
||||
type: 'core_contentbank_view_list',
|
||||
value: viewList
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
return Ajax.call([request])[0].catch(Notification.exception);
|
||||
return setUserPreference('core_contentbank_view_list', viewList)
|
||||
.catch(Notification.exception);
|
||||
};
|
||||
|
||||
/**
|
||||
|
2
lib/amd/build/paged_content_factory.min.js
vendored
2
lib/amd/build/paged_content_factory.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -28,7 +28,7 @@ define(
|
||||
'core/paged_content',
|
||||
'core/paged_content_events',
|
||||
'core/pubsub',
|
||||
'core/ajax'
|
||||
'core_user/repository'
|
||||
],
|
||||
function(
|
||||
$,
|
||||
@ -37,7 +37,7 @@ function(
|
||||
PagedContent,
|
||||
PagedContentEvents,
|
||||
PubSub,
|
||||
Ajax
|
||||
UserRepository
|
||||
) {
|
||||
var TEMPLATES = {
|
||||
PAGED_CONTENT: 'core/paged_content'
|
||||
@ -520,25 +520,9 @@ function(
|
||||
* @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 function(limit) {
|
||||
UserRepository.setUserPreference(persistentLimitKey, limit);
|
||||
};
|
||||
|
||||
return callback;
|
||||
};
|
||||
|
||||
/**
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -22,8 +22,8 @@
|
||||
* @since 3.1
|
||||
*/
|
||||
define(['jquery', 'core/notification', 'core/str', 'core/form-autocomplete',
|
||||
'core/ajax', 'mod_assign/grading_form_change_checker'],
|
||||
function($, notification, str, autocomplete, ajax, checker) {
|
||||
'core/ajax', 'core_user/repository', 'mod_assign/grading_form_change_checker'],
|
||||
function($, notification, str, autocomplete, ajax, UserRepository, checker) {
|
||||
|
||||
/**
|
||||
* GradingNavigation class.
|
||||
@ -219,12 +219,7 @@ define(['jquery', 'core/notification', 'core/str', 'core/form-autocomplete',
|
||||
});
|
||||
}
|
||||
|
||||
return ajax.call([{
|
||||
methodname: 'core_user_set_user_preferences',
|
||||
args: {
|
||||
preferences: preferences
|
||||
}
|
||||
}])[0];
|
||||
return UserRepository.setUserPreferences(preferences);
|
||||
};
|
||||
/**
|
||||
* Turn a filter on or off.
|
||||
|
2
user/amd/build/repository.min.js
vendored
2
user/amd/build/repository.min.js
vendored
@ -1,3 +1,3 @@
|
||||
define("core_user/repository",["exports","core/ajax"],(function(_exports,_ajax){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.unenrolUser=_exports.submitUserEnrolmentForm=_exports.sendMessagesToUsers=_exports.createNotesForUsers=void 0;_exports.unenrolUser=userEnrolmentId=>(0,_ajax.call)([{methodname:"core_enrol_unenrol_user_enrolment",args:{ueid:userEnrolmentId}}])[0];_exports.submitUserEnrolmentForm=formdata=>(0,_ajax.call)([{methodname:"core_enrol_submit_user_enrolment_form",args:{formdata:formdata}}])[0];_exports.createNotesForUsers=notes=>(0,_ajax.call)([{methodname:"core_notes_create_notes",args:{notes:notes}}])[0];_exports.sendMessagesToUsers=messages=>(0,_ajax.call)([{methodname:"core_message_send_instant_messages",args:{messages:messages}}])[0]}));
|
||||
define("core_user/repository",["exports","core/ajax"],(function(_exports,_ajax){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.unenrolUser=_exports.submitUserEnrolmentForm=_exports.setUserPreferences=_exports.setUserPreference=_exports.sendMessagesToUsers=_exports.getUserPreferences=_exports.getUserPreference=_exports.createNotesForUsers=void 0;_exports.getUserPreference=function(name){let userid=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return getUserPreferences(name,userid).then((response=>response.preferences[0].value))};const getUserPreferences=function(){let name=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,userid=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(0,_ajax.call)([{methodname:"core_user_get_user_preferences",args:{name:name,userid:userid}}])[0]};_exports.getUserPreferences=getUserPreferences;_exports.setUserPreference=function(name){let value=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,userid=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return setUserPreferences([{name:name,value:value,userid:userid}])};const setUserPreferences=preferences=>(0,_ajax.call)([{methodname:"core_user_set_user_preferences",args:{preferences:preferences}}])[0];_exports.setUserPreferences=setUserPreferences;_exports.unenrolUser=userEnrolmentId=>(0,_ajax.call)([{methodname:"core_enrol_unenrol_user_enrolment",args:{ueid:userEnrolmentId}}])[0];_exports.submitUserEnrolmentForm=formdata=>(0,_ajax.call)([{methodname:"core_enrol_submit_user_enrolment_form",args:{formdata:formdata}}])[0];_exports.createNotesForUsers=notes=>(0,_ajax.call)([{methodname:"core_notes_create_notes",args:{notes:notes}}])[0];_exports.sendMessagesToUsers=messages=>(0,_ajax.call)([{methodname:"core_message_send_instant_messages",args:{messages:messages}}])[0]}));
|
||||
|
||||
//# sourceMappingURL=repository.min.js.map
|
@ -1 +1 @@
|
||||
{"version":3,"file":"repository.min.js","sources":["../src/repository.js"],"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 * Module to handle AJAX interactions.\n *\n * @module core_user/repository\n * @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport {call as fetchMany} from 'core/ajax';\n\n/**\n * Unenrol the user with the specified user enrolmentid ID.\n *\n * @param {Number} userEnrolmentId\n * @return {Promise}\n */\nexport const unenrolUser = userEnrolmentId => {\n return fetchMany([{\n methodname: 'core_enrol_unenrol_user_enrolment',\n args: {\n ueid: userEnrolmentId,\n },\n }])[0];\n};\n\n/**\n * Submit the user enrolment form with the specified form data.\n *\n * @param {String} formdata\n * @return {Promise}\n */\nexport const submitUserEnrolmentForm = formdata => {\n return fetchMany([{\n methodname: 'core_enrol_submit_user_enrolment_form',\n args: {\n formdata,\n },\n }])[0];\n};\n\nexport const createNotesForUsers = notes => {\n return fetchMany([{\n methodname: 'core_notes_create_notes',\n args: {\n notes\n }\n }])[0];\n};\n\nexport const sendMessagesToUsers = messages => {\n return fetchMany([{\n methodname: 'core_message_send_instant_messages',\n args: {messages}\n }])[0];\n};\n"],"names":["userEnrolmentId","methodname","args","ueid","formdata","notes","messages"],"mappings":"oRA8B2BA,kBAChB,cAAU,CAAC,CACdC,WAAY,oCACZC,KAAM,CACFC,KAAMH,oBAEV,oCAS+BI,WAC5B,cAAU,CAAC,CACdH,WAAY,wCACZC,KAAM,CACFE,SAAAA,aAEJ,gCAG2BC,QACxB,cAAU,CAAC,CACdJ,WAAY,0BACZC,KAAM,CACFG,MAAAA,UAEJ,gCAG2BC,WACxB,cAAU,CAAC,CACdL,WAAY,qCACZC,KAAM,CAACI,SAAAA,aACP"}
|
||||
{"version":3,"file":"repository.min.js","sources":["../src/repository.js"],"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 * Module to handle AJAX interactions.\n *\n * @module core_user/repository\n * @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {call as fetchMany} from 'core/ajax';\n\n/**\n * Get single user preference\n *\n * @param {String} name Name of the preference\n * @param {Number} userid User ID (defaults to current user)\n * @return {Promise}\n */\nexport const getUserPreference = (name, userid = 0) => {\n return getUserPreferences(name, userid)\n .then(response => response.preferences[0].value);\n};\n\n/**\n * Get multiple user preferences\n *\n * @param {String|null} name Name of the preference (omit if you want to retrieve all)\n * @param {Number} userid User ID (defaults to current user)\n * @return {Promise}\n */\nexport const getUserPreferences = (name = null, userid = 0) => {\n return fetchMany([{\n methodname: 'core_user_get_user_preferences',\n args: {name, userid}\n }])[0];\n};\n\n/**\n * Set single user preference\n *\n * @param {String} name Name of the preference\n * @param {String|null} value Value of the preference (omit if you want to remove the current value)\n * @param {Number} userid User ID (defaults to current user)\n * @return {Promise}\n */\nexport const setUserPreference = (name, value = null, userid = 0) => {\n return setUserPreferences([{name, value, userid}]);\n};\n\n/**\n * Set multiple user preferences\n *\n * @param {Object[]} preferences Array of preferences containing name/value/userid attributes\n * @return {Promise}\n */\nexport const setUserPreferences = (preferences) => {\n return fetchMany([{\n methodname: 'core_user_set_user_preferences',\n args: {preferences}\n }])[0];\n};\n\n/**\n * Unenrol the user with the specified user enrolmentid ID.\n *\n * @param {Number} userEnrolmentId\n * @return {Promise}\n */\nexport const unenrolUser = userEnrolmentId => {\n return fetchMany([{\n methodname: 'core_enrol_unenrol_user_enrolment',\n args: {\n ueid: userEnrolmentId,\n },\n }])[0];\n};\n\n/**\n * Submit the user enrolment form with the specified form data.\n *\n * @param {String} formdata\n * @return {Promise}\n */\nexport const submitUserEnrolmentForm = formdata => {\n return fetchMany([{\n methodname: 'core_enrol_submit_user_enrolment_form',\n args: {\n formdata,\n },\n }])[0];\n};\n\nexport const createNotesForUsers = notes => {\n return fetchMany([{\n methodname: 'core_notes_create_notes',\n args: {\n notes\n }\n }])[0];\n};\n\nexport const sendMessagesToUsers = messages => {\n return fetchMany([{\n methodname: 'core_message_send_instant_messages',\n args: {messages}\n }])[0];\n};\n"],"names":["name","userid","getUserPreferences","then","response","preferences","value","methodname","args","setUserPreferences","userEnrolmentId","ueid","formdata","notes","messages"],"mappings":"wYAgCiC,SAACA,UAAMC,8DAAS,SACtCC,mBAAmBF,KAAMC,QAC3BE,MAAKC,UAAYA,SAASC,YAAY,GAAGC,eAUrCJ,mBAAqB,eAACF,4DAAO,KAAMC,8DAAS,SAC9C,cAAU,CAAC,CACdM,WAAY,iCACZC,KAAM,CAACR,KAAAA,KAAMC,OAAAA,WACb,8EAWyB,SAACD,UAAMM,6DAAQ,KAAML,8DAAS,SACpDQ,mBAAmB,CAAC,CAACT,KAAAA,KAAMM,MAAAA,MAAOL,OAAAA,iBAShCQ,mBAAsBJ,cACxB,cAAU,CAAC,CACdE,WAAY,iCACZC,KAAM,CAACH,YAAAA,gBACP,uEASmBK,kBAChB,cAAU,CAAC,CACdH,WAAY,oCACZC,KAAM,CACFG,KAAMD,oBAEV,oCAS+BE,WAC5B,cAAU,CAAC,CACdL,WAAY,wCACZC,KAAM,CACFI,SAAAA,aAEJ,gCAG2BC,QACxB,cAAU,CAAC,CACdN,WAAY,0BACZC,KAAM,CACFK,MAAAA,UAEJ,gCAG2BC,WACxB,cAAU,CAAC,CACdP,WAAY,qCACZC,KAAM,CAACM,SAAAA,aACP"}
|
@ -20,8 +20,60 @@
|
||||
* @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
import {call as fetchMany} from 'core/ajax';
|
||||
|
||||
/**
|
||||
* Get single user preference
|
||||
*
|
||||
* @param {String} name Name of the preference
|
||||
* @param {Number} userid User ID (defaults to current user)
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const getUserPreference = (name, userid = 0) => {
|
||||
return getUserPreferences(name, userid)
|
||||
.then(response => response.preferences[0].value);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get multiple user preferences
|
||||
*
|
||||
* @param {String|null} name Name of the preference (omit if you want to retrieve all)
|
||||
* @param {Number} userid User ID (defaults to current user)
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const getUserPreferences = (name = null, userid = 0) => {
|
||||
return fetchMany([{
|
||||
methodname: 'core_user_get_user_preferences',
|
||||
args: {name, userid}
|
||||
}])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Set single user preference
|
||||
*
|
||||
* @param {String} name Name of the preference
|
||||
* @param {String|null} value Value of the preference (omit if you want to remove the current value)
|
||||
* @param {Number} userid User ID (defaults to current user)
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const setUserPreference = (name, value = null, userid = 0) => {
|
||||
return setUserPreferences([{name, value, userid}]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set multiple user preferences
|
||||
*
|
||||
* @param {Object[]} preferences Array of preferences containing name/value/userid attributes
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const setUserPreferences = (preferences) => {
|
||||
return fetchMany([{
|
||||
methodname: 'core_user_set_user_preferences',
|
||||
args: {preferences}
|
||||
}])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Unenrol the user with the specified user enrolmentid ID.
|
||||
*
|
||||
|
@ -1802,7 +1802,8 @@ class core_user_external extends \core_external\external_api {
|
||||
array(
|
||||
'name' => new external_value(PARAM_RAW, 'The name of the preference'),
|
||||
'value' => new external_value(PARAM_RAW, 'The value of the preference'),
|
||||
'userid' => new external_value(PARAM_INT, 'Id of the user to set the preference'),
|
||||
'userid' => new external_value(PARAM_INT,
|
||||
'Id of the user to set the preference (default to current user)', VALUE_DEFAULT, 0),
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -1830,18 +1831,20 @@ class core_user_external extends \core_external\external_api {
|
||||
|
||||
$userscache = array();
|
||||
foreach ($params['preferences'] as $pref) {
|
||||
$userid = $pref['userid'] ?: $USER->id;
|
||||
|
||||
// Check to which user set the preference.
|
||||
if (!empty($userscache[$pref['userid']])) {
|
||||
$user = $userscache[$pref['userid']];
|
||||
if (!empty($userscache[$userid])) {
|
||||
$user = $userscache[$userid];
|
||||
} else {
|
||||
try {
|
||||
$user = core_user::get_user($pref['userid'], '*', MUST_EXIST);
|
||||
$user = core_user::get_user($userid, '*', MUST_EXIST);
|
||||
core_user::require_active_user($user);
|
||||
$userscache[$pref['userid']] = $user;
|
||||
$userscache[$userid] = $user;
|
||||
} catch (Exception $e) {
|
||||
$warnings[] = array(
|
||||
'item' => 'user',
|
||||
'itemid' => $pref['userid'],
|
||||
'itemid' => $userid,
|
||||
'warningcode' => 'invaliduser',
|
||||
'message' => $e->getMessage()
|
||||
);
|
||||
|
@ -6,7 +6,11 @@ This files describes API changes for code that uses the user API.
|
||||
- `core_user::get_profile_picture` for retrieving user picture.
|
||||
- `core_user::get_profile_url` for retrieving profile url.
|
||||
- `core_user::get_fullname` for retrieving user full name.
|
||||
|
||||
* The `core_user/repository` Javascript module now exports new methods for manipulating user preferences:
|
||||
- `[get|set]UserPreference`
|
||||
- `[get|set]UserPreferences`
|
||||
* The external `core_user_set_user_preferences` method will now default the `userid` property of each preference to
|
||||
that of the current user, if omitted
|
||||
* The following previously deprecated methods have been removed and can no longer be used:
|
||||
- `profile_display_fields`
|
||||
- `profile_edit_category`
|
||||
|
Loading…
x
Reference in New Issue
Block a user