Merge pull request #20051 from otetard/feature/newfilemenu_extend

Allow Owncloud apps to add new items to the “new” file menu.
This commit is contained in:
Thomas Müller 2015-10-29 23:49:57 +01:00
commit 17dc482e8f
1 changed files with 46 additions and 31 deletions

View File

@ -56,6 +56,28 @@
} }
this._fileList = options && options.fileList; 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) { template: function(data) {
@ -163,7 +185,14 @@
if (checkInput()) { if (checkInput()) {
var newname = $input.val(); 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(); $form.remove();
$target.find('.displayname').removeClass('hidden'); $target.find('.displayname').removeClass('hidden');
OC.hideMenus(); OC.hideMenus();
@ -172,23 +201,21 @@
}, },
/** /**
* Creates a file with the given type and name. * Add a new item menu entry in the New file menu (in
* This calls the matching methods on the attached file list. * last position). By clicking on the item, the
* * `actionHandler` function is called.
* @param {string} fileType file type *
* @param {string} name file name * @param {Object} actionSpec items properties
*/ */
_createFile: function(fileType, name) { addMenuEntry: function(actionSpec) {
switch(fileType) { this._menuItems.push({
case 'file': id: actionSpec.id,
this._fileList.createFile(name); displayName: actionSpec.displayName,
break; templateName: actionSpec.templateName,
case 'folder': iconClass: actionSpec.iconClass,
this._fileList.createDirectory(name); fileType: actionSpec.fileType,
break; actionHandler: actionSpec.actionHandler,
default: });
console.warn('Unknown file type "' + fileType + '"');
}
}, },
/** /**
@ -198,19 +225,7 @@
this.$el.html(this.template({ this.$el.html(this.template({
uploadMaxHumanFileSize: 'TODO', uploadMaxHumanFileSize: 'TODO',
uploadLabel: t('files', 'Upload'), uploadLabel: t('files', 'Upload'),
items: [{ items: this._menuItems
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'
}]
})); }));
OC.Util.scaleFixForIE8(this.$('.svg')); OC.Util.scaleFixForIE8(this.$('.svg'));
}, },