You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
4.5 KiB
1 lines
4.5 KiB
define(["jquery","core/notification","core/custom_interaction_events","core/str","core/templates","block_timeline/event_list","core_course/repository","block_timeline/calendar_events_repository"],function(a,b,c,d,e,f,g,h){var i={MORE_COURSES_BUTTON:'[data-action="more-courses"]',MORE_COURSES_BUTTON_CONTAINER:'[data-region="more-courses-button-container"]',NO_COURSES_EMPTY_MESSAGE:'[data-region="no-courses-empty-message"]',COURSES_LIST:'[data-region="courses-list"]',COURSE_ITEMS_LOADING_PLACEHOLDER:'[data-region="course-items-loading-placeholder"]',COURSE_EVENTS_CONTAINER:'[data-region="course-events-container"]',COURSE_NAME:'[data-region="course-name"]',LOADING_ICON:".loading-icon"},j={COURSE_ITEMS:"block_timeline/course-items",LOADING_ICON:"core/loading"},k="inprogress",l="fullname asc",m=5,n=2,o=86400,p=function(a){a.find(i.COURSE_ITEMS_LOADING_PLACEHOLDER).addClass("hidden")},q=function(a){a.find(i.MORE_COURSES_BUTTON_CONTAINER).addClass("hidden")},r=function(a){a.find(i.MORE_COURSES_BUTTON_CONTAINER).removeClass("hidden")},s=function(a){var b=a.find(i.MORE_COURSES_BUTTON);b.prop("disabled",!0),e.render(j.LOADING_ICON,{}).then(function(a){return b.append(a),a})["catch"](function(){return!1})},t=function(a){var b=a.find(i.MORE_COURSES_BUTTON);b.prop("disabled",!1),b.find(i.LOADING_ICON).remove()},u=function(a){a.find(i.NO_COURSES_EMPTY_MESSAGE).removeClass("hidden")},v=function(a,b){var c=a.find(i.COURSES_LIST);e.appendNodeContents(c,b,"")},w=function(a){return a.find(i.COURSE_EVENTS_CONTAINER).length>0},x=function(a){return parseInt(a.attr("data-offset"),10)},y=function(a,b){a.attr("data-offset",b)},z=function(a){return parseInt(a.attr("data-limit"),10)},A=function(a){return parseInt(a.attr("data-days-offset"),10)},B=function(a){var b=a.attr("data-days-limit");return void 0!=b?parseInt(b,10):void 0},C=function(a){return parseInt(a.attr("data-midnight"),10)},D=function(a){var b=C(a),c=A(a);return b+c*o},E=function(a){var b=C(a),c=B(a);return void 0!=c&&b+c*o},F=function(a,b,c,d){var e={courseids:a,starttime:b,limit:c};return d&&(e.endtime=d),h.queryByCourses(e)},G=function(a){return a.data("last-event-load-time")},H=function(a,b){a.data("last-event-load-time",b)},I=function(a,b){return G(a)>b},J=function(a,b,c){var d=a.map(function(a){return a.id});return F(d,b,m+1,c)},K=function(a,b,c,d,f,g){return e.render(j.COURSE_ITEMS,{courses:a,midnight:c,hasdaysoffset:!0,hasdayslimit:void 0!=f,daysoffset:d,dayslimit:f,nodayslimit:void 0==f,urls:{noevents:g}}).then(function(a){return p(b),a?v(b,a):w(b)||u(b),a}).then(function(c){return a.length<n?q(b):r(b),c})["catch"](function(){p(b)})},L=function(c){var e=x(c),h=z(c);return g.getEnrolledCoursesByTimelineClassification(k,h,e,l).then(function(b){var e=Date.now(),g=b.courses,h=b.nextoffset,i=A(c),j=B(c),k=C(c),l=D(c),n=E(c),o=c.attr("data-no-events-url");y(c,h);var p=J(g,l,n),q=K(g,c,k,i,j,o);return a.when(p,q).then(function(b){return I(c,e)?b:(g.forEach(function(e){var g=e.id,h=[],i='[data-region="course-events-container"][data-course-id="'+g+'"]',j=c.find(i),k=j.find(f.rootSelector),l=b.groupedbycourse.filter(function(a){return a.courseid==g});l.length&&(h=l[0].events);var n=a.Deferred().resolve({events:h}).promise();d.get_string("ariaeventlistpaginationnavcourses","block_timeline",e.fullnamedisplay).then(function(a){return f.init(k,m,{1:n},a),a})["catch"](function(){f.init(k,m,{1:n})})}),b)})})["catch"](b.exception)},M=function(c){var e=Date.now(),g=D(c),h=E(c),j=c.find(i.COURSE_EVENTS_CONTAINER),k=j.map(function(){return a(this).attr("data-course-id")}).get();return H(c,e),F(k,g,m+1,h).then(function(b){return I(c,e)?b:(j.each(function(c,e){e=a(e);var g=e.attr("data-course-id"),h=e.find(i.COURSE_NAME).text(),j=e.find(f.rootSelector),k=a.Deferred(),l=[],n=b.groupedbycourse.filter(function(a){return a.courseid==g});n.length&&(l=n[0].events),k.resolve({events:l}),d.get_string("ariaeventlistpaginationnavcourses","block_timeline",h).then(function(a){return f.init(j,m,{1:k.promise()},a),a})["catch"](function(){f.init(j,m,{1:k.promise()})})}),b)})["catch"](b.exception)},N=function(a){c.define(a,[c.events.activate]),a.on(c.events.activate,i.MORE_COURSES_BUTTON,function(b,c){s(a),L(a).then(function(){t(a)})["catch"](function(){t(a)}),c&&(c.originalEvent.preventDefault(),c.originalEvent.stopPropagation()),b.stopPropagation()})},O=function(b){b=a(b),H(b,Date.now()),b.hasClass("active")&&(L(b),b.attr("data-seen",!0)),N(b)},P=function(a){a.removeAttr("data-seen"),a.hasClass("active")&&Q(a)},Q=function(a){a.attr("data-seen")||(w(a)?M(a):L(a),a.attr("data-seen",!0))};return{init:O,reset:P,shown:Q}});
|