diff --git a/admin/tool/usertours/amd/build/usertours.min.js b/admin/tool/usertours/amd/build/usertours.min.js index 6895e7573f0..6b16a51a322 100644 --- a/admin/tool/usertours/amd/build/usertours.min.js +++ b/admin/tool/usertours/amd/build/usertours.min.js @@ -1,2 +1,2 @@ -define ("tool_usertours/usertours",["core/ajax","tool_usertours/tour","jquery","core/templates","core/str","core/log","core/notification"],function(a,b,c,d,e,f,g){var h={tourId:null,currentTour:null,context:null,init:function init(a,b,d){h.tourId=a;h.context=d;if("undefined"==typeof b){b=!0}if(b){h.fetchTour(a)}h.addResetLink();c("body").on("click","[data-action=\"tool_usertours/resetpagetour\"]",function(a){a.preventDefault();h.resetTourState(h.tourId)})},fetchTour:function fetchTour(b){M.util.js_pending("admin_usertour_fetchTour"+b);c.when(a.call([{methodname:"tool_usertours_fetch_and_start_tour",args:{tourid:b,context:h.context,pageurl:window.location.href}}])[0],d.render("tool_usertours/tourstep",{})).then(function(a,c){return h.startBootstrapTour(b,c[0],a.tourconfig)}).always(function(){M.util.js_complete("admin_usertour_fetchTour"+b)}).fail(g.exception)},addResetLink:function addResetLink(){var a;M.util.js_pending("admin_usertour_addResetLink");if(c(".tool_usertours-resettourcontainer").length){a=c(".tool_usertours-resettourcontainer")}else if(c(".logininfo").length){a=c(".logininfo")}else if(c("footer").length){a=c("footer")}else{a=c("body")}d.render("tool_usertours/resettour",{}).then(function(b,c){d.appendNodeContents(a,b,c)}).always(function(){M.util.js_complete("admin_usertour_addResetLink")}).fail()},startBootstrapTour:function startBootstrapTour(a,c,d){if(h.currentTour){d.onEnd=null;h.currentTour.endTour();delete h.currentTour}d.eventHandlers={afterEnd:[h.markTourComplete],afterRender:[h.markStepShown]};d.tourName=d.name;delete d.name;d.template=c;d.steps=d.steps.map(function(a){if("undefined"!=typeof a.element){a.target=a.element;delete a.element}if("undefined"!=typeof a.reflex){a.moveOnClick=!!a.reflex;delete a.reflex}if("undefined"!=typeof a.content){a.body=a.content;delete a.content}return a});h.currentTour=new b(d);return h.currentTour.startTour()},markStepShown:function markStepShown(){var b=this.getStepConfig(this.getCurrentStepNumber());c.when(a.call([{methodname:"tool_usertours_step_shown",args:{tourid:h.tourId,context:h.context,pageurl:window.location.href,stepid:b.stepid,stepindex:this.getCurrentStepNumber()}}])[0]).fail(f.error)},markTourComplete:function markTourComplete(){var b=this.getStepConfig(this.getCurrentStepNumber());c.when(a.call([{methodname:"tool_usertours_complete_tour",args:{tourid:h.tourId,context:h.context,pageurl:window.location.href,stepid:b.stepid,stepindex:this.getCurrentStepNumber()}}])[0]).fail(f.error)},resetTourState:function resetTourState(b){c.when(a.call([{methodname:"tool_usertours_reset_tour",args:{tourid:b,context:h.context,pageurl:window.location.href}}])[0]).then(function(a){if(a.startTour){h.fetchTour(a.startTour)}}).fail(g.exception)}};return{init:h.init,resetTourState:h.resetTourState}}); +define ("tool_usertours/usertours",["core/ajax","tool_usertours/tour","jquery","core/templates","core/str","core/log","core/notification"],function(a,b,c,d,e,f,g){var h={tourId:null,currentTour:null,context:null,init:function init(a,b,d){h.tourId=a;h.context=d;if("undefined"==typeof b){b=!0}if(b){h.fetchTour(a)}h.addResetLink();c("body").on("click","[data-action=\"tool_usertours/resetpagetour\"]",function(a){a.preventDefault();h.resetTourState(h.tourId)})},fetchTour:function fetchTour(b){M.util.js_pending("admin_usertour_fetchTour"+b);c.when(a.call([{methodname:"tool_usertours_fetch_and_start_tour",args:{tourid:b,context:h.context,pageurl:window.location.href}}])[0],d.render("tool_usertours/tourstep",{})).then(function(a,c){if(!a.hasOwnProperty("tourconfig")){return}return h.startBootstrapTour(b,c[0],a.tourconfig)}).always(function(){M.util.js_complete("admin_usertour_fetchTour"+b)}).fail(g.exception)},addResetLink:function addResetLink(){var a;M.util.js_pending("admin_usertour_addResetLink");if(c(".tool_usertours-resettourcontainer").length){a=c(".tool_usertours-resettourcontainer")}else if(c(".logininfo").length){a=c(".logininfo")}else if(c("footer").length){a=c("footer")}else{a=c("body")}d.render("tool_usertours/resettour",{}).then(function(b,c){d.appendNodeContents(a,b,c)}).always(function(){M.util.js_complete("admin_usertour_addResetLink")}).fail()},startBootstrapTour:function startBootstrapTour(a,c,d){if(h.currentTour){d.onEnd=null;h.currentTour.endTour();delete h.currentTour}d.eventHandlers={afterEnd:[h.markTourComplete],afterRender:[h.markStepShown]};d.tourName=d.name;delete d.name;d.template=c;d.steps=d.steps.map(function(a){if("undefined"!=typeof a.element){a.target=a.element;delete a.element}if("undefined"!=typeof a.reflex){a.moveOnClick=!!a.reflex;delete a.reflex}if("undefined"!=typeof a.content){a.body=a.content;delete a.content}return a});h.currentTour=new b(d);return h.currentTour.startTour()},markStepShown:function markStepShown(){var b=this.getStepConfig(this.getCurrentStepNumber());c.when(a.call([{methodname:"tool_usertours_step_shown",args:{tourid:h.tourId,context:h.context,pageurl:window.location.href,stepid:b.stepid,stepindex:this.getCurrentStepNumber()}}])[0]).fail(f.error)},markTourComplete:function markTourComplete(){var b=this.getStepConfig(this.getCurrentStepNumber());c.when(a.call([{methodname:"tool_usertours_complete_tour",args:{tourid:h.tourId,context:h.context,pageurl:window.location.href,stepid:b.stepid,stepindex:this.getCurrentStepNumber()}}])[0]).fail(f.error)},resetTourState:function resetTourState(b){c.when(a.call([{methodname:"tool_usertours_reset_tour",args:{tourid:b,context:h.context,pageurl:window.location.href}}])[0]).then(function(a){if(a.startTour){h.fetchTour(a.startTour)}}).fail(g.exception)}};return{init:h.init,resetTourState:h.resetTourState}}); //# sourceMappingURL=usertours.min.js.map diff --git a/admin/tool/usertours/amd/build/usertours.min.js.map b/admin/tool/usertours/amd/build/usertours.min.js.map index ebfcda00914..9f614add864 100644 --- a/admin/tool/usertours/amd/build/usertours.min.js.map +++ b/admin/tool/usertours/amd/build/usertours.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/usertours.js"],"names":["define","ajax","BootstrapTour","$","templates","str","log","notification","usertours","tourId","currentTour","context","init","startTour","fetchTour","addResetLink","on","e","preventDefault","resetTourState","M","util","js_pending","when","call","methodname","args","tourid","pageurl","window","location","href","render","then","response","template","startBootstrapTour","tourconfig","always","js_complete","fail","exception","ele","length","html","js","appendNodeContents","tourConfig","onEnd","endTour","eventHandlers","afterEnd","markTourComplete","afterRender","markStepShown","tourName","name","steps","map","step","element","target","reflex","moveOnClick","content","body","stepConfig","getStepConfig","getCurrentStepNumber","stepid","stepindex","error"],"mappings":"AAQAA,OAAM,4BACN,CAAC,WAAD,CAAc,qBAAd,CAAqC,QAArC,CAA+C,gBAA/C,CAAiE,UAAjE,CAA6E,UAA7E,CAAyF,mBAAzF,CADM,CAEN,SAASC,CAAT,CAAeC,CAAf,CAA8BC,CAA9B,CAAiCC,CAAjC,CAA4CC,CAA5C,CAAiDC,CAAjD,CAAsDC,CAAtD,CAAoE,CAChE,GAAIC,CAAAA,CAAS,CAAG,CACZC,MAAM,CAAE,IADI,CAGZC,WAAW,CAAE,IAHD,CAKZC,OAAO,CAAE,IALG,CAeZC,IAAI,CAAE,cAASH,CAAT,CAAiBI,CAAjB,CAA4BF,CAA5B,CAAqC,CAEvCH,CAAS,CAACC,MAAV,CAAmBA,CAAnB,CAEAD,CAAS,CAACG,OAAV,CAAoBA,CAApB,CAEA,GAAyB,WAArB,QAAOE,CAAAA,CAAX,CAAsC,CAClCA,CAAS,GACZ,CAED,GAAIA,CAAJ,CAAe,CAEXL,CAAS,CAACM,SAAV,CAAoBL,CAApB,CACH,CAEDD,CAAS,CAACO,YAAV,GAEAZ,CAAC,CAAC,MAAD,CAAD,CAAUa,EAAV,CAAa,OAAb,CAAsB,gDAAtB,CAAsE,SAASC,CAAT,CAAY,CAC9EA,CAAC,CAACC,cAAF,GACAV,CAAS,CAACW,cAAV,CAAyBX,CAAS,CAACC,MAAnC,CACH,CAHD,CAIH,CApCW,CA4CZK,SAAS,CAAE,mBAASL,CAAT,CAAiB,CACxBW,CAAC,CAACC,IAAF,CAAOC,UAAP,CAAkB,2BAA6Bb,CAA/C,EACAN,CAAC,CAACoB,IAAF,CACItB,CAAI,CAACuB,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,CADJ,EAaE5B,IAbF,CAaOlC,CAAG,CAACiE,KAbX,CAcH,CA3MW,CAmNZpD,cAAc,CAAE,wBAASV,CAAT,CAAiB,CAC7BN,CAAC,CAACoB,IAAF,CACItB,CAAI,CAACuB,IAAL,CAAU,CACN,CACIC,UAAU,CAAE,2BADhB,CAEIC,IAAI,CAAE,CACFC,MAAM,CAAMlB,CADV,CAEFE,OAAO,CAAKH,CAAS,CAACG,OAFpB,CAGFiB,OAAO,CAAKC,MAAM,CAACC,QAAP,CAAgBC,IAH1B,CAFV,CADM,CAAV,EASG,CATH,CADJ,EAWEE,IAXF,CAWO,SAASC,CAAT,CAAmB,CACtB,GAAIA,CAAQ,CAACrB,SAAb,CAAwB,CACpBL,CAAS,CAACM,SAAV,CAAoBoB,CAAQ,CAACrB,SAA7B,CACH,CAEJ,CAhBD,EAgBG2B,IAhBH,CAgBQjC,CAAY,CAACkC,SAhBrB,CAiBH,CArOW,CAAhB,CAwOA,MAAqD,CAQjD7B,IAAI,CAAEJ,CAAS,CAACI,IARiC,CAgBjDO,cAAc,CAAEX,CAAS,CAACW,cAhBuB,CAkBxD,CA7PK,CAAN","sourcesContent":["/**\n * User tour control library.\n *\n * @module tool_usertours/usertours\n * @class usertours\n * @package tool_usertours\n * @copyright 2016 Andrew Nicols \n */\ndefine(\n['core/ajax', 'tool_usertours/tour', 'jquery', 'core/templates', 'core/str', 'core/log', 'core/notification'],\nfunction(ajax, BootstrapTour, $, templates, str, log, notification) {\n var usertours = {\n tourId: null,\n\n currentTour: null,\n\n context: null,\n\n /**\n * Initialise the user tour for the current page.\n *\n * @method init\n * @param {Number} tourId The ID of the tour to start.\n * @param {Bool} startTour Attempt to start the tour now.\n * @param {Number} context The context of the current page.\n */\n init: function(tourId, startTour, context) {\n // Only one tour per page is allowed.\n usertours.tourId = tourId;\n\n usertours.context = context;\n\n if (typeof startTour === 'undefined') {\n startTour = true;\n }\n\n if (startTour) {\n // Fetch the tour configuration.\n usertours.fetchTour(tourId);\n }\n\n usertours.addResetLink();\n // Watch for the reset link.\n $('body').on('click', '[data-action=\"tool_usertours/resetpagetour\"]', function(e) {\n e.preventDefault();\n usertours.resetTourState(usertours.tourId);\n });\n },\n\n /**\n * Fetch the configuration specified tour, and start the tour when it has been fetched.\n *\n * @method fetchTour\n * @param {Number} tourId The ID of the tour to start.\n */\n fetchTour: function(tourId) {\n M.util.js_pending('admin_usertour_fetchTour' + tourId);\n $.when(\n ajax.call([\n {\n methodname: 'tool_usertours_fetch_and_start_tour',\n args: {\n tourid: tourId,\n context: usertours.context,\n pageurl: window.location.href,\n }\n }\n ])[0],\n templates.render('tool_usertours/tourstep', {})\n )\n .then(function(response, template) {\n return usertours.startBootstrapTour(tourId, template[0], response.tourconfig);\n })\n .always(function() {\n M.util.js_complete('admin_usertour_fetchTour' + tourId);\n\n return;\n })\n .fail(notification.exception);\n },\n\n /**\n * Add a reset link to the page.\n *\n * @method addResetLink\n */\n addResetLink: function() {\n var ele;\n M.util.js_pending('admin_usertour_addResetLink');\n\n // Append the link to the most suitable place on the page\n // with fallback to legacy selectors and finally the body\n // if there is no better place.\n if ($('.tool_usertours-resettourcontainer').length) {\n ele = $('.tool_usertours-resettourcontainer');\n } else if ($('.logininfo').length) {\n ele = $('.logininfo');\n } else if ($('footer').length) {\n ele = $('footer');\n } else {\n ele = $('body');\n }\n templates.render('tool_usertours/resettour', {})\n .then(function(html, js) {\n templates.appendNodeContents(ele, html, js);\n\n return;\n })\n .always(function() {\n M.util.js_complete('admin_usertour_addResetLink');\n\n return;\n })\n .fail();\n },\n\n /**\n * Start the specified tour.\n *\n * @method startBootstrapTour\n * @param {Number} tourId The ID of the tour to start.\n * @param {String} template The template to use.\n * @param {Object} tourConfig The tour configuration.\n * @return {Object}\n */\n startBootstrapTour: function(tourId, template, tourConfig) {\n if (usertours.currentTour) {\n // End the current tour, but disable end tour handler.\n tourConfig.onEnd = null;\n usertours.currentTour.endTour();\n delete usertours.currentTour;\n }\n\n // Normalize for the new library.\n tourConfig.eventHandlers = {\n afterEnd: [usertours.markTourComplete],\n afterRender: [usertours.markStepShown],\n };\n\n // Sort out the tour name.\n tourConfig.tourName = tourConfig.name;\n delete tourConfig.name;\n\n // Add the template to the configuration.\n // This enables translations of the buttons.\n tourConfig.template = template;\n\n tourConfig.steps = tourConfig.steps.map(function(step) {\n if (typeof step.element !== 'undefined') {\n step.target = step.element;\n delete step.element;\n }\n\n if (typeof step.reflex !== 'undefined') {\n step.moveOnClick = !!step.reflex;\n delete step.reflex;\n }\n\n if (typeof step.content !== 'undefined') {\n step.body = step.content;\n delete step.content;\n }\n\n return step;\n });\n\n usertours.currentTour = new BootstrapTour(tourConfig);\n return usertours.currentTour.startTour();\n },\n\n /**\n * Mark the specified step as being shownd by the user.\n *\n * @method markStepShown\n */\n markStepShown: function() {\n var stepConfig = this.getStepConfig(this.getCurrentStepNumber());\n $.when(\n ajax.call([\n {\n methodname: 'tool_usertours_step_shown',\n args: {\n tourid: usertours.tourId,\n context: usertours.context,\n pageurl: window.location.href,\n stepid: stepConfig.stepid,\n stepindex: this.getCurrentStepNumber(),\n }\n }\n ])[0]\n ).fail(log.error);\n },\n\n /**\n * Mark the specified tour as being completed by the user.\n *\n * @method markTourComplete\n */\n markTourComplete: function() {\n var stepConfig = this.getStepConfig(this.getCurrentStepNumber());\n $.when(\n ajax.call([\n {\n methodname: 'tool_usertours_complete_tour',\n args: {\n tourid: usertours.tourId,\n context: usertours.context,\n pageurl: window.location.href,\n stepid: stepConfig.stepid,\n stepindex: this.getCurrentStepNumber(),\n }\n }\n ])[0]\n ).fail(log.error);\n },\n\n /**\n * Reset the state, and restart the the tour on the current page.\n *\n * @method resetTourState\n * @param {Number} tourId The ID of the tour to start.\n */\n resetTourState: function(tourId) {\n $.when(\n ajax.call([\n {\n methodname: 'tool_usertours_reset_tour',\n args: {\n tourid: tourId,\n context: usertours.context,\n pageurl: window.location.href,\n }\n }\n ])[0]\n ).then(function(response) {\n if (response.startTour) {\n usertours.fetchTour(response.startTour);\n }\n return;\n }).fail(notification.exception);\n }\n };\n\n return /** @alias module:tool_usertours/usertours */ {\n /**\n * Initialise the user tour for the current page.\n *\n * @method init\n * @param {Number} tourId The ID of the tour to start.\n * @param {Bool} startTour Attempt to start the tour now.\n */\n init: usertours.init,\n\n /**\n * Reset the state, and restart the the tour on the current page.\n *\n * @method resetTourState\n * @param {Number} tourId The ID of the tour to restart.\n */\n resetTourState: usertours.resetTourState\n };\n});\n"],"file":"usertours.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/usertours.js"],"names":["define","ajax","BootstrapTour","$","templates","str","log","notification","usertours","tourId","currentTour","context","init","startTour","fetchTour","addResetLink","on","e","preventDefault","resetTourState","M","util","js_pending","when","call","methodname","args","tourid","pageurl","window","location","href","render","then","response","template","hasOwnProperty","startBootstrapTour","tourconfig","always","js_complete","fail","exception","ele","length","html","js","appendNodeContents","tourConfig","onEnd","endTour","eventHandlers","afterEnd","markTourComplete","afterRender","markStepShown","tourName","name","steps","map","step","element","target","reflex","moveOnClick","content","body","stepConfig","getStepConfig","getCurrentStepNumber","stepid","stepindex","error"],"mappings":"AAQAA,OAAM,4BACN,CAAC,WAAD,CAAc,qBAAd,CAAqC,QAArC,CAA+C,gBAA/C,CAAiE,UAAjE,CAA6E,UAA7E,CAAyF,mBAAzF,CADM,CAEN,SAASC,CAAT,CAAeC,CAAf,CAA8BC,CAA9B,CAAiCC,CAAjC,CAA4CC,CAA5C,CAAiDC,CAAjD,CAAsDC,CAAtD,CAAoE,CAChE,GAAIC,CAAAA,CAAS,CAAG,CACZC,MAAM,CAAE,IADI,CAGZC,WAAW,CAAE,IAHD,CAKZC,OAAO,CAAE,IALG,CAeZC,IAAI,CAAE,cAASH,CAAT,CAAiBI,CAAjB,CAA4BF,CAA5B,CAAqC,CAEvCH,CAAS,CAACC,MAAV,CAAmBA,CAAnB,CAEAD,CAAS,CAACG,OAAV,CAAoBA,CAApB,CAEA,GAAyB,WAArB,QAAOE,CAAAA,CAAX,CAAsC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uB,CAkBxD,CAlQK,CAAN","sourcesContent":["/**\n * User tour control library.\n *\n * @module tool_usertours/usertours\n * @class usertours\n * @package tool_usertours\n * @copyright 2016 Andrew Nicols \n */\ndefine(\n['core/ajax', 'tool_usertours/tour', 'jquery', 'core/templates', 'core/str', 'core/log', 'core/notification'],\nfunction(ajax, BootstrapTour, $, templates, str, log, notification) {\n var usertours = {\n tourId: null,\n\n currentTour: null,\n\n context: null,\n\n /**\n * Initialise the user tour for the current page.\n *\n * @method init\n * @param {Number} tourId The ID of the tour to start.\n * @param {Bool} startTour Attempt to start the tour now.\n * @param {Number} context The context of the current page.\n */\n init: function(tourId, startTour, context) {\n // Only one tour per page is allowed.\n usertours.tourId = tourId;\n\n usertours.context = context;\n\n if (typeof startTour === 'undefined') {\n startTour = true;\n }\n\n if (startTour) {\n // Fetch the tour configuration.\n usertours.fetchTour(tourId);\n }\n\n usertours.addResetLink();\n // Watch for the reset link.\n $('body').on('click', '[data-action=\"tool_usertours/resetpagetour\"]', function(e) {\n e.preventDefault();\n usertours.resetTourState(usertours.tourId);\n });\n },\n\n /**\n * Fetch the configuration specified tour, and start the tour when it has been fetched.\n *\n * @method fetchTour\n * @param {Number} tourId The ID of the tour to start.\n */\n fetchTour: function(tourId) {\n M.util.js_pending('admin_usertour_fetchTour' + tourId);\n $.when(\n ajax.call([\n {\n methodname: 'tool_usertours_fetch_and_start_tour',\n args: {\n tourid: tourId,\n context: usertours.context,\n pageurl: window.location.href,\n }\n }\n ])[0],\n templates.render('tool_usertours/tourstep', {})\n )\n .then(function(response, template) {\n // If we don't have any tour config (because it doesn't need showing for the current user), return early.\n if (!response.hasOwnProperty('tourconfig')) {\n return;\n }\n\n return usertours.startBootstrapTour(tourId, template[0], response.tourconfig);\n })\n .always(function() {\n M.util.js_complete('admin_usertour_fetchTour' + tourId);\n\n return;\n })\n .fail(notification.exception);\n },\n\n /**\n * Add a reset link to the page.\n *\n * @method addResetLink\n */\n addResetLink: function() {\n var ele;\n M.util.js_pending('admin_usertour_addResetLink');\n\n // Append the link to the most suitable place on the page\n // with fallback to legacy selectors and finally the body\n // if there is no better place.\n if ($('.tool_usertours-resettourcontainer').length) {\n ele = $('.tool_usertours-resettourcontainer');\n } else if ($('.logininfo').length) {\n ele = $('.logininfo');\n } else if ($('footer').length) {\n ele = $('footer');\n } else {\n ele = $('body');\n }\n templates.render('tool_usertours/resettour', {})\n .then(function(html, js) {\n templates.appendNodeContents(ele, html, js);\n\n return;\n })\n .always(function() {\n M.util.js_complete('admin_usertour_addResetLink');\n\n return;\n })\n .fail();\n },\n\n /**\n * Start the specified tour.\n *\n * @method startBootstrapTour\n * @param {Number} tourId The ID of the tour to start.\n * @param {String} template The template to use.\n * @param {Object} tourConfig The tour configuration.\n * @return {Object}\n */\n startBootstrapTour: function(tourId, template, tourConfig) {\n if (usertours.currentTour) {\n // End the current tour, but disable end tour handler.\n tourConfig.onEnd = null;\n usertours.currentTour.endTour();\n delete usertours.currentTour;\n }\n\n // Normalize for the new library.\n tourConfig.eventHandlers = {\n afterEnd: [usertours.markTourComplete],\n afterRender: [usertours.markStepShown],\n };\n\n // Sort out the tour name.\n tourConfig.tourName = tourConfig.name;\n delete tourConfig.name;\n\n // Add the template to the configuration.\n // This enables translations of the buttons.\n tourConfig.template = template;\n\n tourConfig.steps = tourConfig.steps.map(function(step) {\n if (typeof step.element !== 'undefined') {\n step.target = step.element;\n delete step.element;\n }\n\n if (typeof step.reflex !== 'undefined') {\n step.moveOnClick = !!step.reflex;\n delete step.reflex;\n }\n\n if (typeof step.content !== 'undefined') {\n step.body = step.content;\n delete step.content;\n }\n\n return step;\n });\n\n usertours.currentTour = new BootstrapTour(tourConfig);\n return usertours.currentTour.startTour();\n },\n\n /**\n * Mark the specified step as being shownd by the user.\n *\n * @method markStepShown\n */\n markStepShown: function() {\n var stepConfig = this.getStepConfig(this.getCurrentStepNumber());\n $.when(\n ajax.call([\n {\n methodname: 'tool_usertours_step_shown',\n args: {\n tourid: usertours.tourId,\n context: usertours.context,\n pageurl: window.location.href,\n stepid: stepConfig.stepid,\n stepindex: this.getCurrentStepNumber(),\n }\n }\n ])[0]\n ).fail(log.error);\n },\n\n /**\n * Mark the specified tour as being completed by the user.\n *\n * @method markTourComplete\n */\n markTourComplete: function() {\n var stepConfig = this.getStepConfig(this.getCurrentStepNumber());\n $.when(\n ajax.call([\n {\n methodname: 'tool_usertours_complete_tour',\n args: {\n tourid: usertours.tourId,\n context: usertours.context,\n pageurl: window.location.href,\n stepid: stepConfig.stepid,\n stepindex: this.getCurrentStepNumber(),\n }\n }\n ])[0]\n ).fail(log.error);\n },\n\n /**\n * Reset the state, and restart the the tour on the current page.\n *\n * @method resetTourState\n * @param {Number} tourId The ID of the tour to start.\n */\n resetTourState: function(tourId) {\n $.when(\n ajax.call([\n {\n methodname: 'tool_usertours_reset_tour',\n args: {\n tourid: tourId,\n context: usertours.context,\n pageurl: window.location.href,\n }\n }\n ])[0]\n ).then(function(response) {\n if (response.startTour) {\n usertours.fetchTour(response.startTour);\n }\n return;\n }).fail(notification.exception);\n }\n };\n\n return /** @alias module:tool_usertours/usertours */ {\n /**\n * Initialise the user tour for the current page.\n *\n * @method init\n * @param {Number} tourId The ID of the tour to start.\n * @param {Bool} startTour Attempt to start the tour now.\n */\n init: usertours.init,\n\n /**\n * Reset the state, and restart the the tour on the current page.\n *\n * @method resetTourState\n * @param {Number} tourId The ID of the tour to restart.\n */\n resetTourState: usertours.resetTourState\n };\n});\n"],"file":"usertours.min.js"} \ No newline at end of file diff --git a/admin/tool/usertours/amd/src/usertours.js b/admin/tool/usertours/amd/src/usertours.js index 70bd0579b9b..4bb10506169 100644 --- a/admin/tool/usertours/amd/src/usertours.js +++ b/admin/tool/usertours/amd/src/usertours.js @@ -69,6 +69,11 @@ function(ajax, BootstrapTour, $, templates, str, log, notification) { templates.render('tool_usertours/tourstep', {}) ) .then(function(response, template) { + // If we don't have any tour config (because it doesn't need showing for the current user), return early. + if (!response.hasOwnProperty('tourconfig')) { + return; + } + return usertours.startBootstrapTour(tourId, template[0], response.tourconfig); }) .always(function() { diff --git a/admin/tool/usertours/classes/external/tour.php b/admin/tool/usertours/classes/external/tour.php index d24c684cce2..c16c5a015ee 100644 --- a/admin/tool/usertours/classes/external/tour.php +++ b/admin/tool/usertours/classes/external/tour.php @@ -70,9 +70,9 @@ class tour extends external_api { \tool_usertours\event\tour_started::create([ 'contextid' => $context->id, - 'objectid' => $tourid, + 'objectid' => $tour->get_id(), 'other' => [ - 'pageurl' => $pageurl, + 'pageurl' => $params['pageurl'], ], ])->trigger(); @@ -104,7 +104,7 @@ class tour extends external_api { 'tourconfig' => new external_single_structure([ 'name' => new external_value(PARAM_RAW, 'Tour Name'), 'steps' => new external_multiple_structure(self::step_structure_returns()), - ]) + ], 'Tour config', VALUE_OPTIONAL) ]); } diff --git a/admin/tool/usertours/upgrade.txt b/admin/tool/usertours/upgrade.txt index c123bd40b85..cf5ddbabb1c 100644 --- a/admin/tool/usertours/upgrade.txt +++ b/admin/tool/usertours/upgrade.txt @@ -1,4 +1,9 @@ This files describes API changes in the tool_usertours code. +=== 3.9 === +* The `tourconfig` property returned by the `tool_usertours_fetch_and_start_tour` + external method is now optional, and will be omitted if the tour shouldn't be + shown to the current user + === 3.5 === * Third party library Popper.js was moved from this plugin into core (core/popper)