main.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. const Mn = require('backbone.marionette');
  2. const template = require('./main.ejs');
  3. const HeaderView = require('./header/main');
  4. const MenuView = require('./menu/main');
  5. const FooterView = require('./footer/main');
  6. const Cache = require('../cache');
  7. module.exports = Mn.View.extend({
  8. id: 'app',
  9. className: 'page',
  10. template: template,
  11. modal_setup: false,
  12. modal: null,
  13. ui: {
  14. modal: '#modal-dialog'
  15. },
  16. regions: {
  17. header_region: {
  18. el: '#header',
  19. replaceElement: true
  20. },
  21. menu_region: {
  22. el: '#menu',
  23. replaceElement: true
  24. },
  25. footer_region: '.footer',
  26. app_content_region: '#app-content',
  27. modal_region: '#modal-dialog'
  28. },
  29. /**
  30. * @param {Object} view
  31. */
  32. showAppContent: function (view) {
  33. this.showChildView('app_content_region', view);
  34. },
  35. /**
  36. * @param {Object} view
  37. * @param {Function} [show_callback]
  38. * @param {Function} [shown_callback]
  39. */
  40. showModalDialog: function (view, show_callback, shown_callback) {
  41. this.showChildView('modal_region', view);
  42. let modal = this.getRegion('modal_region').$el.modal('show');
  43. modal.on('hidden.bs.modal', function (/*e*/) {
  44. if (show_callback) {
  45. modal.off('show.bs.modal', show_callback);
  46. }
  47. if (shown_callback) {
  48. modal.off('shown.bs.modal', shown_callback);
  49. }
  50. modal.off('hidden.bs.modal');
  51. view.destroy();
  52. });
  53. if (show_callback) {
  54. modal.on('show.bs.modal', show_callback);
  55. }
  56. if (shown_callback) {
  57. modal.on('shown.bs.modal', shown_callback);
  58. }
  59. },
  60. /**
  61. *
  62. * @param {Function} [hidden_callback]
  63. */
  64. closeModal: function (hidden_callback) {
  65. let modal = this.getRegion('modal_region').$el.modal('hide');
  66. if (hidden_callback) {
  67. modal.on('hidden.bs.modal', hidden_callback);
  68. }
  69. },
  70. onRender: function () {
  71. this.showChildView('header_region', new HeaderView({
  72. model: Cache.User
  73. }));
  74. this.showChildView('menu_region', new MenuView());
  75. this.showChildView('footer_region', new FooterView());
  76. },
  77. reset: function () {
  78. this.getRegion('header_region').reset();
  79. this.getRegion('footer_region').reset();
  80. this.getRegion('modal_region').reset();
  81. }
  82. });