Add upload files in contextmenu

pull/1/head
ClemDee 5 years ago
parent 8193a1997c
commit 0e843f0beb

@ -87,6 +87,7 @@ define([
var faDelete = 'fa-eraser'; var faDelete = 'fa-eraser';
var faProperties = 'fa-database'; var faProperties = 'fa-database';
var faTags = 'fa-hashtag'; var faTags = 'fa-hashtag';
var faUploadFiles = 'cptools-file-upload';
var faEmpty = 'fa-trash-o'; var faEmpty = 'fa-trash-o';
var faRestore = 'fa-repeat'; var faRestore = 'fa-repeat';
var faShowParent = 'fa-location-arrow'; var faShowParent = 'fa-location-arrow';
@ -354,6 +355,11 @@ define([
'data-icon': faTags, 'data-icon': faTags,
}, Messages.fc_hashtag)), }, Messages.fc_hashtag)),
$separator.clone()[0], $separator.clone()[0],
h('li', h('a.cp-app-drive-context-uploadfiles.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': faUploadFiles,
}, Messages.uploadButton)),
$separator.clone()[0],
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', { h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.pad, 'data-icon': AppConfig.applicationsIcon.pad,
@ -977,7 +983,10 @@ define([
// Hide the new shared folder menu if we're already in a shared folder // Hide the new shared folder menu if we're already in a shared folder
return manager.isInSharedFolder(currentPath) || APP.disableSF; return manager.isInSharedFolder(currentPath) || APP.disableSF;
} }
return AppConfig.availablePadTypes.indexOf($el.attr('data-type')) === -1; if (className === 'uploadfiles') { return; }
if (className === 'newdoc') {
return AppConfig.availablePadTypes.indexOf($el.attr('data-type')) === -1;
}
}; };
} else { } else {
// In case of multiple selection, we must hide the option if at least one element // In case of multiple selection, we must hide the option if at least one element
@ -1086,7 +1095,7 @@ define([
switch(type) { switch(type) {
case 'content': case 'content':
show = ['newfolder', 'newsharedfolder', 'newdoc']; show = ['newfolder', 'newsharedfolder', 'uploadfiles', 'newdoc'];
break; break;
case 'tree': case 'tree':
show = ['open', 'openro', 'expandall', 'collapseall', 'color', 'download', 'share', 'rename', 'delete', 'deleteowned', 'removesf', 'properties', 'hashtag']; show = ['open', 'openro', 'expandall', 'collapseall', 'color', 'download', 'share', 'rename', 'delete', 'deleteowned', 'removesf', 'properties', 'hashtag'];
@ -2099,6 +2108,23 @@ define([
}); });
return arr; return arr;
}; };
var openUploadFilesModal = function () {
var $input = $('<input>', {
'type': 'file',
'style': 'display: none;',
'multiple': 'multiple'
}).on('change', function (e) {
var files = Util.slice(e.target.files);
files.forEach(function (file) {
var ev = {
target: $content[0],
path: findDropPath($content[0])
};
APP.FM.handleFile(file, ev);
});
});
$input.click();
}
var addNewPadHandlers = function ($block, isInRoot) { var addNewPadHandlers = function ($block, isInRoot) {
// Handlers // Handlers
if (isInRoot) { if (isInRoot) {
@ -2125,24 +2151,7 @@ define([
}); });
}); });
} }
$block.find('a.cp-app-drive-new-upload, li.cp-app-drive-new-upload') $block.find('a.cp-app-drive-new-upload, li.cp-app-drive-new-upload').click(openUploadFilesModal);
.click(function () {
var $input = $('<input>', {
'type': 'file',
'style': 'display: none;',
'multiple': 'multiple'
}).on('change', function (e) {
var files = Util.slice(e.target.files);
files.forEach(function (file) {
var ev = {
target: $content[0],
path: findDropPath($content[0])
};
APP.FM.handleFile(file, ev);
});
});
$input.click();
});
} }
$block.find('a.cp-app-drive-new-doc, li.cp-app-drive-new-doc') $block.find('a.cp-app-drive-new-doc, li.cp-app-drive-new-doc')
.click(function () { .click(function () {
@ -3631,6 +3640,9 @@ define([
manager.addSharedFolder(paths[0].path, obj, refresh); manager.addSharedFolder(paths[0].path, obj, refresh);
}); });
} }
else if ($(this).hasClass("cp-app-drive-context-uploadfiles")) {
openUploadFilesModal();
}
else if ($(this).hasClass("cp-app-drive-context-newdoc")) { else if ($(this).hasClass("cp-app-drive-context-newdoc")) {
var ntype = $(this).data('type') || 'pad'; var ntype = $(this).data('type') || 'pad';
var path2 = manager.isPathIn(currentPath, [TRASH]) ? '' : currentPath; var path2 = manager.isPathIn(currentPath, [TRASH]) ? '' : currentPath;

Loading…
Cancel
Save