summaryrefslogtreecommitdiffstats
path: root/apps/files
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/js/filelist.js22
-rw-r--r--apps/files/js/mainfileinfodetailview.js4
-rw-r--r--apps/files/js/newfilemenu.js77
-rw-r--r--apps/files/l10n/pt_PT.js9
-rw-r--r--apps/files/l10n/pt_PT.json9
-rw-r--r--apps/files/tests/js/filelistSpec.js47
-rw-r--r--apps/files/tests/js/mainfileinfodetailviewSpec.js14
7 files changed, 137 insertions, 45 deletions
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index b6e1f791edd..d1f68d98eab 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -767,7 +767,7 @@
*/
elementToFile: function($el){
$el = $($el);
- return {
+ var data = {
id: parseInt($el.attr('data-id'), 10),
name: $el.attr('data-file'),
mimetype: $el.attr('data-mime'),
@@ -777,6 +777,15 @@
etag: $el.attr('data-etag'),
permissions: parseInt($el.attr('data-permissions'), 10)
};
+ var icon = $el.attr('data-icon');
+ if (icon) {
+ data.icon = icon;
+ }
+ var mountType = $el.attr('data-mounttype');
+ if (mountType) {
+ data.mountType = mountType;
+ }
+ return data;
},
/**
@@ -899,11 +908,12 @@
mtime = parseInt(fileData.mtime, 10),
mime = fileData.mimetype,
path = fileData.path,
+ dataIcon = null,
linkUrl;
options = options || {};
if (isNaN(mtime)) {
- mtime = new Date().getTime()
+ mtime = new Date().getTime();
}
if (type === 'dir') {
@@ -911,6 +921,7 @@
if (fileData.mountType && fileData.mountType.indexOf('external') === 0) {
icon = OC.MimeType.getIconUrl('dir-external');
+ dataIcon = icon;
}
}
@@ -926,6 +937,11 @@
"data-permissions": fileData.permissions || this.getDirectoryPermissions()
});
+ if (dataIcon) {
+ // icon override
+ tr.attr('data-icon', dataIcon);
+ }
+
if (fileData.mountType) {
tr.attr('data-mounttype', fileData.mountType);
}
@@ -1177,7 +1193,7 @@
// display actions
this.fileActions.display(filenameTd, !options.silent, this);
- if (fileData.isPreviewAvailable) {
+ if (fileData.isPreviewAvailable && mime !== 'httpd/unix-directory') {
var iconDiv = filenameTd.find('.thumbnail');
// lazy load / newly inserted td ?
// the typeof check ensures that the default value of animate is true
diff --git a/apps/files/js/mainfileinfodetailview.js b/apps/files/js/mainfileinfodetailview.js
index abf7da52ff4..69c796e492f 100644
--- a/apps/files/js/mainfileinfodetailview.js
+++ b/apps/files/js/mainfileinfodetailview.js
@@ -128,8 +128,8 @@
$iconDiv.addClass('icon-loading icon-32');
this.loadPreview(this.model.getFullPath(), this.model.get('mimetype'), this.model.get('etag'), $iconDiv, $container, this.model.isImage());
} else {
- // TODO: special icons / shared / external
- $iconDiv.css('background-image', 'url("' + OC.MimeType.getIconUrl('dir') + '")');
+ var iconUrl = this.model.get('icon') || OC.MimeType.getIconUrl('dir');
+ $iconDiv.css('background-image', 'url("' + iconUrl + '")');
OC.Util.scaleFixForIE8($iconDiv);
}
this.$el.find('[title]').tooltip({placement: 'bottom'});
diff --git a/apps/files/js/newfilemenu.js b/apps/files/js/newfilemenu.js
index 0a67aba202b..175eb1d1a75 100644
--- a/apps/files/js/newfilemenu.js
+++ b/apps/files/js/newfilemenu.js
@@ -56,6 +56,28 @@
}
this._fileList = options && options.fileList;
+
+ this._menuItems = [{
+ id: 'file',
+ displayName: t('files', 'Text file'),
+ templateName: t('files', 'New text file.txt'),
+ iconClass: 'icon-filetype-text',
+ fileType: 'file',
+ actionHandler: function(name) {
+ self._fileList.createFile(name);
+ }
+ }, {
+ id: 'folder',
+ displayName: t('files', 'Folder'),
+ templateName: t('files', 'New folder'),
+ iconClass: 'icon-folder',
+ fileType: 'folder',
+ actionHandler: function(name) {
+ self._fileList.createDirectory(name);
+ }
+ }];
+
+ OC.Plugins.attach('OCA.Files.NewFileMenu', this);
},
template: function(data) {
@@ -163,7 +185,14 @@
if (checkInput()) {
var newname = $input.val();
- self._createFile(fileType, newname);
+
+ /* Find the right actionHandler that should be called.
+ * Actions is retrieved by using `actionSpec.id` */
+ action = _.filter(self._menuItems, function(item) {
+ return item.id == $target.attr('data-action');
+ }).pop();
+ action.actionHandler(newname);
+
$form.remove();
$target.find('.displayname').removeClass('hidden');
OC.hideMenus();
@@ -172,23 +201,21 @@
},
/**
- * Creates a file with the given type and name.
- * This calls the matching methods on the attached file list.
- *
- * @param {string} fileType file type
- * @param {string} name file name
- */
- _createFile: function(fileType, name) {
- switch(fileType) {
- case 'file':
- this._fileList.createFile(name);
- break;
- case 'folder':
- this._fileList.createDirectory(name);
- break;
- default:
- console.warn('Unknown file type "' + fileType + '"');
- }
+ * Add a new item menu entry in the “New” file menu (in
+ * last position). By clicking on the item, the
+ * `actionHandler` function is called.
+ *
+ * @param {Object} actionSpec item’s properties
+ */
+ addMenuEntry: function(actionSpec) {
+ this._menuItems.push({
+ id: actionSpec.id,
+ displayName: actionSpec.displayName,
+ templateName: actionSpec.templateName,
+ iconClass: actionSpec.iconClass,
+ fileType: actionSpec.fileType,
+ actionHandler: actionSpec.actionHandler,
+ });
},
/**
@@ -198,19 +225,7 @@
this.$el.html(this.template({
uploadMaxHumanFileSize: 'TODO',
uploadLabel: t('files', 'Upload'),
- items: [{
- id: 'file',
- displayName: t('files', 'Text file'),
- templateName: t('files', 'New text file.txt'),
- iconClass: 'icon-filetype-text',
- fileType: 'file'
- }, {
- id: 'folder',
- displayName: t('files', 'Folder'),
- templateName: t('files', 'New folder'),
- iconClass: 'icon-folder',
- fileType: 'folder'
- }]
+ items: this._menuItems
}));
OC.Util.scaleFixForIE8(this.$('.svg'));
},
diff --git a/apps/files/l10n/pt_PT.js b/apps/files/l10n/pt_PT.js
index b395fdd1cd9..5474826994f 100644
--- a/apps/files/l10n/pt_PT.js
+++ b/apps/files/l10n/pt_PT.js
@@ -30,10 +30,10 @@ OC.L10N.register(
"Favorites" : "Favoritos",
"Home" : "Casa",
"Close" : "Fechar",
+ "Upload cancelled." : "Envio cancelado.",
"Unable to upload {filename} as it is a directory or has 0 bytes" : "Incapaz de enviar {filename}, dado que é uma pasta, ou tem 0 bytes",
"Total file size {size1} exceeds upload limit {size2}" : "O tamanho total do ficheiro {size1} excede o limite de carregamento {size2}",
"Not enough free space, you are uploading {size1} but only {size2} is left" : "Não existe espaço suficiente. Está a enviar {size1} mas apenas existe {size2} disponível",
- "Upload cancelled." : "Envio cancelado.",
"Could not get result from server." : "Não foi possível obter o resultado do servidor.",
"File upload is in progress. Leaving the page now will cancel the upload." : "Envio de ficheiro em progresso. Se deixar a página agora, irá cancelar o envio.",
"Actions" : "Ações",
@@ -75,12 +75,12 @@ OC.L10N.register(
"_%n byte_::_%n bytes_" : ["%n byte","%n bytes"],
"Favorited" : "Assinalado como Favorito",
"Favorite" : "Favorito",
- "{newname} already exists" : "{newname} já existe",
- "Upload" : "Enviar",
"Text file" : "Ficheiro de Texto",
"New text file.txt" : "Novo texto ficheiro.txt",
"Folder" : "Pasta",
"New folder" : "Nova Pasta",
+ "{newname} already exists" : "{newname} já existe",
+ "Upload" : "Enviar",
"An error occurred while trying to update the tags" : "Ocorreu um erro ao tentar atualizar as tags",
"A new file or folder has been <strong>created</strong>" : "Foi <strong>criado</strong> um novo ficheiro ou pasta",
"A file or folder has been <strong>changed</strong>" : "Foi <strong>alterado</strong> um ficheiro ou pasta",
@@ -96,6 +96,9 @@ OC.L10N.register(
"%2$s deleted %1$s" : "%2$s apagou %1$s",
"You restored %1$s" : "Restaurou %1$s",
"%2$s restored %1$s" : "%2$s restaurou %1$s",
+ "Changed by %2$s" : "Alterado por %2$s",
+ "Deleted by %2$s" : "Eliminado por %2$s",
+ "Restored by %2$s" : "Restaurado por %2$s",
"%s could not be renamed as it has been deleted" : "Não foi possível renomear %s devido a ter sido eliminado",
"%s could not be renamed" : "%s não pode ser renomeada",
"Upload (max. %s)" : "Enviar (max. %s)",
diff --git a/apps/files/l10n/pt_PT.json b/apps/files/l10n/pt_PT.json
index afa8a67a5d7..44bf606a97f 100644
--- a/apps/files/l10n/pt_PT.json
+++ b/apps/files/l10n/pt_PT.json
@@ -28,10 +28,10 @@
"Favorites" : "Favoritos",
"Home" : "Casa",
"Close" : "Fechar",
+ "Upload cancelled." : "Envio cancelado.",
"Unable to upload {filename} as it is a directory or has 0 bytes" : "Incapaz de enviar {filename}, dado que é uma pasta, ou tem 0 bytes",
"Total file size {size1} exceeds upload limit {size2}" : "O tamanho total do ficheiro {size1} excede o limite de carregamento {size2}",
"Not enough free space, you are uploading {size1} but only {size2} is left" : "Não existe espaço suficiente. Está a enviar {size1} mas apenas existe {size2} disponível",
- "Upload cancelled." : "Envio cancelado.",
"Could not get result from server." : "Não foi possível obter o resultado do servidor.",
"File upload is in progress. Leaving the page now will cancel the upload." : "Envio de ficheiro em progresso. Se deixar a página agora, irá cancelar o envio.",
"Actions" : "Ações",
@@ -73,12 +73,12 @@
"_%n byte_::_%n bytes_" : ["%n byte","%n bytes"],
"Favorited" : "Assinalado como Favorito",
"Favorite" : "Favorito",
- "{newname} already exists" : "{newname} já existe",
- "Upload" : "Enviar",
"Text file" : "Ficheiro de Texto",
"New text file.txt" : "Novo texto ficheiro.txt",
"Folder" : "Pasta",
"New folder" : "Nova Pasta",
+ "{newname} already exists" : "{newname} já existe",
+ "Upload" : "Enviar",
"An error occurred while trying to update the tags" : "Ocorreu um erro ao tentar atualizar as tags",
"A new file or folder has been <strong>created</strong>" : "Foi <strong>criado</strong> um novo ficheiro ou pasta",
"A file or folder has been <strong>changed</strong>" : "Foi <strong>alterado</strong> um ficheiro ou pasta",
@@ -94,6 +94,9 @@
"%2$s deleted %1$s" : "%2$s apagou %1$s",
"You restored %1$s" : "Restaurou %1$s",
"%2$s restored %1$s" : "%2$s restaurou %1$s",
+ "Changed by %2$s" : "Alterado por %2$s",
+ "Deleted by %2$s" : "Eliminado por %2$s",
+ "Restored by %2$s" : "Restaurado por %2$s",
"%s could not be renamed as it has been deleted" : "Não foi possível renomear %s devido a ter sido eliminado",
"%s could not be renamed" : "%s não pode ser renomeada",
"Upload (max. %s)" : "Enviar (max. %s)",
diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js
index 994e1d32844..05e6fcc6122 100644
--- a/apps/files/tests/js/filelistSpec.js
+++ b/apps/files/tests/js/filelistSpec.js
@@ -1166,7 +1166,7 @@ describe('OCA.Files.FileList tests', function() {
it('renders provided icon for file when provided', function() {
var fileData = {
type: 'file',
- name: 'test dir',
+ name: 'test file',
icon: OC.webroot + '/core/img/filetypes/application-pdf.svg',
mimetype: 'application/pdf'
};
@@ -1178,7 +1178,7 @@ describe('OCA.Files.FileList tests', function() {
it('renders preview when no icon was provided and preview is available', function() {
var fileData = {
type: 'file',
- name: 'test dir',
+ name: 'test file',
isPreviewAvailable: true
};
var $tr = fileList.add(fileData);
@@ -1192,7 +1192,7 @@ describe('OCA.Files.FileList tests', function() {
it('renders default file type icon when no icon was provided and no preview is available', function() {
var fileData = {
type: 'file',
- name: 'test dir',
+ name: 'test file',
isPreviewAvailable: false
};
var $tr = fileList.add(fileData);
@@ -1200,6 +1200,47 @@ describe('OCA.Files.FileList tests', function() {
expect(OC.TestUtil.getImageUrl($imgDiv)).toEqual(OC.webroot + '/core/img/filetypes/file.svg');
expect(previewLoadStub.notCalled).toEqual(true);
});
+ it('does not render preview for directories', function() {
+ var fileData = {
+ type: 'dir',
+ mimetype: 'httpd/unix-directory',
+ name: 'test dir',
+ isPreviewAvailable: true
+ };
+ var $tr = fileList.add(fileData);
+ var $td = $tr.find('td.filename');
+ expect(OC.TestUtil.getImageUrl($td.find('.thumbnail'))).toEqual(OC.webroot + '/core/img/filetypes/folder.svg');
+ expect(previewLoadStub.notCalled).toEqual(true);
+ });
+ it('render external storage icon for external storage root', function() {
+ var fileData = {
+ type: 'dir',
+ mimetype: 'httpd/unix-directory',
+ name: 'test dir',
+ isPreviewAvailable: true,
+ mountType: 'external-root'
+ };
+ var $tr = fileList.add(fileData);
+ var $td = $tr.find('td.filename');
+ expect(OC.TestUtil.getImageUrl($td.find('.thumbnail'))).toEqual(OC.webroot + '/core/img/filetypes/folder-external.svg');
+ expect(previewLoadStub.notCalled).toEqual(true);
+ });
+ it('render external storage icon for external storage subdir', function() {
+ var fileData = {
+ type: 'dir',
+ mimetype: 'httpd/unix-directory',
+ name: 'test dir',
+ isPreviewAvailable: true,
+ mountType: 'external'
+ };
+ var $tr = fileList.add(fileData);
+ var $td = $tr.find('td.filename');
+ expect(OC.TestUtil.getImageUrl($td.find('.thumbnail'))).toEqual(OC.webroot + '/core/img/filetypes/folder-external.svg');
+ expect(previewLoadStub.notCalled).toEqual(true);
+ // default icon override
+ expect($tr.attr('data-icon')).toEqual(OC.webroot + '/core/img/filetypes/folder-external.svg');
+ });
+
});
describe('viewer mode', function() {
it('enabling viewer mode hides files table and action buttons', function() {
diff --git a/apps/files/tests/js/mainfileinfodetailviewSpec.js b/apps/files/tests/js/mainfileinfodetailviewSpec.js
index f4403196f2e..460629806c8 100644
--- a/apps/files/tests/js/mainfileinfodetailviewSpec.js
+++ b/apps/files/tests/js/mainfileinfodetailviewSpec.js
@@ -112,6 +112,20 @@ describe('OCA.Files.MainFileInfoDetailView tests', function() {
lazyLoadPreviewStub.restore();
});
+ it('uses icon from model if present in model', function() {
+ var lazyLoadPreviewStub = sinon.stub(fileList, 'lazyLoadPreview');
+ testFileInfo.set('mimetype', 'httpd/unix-directory');
+ testFileInfo.set('icon', OC.MimeType.getIconUrl('dir-external'));
+ view.setFileInfo(testFileInfo);
+
+ expect(lazyLoadPreviewStub.notCalled).toEqual(true);
+
+ expect(view.$el.find('.thumbnail').hasClass('icon-loading')).toEqual(false);
+ expect(view.$el.find('.thumbnail').css('background-image'))
+ .toContain('filetypes/folder-external.svg');
+
+ lazyLoadPreviewStub.restore();
+ });
it('displays thumbnail', function() {
var lazyLoadPreviewStub = sinon.stub(fileList, 'lazyLoadPreview');