Current Path : C:/xampp/htdocs/moodle/blocks/myoverview/amd/build/ |
Current File : C:/xampp/htdocs/moodle/blocks/myoverview/amd/build/view.min.js |
define ("block_myoverview/view",["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"],function(a,b,c,d,e,f,g,h,i,j){var k={COURSE_REGION:"[data-region=\"course-view-content\"]",ACTION_HIDE_COURSE:"[data-action=\"hide-course\"]",ACTION_SHOW_COURSE:"[data-action=\"show-course\"]",ACTION_ADD_FAVOURITE:"[data-action=\"add-favourite\"]",ACTION_REMOVE_FAVOURITE:"[data-action=\"remove-favourite\"]",FAVOURITE_ICON:"[data-region=\"favourite-icon\"]",ICON_IS_FAVOURITE:"[data-region=\"is-favourite\"]",ICON_NOT_FAVOURITE:"[data-region=\"not-favourite\"]",PAGED_CONTENT_CONTAINER:"[data-region=\"page-container\"]"},l={COURSES_CARDS:"block_myoverview/view-cards",COURSES_LIST:"block_myoverview/view-list",COURSES_SUMMARY:"block_myoverview/view-summary",NOCOURSES:"core_course/no-courses"},m={GROUPING_ALLINCLUDINGHIDDEN:"allincludinghidden",GROUPING_ALL:"all",GROUPING_INPROGRESS:"inprogress",GROUPING_FUTURE:"future",GROUPING_PAST:"past",GROUPING_FAVOURITES:"favourites",GROUPING_HIDDEN:"hidden"},n=[12,24,48,96,0],o=[],p=0,q=0,r=0,s=null,t=function(a){var b=a.find(i.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")}},u={ignoreControlWhileLoading:!0,controlPlacementBottom:!0,persistentLimitKey:"block_myoverview_user_paging_preference"},v=function(a,c){return b.getEnrolledCoursesByTimeline({offset:p,limit:c,classification:a.grouping,sort:a.sort,customfieldname:a.customfieldname,customfieldvalue:a.customfieldvalue})},w=function(a,b){return a.find(k.FAVOURITE_ICON+"[data-course-id=\""+b+"\"]")},x=function(a,b){return a.find("[data-region=\"paged-content-page\"][data-page=\""+b+"\"]")},y=function(a){return a.attr("data-course-id")},z=function(a,b){var c=w(a,b),d=c.find(k.ICON_IS_FAVOURITE);d.addClass("hidden");d.attr("aria-hidden",!0);var e=c.find(k.ICON_NOT_FAVOURITE);e.removeClass("hidden");e.attr("aria-hidden",!1)},A=function(a,b){var c=w(a,b),d=c.find(k.ICON_IS_FAVOURITE);d.removeClass("hidden");d.attr("aria-hidden",!1);var e=c.find(k.ICON_NOT_FAVOURITE);e.addClass("hidden");e.attr("aria-hidden",!0)},B=function(a,b){return a.find("[data-action=\"add-favourite\"][data-course-id=\""+b+"\"]")},C=function(a,b){return a.find("[data-action=\"remove-favourite\"][data-course-id=\""+b+"\"]")},D=function(a,b){var c=C(a,b),e=B(a,b);L(b,!0).then(function(g){if(g){d.publish(h.favourited,b);c.removeClass("hidden");e.addClass("hidden");A(a,b)}else{f.alert("Starring course failed","Could not change favourite state")}}).catch(f.exception)},E=function(a,b){var c=C(a,b),e=B(a,b);L(b,!1).then(function(g){if(g){d.publish(h.unfavorited,b);c.addClass("hidden");e.removeClass("hidden");z(a,b)}else{f.alert("Starring course failed","Could not change favourite state")}}).catch(f.exception)},F=function(a,b){return a.find("[data-action=\"hide-course\"][data-course-id=\""+b+"\"]")},G=function(a,b){return a.find("[data-action=\"show-course\"][data-course-id=\""+b+"\"]")},H=function(a,b){var c=F(a,b),d=G(a,b),e=t(a);J(b,!0);if(e.grouping!=m.GROUPING_ALLINCLUDINGHIDDEN){K(a,b)}c.addClass("hidden");d.removeClass("hidden")},I=function(a,b){var c=F(a,b),d=G(a,b),e=t(a);J(b,null);if(e.grouping!=m.GROUPING_ALLINCLUDINGHIDDEN){K(a,b)}c.removeClass("hidden");d.addClass("hidden")},J=function(a,c){if(!1===c){c=null}return b.updateUserPreferences({preferences:[{type:"block_myoverview_hidden_course_"+a,value:c}]})},K=function(b,d){var e=b.find("[data-region=\"paging-bar\"]"),h=parseInt(e.attr("data-active-page-number")),i=o[h],j=i.courses.reduce(function(a,b){if(d!=b.id){a.push(b)}return a},[]);if(o[h+1]!=void 0){var k=o[h+1].courses.slice(0,1);o.forEach(function(b,c){if(c>h){var d=[];if(o[c+1]!=void 0){d=o[c+1].courses.slice(0,1)}o[c].courses=a.merge(o[c].courses.slice(1),d)}});j=a.merge(j,k)}if(q==h+1&&0==o[h+1].courses.length){var l=b.find("[data-region=\"paged-content-container\"]");c.resetLastPageNumber(a(l).attr("id"),h)}o[h].courses=j;p--;var m=x(b,h);M(b,o[h]).then(function(a,b){return g.replaceNodeContents(m,a,b)}).catch(f.exception);o.forEach(function(a,c){if(c>h){var d=x(b,c);d.remove()}})},L=function(a,c){return b.setFavouriteCourses({courses:[{id:a,favourite:c}]}).then(function(b){if(0==b.warnings.length){o.forEach(function(b){b.courses.forEach(function(d,e){if(d.id==a){b.courses[e].isfavourite=c}})});return!0}else{return!1}}).catch(f.exception)},M=function(a,b){var c=t(a),d="";if("card"==c.display){d=l.COURSES_CARDS}else if("list"==c.display){d=l.COURSES_LIST}else{d=l.COURSES_SUMMARY}b.courses=b.courses.map(function(a){a.showcoursecategory="on"==c.displaycategories?!0:!1;return a});if(b.courses.length){return g.render(d,{courses:b.courses})}else{var e=a.find(i.courseView.region).attr("data-nocoursesimg");return g.render(l.NOCOURSES,{nocoursesimg:e})}},N=function(a){this.find(i.courseView.region).attr("data-paging",a)},O=function(a,b){var c=b+j.SET_ITEMS_PER_PAGE_LIMIT;d.subscribe(c,N.bind(a))},P=function(b){s="block_myoverview_"+b.attr("id")+"_"+Math.random();var d=parseInt(b.find(i.courseView.region).attr("data-paging"),10),e=n.map(function(a){var b=!1;if(a==d){b=!0}return{value:a,active:b}}),h=parseInt(b.find(i.courseView.region).attr("data-totalcoursecount"),10);if(h){e=e.filter(function(a){return a.value<h})}var j=t(b),k=a.extend({},u);k.eventNamespace=s;var l=c.createWithLimit(e,function(c,d){var e=[];c.forEach(function(c){var g=c.pageNumber,h=0<c.limit?c.limit:0;if(r!=h){o=[];p=0;q=0}if(q==g){d.allItemsLoaded(q);e.push(M(b,o[g]));return}r=h;if(o[g+1]==void 0){if(o[g]==void 0){h*=2}}var i=v(j,h).then(function(e){var f=e.courses,h=0,i=[];if(o[g]!=void 0){i=o[g].courses;var j=i.length;if(j<c.limit){h=c.limit-j;i=a.merge(o[g].courses,f.slice(0,h))}}else{h=c.limit;i=0<c.limit?f.slice(0,c.limit):f}o[g]={courses:i};var k=h?f.slice(h,f.length):[];if(k.length){o[g+1]={courses:k}}if(o[g].courses.length<c.limit||!k.length){q=g;d.allItemsLoaded(g)}else if(o[g+1]!=void 0&&o[g+1].courses.length<c.limit){q=g+1}p=e.nextoffset;return M(b,o[g])}).catch(f.exception);e.push(i)});return e},k);l.then(function(a,c){O(b,s);return g.replaceNodeContents(b.find(i.courseView.region),a,c)}).catch(f.exception)},Q=function(b){e.define(b,[e.events.activate]);b.on(e.events.activate,k.ACTION_ADD_FAVOURITE,function(c,d){var e=a(c.target).closest(k.ACTION_ADD_FAVOURITE),f=y(e);D(b,f);d.originalEvent.preventDefault()});b.on(e.events.activate,k.ACTION_REMOVE_FAVOURITE,function(c,d){var e=a(c.target).closest(k.ACTION_REMOVE_FAVOURITE),f=y(e);E(b,f);d.originalEvent.preventDefault()});b.on(e.events.activate,k.FAVOURITE_ICON,function(a,b){b.originalEvent.preventDefault()});b.on(e.events.activate,k.ACTION_HIDE_COURSE,function(c,d){var e=a(c.target).closest(k.ACTION_HIDE_COURSE),f=y(e);H(b,f);d.originalEvent.preventDefault()});b.on(e.events.activate,k.ACTION_SHOW_COURSE,function(c,d){var e=a(c.target).closest(k.ACTION_SHOW_COURSE),f=y(e);I(b,f);d.originalEvent.preventDefault()})},R=function(b){b=a(b);o=[];q=0;p=0;P(b);if(!b.attr("data-init")){Q(b);b.attr("data-init",!0)}},S=function(a){if(0<o.length){o.forEach(function(b,c){var d=x(a,c);M(a,b).then(function(a,b){return g.replaceNodeContents(d,a,b)}).catch(f.exception)})}else{R(a)}};return{init:R,reset:S}}); //# sourceMappingURL=view.min.js.map