From 66a91ddada35313602005c65c188781a2337cf0a Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Fri, 16 Dec 2016 10:13:25 +0000 Subject: [PATCH 01/13] MDL-57139 eslint: enable eslint-plugin-promise rules For promise best practices --- .eslintrc | 14 ++++++++++++++ npm-shrinkwrap.json | 6 ++++++ package.json | 1 + 3 files changed, 21 insertions(+) diff --git a/.eslintrc b/.eslintrc index 35147596304..c50d2bb273d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,4 +1,7 @@ { + 'plugins': [ + 'promise', + ], 'env': { 'browser': true, 'amd': true @@ -170,11 +173,22 @@ 'unicode-bom': 'error', 'wrap-regex': 'off', + // === Promises === + 'promise/always-return': 'warn', + 'promise/no-return-wrap': 'warn', + 'promise/param-names': 'warn', + 'promise/catch-or-return': ['warn', {terminationMethod: ['catch', 'fail']}], + 'promise/no-native': 'warn', + 'promise/no-promise-in-callback': 'warn', + 'promise/no-callback-in-promise': 'warn', + 'promise/avoid-new': 'warn', + // === Deprecations === "no-restricted-properties": ['warn', { 'object': 'M', 'property': 'str', 'message': 'Use AMD module "core/str" or M.util.get_string()' }], + } } diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 3792266410d..19a7c66e9a0 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -821,6 +821,12 @@ "integrity": "sha1-f6qEWZ4P6kIvBLwy20kFQFGj8Ro=", "dev": true }, + "eslint-plugin-promise": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-3.5.0.tgz", + "integrity": "sha1-ePu2/+BHIBYnVp6FpsU3OvKmj8o=", + "dev": true + }, "espree": { "version": "3.4.3", "resolved": "https://registry.npmjs.org/espree/-/espree-3.4.3.tgz", diff --git a/package.json b/package.json index 2a7d142ca14..0ee1295b040 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "devDependencies": { "async": "1.5.2", "eslint": "3.7.1", + "eslint-plugin-promise": "3.5.0", "gherkin-lint": "1.1.3", "grunt": "1.0.1", "grunt-contrib-less": "1.3.0", From 877d997fe13c5885e4414e79cdeaaaa363d43e2b Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Tue, 10 Jan 2017 10:10:56 +0000 Subject: [PATCH 02/13] MDL-57139 messages/notifications: ensure promise best practices Previously there were a few issues with the code * We were capturing a promise without then then .then() that came after it, so our promise wouldn't always be completely resolved by the time then next piece of code was operating on it * We weren't catching all errors with .catch() --- message/amd/src/message_area_messages.js | 85 +++++++++---------- message/amd/src/message_area_search.js | 2 +- .../amd/src/message_popover_controller.js | 47 ++++------ .../amd/src/notification_area_control_area.js | 44 ++++------ .../src/notification_popover_controller.js | 50 +++++------ 5 files changed, 95 insertions(+), 133 deletions(-) diff --git a/message/amd/src/message_area_messages.js b/message/amd/src/message_area_messages.js index 1015e137404..4c5711bafc8 100644 --- a/message/amd/src/message_area_messages.js +++ b/message/amd/src/message_area_messages.js @@ -455,9 +455,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust } }); }); - if (requests.length > 0) { - Ajax.call(requests)[requests.length - 1].then(function() { + $.when(Ajax.call(requests)).then(function() { // Store the last message on the page, and the last message being deleted. var updatemessage = null; var messages = this.messageArea.find(SELECTORS.MESSAGE); @@ -491,7 +490,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust // Trigger event letting other modules know messages were deleted. this.messageArea.trigger(Events.MESSAGESDELETED, [this._getUserId(), updatemessage]); - }.bind(this), Notification.exception); + }.bind(this)).catch(Notification.exception); } else { // Trigger event letting other modules know messages were deleted. this.messageArea.trigger(Events.MESSAGESDELETED, this._getUserId()); @@ -526,49 +525,47 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust * @private */ Messages.prototype._deleteAllMessages = function() { - // Create the confirmation modal if we haven't already. - if (!this._confirmationModal) { - Str.get_strings([ - {key: 'confirm'}, - {key: 'deleteallconfirm', component: 'message'} - ]).done(function(s) { - ModalFactory.create({ - title: s[0], - type: ModalFactory.types.CONFIRM, - body: s[1] - }, this.messageArea.find(SELECTORS.DELETEALLMESSAGES)) - .done(function(modal) { - this._confirmationModal = modal; - - // Only delete the conversation if the user agreed in the confirmation modal. - modal.getRoot().on(ModalEvents.yes, function() { - var otherUserId = this._getUserId(); - var request = { - methodname: 'core_message_delete_conversation', - args: { - userid: this.messageArea.getCurrentUserId(), - otheruserid: otherUserId - } - }; - - // Delete the conversation. - Ajax.call([request])[0].then(function() { - // Clear the message area. - this.messageArea.find(SELECTORS.MESSAGESAREA).empty(); - // Let the app know a conversation was deleted. - this.messageArea.trigger(Events.CONVERSATIONDELETED, otherUserId); - this._hideDeleteAction(); - }.bind(this), Notification.exception); - }.bind(this)); - - // Display the confirmation. - modal.show(); - }.bind(this)); - }.bind(this)); - } else { - // Otherwise just show the existing modal. + if (this._confirmationModal) { + // Just show the existing modal. this._confirmationModal.show(); + return; } + + Str.get_strings([ + {key: 'confirm'}, + {key: 'deleteallconfirm', component: 'message'} + ]).then(function(s) { + return ModalFactory.create({ + title: s[0], + type: ModalFactory.types.CONFIRM, + body: s[1] + }, this.messageArea.find(SELECTORS.DELETEALLMESSAGES)); + }.bind(this)).then(function(modal) { + this._confirmationModal = modal; + // Only delete the conversation if the user agreed in the confirmation modal. + modal.getRoot().on(ModalEvents.yes, function() { + var otherUserId = this._getUserId(); + var request = { + methodname: 'core_message_delete_conversation', + args: { + userid: this.messageArea.getCurrentUserId(), + otheruserid: otherUserId + } + }; + + // Delete the conversation. + Ajax.call([request])[0].then(function() { + // Clear the message area. + this.messageArea.find(SELECTORS.MESSAGESAREA).empty(); + // Let the app know a conversation was deleted. + this.messageArea.trigger(Events.CONVERSATIONDELETED, otherUserId); + this._hideDeleteAction(); + }.bind(this)).catch(Notification.exception); + }.bind(this)); + + // Display the confirmation. + modal.show(); + }.bind(this)).catch(Notification.exception); }; /** diff --git a/message/amd/src/message_area_search.js b/message/amd/src/message_area_search.js index 584f4f8c488..46960d7a7d8 100644 --- a/message/amd/src/message_area_search.js +++ b/message/amd/src/message_area_search.js @@ -385,7 +385,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' this.messageArea.find(SELECTORS.SEARCHFILTER).html(text); Str.get_string('removecoursefilter', 'message', text).then(function(languagestring) { this.messageArea.find(SELECTORS.SEARCHFILTERAREA).attr('aria-label', languagestring); - }.bind(this)); + }.bind(this)).catch(Notification.exception); }; /** diff --git a/message/output/popup/amd/src/message_popover_controller.js b/message/output/popup/amd/src/message_popover_controller.js index 8787b28e40b..56996981222 100644 --- a/message/output/popup/amd/src/message_popover_controller.js +++ b/message/output/popup/amd/src/message_popover_controller.js @@ -151,7 +151,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str', this.unreadCount = count; this.renderUnreadCount(); this.updateButtonAriaLabel(); - }.bind(this)); + }.bind(this)).catch(Notification.exception); }; /** @@ -165,38 +165,27 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str', */ MessagePopoverController.prototype.renderMessages = function(messages, container) { var promises = []; - var allhtml = []; - var alljs = []; - if (messages.length) { - $.each(messages, function(index, message) { - message.contexturl = URL.relativeUrl('/message/index.php', { - user: this.userId, - id: message.userid, - }); + $.each(messages, function(index, message) { + message.contexturl = URL.relativeUrl('/message/index.php', { + user: this.userId, + id: message.userid, + }); - message.profileurl = URL.relativeUrl('/user/profile.php', { - id: message.userid, - }); + message.profileurl = URL.relativeUrl('/user/profile.php', { + id: message.userid, + }); - var promise = Templates.render('message_popup/message_content_item', message); - promises.push(promise); + var promise = Templates.render('message_popup/message_content_item', message) + .then(function(html, js) { + container.append(html); + Templates.runTemplateJS(js); + return; + }); + promises.push(promise); + }.bind(this)); - promise.then(function(html, js) { - allhtml[index] = html; - alljs[index] = js; - }); - }.bind(this)); - } - - return $.when.apply($.when, promises).then(function() { - if (messages.length) { - $.each(messages, function(index) { - container.append(allhtml[index]); - Templates.runTemplateJS(alljs[index]); - }); - } - }); + return $.when.apply($, promises); }; /** diff --git a/message/output/popup/amd/src/notification_area_control_area.js b/message/output/popup/amd/src/notification_area_control_area.js index ee19a0e16aa..5feea45cf11 100644 --- a/message/output/popup/amd/src/notification_area_control_area.js +++ b/message/output/popup/amd/src/notification_area_control_area.js @@ -307,39 +307,27 @@ define(['jquery', 'core/templates', 'core/notification', 'core/custom_interactio */ ControlArea.prototype.renderNotifications = function(notifications) { var promises = []; - var allhtml = []; - var alljs = []; var container = this.getContent(); - if (notifications.length) { - $.each(notifications, function(index, notification) { - // Need to remove the contexturl so the item isn't rendered - // as a link. - var contextUrl = notification.contexturl; - delete notification.contexturl; + $.each(notifications, function(index, notification) { + // Need to remove the contexturl so the item isn't rendered + // as a link. + var contextUrl = notification.contexturl; + delete notification.contexturl; - var promise = Templates.render(TEMPLATES.NOTIFICATION, notification); - - promises.push(promise); - promise.then(function(html, js) { - allhtml[index] = html; - alljs[index] = js; - // Restore it for the cache. - notification.contexturl = contextUrl; - this.setCacheNotification(notification); - }.bind(this)) - .fail(DebugNotification.exception); + var promise = Templates.render(TEMPLATES.NOTIFICATION, notification) + .then(function(html, js) { + container.append(html); + Templates.runTemplateJS(js); + // Restore it for the cache. + notification.contexturl = contextUrl; + this.setCacheNotification(notification); + return; }.bind(this)); - } + promises.push(promise); + }.bind(this)); - return $.when.apply($.when, promises).then(function() { - if (notifications.length) { - $.each(notifications, function(index) { - container.append(allhtml[index]); - Templates.runTemplateJS(alljs[index]); - }); - } - }); + return $.when.apply($, promises); }; /** diff --git a/message/output/popup/amd/src/notification_popover_controller.js b/message/output/popup/amd/src/notification_popover_controller.js index 4036b70eda0..2d5a2c4d369 100644 --- a/message/output/popup/amd/src/notification_popover_controller.js +++ b/message/output/popup/amd/src/notification_popover_controller.js @@ -200,7 +200,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str', 'core/url', this.unreadCount = count; this.renderUnreadCount(); this.updateButtonAriaLabel(); - }.bind(this)); + }.bind(this)).catch(DebugNotification.exception); }; /** @@ -226,39 +226,27 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str', 'core/url', */ NotificationPopoverController.prototype.renderNotifications = function(notifications, container) { var promises = []; - var allhtml = []; - var alljs = []; - if (notifications.length) { - $.each(notifications, function(index, notification) { - // Determine what the offset was when loading this notification. - var offset = this.getOffset() - this.limit; - // Update the view more url to contain the offset to allow the notifications - // page to load to the correct position in the list of notifications. - notification.viewmoreurl = URL.relativeUrl('/message/output/popup/notifications.php', { - notificationid: notification.id, - offset: offset, - }); + $.each(notifications, function(index, notification) { + // Determine what the offset was when loading this notification. + var offset = this.getOffset() - this.limit; + // Update the view more url to contain the offset to allow the notifications + // page to load to the correct position in the list of notifications. + notification.viewmoreurl = URL.relativeUrl('/message/output/popup/notifications.php', { + notificationid: notification.id, + offset: offset, + }); - var promise = Templates.render('message_popup/notification_content_item', notification); - promises.push(promise); + var promise = Templates.render('message_popup/notification_content_item', notification) + .then(function(html, js) { + container.append(html); + Templates.runTemplateJS(js); + return; + }); + promises.push(promise); + }.bind(this)); - promise.then(function(html, js) { - allhtml[index] = html; - alljs[index] = js; - }) - .fail(DebugNotification.exception); - }.bind(this)); - } - - return $.when.apply($.when, promises).then(function() { - if (notifications.length) { - $.each(notifications, function(index) { - container.append(allhtml[index]); - Templates.runTemplateJS(alljs[index]); - }); - } - }); + return $.when.apply($, promises); }; /** From d85d7831d0a8d93bf05b4622cc60f76d60a09816 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Tue, 10 Jan 2017 18:05:39 +0000 Subject: [PATCH 03/13] MDL-57139 assign: ensure promise best practices --- mod/assign/amd/src/participant_selector.js | 1 + 1 file changed, 1 insertion(+) diff --git a/mod/assign/amd/src/participant_selector.js b/mod/assign/amd/src/participant_selector.js index f1d055e9a4a..1323c77c09c 100644 --- a/mod/assign/amd/src/participant_selector.js +++ b/mod/assign/amd/src/participant_selector.js @@ -107,6 +107,7 @@ define(['core/ajax', 'jquery', 'core/templates'], function(ajax, $, templates) { } success(users); + return; }).catch(failure); } }; From e58ecca175a04c14f0e3ff3f5333290e3383d2b8 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Tue, 10 Jan 2017 17:29:31 +0000 Subject: [PATCH 04/13] MDL-57139 core/fragment: simplify promises and always return We can remove the DIY promise handling because the ajax request can just return a promise itself. --- lib/amd/src/fragment.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/lib/amd/src/fragment.js b/lib/amd/src/fragment.js index 28627fce4d4..0a29f68156c 100644 --- a/lib/amd/src/fragment.js +++ b/lib/amd/src/fragment.js @@ -45,10 +45,7 @@ define(['jquery', 'core/ajax'], function($, ajax) { }); } - // Ajax stuff. - var deferred = $.Deferred(); - - var promises = ajax.call([{ + return ajax.call([{ methodname: 'core_get_fragment', args: { component: component, @@ -56,14 +53,7 @@ define(['jquery', 'core/ajax'], function($, ajax) { contextid: contextid, args: formattedparams } - }], false); - - promises[0].done(function(data) { - deferred.resolve(data); - }).fail(function(ex) { - deferred.reject(ex); - }); - return deferred.promise(); + }])[0]; }; return /** @alias module:core/fragment */{ @@ -81,7 +71,7 @@ define(['jquery', 'core/ajax'], function($, ajax) { */ loadFragment: function(component, callback, contextid, params) { var promise = $.Deferred(); - $.when(loadFragment(component, callback, contextid, params)).then(function(data) { + loadFragment(component, callback, contextid, params).then(function(data) { var jsNodes = $(data.javascript); var allScript = ''; jsNodes.each(function(index, scriptNode) { @@ -111,6 +101,7 @@ define(['jquery', 'core/ajax'], function($, ajax) { } }); promise.resolve(data.html, allScript); + return; }).fail(function(ex) { promise.reject(ex); }); From 7efdac5fc3e5c84529af36cf2c06a269caf56976 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Tue, 10 Jan 2017 17:54:17 +0000 Subject: [PATCH 05/13] MDL-57139 tool_usertours: return in promises --- admin/tool/usertours/amd/src/usertours.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/admin/tool/usertours/amd/src/usertours.js b/admin/tool/usertours/amd/src/usertours.js index e0d877d52c3..4541f232421 100644 --- a/admin/tool/usertours/amd/src/usertours.js +++ b/admin/tool/usertours/amd/src/usertours.js @@ -68,6 +68,7 @@ function(ajax, BootstrapTour, $, templates, str, log, notification) { templates.render('tool_usertours/tourstep', {}) ).then(function(response, template) { usertours.startBootstrapTour(tourId, template[0], response.tourconfig); + return; }).fail(notification.exception); }, @@ -213,6 +214,7 @@ function(ajax, BootstrapTour, $, templates, str, log, notification) { if (response.startTour) { usertours.fetchTour(response.startTour); } + return; }).fail(notification.exception); } }; From 1fea12b0ebefce42b44e9b459d90aa7a73663502 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Tue, 10 Jan 2017 11:07:34 +0000 Subject: [PATCH 06/13] MDL-57139 mod_lti: ensure promise best practices --- mod/lti/amd/src/contentitem.js | 65 ++++++++++++------------- mod/lti/amd/src/tool_card_controller.js | 24 +++++---- 2 files changed, 43 insertions(+), 46 deletions(-) diff --git a/mod/lti/amd/src/contentitem.js b/mod/lti/amd/src/contentitem.js index 42e9808c402..a6dad9222b5 100644 --- a/mod/lti/amd/src/contentitem.js +++ b/mod/lti/amd/src/contentitem.js @@ -46,42 +46,41 @@ define( * @param {object} postData The data to be sent for the content item selection request. */ init: function(url, postData) { - var dialogueTitle = ''; + var context = { + url: url, + postData: postData + }; + var bodyPromise = templates.render('mod_lti/contentitem', context); + + if (dialogue) { + // Set dialogue body. + dialogue.setBody(bodyPromise); + // Display the dialogue. + dialogue.show(); + return; + } + str.get_string('selectcontent', 'lti').then(function(title) { - dialogueTitle = title; - var context = { - url: url, - postData: postData - }; + return ModalFactory.create({ + title: title, + body: bodyPromise, + large: true + }); + }).then(function(modal) { + dialogue = modal; + // On hide handler. + modal.getRoot().on(ModalEvents.hidden, function() { + // Empty modal contents when it's hidden. + modal.setBody(''); - var body = templates.render('mod_lti/contentitem', context); - if (dialogue) { - // Set dialogue body. - dialogue.setBody(body); - // Display the dialogue. - dialogue.show(); - } else { - ModalFactory.create({ - title: dialogueTitle, - body: body, - large: true - }).done(function(modal) { - dialogue = modal; + // Fetch notifications. + notification.fetchNotifications(); + }); - // Display the dialogue. - dialogue.show(); - - // On hide handler. - modal.getRoot().on(ModalEvents.hidden, function() { - // Empty modal contents when it's hidden. - modal.setBody(''); - - // Fetch notifications. - notification.fetchNotifications(); - }); - }); - } - }); + // Display the dialogue. + modal.show(); + return; + }).catch(notification.exception); } }; diff --git a/mod/lti/amd/src/tool_card_controller.js b/mod/lti/amd/src/tool_card_controller.js index 99042db9fbe..4050f724f65 100644 --- a/mod/lti/amd/src/tool_card_controller.js +++ b/mod/lti/amd/src/tool_card_controller.js @@ -477,21 +477,19 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/templates', 'mod_lti/t state: toolType.constants.state.configured }); - promise.done(function(toolTypeData) { + promise.then(function(toolTypeData) { stopLoading(element); + announceSuccess(element); + return toolTypeData; + }).then(function(toolTypeData) { + return templates.render('mod_lti/tool_card', toolTypeData); + }).then(function(renderResult) { + var html = renderResult[0]; + var js = renderResult[1]; - var announcePromise = announceSuccess(element); - var renderPromise = templates.render('mod_lti/tool_card', toolTypeData); - - $.when(renderPromise, announcePromise).then(function(renderResult) { - var html = renderResult[0]; - var js = renderResult[1]; - - templates.replaceNode(element, html, js); - }); - }); - - promise.fail(function() { + templates.replaceNode(element, html, js); + return; + }).catch(function() { stopLoading(element); announceFailure(element); }); From 08c2360e4aafc14d7c9702a7a05837099b2625cb Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Sun, 15 Jan 2017 14:48:51 +0000 Subject: [PATCH 07/13] MDL-57139 competencies: ensure promise best practices --- admin/tool/lp/amd/src/actionselector.js | 2 + admin/tool/lp/amd/src/competencies.js | 12 ++-- .../tool/lp/amd/src/competency_rule_points.js | 1 + admin/tool/lp/amd/src/competencyactions.js | 58 ++++++++++--------- admin/tool/lp/amd/src/competencypicker.js | 21 +++---- .../lp/amd/src/competencypicker_user_plans.js | 3 +- admin/tool/lp/amd/src/competencyruleconfig.js | 26 ++++----- admin/tool/lp/amd/src/evidence_delete.js | 1 + admin/tool/lp/amd/src/form-cohort-selector.js | 4 +- admin/tool/lp/amd/src/form-user-selector.js | 3 +- .../tool/lp/amd/src/frameworks_datasource.js | 11 ++-- .../tool/lp/amd/src/parentcompetency_form.js | 1 + admin/tool/lp/amd/src/planactions.js | 14 ++--- .../lp/amd/src/user_competency_plan_popup.js | 10 ++-- .../lp/amd/src/user_competency_workflow.js | 9 ++- .../tool/lp/amd/src/user_evidence_actions.js | 12 ++-- report/competency/amd/src/grading_popup.js | 17 +++--- 17 files changed, 103 insertions(+), 102 deletions(-) diff --git a/admin/tool/lp/amd/src/actionselector.js b/admin/tool/lp/amd/src/actionselector.js index 582478ba332..380e05af76f 100644 --- a/admin/tool/lp/amd/src/actionselector.js +++ b/admin/tool/lp/amd/src/actionselector.js @@ -131,6 +131,7 @@ define(['jquery', html, self._afterRender.bind(self) ); + return; }).fail(Notification.exception); }; @@ -156,6 +157,7 @@ define(['jquery', return self._render().then(function(html) { self._find('[data-region="action-selector"]').replaceWith(html); self._afterRender(); + return; }); }; diff --git a/admin/tool/lp/amd/src/competencies.js b/admin/tool/lp/amd/src/competencies.js index 79e1aa96a64..1b8211617a9 100644 --- a/admin/tool/lp/amd/src/competencies.js +++ b/admin/tool/lp/amd/src/competencies.js @@ -181,13 +181,13 @@ define(['jquery', pagerender = 'tool_lp/plan_page'; pageregion = 'plan-page'; } - ajax.call(requests)[requests.length - 1].then(function(context) { - return templates.render(pagerender, context).done(function(html, js) { - $('[data-region="' + pageregion + '"]').replaceWith(html); - templates.runTemplateJS(js); - }); - }, notification.exception); + return templates.render(pagerender, context); + }).then(function(html, js) { + $('[data-region="' + pageregion + '"]').replaceWith(html); + templates.runTemplateJS(js); + return; + }).catch(notification.exception); }); } diff --git a/admin/tool/lp/amd/src/competency_rule_points.js b/admin/tool/lp/amd/src/competency_rule_points.js index 5c4ec1721bb..542cf0901aa 100644 --- a/admin/tool/lp/amd/src/competency_rule_points.js +++ b/admin/tool/lp/amd/src/competency_rule_points.js @@ -166,6 +166,7 @@ define(['jquery', // We're done, let's trigger a change. self._templateLoaded = true; self._triggerChange(); + return; }); }; diff --git a/admin/tool/lp/amd/src/competencyactions.js b/admin/tool/lp/amd/src/competencyactions.js index 522e8272f2a..5c433f4ba7f 100644 --- a/admin/tool/lp/amd/src/competencyactions.js +++ b/admin/tool/lp/amd/src/competencyactions.js @@ -430,12 +430,13 @@ define(['jquery', var promises = ajax.call(calls); promises[calls.length - 1].then(function(context) { - return templates.render('tool_lp/related_competencies', context).done(function(html, js) { - $('[data-region="relatedcompetencies"]').replaceWith(html); - templates.runTemplateJS(js); - updatedRelatedCompetencies(); - }); - }, notification.exception); + return templates.render('tool_lp/related_competencies', context); + }).then(function(html, js) { + $('[data-region="relatedcompetencies"]').replaceWith(html); + templates.runTemplateJS(js); + updatedRelatedCompetencies(); + return; + }).catch(notification.exception); }); } @@ -472,7 +473,8 @@ define(['jquery', relatedTarget.ruleconfig = config.ruleconfig; renderCompetencySummary(relatedTarget); } - }, notification.exception); + return; + }).catch(notification.exception); }; /** @@ -692,28 +694,27 @@ define(['jquery', type: strs[1] }; } - }).then(function() { - return templates.render('tool_lp/competency_summary', context).then(function(html) { - $('[data-region="competencyinfo"]').html(html); - $('[data-action="deleterelation"]').on('click', deleteRelatedHandler); - }); - }).then(function() { + return context; + }).then(function(context) { + return templates.render('tool_lp/competency_summary', context); + }).then(function(html) { + $('[data-region="competencyinfo"]').html(html); + $('[data-action="deleterelation"]').on('click', deleteRelatedHandler); return templates.render('tool_lp/loading', {}); }).then(function(html, js) { templates.replaceNodeContents('[data-region="relatedcompetencies"]', html, js); - }).done(function() { - ajax.call([{ + return ajax.call([{ methodname: 'tool_lp_data_for_related_competencies_section', - args: {competencyid: competency.id}, - done: function(context) { - return templates.render('tool_lp/related_competencies', context).done(function(html, js) { - $('[data-region="relatedcompetencies"]').replaceWith(html); - templates.runTemplateJS(js); - updatedRelatedCompetencies(); - }); - } - }]); - }).fail(notification.exception); + args: {competencyid: competency.id} + }])[0]; + }).then(function(context) { + return templates.render('tool_lp/related_competencies', context); + }).then(function(html, js) { + $('[data-region="relatedcompetencies"]').replaceWith(html); + templates.runTemplateJS(js); + updatedRelatedCompetencies(); + return; + }).catch(notification.exception); }; /** @@ -776,16 +777,17 @@ define(['jquery', // Log Competency viewed event. triggerCompetencyViewedEvent(competency); } - strSelectedTaxonomy(level).then(function(str) { selectedTitle.text(str); - }); + return; + }).catch(notification.exception); strAddTaxonomy(sublevel).then(function(str) { btn.show() .find('[data-region="term"]') .text(str); - }); + return; + }).catch(notification.exception); // We handled this event so consume it. evt.preventDefault(); diff --git a/admin/tool/lp/amd/src/competencypicker.js b/admin/tool/lp/amd/src/competencypicker.js index 1aebe058e79..23dce8a71ab 100644 --- a/admin/tool/lp/amd/src/competencypicker.js +++ b/admin/tool/lp/amd/src/competencypicker.js @@ -134,7 +134,7 @@ define(['jquery', if (!self._singleFramework) { self._find('[data-action="chooseframework"]').change(function(e) { self._frameworkId = $(e.target).val(); - self._loadCompetencies().then(self._refresh.bind(self)); + self._loadCompetencies().then(self._refresh.bind(self)).catch(Notification.exception); }); } @@ -203,15 +203,15 @@ define(['jquery', */ Picker.prototype.display = function() { var self = this; - return self._render().then(function(html) { - return Str.get_string('competencypicker', 'tool_lp').then(function(title) { - self._popup = new Dialogue( - title, - html, - self._afterRender.bind(self) - ); - }); - }).fail(Notification.exception); + return $.when(Str.get_string('competencypicker', 'tool_lp'), self._render()) + .then(function(title, render) { + self._popup = new Dialogue( + title, + render[0], + self._afterRender.bind(self) + ); + return; + }).catch(Notification.exception); }; /** @@ -388,6 +388,7 @@ define(['jquery', return self._render().then(function(html) { self._find('[data-region="competencylinktree"]').replaceWith(html); self._afterRender(); + return; }); }; diff --git a/admin/tool/lp/amd/src/competencypicker_user_plans.js b/admin/tool/lp/amd/src/competencypicker_user_plans.js index 8d5b5369f0c..e621f32eebc 100644 --- a/admin/tool/lp/amd/src/competencypicker_user_plans.js +++ b/admin/tool/lp/amd/src/competencypicker_user_plans.js @@ -77,7 +77,8 @@ define(['jquery', if (!self._singlePlan) { self._find('[data-action="chooseplan"]').change(function(e) { self._planId = $(e.target).val(); - self._loadCompetencies().then(self._refresh.bind(self)); + self._loadCompetencies().then(self._refresh.bind(self)) + .catch(Notification.exception); }); } }; diff --git a/admin/tool/lp/amd/src/competencyruleconfig.js b/admin/tool/lp/amd/src/competencyruleconfig.js index 3a956cb40d6..b0e3db621b2 100644 --- a/admin/tool/lp/amd/src/competencyruleconfig.js +++ b/admin/tool/lp/amd/src/competencyruleconfig.js @@ -165,14 +165,14 @@ define(['jquery', if (!self._competency) { return false; } - return self._render().then(function(html) { - return Str.get_string('competencyrule', 'tool_lp').then(function(title) { - self._popup = new Dialogue( - title, - html, - self._afterRender.bind(self) - ); - }); + return $.when(Str.get_string('competencyrule', 'tool_lp'), self._render()) + .then(function(title, render) { + self._popup = new Dialogue( + title, + render[0], + self._afterRender.bind(self) + ); + return; }).fail(Notification.exception); }; @@ -312,9 +312,9 @@ define(['jquery', */ RuleConfig.prototype._initOutcomes = function() { var self = this; - return Outcomes.getAll().then(function(outcomes) { self._outcomesOption = outcomes; + return; }); }; @@ -328,11 +328,11 @@ define(['jquery', RuleConfig.prototype._initRules = function() { var self = this, promises = []; - $.each(self._rules, function(index, rule) { var promise = rule.init().then(function() { rule.setTargetCompetency(self._competency); rule.on('change', self._afterRuleConfigChange.bind(self)); + return; }, function() { // Upon failure remove the rule, and resolve the promise. self._rules.splice(index, 1); @@ -518,13 +518,13 @@ define(['jquery', self._afterChange(); return; } - rule.injectTemplate(container).then(function() { container.show(); - }, function() { - container.empty().hide(); + return; }).always(function() { self._afterChange(); + }).catch(function() { + container.empty().hide(); }); }; diff --git a/admin/tool/lp/amd/src/evidence_delete.js b/admin/tool/lp/amd/src/evidence_delete.js index ac59ad9a28b..e695e122a2b 100644 --- a/admin/tool/lp/amd/src/evidence_delete.js +++ b/admin/tool/lp/amd/src/evidence_delete.js @@ -76,6 +76,7 @@ define(['jquery', }]); promise[0].then(function() { parent.remove(); + return; }).fail(Notification.exception); } ); diff --git a/admin/tool/lp/amd/src/form-cohort-selector.js b/admin/tool/lp/amd/src/form-cohort-selector.js index 486c25cdcd9..281c492cc30 100644 --- a/admin/tool/lp/amd/src/form-cohort-selector.js +++ b/admin/tool/lp/amd/src/form-cohort-selector.js @@ -51,7 +51,6 @@ define(['jquery', 'core/ajax', 'core/templates'], function($, Ajax, Templates) { includes: includes } }]); - promise[0].then(function(results) { var promises = [], i = 0; @@ -69,9 +68,10 @@ define(['jquery', 'core/ajax', 'core/templates'], function($, Ajax, Templates) { i++; }); success(results.cohorts); + return; }); - }, failure); + }).catch(failure); } }; diff --git a/admin/tool/lp/amd/src/form-user-selector.js b/admin/tool/lp/amd/src/form-user-selector.js index 8713d069d6a..3d1e6139ee1 100644 --- a/admin/tool/lp/amd/src/form-user-selector.js +++ b/admin/tool/lp/amd/src/form-user-selector.js @@ -79,9 +79,10 @@ define(['jquery', 'core/ajax', 'core/templates'], function($, Ajax, Templates) { i++; }); success(results.users); + return; }); - }, failure); + }).catch(failure); } }; diff --git a/admin/tool/lp/amd/src/frameworks_datasource.js b/admin/tool/lp/amd/src/frameworks_datasource.js index 3638830c654..c46d0050a9b 100644 --- a/admin/tool/lp/amd/src/frameworks_datasource.js +++ b/admin/tool/lp/amd/src/frameworks_datasource.js @@ -35,20 +35,17 @@ define(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notificat * @return {Promise} */ list: function(contextId, options) { - var promise, - args = { + var args = { context: { contextid: contextId } }; $.extend(args, typeof options === 'undefined' ? {} : options); - promise = Ajax.call([{ + return Ajax.call([{ methodname: 'core_competency_list_competency_frameworks', args: args }])[0]; - - return promise.fail(Notification.exception); }, /** @@ -76,6 +73,7 @@ define(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notificat * @param {String} query The query string. * @param {Function} callback A callback function receiving an array of results. */ + /* eslint-disable promise/no-callback-in-promise */ transport: function(selector, query, callback) { var el = $(selector), contextId = el.data('contextid'), @@ -84,11 +82,10 @@ define(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notificat if (!contextId) { throw new Error('The attribute data-contextid is required on ' + selector); } - this.list(contextId, { query: query, onlyvisible: onlyVisible, - }).then(callback); + }).then(callback).catch(Notification.exception); } }; diff --git a/admin/tool/lp/amd/src/parentcompetency_form.js b/admin/tool/lp/amd/src/parentcompetency_form.js index 705ab294f09..c42aece359f 100644 --- a/admin/tool/lp/amd/src/parentcompetency_form.js +++ b/admin/tool/lp/amd/src/parentcompetency_form.js @@ -81,6 +81,7 @@ define(['jquery', 'core/ajax', 'core/str', 'tool_lp/competencypicker', 'core/tem Str.get_string('competencyframeworkroot', 'tool_lp').then(function(rootframework) { $(self.staticElementSelector).html(rootframework); $(self.inputHiddenSelector).val(data.competencyId); + return; }).fail(Notification.exception); } }; diff --git a/admin/tool/lp/amd/src/planactions.js b/admin/tool/lp/amd/src/planactions.js index 932318f69cf..be39396e356 100644 --- a/admin/tool/lp/amd/src/planactions.js +++ b/admin/tool/lp/amd/src/planactions.js @@ -110,15 +110,16 @@ define(['jquery', * Callback to render the region template. * * @param {Object} context The context for the template. + * @return {Promise} */ PlanActions.prototype._renderView = function(context) { var self = this; - templates.render(self._template, context) - .done(function(newhtml, newjs) { + return templates.render(self._template, context) + .then(function(newhtml, newjs) { $(self._region).replaceWith(newhtml); templates.runTemplateJS(newjs); - }) - .fail(notification.exception); + return; + }); }; /** @@ -130,16 +131,15 @@ define(['jquery', */ PlanActions.prototype._callAndRefresh = function(calls, planData) { var self = this; - calls.push({ methodname: self._contextMethod, args: self._getContextArgs(planData) }); // Apply all the promises, and refresh when the last one is resolved. - return $.when.apply($.when, ajax.call(calls)) + return $.when.apply($, ajax.call(calls)) .then(function() { - self._renderView(arguments[arguments.length - 1]); + return self._renderView(arguments[arguments.length - 1]); }) .fail(notification.exception); }; diff --git a/admin/tool/lp/amd/src/user_competency_plan_popup.js b/admin/tool/lp/amd/src/user_competency_plan_popup.js index 6600b1f8285..e7aff466753 100644 --- a/admin/tool/lp/amd/src/user_competency_plan_popup.js +++ b/admin/tool/lp/amd/src/user_competency_plan_popup.js @@ -58,7 +58,6 @@ define(['jquery', 'core/notification', 'core/str', 'core/ajax', 'core/templates' done: this._contextLoaded.bind(this), fail: notification.exception }]); - // Log the user competency viewed in plan event. requests[0].then(function(result) { var eventMethodName = 'core_competency_user_competency_viewed_in_plan'; @@ -66,12 +65,11 @@ define(['jquery', 'core/notification', 'core/str', 'core/ajax', 'core/templates' if (result.plan.iscompleted) { eventMethodName = 'core_competency_user_competency_plan_viewed'; } - ajax.call([{ + return ajax.call([{ methodname: eventMethodName, - args: {competencyid: competencyId, userid: userId, planid: planId}, - fail: notification.exception - }]); - }); + args: {competencyid: competencyId, userid: userId, planid: planId} + }])[0]; + }).catch(notification.exception); }; /** diff --git a/admin/tool/lp/amd/src/user_competency_workflow.js b/admin/tool/lp/amd/src/user_competency_workflow.js index f61c0f9d67d..d6d6b71c45a 100644 --- a/admin/tool/lp/amd/src/user_competency_workflow.js +++ b/admin/tool/lp/amd/src/user_competency_workflow.js @@ -61,7 +61,7 @@ define(['jquery', Ajax.call([call])[0].then(function() { this._trigger('review-request-cancelled', data); this._trigger('status-changed', data); - }.bind(this), function() { + }.bind(this)).catch(function() { this._trigger('error-occured', data); }.bind(this)); }; @@ -106,7 +106,7 @@ define(['jquery', Ajax.call([call])[0].then(function() { this._trigger('review-requested', data); this._trigger('status-changed', data); - }.bind(this), function() { + }.bind(this)).catch(function() { this._trigger('error-occured', data); }.bind(this)); }; @@ -147,11 +147,10 @@ define(['jquery', competencyid: data.competencyid } }; - Ajax.call([call])[0].then(function() { this._trigger('review-started', data); this._trigger('status-changed', data); - }.bind(this), function() { + }.bind(this)).catch(function() { this._trigger('error-occured', data); }.bind(this)); }; @@ -196,7 +195,7 @@ define(['jquery', Ajax.call([call])[0].then(function() { this._trigger('review-stopped', data); this._trigger('status-changed', data); - }.bind(this), function() { + }.bind(this)).catch(function() { this._trigger('error-occured', data); }.bind(this)); }; diff --git a/admin/tool/lp/amd/src/user_evidence_actions.js b/admin/tool/lp/amd/src/user_evidence_actions.js index b9ef6863a8c..1c37728af10 100644 --- a/admin/tool/lp/amd/src/user_evidence_actions.js +++ b/admin/tool/lp/amd/src/user_evidence_actions.js @@ -98,14 +98,15 @@ define(['jquery', * Callback to render the region template. * * @param {Object} context The context for the template. + * @return {Promise} */ UserEvidenceActions.prototype._renderView = function(context) { var self = this; - templates.render(self._template, context) - .done(function(newhtml, newjs) { + return templates.render(self._template, context) + .then(function(newhtml, newjs) { templates.replaceNode($(self._region), newhtml, newjs); - }) - .fail(notification.exception); + return; + }); }; /** @@ -117,7 +118,6 @@ define(['jquery', */ UserEvidenceActions.prototype._callAndRefresh = function(calls, evidenceData) { var self = this; - calls.push({ methodname: self._contextMethod, args: self._getContextArgs(evidenceData) @@ -126,7 +126,7 @@ define(['jquery', // Apply all the promises, and refresh when the last one is resolved. return $.when.apply($.when, ajax.call(calls)) .then(function() { - self._renderView(arguments[arguments.length - 1]); + return self._renderView(arguments[arguments.length - 1]); }) .fail(notification.exception); }; diff --git a/report/competency/amd/src/grading_popup.js b/report/competency/amd/src/grading_popup.js index 13ce49c5cd0..20d21605a03 100644 --- a/report/competency/amd/src/grading_popup.js +++ b/report/competency/amd/src/grading_popup.js @@ -54,18 +54,15 @@ define(['jquery', 'core/notification', 'core/str', 'core/ajax', 'core/log', 'cor var requests = ajax.call([{ methodname: 'tool_lp_data_for_user_competency_summary_in_course', args: {userid: userId, competencyid: competencyId, courseid: courseId}, - done: this._contextLoaded.bind(this), - fail: notification.exception + }, { + methodname: 'core_competency_user_competency_viewed_in_course', + args: {userid: userId, competencyid: competencyId, courseid: courseId}, }]); - // Log the user competency viewed in course event. - requests[0].then(function() { - ajax.call([{ - methodname: 'core_competency_user_competency_viewed_in_course', - args: {userid: userId, competencyid: competencyId, courseid: courseId}, - fail: notification.exception - }]); - }); + $.when.apply($, requests).then(function() { + this._contextLoaded.bind(this); + return; + }).catch(notification.exception); }; /** From 72ed079f600078e69af9c3938bedfc17b12e6cbc Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Thu, 1 Jun 2017 12:37:15 +0100 Subject: [PATCH 08/13] MDL-57139 myoverview: Use promise best practices Simplified promise * Always return * Make use of promise chaining features to simplfy flow --- blocks/myoverview/amd/src/event_list.js | 53 +++++++++++++------------ 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/blocks/myoverview/amd/src/event_list.js b/blocks/myoverview/amd/src/event_list.js index 17e888f0040..f1d273ee24b 100644 --- a/blocks/myoverview/amd/src/event_list.js +++ b/blocks/myoverview/amd/src/event_list.js @@ -350,34 +350,37 @@ define(['jquery', 'core/notification', 'core/templates', // Request data from the server. return promise.then(function(result) { - return result.events; - }).then(function(calendarEvents) { - if (!calendarEvents.length || (calendarEvents.length < limit)) { - // We have no more events so mark the list as done. + if (!result.events.length) { + // No events, nothing to do. + setLoadedAll(root); + return 0; + } + + var calendarEvents = result.events; + + // Remember the last id we've seen. + root.attr('data-last-id', calendarEvents[calendarEvents.length - 1].id); + + if (calendarEvents.length <= limit) { + // No more events to load, disable loading button. setLoadedAll(root); } - if (calendarEvents.length) { - // Remember the last id we've seen. - root.attr('data-last-id', calendarEvents[calendarEvents.length - 1].id); - - // Render the events. - return render(root, calendarEvents).then(function(renderCount) { - updateContentVisibility(root, calendarEvents.length); - - if (renderCount < calendarEvents.length) { - // if the number of events that was rendered is less than - // the number we sent for rendering we can assume that there - // are no groups to add them in. Since the ordering of the - // events is guaranteed it means that any future requests will - // also yield events that can't be rendered, so let's not bother - // sending any more requests. - setLoadedAll(root); - } - }); - } else { - updateContentVisibility(root, calendarEvents.length); - } + // Render the events. + return render(root, calendarEvents).then(function(renderCount) { + if (renderCount < calendarEvents.length) { + // if the number of events that was rendered is less than + // the number we sent for rendering we can assume that there + // are no groups to add them in. Since the ordering of the + // events is guaranteed it means that any future requests will + // also yield events that can't be rendered, so let's not bother + // sending any more requests. + setLoadedAll(root); + } + return calendarEvents.length; + }); + }).then(function(eventCount) { + return updateContentVisibility(root, eventCount); }).fail( Notification.exception ).always(function() { From a1ce3266693e74abce0e1721f7671283cccc202e Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Thu, 1 Jun 2017 14:18:49 +0100 Subject: [PATCH 09/13] MDL-57139 course: update menu action promises to best practices --- course/amd/src/actions.js | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/course/amd/src/actions.js b/course/amd/src/actions.js index a804b45cf17..d7e7b8456f0 100644 --- a/course/amd/src/actions.js +++ b/course/amd/src/actions.js @@ -354,27 +354,32 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/str' * @param {String} titlestr string for "title" attribute (if different from stringname) * @param {String} titlecomponent * @param {String} newaction new value for data-action attribute of the link + * @return {Promise} promise which is resolved when the replacement has completed */ var replaceActionItem = function(actionitem, image, stringname, stringcomponent, titlestr, titlecomponent, newaction) { - str.get_string(stringname, stringcomponent).done(function(newstring) { - actionitem.find('span.menu-action-text').html(newstring); - actionitem.attr('title', newstring); - }); + + var stringRequests = [{key: stringname, component: stringcomponent}]; if (titlestr) { - str.get_string(titlestr, titlecomponent).then(function(newtitle) { - templates.renderPix(image, 'core', newtitle).then(function(html) { - actionitem.find('.icon').replaceWith(html); - }); - actionitem.attr('title', newtitle); - }); - } else { - templates.renderPix(image, 'core', '').then(function(html) { - actionitem.find('.icon').replaceWith(html); - }); + stringRequests.push({key: titlestr, component: titlecomponent}); } - actionitem.attr('data-action', newaction); + + return str.get_strings(stringRequests).then(function(strings) { + actionitem.find('span.menu-action-text').html(strings[0]); + actionitem.attr('title', strings[0]); + + var title = ''; + if (titlestr) { + title = strings[1]; + actionitem.attr('title', title); + } + return templates.renderPix(image, 'core', title); + }).then(function(pixhtml) { + actionitem.find('.icon').replaceWith(pixhtml); + actionitem.attr('data-action', newaction); + return; + }).catch(notification.exception); }; /** From f8587005cbebce5eb8f8f9fd2c68d9f5e1be1508 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Thu, 1 Jun 2017 14:22:35 +0100 Subject: [PATCH 10/13] MDL-57139 survey: fix promise return --- mod/survey/amd/src/validation.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mod/survey/amd/src/validation.js b/mod/survey/amd/src/validation.js index 75880c2dd1a..5439e684923 100644 --- a/mod/survey/amd/src/validation.js +++ b/mod/survey/amd/src/validation.js @@ -49,11 +49,10 @@ define(['jquery', 'core/str', 'core/modal_factory', 'core/notification'], functi if (form.find('input:radio[data-survey-default="true"]:checked').length !== 0) { e.preventDefault(); // Display the modal error. - modalPromise.then(function(modal) { + return modalPromise.then(function(modal) { modal.show(); - return; + return false; }); - return false; } return true; From 4276f9c717316ce510a8294145830b57b90f2beb Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Thu, 1 Jun 2017 14:43:00 +0100 Subject: [PATCH 11/13] MDL-57139 amd/user_date: always return --- lib/amd/src/user_date.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/amd/src/user_date.js b/lib/amd/src/user_date.js index d739f540c39..826ce41628c 100644 --- a/lib/amd/src/user_date.js +++ b/lib/amd/src/user_date.js @@ -127,8 +127,9 @@ define(['jquery', 'core/ajax', 'core/sessionstorage', 'core/config'], addToLocalStorage(key, value); date.deferred.resolve(value); }); + return; }) - .fail(function(ex) { + .catch(function(ex) { // If we failed to retrieve the dates then reject the date's // deferred objects to make sure they don't hang. dates.forEach(function(date) { From 751ec02540b633a6adf6dc783fc42829003b6e51 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Thu, 1 Jun 2017 14:43:23 +0100 Subject: [PATCH 12/13] MDL-57139 amd/templates: catch unhandled promise failure --- lib/amd/src/templates.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/amd/src/templates.js b/lib/amd/src/templates.js index e2c2f053518..8dae59674c2 100644 --- a/lib/amd/src/templates.js +++ b/lib/amd/src/templates.js @@ -170,7 +170,7 @@ define(['core/mustache', ready.reject('Invalid icon system specified' + config.iconsystemmodule); } else { iconSystem = system; - system.init().then(ready.resolve); + system.init().then(ready.resolve).catch(notification.exception); } }); @@ -698,7 +698,7 @@ define(['core/mustache', ready.reject('Invalid icon system specified' + config.iconsystem); } else { iconSystem = system; - system.init().then(ready.resolve); + system.init().then(ready.resolve).catch(notification.exception); } }); From 50c277a5d8f54f9ca2d560810db3c60221661296 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Sun, 15 Jan 2017 17:46:25 +0000 Subject: [PATCH 13/13] MDL-57139 js: built --- admin/tool/lp/amd/build/competencies.min.js | 2 +- admin/tool/lp/amd/build/competencyactions.min.js | 2 +- admin/tool/lp/amd/build/competencypicker.min.js | 2 +- admin/tool/lp/amd/build/competencypicker_user_plans.min.js | 2 +- admin/tool/lp/amd/build/competencyruleconfig.min.js | 2 +- admin/tool/lp/amd/build/form-cohort-selector.min.js | 2 +- admin/tool/lp/amd/build/form-user-selector.min.js | 2 +- admin/tool/lp/amd/build/frameworks_datasource.min.js | 2 +- admin/tool/lp/amd/build/planactions.min.js | 2 +- admin/tool/lp/amd/build/user_competency_plan_popup.min.js | 2 +- admin/tool/lp/amd/build/user_competency_workflow.min.js | 2 +- admin/tool/lp/amd/build/user_evidence_actions.min.js | 2 +- blocks/myoverview/amd/build/event_list.min.js | 2 +- course/amd/build/actions.min.js | 2 +- lib/amd/build/fragment.min.js | 2 +- lib/amd/build/templates.min.js | 2 +- lib/amd/build/user_date.min.js | 2 +- message/amd/build/message_area_messages.min.js | 2 +- message/amd/build/message_area_search.min.js | 2 +- .../output/popup/amd/build/message_popover_controller.min.js | 2 +- .../popup/amd/build/notification_area_control_area.min.js | 2 +- .../popup/amd/build/notification_popover_controller.min.js | 2 +- mod/lti/amd/build/contentitem.min.js | 2 +- mod/lti/amd/build/tool_card_controller.min.js | 2 +- mod/survey/amd/build/validation.min.js | 2 +- report/competency/amd/build/grading_popup.min.js | 2 +- 26 files changed, 26 insertions(+), 26 deletions(-) diff --git a/admin/tool/lp/amd/build/competencies.min.js b/admin/tool/lp/amd/build/competencies.min.js index 6177d34c14a..1f5ddbe40eb 100644 --- a/admin/tool/lp/amd/build/competencies.min.js +++ b/admin/tool/lp/amd/build/competencies.min.js @@ -1 +1 @@ -define(["jquery","core/notification","core/ajax","core/templates","core/str","tool_lp/competencypicker","tool_lp/dragdrop-reorder"],function(a,b,c,d,e,f,g){var h=function(b,c,d){this.itemid=b,this.itemtype=c,this.pageContextId=d,this.pickerInstance=null,a('[data-region="actions"] button').prop("disabled",!1),this.registerEvents(),this.registerDragDrop()};return h.prototype.registerDragDrop=function(){var a=this;e.get_string("movecompetency","tool_lp").done(function(b){g.dragdrop("movecompetency",b,{identifier:"movecompetency",component:"tool_lp"},{identifier:"movecompetencyafter",component:"tool_lp"},"drag-samenode","drag-parentnode","drag-handlecontainer",function(b,c){a.handleDrop(b,c)})}).fail(b.exception)},h.prototype.handleDrop=function(d,e){var f=a(d).data("id"),g=a(e).data("id"),h=this,i=[];if("course"==h.itemtype)i=c.call([{methodname:"core_competency_reorder_course_competency",args:{courseid:h.itemid,competencyidfrom:f,competencyidto:g}}]);else if("template"==h.itemtype)i=c.call([{methodname:"core_competency_reorder_template_competency",args:{templateid:h.itemid,competencyidfrom:f,competencyidto:g}}]);else{if("plan"!=h.itemtype)return;i=c.call([{methodname:"core_competency_reorder_plan_competency",args:{planid:h.itemid,competencyidfrom:f,competencyidto:g}}])}i[0].fail(b.exception)},h.prototype.pickCompetency=function(){var e,g,h,i,j=this;j.pickerInstance||("template"!==j.itemtype&&"course"!==j.itemtype||(i="parents"),j.pickerInstance=new f(j.pageContextId,(!1),i),j.pickerInstance.on("save",function(f,i){var k=i.competencyIds;"course"===j.itemtype?(e=[],a.each(k,function(a,b){e.push({methodname:"core_competency_add_competency_to_course",args:{courseid:j.itemid,competencyid:b}})}),e.push({methodname:"tool_lp_data_for_course_competencies_page",args:{courseid:j.itemid}}),g="tool_lp/course_competencies_page",h="coursecompetenciespage"):"template"===j.itemtype?(e=[],a.each(k,function(a,b){e.push({methodname:"core_competency_add_competency_to_template",args:{templateid:j.itemid,competencyid:b}})}),e.push({methodname:"tool_lp_data_for_template_competencies_page",args:{templateid:j.itemid,pagecontext:{contextid:j.pageContextId}}}),g="tool_lp/template_competencies_page",h="templatecompetenciespage"):"plan"===j.itemtype&&(e=[],a.each(k,function(a,b){e.push({methodname:"core_competency_add_competency_to_plan",args:{planid:j.itemid,competencyid:b}})}),e.push({methodname:"tool_lp_data_for_plan_page",args:{planid:j.itemid}}),g="tool_lp/plan_page",h="plan-page"),c.call(e)[e.length-1].then(function(b){return d.render(g,b).done(function(b,c){a('[data-region="'+h+'"]').replaceWith(b),d.runTemplateJS(c)})},b.exception)})),j.pickerInstance.display()},h.prototype.doDelete=function(e){var f=this,g=[],h="",i="";"course"==f.itemtype?(g=c.call([{methodname:"core_competency_remove_competency_from_course",args:{courseid:f.itemid,competencyid:e}},{methodname:"tool_lp_data_for_course_competencies_page",args:{courseid:f.itemid}}]),h="tool_lp/course_competencies_page",i="coursecompetenciespage"):"template"==f.itemtype?(g=c.call([{methodname:"core_competency_remove_competency_from_template",args:{templateid:f.itemid,competencyid:e}},{methodname:"tool_lp_data_for_template_competencies_page",args:{templateid:f.itemid,pagecontext:{contextid:f.pageContextId}}}]),h="tool_lp/template_competencies_page",i="templatecompetenciespage"):"plan"==f.itemtype&&(g=c.call([{methodname:"core_competency_remove_competency_from_plan",args:{planid:f.itemid,competencyid:e}},{methodname:"tool_lp_data_for_plan_page",args:{planid:f.itemid}}]),h="tool_lp/plan_page",i="plan-page"),g[1].done(function(c){d.render(h,c).done(function(b,c){a('[data-region="'+i+'"]').replaceWith(b),d.runTemplateJS(c)}).fail(b.exception)}).fail(b.exception)},h.prototype.deleteHandler=function(a){var d,f=this,g=[];if("course"==f.itemtype)d="unlinkcompetencycourse";else if("template"==f.itemtype)d="unlinkcompetencytemplate";else{if("plan"!=f.itemtype)return;d="unlinkcompetencyplan"}g=c.call([{methodname:"core_competency_read_competency",args:{id:a}}]),g[0].done(function(c){e.get_strings([{key:"confirm",component:"moodle"},{key:d,component:"tool_lp",param:c.shortname},{key:"confirm",component:"moodle"},{key:"cancel",component:"moodle"}]).done(function(c){b.confirm(c[0],c[1],c[2],c[3],function(){f.doDelete(a)})}).fail(b.exception)}).fail(b.exception)},h.prototype.registerEvents=function(){var e=this;"course"==e.itemtype&&a('[data-region="coursecompetenciespage"]').on("change",'select[data-field="ruleoutcome"]',function(f){var g=[],h="tool_lp/course_competencies_page",i="coursecompetenciespage",j=a(f.target).data("id"),k=a(f.target).val();g=c.call([{methodname:"core_competency_set_course_competency_ruleoutcome",args:{coursecompetencyid:j,ruleoutcome:k}},{methodname:"tool_lp_data_for_course_competencies_page",args:{courseid:e.itemid}}]),g[1].done(function(c){d.render(h,c).done(function(b,c){a('[data-region="'+i+'"]').replaceWith(b),d.runTemplateJS(c)}).fail(b.exception)}).fail(b.exception)}),a('[data-region="actions"] button').click(function(a){a.preventDefault(),e.pickCompetency()}),a('[data-action="delete-competency-link"]').click(function(b){b.preventDefault();var c=a(b.target).closest("[data-id]").data("id");e.deleteHandler(c)})},h}); \ No newline at end of file +define(["jquery","core/notification","core/ajax","core/templates","core/str","tool_lp/competencypicker","tool_lp/dragdrop-reorder"],function(a,b,c,d,e,f,g){var h=function(b,c,d){this.itemid=b,this.itemtype=c,this.pageContextId=d,this.pickerInstance=null,a('[data-region="actions"] button').prop("disabled",!1),this.registerEvents(),this.registerDragDrop()};return h.prototype.registerDragDrop=function(){var a=this;e.get_string("movecompetency","tool_lp").done(function(b){g.dragdrop("movecompetency",b,{identifier:"movecompetency",component:"tool_lp"},{identifier:"movecompetencyafter",component:"tool_lp"},"drag-samenode","drag-parentnode","drag-handlecontainer",function(b,c){a.handleDrop(b,c)})}).fail(b.exception)},h.prototype.handleDrop=function(d,e){var f=a(d).data("id"),g=a(e).data("id"),h=this,i=[];if("course"==h.itemtype)i=c.call([{methodname:"core_competency_reorder_course_competency",args:{courseid:h.itemid,competencyidfrom:f,competencyidto:g}}]);else if("template"==h.itemtype)i=c.call([{methodname:"core_competency_reorder_template_competency",args:{templateid:h.itemid,competencyidfrom:f,competencyidto:g}}]);else{if("plan"!=h.itemtype)return;i=c.call([{methodname:"core_competency_reorder_plan_competency",args:{planid:h.itemid,competencyidfrom:f,competencyidto:g}}])}i[0].fail(b.exception)},h.prototype.pickCompetency=function(){var e,g,h,i,j=this;j.pickerInstance||("template"!==j.itemtype&&"course"!==j.itemtype||(i="parents"),j.pickerInstance=new f(j.pageContextId,(!1),i),j.pickerInstance.on("save",function(f,i){var k=i.competencyIds;"course"===j.itemtype?(e=[],a.each(k,function(a,b){e.push({methodname:"core_competency_add_competency_to_course",args:{courseid:j.itemid,competencyid:b}})}),e.push({methodname:"tool_lp_data_for_course_competencies_page",args:{courseid:j.itemid}}),g="tool_lp/course_competencies_page",h="coursecompetenciespage"):"template"===j.itemtype?(e=[],a.each(k,function(a,b){e.push({methodname:"core_competency_add_competency_to_template",args:{templateid:j.itemid,competencyid:b}})}),e.push({methodname:"tool_lp_data_for_template_competencies_page",args:{templateid:j.itemid,pagecontext:{contextid:j.pageContextId}}}),g="tool_lp/template_competencies_page",h="templatecompetenciespage"):"plan"===j.itemtype&&(e=[],a.each(k,function(a,b){e.push({methodname:"core_competency_add_competency_to_plan",args:{planid:j.itemid,competencyid:b}})}),e.push({methodname:"tool_lp_data_for_plan_page",args:{planid:j.itemid}}),g="tool_lp/plan_page",h="plan-page"),c.call(e)[e.length-1].then(function(a){return d.render(g,a)}).then(function(b,c){a('[data-region="'+h+'"]').replaceWith(b),d.runTemplateJS(c)})["catch"](b.exception)})),j.pickerInstance.display()},h.prototype.doDelete=function(e){var f=this,g=[],h="",i="";"course"==f.itemtype?(g=c.call([{methodname:"core_competency_remove_competency_from_course",args:{courseid:f.itemid,competencyid:e}},{methodname:"tool_lp_data_for_course_competencies_page",args:{courseid:f.itemid}}]),h="tool_lp/course_competencies_page",i="coursecompetenciespage"):"template"==f.itemtype?(g=c.call([{methodname:"core_competency_remove_competency_from_template",args:{templateid:f.itemid,competencyid:e}},{methodname:"tool_lp_data_for_template_competencies_page",args:{templateid:f.itemid,pagecontext:{contextid:f.pageContextId}}}]),h="tool_lp/template_competencies_page",i="templatecompetenciespage"):"plan"==f.itemtype&&(g=c.call([{methodname:"core_competency_remove_competency_from_plan",args:{planid:f.itemid,competencyid:e}},{methodname:"tool_lp_data_for_plan_page",args:{planid:f.itemid}}]),h="tool_lp/plan_page",i="plan-page"),g[1].done(function(c){d.render(h,c).done(function(b,c){a('[data-region="'+i+'"]').replaceWith(b),d.runTemplateJS(c)}).fail(b.exception)}).fail(b.exception)},h.prototype.deleteHandler=function(a){var d,f=this,g=[];if("course"==f.itemtype)d="unlinkcompetencycourse";else if("template"==f.itemtype)d="unlinkcompetencytemplate";else{if("plan"!=f.itemtype)return;d="unlinkcompetencyplan"}g=c.call([{methodname:"core_competency_read_competency",args:{id:a}}]),g[0].done(function(c){e.get_strings([{key:"confirm",component:"moodle"},{key:d,component:"tool_lp",param:c.shortname},{key:"confirm",component:"moodle"},{key:"cancel",component:"moodle"}]).done(function(c){b.confirm(c[0],c[1],c[2],c[3],function(){f.doDelete(a)})}).fail(b.exception)}).fail(b.exception)},h.prototype.registerEvents=function(){var e=this;"course"==e.itemtype&&a('[data-region="coursecompetenciespage"]').on("change",'select[data-field="ruleoutcome"]',function(f){var g=[],h="tool_lp/course_competencies_page",i="coursecompetenciespage",j=a(f.target).data("id"),k=a(f.target).val();g=c.call([{methodname:"core_competency_set_course_competency_ruleoutcome",args:{coursecompetencyid:j,ruleoutcome:k}},{methodname:"tool_lp_data_for_course_competencies_page",args:{courseid:e.itemid}}]),g[1].done(function(c){d.render(h,c).done(function(b,c){a('[data-region="'+i+'"]').replaceWith(b),d.runTemplateJS(c)}).fail(b.exception)}).fail(b.exception)}),a('[data-region="actions"] button').click(function(a){a.preventDefault(),e.pickCompetency()}),a('[data-action="delete-competency-link"]').click(function(b){b.preventDefault();var c=a(b.target).closest("[data-id]").data("id");e.deleteHandler(c)})},h}); \ No newline at end of file diff --git a/admin/tool/lp/amd/build/competencyactions.min.js b/admin/tool/lp/amd/build/competencyactions.min.js index 594bc756b85..143c935e794 100644 --- a/admin/tool/lp/amd/build/competencyactions.min.js +++ b/admin/tool/lp/amd/build/competencyactions.min.js @@ -1 +1 @@ -define(["jquery","core/url","core/templates","core/notification","core/str","core/ajax","tool_lp/dragdrop-reorder","tool_lp/tree","tool_lp/dialogue","tool_lp/menubar","tool_lp/competencypicker","tool_lp/competency_outcomes","tool_lp/competencyruleconfig"],function(a,b,c,d,e,f,g,h,i,j,k,l,m){var n,o,p,q,r,s,t=null,u=null,v=null,w=null,x=function(){var c=a('[data-region="competencyactions"]').data("competency"),f={competencyframeworkid:t.getCompetencyFrameworkId(),pagecontextid:n};null!==c&&(f.parentid=c.id);var g=function(){var c=a.param(f);window.location=b.relativeUrl("/admin/tool/lp/editcompetency.php?"+c)};null!==c&&t.hasRule(c.id)?e.get_strings([{key:"confirm",component:"moodle"},{key:"addingcompetencywillresetparentrule",component:"tool_lp",param:c.shortname},{key:"yes",component:"core"},{key:"no",component:"core"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],g)}).fail(d.exception):g()},y=function(){var b=a('[data-region="filtercompetencies"]').data("frameworkid"),c=f.call([{methodname:"core_competency_set_parent_competency",args:{competencyid:u,parentid:v}},{methodname:"tool_lp_data_for_competencies_manage_page",args:{competencyframeworkid:b,search:a('[data-region="filtercompetencies"] input').val()}}]);c[1].done(E).fail(d.exception)},z=function(){if(v="undefined"==typeof v?0:v,v!=u){var a=t.getCompetency(v)||{},b=t.getCompetency(u)||{},c="movecompetencywillresetrules",f=!1;b.parentid!=v&&(a.path&&a.path.indexOf("/"+b.id+"/")>=0&&(c="movecompetencytochildofselfwillresetrules",f=f||t.hasRule(b.id)),f=f||t.hasRule(a.id)||t.hasRule(b.parentid),f?e.get_strings([{key:"confirm",component:"moodle"},{key:c,component:"tool_lp"},{key:"yes",component:"moodle"},{key:"no",component:"moodle"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],y)}).fail(d.exception):y())}},A=function(b){var c=a(b.getContent()),d=c.find("[data-enhance=movetree]"),e=new h(d,(!1));e.on("selectionchanged",function(b,c){var d=c.selected;v=a(d).data("id")}),d.show(),c.on("click",'[data-action="move"]',function(){b.close(),z()}),c.on("click",'[data-action="cancel"]',function(){b.close()})},B=function(a,b){var c;for(c=0;cspan",O).on("dragover","li>span",P).on("dragenter","li>span",Q).on("dragleave","li>span",R).on("drop","li>span",S),b.on("selectionchanged",$),p=new m(t,s),p.on("save",L.bind(this))}}}); \ No newline at end of file +define(["jquery","core/url","core/templates","core/notification","core/str","core/ajax","tool_lp/dragdrop-reorder","tool_lp/tree","tool_lp/dialogue","tool_lp/menubar","tool_lp/competencypicker","tool_lp/competency_outcomes","tool_lp/competencyruleconfig"],function(a,b,c,d,e,f,g,h,i,j,k,l,m){var n,o,p,q,r,s,t=null,u=null,v=null,w=null,x=function(){var c=a('[data-region="competencyactions"]').data("competency"),f={competencyframeworkid:t.getCompetencyFrameworkId(),pagecontextid:n};null!==c&&(f.parentid=c.id);var g=function(){var c=a.param(f);window.location=b.relativeUrl("/admin/tool/lp/editcompetency.php?"+c)};null!==c&&t.hasRule(c.id)?e.get_strings([{key:"confirm",component:"moodle"},{key:"addingcompetencywillresetparentrule",component:"tool_lp",param:c.shortname},{key:"yes",component:"core"},{key:"no",component:"core"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],g)}).fail(d.exception):g()},y=function(){var b=a('[data-region="filtercompetencies"]').data("frameworkid"),c=f.call([{methodname:"core_competency_set_parent_competency",args:{competencyid:u,parentid:v}},{methodname:"tool_lp_data_for_competencies_manage_page",args:{competencyframeworkid:b,search:a('[data-region="filtercompetencies"] input').val()}}]);c[1].done(E).fail(d.exception)},z=function(){if(v="undefined"==typeof v?0:v,v!=u){var a=t.getCompetency(v)||{},b=t.getCompetency(u)||{},c="movecompetencywillresetrules",f=!1;b.parentid!=v&&(a.path&&a.path.indexOf("/"+b.id+"/")>=0&&(c="movecompetencytochildofselfwillresetrules",f=f||t.hasRule(b.id)),f=f||t.hasRule(a.id)||t.hasRule(b.parentid),f?e.get_strings([{key:"confirm",component:"moodle"},{key:c,component:"tool_lp"},{key:"yes",component:"moodle"},{key:"no",component:"moodle"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],y)}).fail(d.exception):y())}},A=function(b){var c=a(b.getContent()),d=c.find("[data-enhance=movetree]"),e=new h(d,(!1));e.on("selectionchanged",function(b,c){var d=c.selected;v=a(d).data("id")}),d.show(),c.on("click",'[data-action="move"]',function(){b.close(),z()}),c.on("click",'[data-action="cancel"]',function(){b.close()})},B=function(a,b){var c;for(c=0;cspan",O).on("dragover","li>span",P).on("dragenter","li>span",Q).on("dragleave","li>span",R).on("drop","li>span",S),b.on("selectionchanged",$),p=new m(t,s),p.on("save",L.bind(this))}}}); \ No newline at end of file diff --git a/admin/tool/lp/amd/build/competencypicker.min.js b/admin/tool/lp/amd/build/competencypicker.min.js index e4312d2a55f..e32b0808ae2 100644 --- a/admin/tool/lp/amd/build/competencypicker.min.js +++ b/admin/tool/lp/amd/build/competencypicker.min.js @@ -1 +1 @@ -define(["jquery","core/notification","core/ajax","core/templates","tool_lp/dialogue","core/str","tool_lp/tree"],function(a,b,c,d,e,f,g){var h=function(b,c,d,e){var f=this;f._eventNode=a("
"),f._frameworks=[],f._reset(),f._pageContextId=b,f._pageContextIncludes=d||"children",f._multiSelect="undefined"==typeof e||e===!0,c&&(f._frameworkId=c,f._singleFramework=!0)};return h.prototype._competencies=null,h.prototype._disallowedCompetencyIDs=null,h.prototype._eventNode=null,h.prototype._frameworks=null,h.prototype._frameworkId=null,h.prototype._pageContextId=null,h.prototype._pageContextIncludes=null,h.prototype._popup=null,h.prototype._searchText="",h.prototype._selectedCompetencies=null,h.prototype._singleFramework=!1,h.prototype._multiSelect=!0,h.prototype._onlyVisible=!0,h.prototype._afterRender=function(){var b=this,c=new g(b._find("[data-enhance=linktree]"),b._multiSelect);b._find("[data-enhance=linktree]").show(),c.on("selectionchanged",function(c,d){var e=d.selected;c.preventDefault();var f=[];a.each(e,function(c,d){var e=a(d).data("id"),g=!0;"undefined"==typeof e?g=!1:a.each(b._disallowedCompetencyIDs,function(a,b){b==e&&(g=!1)}),g&&f.push(e)}),b._selectedCompetencies=f,b._selectedCompetencies.length?b._find('[data-region="competencylinktree"] [data-action="add"]').removeAttr("disabled"):b._find('[data-region="competencylinktree"] [data-action="add"]').attr("disabled","disabled")}),b._singleFramework||b._find('[data-action="chooseframework"]').change(function(c){b._frameworkId=a(c.target).val(),b._loadCompetencies().then(b._refresh.bind(b))}),b._find('[data-region="filtercompetencies"] button').click(function(c){return c.preventDefault(),a(c.target).attr("disabled","disabled"),b._searchText=b._find('[data-region="filtercompetencies"] input').val()||"",b._refresh().always(function(){a(c.target).removeAttr("disabled")})}),b._find('[data-region="competencylinktree"] [data-action="cancel"]').click(function(a){a.preventDefault(),b.close()}),b._find('[data-region="competencylinktree"] [data-action="add"]').click(function(a){a.preventDefault(),b._selectedCompetencies.length&&(b._multiSelect?b._trigger("save",{competencyIds:b._selectedCompetencies}):b._trigger("save",{competencyId:b._selectedCompetencies[0]}),b.close())});var d=b._selectedCompetencies.slice(0);a.each(d,function(a,d){var e=b._find("[data-id="+d+"]");e.length&&(c.toggleItem(e),c.updateFocus(e))})},h.prototype.close=function(){var a=this;a._popup.close(),a._reset()},h.prototype.display=function(){var a=this;return a._render().then(function(b){return f.get_string("competencypicker","tool_lp").then(function(c){a._popup=new e(c,b,a._afterRender.bind(a))})}).fail(b.exception)},h.prototype._fetchCompetencies=function(a,d){var e=this;return c.call([{methodname:"core_competency_search_competencies",args:{searchtext:d,competencyframeworkid:a}}])[0].done(function(a){function b(a,c){for(var d=0;d0?a.when():(d=e._singleFramework?c.call([{methodname:"core_competency_read_competency_framework",args:{id:this._frameworkId}}])[0].then(function(a){return[a]}):c.call([{methodname:"core_competency_list_competency_frameworks",args:{sort:"shortname",context:{contextid:e._pageContextId},includes:e._pageContextIncludes,onlyvisible:e._onlyVisible}}])[0],d.done(function(a){e._frameworks=a}).fail(b.exception))},h.prototype.on=function(a,b){this._eventNode.on(a,b)},h.prototype._preRender=function(){var b=this;return b._loadFrameworks().then(function(){return!b._frameworkId&&b._frameworks.length>0&&(b._frameworkId=b._frameworks[0].id),b._frameworkId?b._loadCompetencies():(b._frameworks=[],a.when())})},h.prototype._refresh=function(){var a=this;return a._render().then(function(b){a._find('[data-region="competencylinktree"]').replaceWith(b),a._afterRender()})},h.prototype._render=function(){var b=this;return b._preRender().then(function(){b._singleFramework||a.each(b._frameworks,function(a,c){c.id==b._frameworkId?c.selected=!0:c.selected=!1});var c={competencies:b._competencies,framework:b._getFramework(b._frameworkId),frameworks:b._frameworks,search:b._searchText,singleFramework:b._singleFramework};return d.render("tool_lp/competency_picker",c)})},h.prototype._reset=function(){this._competencies=[],this._disallowedCompetencyIDs=[],this._popup=null,this._searchText="",this._selectedCompetencies=[]},h.prototype.setDisallowedCompetencyIDs=function(a){this._disallowedCompetencyIDs=a},h.prototype._trigger=function(a,b){this._eventNode.trigger(a,[b])},h}); \ No newline at end of file +define(["jquery","core/notification","core/ajax","core/templates","tool_lp/dialogue","core/str","tool_lp/tree"],function(a,b,c,d,e,f,g){var h=function(b,c,d,e){var f=this;f._eventNode=a("
"),f._frameworks=[],f._reset(),f._pageContextId=b,f._pageContextIncludes=d||"children",f._multiSelect="undefined"==typeof e||e===!0,c&&(f._frameworkId=c,f._singleFramework=!0)};return h.prototype._competencies=null,h.prototype._disallowedCompetencyIDs=null,h.prototype._eventNode=null,h.prototype._frameworks=null,h.prototype._frameworkId=null,h.prototype._pageContextId=null,h.prototype._pageContextIncludes=null,h.prototype._popup=null,h.prototype._searchText="",h.prototype._selectedCompetencies=null,h.prototype._singleFramework=!1,h.prototype._multiSelect=!0,h.prototype._onlyVisible=!0,h.prototype._afterRender=function(){var c=this,d=new g(c._find("[data-enhance=linktree]"),c._multiSelect);c._find("[data-enhance=linktree]").show(),d.on("selectionchanged",function(b,d){var e=d.selected;b.preventDefault();var f=[];a.each(e,function(b,d){var e=a(d).data("id"),g=!0;"undefined"==typeof e?g=!1:a.each(c._disallowedCompetencyIDs,function(a,b){b==e&&(g=!1)}),g&&f.push(e)}),c._selectedCompetencies=f,c._selectedCompetencies.length?c._find('[data-region="competencylinktree"] [data-action="add"]').removeAttr("disabled"):c._find('[data-region="competencylinktree"] [data-action="add"]').attr("disabled","disabled")}),c._singleFramework||c._find('[data-action="chooseframework"]').change(function(d){c._frameworkId=a(d.target).val(),c._loadCompetencies().then(c._refresh.bind(c))["catch"](b.exception)}),c._find('[data-region="filtercompetencies"] button').click(function(b){return b.preventDefault(),a(b.target).attr("disabled","disabled"),c._searchText=c._find('[data-region="filtercompetencies"] input').val()||"",c._refresh().always(function(){a(b.target).removeAttr("disabled")})}),c._find('[data-region="competencylinktree"] [data-action="cancel"]').click(function(a){a.preventDefault(),c.close()}),c._find('[data-region="competencylinktree"] [data-action="add"]').click(function(a){a.preventDefault(),c._selectedCompetencies.length&&(c._multiSelect?c._trigger("save",{competencyIds:c._selectedCompetencies}):c._trigger("save",{competencyId:c._selectedCompetencies[0]}),c.close())});var e=c._selectedCompetencies.slice(0);a.each(e,function(a,b){var e=c._find("[data-id="+b+"]");e.length&&(d.toggleItem(e),d.updateFocus(e))})},h.prototype.close=function(){var a=this;a._popup.close(),a._reset()},h.prototype.display=function(){var c=this;return a.when(f.get_string("competencypicker","tool_lp"),c._render()).then(function(a,b){c._popup=new e(a,b[0],c._afterRender.bind(c))})["catch"](b.exception)},h.prototype._fetchCompetencies=function(a,d){var e=this;return c.call([{methodname:"core_competency_search_competencies",args:{searchtext:d,competencyframeworkid:a}}])[0].done(function(a){function b(a,c){for(var d=0;d0?a.when():(d=e._singleFramework?c.call([{methodname:"core_competency_read_competency_framework",args:{id:this._frameworkId}}])[0].then(function(a){return[a]}):c.call([{methodname:"core_competency_list_competency_frameworks",args:{sort:"shortname",context:{contextid:e._pageContextId},includes:e._pageContextIncludes,onlyvisible:e._onlyVisible}}])[0],d.done(function(a){e._frameworks=a}).fail(b.exception))},h.prototype.on=function(a,b){this._eventNode.on(a,b)},h.prototype._preRender=function(){var b=this;return b._loadFrameworks().then(function(){return!b._frameworkId&&b._frameworks.length>0&&(b._frameworkId=b._frameworks[0].id),b._frameworkId?b._loadCompetencies():(b._frameworks=[],a.when())})},h.prototype._refresh=function(){var a=this;return a._render().then(function(b){a._find('[data-region="competencylinktree"]').replaceWith(b),a._afterRender()})},h.prototype._render=function(){var b=this;return b._preRender().then(function(){b._singleFramework||a.each(b._frameworks,function(a,c){c.id==b._frameworkId?c.selected=!0:c.selected=!1});var c={competencies:b._competencies,framework:b._getFramework(b._frameworkId),frameworks:b._frameworks,search:b._searchText,singleFramework:b._singleFramework};return d.render("tool_lp/competency_picker",c)})},h.prototype._reset=function(){this._competencies=[],this._disallowedCompetencyIDs=[],this._popup=null,this._searchText="",this._selectedCompetencies=[]},h.prototype.setDisallowedCompetencyIDs=function(a){this._disallowedCompetencyIDs=a},h.prototype._trigger=function(a,b){this._eventNode.trigger(a,[b])},h}); \ No newline at end of file diff --git a/admin/tool/lp/amd/build/competencypicker_user_plans.min.js b/admin/tool/lp/amd/build/competencypicker_user_plans.min.js index bf54916e46d..fd3bf2d4760 100644 --- a/admin/tool/lp/amd/build/competencypicker_user_plans.min.js +++ b/admin/tool/lp/amd/build/competencypicker_user_plans.min.js @@ -1 +1 @@ -define(["jquery","core/notification","core/ajax","core/templates","core/str","tool_lp/tree","tool_lp/competencypicker"],function(a,b,c,d,e,f,g){var h=function(a,b,c){g.prototype.constructor.apply(this,[1,!1,"self",c]),this._userId=a,this._plans=[],b&&(this._planId=b,this._singlePlan=!0)};return h.prototype=Object.create(g.prototype),h.prototype._plans=null,h.prototype._planId=null,h.prototype._singlePlan=!1,h.prototype._userId=null,h.prototype._afterRender=function(){var b=this;g.prototype._afterRender.apply(b,arguments),b._singlePlan||b._find('[data-action="chooseplan"]').change(function(c){b._planId=a(c.target).val(),b._loadCompetencies().then(b._refresh.bind(b))})},h.prototype._fetchCompetencies=function(a,d){var e=this;return c.call([{methodname:"core_competency_list_plan_competencies",args:{id:a}}])[0].done(function(a){var b,c,f=[];for(b=0;b0?a.when():(d=e._singlePlan?c.call([{methodname:"core_competency_read_plan",args:{id:this._planId}}])[0].then(function(a){return[a]}):c.call([{methodname:"core_competency_list_user_plans",args:{userid:e._userId}}])[0],d.done(function(a){e._plans=a}).fail(b.exception))},h.prototype._preRender=function(){var b=this;return b._loadPlans().then(function(){return!b._planId&&b._plans.length>0&&(b._planId=b._plans[0].id),b._planId?b._loadCompetencies():(b._plans=[],a.when())})},h.prototype._render=function(){var b=this;return b._preRender().then(function(){b._singlePlan||a.each(b._plans,function(a,c){c.id==b._planId?c.selected=!0:c.selected=!1});var c={competencies:b._competencies,plan:b._getPlan(b._planId),plans:b._plans,search:b._searchText,singlePlan:b._singlePlan};return d.render("tool_lp/competency_picker_user_plans",c)})},h}); \ No newline at end of file +define(["jquery","core/notification","core/ajax","core/templates","core/str","tool_lp/tree","tool_lp/competencypicker"],function(a,b,c,d,e,f,g){var h=function(a,b,c){g.prototype.constructor.apply(this,[1,!1,"self",c]),this._userId=a,this._plans=[],b&&(this._planId=b,this._singlePlan=!0)};return h.prototype=Object.create(g.prototype),h.prototype._plans=null,h.prototype._planId=null,h.prototype._singlePlan=!1,h.prototype._userId=null,h.prototype._afterRender=function(){var c=this;g.prototype._afterRender.apply(c,arguments),c._singlePlan||c._find('[data-action="chooseplan"]').change(function(d){c._planId=a(d.target).val(),c._loadCompetencies().then(c._refresh.bind(c))["catch"](b.exception)})},h.prototype._fetchCompetencies=function(a,d){var e=this;return c.call([{methodname:"core_competency_list_plan_competencies",args:{id:a}}])[0].done(function(a){var b,c,f=[];for(b=0;b0?a.when():(d=e._singlePlan?c.call([{methodname:"core_competency_read_plan",args:{id:this._planId}}])[0].then(function(a){return[a]}):c.call([{methodname:"core_competency_list_user_plans",args:{userid:e._userId}}])[0],d.done(function(a){e._plans=a}).fail(b.exception))},h.prototype._preRender=function(){var b=this;return b._loadPlans().then(function(){return!b._planId&&b._plans.length>0&&(b._planId=b._plans[0].id),b._planId?b._loadCompetencies():(b._plans=[],a.when())})},h.prototype._render=function(){var b=this;return b._preRender().then(function(){b._singlePlan||a.each(b._plans,function(a,c){c.id==b._planId?c.selected=!0:c.selected=!1});var c={competencies:b._competencies,plan:b._getPlan(b._planId),plans:b._plans,search:b._searchText,singlePlan:b._singlePlan};return d.render("tool_lp/competency_picker_user_plans",c)})},h}); \ No newline at end of file diff --git a/admin/tool/lp/amd/build/competencyruleconfig.min.js b/admin/tool/lp/amd/build/competencyruleconfig.min.js index f5f7f431102..db877a5e0c0 100644 --- a/admin/tool/lp/amd/build/competencyruleconfig.min.js +++ b/admin/tool/lp/amd/build/competencyruleconfig.min.js @@ -1 +1 @@ -define(["jquery","core/notification","core/templates","tool_lp/dialogue","tool_lp/competency_outcomes","core/str"],function(a,b,c,d,e,f){var g=function(b,c){this._eventNode=a("
"),this._tree=b,this._rulesModules=c,this._setUp()};return g.prototype._competency=null,g.prototype._eventNode=null,g.prototype._outcomesOption=null,g.prototype._popup=null,g.prototype._ready=null,g.prototype._rules=null,g.prototype._rulesModules=null,g.prototype._tree=null,g.prototype._afterChange=function(){this._isValid()?this._find('[data-action="save"]').prop("disabled",!1):this._find('[data-action="save"]').prop("disabled",!0)},g.prototype._afterRuleConfigChange=function(a,b){b==this._getRule()&&this._afterChange()},g.prototype._afterRender=function(){var a=this;a._find('[name="outcome"]').on("change",function(){a._switchedOutcome()}).trigger("change"),a._find('[name="rule"]').on("change",function(){a._switchedRule()}).trigger("change"),a._find('[data-action="save"]').on("click",function(){a._trigger("save",a._getConfig()),a.close()}),a._find('[data-action="cancel"]').on("click",function(){a.close()})},g.prototype.canBeConfigured=function(){var b=!1;return a.each(this._rules,function(a,c){if(c.canConfig())return void(b=!0)}),b},g.prototype.close=function(){this._popup.close(),this._popup=null},g.prototype.display=function(){var a=this;return!!a._competency&&a._render().then(function(b){return f.get_string("competencyrule","tool_lp").then(function(c){a._popup=new d(c,b,a._afterRender.bind(a))})}).fail(b.exception)},g.prototype._find=function(b){return a(this._popup.getContent()).find(b)},g.prototype._getApplicableOutcomesOptions=function(){var b=this,c=[];return a.each(b._outcomesOption,function(a,d){c.push({code:d.code,name:d.name,selected:d.code==b._competency.ruleoutcome})}),c},g.prototype._getApplicableRulesOptions=function(){var b=this,c=[];return a.each(b._rules,function(a,d){d.canConfig()&&c.push({name:b._getRuleName(d.getType()),type:d.getType(),selected:d.getType()==b._competency.ruletype})}),c},g.prototype._getConfig=function(){var a=this._getRule();return{ruletype:a?a.getType():null,ruleconfig:a?a.getConfig():null,ruleoutcome:this._getOutcome()}},g.prototype._getOutcome=function(){return this._find('[name="outcome"]').val()},g.prototype._getRule=function(){var b,c=this._find('[name="rule"]').val();return a.each(this._rules,function(a,d){if(d.getType()==c)return void(b=d)}),b},g.prototype._getRuleName=function(b){var c,d=this;return a.each(d._rulesModules,function(a,d){if(d.type==b)return void(c=d.name)}),c},g.prototype._initOutcomes=function(){var a=this;return e.getAll().then(function(b){a._outcomesOption=b})},g.prototype._initRules=function(){var b=this,c=[];return a.each(b._rules,function(d,e){var f=e.init().then(function(){e.setTargetCompetency(b._competency),e.on("change",b._afterRuleConfigChange.bind(b))},function(){return b._rules.splice(d,1),a.when()});c.push(f)}),a.when.apply(a.when,c)},g.prototype._isValid=function(){var a=this._getOutcome(),b=this._getRule();return a==e.NONE||!!b&&b.isValid()},g.prototype.on=function(a,b){this._eventNode.on(a,b)},g.prototype._preRender=function(){return this.ready()},g.prototype.ready=function(){return this._ready.promise()},g.prototype._render=function(){var a=this;return this._preRender().then(function(){var b;a.canBeConfigured()?(b={},b.outcomes=a._getApplicableOutcomesOptions(),b.rules=a._getApplicableRulesOptions()):b=!1;var d={competencyshortname:a._competency.shortname,config:b};return c.render("tool_lp/competency_rule_config",d)})},g.prototype.setTargetCompetencyId=function(b){var c=this;c._competency=c._tree.getCompetency(b),a.each(c._rules,function(a,b){b.setTargetCompetency(c._competency)})},g.prototype._setUp=function(){var b=this,c=[],d=[];b._ready=a.Deferred(),b._rules=[],a.each(b._rulesModules,function(a,b){d.push(b.amd)}),require(d,function(){a.each(arguments,function(a,c){var d=new c(b._tree);b._rules.push(d)}),c.push(b._initRules()),c.push(b._initOutcomes()),a.when.apply(a.when,c).always(function(){b._ready.resolve()})})},g.prototype._switchedOutcome=function(){var a=this,b=a._getOutcome();return b==e.NONE?(a._find('[data-region="rule-type"]').hide().find('[name="rule"]').val(-1),a._find('[data-region="rule-config"]').empty().hide(),void a._afterChange()):(a._find('[data-region="rule-type"]').show(),a._find('[data-region="rule-config"]').show(),void a._afterChange())},g.prototype._switchedRule=function(){var a=this,b=a._find('[data-region="rule-config"]'),c=a._getRule();return c?void c.injectTemplate(b).then(function(){b.show()},function(){b.empty().hide()}).always(function(){a._afterChange()}):(b.empty().hide(),void a._afterChange())},g.prototype._trigger=function(a,b){this._eventNode.trigger(a,[b])},g}); \ No newline at end of file +define(["jquery","core/notification","core/templates","tool_lp/dialogue","tool_lp/competency_outcomes","core/str"],function(a,b,c,d,e,f){var g=function(b,c){this._eventNode=a("
"),this._tree=b,this._rulesModules=c,this._setUp()};return g.prototype._competency=null,g.prototype._eventNode=null,g.prototype._outcomesOption=null,g.prototype._popup=null,g.prototype._ready=null,g.prototype._rules=null,g.prototype._rulesModules=null,g.prototype._tree=null,g.prototype._afterChange=function(){this._isValid()?this._find('[data-action="save"]').prop("disabled",!1):this._find('[data-action="save"]').prop("disabled",!0)},g.prototype._afterRuleConfigChange=function(a,b){b==this._getRule()&&this._afterChange()},g.prototype._afterRender=function(){var a=this;a._find('[name="outcome"]').on("change",function(){a._switchedOutcome()}).trigger("change"),a._find('[name="rule"]').on("change",function(){a._switchedRule()}).trigger("change"),a._find('[data-action="save"]').on("click",function(){a._trigger("save",a._getConfig()),a.close()}),a._find('[data-action="cancel"]').on("click",function(){a.close()})},g.prototype.canBeConfigured=function(){var b=!1;return a.each(this._rules,function(a,c){if(c.canConfig())return void(b=!0)}),b},g.prototype.close=function(){this._popup.close(),this._popup=null},g.prototype.display=function(){var c=this;return!!c._competency&&a.when(f.get_string("competencyrule","tool_lp"),c._render()).then(function(a,b){c._popup=new d(a,b[0],c._afterRender.bind(c))}).fail(b.exception)},g.prototype._find=function(b){return a(this._popup.getContent()).find(b)},g.prototype._getApplicableOutcomesOptions=function(){var b=this,c=[];return a.each(b._outcomesOption,function(a,d){c.push({code:d.code,name:d.name,selected:d.code==b._competency.ruleoutcome})}),c},g.prototype._getApplicableRulesOptions=function(){var b=this,c=[];return a.each(b._rules,function(a,d){d.canConfig()&&c.push({name:b._getRuleName(d.getType()),type:d.getType(),selected:d.getType()==b._competency.ruletype})}),c},g.prototype._getConfig=function(){var a=this._getRule();return{ruletype:a?a.getType():null,ruleconfig:a?a.getConfig():null,ruleoutcome:this._getOutcome()}},g.prototype._getOutcome=function(){return this._find('[name="outcome"]').val()},g.prototype._getRule=function(){var b,c=this._find('[name="rule"]').val();return a.each(this._rules,function(a,d){if(d.getType()==c)return void(b=d)}),b},g.prototype._getRuleName=function(b){var c,d=this;return a.each(d._rulesModules,function(a,d){if(d.type==b)return void(c=d.name)}),c},g.prototype._initOutcomes=function(){var a=this;return e.getAll().then(function(b){a._outcomesOption=b})},g.prototype._initRules=function(){var b=this,c=[];return a.each(b._rules,function(d,e){var f=e.init().then(function(){e.setTargetCompetency(b._competency),e.on("change",b._afterRuleConfigChange.bind(b))},function(){return b._rules.splice(d,1),a.when()});c.push(f)}),a.when.apply(a.when,c)},g.prototype._isValid=function(){var a=this._getOutcome(),b=this._getRule();return a==e.NONE||!!b&&b.isValid()},g.prototype.on=function(a,b){this._eventNode.on(a,b)},g.prototype._preRender=function(){return this.ready()},g.prototype.ready=function(){return this._ready.promise()},g.prototype._render=function(){var a=this;return this._preRender().then(function(){var b;a.canBeConfigured()?(b={},b.outcomes=a._getApplicableOutcomesOptions(),b.rules=a._getApplicableRulesOptions()):b=!1;var d={competencyshortname:a._competency.shortname,config:b};return c.render("tool_lp/competency_rule_config",d)})},g.prototype.setTargetCompetencyId=function(b){var c=this;c._competency=c._tree.getCompetency(b),a.each(c._rules,function(a,b){b.setTargetCompetency(c._competency)})},g.prototype._setUp=function(){var b=this,c=[],d=[];b._ready=a.Deferred(),b._rules=[],a.each(b._rulesModules,function(a,b){d.push(b.amd)}),require(d,function(){a.each(arguments,function(a,c){var d=new c(b._tree);b._rules.push(d)}),c.push(b._initRules()),c.push(b._initOutcomes()),a.when.apply(a.when,c).always(function(){b._ready.resolve()})})},g.prototype._switchedOutcome=function(){var a=this,b=a._getOutcome();return b==e.NONE?(a._find('[data-region="rule-type"]').hide().find('[name="rule"]').val(-1),a._find('[data-region="rule-config"]').empty().hide(),void a._afterChange()):(a._find('[data-region="rule-type"]').show(),a._find('[data-region="rule-config"]').show(),void a._afterChange())},g.prototype._switchedRule=function(){var a=this,b=a._find('[data-region="rule-config"]'),c=a._getRule();return c?void c.injectTemplate(b).then(function(){b.show()}).always(function(){a._afterChange()})["catch"](function(){b.empty().hide()}):(b.empty().hide(),void a._afterChange())},g.prototype._trigger=function(a,b){this._eventNode.trigger(a,[b])},g}); \ No newline at end of file diff --git a/admin/tool/lp/amd/build/form-cohort-selector.min.js b/admin/tool/lp/amd/build/form-cohort-selector.min.js index b582a15777b..fd26ffb72b5 100644 --- a/admin/tool/lp/amd/build/form-cohort-selector.min.js +++ b/admin/tool/lp/amd/build/form-cohort-selector.min.js @@ -1 +1 @@ -define(["jquery","core/ajax","core/templates"],function(a,b,c){return{processResults:function(b,c){var d=[];return a.each(c,function(a,b){d.push({value:b.id,label:b._label})}),d},transport:function(d,e,f,g){var h,i=parseInt(a(d).data("contextid"),10),j=a(d).data("includes");h=b.call([{methodname:"tool_lp_search_cohorts",args:{query:e,context:{contextid:i},includes:j}}]),h[0].then(function(b){var d=[],e=0;return a.each(b.cohorts,function(a,b){d.push(c.render("tool_lp/form-cohort-selector-suggestion",b))}),a.when.apply(a.when,d).then(function(){var c=arguments;a.each(b.cohorts,function(a,b){b._label=c[e],e++}),f(b.cohorts)})},g)}}}); \ No newline at end of file +define(["jquery","core/ajax","core/templates"],function(a,b,c){return{processResults:function(b,c){var d=[];return a.each(c,function(a,b){d.push({value:b.id,label:b._label})}),d},transport:function(d,e,f,g){var h,i=parseInt(a(d).data("contextid"),10),j=a(d).data("includes");h=b.call([{methodname:"tool_lp_search_cohorts",args:{query:e,context:{contextid:i},includes:j}}]),h[0].then(function(b){var d=[],e=0;return a.each(b.cohorts,function(a,b){d.push(c.render("tool_lp/form-cohort-selector-suggestion",b))}),a.when.apply(a.when,d).then(function(){var c=arguments;a.each(b.cohorts,function(a,b){b._label=c[e],e++}),f(b.cohorts)})})["catch"](g)}}}); \ No newline at end of file diff --git a/admin/tool/lp/amd/build/form-user-selector.min.js b/admin/tool/lp/amd/build/form-user-selector.min.js index d228806883a..febb8d4408f 100644 --- a/admin/tool/lp/amd/build/form-user-selector.min.js +++ b/admin/tool/lp/amd/build/form-user-selector.min.js @@ -1 +1 @@ -define(["jquery","core/ajax","core/templates"],function(a,b,c){return{processResults:function(b,c){var d=[];return a.each(c,function(a,b){d.push({value:b.id,label:b._label})}),d},transport:function(d,e,f,g){var h,i=a(d).data("capability");"undefined"==typeof i&&(i=""),h=b.call([{methodname:"tool_lp_search_users",args:{query:e,capability:i}}]),h[0].then(function(b){var d=[],e=0;return a.each(b.users,function(b,e){var f=e,g=[];a.each(["idnumber","email","phone1","phone2","department","institution"],function(a,b){"undefined"!=typeof e[b]&&""!==e[b]&&(f.hasidentity=!0,g.push(e[b]))}),f.identity=g.join(", "),d.push(c.render("tool_lp/form-user-selector-suggestion",f))}),a.when.apply(a.when,d).then(function(){var c=arguments;a.each(b.users,function(a,b){b._label=c[e],e++}),f(b.users)})},g)}}}); \ No newline at end of file +define(["jquery","core/ajax","core/templates"],function(a,b,c){return{processResults:function(b,c){var d=[];return a.each(c,function(a,b){d.push({value:b.id,label:b._label})}),d},transport:function(d,e,f,g){var h,i=a(d).data("capability");"undefined"==typeof i&&(i=""),h=b.call([{methodname:"tool_lp_search_users",args:{query:e,capability:i}}]),h[0].then(function(b){var d=[],e=0;return a.each(b.users,function(b,e){var f=e,g=[];a.each(["idnumber","email","phone1","phone2","department","institution"],function(a,b){"undefined"!=typeof e[b]&&""!==e[b]&&(f.hasidentity=!0,g.push(e[b]))}),f.identity=g.join(", "),d.push(c.render("tool_lp/form-user-selector-suggestion",f))}),a.when.apply(a.when,d).then(function(){var c=arguments;a.each(b.users,function(a,b){b._label=c[e],e++}),f(b.users)})})["catch"](g)}}}); \ No newline at end of file diff --git a/admin/tool/lp/amd/build/frameworks_datasource.min.js b/admin/tool/lp/amd/build/frameworks_datasource.min.js index cfc5c70bddb..9f2ec483896 100644 --- a/admin/tool/lp/amd/build/frameworks_datasource.min.js +++ b/admin/tool/lp/amd/build/frameworks_datasource.min.js @@ -1 +1 @@ -define(["jquery","core/ajax","core/notification"],function(a,b,c){return{list:function(d,e){var f,g={context:{contextid:d}};return a.extend(g,"undefined"==typeof e?{}:e),f=b.call([{methodname:"core_competency_list_competency_frameworks",args:g}])[0],f.fail(c.exception)},processResults:function(b,c){var d=[];return a.each(c,function(a,b){d.push({value:b.id,label:b.shortname+" "+b.idnumber})}),d},transport:function(b,c,d){var e=a(b),f=e.data("contextid"),g=e.data("onlyvisible");if(!f)throw new Error("The attribute data-contextid is required on "+b);this.list(f,{query:c,onlyvisible:g}).then(d)}}}); \ No newline at end of file +define(["jquery","core/ajax","core/notification"],function(a,b,c){return{list:function(c,d){var e={context:{contextid:c}};return a.extend(e,"undefined"==typeof d?{}:d),b.call([{methodname:"core_competency_list_competency_frameworks",args:e}])[0]},processResults:function(b,c){var d=[];return a.each(c,function(a,b){d.push({value:b.id,label:b.shortname+" "+b.idnumber})}),d},transport:function(b,d,e){var f=a(b),g=f.data("contextid"),h=f.data("onlyvisible");if(!g)throw new Error("The attribute data-contextid is required on "+b);this.list(g,{query:d,onlyvisible:h}).then(e)["catch"](c.exception)}}}); \ No newline at end of file diff --git a/admin/tool/lp/amd/build/planactions.min.js b/admin/tool/lp/amd/build/planactions.min.js index aeb8b9e7c31..f63fbbcaca5 100644 --- a/admin/tool/lp/amd/build/planactions.min.js +++ b/admin/tool/lp/amd/build/planactions.min.js @@ -1 +1 @@ -define(["jquery","core/templates","core/ajax","core/notification","core/str","tool_lp/menubar","tool_lp/dialogue"],function(a,b,c,d,e,f,g){var h=function(a){if(this._type=a,"plan"===a)this._region='[data-region="plan-page"]',this._planNode='[data-region="plan-page"]',this._template="tool_lp/plan_page",this._contextMethod="tool_lp_data_for_plan_page";else{if("plans"!==a)throw new TypeError("Unexpected type.");this._region='[data-region="plans"]',this._planNode='[data-region="plan-node"]',this._template="tool_lp/plans_page",this._contextMethod="tool_lp_data_for_plans_page"}};return h.prototype._contextMethod=null,h.prototype._planNode=null,h.prototype._region=null,h.prototype._template=null,h.prototype._type=null,h.prototype._getContextArgs=function(a){var b=this,c={};return"plan"===b._type?c={planid:a.id}:"plans"===b._type&&(c={userid:a.userid}),c},h.prototype.refresh=function(b){var c=this._findPlanData(a(b));this._callAndRefresh([],c)},h.prototype._renderView=function(c){var e=this;b.render(e._template,c).done(function(c,d){a(e._region).replaceWith(c),b.runTemplateJS(d)}).fail(d.exception)},h.prototype._callAndRefresh=function(b,e){var f=this;return b.push({methodname:f._contextMethod,args:f._getContextArgs(e)}),a.when.apply(a.when,c.call(b)).then(function(){f._renderView(arguments[arguments.length-1])}).fail(d.exception)},h.prototype._doDelete=function(a){var b=this,c=[{methodname:"core_competency_delete_plan",args:{id:a.id}}];b._callAndRefresh(c,a)},h.prototype.deletePlan=function(a){var b,f=this;b=c.call([{methodname:"core_competency_read_plan",args:{id:a.id}}]),b[0].done(function(b){e.get_strings([{key:"confirm",component:"moodle"},{key:"deleteplan",component:"tool_lp",param:b.name},{key:"delete",component:"moodle"},{key:"cancel",component:"moodle"}]).done(function(b){d.confirm(b[0],b[1],b[2],b[3],function(){f._doDelete(a)})}).fail(d.exception)}).fail(d.exception)},h.prototype._doReopenPlan=function(a){var b=this,c=[{methodname:"core_competency_reopen_plan",args:{planid:a.id}}];b._callAndRefresh(c,a)},h.prototype.reopenPlan=function(a){var b=this,f=c.call([{methodname:"core_competency_read_plan",args:{id:a.id}}]);f[0].done(function(c){e.get_strings([{key:"confirm",component:"moodle"},{key:"reopenplanconfirm",component:"tool_lp",param:c.name},{key:"reopenplan",component:"tool_lp"},{key:"cancel",component:"moodle"}]).done(function(c){d.confirm(c[0],c[1],c[2],c[3],function(){b._doReopenPlan(a)})}).fail(d.exception)}).fail(d.exception)},h.prototype._doCompletePlan=function(a){var b=this,c=[{methodname:"core_competency_complete_plan",args:{planid:a.id}}];b._callAndRefresh(c,a)},h.prototype.completePlan=function(a){var b=this,f=c.call([{methodname:"core_competency_read_plan",args:{id:a.id}}]);f[0].done(function(c){e.get_strings([{key:"confirm",component:"moodle"},{key:"completeplanconfirm",component:"tool_lp",param:c.name},{key:"completeplan",component:"tool_lp"},{key:"cancel",component:"moodle"}]).done(function(c){d.confirm(c[0],c[1],c[2],c[3],function(){b._doCompletePlan(a)})}).fail(d.exception)}).fail(d.exception)},h.prototype._doUnlinkPlan=function(a){var b=this,c=[{methodname:"core_competency_unlink_plan_from_template",args:{planid:a.id}}];b._callAndRefresh(c,a)},h.prototype.unlinkPlan=function(a){var b=this,f=c.call([{methodname:"core_competency_read_plan",args:{id:a.id}}]);f[0].done(function(c){e.get_strings([{key:"confirm",component:"moodle"},{key:"unlinkplantemplateconfirm",component:"tool_lp",param:c.name},{key:"unlinkplantemplate",component:"tool_lp"},{key:"cancel",component:"moodle"}]).done(function(c){d.confirm(c[0],c[1],c[2],c[3],function(){b._doUnlinkPlan(a)})}).fail(d.exception)}).fail(d.exception)},h.prototype._doRequestReview=function(a){var b=[{methodname:"core_competency_plan_request_review",args:{id:a.id}}];this._callAndRefresh(b,a)},h.prototype.requestReview=function(a){this._doRequestReview(a)},h.prototype._doCancelReviewRequest=function(a){var b=[{methodname:"core_competency_plan_cancel_review_request",args:{id:a.id}}];this._callAndRefresh(b,a)},h.prototype.cancelReviewRequest=function(a){this._doCancelReviewRequest(a)},h.prototype._doStartReview=function(a){var b=[{methodname:"core_competency_plan_start_review",args:{id:a.id}}];this._callAndRefresh(b,a)},h.prototype.startReview=function(a){this._doStartReview(a)},h.prototype._doStopReview=function(a){var b=[{methodname:"core_competency_plan_stop_review",args:{id:a.id}}];this._callAndRefresh(b,a)},h.prototype.stopReview=function(a){this._doStopReview(a)},h.prototype._doApprove=function(a){var b=[{methodname:"core_competency_approve_plan",args:{id:a.id}}];this._callAndRefresh(b,a)},h.prototype.approve=function(a){this._doApprove(a)},h.prototype._doUnapprove=function(a){var b=[{methodname:"core_competency_unapprove_plan",args:{id:a.id}}];this._callAndRefresh(b,a)},h.prototype.unapprove=function(a){this._doUnapprove(a)},h.prototype._showLinkedCoursesHandler=function(f){f.preventDefault();var h=a(f.target).data("id"),i=c.call([{methodname:"tool_lp_list_courses_using_competency",args:{id:h}}]);i[0].done(function(a){var c={courses:a};b.render("tool_lp/linked_courses_summary",c).done(function(a){e.get_string("linkedcourses","tool_lp").done(function(b){new g(b,a)}).fail(d.exception)}).fail(d.exception)}).fail(d.exception)},h.prototype._eventHandler=function(b,c){c.preventDefault();var d=this._findPlanData(a(c.target));this[b](d)},h.prototype._findPlanData=function(b){var c,d=b.parentsUntil(a(this._region).parent(),this._planNode);if(1!=d.length)throw new Error("The plan node was not located.");if(c=d.data(),"undefined"==typeof c||"undefined"==typeof c.id)throw new Error("Plan data could not be found.");return c},h.prototype.enhanceMenubar=function(a){f.enhance(a,{'[data-action="plan-delete"]':this._eventHandler.bind(this,"deletePlan"),'[data-action="plan-complete"]':this._eventHandler.bind(this,"completePlan"),'[data-action="plan-reopen"]':this._eventHandler.bind(this,"reopenPlan"),'[data-action="plan-unlink"]':this._eventHandler.bind(this,"unlinkPlan"),'[data-action="plan-request-review"]':this._eventHandler.bind(this,"requestReview"),'[data-action="plan-cancel-review-request"]':this._eventHandler.bind(this,"cancelReviewRequest"),'[data-action="plan-start-review"]':this._eventHandler.bind(this,"startReview"),'[data-action="plan-stop-review"]':this._eventHandler.bind(this,"stopReview"),'[data-action="plan-approve"]':this._eventHandler.bind(this,"approve"),'[data-action="plan-unapprove"]':this._eventHandler.bind(this,"unapprove")})},h.prototype.registerEvents=function(){var b=a(this._region);b.find('[data-action="plan-delete"]').click(this._eventHandler.bind(this,"deletePlan")),b.find('[data-action="plan-complete"]').click(this._eventHandler.bind(this,"completePlan")),b.find('[data-action="plan-reopen"]').click(this._eventHandler.bind(this,"reopenPlan")),b.find('[data-action="plan-unlink"]').click(this._eventHandler.bind(this,"unlinkPlan")),b.find('[data-action="plan-request-review"]').click(this._eventHandler.bind(this,"requestReview")),b.find('[data-action="plan-cancel-review-request"]').click(this._eventHandler.bind(this,"cancelReviewRequest")),b.find('[data-action="plan-start-review"]').click(this._eventHandler.bind(this,"startReview")),b.find('[data-action="plan-stop-review"]').click(this._eventHandler.bind(this,"stopReview")),b.find('[data-action="plan-approve"]').click(this._eventHandler.bind(this,"approve")),b.find('[data-action="plan-unapprove"]').click(this._eventHandler.bind(this,"unapprove")),b.find('[data-action="find-courses-link"]').click(this._showLinkedCoursesHandler.bind(this))},h}); \ No newline at end of file +define(["jquery","core/templates","core/ajax","core/notification","core/str","tool_lp/menubar","tool_lp/dialogue"],function(a,b,c,d,e,f,g){var h=function(a){if(this._type=a,"plan"===a)this._region='[data-region="plan-page"]',this._planNode='[data-region="plan-page"]',this._template="tool_lp/plan_page",this._contextMethod="tool_lp_data_for_plan_page";else{if("plans"!==a)throw new TypeError("Unexpected type.");this._region='[data-region="plans"]',this._planNode='[data-region="plan-node"]',this._template="tool_lp/plans_page",this._contextMethod="tool_lp_data_for_plans_page"}};return h.prototype._contextMethod=null,h.prototype._planNode=null,h.prototype._region=null,h.prototype._template=null,h.prototype._type=null,h.prototype._getContextArgs=function(a){var b=this,c={};return"plan"===b._type?c={planid:a.id}:"plans"===b._type&&(c={userid:a.userid}),c},h.prototype.refresh=function(b){var c=this._findPlanData(a(b));this._callAndRefresh([],c)},h.prototype._renderView=function(c){var d=this;return b.render(d._template,c).then(function(c,e){a(d._region).replaceWith(c),b.runTemplateJS(e)})},h.prototype._callAndRefresh=function(b,e){var f=this;return b.push({methodname:f._contextMethod,args:f._getContextArgs(e)}),a.when.apply(a,c.call(b)).then(function(){return f._renderView(arguments[arguments.length-1])}).fail(d.exception)},h.prototype._doDelete=function(a){var b=this,c=[{methodname:"core_competency_delete_plan",args:{id:a.id}}];b._callAndRefresh(c,a)},h.prototype.deletePlan=function(a){var b,f=this;b=c.call([{methodname:"core_competency_read_plan",args:{id:a.id}}]),b[0].done(function(b){e.get_strings([{key:"confirm",component:"moodle"},{key:"deleteplan",component:"tool_lp",param:b.name},{key:"delete",component:"moodle"},{key:"cancel",component:"moodle"}]).done(function(b){d.confirm(b[0],b[1],b[2],b[3],function(){f._doDelete(a)})}).fail(d.exception)}).fail(d.exception)},h.prototype._doReopenPlan=function(a){var b=this,c=[{methodname:"core_competency_reopen_plan",args:{planid:a.id}}];b._callAndRefresh(c,a)},h.prototype.reopenPlan=function(a){var b=this,f=c.call([{methodname:"core_competency_read_plan",args:{id:a.id}}]);f[0].done(function(c){e.get_strings([{key:"confirm",component:"moodle"},{key:"reopenplanconfirm",component:"tool_lp",param:c.name},{key:"reopenplan",component:"tool_lp"},{key:"cancel",component:"moodle"}]).done(function(c){d.confirm(c[0],c[1],c[2],c[3],function(){b._doReopenPlan(a)})}).fail(d.exception)}).fail(d.exception)},h.prototype._doCompletePlan=function(a){var b=this,c=[{methodname:"core_competency_complete_plan",args:{planid:a.id}}];b._callAndRefresh(c,a)},h.prototype.completePlan=function(a){var b=this,f=c.call([{methodname:"core_competency_read_plan",args:{id:a.id}}]);f[0].done(function(c){e.get_strings([{key:"confirm",component:"moodle"},{key:"completeplanconfirm",component:"tool_lp",param:c.name},{key:"completeplan",component:"tool_lp"},{key:"cancel",component:"moodle"}]).done(function(c){d.confirm(c[0],c[1],c[2],c[3],function(){b._doCompletePlan(a)})}).fail(d.exception)}).fail(d.exception)},h.prototype._doUnlinkPlan=function(a){var b=this,c=[{methodname:"core_competency_unlink_plan_from_template",args:{planid:a.id}}];b._callAndRefresh(c,a)},h.prototype.unlinkPlan=function(a){var b=this,f=c.call([{methodname:"core_competency_read_plan",args:{id:a.id}}]);f[0].done(function(c){e.get_strings([{key:"confirm",component:"moodle"},{key:"unlinkplantemplateconfirm",component:"tool_lp",param:c.name},{key:"unlinkplantemplate",component:"tool_lp"},{key:"cancel",component:"moodle"}]).done(function(c){d.confirm(c[0],c[1],c[2],c[3],function(){b._doUnlinkPlan(a)})}).fail(d.exception)}).fail(d.exception)},h.prototype._doRequestReview=function(a){var b=[{methodname:"core_competency_plan_request_review",args:{id:a.id}}];this._callAndRefresh(b,a)},h.prototype.requestReview=function(a){this._doRequestReview(a)},h.prototype._doCancelReviewRequest=function(a){var b=[{methodname:"core_competency_plan_cancel_review_request",args:{id:a.id}}];this._callAndRefresh(b,a)},h.prototype.cancelReviewRequest=function(a){this._doCancelReviewRequest(a)},h.prototype._doStartReview=function(a){var b=[{methodname:"core_competency_plan_start_review",args:{id:a.id}}];this._callAndRefresh(b,a)},h.prototype.startReview=function(a){this._doStartReview(a)},h.prototype._doStopReview=function(a){var b=[{methodname:"core_competency_plan_stop_review",args:{id:a.id}}];this._callAndRefresh(b,a)},h.prototype.stopReview=function(a){this._doStopReview(a)},h.prototype._doApprove=function(a){var b=[{methodname:"core_competency_approve_plan",args:{id:a.id}}];this._callAndRefresh(b,a)},h.prototype.approve=function(a){this._doApprove(a)},h.prototype._doUnapprove=function(a){var b=[{methodname:"core_competency_unapprove_plan",args:{id:a.id}}];this._callAndRefresh(b,a)},h.prototype.unapprove=function(a){this._doUnapprove(a)},h.prototype._showLinkedCoursesHandler=function(f){f.preventDefault();var h=a(f.target).data("id"),i=c.call([{methodname:"tool_lp_list_courses_using_competency",args:{id:h}}]);i[0].done(function(a){var c={courses:a};b.render("tool_lp/linked_courses_summary",c).done(function(a){e.get_string("linkedcourses","tool_lp").done(function(b){new g(b,a)}).fail(d.exception)}).fail(d.exception)}).fail(d.exception)},h.prototype._eventHandler=function(b,c){c.preventDefault();var d=this._findPlanData(a(c.target));this[b](d)},h.prototype._findPlanData=function(b){var c,d=b.parentsUntil(a(this._region).parent(),this._planNode);if(1!=d.length)throw new Error("The plan node was not located.");if(c=d.data(),"undefined"==typeof c||"undefined"==typeof c.id)throw new Error("Plan data could not be found.");return c},h.prototype.enhanceMenubar=function(a){f.enhance(a,{'[data-action="plan-delete"]':this._eventHandler.bind(this,"deletePlan"),'[data-action="plan-complete"]':this._eventHandler.bind(this,"completePlan"),'[data-action="plan-reopen"]':this._eventHandler.bind(this,"reopenPlan"),'[data-action="plan-unlink"]':this._eventHandler.bind(this,"unlinkPlan"),'[data-action="plan-request-review"]':this._eventHandler.bind(this,"requestReview"),'[data-action="plan-cancel-review-request"]':this._eventHandler.bind(this,"cancelReviewRequest"),'[data-action="plan-start-review"]':this._eventHandler.bind(this,"startReview"),'[data-action="plan-stop-review"]':this._eventHandler.bind(this,"stopReview"),'[data-action="plan-approve"]':this._eventHandler.bind(this,"approve"),'[data-action="plan-unapprove"]':this._eventHandler.bind(this,"unapprove")})},h.prototype.registerEvents=function(){var b=a(this._region);b.find('[data-action="plan-delete"]').click(this._eventHandler.bind(this,"deletePlan")),b.find('[data-action="plan-complete"]').click(this._eventHandler.bind(this,"completePlan")),b.find('[data-action="plan-reopen"]').click(this._eventHandler.bind(this,"reopenPlan")),b.find('[data-action="plan-unlink"]').click(this._eventHandler.bind(this,"unlinkPlan")),b.find('[data-action="plan-request-review"]').click(this._eventHandler.bind(this,"requestReview")),b.find('[data-action="plan-cancel-review-request"]').click(this._eventHandler.bind(this,"cancelReviewRequest")),b.find('[data-action="plan-start-review"]').click(this._eventHandler.bind(this,"startReview")),b.find('[data-action="plan-stop-review"]').click(this._eventHandler.bind(this,"stopReview")),b.find('[data-action="plan-approve"]').click(this._eventHandler.bind(this,"approve")),b.find('[data-action="plan-unapprove"]').click(this._eventHandler.bind(this,"unapprove")),b.find('[data-action="find-courses-link"]').click(this._showLinkedCoursesHandler.bind(this))},h}); \ No newline at end of file diff --git a/admin/tool/lp/amd/build/user_competency_plan_popup.min.js b/admin/tool/lp/amd/build/user_competency_plan_popup.min.js index 610c93595d5..755a66433ab 100644 --- a/admin/tool/lp/amd/build/user_competency_plan_popup.min.js +++ b/admin/tool/lp/amd/build/user_competency_plan_popup.min.js @@ -1 +1 @@ -define(["jquery","core/notification","core/str","core/ajax","core/templates","tool_lp/dialogue"],function(a,b,c,d,e,f){var g=function(b,c,d){this._regionSelector=b,this._userCompetencySelector=c,this._planId=d,a(this._regionSelector).on("click",this._userCompetencySelector,this._handleClick.bind(this))};return g.prototype._handleClick=function(c){c.preventDefault();var e=a(c.target).closest("tr"),f=a(e).data("competencyid"),g=a(e).data("userid"),h=this._planId,i=d.call([{methodname:"tool_lp_data_for_user_competency_summary_in_plan",args:{competencyid:f,planid:h},done:this._contextLoaded.bind(this),fail:b.exception}]);i[0].then(function(a){var c="core_competency_user_competency_viewed_in_plan";a.plan.iscompleted&&(c="core_competency_user_competency_plan_viewed"),d.call([{methodname:c,args:{competencyid:f,userid:g,planid:h},fail:b.exception}])})},g.prototype._contextLoaded=function(a){var d=this;e.render("tool_lp/user_competency_summary_in_plan",a).done(function(a,g){c.get_string("usercompetencysummary","report_competency").done(function(b){new f(b,a,e.runTemplateJS.bind(e,g),d._refresh.bind(d),(!0))}).fail(b.exception)}).fail(b.exception)},g.prototype._refresh=function(){var a=this._planId;d.call([{methodname:"tool_lp_data_for_plan_page",args:{planid:a},done:this._pageContextLoaded.bind(this),fail:b.exception}])},g.prototype._pageContextLoaded=function(a){var c=this;e.render("tool_lp/plan_page",a).done(function(a,b){e.replaceNode(c._regionSelector,a,b)}).fail(b.exception)},g.prototype._regionSelector=null,g.prototype._userCompetencySelector=null,g.prototype._planId=null,g}); \ No newline at end of file +define(["jquery","core/notification","core/str","core/ajax","core/templates","tool_lp/dialogue"],function(a,b,c,d,e,f){var g=function(b,c,d){this._regionSelector=b,this._userCompetencySelector=c,this._planId=d,a(this._regionSelector).on("click",this._userCompetencySelector,this._handleClick.bind(this))};return g.prototype._handleClick=function(c){c.preventDefault();var e=a(c.target).closest("tr"),f=a(e).data("competencyid"),g=a(e).data("userid"),h=this._planId,i=d.call([{methodname:"tool_lp_data_for_user_competency_summary_in_plan",args:{competencyid:f,planid:h},done:this._contextLoaded.bind(this),fail:b.exception}]);i[0].then(function(a){var b="core_competency_user_competency_viewed_in_plan";return a.plan.iscompleted&&(b="core_competency_user_competency_plan_viewed"),d.call([{methodname:b,args:{competencyid:f,userid:g,planid:h}}])[0]})["catch"](b.exception)},g.prototype._contextLoaded=function(a){var d=this;e.render("tool_lp/user_competency_summary_in_plan",a).done(function(a,g){c.get_string("usercompetencysummary","report_competency").done(function(b){new f(b,a,e.runTemplateJS.bind(e,g),d._refresh.bind(d),(!0))}).fail(b.exception)}).fail(b.exception)},g.prototype._refresh=function(){var a=this._planId;d.call([{methodname:"tool_lp_data_for_plan_page",args:{planid:a},done:this._pageContextLoaded.bind(this),fail:b.exception}])},g.prototype._pageContextLoaded=function(a){var c=this;e.render("tool_lp/plan_page",a).done(function(a,b){e.replaceNode(c._regionSelector,a,b)}).fail(b.exception)},g.prototype._regionSelector=null,g.prototype._userCompetencySelector=null,g.prototype._planId=null,g}); \ No newline at end of file diff --git a/admin/tool/lp/amd/build/user_competency_workflow.min.js b/admin/tool/lp/amd/build/user_competency_workflow.min.js index 821222fd2b0..deab0e18ab3 100644 --- a/admin/tool/lp/amd/build/user_competency_workflow.min.js +++ b/admin/tool/lp/amd/build/user_competency_workflow.min.js @@ -1 +1 @@ -define(["jquery","core/templates","core/ajax","core/notification","core/str","tool_lp/menubar","tool_lp/event_base"],function(a,b,c,d,e,f,g){var h=function(){g.prototype.constructor.apply(this,[])};return h.prototype=Object.create(g.prototype),h.prototype._nodeSelector='[data-node="user-competency"]',h.prototype._cancelReviewRequest=function(a){var b={methodname:"core_competency_user_competency_cancel_review_request",args:{userid:a.userid,competencyid:a.competencyid}};c.call([b])[0].then(function(){this._trigger("review-request-cancelled",a),this._trigger("status-changed",a)}.bind(this),function(){this._trigger("error-occured",a)}.bind(this))},h.prototype.cancelReviewRequest=function(a){this._cancelReviewRequest(a)},h.prototype._cancelReviewRequestHandler=function(b){b.preventDefault();var c=this._findUserCompetencyData(a(b.target));this.cancelReviewRequest(c)},h.prototype._requestReview=function(a){var b={methodname:"core_competency_user_competency_request_review",args:{userid:a.userid,competencyid:a.competencyid}};c.call([b])[0].then(function(){this._trigger("review-requested",a),this._trigger("status-changed",a)}.bind(this),function(){this._trigger("error-occured",a)}.bind(this))},h.prototype.requestReview=function(a){this._requestReview(a)},h.prototype._requestReviewHandler=function(b){b.preventDefault();var c=this._findUserCompetencyData(a(b.target));this.requestReview(c)},h.prototype._startReview=function(a){var b={methodname:"core_competency_user_competency_start_review",args:{userid:a.userid,competencyid:a.competencyid}};c.call([b])[0].then(function(){this._trigger("review-started",a),this._trigger("status-changed",a)}.bind(this),function(){this._trigger("error-occured",a)}.bind(this))},h.prototype.startReview=function(a){this._startReview(a)},h.prototype._startReviewHandler=function(b){b.preventDefault();var c=this._findUserCompetencyData(a(b.target));this.startReview(c)},h.prototype._stopReview=function(a){var b={methodname:"core_competency_user_competency_stop_review",args:{userid:a.userid,competencyid:a.competencyid}};c.call([b])[0].then(function(){this._trigger("review-stopped",a),this._trigger("status-changed",a)}.bind(this),function(){this._trigger("error-occured",a)}.bind(this))},h.prototype.stopReview=function(a){this._stopReview(a)},h.prototype._stopReviewHandler=function(b){b.preventDefault();var c=this._findUserCompetencyData(a(b.target));this.stopReview(c)},h.prototype.enhanceMenubar=function(a){f.enhance(a,{'[data-action="request-review"]':this._requestReviewHandler.bind(this),'[data-action="cancel-review-request"]':this._cancelReviewRequestHandler.bind(this)})},h.prototype._findUserCompetencyData=function(a){var b,c=a.parents(this._nodeSelector);if(1!=c.length)throw new Error("The evidence node was not located.");if(b=c.data(),"undefined"==typeof b||"undefined"==typeof b.userid||"undefined"==typeof b.competencyid)throw new Error("User competency data could not be found.");return b},h.prototype.enhanceMenubar=function(a){f.enhance(a,{'[data-action="request-review"]':this._requestReviewHandler.bind(this),'[data-action="cancel-review-request"]':this._cancelReviewRequestHandler.bind(this),'[data-action="start-review"]':this._startReviewHandler.bind(this),'[data-action="stop-review"]':this._stopReviewHandler.bind(this)})},h.prototype.registerEvents=function(b){var c=a(b);c.find('[data-action="request-review"]').click(this._requestReviewHandler.bind(this)),c.find('[data-action="cancel-review-request"]').click(this._cancelReviewRequestHandler.bind(this)),c.find('[data-action="start-review"]').click(this._startReviewHandler.bind(this)),c.find('[data-action="stop-review"]').click(this._stopReviewHandler.bind(this))},h}); \ No newline at end of file +define(["jquery","core/templates","core/ajax","core/notification","core/str","tool_lp/menubar","tool_lp/event_base"],function(a,b,c,d,e,f,g){var h=function(){g.prototype.constructor.apply(this,[])};return h.prototype=Object.create(g.prototype),h.prototype._nodeSelector='[data-node="user-competency"]',h.prototype._cancelReviewRequest=function(a){var b={methodname:"core_competency_user_competency_cancel_review_request",args:{userid:a.userid,competencyid:a.competencyid}};c.call([b])[0].then(function(){this._trigger("review-request-cancelled",a),this._trigger("status-changed",a)}.bind(this))["catch"](function(){this._trigger("error-occured",a)}.bind(this))},h.prototype.cancelReviewRequest=function(a){this._cancelReviewRequest(a)},h.prototype._cancelReviewRequestHandler=function(b){b.preventDefault();var c=this._findUserCompetencyData(a(b.target));this.cancelReviewRequest(c)},h.prototype._requestReview=function(a){var b={methodname:"core_competency_user_competency_request_review",args:{userid:a.userid,competencyid:a.competencyid}};c.call([b])[0].then(function(){this._trigger("review-requested",a),this._trigger("status-changed",a)}.bind(this))["catch"](function(){this._trigger("error-occured",a)}.bind(this))},h.prototype.requestReview=function(a){this._requestReview(a)},h.prototype._requestReviewHandler=function(b){b.preventDefault();var c=this._findUserCompetencyData(a(b.target));this.requestReview(c)},h.prototype._startReview=function(a){var b={methodname:"core_competency_user_competency_start_review",args:{userid:a.userid,competencyid:a.competencyid}};c.call([b])[0].then(function(){this._trigger("review-started",a),this._trigger("status-changed",a)}.bind(this))["catch"](function(){this._trigger("error-occured",a)}.bind(this))},h.prototype.startReview=function(a){this._startReview(a)},h.prototype._startReviewHandler=function(b){b.preventDefault();var c=this._findUserCompetencyData(a(b.target));this.startReview(c)},h.prototype._stopReview=function(a){var b={methodname:"core_competency_user_competency_stop_review",args:{userid:a.userid,competencyid:a.competencyid}};c.call([b])[0].then(function(){this._trigger("review-stopped",a),this._trigger("status-changed",a)}.bind(this))["catch"](function(){this._trigger("error-occured",a)}.bind(this))},h.prototype.stopReview=function(a){this._stopReview(a)},h.prototype._stopReviewHandler=function(b){b.preventDefault();var c=this._findUserCompetencyData(a(b.target));this.stopReview(c)},h.prototype.enhanceMenubar=function(a){f.enhance(a,{'[data-action="request-review"]':this._requestReviewHandler.bind(this),'[data-action="cancel-review-request"]':this._cancelReviewRequestHandler.bind(this)})},h.prototype._findUserCompetencyData=function(a){var b,c=a.parents(this._nodeSelector);if(1!=c.length)throw new Error("The evidence node was not located.");if(b=c.data(),"undefined"==typeof b||"undefined"==typeof b.userid||"undefined"==typeof b.competencyid)throw new Error("User competency data could not be found.");return b},h.prototype.enhanceMenubar=function(a){f.enhance(a,{'[data-action="request-review"]':this._requestReviewHandler.bind(this),'[data-action="cancel-review-request"]':this._cancelReviewRequestHandler.bind(this),'[data-action="start-review"]':this._startReviewHandler.bind(this),'[data-action="stop-review"]':this._stopReviewHandler.bind(this)})},h.prototype.registerEvents=function(b){var c=a(b);c.find('[data-action="request-review"]').click(this._requestReviewHandler.bind(this)),c.find('[data-action="cancel-review-request"]').click(this._cancelReviewRequestHandler.bind(this)),c.find('[data-action="start-review"]').click(this._startReviewHandler.bind(this)),c.find('[data-action="stop-review"]').click(this._stopReviewHandler.bind(this))},h}); \ No newline at end of file diff --git a/admin/tool/lp/amd/build/user_evidence_actions.min.js b/admin/tool/lp/amd/build/user_evidence_actions.min.js index a69a9d82ff3..f8b28d73c73 100644 --- a/admin/tool/lp/amd/build/user_evidence_actions.min.js +++ b/admin/tool/lp/amd/build/user_evidence_actions.min.js @@ -1 +1 @@ -define(["jquery","core/templates","core/ajax","core/notification","core/str","tool_lp/menubar","tool_lp/competencypicker_user_plans"],function(a,b,c,d,e,f,g){var h=function(a){if(this._type=a,"evidence"===a)this._region='[data-region="user-evidence-page"]',this._evidenceNode='[data-region="user-evidence-page"]',this._template="tool_lp/user_evidence_page",this._contextMethod="tool_lp_data_for_user_evidence_page";else{if("list"!==a)throw new TypeError("Unexpected type.");this._region='[data-region="user-evidence-list"]',this._evidenceNode='[data-region="user-evidence-node"]',this._template="tool_lp/user_evidence_list_page",this._contextMethod="tool_lp_data_for_user_evidence_list_page"}};return h.prototype._contextMethod=null,h.prototype._evidenceNode=null,h.prototype._region=null,h.prototype._template=null,h.prototype._type=null,h.prototype._getContextArgs=function(a){var b=this,c={};return"evidence"===b._type?c={id:a.id}:"list"===b._type&&(c={userid:a.userid}),c},h.prototype._renderView=function(c){var e=this;b.render(e._template,c).done(function(c,d){b.replaceNode(a(e._region),c,d)}).fail(d.exception)},h.prototype._callAndRefresh=function(b,e){var f=this;return b.push({methodname:f._contextMethod,args:f._getContextArgs(e)}),a.when.apply(a.when,c.call(b)).then(function(){f._renderView(arguments[arguments.length-1])}).fail(d.exception)},h.prototype._doDelete=function(a){var b=this,c=[{methodname:"core_competency_delete_user_evidence",args:{id:a.id}}];b._callAndRefresh(c,a)},h.prototype.deleteEvidence=function(a){var b,f=this;b=c.call([{methodname:"core_competency_read_user_evidence",args:{id:a.id}}]),b[0].done(function(b){e.get_strings([{key:"confirm",component:"moodle"},{key:"deleteuserevidence",component:"tool_lp",param:b.name},{key:"delete",component:"moodle"},{key:"cancel",component:"moodle"}]).done(function(b){d.confirm(b[0],b[1],b[2],b[3],function(){f._doDelete(a)})}).fail(d.exception)}).fail(d.exception)},h.prototype._deleteEvidenceHandler=function(b){b.preventDefault();var c=this._findEvidenceData(a(b.target));this.deleteEvidence(c)},h.prototype._doCreateUserEvidenceCompetency=function(b,c){var d=this,e=[];a.each(c,function(a,c){e.push({methodname:"core_competency_create_user_evidence_competency",args:{userevidenceid:b.id,competencyid:c}})}),d._callAndRefresh(e,b)},h.prototype.createUserEvidenceCompetency=function(a){var b=this,c=new g(a.userid);c.on("save",function(c,d){var e=d.competencyIds;b._doCreateUserEvidenceCompetency(a,e,d.requestReview)}),c.display()},h.prototype._createUserEvidenceCompetencyHandler=function(b){b.preventDefault();var c=this._findEvidenceData(a(b.target));this.createUserEvidenceCompetency(c)},h.prototype._doDeleteUserEvidenceCompetency=function(a,b){var c=this,d=[];d.push({methodname:"core_competency_delete_user_evidence_competency",args:{userevidenceid:a.id,competencyid:b}}),c._callAndRefresh(d,a)},h.prototype.deleteUserEvidenceCompetency=function(a,b){this._doDeleteUserEvidenceCompetency(a,b)},h.prototype._deleteUserEvidenceCompetencyHandler=function(b){var c=this._findEvidenceData(a(b.currentTarget)),d=a(b.currentTarget).data("id");b.preventDefault(),this.deleteUserEvidenceCompetency(c,d)},h.prototype._doReviewUserEvidenceCompetencies=function(a){var b=this,c=[{methodname:"core_competency_request_review_of_user_evidence_linked_competencies",args:{id:a.id}}];b._callAndRefresh(c,a)},h.prototype.reviewUserEvidenceCompetencies=function(a){var b,f=this;b=c.call([{methodname:"core_competency_read_user_evidence",args:{id:a.id}}]),b[0].done(function(b){e.get_strings([{key:"confirm",component:"moodle"},{key:"sendallcompetenciestoreview",component:"tool_lp",param:b.name},{key:"confirm",component:"moodle"},{key:"cancel",component:"moodle"}]).done(function(b){d.confirm(b[0],b[1],b[2],b[3],function(){f._doReviewUserEvidenceCompetencies(a)})}).fail(d.exception)}).fail(d.exception)},h.prototype._reviewUserEvidenceCompetenciesHandler=function(b){b.preventDefault();var c=this._findEvidenceData(a(b.target));this.reviewUserEvidenceCompetencies(c)},h.prototype._findEvidenceData=function(b){var c,d=b.parentsUntil(a(this._region).parent(),this._evidenceNode);if(1!=d.length)throw new Error("The evidence node was not located.");if(c=d.data(),"undefined"==typeof c||"undefined"==typeof c.id)throw new Error("Evidence data could not be found.");return c},h.prototype.enhanceMenubar=function(a){var b=this;f.enhance(a,{'[data-action="user-evidence-delete"]':b._deleteEvidenceHandler.bind(b),'[data-action="link-competency"]':b._createUserEvidenceCompetencyHandler.bind(b),'[data-action="send-competencies-review"]':b._reviewUserEvidenceCompetenciesHandler.bind(b)})},h.prototype.registerEvents=function(){var b=a(this._region),c=this;b.find('[data-action="user-evidence-delete"]').click(c._deleteEvidenceHandler.bind(c)),b.find('[data-action="link-competency"]').click(c._createUserEvidenceCompetencyHandler.bind(c)),b.find('[data-action="delete-competency-link"]').click(c._deleteUserEvidenceCompetencyHandler.bind(c)),b.find('[data-action="send-competencies-review"]').click(c._reviewUserEvidenceCompetenciesHandler.bind(c))},h}); \ No newline at end of file +define(["jquery","core/templates","core/ajax","core/notification","core/str","tool_lp/menubar","tool_lp/competencypicker_user_plans"],function(a,b,c,d,e,f,g){var h=function(a){if(this._type=a,"evidence"===a)this._region='[data-region="user-evidence-page"]',this._evidenceNode='[data-region="user-evidence-page"]',this._template="tool_lp/user_evidence_page",this._contextMethod="tool_lp_data_for_user_evidence_page";else{if("list"!==a)throw new TypeError("Unexpected type.");this._region='[data-region="user-evidence-list"]',this._evidenceNode='[data-region="user-evidence-node"]',this._template="tool_lp/user_evidence_list_page",this._contextMethod="tool_lp_data_for_user_evidence_list_page"}};return h.prototype._contextMethod=null,h.prototype._evidenceNode=null,h.prototype._region=null,h.prototype._template=null,h.prototype._type=null,h.prototype._getContextArgs=function(a){var b=this,c={};return"evidence"===b._type?c={id:a.id}:"list"===b._type&&(c={userid:a.userid}),c},h.prototype._renderView=function(c){var d=this;return b.render(d._template,c).then(function(c,e){b.replaceNode(a(d._region),c,e)})},h.prototype._callAndRefresh=function(b,e){var f=this;return b.push({methodname:f._contextMethod,args:f._getContextArgs(e)}),a.when.apply(a.when,c.call(b)).then(function(){return f._renderView(arguments[arguments.length-1])}).fail(d.exception)},h.prototype._doDelete=function(a){var b=this,c=[{methodname:"core_competency_delete_user_evidence",args:{id:a.id}}];b._callAndRefresh(c,a)},h.prototype.deleteEvidence=function(a){var b,f=this;b=c.call([{methodname:"core_competency_read_user_evidence",args:{id:a.id}}]),b[0].done(function(b){e.get_strings([{key:"confirm",component:"moodle"},{key:"deleteuserevidence",component:"tool_lp",param:b.name},{key:"delete",component:"moodle"},{key:"cancel",component:"moodle"}]).done(function(b){d.confirm(b[0],b[1],b[2],b[3],function(){f._doDelete(a)})}).fail(d.exception)}).fail(d.exception)},h.prototype._deleteEvidenceHandler=function(b){b.preventDefault();var c=this._findEvidenceData(a(b.target));this.deleteEvidence(c)},h.prototype._doCreateUserEvidenceCompetency=function(b,c){var d=this,e=[];a.each(c,function(a,c){e.push({methodname:"core_competency_create_user_evidence_competency",args:{userevidenceid:b.id,competencyid:c}})}),d._callAndRefresh(e,b)},h.prototype.createUserEvidenceCompetency=function(a){var b=this,c=new g(a.userid);c.on("save",function(c,d){var e=d.competencyIds;b._doCreateUserEvidenceCompetency(a,e,d.requestReview)}),c.display()},h.prototype._createUserEvidenceCompetencyHandler=function(b){b.preventDefault();var c=this._findEvidenceData(a(b.target));this.createUserEvidenceCompetency(c)},h.prototype._doDeleteUserEvidenceCompetency=function(a,b){var c=this,d=[];d.push({methodname:"core_competency_delete_user_evidence_competency",args:{userevidenceid:a.id,competencyid:b}}),c._callAndRefresh(d,a)},h.prototype.deleteUserEvidenceCompetency=function(a,b){this._doDeleteUserEvidenceCompetency(a,b)},h.prototype._deleteUserEvidenceCompetencyHandler=function(b){var c=this._findEvidenceData(a(b.currentTarget)),d=a(b.currentTarget).data("id");b.preventDefault(),this.deleteUserEvidenceCompetency(c,d)},h.prototype._doReviewUserEvidenceCompetencies=function(a){var b=this,c=[{methodname:"core_competency_request_review_of_user_evidence_linked_competencies",args:{id:a.id}}];b._callAndRefresh(c,a)},h.prototype.reviewUserEvidenceCompetencies=function(a){var b,f=this;b=c.call([{methodname:"core_competency_read_user_evidence",args:{id:a.id}}]),b[0].done(function(b){e.get_strings([{key:"confirm",component:"moodle"},{key:"sendallcompetenciestoreview",component:"tool_lp",param:b.name},{key:"confirm",component:"moodle"},{key:"cancel",component:"moodle"}]).done(function(b){d.confirm(b[0],b[1],b[2],b[3],function(){f._doReviewUserEvidenceCompetencies(a)})}).fail(d.exception)}).fail(d.exception)},h.prototype._reviewUserEvidenceCompetenciesHandler=function(b){b.preventDefault();var c=this._findEvidenceData(a(b.target));this.reviewUserEvidenceCompetencies(c)},h.prototype._findEvidenceData=function(b){var c,d=b.parentsUntil(a(this._region).parent(),this._evidenceNode);if(1!=d.length)throw new Error("The evidence node was not located.");if(c=d.data(),"undefined"==typeof c||"undefined"==typeof c.id)throw new Error("Evidence data could not be found.");return c},h.prototype.enhanceMenubar=function(a){var b=this;f.enhance(a,{'[data-action="user-evidence-delete"]':b._deleteEvidenceHandler.bind(b),'[data-action="link-competency"]':b._createUserEvidenceCompetencyHandler.bind(b),'[data-action="send-competencies-review"]':b._reviewUserEvidenceCompetenciesHandler.bind(b)})},h.prototype.registerEvents=function(){var b=a(this._region),c=this;b.find('[data-action="user-evidence-delete"]').click(c._deleteEvidenceHandler.bind(c)),b.find('[data-action="link-competency"]').click(c._createUserEvidenceCompetencyHandler.bind(c)),b.find('[data-action="delete-competency-link"]').click(c._deleteUserEvidenceCompetencyHandler.bind(c)),b.find('[data-action="send-competencies-review"]').click(c._reviewUserEvidenceCompetenciesHandler.bind(c))},h}); \ No newline at end of file diff --git a/blocks/myoverview/amd/build/event_list.min.js b/blocks/myoverview/amd/build/event_list.min.js index cdc315e0ed1..b1db8fe730b 100644 --- a/blocks/myoverview/amd/build/event_list.min.js +++ b/blocks/myoverview/amd/build/event_list.min.js @@ -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"]',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={EVENT_LIST_ITEMS:"block_myoverview/event-list-items",COURSE_EVENT_LIST_ITEMS:"block_myoverview/course-event-list-items"},i=function(a){a.attr("data-loaded-all",!0)},j=function(a){return!!a.attr("data-loaded-all")},k=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)},l=function(a){var b=a.find(g.LOADING_ICON_CONTAINER),c=a.find(g.VIEW_MORE_BUTTON);a.removeClass("loading"),b.addClass("hidden"),j(a)||c.prop("disabled",!1)},m=function(a){return a.hasClass("loading")},n=function(a){a.attr("data-has-events",!0)},o=function(a){return!!a.attr("data-has-events")},p=function(a,b){b?n(a):o(a)||q(a)},q=function(a){a.find(g.EVENT_LIST_CONTENT).addClass("hidden"),a.find(g.EMPTY_MESSAGE).removeClass("hidden")},r=function(a,b,d){return a.removeClass("hidden"),c.render(d,{events:b}).done(function(b,d){c.appendNodeContents(a.find(g.EVENT_LIST),b,d)})},s=function(a,b){var c=b.timesort||0;return c-a},t=function(a,b,c){var d=a.attr("data-midnight"),e=+c.attr("data-start-day")*f,g=+c.attr("data-end-day")*f,h=s(d,b);return""===c.attr("data-end-day")?e<=h:e<=h&&h"+b+"").find(l.ACTIVITYLI).each(function(b){t(a(this).attr("id"),h),0===b&&(u(a(this).attr("id"),i),d=null)}),d&&d.focus(),r(c,j,400),s(g,400),c.trigger(a.Event("coursemoduleedited",{ajaxreturn:b,action:i}))}).fail(function(b){r(c,j),s(g);var e=a.Event("coursemoduleeditfailed",{exception:b,action:i});c.trigger(e),e.isDefaultPrevented()||d.exception(b)})},x=function(c,d,e){var f=o(c),g=b.call([{methodname:"core_course_get_module",args:{id:d,sectionreturn:e}}],!0);a.when.apply(a,g).done(function(a){r(c,f,400),C(a)}).fail(function(){r(c,f)})},y=function(a,b){var c=a.attr("class").match(/modtype_([^\s]*)/)[1],f=n(a);e.get_string("pluginname",c).done(function(a){var c={type:a,name:f};e.get_strings([{key:"confirm"},{key:null===f?"deletechecktype":"deletechecktypename",param:c},{key:"yes"},{key:"no"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],b)})})},z=function(a,b){e.get_strings([{key:"confirm"},{key:"yes"},{key:"no"}]).done(function(c){d.confirm(c[0],a,c[1],c[2],b)})},A=function(a,b,d,f,g,h,i){e.get_string(d,f).done(function(b){a.find("span.menu-action-text").html(b),a.attr("title",b)}),g?e.get_string(g,h).then(function(d){c.renderPix(b,"core",d).then(function(b){a.find(".icon").replaceWith(b)}),a.attr("title",d)}):c.renderPix(b,"core","").then(function(b){a.find(".icon").replaceWith(b)}),a.attr("data-action",i)},B=function(b,c,d,e){var f=c.attr("data-action");if("hide"===f||"show"===f){if("hide"===f?(b.addClass("hidden"),A(c,"i/show","showfromothers","format_"+e,null,null,"show")):(b.removeClass("hidden"),A(c,"i/hide","hidefromothers","format_"+e,null,null,"hide")),void 0!==d.modules)for(var g in d.modules)C(d.modules[g]);void 0!==d.section_availability&&b.find(".section_availability").first().replaceWith(d.section_availability)}else if("setmarker"===f){var h=a(l.SECTIONLI+".current"),i=h.find(l.SECTIONACTIONMENU+" a[data-action=removemarker]");h.removeClass("current"),A(i,"i/marker","highlight","core","markthistopic","core","setmarker"),b.addClass("current"),A(c,"i/marked","highlightoff","core","markedthistopic","core","removemarker")}else"removemarker"===f&&(b.removeClass("current"),A(c,"i/marker","highlight","core","markthistopic","core","setmarker"))},C=function(b){a("
"+b+"
").find(l.ACTIVITYLI).each(function(){var c=a(this).attr("id");a(l.ACTIVITYLI+"#"+c).replaceWith(b),t(c,!1)})},D=function(c,e,f,g){var h=f.attr("data-action"),i=f.attr("data-sectionreturn")?f.attr("data-sectionreturn"):0,j=p(c),k=b.call([{methodname:"core_course_edit_section",args:{id:e,action:h,sectionreturn:i}}],!0),m=q(c);a.when.apply(a,k).done(function(b){var d=a.parseJSON(b);r(c,j),s(m),c.find(l.SECTIONACTIONMENU).find(l.TOGGLE).focus();var e=a.Event("coursesectionedited",{ajaxreturn:d,action:h});c.trigger(e),e.isDefaultPrevented()||B(c,f,d,g)}).fail(function(b){r(c,j),s(m);var e=a.Event("coursesectioneditfailed",{exception:b,action:h});c.trigger(e),e.isDefaultPrevented()||d.exception(b)})};return g.use("moodle-course-coursebase",function(){M.course.coursebase.register_module({set_visibility_resource_ui:function(b){var c=a(b.element.getDOMNode()),d=m(c);if(d){var e=c.find("."+k.EDITINGMOVE).attr("data-sectionreturn");x(c,d,e)}}})}),{initCoursePage:function(b){a("body").on("click keypress",l.ACTIVITYLI+" "+l.ACTIVITYACTION+"[data-action]",function(b){if("keypress"!==b.type||13===b.keyCode){var c=a(this),d=c.closest(l.ACTIVITYLI),e=c.attr("data-action"),f=m(d);switch(e){case"moveleft":case"moveright":case"delete":case"duplicate":case"hide":case"stealth":case"show":case"groupsseparate":case"groupsvisible":case"groupsnone":break;default:return}f&&(b.preventDefault(),"delete"===e?y(d,function(){w(d,f,c)}):w(d,f,c))}}),a("body").on("click keypress",l.SECTIONLI+" "+l.SECTIONACTIONMENU+"[data-sectionid] a[data-action]",function(c){if("keypress"!==c.type||13===c.keyCode){var d=a(this),e=d.closest(l.SECTIONLI),f=d.closest(l.SECTIONACTIONMENU).attr("data-sectionid");c.preventDefault(),d.attr("data-confirm")?z(d.attr("data-confirm"),function(){D(e,f,d,b)}):D(e,f,d,b)}}),e.get_string("numberweeks").done(function(b){var c=a(l.ADDSECTIONS),d=c.attr("data-add-sections"),e=a('
');e.find("label").html(b),h.create({title:d,type:h.types.SAVE_CANCEL,body:e.html()},c).done(function(b){var e=a(b.getBody()).find("#add_section_numsections"),f=function(){""+parseInt(e.val())===e.val()&&parseInt(e.val())>=1&&(document.location=c.attr("href")+"&numsections="+parseInt(e.val()))};b.setSaveButtonText(d),b.getRoot().on(i.shown,function(){e.focus().select().on("keydown",function(a){a.keyCode===j.enter&&f()})}),b.getRoot().on(i.save,function(a){a.preventDefault(),f()})})})},replaceSectionActionItem:function(a,b,c,d,e,f,g,h){var i=a.find(l.SECTIONACTIONMENU+" "+b);A(i,c,d,e,f,g,h)}}}); \ No newline at end of file +define(["jquery","core/ajax","core/templates","core/notification","core/str","core/url","core/yui","core/modal_factory","core/modal_events","core/key_codes"],function(a,b,c,d,e,f,g,h,i,j){var k={EDITINPROGRESS:"editinprogress",SECTIONDRAGGABLE:"sectiondraggable",EDITINGMOVE:"editing_move"},l={ACTIVITYLI:"li.activity",ACTIONAREA:".actions",ACTIVITYACTION:"a.cm-edit-action",MENU:".moodle-actionmenu[data-enhance=moodle-core-actionmenu]",TOGGLE:".toggle-display,.dropdown-toggle",SECTIONLI:"li.section",SECTIONACTIONMENU:".section_action_menu",ADDSECTIONS:"#changenumsections [data-add-sections]"};g.use("moodle-course-coursebase",function(){var a=M.course.format.get_section_selector();a&&(l.SECTIONLI=a)});var m=function(a){var b;return g.use("moodle-course-util",function(c){b=c.Moodle.core_course.util.cm.getId(c.Node(a.get(0)))}),b},n=function(a){var b;return g.use("moodle-course-util",function(c){b=c.Moodle.core_course.util.cm.getName(c.Node(a.get(0)))}),b},o=function(a){a.addClass(k.EDITINPROGRESS);var b=a.find(l.ACTIONAREA).get(0);if(b){var c=M.util.add_spinner(g,g.Node(b));return c.show(),c}return null},p=function(a){a.addClass(k.EDITINPROGRESS);var b=a.find(l.SECTIONACTIONMENU).get(0);if(b){var c=M.util.add_spinner(g,g.Node(b));return c.show(),c}return null},q=function(a){var b=M.util.add_lightbox(g,g.Node(a.get(0)));return b.show(),b},r=function(a,b,c){window.setTimeout(function(){a.removeClass(k.EDITINPROGRESS),b&&b.hide()},c)},s=function(a,b){a&&window.setTimeout(function(){a.hide()},b)},t=function(a,b){if(g.use("moodle-course-coursebase",function(){M.course.coursebase.invoke_function("setup_for_resource","#"+a)}),M.core.actionmenu&&M.core.actionmenu.newDOMNode&&M.core.actionmenu.newDOMNode(g.one("#"+a)),b){var c=g.one("#"+a+" "+l.MENU).one(l.TOGGLE);c&&c.simulate&&c.simulate("click")}},u=function(b,c){var d=a("#"+b),e="[data-action="+c+"]";"groupsseparate"!==c&&"groupsvisible"!==c&&"groupsnone"!==c||(e="[data-action=groupsseparate],[data-action=groupsvisible],[data-action=groupsnone]"),d.find(e).is(":visible")?d.find(e).focus():d.find(l.MENU).find(l.TOGGLE).focus()},v=function(b){var c=a("a:visible"),d=!1,e=null;return c.each(function(){if(a.contains(b[0],this))d=!0;else if(d)return e=this,!1}),e},w=function(c,e,f){var g,h=f.attr("data-keepopen"),i=f.attr("data-action"),j=o(c),k=b.call([{methodname:"core_course_edit_module",args:{id:e,action:i,sectionreturn:f.attr("data-sectionreturn")?f.attr("data-sectionreturn"):0}}],!0);"duplicate"===i&&(g=q(f.closest(l.SECTIONLI))),a.when.apply(a,k).done(function(b){var d=v(c);c.replaceWith(b),a("
"+b+"
").find(l.ACTIVITYLI).each(function(b){t(a(this).attr("id"),h),0===b&&(u(a(this).attr("id"),i),d=null)}),d&&d.focus(),r(c,j,400),s(g,400),c.trigger(a.Event("coursemoduleedited",{ajaxreturn:b,action:i}))}).fail(function(b){r(c,j),s(g);var e=a.Event("coursemoduleeditfailed",{exception:b,action:i});c.trigger(e),e.isDefaultPrevented()||d.exception(b)})},x=function(c,d,e){var f=o(c),g=b.call([{methodname:"core_course_get_module",args:{id:d,sectionreturn:e}}],!0);a.when.apply(a,g).done(function(a){r(c,f,400),C(a)}).fail(function(){r(c,f)})},y=function(a,b){var c=a.attr("class").match(/modtype_([^\s]*)/)[1],f=n(a);e.get_string("pluginname",c).done(function(a){var c={type:a,name:f};e.get_strings([{key:"confirm"},{key:null===f?"deletechecktype":"deletechecktypename",param:c},{key:"yes"},{key:"no"}]).done(function(a){d.confirm(a[0],a[1],a[2],a[3],b)})})},z=function(a,b){e.get_strings([{key:"confirm"},{key:"yes"},{key:"no"}]).done(function(c){d.confirm(c[0],a,c[1],c[2],b)})},A=function(a,b,f,g,h,i,j){var k=[{key:f,component:g}];return h&&k.push({key:h,component:i}),e.get_strings(k).then(function(d){a.find("span.menu-action-text").html(d[0]),a.attr("title",d[0]);var e="";return h&&(e=d[1],a.attr("title",e)),c.renderPix(b,"core",e)}).then(function(b){a.find(".icon").replaceWith(b),a.attr("data-action",j)})["catch"](d.exception)},B=function(b,c,d,e){var f=c.attr("data-action");if("hide"===f||"show"===f){if("hide"===f?(b.addClass("hidden"),A(c,"i/show","showfromothers","format_"+e,null,null,"show")):(b.removeClass("hidden"),A(c,"i/hide","hidefromothers","format_"+e,null,null,"hide")),void 0!==d.modules)for(var g in d.modules)C(d.modules[g]);void 0!==d.section_availability&&b.find(".section_availability").first().replaceWith(d.section_availability)}else if("setmarker"===f){var h=a(l.SECTIONLI+".current"),i=h.find(l.SECTIONACTIONMENU+" a[data-action=removemarker]");h.removeClass("current"),A(i,"i/marker","highlight","core","markthistopic","core","setmarker"),b.addClass("current"),A(c,"i/marked","highlightoff","core","markedthistopic","core","removemarker")}else"removemarker"===f&&(b.removeClass("current"),A(c,"i/marker","highlight","core","markthistopic","core","setmarker"))},C=function(b){a("
"+b+"
").find(l.ACTIVITYLI).each(function(){var c=a(this).attr("id");a(l.ACTIVITYLI+"#"+c).replaceWith(b),t(c,!1)})},D=function(c,e,f,g){var h=f.attr("data-action"),i=f.attr("data-sectionreturn")?f.attr("data-sectionreturn"):0,j=p(c),k=b.call([{methodname:"core_course_edit_section",args:{id:e,action:h,sectionreturn:i}}],!0),m=q(c);a.when.apply(a,k).done(function(b){var d=a.parseJSON(b);r(c,j),s(m),c.find(l.SECTIONACTIONMENU).find(l.TOGGLE).focus();var e=a.Event("coursesectionedited",{ajaxreturn:d,action:h});c.trigger(e),e.isDefaultPrevented()||B(c,f,d,g)}).fail(function(b){r(c,j),s(m);var e=a.Event("coursesectioneditfailed",{exception:b,action:h});c.trigger(e),e.isDefaultPrevented()||d.exception(b)})};return g.use("moodle-course-coursebase",function(){M.course.coursebase.register_module({set_visibility_resource_ui:function(b){var c=a(b.element.getDOMNode()),d=m(c);if(d){var e=c.find("."+k.EDITINGMOVE).attr("data-sectionreturn");x(c,d,e)}}})}),{initCoursePage:function(b){a("body").on("click keypress",l.ACTIVITYLI+" "+l.ACTIVITYACTION+"[data-action]",function(b){if("keypress"!==b.type||13===b.keyCode){var c=a(this),d=c.closest(l.ACTIVITYLI),e=c.attr("data-action"),f=m(d);switch(e){case"moveleft":case"moveright":case"delete":case"duplicate":case"hide":case"stealth":case"show":case"groupsseparate":case"groupsvisible":case"groupsnone":break;default:return}f&&(b.preventDefault(),"delete"===e?y(d,function(){w(d,f,c)}):w(d,f,c))}}),a("body").on("click keypress",l.SECTIONLI+" "+l.SECTIONACTIONMENU+"[data-sectionid] a[data-action]",function(c){if("keypress"!==c.type||13===c.keyCode){var d=a(this),e=d.closest(l.SECTIONLI),f=d.closest(l.SECTIONACTIONMENU).attr("data-sectionid");c.preventDefault(),d.attr("data-confirm")?z(d.attr("data-confirm"),function(){D(e,f,d,b)}):D(e,f,d,b)}}),e.get_string("numberweeks").done(function(b){var c=a(l.ADDSECTIONS),d=c.attr("data-add-sections"),e=a('
');e.find("label").html(b),h.create({title:d,type:h.types.SAVE_CANCEL,body:e.html()},c).done(function(b){var e=a(b.getBody()).find("#add_section_numsections"),f=function(){""+parseInt(e.val())===e.val()&&parseInt(e.val())>=1&&(document.location=c.attr("href")+"&numsections="+parseInt(e.val()))};b.setSaveButtonText(d),b.getRoot().on(i.shown,function(){e.focus().select().on("keydown",function(a){a.keyCode===j.enter&&f()})}),b.getRoot().on(i.save,function(a){a.preventDefault(),f()})})})},replaceSectionActionItem:function(a,b,c,d,e,f,g,h){var i=a.find(l.SECTIONACTIONMENU+" "+b);A(i,c,d,e,f,g,h)}}}); \ No newline at end of file diff --git a/lib/amd/build/fragment.min.js b/lib/amd/build/fragment.min.js index 907a9050068..5a06600427a 100644 --- a/lib/amd/build/fragment.min.js +++ b/lib/amd/build/fragment.min.js @@ -1 +1 @@ -define(["jquery","core/ajax"],function(a,b){var c=function(c,d,e,f){var g=[];for(var h in f)g.push({name:h,value:f[h]});var i=a.Deferred(),j=b.call([{methodname:"core_get_fragment",args:{component:c,callback:d,contextid:e,args:g}}],!1);return j[0].done(function(a){i.resolve(a)}).fail(function(a){i.reject(a)}),i.promise()};return{loadFragment:function(b,d,e,f){var g=a.Deferred();return a.when(c(b,d,e,f)).then(function(b){var c=a(b.javascript),d="";c.each(function(b,c){c=a(c);var e=c.prop("tagName");if(e&&"script"==e.toLowerCase())if(c.attr("src")){var f=!1;a("script").each(function(b,d){return a(d).attr("src")==c.attr("src")&&(f=!0),!f}),f||(d+=" { ",d+=' node = document.createElement("script"); ',d+=' node.type = "text/javascript"; ',d+=' node.src = decodeURI("'+encodeURI(c.attr("src"))+'"); ',d+=' document.getElementsByTagName("head")[0].appendChild(node); ',d+=" } ")}else d+=" "+c.text()}),g.resolve(b.html,d)}).fail(function(a){g.reject(a)}),g.promise()}}}); \ No newline at end of file +define(["jquery","core/ajax"],function(a,b){var c=function(a,c,d,e){var f=[];for(var g in e)f.push({name:g,value:e[g]});return b.call([{methodname:"core_get_fragment",args:{component:a,callback:c,contextid:d,args:f}}])[0]};return{loadFragment:function(b,d,e,f){var g=a.Deferred();return c(b,d,e,f).then(function(b){var c=a(b.javascript),d="";c.each(function(b,c){c=a(c);var e=c.prop("tagName");if(e&&"script"==e.toLowerCase())if(c.attr("src")){var f=!1;a("script").each(function(b,d){return a(d).attr("src")==c.attr("src")&&(f=!0),!f}),f||(d+=" { ",d+=' node = document.createElement("script"); ',d+=' node.type = "text/javascript"; ',d+=' node.src = decodeURI("'+encodeURI(c.attr("src"))+'"); ',d+=' document.getElementsByTagName("head")[0].appendChild(node); ',d+=" } ")}else d+=" "+c.text()}),g.resolve(b.html,d)}).fail(function(a){g.reject(a)}),g.promise()}}}); \ No newline at end of file diff --git a/lib/amd/build/templates.min.js b/lib/amd/build/templates.min.js index d0d47f8cfc5..0036edc765e 100644 --- a/lib/amd/build/templates.min.js +++ b/lib/amd/build/templates.min.js @@ -1 +1 @@ -define(["core/mustache","jquery","core/ajax","core/str","core/notification","core/url","core/config","core/localstorage","core/icon_system","core/event","core/yui","core/log","core/truncate","core/user_date"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n){var o=0,p={},q={},r={},s=function(){this.requiredStrings=[],this.requiredJS=[],this.requiredDates=[],this.currentThemeName=""};s.prototype.requiredStrings=null,s.prototype.requiredDates=[],s.prototype.requiredJS=null,s.prototype.currentThemeName="",s.prototype.getTemplate=function(a){var d=a.split("/"),e=d.shift(),f=d.shift(),g=this.currentThemeName+"/"+a;if(g in q)return q[g];var i=h.get("core_template/"+g);if(i)return p[g]=i,q[g]=b.Deferred().resolve(i).promise(),q[g];var j=c.call([{methodname:"core_output_load_template",args:{component:e,template:f,themename:this.currentThemeName}}],!0,!1);return q[g]=j[0].then(function(a){return p[g]=a,h.set("core_template/"+g,a),a}),q[g]},s.prototype.partialHelper=function(a){var b=this.currentThemeName+"/"+a;return b in p||e.exception(new Error("Failed to pre-fetch the template: "+a)),p[b]},s.prototype.renderIcon=function(a,c,d){var e=g.iconsystemmodule,f=b.Deferred();return require([e],function(a){var b=new a;b instanceof i?(r=b,b.init().then(f.resolve)):f.reject("Invalid icon system specified"+g.iconsystemmodule)}),f.then(function(a){return this.getTemplate(a.getTemplateName())}.bind(this)).then(function(b){return r.renderIcon(a,c,d,b)})},s.prototype.pixHelper=function(a,b,c){var d=b.split(","),e="",f="",g="";d.length>0&&(e=c(d.shift().trim(),a)),d.length>0&&(f=c(d.shift().trim(),a)),d.length>0&&(g=c(d.join(",").trim(),a));var h=r.getTemplateName(),i=this.currentThemeName+"/"+h,j=p[i];return e=e.replace(///gi,"/"),r.renderIcon(e,f,g,j)},s.prototype.jsHelper=function(a,b,c){return this.requiredJS.push(c(b,a)),""},s.prototype.stringHelper=function(a,b,c){var d=b.split(","),e="",f="",g="";d.length>0&&(e=d.shift().trim()),d.length>0&&(f=d.shift().trim()),d.length>0&&(g=d.join(",").trim()),""!==g&&(g=c(g,a)),0===g.indexOf("{")&&0!==g.indexOf("{{")&&(g=JSON.parse(g));var h=this.requiredStrings.length;return this.requiredStrings.push({key:e,component:f,param:g}),"[[_s"+h+"]]"},s.prototype.quoteHelper=function(a,b,c){var d=c(b.trim(),a);return d=d.replace('"','\\"').replace(/([\{\}]{2,3})/g,"{{=<% %>=}}$1<%={{ }}=%>"),'"'+d+'"'},s.prototype.shortenTextHelper=function(a,b,c){var d=/(.*?),(.*)/,e=b.match(d),f=e[1].trim(),g=e[2].trim(),h=c(g,a);return m.truncate(h,{length:f,words:!0,ellipsis:"..."})},s.prototype.userDateHelper=function(a,b,c){var d=/(.*?),(.*)/,e=b.match(d),f=c(e[1].trim(),a),g=c(e[2].trim(),a),h=this.requiredDates.length;return this.requiredDates.push({timestamp:f,format:g}),"[[_t_"+h+"]]"},s.prototype.addHelpers=function(a,b){this.currentThemeName=b,this.requiredStrings=[],this.requiredJS=[],a.uniqid=o++,a.str=function(){return this.stringHelper.bind(this,a)}.bind(this),a.pix=function(){return this.pixHelper.bind(this,a)}.bind(this),a.js=function(){return this.jsHelper.bind(this,a)}.bind(this),a.quote=function(){return this.quoteHelper.bind(this,a)}.bind(this),a.shortentext=function(){return this.shortenTextHelper.bind(this,a)}.bind(this),a.userdate=function(){return this.userDateHelper.bind(this,a)}.bind(this),a.globals={config:g},a.currentTheme=b},s.prototype.getJS=function(){var a="";return this.requiredJS.length>0&&(a=this.requiredJS.join(";\n")),a},s.prototype.treatStringsInContent=function(a,b){var c,d,e,f,g,h,i=/\[\[_s\d+\]\]/;do{for(c="",d=a.search(i);d>-1;){c+=a.substring(0,d),a=a.substr(d),e="",f=4,g=a.substr(f,1);do e+=g,f++,g=a.substr(f,1);while("]"!=g);h=b[parseInt(e,10)],"undefined"==typeof h&&(l.debug("Could not find string for pattern [[_s"+e+"]]."),h=""),c+=h,a=a.substr(6+e.length),d=a.search(i)}a=c+a,d=a.search(i)}while(d>-1);return a},s.prototype.treatDatesInContent=function(a,b){return b.forEach(function(b,c){var d="\\[\\[_t_"+c+"\\]\\]",e=new RegExp(d,"g");a=a.replace(e,b)}),a},s.prototype.doRender=function(c,e,f){this.currentThemeName=f;var g=r.getTemplateName();return this.getTemplate(g).then(function(){this.addHelpers(e,f);var d=a.render(c,e,this.partialHelper.bind(this));return b.Deferred().resolve(d.trim(),this.getJS()).promise()}.bind(this)).then(function(a,c){return this.requiredStrings.length>0?d.get_strings(this.requiredStrings).then(function(d){return this.requiredDates=this.requiredDates.map(function(a){return{timestamp:this.treatStringsInContent(a.timestamp,d),format:this.treatStringsInContent(a.format,d)}}.bind(this)),a=this.treatStringsInContent(a,d),c=this.treatStringsInContent(c,d),b.Deferred().resolve(a,c).promise()}.bind(this)):b.Deferred().resolve(a,c).promise()}.bind(this)).then(function(a,c){return this.requiredDates.length>0?n.get(this.requiredDates).then(function(d){return a=this.treatDatesInContent(a,d),c=this.treatDatesInContent(c,d),b.Deferred().resolve(a,c).promise()}.bind(this)):b.Deferred().resolve(a,c).promise()}.bind(this))};var t=function(a){if(""!==a.trim()){var c=b("