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() {
|
|
|
|
var TEMPLATE =
|
2015-08-12 15:30:20 +00:00
|
|
|
'<a href="#" class="thumbnail action-default"></a><div title="{{name}}" class="fileName ellipsis">{{name}}</div>' +
|
2015-08-04 14:02:18 +00:00
|
|
|
'<div class="file-details ellipsis">' +
|
2015-07-15 15:05:25 +00:00
|
|
|
' <a href="#" ' +
|
|
|
|
' alt="{{starAltText}}"' +
|
2015-07-17 12:09:00 +00:00
|
|
|
' class="action action-favorite favorite">' +
|
2015-07-15 15:05:25 +00:00
|
|
|
' <img class="svg" src="{{starIcon}}" />' +
|
|
|
|
' </a>' +
|
2015-07-17 12:09:00 +00:00
|
|
|
' <span class="size" title="{{altSize}}">{{size}}</span>, <span class="date" title="{{altDate}}">{{date}}</span>' +
|
2015-07-15 15:05:25 +00:00
|
|
|
'</div>';
|
2015-07-15 10:06:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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,
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click a.action-favorite': '_onClickFavorite',
|
|
|
|
'click a.action-default': '_onClickDefaultAction'
|
|
|
|
},
|
2015-07-15 10:06:13 +00:00
|
|
|
|
2015-08-12 15:30:20 +00:00
|
|
|
template: function(data) {
|
2015-07-15 10:06:13 +00:00
|
|
|
if (!this._template) {
|
|
|
|
this._template = Handlebars.compile(TEMPLATE);
|
|
|
|
}
|
2015-08-12 15:30:20 +00:00
|
|
|
return this._template(data);
|
|
|
|
},
|
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) {
|
|
|
|
throw 'Missing requird parameter "fileList"';
|
|
|
|
}
|
|
|
|
if (!this._fileActions) {
|
|
|
|
throw 'Missing requird parameter "fileActions"';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_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();
|
|
|
|
},
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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-07-15 14:09:00 +00:00
|
|
|
nameLabel: t('files', 'Name'),
|
2015-08-12 15:30:20 +00:00
|
|
|
name: 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-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')),
|
|
|
|
date: OC.Util.relativeModifiedDate(this.model.get('mtime')),
|
2015-07-15 15:05:25 +00:00
|
|
|
starAltText: isFavorite ? t('files', 'Favorited') : t('files', 'Favorite'),
|
|
|
|
starIcon: OC.imagePath('core', isFavorite ? 'actions/starred' : 'actions/star')
|
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-08-12 15:30:20 +00:00
|
|
|
if (!this.model.isDirectory()) {
|
2015-07-16 10:49:34 +00:00
|
|
|
// TODO: inject utility class?
|
|
|
|
FileList.lazyLoadPreview({
|
2015-08-12 15:30:20 +00:00
|
|
|
path: this.model.getFullPath(),
|
|
|
|
mime: this.model.get('mimetype'),
|
|
|
|
etag: this.model.get('etag'),
|
2015-08-24 14:58:30 +00:00
|
|
|
x: 75,
|
|
|
|
y: 75,
|
2015-07-16 10:49:34 +00:00
|
|
|
callback: function(previewUrl) {
|
|
|
|
$iconDiv.css('background-image', 'url("' + previewUrl + '")');
|
|
|
|
}
|
2015-07-15 14:09:00 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// TODO: special icons / shared / external
|
|
|
|
$iconDiv.css('background-image', 'url("' + OC.MimeType.getIconUrl('dir') + '")');
|
|
|
|
}
|
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();
|
2015-07-15 10:06:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
OCA.Files.MainFileInfoDetailView = MainFileInfoDetailView;
|
|
|
|
})();
|