APIs

Show:
  1. /**
  2. @module ember-flexberry
  3. */
  4.  
  5. import Controller from '@ember/controller';
  6. import { inject as service} from '@ember/service';
  7.  
  8. /**
  9. Controller for editing record modal window in OLV component.
  10.  
  11. @class EditrecordDialog
  12. */
  13. export default Controller.extend({
  14. objectlistviewEvents: service(),
  15.  
  16. /**
  17. Service for managing the state of the application.
  18.  
  19. @property appState
  20. @type AppStateService
  21. */
  22. appState: service(),
  23.  
  24. /**
  25. Service that triggers lookup events.
  26.  
  27. @property lookupEventsService
  28. @type Service
  29. */
  30. lookupEventsService: service('lookup-events'),
  31.  
  32. /**
  33. Editrecord modal dialog outlet name
  34.  
  35. @property modalOutletName
  36. @type String
  37. @default 'editrecord-modal'
  38. */
  39. modalOutletName: 'editrecord-modal',
  40.  
  41. /**
  42. Editrecord modal dialog outlet name for content
  43.  
  44. @property modalContentOutletName
  45. @type String
  46. @default 'editrecord-modal-content'
  47. */
  48. modalContentOutletName: 'editrecord-modal-content',
  49.  
  50. /**
  51. Current open a modal window.
  52.  
  53. @property _openedModalDialog
  54. @type JQuery
  55. @private
  56. */
  57. _openedModalDialog: undefined,
  58.  
  59. /**
  60. Size of Semantic-UI modal and his class.
  61. [More info](http://semantic-ui.com/modules/modal.html#size).
  62.  
  63. Possible variants of size:
  64. - **small**
  65. - **large**
  66. - **fullscreen**
  67.  
  68. @property sizeClass
  69. @type String
  70. @default 'editrecord-dialog'
  71. */
  72. sizeClass: 'editrecord-dialog',
  73.  
  74. actions: {
  75. /**
  76. * Handles create modal window action.
  77. * It saves created window to have opportunity to close it later.
  78. *
  79. * @method createdModalDialog
  80. * @param {JQuery} modalDialog Created modal window.
  81. */
  82. createdModalDialog: function(modalDialog) {
  83. this.set('_openedModalDialog', modalDialog);
  84. this.get('objectlistviewEvents').editRecordDialogCreatedTrigger();
  85. this.get('appState').loading();
  86. this.get('lookupEventsService').on('lookupDialogOnHidden', this, this._refreshDimmer);
  87. },
  88.  
  89. /**
  90. Handler for close editrecord modal dialog.
  91.  
  92. @method actions.onEditRecordDialogClosing
  93. @public
  94. */
  95. onEditRecordDialogClosing: function() {
  96. this._closeModalDialog();
  97. },
  98.  
  99. /**
  100. Handler for action after edit record dialog was closed.
  101.  
  102. @method actions.onEditRecordDialogHidden
  103. @public
  104. */
  105. onEditRecordDialogHidden: function() {
  106. this._closeModalDialog();
  107. this.get('objectlistviewEvents').editRecordDialogHiddenTrigger();
  108. },
  109. },
  110.  
  111. /**
  112. Close current modal window if it exists.
  113.  
  114. @method _closeModalDialog
  115. @private
  116. */
  117. _closeModalDialog() {
  118. this.get('appState').reset();
  119. this.get('lookupEventsService').off('lookupDialogOnHidden', this, this._refreshDimmer);
  120. let openedDialog = this.get('_openedModalDialog');
  121. if (openedDialog) {
  122. openedDialog.modal('hide');
  123. this.set('_openedModalDialog', undefined);
  124. }
  125.  
  126. let modalOutletName = this.get('modalOutletName');
  127.  
  128. //close other opened modal windows
  129. this.send('removeModalDialog', { outlet: 'modal' });
  130.  
  131. //close this modal window
  132. this.send('removeModalDialog', { outlet: modalOutletName });
  133. },
  134.  
  135. /**
  136. Refresh dimmer for modal dialog.
  137.  
  138. @method _refreshDimmer
  139. @private
  140. */
  141. _refreshDimmer() {
  142. let openedDialog = this.get('_openedModalDialog');
  143. if (openedDialog) {
  144. openedDialog.modal('show dimmer');
  145. }
  146. }
  147. });
  148.