Refactor context menu in drive

pull/1/head
yflory 7 years ago
parent 4bea1aa2df
commit 2e436f16c9

@ -571,7 +571,6 @@ define([
// RENAME // RENAME
exp.rename = function (path, newName, cb) { exp.rename = function (path, newName, cb) {
if (sframeChan) { if (sframeChan) {
console.log(path, newName);
return void sframeChan.query("Q_DRIVE_USEROBJECT", { return void sframeChan.query("Q_DRIVE_USEROBJECT", {
cmd: "rename", cmd: "rename",
data: { data: {

@ -18,50 +18,6 @@
<div id="cp-app-drive-toolbar"></div> <div id="cp-app-drive-toolbar"></div>
<div id="cp-app-drive-content" tabindex="2"></div> <div id="cp-app-drive-content" tabindex="2"></div>
</div> </div>
<div id="cp-app-drive-context-tree" class="cp-app-drive-context dropdown cp-unselectable">
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" style="display:block;position:static;margin-bottom:5px;">
<li><a tabindex="-1" data-icon="fa-folder-open" class="cp-app-drive-context-open dropdown-item" data-localization="fc_open">Open</a></li>
<li><a tabindex="-1" data-icon="fa-eye" class="cp-app-drive-context-openro dropdown-item" data-localization="fc_open_ro">Open (read-only)</a></li>
<li><a tabindex="-1" data-icon="fa-pencil" class="cp-app-drive-context-rename cp-app-drive-context-editable dropdown-item" data-localization="fc_rename">Rename</a></li>
<li><a tabindex="-1" data-icon="fa-trash" class="cp-app-drive-context-delete cp-app-drive-context-editable dropdown-item" data-localization="fc_delete">Delete</a></li>
<li><a tabindex="-1" data-icon="fa-eraser" class="cp-app-drive-context-deleteowned dropdown-item" data-localization="fc_delete_owned">Delete permanently</a></li>
<li><a tabindex="-1" data-icon="fa-folder" class="cp-app-drive-context-newfolder cp-app-drive-context-editable dropdown-item" data-localization="fc_newfolder">New folder</a></li>
<li><a tabindex="-1" data-icon="fa-database" class="cp-app-drive-context-properties dropdown-item" data-localization="fc_prop">Properties</a></li>
<li><a tabindex="-1" data-icon="fa-hashtag" class="cp-app-drive-context-hashtag dropdown-item" data-localization="fc_hashtag">Tags</a></li>
</ul>
</div>
<div id="cp-app-drive-context-content" class="cp-app-drive-context dropdown cp-unselectable">
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" style="display:block;position:static;margin-bottom:5px;">
<li><a tabindex="-1" data-icon="fa-folder" class="cp-app-drive-context-newfolder cp-app-drive-context-editable dropdown-item" data-localization="fc_newfolder">New folder</a></li>
<li><a tabindex="-1" data-icon="fa-file-word-o" class="cp-app-drive-context-newdoc cp-app-drive-context-own cp-app-drive-context-editable dropdown-item" data-type="pad" data-localization="button_newpad">New pad</a></li>
<li><a tabindex="-1" data-icon="fa-file-code-o" class="cp-app-drive-context-newdoc cp-app-drive-context-own cp-app-drive-context-editable dropdown-item" data-type="code" data-localization="button_newcode">New code</a></li>
<li><a tabindex="-1" data-icon="fa-file-powerpoint-o" class="cp-app-drive-context-newdoc cp-app-drive-context-own cp-app-drive-context-editable dropdown-item" data-type="slide" data-localization="button_newslide">New slide</a></li>
<li><a tabindex="-1" data-icon="fa-calendar" class="cp-app-drive-context-newdoc cp-app-drive-context-own cp-app-drive-context-editable dropdown-item" data-type="poll" data-localization="button_newpoll">New poll</a></li>
<li><a tabindex="-1" data-icon="fa-paint-brush" class="cp-app-drive-context-newdoc cp-app-drive-context-own cp-app-drive-context-editable dropdown-item" data-type="whiteboard" data-localization="button_newwhiteboard">New whiteboard</a></li>
</ul>
</div>
<div id="cp-app-drive-context-default" class="cp-app-drive-context dropdown cp-unselectable">
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" style="display:block;position:static;margin-bottom:5px;">
<li><a tabindex="-1" data-icon="fa-folder-open" class="cp-app-drive-context-open dropdown-item" data-localization="fc_open">Open</a></li>
<li><a tabindex="-1" data-icon="fa-eye" class="cp-app-drive-context-openro dropdown-item" data-localization="fc_open_ro">Open (read-only)</a></li>
<li><a tabindex="-1" data-icon="fa-trash" class="cp-app-drive-context-delete dropdown-item" data-localization="fc_delete">Delete</a></li>
<li><a tabindex="-1" data-icon="fa-eraser" class="cp-app-drive-context-deleteowned dropdown-item" data-localization="fc_delete_owned">Delete permanently</a></li>
<li><a tabindex="-1" data-icon="fa-database" class="cp-app-drive-context-properties dropdown-item" data-localization="fc_prop">Properties</a></li>
<li><a tabindex="-1" data-icon="fa-hashtag" class="cp-app-drive-context-hashtag dropdown-item" data-localization="fc_hashtag">Tags</a></li>
</ul>
</div>
<div id="cp-app-drive-context-trashtree" class="cp-app-drive-context dropdown cp-unselectable">
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" style="display:block;position:static;margin-bottom:5px;">
<li><a tabindex="-1" data-icon="fa-trash-o" class="cp-app-drive-context-empty cp-app-drive-context-editable dropdown-item" data-localization="fc_empty">Empty the trash</a></li>
</ul>
</div>
<div id="cp-app-drive-context-trash" class="cp-app-drive-context dropdown cp-unselectable">
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" style="display:block;position:static;margin-bottom:5px;">
<li><a tabindex="-1" data-icon="fa-eraser" class="cp-app-drive-context-remove cp-app-drive-context-editable dropdown-item" data-localization="fc_remove">Delete permanently</a></li>
<li><a tabindex="-1" data-icon="fa-repeat" class="cp-app-drive-context-restore cp-app-drive-context-editable dropdown-item" data-localization="fc_restore">Restore</a></li>
<li><a tabindex="-1" data-icon="fa-database" class="cp-app-drive-context-properties dropdown-item" data-localization="fc_prop">Properties</a></li>
</ul>
</div>
</div> </div>
</body> </body>
</html> </html>

@ -11,6 +11,7 @@ define([
'/bower_components/nthen/index.js', '/bower_components/nthen/index.js',
'/common/sframe-common.js', '/common/sframe-common.js',
'/common/common-realtime.js', '/common/common-realtime.js',
'/common/hyperscript.js',
'/common/userObject.js', '/common/userObject.js',
'/customize/application_config.js', '/customize/application_config.js',
'/bower_components/chainpad-listmap/chainpad-listmap.js', '/bower_components/chainpad-listmap/chainpad-listmap.js',
@ -32,6 +33,7 @@ define([
nThen, nThen,
SFCommon, SFCommon,
CommonRealtime, CommonRealtime,
h,
FO, FO,
AppConfig, AppConfig,
Listmap, Listmap,
@ -155,19 +157,30 @@ define([
}; };
// Icons // Icons
var faFolder = 'fa-folder';
var faFolderOpen = 'fa-folder-open';
var faReadOnly = 'fa-eye';
var faRename = 'fa-pencil';
var faTrash = 'fa-trash';
var faDelete = 'fa-eraser';
var faProperties = 'fa-database';
var faTags = 'fa-hashtag';
var faEmpty = 'fa-trash-o';
var faRestore = 'fa-repeat';
var faShowParent = 'fa-location-arrow';
var $folderIcon = $('<span>', { var $folderIcon = $('<span>', {
"class": "fa fa-folder cp-app-drive-icon-folder cp-app-drive-content-icon" "class": faFolder + " fa cp-app-drive-icon-folder cp-app-drive-content-icon"
}); });
//var $folderIcon = $('<img>', {src: "/customize/images/icons/folder.svg", "class": "folder icon"}); //var $folderIcon = $('<img>', {src: "/customize/images/icons/folder.svg", "class": "folder icon"});
var $folderEmptyIcon = $folderIcon.clone(); var $folderEmptyIcon = $folderIcon.clone();
var $folderOpenedIcon = $('<span>', {"class": "fa fa-folder-open cp-app-drive-icon-folder"}); var $folderOpenedIcon = $('<span>', {"class": faFolderOpen + " fa cp-app-drive-icon-folder"});
//var $folderOpenedIcon = $('<img>', {src: "/customize/images/icons/folderOpen.svg", "class": "folder icon"}); //var $folderOpenedIcon = $('<img>', {src: "/customize/images/icons/folderOpen.svg", "class": "folder icon"});
var $folderOpenedEmptyIcon = $folderOpenedIcon.clone(); var $folderOpenedEmptyIcon = $folderOpenedIcon.clone();
//var $upIcon = $('<span>', {"class": "fa fa-arrow-circle-up"}); //var $upIcon = $('<span>', {"class": "fa fa-arrow-circle-up"});
var $unsortedIcon = $('<span>', {"class": "fa fa-files-o"}); var $unsortedIcon = $('<span>', {"class": "fa fa-files-o"});
var $templateIcon = $('<span>', {"class": "fa fa-cubes"}); var $templateIcon = $('<span>', {"class": "fa fa-cubes"});
var $recentIcon = $('<span>', {"class": "fa fa-clock-o"}); var $recentIcon = $('<span>', {"class": "fa fa-clock-o"});
var $trashIcon = $('<span>', {"class": "fa fa-trash"}); var $trashIcon = $('<span>', {"class": "fa " + faTrash});
var $trashEmptyIcon = $('<span>', {"class": "fa fa-trash-o"}); var $trashEmptyIcon = $('<span>', {"class": "fa fa-trash-o"});
//var $collapseIcon = $('<span>', {"class": "fa fa-minus-square-o cp-app-drive-icon-expcol"}); //var $collapseIcon = $('<span>', {"class": "fa fa-minus-square-o cp-app-drive-icon-expcol"});
var $expandIcon = $('<span>', {"class": "fa fa-plus-square-o cp-app-drive-icon-expcol"}); var $expandIcon = $('<span>', {"class": "fa fa-plus-square-o cp-app-drive-icon-expcol"});
@ -181,7 +194,7 @@ define([
var $searchIcon = $('<span>', {"class": "fa fa-search cp-app-drive-tree-search-con"}); var $searchIcon = $('<span>', {"class": "fa fa-search cp-app-drive-tree-search-con"});
var $addIcon = $('<span>', {"class": "fa fa-plus"}); var $addIcon = $('<span>', {"class": "fa fa-plus"});
var $renamedIcon = $('<span>', {"class": "fa fa-flag"}); var $renamedIcon = $('<span>', {"class": "fa fa-flag"});
var $readonlyIcon = $('<span>', {"class": "fa fa-eye"}); var $readonlyIcon = $('<span>', {"class": "fa " + faReadOnly});
var $ownedIcon = $('<span>', {"class": "fa fa-id-card-o"}); var $ownedIcon = $('<span>', {"class": "fa fa-id-card-o"});
var $ownerIcon = $('<span>', {"class": "fa fa-id-card"}); var $ownerIcon = $('<span>', {"class": "fa fa-id-card"});
@ -200,6 +213,91 @@ define([
}); });
}; };
var createContextMenu = function () {
var menu = h('div.cp-app-drive-context.dropdown.cp-unselectable', [
h('ul.dropdown-menu', {
'role': 'menu',
'aria-labelledby': 'dropdownMenu',
'style': 'display:block;position:static;margin-bottom:5px;'
}, [
h('li', h('a.cp-app-drive-context-open.dropdown-item', {
'tabindex': '-1',
'data-icon': faFolderOpen,
}, Messages.fc_open)),
h('li', h('a.cp-app-drive-context-openro.dropdown-item', {
'tabindex': '-1',
'data-icon': faReadOnly,
}, Messages.fc_open_ro)),
h('li', h('a.cp-app-drive-context-openparent.dropdown-item', {
'tabindex': '-1',
'data-icon': faShowParent,
}, Messages.fm_openParent)),
h('li', h('a.cp-app-drive-context-newfolder.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': faFolder,
}, Messages.fc_newfolder)),
h('li', h('a.cp-app-drive-context-hashtag.dropdown-item', {
'tabindex': '-1',
'data-icon': faTags,
}, Messages.fc_hashtag)),
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable.cp-app-drive-context-own', {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.pad,
'data-type': 'pad'
}, Messages.button_newpad)),
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable.cp-app-drive-context-own', {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.code,
'data-type': 'code'
}, Messages.button_newcode)),
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable.cp-app-drive-context-own', {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.slide,
'data-type': 'slide'
}, Messages.button_newslide)),
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable.cp-app-drive-context-own', {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.poll,
'data-type': 'poll'
}, Messages.button_newpoll)),
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable.cp-app-drive-context-own', {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.whiteboard,
'data-type': 'whiteboard'
}, Messages.button_newwhiteboard)),
h('li', h('a.cp-app-drive-context-empty.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': faEmpty,
}, Messages.fc_empty)),
h('li', h('a.cp-app-drive-context-restore.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': faRestore,
}, Messages.fc_restore)),
h('li', h('a.cp-app-drive-context-rename.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': faRename,
}, Messages.fc_rename)),
h('li', h('a.cp-app-drive-context-delete.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': faTrash,
}, Messages.fc_delete)),
h('li', h('a.cp-app-drive-context-deleteowned.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': faDelete,
}, Messages.fc_delete_owned)),
h('li', h('a.cp-app-drive-context-remove.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': faDelete,
}, Messages.fc_remove)),
h('li', h('a.cp-app-drive-context-properties.dropdown-item', {
'tabindex': '-1',
'data-icon': faProperties,
}, Messages.fc_prop)),
])
]);
return $(menu);
};
var andThen = function (common, proxy) { var andThen = function (common, proxy) {
var files = proxy.drive; var files = proxy.drive;
var metadataMgr = common.getMetadataMgr(); var metadataMgr = common.getMetadataMgr();
@ -227,7 +325,8 @@ define([
var $content = APP.$content = $("#cp-app-drive-content"); var $content = APP.$content = $("#cp-app-drive-content");
var $appContainer = $(".cp-app-drive-container"); var $appContainer = $(".cp-app-drive-container");
var $driveToolbar = $("#cp-app-drive-toolbar"); var $driveToolbar = $("#cp-app-drive-toolbar");
var $contextMenu = $("#cp-app-drive-context-tree"); var $contextMenu = createContextMenu().appendTo($appContainer);
var $contentContextMenu = $("#cp-app-drive-context-content"); var $contentContextMenu = $("#cp-app-drive-context-content");
var $defaultContextMenu = $("#cp-app-drive-context-default"); var $defaultContextMenu = $("#cp-app-drive-context-default");
var $trashTreeContextMenu = $("#cp-app-drive-context-trashtree"); var $trashTreeContextMenu = $("#cp-app-drive-context-trashtree");
@ -638,68 +737,112 @@ define([
},0); },0);
}; };
var filterContextMenu = function ($menu, paths) { var filterContextMenu = function (type, paths) {
//var path = $element.data('path');
if (!paths || paths.length === 0) { logError('no paths'); } if (!paths || paths.length === 0) { logError('no paths'); }
var hide = []; $contextMenu.find('li').hide();
var hasFolder = false;
paths.forEach(function (p) { var show = [];
var path = p.path; var filter;
var $element = p.element;
if (path.length === 1) { if (type === "content") {
// Can't rename or delete root elements filter = function ($el, className) {
hide.push($menu.find('a.cp-app-drive-context-rename')); if (className === 'newfolder') { return; }
hide.push($menu.find('a.cp-app-drive-context-delete')); return AppConfig.availablePadTypes.indexOf($el.attr('data-type')) === -1;
} };
if (!APP.editable) { } else {
hide.push($menu.find('a.cp-app-drive-context-editable')); // In case of multiple selection, we must hide the option if at least one element
} // is not compatible
if (!isOwnDrive()) { var containsFolder = false;
hide.push($menu.find('a.cp-app-drive-context-own')); var hide = [];
} paths.forEach(function (p) {
if (!$element.is('.cp-app-drive-element-owned')) { var path = p.path;
hide.push($menu.find('a.cp-app-drive-context-deleteowned')); var $element = p.element;
} if (path.length === 1) {
if ($element.is('.cp-app-drive-element-notrash')) { // Can't rename or delete root elements
hide.push($menu.find('a.cp-app-drive-context-delete')); hide.push('delete');
} hide.push('rename');
if ($element.is('.cp-app-drive-element-file')) {
// No folder in files
hide.push($menu.find('a.cp-app-drive-context-newfolder'));
if ($element.is('.cp-app-drive-element-readonly')) {
// Keep only open readonly
hide.push($menu.find('a.cp-app-drive-context-open'));
} else if ($element.is('.cp-app-drive-element-noreadonly')) {
// Keep only open readonly
hide.push($menu.find('a.cp-app-drive-context-openro'));
} }
} else { if (!$element.is('.cp-app-drive-element-owned')) {
if (hasFolder) { hide.push('deleteowned');
// More than 1 folder selected: cannot create a new subfolder }
hide.push($menu.find('a.cp-app-drive-context-newfolder')); if ($element.is('.cp-app-drive-element-notrash')) {
// We can't delete elements in virtual categories
hide.push('delete');
} else {
// We can only open parent in virtual categories
hide.push('openparent');
}
if ($element.is('.cp-app-drive-element-file')) {
// No folder in files
hide.push('newfolder');
if ($element.is('.cp-app-drive-element-readonly')) {
hide.push('open'); // Remove open 'edit' mode
} else if ($element.is('.cp-app-drive-element-noreadonly')) {
hide.push('openro'); // Remove open 'view' mode
}
} else { // it's a folder
if (containsFolder) {
// More than 1 folder selected: cannot create a new subfolder
hide.push('newfolder');
}
containsFolder = true;
hide.push('openro');
hide.push('properties');
hide.push('hashtag');
}
// If we're in the trash, hide restore and properties for non-root elements
if (type === "trash" && path && path.length > 4) {
hide.push('restore');
hide.push('properties');
} }
hasFolder = true; });
hide.push($menu.find('a.cp-app-drive-context-openro')); if (paths.length > 1) {
hide.push($menu.find('a.cp-app-drive-context-properties')); hide.push('restore');
hide.push($menu.find('a.cp-app-drive-context-hashtag')); hide.push('properties');
hide.push('rename');
hide.push('openparent');
} }
// If we're in the trash, hide restore and properties for non-root elements if (containsFolder && paths.length > 1) {
if ($menu.find('a.cp-app-drive-context-restore').length && path && path.length > 4) { // Cannot open multiple folders
hide.push($menu.find('a.cp-app-drive-context-restore')); hide.push('open');
hide.push($menu.find('a.cp-app-drive-context-properties'));
} }
});
if (paths.length > 1) { filter = function ($el, className) {
hide.push($menu.find('a.cp-app-drive-context-restore')); if (hide.indexOf(className) !== -1) { return true; }
hide.push($menu.find('a.cp-app-drive-context-properties')); };
hide.push($menu.find('a.cp-app-drive-context-rename'));
} }
if (hasFolder && paths.length > 1) {
// Cannot open multiple folders switch(type) {
hide.push($menu.find('a.cp-app-drive-context-open')); case 'content':
show = ['newfolder', 'newdoc'];
break;
case 'tree':
show = ['open', 'openro', 'rename', 'delete', 'deleteowned', 'newfolder',
'properties', 'hashtag'];
break;
case 'default':
show = ['open', 'openro', 'openparent', 'delete', 'deleteowned', 'properties', 'hashtag'];
break;
case 'trashtree': {
show = ['empty'];
break;
}
case 'trash': {
show = ['remove', 'restore', 'properties'];
}
} }
return hide;
var filtered = [];
show.forEach(function (className) {
var $el = $contextMenu.find('.cp-app-drive-context-' + className);
if (!APP.editable && $el.is('.cp-app-drive-context-editable')) { return; }
if (!isOwnDrive && $el.is('.cp-app-drive-context-own')) { return; }
if (filter($el, className)) { return; }
$el.parent('li').show();
filtered.push('.cp-app-drive-context-' + className);
});
return filtered;
}; };
var getSelectedPaths = function ($element) { var getSelectedPaths = function ($element) {
@ -763,16 +906,13 @@ define([
$container.html(''); $container.html('');
var $element = $li.length === 1 ? $li : $($li[0]); var $element = $li.length === 1 ? $li : $($li[0]);
var paths = getSelectedPaths($element); var paths = getSelectedPaths($element);
var $menu = $element.data('context'); var menuType = $element.data('context');
if (!$menu) { return; } if (!menuType) { return; }
//var actions = []; //var actions = [];
var $actions = $menu.find('a'); var toShow = filterContextMenu(menuType, paths);
var toHide = filterContextMenu($menu, paths); var $actions = $contextMenu.find('a');
$actions = $actions.filter(function (i, el) { $actions = $actions.filter(function (i, el) {
for (var j = 0; j < toHide.length; j++) { return toShow.some(function (className) { return $(el).is(className); });
if ($(el).is(toHide[j])) { return false; }
}
return true;
}); });
$actions.each(function (i, el) { $actions.each(function (i, el) {
var $a = $('<button>', {'class': 'cp-app-drive-element'}); var $a = $('<button>', {'class': 'cp-app-drive-element'});
@ -863,7 +1003,8 @@ define([
updateContextButton(); updateContextButton();
}; };
var displayMenu = function (e, $menu) { var displayMenu = function (e) {
var $menu = $contextMenu;
$menu.css({ display: "block" }); $menu.css({ display: "block" });
if (APP.mobile()) { return; } if (APP.mobile()) { return; }
var h = $menu.outerHeight(); var h = $menu.outerHeight();
@ -905,101 +1046,49 @@ define([
}; };
// Open the selected context menu on the closest "li" element // Open the selected context menu on the closest "li" element
var openContextMenu = function (e, $menu) { var openContextMenu = function (type) {
APP.hideMenu(); return function (e) {
e.stopPropagation(); APP.hideMenu();
e.stopPropagation();
var $element = findDataHolder($(e.target));
if (!$element.length) {
logError("Unable to locate the .element tag", e.target);
$menu.hide();
log(Messages.fm_contextMenuError);
return false;
}
if (!$element.hasClass('cp-app-drive-element-selected')) { //paths.length === 1) {
onElementClick(undefined, $element);
}
var paths = getSelectedPaths($element);
var toHide = filterContextMenu($menu, paths);
toHide.forEach(function ($a) {
$a.parent('li').hide();
});
displayMenu(e, $menu); var paths;
if (type === 'content') {
paths = [{path: $(e.target).closest('#' + FOLDER_CONTENT_ID).data('path')}];
if (!paths) { return; }
removeSelected();
} else {
var $element = findDataHolder($(e.target));
if ($menu.find('li:visible').length === 0) { if (type === 'trash' && !$element.data('path')) { return; }
debug("No visible element in the context menu. Abort.");
$menu.hide();
return true;
}
$menu.find('a').data('paths', paths); if (!$element.length) {
//$menu.find('a').data('path', path); logError("Unable to locate the .element tag", e.target);
//$menu.find('a').data('element', $element); log(Messages.fm_contextMenuError);
return false; return false;
}; }
var openDirectoryContextMenu = function (e) {
$contextMenu.find('li').show();
openContextMenu(e, $contextMenu);
return false;
};
var openDefaultContextMenu = function (e) { if (!$element.hasClass('cp-app-drive-element-selected')) {
$defaultContextMenu.find('li').show(); onElementClick(undefined, $element);
openContextMenu(e, $defaultContextMenu); }
return false;
};
var openTrashTreeContextMenu = function (e) { paths = getSelectedPaths($element);
removeSelected(); }
$trashTreeContextMenu.find('li').show();
openContextMenu(e, $trashTreeContextMenu);
return false;
};
var openTrashContextMenu = function (e) { $contextMenu.attr('data-menu-type', type);
var path = findDataHolder($(e.target)).data('path');
if (!path) { return; }
$trashContextMenu.find('li').show();
openContextMenu(e, $trashContextMenu);
return false;
};
var openContentContextMenu = function (e) { filterContextMenu(type, paths);
APP.hideMenu();
e.stopPropagation();
var path = $(e.target).closest('#' + FOLDER_CONTENT_ID).data('path');
if (!path) { return; }
var $menu = $contentContextMenu;
removeSelected();
if (!APP.editable) { displayMenu(e);
$menu.find('a.cp-app-drive-context-editable').parent('li').hide();
}
if (!isOwnDrive()) {
$menu.find('a.cp-app-drive-context-own').parent('li').hide();
}
$menu.find('[data-type]').each(function (idx, el) { if ($contextMenu.find('li:visible').length === 0) {
if (AppConfig.availablePadTypes.indexOf($(el).attr('data-type')) === -1) { debug("No visible element in the context menu. Abort.");
$(el).hide(); $contextMenu.hide();
return true;
} }
});
displayMenu(e, $menu);
if ($menu.find('li:visible').length === 0) {
debug("No visible element in the context menu. Abort.");
$menu.hide();
return true;
}
$menu.find('a').data('path', path); $contextMenu.data('paths', paths);
return false; return false;
};
}; };
var getElementName = function (path) { var getElementName = function (path) {
@ -1303,11 +1392,11 @@ define([
onElementClick(e, $element, newPath); onElementClick(e, $element, newPath);
}); });
if (!isTrash) { if (!isTrash) {
$element.contextmenu(openDirectoryContextMenu); $element.contextmenu(openContextMenu('tree'));
$element.data('context', $contextMenu); $element.data('context', 'tree');
} else { } else {
$element.contextmenu(openTrashContextMenu); $element.contextmenu(openContextMenu('trash'));
$element.data('context', $trashContextMenu); $element.data('context', 'trash');
} }
var isNewFolder = APP.newFolder && filesOp.comparePath(newPath, APP.newFolder); var isNewFolder = APP.newFolder && filesOp.comparePath(newPath, APP.newFolder);
if (isNewFolder) { if (isNewFolder) {
@ -1911,8 +2000,8 @@ define([
e.stopPropagation(); e.stopPropagation();
onElementClick(e, $element, path); onElementClick(e, $element, path);
}); });
$element.contextmenu(openDefaultContextMenu); $element.contextmenu(openContextMenu('default'));
$element.data('context', $defaultContextMenu); $element.data('context', 'default');
if (draggable) { if (draggable) {
addDragAndDropHandlers($element, path, false, false); addDragAndDropHandlers($element, path, false, false);
} }
@ -1951,8 +2040,8 @@ define([
e.stopPropagation(); e.stopPropagation();
onElementClick(e, $element); onElementClick(e, $element);
}); });
$element.contextmenu(openDefaultContextMenu); $element.contextmenu(openContextMenu('default'));
$element.data('context', $defaultContextMenu); $element.data('context', 'default');
$container.append($element); $container.append($element);
}); });
}; };
@ -2082,8 +2171,8 @@ define([
e.stopPropagation(); e.stopPropagation();
onElementClick(e, $element, path); onElementClick(e, $element, path);
}); });
$element.contextmenu(openDefaultContextMenu); $element.contextmenu(openContextMenu('default'));
$element.data('context', $defaultContextMenu); $element.data('context', 'default');
/*if (draggable) { /*if (draggable) {
addDragAndDropHandlers($element, path, false, false); addDragAndDropHandlers($element, path, false, false);
}*/ }*/
@ -2122,8 +2211,8 @@ define([
e.stopPropagation(); e.stopPropagation();
onElementClick(e, $element); onElementClick(e, $element);
}); });
$element.contextmenu(openDefaultContextMenu); $element.contextmenu(openContextMenu('default'));
$element.data('context', $defaultContextMenu); $element.data('context', 'default');
$container.append($element); $container.append($element);
}); });
}; };
@ -2261,7 +2350,7 @@ define([
} else if (isOwned) { } else if (isOwned) {
displayOwned($list); displayOwned($list);
} else { } else {
$dirContent.contextmenu(openContentContextMenu); $dirContent.contextmenu(openContextMenu('content'));
if (filesOp.hasSubfolder(root)) { $list.append($folderHeader); } if (filesOp.hasSubfolder(root)) { $list.append($folderHeader); }
// display sub directories // display sub directories
var keys = Object.keys(root); var keys = Object.keys(root);
@ -2374,7 +2463,7 @@ define([
} }
$rootElement.addClass('cp-app-drive-tree-root'); $rootElement.addClass('cp-app-drive-tree-root');
$rootElement.find('>.cp-app-drive-element-row') $rootElement.find('>.cp-app-drive-element-row')
.contextmenu(openDirectoryContextMenu); .contextmenu(openContextMenu('tree'));
$('<ul>', {'class': 'cp-app-drive-tree-docs'}) $('<ul>', {'class': 'cp-app-drive-tree-docs'})
.append($rootElement).appendTo($container); .append($rootElement).appendTo($container);
$container = $rootElement; $container = $rootElement;
@ -2396,7 +2485,7 @@ define([
(isCurrentFolder ? $folderOpenedIcon : $folderIcon); (isCurrentFolder ? $folderOpenedIcon : $folderIcon);
var $element = createTreeElement(key, $icon.clone(), newPath, true, true, subfolder, isCurrentFolder); var $element = createTreeElement(key, $icon.clone(), newPath, true, true, subfolder, isCurrentFolder);
$element.appendTo($list); $element.appendTo($list);
$element.find('>.cp-app-drive-element-row').contextmenu(openDirectoryContextMenu); $element.find('>.cp-app-drive-element-row').contextmenu(openContextMenu('tree'));
createTree($element, newPath); createTree($element, newPath);
}); });
}; };
@ -2425,7 +2514,8 @@ define([
var isOpened = filesOp.comparePath(path, currentPath); var isOpened = filesOp.comparePath(path, currentPath);
var $trashElement = createTreeElement(TRASH_NAME, $icon, [TRASH], false, true, false, isOpened); var $trashElement = createTreeElement(TRASH_NAME, $icon, [TRASH], false, true, false, isOpened);
$trashElement.addClass('root'); $trashElement.addClass('root');
$trashElement.find('>.cp-app-drive-element-row').contextmenu(openTrashTreeContextMenu); $trashElement.find('>.cp-app-drive-element-row')
.contextmenu(openContextMenu('trashtree'));
var $trashList = $('<ul>', { 'class': 'cp-app-drive-tree-category' }) var $trashList = $('<ul>', { 'class': 'cp-app-drive-tree-category' })
.append($trashElement); .append($trashElement);
$container.append($trashList); $container.append($trashList);
@ -2588,22 +2678,44 @@ define([
UIElements.getProperties(common, data, cb); UIElements.getProperties(common, data, cb);
}; };
if (!APP.loggedIn) {
$contextMenu.find('.cp-app-drive-context-delete').text(Messages.fc_remove)
.attr('data-icon', 'fa-eraser');
}
var deletePaths = function (paths) {
var pathsList = [];
paths.forEach(function (p) { pathsList.push(p.path); });
var msg = Messages._getKey("fm_removeSeveralPermanentlyDialog", [paths.length]);
if (paths.length === 1) {
msg = Messages.fm_removePermanentlyDialog;
}
UI.confirm(msg, function(res) {
$(window).focus();
if (!res) { return; }
filesOp.delete(pathsList, refresh);
});
};
$contextMenu.on("click", "a", function(e) { $contextMenu.on("click", "a", function(e) {
e.stopPropagation(); e.stopPropagation();
var paths = $(this).data('paths'); var paths = $contextMenu.data('paths');
var pathsList = [];
var type = $contextMenu.attr('data-menu-type');
var el; var el;
if (paths.length === 0) { if (paths.length === 0) {
log(Messages.fm_forbidden); log(Messages.fm_forbidden);
debug("Directory context menu on a forbidden or unexisting element. ", paths); debug("Context menu on a forbidden or unexisting element. ", paths);
return; return;
} }
if ($(this).hasClass("cp-app-drive-context-rename")) { if ($(this).hasClass("cp-app-drive-context-rename")) {
if (paths.length !== 1) { return; } if (paths.length !== 1) { return; }
displayRenameInput(paths[0].element, paths[0].path); displayRenameInput(paths[0].element, paths[0].path);
} }
else if($(this).hasClass("cp-app-drive-context-delete")) { else if($(this).hasClass("cp-app-drive-context-delete")) {
var pathsList = []; if (!APP.loggedIn) {
return void deletePaths(paths);
}
paths.forEach(function (p) { pathsList.push(p.path); }); paths.forEach(function (p) { pathsList.push(p.path); });
moveElements(pathsList, [TRASH], false, refresh); moveElements(pathsList, [TRASH], false, refresh);
} }
@ -2640,108 +2752,37 @@ define([
else if ($(this).hasClass('cp-app-drive-context-openro')) { else if ($(this).hasClass('cp-app-drive-context-openro')) {
paths.forEach(function (p) { paths.forEach(function (p) {
var el = filesOp.find(p.path); var el = filesOp.find(p.path);
if (filesOp.isFolder(el)) { return; } if (filesOp.isPathIn(p.path, [FILES_DATA])) { el = el.href; }
if (!el || filesOp.isFolder(el)) { return; }
var roUrl = getReadOnlyUrl(el); var roUrl = getReadOnlyUrl(el);
openFile(null, roUrl); openFile(null, roUrl);
}); });
} }
else if ($(this).hasClass('cp-app-drive-context-newfolder')) { else if ($(this).hasClass('cp-app-drive-context-newfolder')) {
if (paths.length !== 1) { return; } if (paths.length !== 1) { return; }
var onCreated = function (err, info) { var onFolderCreated = function (err, info) {
if (err) { return void logError(err); } if (err) { return void logError(err); }
APP.newFolder = info.newPath; APP.newFolder = info.newPath;
APP.displayDirectory(paths[0].path); APP.displayDirectory(paths[0].path);
}; };
filesOp.addFolder(paths[0].path, null, onCreated); filesOp.addFolder(paths[0].path, null, onFolderCreated);
}
else if ($(this).hasClass("cp-app-drive-context-properties")) {
if (paths.length !== 1) { return; }
el = filesOp.find(paths[0].path);
getProperties(el, function (e, $prop) {
if (e) { return void logError(e); }
UI.alert($prop[0], undefined, true);
});
} }
else if ($(this).hasClass("cp-app-drive-context-hashtag")) { else if ($(this).hasClass("cp-app-drive-context-newdoc")) {
if (paths.length !== 1) { return; } var ntype = $(this).data('type') || 'pad';
el = filesOp.find(paths[0].path); var path2 = filesOp.isPathIn(currentPath, [TRASH]) ? '' : currentPath;
var data = filesOp.getFileData(el); common.sessionStorage.put(Constants.newPadPathKey, path2, function () {
if (!data) { return void console.error("Expected to find a file"); } common.openURL('/' + ntype + '/');
var href = data.href;
common.updateTags(href);
}
APP.hideMenu();
});
if (!APP.loggedIn) {
$defaultContextMenu.find('.cp-app-drive-context-delete').text(Messages.fc_remove)
.attr('data-icon', 'fa-eraser');
}
$defaultContextMenu.on("click", "a", function(e) {
e.stopPropagation();
var paths = $(this).data('paths');
var el;
if (paths.length === 0) {
log(Messages.fm_forbidden);
debug("Context menu on a forbidden or unexisting element. ", paths);
return;
}
if ($(this).hasClass('cp-app-drive-context-open')) {
paths.forEach(function (p) {
var $element = p.element;
$element.dblclick();
});
}
else if ($(this).hasClass('cp-app-drive-context-openro')) {
paths.forEach(function (p) {
var el = filesOp.find(p.path);
if (filesOp.isPathIn(p.path, [FILES_DATA])) { el = el.href; }
if (!el || filesOp.isFolder(el)) { return; }
var roUrl = getReadOnlyUrl(el);
openFile(null, roUrl);
}); });
} }
else if ($(this).hasClass('cp-app-drive-context-delete')) { else if ($(this).hasClass("cp-app-drive-context-properties")) {
var pathsList = []; if (type === 'trash') {
paths.forEach(function (p) { pathsList.push(p.path); }); var pPath = paths[0].path;
if (!APP.loggedIn) { if (paths.length !== 1 || pPath.length !== 4) { return; }
var msg = Messages._getKey("fm_removeSeveralPermanentlyDialog", [paths.length]); var element = filesOp.find(pPath.slice(0,3)); // element containing the oldpath
if (paths.length === 1) { var sPath = stringifyPath(element.path);
msg = Messages.fm_removePermanentlyDialog; UI.alert('<strong>' + Messages.fm_originalPath + "</strong>:<br>" + sPath, undefined, true);
}
UI.confirm(msg, function(res) {
$(window).focus();
if (!res) { return; }
filesOp.delete(pathsList, refresh);
});
return; return;
} }
moveElements(pathsList, [TRASH], false, refresh);
}
else if ($(this).hasClass('cp-app-drive-context-deleteowned')) {
var msgD = Messages.fm_deleteOwnedPads;
UI.confirm(msgD, function(res) {
$(window).focus();
if (!res) { return; }
// Try to delete each selected pad from server, and delete from drive if no error
var n = nThen(function () {});
paths.forEach(function (p) {
var el = filesOp.find(p.path);
var data = filesOp.getFileData(el);
var parsed = Hash.parsePadUrl(data.href);
var channel = Util.base64ToHex(parsed.hashData.channel);
n = n.nThen(function (waitFor) {
sframeChan.query('Q_CONTACTS_CLEAR_OWNED_CHANNEL', channel,
waitFor(function (e) {
if (e) { return void console.error(e); }
filesOp.delete([p.path], refresh);
}));
});
});
});
return;
}
else if ($(this).hasClass("cp-app-drive-context-properties")) {
if (paths.length !== 1) { return; } if (paths.length !== 1) { return; }
el = filesOp.find(paths[0].path); el = filesOp.find(paths[0].path);
getProperties(el, function (e, $prop) { getProperties(el, function (e, $prop) {
@ -2757,98 +2798,45 @@ define([
var href = data.href; var href = data.href;
common.updateTags(href); common.updateTags(href);
} }
APP.hideMenu(); else if ($(this).hasClass("cp-app-drive-context-empty")) {
}); if (paths.length !== 1 || !paths[0].element
|| !filesOp.comparePath(paths[0].path, [TRASH])) {
$contentContextMenu.on('click', 'a', function (e) { log(Messages.fm_forbidden);
e.stopPropagation(); return;
var path = $(this).data('path');
var onCreated = function (err, info) {
if (err === E_OVER_LIMIT) {
return void UI.alert(Messages.pinLimitDrive, null, true);
}
if (err) {
return void UI.alert(Messages.fm_error_cantPin);
} }
APP.newFolder = info.newPath;
refresh();
};
if ($(this).hasClass("cp-app-drive-context-newfolder")) {
filesOp.addFolder(path, null, onCreated);
}
else if ($(this).hasClass("cp-app-drive-context-newdoc")) {
var type = $(this).data('type') || 'pad';
var path2 = filesOp.isPathIn(currentPath, [TRASH]) ? '' : currentPath;
common.sessionStorage.put(Constants.newPadPathKey, path2, function () {
common.openURL('/' + type + '/');
});
}
APP.hideMenu();
});
$trashTreeContextMenu.on('click', 'a', function (e) {
e.stopPropagation();
var paths = $(this).data('paths');
if (paths.length !== 1 || !paths[0].element || !filesOp.comparePath(paths[0].path, [TRASH])) {
log(Messages.fm_forbidden);
debug("Trash tree context menu on a forbidden or unexisting element. ", paths);
return;
}
if ($(this).hasClass("cp-app-drive-context-empty")) {
UI.confirm(Messages.fm_emptyTrashDialog, function(res) { UI.confirm(Messages.fm_emptyTrashDialog, function(res) {
if (!res) { return; } if (!res) { return; }
filesOp.emptyTrash(refresh); filesOp.emptyTrash(refresh);
}); });
} }
APP.hideMenu(); else if ($(this).hasClass("cp-app-drive-context-remove")) {
}); return void deletePaths(paths);
$trashContextMenu.on('click', 'a', function (e) {
e.stopPropagation();
var paths = $(this).data('paths');
if (paths.length === 0) {
log(Messages.fm_forbidden);
debug("Trash context menu on a forbidden or unexisting element. ", paths);
return;
}
var path = paths[0].path;
var name = paths[0].path[paths[0].path.length - 1];
if ($(this).hasClass("cp-app-drive-context-remove")) {
if (paths.length === 1) {
UI.confirm(Messages.fm_removePermanentlyDialog, function(res) {
if (!res) { return; }
filesOp.delete([path], refresh);
});
return;
}
var pathsList = [];
paths.forEach(function (p) { pathsList.push(p.path); });
var msg = Messages._getKey("fm_removeSeveralPermanentlyDialog", [paths.length]);
UI.confirm(msg, function(res) {
if (!res) { return; }
filesOp.delete(pathsList, refresh);
});
} }
else if ($(this).hasClass("cp-app-drive-context-restore")) { else if ($(this).hasClass("cp-app-drive-context-restore")) {
if (paths.length !== 1) { return; } if (paths.length !== 1) { return; }
if (path.length === 4) { var restorePath = paths[0].path;
var el = filesOp.find(path); var restoreName = paths[0].path[paths[0].path.length - 1];
if (filesOp.isFile(el)) { if (restorePath.length === 4) {
name = filesOp.getTitle(el); var rEl = filesOp.find(restorePath);
if (filesOp.isFile(rEl)) {
restoreName = filesOp.getTitle(rEl);
} else { } else {
name = path[1]; restoreName = restorePath[1];
} }
} }
UI.confirm(Messages._getKey("fm_restoreDialog", [name]), function(res) { UI.confirm(Messages._getKey("fm_restoreDialog", [restoreName]), function(res) {
if (!res) { return; } if (!res) { return; }
filesOp.restore(path, refresh); filesOp.restore(restorePath, refresh);
}); });
} }
else if ($(this).hasClass("cp-app-drive-context-properties")) { else if ($(this).hasClass("cp-app-drive-context-openparent")) {
if (paths.length !== 1 || path.length !== 4) { return; } if (paths.length !== 1) { return; }
var element = filesOp.find(path.slice(0,3)); // element containing the oldpath var parentPath = paths[0].path.slice();
var sPath = stringifyPath(element.path); if (filesOp.isInTrashRoot(parentPath)) { parentPath = [TRASH]; }
UI.alert('<strong>' + Messages.fm_originalPath + "</strong>:<br>" + sPath, undefined, true); else { parentPath.pop(); }
el = filesOp.find(paths[0].path);
APP.selectedFiles = [el];
APP.displayDirectory(parentPath);
} }
APP.hideMenu(); APP.hideMenu();
}); });

Loading…
Cancel
Save