2015-07-15 10:06:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
/**
|
|
|
|
* @class OCA.Files.MainFileInfoDetailView
|
|
|
|
* @classdesc
|
|
|
|
*
|
|
|
|
* Displays main details about a file
|
|
|
|
*
|
|
|
|
*/
|
2015-08-12 15:30:20 +00:00
|
|
|
var MainFileInfoDetailView = OCA.Files.DetailFileInfoView.extend(
|
2015-07-15 10:06:13 +00:00
|
|
|
/** @lends OCA.Files.MainFileInfoDetailView.prototype */ {
|
2015-08-12 15:30:20 +00:00
|
|
|
|
|
|
|
className: 'mainFileInfoView',
|
2015-07-15 10:06:13 +00:00
|
|
|
|
|
|
|
/**
|
2015-08-12 15:30:20 +00:00
|
|
|
* Associated file list instance, for file actions
|
|
|
|
*
|
|
|
|
* @type {OCA.Files.FileList}
|
2015-07-15 10:06:13 +00:00
|
|
|
*/
|
2015-08-12 15:30:20 +00:00
|
|
|
_fileList: null,
|
2015-07-15 10:06:13 +00:00
|
|
|
|
|
|
|
/**
|
2015-08-12 15:30:20 +00:00
|
|
|
* File actions
|
|
|
|
*
|
|
|
|
* @type {OCA.Files.FileActions}
|
2015-07-15 10:06:13 +00:00
|
|
|
*/
|
2015-08-12 15:30:20 +00:00
|
|
|
_fileActions: null,
|
|
|
|
|
2016-07-04 10:02:07 +00:00
|
|
|
/**
|
|
|
|
* @type {OCA.Files.SidebarPreviewManager}
|
|
|
|
*/
|
|
|
|
_previewManager: null,
|
|
|
|
|
2015-08-12 15:30:20 +00:00
|
|
|
events: {
|
|
|
|
'click a.action-favorite': '_onClickFavorite',
|
2016-05-06 11:04:59 +00:00
|
|
|
'click a.action-default': '_onClickDefaultAction',
|
|
|
|
'click a.permalink': '_onClickPermalink',
|
|
|
|
'focus .permalink-field>input': '_onFocusPermalink'
|
2015-08-12 15:30:20 +00:00
|
|
|
},
|
2015-07-15 10:06:13 +00:00
|
|
|
|
2015-08-12 15:30:20 +00:00
|
|
|
template: function(data) {
|
2018-10-01 18:07:09 +00:00
|
|
|
return OCA.Files.Templates['mainfileinfodetailsview'](data);
|
2015-08-12 15:30:20 +00:00
|
|
|
},
|
2015-07-15 10:06:13 +00:00
|
|
|
|
2015-08-12 15:30:20 +00:00
|
|
|
initialize: function(options) {
|
|
|
|
options = options || {};
|
|
|
|
this._fileList = options.fileList;
|
|
|
|
this._fileActions = options.fileActions;
|
|
|
|
if (!this._fileList) {
|
2015-10-15 14:30:50 +00:00
|
|
|
throw 'Missing required parameter "fileList"';
|
2015-08-12 15:30:20 +00:00
|
|
|
}
|
|
|
|
if (!this._fileActions) {
|
2015-10-15 14:30:50 +00:00
|
|
|
throw 'Missing required parameter "fileActions"';
|
2015-08-12 15:30:20 +00:00
|
|
|
}
|
2016-07-04 10:02:07 +00:00
|
|
|
this._previewManager = new OCA.Files.SidebarPreviewManager(this._fileList);
|
2017-05-10 12:29:20 +00:00
|
|
|
|
|
|
|
this._setupClipboard();
|
2015-08-12 15:30:20 +00:00
|
|
|
},
|
|
|
|
|
2017-05-10 12:29:20 +00:00
|
|
|
_setupClipboard: function() {
|
|
|
|
var clipboard = new Clipboard('.permalink');
|
|
|
|
clipboard.on('success', function(e) {
|
|
|
|
var $el = $(e.trigger);
|
|
|
|
$el.tooltip('hide')
|
|
|
|
.attr('data-original-title', t('core', 'Copied!'))
|
|
|
|
.tooltip('fixTitle')
|
|
|
|
.tooltip({placement: 'bottom', trigger: 'manual'})
|
|
|
|
.tooltip('show');
|
|
|
|
_.delay(function() {
|
|
|
|
$el.tooltip('hide');
|
|
|
|
$el.attr('data-original-title', t('files', 'Copy direct link (only works for users who have access to this file/folder)'))
|
|
|
|
.tooltip('fixTitle');
|
|
|
|
}, 3000);
|
|
|
|
});
|
|
|
|
clipboard.on('error', function(e) {
|
|
|
|
var $row = this.$('.permalink-field');
|
|
|
|
$row.toggleClass('hidden');
|
|
|
|
if (!$row.hasClass('hidden')) {
|
|
|
|
$row.find('>input').focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_onClickPermalink: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
return;
|
2016-05-06 11:04:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_onFocusPermalink: function() {
|
|
|
|
this.$('.permalink-field>input').select();
|
|
|
|
},
|
|
|
|
|
2015-08-12 15:30:20 +00: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 11:04:59 +00:00
|
|
|
_makePermalink: function(fileId) {
|
|
|
|
var baseUrl = OC.getProtocol() + '://' + OC.getHost();
|
|
|
|
return baseUrl + OC.generateUrl('/f/{fileId}', {fileId: fileId});
|
|
|
|
},
|
|
|
|
|
2015-08-12 15:30:20 +00: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 14:03:45 +00: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 15:30:20 +00:00
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders this details view
|
|
|
|
*/
|
|
|
|
render: function() {
|
2017-06-09 05:55:27 +00:00
|
|
|
this.trigger('pre-render');
|
|
|
|
|
2015-08-12 15:30:20 +00:00
|
|
|
if (this.model) {
|
|
|
|
var isFavorite = (this.model.get('tags') || []).indexOf(OC.TAG_FAVORITE) >= 0;
|
2018-01-05 18:06:06 +00:00
|
|
|
var availableActions = this._fileActions.get(
|
|
|
|
this.model.get('mimetype'),
|
|
|
|
this.model.get('type'),
|
|
|
|
this.model.get('permissions')
|
|
|
|
);
|
|
|
|
var hasFavoriteAction = 'Favorite' in availableActions;
|
2015-08-12 15:30:20 +00:00
|
|
|
this.$el.html(this.template({
|
2015-08-28 15:51:26 +00:00
|
|
|
type: this.model.isImage()? 'image': '',
|
2015-07-15 14:09:00 +00:00
|
|
|
nameLabel: t('files', 'Name'),
|
2015-08-25 09:29:35 +00:00
|
|
|
name: this.model.get('displayName') || this.model.get('name'),
|
2015-07-15 14:09:00 +00:00
|
|
|
pathLabel: t('files', 'Path'),
|
2015-08-12 15:30:20 +00:00
|
|
|
path: this.model.get('path'),
|
2015-08-25 09:29:35 +00:00
|
|
|
hasSize: this.model.has('size'),
|
2015-07-15 14:09:00 +00:00
|
|
|
sizeLabel: t('files', 'Size'),
|
2015-08-12 15:30:20 +00:00
|
|
|
size: OC.Util.humanFileSize(this.model.get('size'), true),
|
|
|
|
altSize: n('files', '%n byte', '%n bytes', this.model.get('size')),
|
2015-07-15 14:09:00 +00:00
|
|
|
dateLabel: t('files', 'Modified'),
|
2015-08-12 15:30:20 +00:00
|
|
|
altDate: OC.Util.formatDate(this.model.get('mtime')),
|
2016-08-31 15:44:09 +00:00
|
|
|
timestamp: this.model.get('mtime'),
|
2015-08-12 15:30:20 +00:00
|
|
|
date: OC.Util.relativeModifiedDate(this.model.get('mtime')),
|
2018-01-05 18:06:06 +00:00
|
|
|
hasFavoriteAction: hasFavoriteAction,
|
2015-07-15 15:05:25 +00:00
|
|
|
starAltText: isFavorite ? t('files', 'Favorited') : t('files', 'Favorite'),
|
2016-11-21 13:40:34 +00:00
|
|
|
starClass: isFavorite ? 'icon-starred' : 'icon-star',
|
2016-05-06 11:04:59 +00:00
|
|
|
permalink: this._makePermalink(this.model.get('id')),
|
2017-04-13 09:30:35 +00:00
|
|
|
permalinkTitle: t('files', 'Copy direct link (only works for users who have access to this file/folder)')
|
2015-07-15 14:09:00 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
// TODO: we really need OC.Previews
|
2015-07-16 10:49:34 +00:00
|
|
|
var $iconDiv = this.$el.find('.thumbnail');
|
2015-09-11 13:25:42 +00:00
|
|
|
var $container = this.$el.find('.thumbnailContainer');
|
2015-08-12 15:30:20 +00:00
|
|
|
if (!this.model.isDirectory()) {
|
2015-09-15 13:40:42 +00:00
|
|
|
$iconDiv.addClass('icon-loading icon-32');
|
2016-07-04 10:02:07 +00:00
|
|
|
this._previewManager.loadPreview(this.model, $iconDiv, $container);
|
2015-07-15 14:09:00 +00:00
|
|
|
} else {
|
2015-10-28 16:43:36 +00:00
|
|
|
var iconUrl = this.model.get('icon') || OC.MimeType.getIconUrl('dir');
|
|
|
|
$iconDiv.css('background-image', 'url("' + iconUrl + '")');
|
2015-07-15 14:09:00 +00:00
|
|
|
}
|
2015-08-07 10:33:50 +00:00
|
|
|
this.$el.find('[title]').tooltip({placement: 'bottom'});
|
2015-08-12 15:30:20 +00:00
|
|
|
} else {
|
|
|
|
this.$el.empty();
|
2015-07-15 10:06:13 +00:00
|
|
|
}
|
2015-08-12 15:30:20 +00:00
|
|
|
this.delegateEvents();
|
2017-06-09 05:55:27 +00:00
|
|
|
|
|
|
|
this.trigger('post-render');
|
2015-07-15 10:06:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
OCA.Files.MainFileInfoDetailView = MainFileInfoDetailView;
|
|
|
|
})();
|