application.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import Ember from 'ember';
  2. export default Ember.Route.extend({
  3. actions: {
  4. // Loading handler
  5. loading: function() {
  6. this.get('page-title').setPlaceholderTitle();
  7. return true;
  8. },
  9. // Error handlers
  10. error: function(reason) {
  11. if (reason.status === 0) {
  12. this.get('page-title').setTitle(gettext('Connection lost'));
  13. return this.intermediateTransitionTo('error-0');
  14. }
  15. if (typeof reason.responseJSON !== 'undefined' && typeof reason.responseJSON.ban !== 'undefined') {
  16. this.get('page-title').setTitle(gettext('You are banned'));
  17. return this.intermediateTransitionTo('error-banned', reason.responseJSON.ban);
  18. }
  19. if (reason.status === 403) {
  20. this.get('page-title').setTitle(gettext('Page not available'));
  21. var final_error = {status: 403, message: null};
  22. if (typeof reason.responseJSON !== 'undefined' && typeof reason.responseJSON.detail !== 'undefined' && reason.responseJSON.detail !== 'Permission denied') {
  23. final_error.message = reason.responseJSON.detail;
  24. }
  25. return this.intermediateTransitionTo('error-403', final_error);
  26. }
  27. if (reason.status === 404) {
  28. this.get('page-title').setTitle(gettext('Page not found'));
  29. return this.intermediateTransitionTo('error-404');
  30. }
  31. this.get('page-title').setTitle(gettext('Error'));
  32. return true;
  33. },
  34. toastError: function(reason) {
  35. var errorMessage = gettext('Unknown error has occured.');
  36. if (reason.status === 0) {
  37. errorMessage = gettext('Lost connection with application.');
  38. }
  39. if (reason.status === 403) {
  40. if (typeof reason.responseJSON !== 'undefined' && typeof reason.responseJSON.detail !== 'undefined' && reason.responseJSON.detail !== 'Permission denied') {
  41. errorMessage = reason.responseJSON.detail;
  42. } else {
  43. errorMessage = gettext("You don't have permission to perform this action.");
  44. }
  45. }
  46. if (reason.status === 404) {
  47. errorMessage = gettext('Action link is invalid.');
  48. }
  49. this.get('toast').error(errorMessage);
  50. },
  51. showBan: function(ban) {
  52. this.get('page-title').setTitle(gettext('You are banned'));
  53. this.intermediateTransitionTo('error-banned', ban);
  54. },
  55. // Auth
  56. openLoginModal: function() {
  57. this.controllerFor("loginModal").send('open');
  58. },
  59. logOut: function() {
  60. this.get('auth').logout();
  61. Ember.$('#hidden-logout-form').submit();
  62. }
  63. }
  64. });