APIs

Show:
  1. /**
  2. @module ember-flexberry
  3. */
  4.  
  5. import { computed } from '@ember/object';
  6. import FlexberryFile from './../flexberry-file';
  7.  
  8. /**
  9. Mobile version of {{#crossLink "FlexberryFileComponent"}}flexberry-file{{/crossLink}} component (with mobile-specific defaults).
  10.  
  11. @class Mobile.FlexberryFileComponent
  12. @extends FlexberryFileComponent
  13. */
  14. export default FlexberryFile.extend({
  15. /**
  16. Flag: whether component is mobile or not.
  17. Used in base class for class names bindings.
  18.  
  19. @property _isMobile
  20. @type Boolean
  21. @default true
  22. @private
  23. */
  24. _isMobile: true,
  25.  
  26. /**
  27. Items for component's menu.
  28.  
  29. @readOnly
  30. @property _menuItems
  31. @type Object[]
  32. @private
  33. */
  34. _menuItems: computed('showPreview', 'readonly', 'i18n.locale', '_uploadButtonIsVisible', '_downloadButtonIsVisible', function() {
  35. let menuSubItems = [];
  36. if (this.get('showPreview')) {
  37. menuSubItems.push({
  38. icon: 'zoom icon',
  39. title: this.get('i18n').t('components.flexberry-file.menu-for-file.zoom-image-item-caption'),
  40. isZoomItem: true
  41. });
  42. }
  43.  
  44. if (!this.get('readonly')) {
  45. menuSubItems.push({
  46. icon: 'file outline icon',
  47. title: this.get('i18n').t('components.flexberry-file.menu-for-file.replace-file-item-caption'),
  48. isReplaceItem: true
  49. });
  50. }
  51.  
  52. if (!this.get('readonly')) {
  53. menuSubItems.push({
  54. icon: 'trash icon',
  55. title: this.get('i18n').t('components.flexberry-file.menu-for-file.delete-file-item-caption'),
  56. isDeleteItem: true
  57. });
  58. }
  59. if (this.get('_uploadButtonIsVisible')) {
  60. menuSubItems.push({
  61. icon: 'upload outline icon',
  62. title: this.get('i18n').t('components.flexberry-file.upload-button-title'),
  63. isUploadItem: true
  64. });
  65. }
  66. if (this.get('_downloadButtonIsVisible')) {
  67. menuSubItems.push({
  68. icon: 'download outline icon',
  69. title: this.get('i18n').t('components.flexberry-file.download-button-title'),
  70. isDownloadItem: true
  71. });
  72. }
  73. return [{
  74. icon: 'list layout icon',
  75. itemsAlignment: undefined,
  76. items: menuSubItems
  77. }];
  78. }),
  79.  
  80. actions: {
  81. /**
  82. Handles click on menu item of selected file.
  83.  
  84. @method actions.onMenuItemClick
  85. @param {Object} e Information about selected menu item.
  86. @param {Object} [e.data] Data of selected menu item.
  87. @public
  88. */
  89. onMenuItemClick(e) {
  90. if (!e.item) {
  91. return;
  92. }
  93.  
  94. if (e.item.isZoomItem) {
  95. this.send('viewLoadedImage');
  96.  
  97. return;
  98. }
  99.  
  100. if (e.item.isReplaceItem) {
  101. let addButton = this.$('.flexberry-file-add-button');
  102. addButton.click();
  103.  
  104. return;
  105. }
  106.  
  107. if (e.item.isDeleteItem) {
  108. this.removeFile();
  109.  
  110. return;
  111. }
  112.  
  113. if (e.item.isDownloadItem) {
  114. this.downloadFile();
  115.  
  116. return;
  117. }
  118.  
  119. if (e.item.isUploadItem){
  120. this.uploadFile();
  121.  
  122. return;
  123. }
  124. }
  125. },
  126.  
  127. /**
  128. Components class names bindings.
  129.  
  130. @property classNameBindings
  131. @type String[]
  132. @default ['isMobile:mobile']
  133. */
  134. classNameBindings: ['_isMobile:mobile'],
  135.  
  136. /**
  137. Flag: indicates whether to show preview element for images or not.
  138.  
  139. @property showPreview
  140. @type Boolean
  141. @default true
  142. */
  143. showPreview: true,
  144.  
  145. /**
  146. Handles end of rerender.
  147. Dropdown part of menu is initialized here in order to get dropdown behavior,
  148. when menu disappeares after item selecting.
  149. */
  150. didRender() {
  151. this._super(...arguments);
  152.  
  153. // TODO: Move collapse menu logic into flexberry-menu component,
  154. // make it available through component setting (for example collapseMenuOnItemClick=true),
  155. // and remove all didRender logic then.
  156. let dropdownElement = this.$('.flexberry-file-menu .dropdown');
  157. if (dropdownElement && dropdownElement.length > 0) {
  158. dropdownElement.dropdown();
  159. }
  160. },
  161. });
  162.