Skip to content

Commit

Permalink
MDL-61234 tool_usertours: Wrap library calls in pendingjs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jan 19, 2018
1 parent f68150a commit 64c9b40
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion admin/tool/usertours/amd/build/usertours.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 25 additions & 7 deletions admin/tool/usertours/amd/src/usertours.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function(ajax, BootstrapTour, $, templates, str, log, notification) {
* @param {Number} tourId The ID of the tour to start.
*/
fetchTour: function(tourId) {
M.util.js_pending('admin_usertour_fetchTour' + tourId);
$.when(
ajax.call([
{
Expand All @@ -66,10 +67,16 @@ function(ajax, BootstrapTour, $, templates, str, log, notification) {
}
])[0],
templates.render('tool_usertours/tourstep', {})
).then(function(response, template) {
usertours.startBootstrapTour(tourId, template[0], response.tourconfig);
)
.then(function(response, template) {
return usertours.startBootstrapTour(tourId, template[0], response.tourconfig);
})
.always(function() {
M.util.js_complete('admin_usertour_fetchTour' + tourId);

return;
}).fail(notification.exception);
})
.fail(notification.exception);
},

/**
Expand All @@ -79,6 +86,8 @@ function(ajax, BootstrapTour, $, templates, str, log, notification) {
*/
addResetLink: function() {
var ele;
M.util.js_pending('admin_usertour_addResetLink');

// Append the link to the most suitable place on the page
// with fallback to legacy selectors and finally the body
// if there is no better place.
Expand All @@ -92,9 +101,17 @@ function(ajax, BootstrapTour, $, templates, str, log, notification) {
ele = $('body');
}
templates.render('tool_usertours/resettour', {})
.done(function(html, js) {
templates.appendNodeContents(ele, html, js);
});
.then(function(html, js) {
templates.appendNodeContents(ele, html, js);

return;
})
.always(function() {
M.util.js_complete('admin_usertour_addResetLink');

return;
})
.fail();
},

/**
Expand All @@ -104,6 +121,7 @@ function(ajax, BootstrapTour, $, templates, str, log, notification) {
* @param {Number} tourId The ID of the tour to start.
* @param {String} template The template to use.
* @param {Object} tourConfig The tour configuration.
* @return {Object}
*/
startBootstrapTour: function(tourId, template, tourConfig) {
if (usertours.currentTour) {
Expand Down Expand Up @@ -147,7 +165,7 @@ function(ajax, BootstrapTour, $, templates, str, log, notification) {
});

usertours.currentTour = new BootstrapTour(tourConfig);
usertours.currentTour.startTour();
return usertours.currentTour.startTour();
},

/**
Expand Down

0 comments on commit 64c9b40

Please sign in to comment.