2015-07-15 13:06:13 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
var TEMPLATE =
|
2015-09-28 15:14:18 +03:00
|
|
|
'<div class="thumbnailContainer"><a href="#" class="thumbnail action-default"><div class="stretcher"/></a></div>' +
|
2015-08-30 15:17:18 +03:00
|
|
|
'<div class="file-details-container">' +
|
2016-05-06 14:04:59 +03:00
|
|
|
'<div class="fileName">' +
|
|
|
|
'<h3 title="{{name}}" class="ellipsis">{{name}}</h3>' +
|
|
|
|
'<a class="permalink" href="{{permalink}}" title="{{permalinkTitle}}">' +
|
2016-11-17 23:46:07 +03:00
|
|
|
'<span class="icon icon-clippy"></span>' +
|
2016-05-06 14:04:59 +03:00
|
|
|
'<span class="hidden-visually">{{permalinkTitle}}</span>' +
|
|
|
|
'</a>' +
|
|
|
|
'</div>' +
|
2015-08-30 15:17:18 +03:00
|
|
|
' <div class="file-details ellipsis">' +
|
2016-11-21 16:40:34 +03:00
|
|
|
' <a href="#" class="action action-favorite favorite permanent">' +
|
|
|
|
' <span class="icon {{starClass}}" title="{{starAltText}}"></span>' +
|
2015-08-30 15:17:18 +03:00
|
|
|
' </a>' +
|
2016-08-31 18:44:09 +03:00
|
|
|
' {{#if hasSize}}<span class="size" title="{{altSize}}">{{size}}</span>, {{/if}}<span class="date live-relative-timestamp" data-timestamp="{{timestamp}}" title="{{altDate}}">{{date}}</span>' +
|
2015-08-30 15:17:18 +03:00
|
|
|
' </div>' +
|
2016-05-06 14:04:59 +03:00
|
|
|
'</div>' +
|
|
|
|
'<div class="hidden permalink-field">' +
|
|
|
|
'<input type="text" value="{{permalink}}" placeholder="{{permalinkTitle}}" readonly="readonly"/>' +
|
2015-07-15 18:05:25 +03:00
|
|
|
'</div>';
|
2015-07-15 13:06:13 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @class OCA.Files.MainFileInfoDetailView
|
|
|
|
* @classdesc
|
|
|
|
*
|
|
|
|
* Displays main details about a file
|
|
|
|
*
|
|
|
|
*/
|
2015-08-12 18:30:20 +03:00
|
|
|
var MainFileInfoDetailView = OCA.Files.DetailFileInfoView.extend(
|
2015-07-15 13:06:13 +03:00
|
|
|
/** @lends OCA.Files.MainFileInfoDetailView.prototype */ {
|
2015-08-12 18:30:20 +03:00
|
|
|
|
|
|
|
className: 'mainFileInfoView',
|
2015-07-15 13:06:13 +03:00
|
|
|
|
|
|
|
/**
|
2015-08-12 18:30:20 +03:00
|
|
|
* Associated file list instance, for file actions
|
|
|
|
*
|
|
|
|
* @type {OCA.Files.FileList}
|
2015-07-15 13:06:13 +03:00
|
|
|
*/
|
2015-08-12 18:30:20 +03:00
|
|
|
_fileList: null,
|
2015-07-15 13:06:13 +03:00
|
|
|
|
|
|
|
/**
|
2015-08-12 18:30:20 +03:00
|
|
|
* File actions
|
|
|
|
*
|
|
|
|
* @type {OCA.Files.FileActions}
|
2015-07-15 13:06:13 +03:00
|
|
|
*/
|
2015-08-12 18:30:20 +03:00
|
|
|
_fileActions: null,
|
|
|
|
|
2016-07-04 13:02:07 +03:00
|
|
|
/**
|
|
|
|
* @type {OCA.Files.SidebarPreviewManager}
|
|
|
|
*/
|
|
|
|
_previewManager: null,
|
|
|
|
|
2015-08-12 18:30:20 +03:00
|
|
|
events: {
|
|
|
|
'click a.action-favorite': '_onClickFavorite',
|
2016-05-06 14:04:59 +03:00
|
|
|
'click a.action-default': '_onClickDefaultAction',
|
|
|
|
'click a.permalink': '_onClickPermalink',
|
|
|
|
'focus .permalink-field>input': '_onFocusPermalink'
|
2015-08-12 18:30:20 +03:00
|
|
|
},
|
2015-07-15 13:06:13 +03:00
|
|
|
|
2015-08-12 18:30:20 +03:00
|
|
|
template: function(data) {
|
2015-07-15 13:06:13 +03:00
|
|
|
if (!this._template) {
|
|
|
|
this._template = Handlebars.compile(TEMPLATE);
|
|
|
|
}
|
2015-08-12 18:30:20 +03:00
|
|
|
return this._template(data);
|
|
|
|
},
|
2015-07-15 13:06:13 +03:00
|
|
|
|
2015-08-12 18:30:20 +03:00
|
|
|
initialize: function(options) {
|
|
|
|
options = options || {};
|
|
|
|
this._fileList = options.fileList;
|
|
|
|
this._fileActions = options.fileActions;
|
|
|
|
if (!this._fileList) {
|
2015-10-15 17:30:50 +03:00
|
|
|
throw 'Missing required parameter "fileList"';
|
2015-08-12 18:30:20 +03:00
|
|
|
}
|
|
|
|
if (!this._fileActions) {
|
2015-10-15 17:30:50 +03:00
|
|
|
throw 'Missing required parameter "fileActions"';
|
2015-08-12 18:30:20 +03:00
|
|
|
}
|
2016-07-04 13:02:07 +03:00
|
|
|
this._previewManager = new OCA.Files.SidebarPreviewManager(this._fileList);
|
2015-08-12 18:30:20 +03:00
|
|
|
},
|
|
|
|
|
2016-05-06 14:04:59 +03:00
|
|
|
_onClickPermalink: function() {
|
|
|
|
var $row = this.$('.permalink-field');
|
|
|
|
$row.toggleClass('hidden');
|
|
|
|
if (!$row.hasClass('hidden')) {
|
|
|
|
$row.find('>input').focus();
|
|
|
|
}
|
|
|
|
// cancel click, user must right-click + copy or middle click
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onFocusPermalink: function() {
|
|
|
|
this.$('.permalink-field>input').select();
|
|
|
|
},
|
|
|
|
|
2015-08-12 18:30:20 +03:00
|
|
|
_onClickFavorite: function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
this._fileActions.triggerAction('Favorite', this.model, this._fileList);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onClickDefaultAction: function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
this._fileActions.triggerAction(null, this.model, this._fileList);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onModelChanged: function() {
|
|
|
|
// simply re-render
|
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
|
2016-05-06 14:04:59 +03:00
|
|
|
_makePermalink: function(fileId) {
|
|
|
|
var baseUrl = OC.getProtocol() + '://' + OC.getHost();
|
|
|
|
return baseUrl + OC.generateUrl('/f/{fileId}', {fileId: fileId});
|
|
|
|
},
|
|
|
|
|
2015-08-12 18:30:20 +03:00
|
|
|
setFileInfo: function(fileInfo) {
|
|
|
|
if (this.model) {
|
|
|
|
this.model.off('change', this._onModelChanged, this);
|
|
|
|
}
|
|
|
|
this.model = fileInfo;
|
|
|
|
if (this.model) {
|
|
|
|
this.model.on('change', this._onModelChanged, this);
|
|
|
|
}
|
2016-11-21 17:03:45 +03:00
|
|
|
|
|
|
|
if (this.model) {
|
|
|
|
var properties = [];
|
|
|
|
if( !this.model.has('size') ) {
|
|
|
|
properties.push(OC.Files.Client.PROPERTY_SIZE);
|
|
|
|
properties.push(OC.Files.Client.PROPERTY_GETCONTENTLENGTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( properties.length > 0){
|
|
|
|
this.model.reloadProperties(properties);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-12 18:30:20 +03:00
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders this details view
|
|
|
|
*/
|
|
|
|
render: function() {
|
|
|
|
if (this.model) {
|
|
|
|
var isFavorite = (this.model.get('tags') || []).indexOf(OC.TAG_FAVORITE) >= 0;
|
|
|
|
this.$el.html(this.template({
|
2015-08-28 18:51:26 +03:00
|
|
|
type: this.model.isImage()? 'image': '',
|
2015-07-15 17:09:00 +03:00
|
|
|
nameLabel: t('files', 'Name'),
|
2015-08-25 12:29:35 +03:00
|
|
|
name: this.model.get('displayName') || this.model.get('name'),
|
2015-07-15 17:09:00 +03:00
|
|
|
pathLabel: t('files', 'Path'),
|
2015-08-12 18:30:20 +03:00
|
|
|
path: this.model.get('path'),
|
2015-08-25 12:29:35 +03:00
|
|
|
hasSize: this.model.has('size'),
|
2015-07-15 17:09:00 +03:00
|
|
|
sizeLabel: t('files', 'Size'),
|
2015-08-12 18:30:20 +03:00
|
|
|
size: OC.Util.humanFileSize(this.model.get('size'), true),
|
|
|
|
altSize: n('files', '%n byte', '%n bytes', this.model.get('size')),
|
2015-07-15 17:09:00 +03:00
|
|
|
dateLabel: t('files', 'Modified'),
|
2015-08-12 18:30:20 +03:00
|
|
|
altDate: OC.Util.formatDate(this.model.get('mtime')),
|
2016-08-31 18:44:09 +03:00
|
|
|
timestamp: this.model.get('mtime'),
|
2015-08-12 18:30:20 +03:00
|
|
|
date: OC.Util.relativeModifiedDate(this.model.get('mtime')),
|
2015-07-15 18:05:25 +03:00
|
|
|
starAltText: isFavorite ? t('files', 'Favorited') : t('files', 'Favorite'),
|
2016-11-21 16:40:34 +03:00
|
|
|
starClass: isFavorite ? 'icon-starred' : 'icon-star',
|
2016-05-06 14:04:59 +03:00
|
|
|
permalink: this._makePermalink(this.model.get('id')),
|
2016-11-17 23:46:07 +03:00
|
|
|
permalinkTitle: t('files', 'Copy local link')
|
2015-07-15 17:09:00 +03:00
|
|
|
}));
|
|
|
|
|
|
|
|
// TODO: we really need OC.Previews
|
2015-07-16 13:49:34 +03:00
|
|
|
var $iconDiv = this.$el.find('.thumbnail');
|
2015-09-11 16:25:42 +03:00
|
|
|
var $container = this.$el.find('.thumbnailContainer');
|
2015-08-12 18:30:20 +03:00
|
|
|
if (!this.model.isDirectory()) {
|
2015-09-15 16:40:42 +03:00
|
|
|
$iconDiv.addClass('icon-loading icon-32');
|
2016-07-04 13:02:07 +03:00
|
|
|
this._previewManager.loadPreview(this.model, $iconDiv, $container);
|
2015-07-15 17:09:00 +03:00
|
|
|
} else {
|
2015-10-28 19:43:36 +03:00
|
|
|
var iconUrl = this.model.get('icon') || OC.MimeType.getIconUrl('dir');
|
|
|
|
$iconDiv.css('background-image', 'url("' + iconUrl + '")');
|
2015-09-29 19:15:15 +03:00
|
|
|
OC.Util.scaleFixForIE8($iconDiv);
|
2015-07-15 17:09:00 +03:00
|
|
|
}
|
2015-08-07 13:33:50 +03:00
|
|
|
this.$el.find('[title]').tooltip({placement: 'bottom'});
|
2015-08-12 18:30:20 +03:00
|
|
|
} else {
|
|
|
|
this.$el.empty();
|
2015-07-15 13:06:13 +03:00
|
|
|
}
|
2015-08-12 18:30:20 +03:00
|
|
|
this.delegateEvents();
|
2015-07-15 13:06:13 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
OCA.Files.MainFileInfoDetailView = MainFileInfoDetailView;
|
|
|
|
})();
|