admin/tool/usertours/amd/src/repository.js

  1. /**
  2. * Javascript module to handle tool_usertour AJAX requests.
  3. *
  4. * @module tool_usertours/repository
  5. * @copyright 2016 Andrew Nicols <andrew@nicols.co.uk>
  6. */
  7. import {call as fetchMany} from 'core/ajax';
  8. import moodleConfig from 'core/config';
  9. /**
  10. * Reset the tour state of the specified tour.
  11. *
  12. * @param {number} tourid
  13. * @return {Promise}
  14. */
  15. export const resetTourState = tourid => fetchMany([{
  16. methodname: 'tool_usertours_reset_tour',
  17. args: {
  18. tourid,
  19. context: moodleConfig.contextid,
  20. pageurl: window.location.href,
  21. }
  22. }])[0];
  23. /**
  24. * Mark the specified tour as complete.
  25. *
  26. * @param {number} stepid
  27. * @param {number} tourid
  28. * @param {number} stepindex
  29. * @return {Promise}
  30. */
  31. export const markTourComplete = (stepid, tourid, stepindex) => fetchMany([{
  32. methodname: 'tool_usertours_complete_tour',
  33. args: {
  34. stepid,
  35. stepindex: stepindex,
  36. tourid,
  37. context: moodleConfig.contextid,
  38. pageurl: window.location.href,
  39. }
  40. }])[0];
  41. /**
  42. * Fetch the specified tour.
  43. *
  44. * @param {number} tourid
  45. * @return {Promise}
  46. */
  47. export const fetchTour = tourid => fetchMany([{
  48. methodname: 'tool_usertours_fetch_and_start_tour',
  49. args: {
  50. tourid,
  51. context: moodleConfig.contextid,
  52. pageurl: window.location.href,
  53. }
  54. }])[0];
  55. /**
  56. * Mark the specified step as having been shown.
  57. *
  58. * @param {number} stepid
  59. * @param {number} tourid
  60. * @param {number} stepindex
  61. * @return {Promise}
  62. */
  63. export const markStepShown = (stepid, tourid, stepindex) => fetchMany([{
  64. methodname: 'tool_usertours_step_shown',
  65. args: {
  66. tourid,
  67. stepid,
  68. stepindex,
  69. context: moodleConfig.contextid,
  70. pageurl: window.location.href,
  71. }
  72. }])[0];