You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mainfileinfodetailview.js 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * Copyright (c) 2015
  3. *
  4. * This file is licensed under the Affero General Public License version 3
  5. * or later.
  6. *
  7. * See the COPYING-README file.
  8. *
  9. */
  10. (function() {
  11. var TEMPLATE =
  12. '<div class="thumbnailContainer"><a href="#" class="thumbnail action-default"><div class="stretcher"/></a></div>' +
  13. '<div class="file-details-container">' +
  14. '<div class="fileName">' +
  15. '<h3 title="{{name}}" class="ellipsis">{{name}}</h3>' +
  16. '<a class="permalink" href="{{permalink}}" title="{{permalinkTitle}}" data-clipboard-text="{{permalink}}">' +
  17. '<span class="icon icon-clippy"></span>' +
  18. '<span class="hidden-visually">{{permalinkTitle}}</span>' +
  19. '</a>' +
  20. '</div>' +
  21. ' <div class="file-details ellipsis">' +
  22. ' <a href="#" class="action action-favorite favorite permanent">' +
  23. ' <span class="icon {{starClass}}" title="{{starAltText}}"></span>' +
  24. ' </a>' +
  25. ' {{#if hasSize}}<span class="size" title="{{altSize}}">{{size}}</span>, {{/if}}<span class="date live-relative-timestamp" data-timestamp="{{timestamp}}" title="{{altDate}}">{{date}}</span>' +
  26. ' </div>' +
  27. '</div>' +
  28. '<div class="hidden permalink-field">' +
  29. '<input type="text" value="{{permalink}}" placeholder="{{permalinkTitle}}" readonly="readonly"/>' +
  30. '</div>';
  31. /**
  32. * @class OCA.Files.MainFileInfoDetailView
  33. * @classdesc
  34. *
  35. * Displays main details about a file
  36. *
  37. */
  38. var MainFileInfoDetailView = OCA.Files.DetailFileInfoView.extend(
  39. /** @lends OCA.Files.MainFileInfoDetailView.prototype */ {
  40. className: 'mainFileInfoView',
  41. /**
  42. * Associated file list instance, for file actions
  43. *
  44. * @type {OCA.Files.FileList}
  45. */
  46. _fileList: null,
  47. /**
  48. * File actions
  49. *
  50. * @type {OCA.Files.FileActions}
  51. */
  52. _fileActions: null,
  53. /**
  54. * @type {OCA.Files.SidebarPreviewManager}
  55. */
  56. _previewManager: null,
  57. events: {
  58. 'click a.action-favorite': '_onClickFavorite',
  59. 'click a.action-default': '_onClickDefaultAction',
  60. 'click a.permalink': '_onClickPermalink',
  61. 'focus .permalink-field>input': '_onFocusPermalink'
  62. },
  63. template: function(data) {
  64. if (!this._template) {
  65. this._template = Handlebars.compile(TEMPLATE);
  66. }
  67. return this._template(data);
  68. },
  69. initialize: function(options) {
  70. options = options || {};
  71. this._fileList = options.fileList;
  72. this._fileActions = options.fileActions;
  73. if (!this._fileList) {
  74. throw 'Missing required parameter "fileList"';
  75. }
  76. if (!this._fileActions) {
  77. throw 'Missing required parameter "fileActions"';
  78. }
  79. this._previewManager = new OCA.Files.SidebarPreviewManager(this._fileList);
  80. this._setupClipboard();
  81. },
  82. _setupClipboard: function() {
  83. var clipboard = new Clipboard('.permalink');
  84. clipboard.on('success', function(e) {
  85. var $el = $(e.trigger);
  86. $el.tooltip('hide')
  87. .attr('data-original-title', t('core', 'Copied!'))
  88. .tooltip('fixTitle')
  89. .tooltip({placement: 'bottom', trigger: 'manual'})
  90. .tooltip('show');
  91. _.delay(function() {
  92. $el.tooltip('hide');
  93. $el.attr('data-original-title', t('files', 'Copy direct link (only works for users who have access to this file/folder)'))
  94. .tooltip('fixTitle');
  95. }, 3000);
  96. });
  97. clipboard.on('error', function(e) {
  98. var $row = this.$('.permalink-field');
  99. $row.toggleClass('hidden');
  100. if (!$row.hasClass('hidden')) {
  101. $row.find('>input').focus();
  102. }
  103. });
  104. },
  105. _onClickPermalink: function(e) {
  106. e.preventDefault();
  107. return;
  108. },
  109. _onFocusPermalink: function() {
  110. this.$('.permalink-field>input').select();
  111. },
  112. _onClickFavorite: function(event) {
  113. event.preventDefault();
  114. this._fileActions.triggerAction('Favorite', this.model, this._fileList);
  115. },
  116. _onClickDefaultAction: function(event) {
  117. event.preventDefault();
  118. this._fileActions.triggerAction(null, this.model, this._fileList);
  119. },
  120. _onModelChanged: function() {
  121. // simply re-render
  122. this.render();
  123. },
  124. _makePermalink: function(fileId) {
  125. var baseUrl = OC.getProtocol() + '://' + OC.getHost();
  126. return baseUrl + OC.generateUrl('/f/{fileId}', {fileId: fileId});
  127. },
  128. setFileInfo: function(fileInfo) {
  129. if (this.model) {
  130. this.model.off('change', this._onModelChanged, this);
  131. }
  132. this.model = fileInfo;
  133. if (this.model) {
  134. this.model.on('change', this._onModelChanged, this);
  135. }
  136. if (this.model) {
  137. var properties = [];
  138. if( !this.model.has('size') ) {
  139. properties.push(OC.Files.Client.PROPERTY_SIZE);
  140. properties.push(OC.Files.Client.PROPERTY_GETCONTENTLENGTH);
  141. }
  142. if( properties.length > 0){
  143. this.model.reloadProperties(properties);
  144. }
  145. }
  146. this.render();
  147. },
  148. /**
  149. * Renders this details view
  150. */
  151. render: function() {
  152. this.trigger('pre-render');
  153. if (this.model) {
  154. var isFavorite = (this.model.get('tags') || []).indexOf(OC.TAG_FAVORITE) >= 0;
  155. this.$el.html(this.template({
  156. type: this.model.isImage()? 'image': '',
  157. nameLabel: t('files', 'Name'),
  158. name: this.model.get('displayName') || this.model.get('name'),
  159. pathLabel: t('files', 'Path'),
  160. path: this.model.get('path'),
  161. hasSize: this.model.has('size'),
  162. sizeLabel: t('files', 'Size'),
  163. size: OC.Util.humanFileSize(this.model.get('size'), true),
  164. altSize: n('files', '%n byte', '%n bytes', this.model.get('size')),
  165. dateLabel: t('files', 'Modified'),
  166. altDate: OC.Util.formatDate(this.model.get('mtime')),
  167. timestamp: this.model.get('mtime'),
  168. date: OC.Util.relativeModifiedDate(this.model.get('mtime')),
  169. starAltText: isFavorite ? t('files', 'Favorited') : t('files', 'Favorite'),
  170. starClass: isFavorite ? 'icon-starred' : 'icon-star',
  171. permalink: this._makePermalink(this.model.get('id')),
  172. permalinkTitle: t('files', 'Copy direct link (only works for users who have access to this file/folder)')
  173. }));
  174. // TODO: we really need OC.Previews
  175. var $iconDiv = this.$el.find('.thumbnail');
  176. var $container = this.$el.find('.thumbnailContainer');
  177. if (!this.model.isDirectory()) {
  178. $iconDiv.addClass('icon-loading icon-32');
  179. this._previewManager.loadPreview(this.model, $iconDiv, $container);
  180. } else {
  181. var iconUrl = this.model.get('icon') || OC.MimeType.getIconUrl('dir');
  182. $iconDiv.css('background-image', 'url("' + iconUrl + '")');
  183. OC.Util.scaleFixForIE8($iconDiv);
  184. }
  185. this.$el.find('[title]').tooltip({placement: 'bottom'});
  186. } else {
  187. this.$el.empty();
  188. }
  189. this.delegateEvents();
  190. this.trigger('post-render');
  191. }
  192. });
  193. OCA.Files.MainFileInfoDetailView = MainFileInfoDetailView;
  194. })();