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() {
|
|
|
|
/**
|
|
|
|
* @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) {
|
2018-10-01 21:07:09 +03:00
|
|
|
return OCA.Files.Templates['mainfileinfodetailsview'](data);
|
2015-08-12 18:30:20 +03:00
|
|
|
},
|
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);
|
2017-05-10 15:29:20 +03:00
|
|
|
|
|
|
|
this._setupClipboard();
|
2015-08-12 18:30:20 +03:00
|
|
|
},
|
|
|
|
|
2017-05-10 15:29:20 +03: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 14:04:59 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_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() {
|
2017-06-09 08:55:27 +03:00
|
|
|
this.trigger('pre-render');
|
|
|
|
|
2015-08-12 18:30:20 +03:00
|
|
|
if (this.model) {
|
|
|
|
var isFavorite = (this.model.get('tags') || []).indexOf(OC.TAG_FAVORITE) >= 0;
|
2018-01-05 21:06:06 +03: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 18:30:20 +03:00
|
|
|
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')),
|
2018-01-05 21:06:06 +03:00
|
|
|
hasFavoriteAction: hasFavoriteAction,
|
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')),
|
2017-04-13 12:30:35 +03:00
|
|
|
permalinkTitle: t('files', 'Copy direct link (only works for users who have access to this file/folder)')
|
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');
|
2019-09-03 11:07:27 +03:00
|
|
|
if (typeof this.model.get('mountType') !== 'undefined') {
|
|
|
|
iconUrl = OC.MimeType.getIconUrl('dir-' + this.model.get('mountType'))
|
|
|
|
}
|
2015-10-28 19:43:36 +03:00
|
|
|
$iconDiv.css('background-image', 'url("' + iconUrl + '")');
|
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();
|
2017-06-09 08:55:27 +03:00
|
|
|
|
|
|
|
this.trigger('post-render');
|
2015-07-15 13:06:13 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
OCA.Files.MainFileInfoDetailView = MainFileInfoDetailView;
|
|
|
|
})();
|