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); }; /**