custom-wizard-redirect.js.es6 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import ApplicationRoute from 'discourse/routes/application';
  2. export default {
  3. name: "custom-wizard-redirect",
  4. after: "message-bus",
  5. initialize: function (container) {
  6. const messageBus = container.lookup('message-bus:main');
  7. if (!messageBus) { return; }
  8. messageBus.subscribe("/redirect_to_wizard", function (wizardId) {
  9. const wizardUrl = window.location.origin + '/w/' + wizardId;
  10. window.location.href = wizardUrl;
  11. });
  12. ApplicationRoute.reopen({
  13. actions: {
  14. willTransition(transition) {
  15. const redirectToWizard = this.get('currentUser.redirect_to_wizard');
  16. const excludedPaths = Discourse.SiteSettings.wizard_redirect_exclude_paths.split('|').concat(['loading']);
  17. if (redirectToWizard && (!transition.intent.name || !excludedPaths.find((p) => {
  18. return transition.intent.name.indexOf(p) > -1;
  19. }))) {
  20. transition.abort();
  21. window.location = '/w/' + redirectToWizard.dasherize();
  22. }
  23. return this._super(transition);
  24. }
  25. }
  26. })
  27. }
  28. };