weekly release 4.0dev
[moodle.git] / blocks / myoverview / amd / build / view.min.js
1 function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("block_myoverview/view",["exports","jquery","block_myoverview/repository","core/paged_content_factory","core/pubsub","core/custom_interaction_events","core/notification","core/templates","core_course/events","block_myoverview/selectors","core/paged_content_events","core/aria","core/utils"],function(a,b,c,d,e,f,g,h,i,j,k,l,m){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.reset=a.init=a.clearSearch=void 0;b=p(b);c=o(c);d=o(d);e=o(e);f=o(f);g=o(g);h=o(h);i=o(i);j=p(j);k=o(k);l=o(l);function n(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;n=function(){return a};return a}function o(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=n();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a){if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;if(f&&(f.get||f.set)){Object.defineProperty(c,e,f)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}function p(a){return a&&a.__esModule?a:{default:a}}function q(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);if(b)d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable});c.push.apply(c,d)}return c}function r(a){for(var b=1,c;b<arguments.length;b++){c=null!=arguments[b]?arguments[b]:{};if(b%2){q(Object(c),!0).forEach(function(b){s(a,b,c[b])})}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(a,Object.getOwnPropertyDescriptors(c))}else{q(Object(c)).forEach(function(b){Object.defineProperty(a,b,Object.getOwnPropertyDescriptor(c,b))})}}return a}function s(a,b,c){if(b in a){Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0})}else{a[b]=c}return a}function t(a){return x(a)||w(a)||v(a)||u()}function u(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function v(a,b){if(!a)return;if("string"==typeof a)return y(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);if("Object"===c&&a.constructor)c=a.constructor.name;if("Map"===c||"Set"===c)return Array.from(c);if("Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c))return y(a,b)}function w(a){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(a))return Array.from(a)}function x(a){if(Array.isArray(a))return y(a)}function y(a,b){if(null==b||b>a.length)b=a.length;for(var c=0,d=Array(b);c<b;c++){d[c]=a[c]}return d}var z={COURSES_CARDS:"block_myoverview/view-cards",COURSES_LIST:"block_myoverview/view-list",COURSES_SUMMARY:"block_myoverview/view-summary",NOCOURSES:"core_course/no-courses"},A={GROUPING_ALLINCLUDINGHIDDEN:"allincludinghidden",GROUPING_ALL:"all",GROUPING_INPROGRESS:"inprogress",GROUPING_FUTURE:"future",GROUPING_PAST:"past",GROUPING_FAVOURITES:"favourites",GROUPING_HIDDEN:"hidden"},B=[12,24,48,96,0],C=[],D=0,E=0,F=0,G=null,H=function(a){var b=a.find(j.default.courseView.region);return{display:b.attr("data-display"),grouping:b.attr("data-grouping"),sort:b.attr("data-sort"),displaycategories:b.attr("data-displaycategories"),customfieldname:b.attr("data-customfieldname"),customfieldvalue:b.attr("data-customfieldvalue")}},I={ignoreControlWhileLoading:!0,controlPlacementBottom:!0,persistentLimitKey:"block_myoverview_user_paging_preference"},J=function(a,b){return c.getEnrolledCoursesByTimeline({offset:D,limit:b,classification:a.grouping,sort:a.sort,customfieldname:a.customfieldname,customfieldvalue:a.customfieldvalue})},K=function(a,b,d){return c.getEnrolledCoursesByTimeline({offset:D,limit:b,classification:"search",sort:a.sort,customfieldname:a.customfieldname,customfieldvalue:a.customfieldvalue,searchvalue:d})},L=function(a,b){return a.find(j.default.FAVOURITE_ICON+"[data-course-id=\""+b+"\"]")},M=function(a,b){return a.find("[data-region=\"paged-content-page\"][data-page=\""+b+"\"]")},N=function(a){return a.attr("data-course-id")},O=function(a,b){var c=L(a,b),d=c.find(j.default.ICON_IS_FAVOURITE);d.addClass("hidden");l.hide(d);var e=c.find(j.default.ICON_NOT_FAVOURITE);e.removeClass("hidden");l.unhide(e)},P=function(a,b){var c=L(a,b),d=c.find(j.default.ICON_IS_FAVOURITE);d.removeClass("hidden");l.unhide(d);var e=c.find(j.default.ICON_NOT_FAVOURITE);e.addClass("hidden");l.hide(e)},Q=function(a,b){return a.find("[data-action=\"add-favourite\"][data-course-id=\""+b+"\"]")},R=function(a,b){return a.find("[data-action=\"remove-favourite\"][data-course-id=\""+b+"\"]")},S=function(a,b){var c=R(a,b),d=Q(a,b);$(b,!0).then(function(f){if(f){e.publish(i.favorited,b);c.removeClass("hidden");d.addClass("hidden");P(a,b)}else{g.alert("Starring course failed","Could not change favourite state")}}).catch(g.exception)},T=function(a,b){var c=R(a,b),d=Q(a,b);$(b,!1).then(function(f){if(f){e.publish(i.unfavorited,b);c.addClass("hidden");d.removeClass("hidden");O(a,b)}else{g.alert("Starring course failed","Could not change favourite state")}}).catch(g.exception)},U=function(a,b){return a.find("[data-action=\"hide-course\"][data-course-id=\""+b+"\"]")},V=function(a,b){return a.find("[data-action=\"show-course\"][data-course-id=\""+b+"\"]")},W=function(a,b){var c=U(a,b),d=V(a,b),e=H(a);Y(b,!0);if(e.grouping!==A.GROUPING_ALLINCLUDINGHIDDEN){Z(a,b)}c.addClass("hidden");d.removeClass("hidden")},X=function(a,b){var c=U(a,b),d=V(a,b),e=H(a);Y(b,null);if(e.grouping!==A.GROUPING_ALLINCLUDINGHIDDEN){Z(a,b)}c.removeClass("hidden");d.addClass("hidden")},Y=function(a,b){if(!1===b){b=null}return c.updateUserPreferences({preferences:[{type:"block_myoverview_hidden_course_"+a,value:b}]})},Z=function(a,c){var e=a.find("[data-region=\"paging-bar\"]"),f=parseInt(e.attr("data-active-page-number")),i=C[f],j=i.courses.reduce(function(a,b){if(+c!=+b.id){a.push(b)}return a},[]);if("undefined"!=typeof C[f+1]){var l=C[f+1].courses.slice(0,1);C.forEach(function(a,b){if(b>f){var c=[];if("undefined"!=typeof C[b+1]){c=C[b+1].courses.slice(0,1)}C[b].courses=[].concat(t(C[b].courses.slice(1)),t(c))}});j=[].concat(t(j),t(l))}if(E===f+1&&0===C[f+1].courses.length){var m=a.find("[data-region=\"paged-content-container\"]");d.resetLastPageNumber((0,b.default)(m).attr("id"),f)}C[f].courses=j;D--;var k=M(a,f);aa(a,C[f]).then(function(a,b){return h.replaceNodeContents(k,a,b)}).catch(g.exception);C.forEach(function(b,c){if(c>f){var d=M(a,c);d.remove()}})},$=function(a,b){return c.setFavouriteCourses({courses:[{id:a,favourite:b}]}).then(function(c){if(0===c.warnings.length){C.forEach(function(c){c.courses.forEach(function(d,e){if(d.id===a){c.courses[e].isfavourite=b}})});return!0}else{return!1}}).catch(g.exception)},_=function(a){var b=a.find(j.default.courseView.region).attr("data-nocoursesimg");return h.render(z.NOCOURSES,{nocoursesimg:b})},aa=function(a,b){var c=H(a),d="";if("card"===c.display){d=z.COURSES_CARDS}else if("list"===c.display){d=z.COURSES_LIST}else{d=z.COURSES_SUMMARY}if(!b){return _(a)}else{if(!1===Array.isArray(b.courses)){b.courses=Object.values(b.courses)}b.courses=b.courses.map(function(a){a.showcoursecategory="on"===c.displaycategories;return a});if(b.courses.length){return h.render(d,{courses:b.courses})}else{return _(a)}}},ba=function(a){return function(b){return a.find(j.default.courseView.region).attr("data-paging",b)}},ca=function(a,b){var c=b+k.SET_ITEMS_PER_PAGE_LIMIT;e.subscribe(c,ba(a))},da=function(a,b){var c=B.map(function(b){var c=!1;if(b===a){c=!0}return{value:b,active:c}}),d=parseInt(b.find(j.default.courseView.region).attr("data-totalcoursecount"),10);return c.filter(function(a){return a.value<d||0===a.value})},ea=function(a,b,c,d){var e=4<arguments.length&&arguments[4]!==void 0?arguments[4]:null,f=a.courses?a.courses:a,g=0,h=[];if("undefined"!=typeof C[b]){h=C[b].courses;var j=h.length;if(j<c.limit){g=c.limit-j;h=r({},C[b].courses,{},f.slice(0,g))}}else{g=c.limit||!1;h=0<c.limit?f.slice(0,c.limit):f}C[b]={courses:h};var i=!1!==g?f.slice(g,f.length):[];if(i.length){C[b+1]={courses:i}}if(C[b].courses.length<c.limit||!i.length){E=b;if(null===e){d.allItemsLoaded(b)}}else if("undefined"!=typeof C[b+1]&&C[b+1].courses.length<c.limit){E=b+1}D=a.nextoffset},fa=function(){D=0;C=[];E=0;F=0},ga=function(){fa();return function(a,b,c,d,e,f,h){var i=J(a,h).then(function(a){ea(a,b,c,d);return aa(e,C[b])}).catch(g.exception);f.push(i)}},ha=function(){fa();return function(a,b,c,d,e,f,h,i){var j=K(a,h,i).then(function(a){ea(a,b,c,d);return aa(e,C[b])}).catch(g.exception);f.push(j)}},ia=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null,e=parseInt(a.find(j.default.courseView.region).attr("data-paging"),10),f=da(e,a),i=H(a),k=r({},{},{},I);k.eventNamespace=G;var l=d.createWithLimit(f,function(d,e){var f=[];d.forEach(function(d){var g=d.pageNumber,h=0<d.limit?d.limit:0;if(+F!=+h){C=[];D=0;E=0}if(E===g){e.allItemsLoaded(E);f.push(aa(a,C[g]));return}F=h;if("undefined"==typeof C[g+1]){if("undefined"==typeof C[g]){h*=2}}b(i,g,d,e,a,f,h,c)});return f},k);l.then(function(b,c){ca(a,G);return h.replaceNodeContents(a.find(j.default.courseView.region),b,c)}).catch(g.exception)},ja=function(a,c){f.define(a,[f.events.activate]);a.on(f.events.activate,j.default.ACTION_ADD_FAVOURITE,function(c,d){var e=(0,b.default)(c.target).closest(j.default.ACTION_ADD_FAVOURITE),f=N(e);S(a,f);d.originalEvent.preventDefault()});a.on(f.events.activate,j.default.ACTION_REMOVE_FAVOURITE,function(c,d){var e=(0,b.default)(c.target).closest(j.default.ACTION_REMOVE_FAVOURITE),f=N(e);T(a,f);d.originalEvent.preventDefault()});a.on(f.events.activate,j.default.FAVOURITE_ICON,function(a,b){b.originalEvent.preventDefault()});a.on(f.events.activate,j.default.ACTION_HIDE_COURSE,function(c,d){var e=(0,b.default)(c.target).closest(j.default.ACTION_HIDE_COURSE),f=N(e);W(a,f);d.originalEvent.preventDefault()});a.on(f.events.activate,j.default.ACTION_SHOW_COURSE,function(c,d){var e=(0,b.default)(c.target).closest(j.default.ACTION_SHOW_COURSE),f=N(e);X(a,f);d.originalEvent.preventDefault()});var d=c.querySelector(j.default.region.searchInput),e=c.querySelector(j.default.region.clearIcon),g=c.querySelector(j.default.region.searchIcon);e.addEventListener("click",function(){d.value="";ka(g,e,a)});d.addEventListener("input",(0,m.debounce)(function(){if(""===d.value){ka(g,e,a)}else{la(g,e);ia(a,ha(),d.value.trim())}},300))},ka=function(a,b,c){a.classList.remove("d-none");b.parentElement.classList.add("d-none");ma(c)};a.clearSearch=ka;var la=function(a,b){a.classList.add("d-none");b.parentElement.classList.remove("d-none")},ma=function(a){a=(0,b.default)(a);C=[];E=0;D=0;if(!a.attr("data-init")){var c=document.querySelector(j.default.region.selectBlock);ja(a,c);G="block_myoverview_"+a.attr("id")+"_"+Math.random();a.attr("data-init",!0)}ia(a,ga())};a.init=ma;var na=function(a){if(0<C.length){C.forEach(function(b,c){var d=M(a,c);aa(a,b).then(function(a,b){return h.replaceNodeContents(d,a,b)}).catch(g.exception)})}else{ma(a)}};a.reset=na});
2 //# sourceMappingURL=view.min.js.map