application.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import Ember from 'ember';
  2. export default Ember.Route.extend({
  3. actions: {
  4. setTitle: function(title) {
  5. if (typeof title === 'string') {
  6. title = {title: title};
  7. }
  8. var complete_title = title.title;
  9. if (typeof title.page !== 'undefined') {
  10. complete_title += ' (' + interpolate(gettext('page %(page)s'), {page:title.page}, true) + ')';
  11. }
  12. if (typeof title.parent !== 'undefined') {
  13. complete_title += ' | ' + title.parent;
  14. }
  15. complete_title += ' | ' + this.get('settings.forum_name');
  16. document.title = complete_title;
  17. return false;
  18. },
  19. // Error handler
  20. error: function(reason) {
  21. if (reason.status === 0) {
  22. this.send('setTitle', gettext('Connection lost'));
  23. return this.intermediateTransitionTo('error-0');
  24. }
  25. if (typeof reason.responseJSON !== 'undefined' && typeof reason.responseJSON.ban !== 'undefined') {
  26. this.send('setTitle', gettext('You are banned'));
  27. return this.intermediateTransitionTo('error-banned', reason.responseJSON.ban);
  28. }
  29. if (reason.status === 403) {
  30. this.send('setTitle', gettext('Page not available'));
  31. var final_error = {status: 403, message: null};
  32. if (typeof reason.responseJSON !== 'undefined' && typeof reason.responseJSON.detail !== 'undefined' && reason.responseJSON.detail !== 'Permission denied') {
  33. final_error.message = reason.responseJSON.detail;
  34. }
  35. return this.intermediateTransitionTo('error-403', final_error);
  36. }
  37. if (reason.status === 404) {
  38. this.send('setTitle', gettext('Page not found'));
  39. return this.intermediateTransitionTo('error-404');
  40. }
  41. this.send('setTitle', gettext('Error'));
  42. return true;
  43. },
  44. showBan: function(ban) {
  45. this.send('setTitle', gettext('You are banned'));
  46. this.intermediateTransitionTo('error-banned', ban);
  47. return false;
  48. },
  49. // Flashes
  50. flashInfo: function(message) {
  51. this.controllerFor("flashMessage").send('setFlash', 'info', message);
  52. return false;
  53. },
  54. flashSuccess: function(message) {
  55. this.controllerFor("flashMessage").send('setFlash', 'success', message);
  56. return false;
  57. },
  58. flashWarning: function(message) {
  59. this.controllerFor("flashMessage").send('setFlash', 'warning', message);
  60. return false;
  61. },
  62. flashError: function(message) {
  63. this.controllerFor("flashMessage").send('setFlash', 'error', message);
  64. return false;
  65. },
  66. // Auth
  67. openLoginModal: function() {
  68. this.controllerFor("loginModal").send('open');
  69. return false;
  70. },
  71. logOut: function() {
  72. this.get('auth').logout();
  73. Ember.$('#hidden-logout-form').submit();
  74. return false;
  75. }
  76. }
  77. });