mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-57503 block_myoverview: use get actions events by course
Updated the myoverview block javascript to use the new external functions that retrieve events by course. Part of MDL-55611 epic.
This commit is contained in:
parent
89e9edf4a4
commit
42016853d1
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
define(["jquery","core/notification","core/templates","core/custom_interaction_events","block_myoverview/calendar_events_repository"],function(a,b,c,d,e){var f=86400,g={EMPTY_MESSAGE:'[data-region="empty-message"]',EVENT_LIST:'[data-region="event-list"]',EVENT_LIST_CONTENT:'[data-region="event-list-content"]',EVENT_LIST_GROUP_CONTAINER:'[data-region="event-list-group-container"]',LOADING_ICON_CONTAINER:'[data-region="loading-icon-container"]',VIEW_MORE_BUTTON:'[data-action="view-more"]'},h=function(a){a.attr("data-loaded-all",!0)},i=function(a){return!!a.attr("data-loaded-all")},j=function(a){var b=a.find(g.LOADING_ICON_CONTAINER),c=a.find(g.VIEW_MORE_BUTTON);a.addClass("loading"),b.removeClass("hidden"),c.prop("disabled",!0)},k=function(a){var b=a.find(g.LOADING_ICON_CONTAINER),c=a.find(g.VIEW_MORE_BUTTON);a.removeClass("loading"),b.addClass("hidden"),i(a)||c.prop("disabled",!1)},l=function(a){return a.hasClass("loading")},m=function(a){a.attr("data-has-events",!0)},n=function(a){return!!a.attr("data-has-events")},o=function(a,b){b?m(a):n(a)||p(a)},p=function(a){a.find(g.EVENT_LIST_CONTENT).addClass("hidden"),a.find(g.EMPTY_MESSAGE).removeClass("hidden")},q=function(a,b){return a.removeClass("hidden"),c.render("block_myoverview/event-list-items",{events:b}).done(function(b,d){c.appendNodeContents(a.find(g.EVENT_LIST),b,d)})},r=function(a,b){var c=b.timesort||0;return c-a},s=function(a,b){var c=Math.floor((new Date).setHours(0,0,0,0)/1e3),d=+b.attr("data-start-day")*f,e=+b.attr("data-end-day")*f,g=r(c,a);return e?d<=g&&g<e:d<=g},t=function(b){return function(c){return s(c,a(b))}},u=function(b,c){var d=0;return a.when.apply(a,a.map(b.find(g.EVENT_LIST_GROUP_CONTAINER),function(b){var e=c.filter(t(b));return e.length?(d+=e.length,q(a(b),e)):null})).then(function(){return d})},v=function(c){c=a(c);var d=+c.attr("data-limit"),f=+c.attr("data-course-id"),g=c.attr("data-last-id")?c.attr("data-last-id"):void 0,i=new Date,m=Math.floor(i.setHours(0,0,0,0)/1e3);if(l(c))return a.Deferred().resolve();j(c);var n=null;return n=f?e.queryFromTimeByCourse(f,m,d,g):e.queryFromTime(m,d,g),n.then(function(a){return a.events}).then(function(a){return(!a.length||a.length<d)&&h(c),a.length?(c.attr("data-last-id",a[a.length-1].id),u(c,a).then(function(b){o(c,a.length),b<a.length&&h(c)})):void o(c,a.length)}).fail(b.exception).always(function(){k(c)})},w=function(a){d.define(a,[d.events.activate]),a.one(d.events.activate,g.VIEW_MORE_BUTTON,function(){v(a)})};return{init:function(b){b=a(b),v(b),w(b)},registerEventListeners:w,load:v}});
|
||||
define(["jquery","core/notification","core/templates","core/custom_interaction_events","block_myoverview/calendar_events_repository"],function(a,b,c,d,e){var f=86400,g={EMPTY_MESSAGE:'[data-region="empty-message"]',ROOT:'[data-region="event-list-container"]',EVENT_LIST:'[data-region="event-list"]',EVENT_LIST_CONTENT:'[data-region="event-list-content"]',EVENT_LIST_GROUP_CONTAINER:'[data-region="event-list-group-container"]',LOADING_ICON_CONTAINER:'[data-region="loading-icon-container"]',VIEW_MORE_BUTTON:'[data-action="view-more"]'},h=function(a){a.attr("data-loaded-all",!0)},i=function(a){return!!a.attr("data-loaded-all")},j=function(a){var b=a.find(g.LOADING_ICON_CONTAINER),c=a.find(g.VIEW_MORE_BUTTON);a.addClass("loading"),b.removeClass("hidden"),c.prop("disabled",!0)},k=function(a){var b=a.find(g.LOADING_ICON_CONTAINER),c=a.find(g.VIEW_MORE_BUTTON);a.removeClass("loading"),b.addClass("hidden"),i(a)||c.prop("disabled",!1)},l=function(a){return a.hasClass("loading")},m=function(a){a.attr("data-has-events",!0)},n=function(a){return!!a.attr("data-has-events")},o=function(a,b){b?m(a):n(a)||p(a)},p=function(a){a.find(g.EVENT_LIST_CONTENT).addClass("hidden"),a.find(g.EMPTY_MESSAGE).removeClass("hidden")},q=function(a,b){return a.removeClass("hidden"),c.render("block_myoverview/event-list-items",{events:b}).done(function(b,d){c.appendNodeContents(a.find(g.EVENT_LIST),b,d)})},r=function(a,b){var c=b.timesort||0;return c-a},s=function(a,b){var c=Math.floor((new Date).setHours(0,0,0,0)/1e3),d=+b.attr("data-start-day")*f,e=+b.attr("data-end-day")*f,g=r(c,a);return e?d<=g&&g<e:d<=g},t=function(b){return function(c){return s(c,a(b))}},u=function(b,c){var d=0;return a.when.apply(a,a.map(b.find(g.EVENT_LIST_GROUP_CONTAINER),function(b){var e=c.filter(t(b));return e.length?(d+=e.length,q(a(b),e)):null})).then(function(){return d})},v=function(c,d){c=a(c);var f=+c.attr("data-limit"),g=+c.attr("data-course-id"),i=c.attr("data-last-id"),m=new Date,n=Math.floor(m.setHours(0,0,0,0)/1e3);if(l(c))return a.Deferred().resolve();if(j(c),"undefined"==typeof d){var p={starttime:n,limit:f};i&&(p.aftereventid=i),g?(p.courseid=g,d=e.queryByCourse(p)):d=e.queryByTime(p)}return d.then(function(a){return a.events}).then(function(a){return(!a.length||a.length<f)&&h(c),a.length?(c.attr("data-last-id",a[a.length-1].id),u(c,a).then(function(b){o(c,a.length),b<a.length&&h(c)})):void o(c,a.length)}).fail(b.exception).always(function(){k(c)})},w=function(a){d.define(a,[d.events.activate]),a.on(d.events.activate,g.VIEW_MORE_BUTTON,function(){v(a)})};return{init:function(b){b=a(b),v(b),w(b)},registerEventListeners:w,load:v,rootSelector:g.ROOT}});
|
@ -1 +1 @@
|
||||
define(["jquery","block_myoverview/event_list"],function(a,b){var c={EVENTS_BY_COURSE_CONTAINER:'[data-region="course-events-container"]',EVENTS_LIST_CONTAINER:'[data-region="event-list-container"]'},d=function(d){d.find(c.EVENTS_BY_COURSE_CONTAINER).each(function(d,e){e=a(e);var f=e.find(c.EVENTS_LIST_CONTAINER);b.load(f)})};return{init:function(b){b=a(b),d(b)}}});
|
||||
define(["jquery","block_myoverview/event_list","block_myoverview/calendar_events_repository"],function(a,b,c){var d={EVENTS_BY_COURSE_CONTAINER:'[data-region="course-events-container"]'},e=function(e){var f=e.find(d.EVENTS_BY_COURSE_CONTAINER);if(f.length){var g=new Date,h=Math.floor(g.setHours(0,0,0,0)/1e3),i=f.attr("data-limit"),j=f.map(function(){return a(this).attr("data-course-id")}).get(),k=c.queryByCourses({courseids:j,starttime:h,limit:i});f.each(function(c,d){d=a(d);var e=d.attr("data-course-id"),f=d.find(b.rootSelector),g=a.Deferred();k.done(function(a){var b=[],c=a.groupedbycourse.filter(function(a){return a.courseid==e});c.length&&(b=c[0].events),g.resolve({events:b})}).fail(function(a){g.reject(a)}),b.load(f,g)})}};return{init:function(b){b=a(b),e(b)}}});
|
@ -24,834 +24,128 @@
|
||||
*/
|
||||
define(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notification) {
|
||||
|
||||
var date = new Date(),
|
||||
currentTime = Math.floor(date.setHours(0, 0, 0, 0) / 1000),
|
||||
todayTime = currentTime + (60 * 60),
|
||||
tomorrowTime = currentTime + (60 * 60 * 26),
|
||||
twoWeeksTime = currentTime + (60 * 60 * 24 * 14),
|
||||
twoMonthsTime = currentTime + (60 * 60 * 24 * 56),
|
||||
twoYearsTime = currentTime + (60 * 60 * 24 * 365 * 2),
|
||||
dataCache = [
|
||||
{
|
||||
id: 1,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 1',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 1,
|
||||
coursename: 'Course 1',
|
||||
coursesummary: 'This is a brief summary of course 1',
|
||||
courseStartDate: 'Oct 1, 2016',
|
||||
courseEndDate: 'Oct 6, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: todayTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 2',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 1,
|
||||
coursename: 'Course 1',
|
||||
coursesummary: 'This is a brief summary of course 1',
|
||||
courseStartDate: 'Oct 1, 2016',
|
||||
courseEndDate: 'Oct 6, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: todayTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 3',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 1,
|
||||
coursename: 'Course 1',
|
||||
coursesummary: 'This is a brief summary of course 1',
|
||||
courseStartDate: 'Oct 1, 2016',
|
||||
courseEndDate: 'Oct 6, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: todayTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 4',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 2,
|
||||
coursename: 'Course 2',
|
||||
coursesummary: 'This is a brief summary of course 2',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: todayTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 5',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 2,
|
||||
coursename: 'Course 2',
|
||||
coursesummary: 'This is a brief summary of course 2',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: todayTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 6',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 2,
|
||||
coursename: 'Course 2',
|
||||
coursesummary: 'This is a brief summary of course 2',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: todayTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 7',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 3,
|
||||
coursename: 'Course 3',
|
||||
coursesummary: 'This is a brief summary of course 3',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: tomorrowTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 8',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 3,
|
||||
coursename: 'Course 3',
|
||||
coursesummary: 'This is a brief summary of course 3',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: tomorrowTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 9',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 2,
|
||||
coursename: 'Course 2',
|
||||
coursesummary: 'This is a brief summary of course 2',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: tomorrowTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 10,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 10',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 1,
|
||||
coursename: 'Course 1',
|
||||
coursesummary: 'This is a brief summary of course 1',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: tomorrowTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 11,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 11',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 2,
|
||||
coursename: 'Course 2',
|
||||
coursesummary: 'This is a brief summary of course 2',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: tomorrowTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 12,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 12',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 2,
|
||||
coursename: 'Course 2',
|
||||
coursesummary: 'This is a brief summary of course 2',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: tomorrowTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 13,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 13',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 1,
|
||||
coursename: 'Course 1',
|
||||
coursesummary: 'This is a brief summary of course 1',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: tomorrowTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 14,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 14',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 3,
|
||||
coursename: 'Course 3',
|
||||
coursesummary: 'This is a brief summary of course 3',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: tomorrowTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 15,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 15',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 1,
|
||||
coursename: 'Course 1',
|
||||
coursesummary: 'This is a brief summary of course 1',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: tomorrowTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 16,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 16',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 1,
|
||||
coursename: 'Course 1',
|
||||
coursesummary: 'This is a brief summary of course 1',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: tomorrowTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 17,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 17',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 1,
|
||||
coursename: 'Course 1',
|
||||
coursesummary: 'This is a brief summary of course 1',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoWeeksTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 18,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 18',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 2,
|
||||
coursename: 'Course 2',
|
||||
coursesummary: 'This is a brief summary of course 2',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoWeeksTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 19,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 19',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 2,
|
||||
coursename: 'Course 2',
|
||||
coursesummary: 'This is a brief summary of course 2',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoWeeksTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 20,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 20',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 2,
|
||||
coursename: 'Course 2',
|
||||
coursesummary: 'This is a brief summary of course 2',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoWeeksTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 21,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 21',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 2,
|
||||
coursename: 'Course 2',
|
||||
coursesummary: 'This is a brief summary of course 2',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoWeeksTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 22,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 22',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 3,
|
||||
coursename: 'Course 3',
|
||||
coursesummary: 'This is a brief summary of course 3',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoWeeksTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 23,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 23',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 3,
|
||||
coursename: 'Course 3',
|
||||
coursesummary: 'This is a brief summary of course 3',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoWeeksTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 24,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 24',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 3,
|
||||
coursename: 'Course 3',
|
||||
coursesummary: 'This is a brief summary of course 3',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoWeeksTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 25,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 25',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 3,
|
||||
coursename: 'Course 3',
|
||||
coursesummary: 'This is a brief summary of course 3',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoWeeksTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 26,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 26',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 3,
|
||||
coursename: 'Course 3',
|
||||
coursesummary: 'This is a brief summary of course 3',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoWeeksTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 27,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 27',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 1,
|
||||
coursename: 'Course 1',
|
||||
coursesummary: 'This is a brief summary of course 1',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoWeeksTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 28,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 28',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 1,
|
||||
coursename: 'Course 1',
|
||||
coursesummary: 'This is a brief summary of course 1',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoWeeksTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 29,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 29',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 1,
|
||||
coursename: 'Course 1',
|
||||
coursesummary: 'This is a brief summary of course 1',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoWeeksTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 30,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 30',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 1,
|
||||
coursename: 'Course 1',
|
||||
coursesummary: 'This is a brief summary of course 1',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoWeeksTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 31,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 31',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 3,
|
||||
coursename: 'Course 3',
|
||||
coursesummary: 'This is a brief summary of course 3',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoWeeksTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 32,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 32',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 3,
|
||||
coursename: 'Course 3',
|
||||
coursesummary: 'This is a brief summary of course 3',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoWeeksTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 33,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 33',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 2,
|
||||
coursename: 'Course 2',
|
||||
coursesummary: 'This is a brief summary of course 2',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoMonthsTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 34,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 34',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 2,
|
||||
coursename: 'Course 2',
|
||||
coursesummary: 'This is a brief summary of course 2',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016', itemcount: 1,
|
||||
orderTime: twoMonthsTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 35,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 35',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 2,
|
||||
coursename: 'Course 2',
|
||||
coursesummary: 'This is a brief summary of course 2',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoMonthsTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 36,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 36',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 1,
|
||||
coursename: 'Course 1',
|
||||
coursesummary: 'This is a brief summary of course 1',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoYearsTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 37,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 37',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 2,
|
||||
coursename: 'Course 2',
|
||||
coursesummary: 'This is a brief summary of course 2',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoYearsTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 38,
|
||||
actionname: 'Submit assignment',
|
||||
actionurl: 'https://www.google.com',
|
||||
enddate: 'Nov 4th, 10am',
|
||||
contextname: 'Assignment due 38',
|
||||
contexturl: 'https://www.google.com',
|
||||
courseid: 3,
|
||||
coursename: 'Course 3',
|
||||
coursesummary: 'This is a brief summary of course 3',
|
||||
courseStartDate: 'Oct 7, 2016',
|
||||
courseEndDate: 'Oct 14, 2016',
|
||||
itemcount: 1,
|
||||
orderTime: twoYearsTime,
|
||||
icon: {
|
||||
key: 'icon',
|
||||
component: 'mod_assign',
|
||||
alttext: 'Assignment icon',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
var DEFAULT_LIMIT = 20;
|
||||
|
||||
var queryFromTimeByCourse = function(courseId, startTime, limit, offset) {
|
||||
var deferred = $.Deferred();
|
||||
|
||||
setTimeout(function() {
|
||||
deferred.resolve(groupEventsByCourseAndTime(courseId, startTime, limit, offset));
|
||||
}, 1000);
|
||||
|
||||
return deferred.promise();
|
||||
};
|
||||
|
||||
var groupEventsByCourseAndTime = function(courseId, startTime, limit, offset) {
|
||||
var eventsByCourse = {};
|
||||
var events = {};
|
||||
$.each(dataCache, function(index, value) {
|
||||
if (!eventsByCourse[value.courseid]) {
|
||||
eventsByCourse[value.courseid] = {
|
||||
courseid: value.courseid,
|
||||
coursename: value.coursename,
|
||||
coursesummary: value.coursesummary,
|
||||
courseStartDate: value.courseStartDate,
|
||||
courseEndDate: value.courseEndDate,
|
||||
calendarEvents: []
|
||||
};
|
||||
}
|
||||
eventsByCourse[value.courseid].calendarEvents.push(value);
|
||||
});
|
||||
|
||||
if (typeof eventsByCourse[courseId] !== 'undefined') {
|
||||
// There are events for this course.
|
||||
events = eventsByCourse[courseId].calendarEvents.slice(offset, offset + limit);
|
||||
/**
|
||||
* Retrieve a list of calendar events for the logged in user for the
|
||||
* given course.
|
||||
*
|
||||
* Valid args are:
|
||||
* int courseid Only get events for this course
|
||||
* int starttime Only get events after this time
|
||||
* int endtime Only get events before this time
|
||||
* int limit Limit the number of results returned
|
||||
* int aftereventid Offset the result set from the given id
|
||||
*
|
||||
* @method queryByCourse
|
||||
* @param {object} args The request arguments
|
||||
* @return {promise} Resolved with an array of the calendar events
|
||||
*/
|
||||
var queryByCourse = function(args) {
|
||||
if (!args.hasOwnProperty('limit')) {
|
||||
args.limit = DEFAULT_LIMIT;
|
||||
}
|
||||
|
||||
return {
|
||||
events: events
|
||||
args.limitnum = args.limit;
|
||||
delete args.limit;
|
||||
|
||||
if (args.hasOwnProperty('starttime')) {
|
||||
args.timesortfrom = args.starttime;
|
||||
delete args.starttime;
|
||||
}
|
||||
|
||||
if (args.hasOwnProperty('endtime')) {
|
||||
args.timesortto = args.endtime;
|
||||
delete args.endtime;
|
||||
}
|
||||
|
||||
var request = {
|
||||
methodname: 'core_calendar_get_action_events_by_course',
|
||||
args: args
|
||||
};
|
||||
|
||||
var promise = Ajax.call([request])[0];
|
||||
|
||||
promise.fail(Notification.exception);
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve a list of calendar events for the given courses for the
|
||||
* logged in user.
|
||||
*
|
||||
* Valid args are:
|
||||
* array courseids Get events for these courses
|
||||
* int starttime Only get events after this time
|
||||
* int endtime Only get events before this time
|
||||
* int limit Limit the number of results returned
|
||||
*
|
||||
* @method queryByCourses
|
||||
* @param {object} args The request arguments
|
||||
* @return {promise} Resolved with an array of the calendar events
|
||||
*/
|
||||
var queryByCourses = function(args) {
|
||||
if (!args.hasOwnProperty('limit')) {
|
||||
// This is intentionally smaller than the default limit.
|
||||
args.limit = 10;
|
||||
}
|
||||
|
||||
args.limitnum = args.limit;
|
||||
delete args.limit;
|
||||
|
||||
if (args.hasOwnProperty('starttime')) {
|
||||
args.timesortfrom = args.starttime;
|
||||
delete args.starttime;
|
||||
}
|
||||
|
||||
if (args.hasOwnProperty('endtime')) {
|
||||
args.timesortto = args.endtime;
|
||||
delete args.endtime;
|
||||
}
|
||||
|
||||
var request = {
|
||||
methodname: 'core_calendar_get_action_events_by_courses',
|
||||
args: args
|
||||
};
|
||||
|
||||
var promise = Ajax.call([request])[0];
|
||||
|
||||
promise.fail(Notification.exception);
|
||||
|
||||
return promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve a list of calendar events for the logged in user after the given
|
||||
* time.
|
||||
*
|
||||
* @method queryFromTime
|
||||
* @param {int} startTime Only get events after this time
|
||||
* @param {int} limit Limit the number of results returned
|
||||
* @param {int} afterEventId Offset the result set from the given id
|
||||
* @return {promise} Resolved with an array of the calendar events
|
||||
* Valid args are:
|
||||
* int starttime Only get events after this time
|
||||
* int endtime Only get events before this time
|
||||
* int limit Limit the number of results returned
|
||||
* int aftereventid Offset the result set from the given id
|
||||
*
|
||||
* @method queryByTime
|
||||
* @param {object} args The request arguments
|
||||
* @return {promise} Resolved with an array of the calendar events
|
||||
*/
|
||||
var queryFromTime = function(startTime, limit, afterEventId) {
|
||||
limit = (typeof limit === 'undefined') ? DEFAULT_LIMIT : limit;
|
||||
var queryByTime = function(args) {
|
||||
if (!args.hasOwnProperty('limit')) {
|
||||
args.limit = DEFAULT_LIMIT;
|
||||
}
|
||||
|
||||
var args = {
|
||||
timesortfrom: startTime,
|
||||
limitnum: limit,
|
||||
};
|
||||
args.limitnum = args.limit;
|
||||
delete args.limit;
|
||||
|
||||
if (typeof afterEventId !== 'undefined') {
|
||||
args.aftereventid = afterEventId;
|
||||
if (args.hasOwnProperty('starttime')) {
|
||||
args.timesortfrom = args.starttime;
|
||||
delete args.starttime;
|
||||
}
|
||||
|
||||
if (args.hasOwnProperty('endtime')) {
|
||||
args.timesortto = args.endtime;
|
||||
delete args.endtime;
|
||||
}
|
||||
|
||||
var request = {
|
||||
@ -867,7 +161,8 @@ define(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notificat
|
||||
};
|
||||
|
||||
return {
|
||||
queryFromTime: queryFromTime,
|
||||
queryFromTimeByCourse: queryFromTimeByCourse
|
||||
queryByTime: queryByTime,
|
||||
queryByCourse: queryByCourse,
|
||||
queryByCourses: queryByCourses,
|
||||
};
|
||||
});
|
||||
|
@ -31,6 +31,7 @@ define(['jquery', 'core/notification', 'core/templates',
|
||||
|
||||
var SELECTORS = {
|
||||
EMPTY_MESSAGE: '[data-region="empty-message"]',
|
||||
ROOT: '[data-region="event-list-container"]',
|
||||
EVENT_LIST: '[data-region="event-list"]',
|
||||
EVENT_LIST_CONTENT: '[data-region="event-list-content"]',
|
||||
EVENT_LIST_GROUP_CONTAINER: '[data-region="event-list-group-container"]',
|
||||
@ -282,15 +283,24 @@ define(['jquery', 'core/notification', 'core/templates',
|
||||
* existing list. The events will be loaded based on the set of data attributes
|
||||
* on the root element.
|
||||
*
|
||||
* This function can be provided with a jQuery promise. If it is then it won't
|
||||
* attempt to load data by itself, instead it will use the given promise.
|
||||
*
|
||||
* The provided promise must resolve with an an object that has an events key
|
||||
* and value is an array of calendar events.
|
||||
* E.g.
|
||||
* { events: ['event 1', 'event 2'] }
|
||||
*
|
||||
* @method load
|
||||
* @param {object} The root element of the event list
|
||||
* @param {promise} A jquery promise
|
||||
* @param {object} root The root element of the event list
|
||||
* @param {object} promise A jQuery promise resolved with events
|
||||
* @return {promise} A jquery promise
|
||||
*/
|
||||
var load = function(root) {
|
||||
var load = function(root, promise) {
|
||||
root = $(root);
|
||||
var limit = +root.attr('data-limit'),
|
||||
courseId = +root.attr('data-course-id'),
|
||||
lastId = root.attr('data-last-id') ? root.attr('data-last-id') : undefined,
|
||||
lastId = root.attr('data-last-id'),
|
||||
date = new Date(),
|
||||
todayTime = Math.floor(date.setHours(0, 0, 0, 0) / 1000);
|
||||
|
||||
@ -301,11 +311,26 @@ define(['jquery', 'core/notification', 'core/templates',
|
||||
|
||||
startLoading(root);
|
||||
|
||||
var promise = null;
|
||||
if (courseId) {
|
||||
promise = CalendarEventsRepository.queryFromTimeByCourse(courseId, todayTime, limit, lastId);
|
||||
} else {
|
||||
promise = CalendarEventsRepository.queryFromTime(todayTime, limit, lastId);
|
||||
// If we haven't been provided a promise to resolve the
|
||||
// data then we will load our own.
|
||||
if (typeof promise == 'undefined') {
|
||||
var args = {
|
||||
starttime: todayTime,
|
||||
limit: limit,
|
||||
};
|
||||
|
||||
if (lastId) {
|
||||
args.aftereventid = lastId;
|
||||
}
|
||||
|
||||
// If we have a course id then we only want events from that course.
|
||||
if (courseId) {
|
||||
args.courseid = courseId;
|
||||
promise = CalendarEventsRepository.queryByCourse(args);
|
||||
} else {
|
||||
// Otherwise we want events from any course.
|
||||
promise = CalendarEventsRepository.queryByTime(args);
|
||||
}
|
||||
}
|
||||
|
||||
// Request data from the server.
|
||||
@ -354,7 +379,7 @@ define(['jquery', 'core/notification', 'core/templates',
|
||||
*/
|
||||
var registerEventListeners = function(root) {
|
||||
CustomEvents.define(root, [CustomEvents.events.activate]);
|
||||
root.one(CustomEvents.events.activate, SELECTORS.VIEW_MORE_BUTTON, function() {
|
||||
root.on(CustomEvents.events.activate, SELECTORS.VIEW_MORE_BUTTON, function() {
|
||||
load(root);
|
||||
});
|
||||
};
|
||||
@ -366,6 +391,7 @@ define(['jquery', 'core/notification', 'core/templates',
|
||||
registerEventListeners(root);
|
||||
},
|
||||
registerEventListeners: registerEventListeners,
|
||||
load: load
|
||||
load: load,
|
||||
rootSelector: SELECTORS.ROOT,
|
||||
};
|
||||
});
|
||||
|
@ -21,11 +21,16 @@
|
||||
* @copyright 2016 Simey Lameze <simey@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define(['jquery', 'block_myoverview/event_list'], function($, EventList) {
|
||||
define(
|
||||
[
|
||||
'jquery',
|
||||
'block_myoverview/event_list',
|
||||
'block_myoverview/calendar_events_repository'
|
||||
],
|
||||
function($, EventList, EventsRepository) {
|
||||
|
||||
var SELECTORS = {
|
||||
EVENTS_BY_COURSE_CONTAINER: '[data-region="course-events-container"]',
|
||||
EVENTS_LIST_CONTAINER: '[data-region="event-list-container"]'
|
||||
};
|
||||
|
||||
/**
|
||||
@ -35,11 +40,58 @@ define(['jquery', 'block_myoverview/event_list'], function($, EventList) {
|
||||
* @param {Object} root The root element of sort by course list.
|
||||
*/
|
||||
var load = function(root) {
|
||||
var courseBlocks = root.find(SELECTORS.EVENTS_BY_COURSE_CONTAINER);
|
||||
|
||||
root.find(SELECTORS.EVENTS_BY_COURSE_CONTAINER).each(function(index, container) {
|
||||
if (!courseBlocks.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
var date = new Date();
|
||||
var todayTime = Math.floor(date.setHours(0, 0, 0, 0) / 1000);
|
||||
var limit = courseBlocks.attr('data-limit');
|
||||
var courseIds = courseBlocks.map(function() {
|
||||
return $(this).attr('data-course-id');
|
||||
}).get();
|
||||
|
||||
// Load the first set of events for each course in a single request.
|
||||
// We want to avoid sending an individual request for each course because
|
||||
// there could be lots of them.
|
||||
var coursesPromise = EventsRepository.queryByCourses({
|
||||
courseids: courseIds,
|
||||
starttime: todayTime,
|
||||
limit: limit
|
||||
});
|
||||
|
||||
// Load the events into each course block.
|
||||
courseBlocks.each(function(index, container) {
|
||||
container = $(container);
|
||||
var eventListContainer = container.find(SELECTORS.EVENTS_LIST_CONTAINER);
|
||||
EventList.load(eventListContainer);
|
||||
var courseId = container.attr('data-course-id');
|
||||
var eventListContainer = container.find(EventList.rootSelector);
|
||||
var promise = $.Deferred();
|
||||
|
||||
// Once all of the course events have been loaded then we need
|
||||
// to extract just the ones relevant to this course block and
|
||||
// hand them to the event list to render.
|
||||
coursesPromise.done(function (result) {
|
||||
var events = [];
|
||||
// Get this course block's events from the collection returned
|
||||
// from the server.
|
||||
var courseGroup = result.groupedbycourse.filter(function(group) {
|
||||
return group.courseid == courseId;
|
||||
});
|
||||
|
||||
if (courseGroup.length) {
|
||||
events = courseGroup[0].events;
|
||||
}
|
||||
|
||||
promise.resolve({events: events});
|
||||
}).fail(function(e) {
|
||||
promise.reject(e);
|
||||
});
|
||||
|
||||
// Provide the event list with a promise that will be resolved
|
||||
// when we have received the events from the server.
|
||||
EventList.load(eventListContainer, promise);
|
||||
});
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user