main.js 2.6 KB

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