application.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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(error){
  21. if (error.status === 0) {
  22. this.send('setTitle', gettext('Connection lost'));
  23. return this.intermediateTransitionTo('error-0');
  24. }
  25. if (error.status === 403) {
  26. this.send('setTitle', gettext('Page not available'));
  27. var final_error = {status: 403, message: null};
  28. if (error.responseJSON.detail !== 'Permission denied') {
  29. final_error.message = error.responseJSON.detail;
  30. }
  31. return this.intermediateTransitionTo('error-403', final_error);
  32. }
  33. if (error.status === 404) {
  34. this.send('setTitle', gettext('Page not found'));
  35. return this.intermediateTransitionTo('error-404');
  36. }
  37. this.send('setTitle', gettext('Error'));
  38. return true;
  39. },
  40. // Flashes
  41. flashInfo: function(message) {
  42. this.controllerFor("flashMessage").send('setFlash', 'info', message);
  43. return false;
  44. },
  45. flashSuccess: function(message) {
  46. this.controllerFor("flashMessage").send('setFlash', 'success', message);
  47. return false;
  48. },
  49. flashWarning: function(message) {
  50. this.controllerFor("flashMessage").send('setFlash', 'warning', message);
  51. return false;
  52. },
  53. flashError: function(message) {
  54. this.controllerFor("flashMessage").send('setFlash', 'error', message);
  55. return false;
  56. },
  57. // Auth
  58. openLoginModal: function() {
  59. this.controllerFor("loginModal").send('open');
  60. return false;
  61. },
  62. logOut: function() {
  63. this.get('auth').logout();
  64. Ember.$('#hidden-logout-form').submit();
  65. return false;
  66. }
  67. }
  68. });