@ -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' ) ; }
$contextMenu . find ( 'li' ) . hide ( ) ;
var show = [ ] ;
var filter ;
if ( type === "content" ) {
filter = function ( $el , className ) {
if ( className === 'newfolder' ) { return ; }
return AppConfig . availablePadTypes . indexOf ( $el . attr ( 'data-type' ) ) === - 1 ;
} ;
} else {
// In case of multiple selection, we must hide the option if at least one element
// is not compatible
var containsFolder = false ;
var hide = [ ] ;
var hide = [ ] ;
var hasFolder = false ;
paths . forEach ( function ( p ) {
paths . forEach ( function ( p ) {
var path = p . path ;
var path = p . path ;
var $element = p . element ;
var $element = p . element ;
if ( path . length === 1 ) {
if ( path . length === 1 ) {
// Can't rename or delete root elements
// Can't rename or delete root elements
hide . push ( $menu . find ( 'a.cp-app-drive-context-rename' ) ) ;
hide . push ( 'delete' ) ;
hide . push ( $menu . find ( 'a.cp-app-drive-context-delete' ) ) ;
hide . push ( 'rename' ) ;
}
if ( ! APP . editable ) {
hide . push ( $menu . find ( 'a.cp-app-drive-context-editable' ) ) ;
}
if ( ! isOwnDrive ( ) ) {
hide . push ( $menu . find ( 'a.cp-app-drive-context-own' ) ) ;
}
}
if ( ! $element . is ( '.cp-app-drive-element-owned' ) ) {
if ( ! $element . is ( '.cp-app-drive-element-owned' ) ) {
hide . push ( $menu . find ( ' a.cp-app-drive-context- deleteowned') ) ;
hide . push ( 'deleteowned' ) ;
}
}
if ( $element . is ( '.cp-app-drive-element-notrash' ) ) {
if ( $element . is ( '.cp-app-drive-element-notrash' ) ) {
hide . push ( $menu . find ( 'a.cp-app-drive-context-delete' ) ) ;
// 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' ) ) {
if ( $element . is ( '.cp-app-drive-element-file' ) ) {
// No folder in files
// No folder in files
hide . push ( $menu . find ( 'a.cp-app-drive-context-newfolder' ) ) ;
hide . push ( ' newfolder') ;
if ( $element . is ( '.cp-app-drive-element-readonly' ) ) {
if ( $element . is ( '.cp-app-drive-element-readonly' ) ) {
// Keep only open readonly
hide . push ( 'open' ) ; // Remove open 'edit' mode
hide . push ( $menu . find ( 'a.cp-app-drive-context-open' ) ) ;
} else if ( $element . is ( '.cp-app-drive-element-noreadonly' ) ) {
} else if ( $element . is ( '.cp-app-drive-element-noreadonly' ) ) {
// Keep only open readonly
hide . push ( 'openro' ) ; // Remove open 'view' mode
hide . push ( $menu . find ( 'a.cp-app-drive-context-openro' ) ) ;
}
}
} else {
} else { // it's a folder
if ( ha sFolder) {
if ( contain sFolder) {
// More than 1 folder selected: cannot create a new subfolder
// More than 1 folder selected: cannot create a new subfolder
hide . push ( $menu . find ( ' a.cp-app-drive-context- newfolder') ) ;
hide . push ( ' newfolder') ;
}
}
ha sFolder = true ;
contain sFolder = true ;
hide . push ( $menu . find ( ' a.cp-app-drive-context- openro') ) ;
hide . push ( ' openro') ;
hide . push ( $menu . find ( ' a.cp-app-drive-context- properties') ) ;
hide . push ( ' properties') ;
hide . push ( $menu . find ( ' a.cp-app-drive-context- hashtag') ) ;
hide . push ( ' hashtag') ;
}
}
// If we're in the trash, hide restore and properties for non-root elements
// If we're in the trash, hide restore and properties for non-root elements
if ( $menu . find ( 'a.cp-app-drive-context-restore' ) . length && path && path . length > 4 ) {
if ( type === "trash" && path && path . length > 4 ) {
hide . push ( $menu . find ( ' a.cp-app-drive-context- restore') ) ;
hide . push ( ' restore') ;
hide . push ( $menu . find ( ' a.cp-app-drive-context- properties') ) ;
hide . push ( ' properties') ;
}
}
} ) ;
} ) ;
if ( paths . length > 1 ) {
if ( paths . length > 1 ) {
hide . push ( $menu . find ( 'a.cp-app-drive-context-restore' ) ) ;
hide . push ( 'restore' ) ;
hide . push ( $menu . find ( 'a.cp-app-drive-context-properties' ) ) ;
hide . push ( 'properties' ) ;
hide . push ( $menu . find ( 'a.cp-app-drive-context-rename' ) ) ;
hide . push ( 'rename' ) ;
hide . push ( 'openparent' ) ;
}
}
if ( ha sFolder && paths . length > 1 ) {
if ( contain sFolder && paths . length > 1 ) {
// Cannot open multiple folders
// Cannot open multiple folders
hide . push ( $menu . find ( ' a.cp-app-drive-context- open') ) ;
hide . push ( ' open') ;
}
}
return hide ;
filter = function ( $el , className ) {
if ( hide . indexOf ( className ) !== - 1 ) { return true ; }
} ;
}
switch ( type ) {
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' ] ;
}
}
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,102 +1046,50 @@ 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 ) {
return function ( e ) {
APP . hideMenu ( ) ;
APP . hideMenu ( ) ;
e . stopPropagation ( ) ;
e . stopPropagation ( ) ;
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 ) ) ;
var $element = findDataHolder ( $ ( e . target ) ) ;
if ( type === 'trash' && ! $element . data ( 'path' ) ) { return ; }
if ( ! $element . length ) {
if ( ! $element . length ) {
logError ( "Unable to locate the .element tag" , e . target ) ;
logError ( "Unable to locate the .element tag" , e . target ) ;
$menu . hide ( ) ;
log ( Messages . fm _contextMenuError ) ;
log ( Messages . fm _contextMenuError ) ;
return false ;
return false ;
}
}
if ( ! $element . hasClass ( 'cp-app-drive-element-selected' ) ) { //paths.length === 1) {
if ( ! $element . hasClass ( 'cp-app-drive-element-selected' ) ) {
onElementClick ( undefined , $element ) ;
onElementClick ( undefined , $element ) ;
}
}
var paths = getSelectedPaths ( $element ) ;
paths = getSelectedPaths ( $element ) ;
var toHide = filterContextMenu ( $menu , paths ) ;
toHide . forEach ( function ( $a ) {
$a . parent ( 'li' ) . hide ( ) ;
} ) ;
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 ( 'paths' , paths ) ;
$contextMenu . attr ( 'data-menu-type' , type ) ;
//$menu.find('a').data('path', path);
//$menu.find('a').data('element', $element);
return false ;
} ;
var openDirectoryContextMenu = function ( e ) {
$contextMenu . find ( 'li' ) . show ( ) ;
openContextMenu ( e , $contextMenu ) ;
return false ;
} ;
var openDefaultContextMenu = function ( e ) {
$defaultContextMenu . find ( 'li' ) . show ( ) ;
openContextMenu ( e , $defaultContextMenu ) ;
return false ;
} ;
var openTrashTreeContextMenu = function ( e ) {
removeSelected ( ) ;
$trashTreeContextMenu . find ( 'li' ) . show ( ) ;
openContextMenu ( e , $trashTreeContextMenu ) ;
return false ;
} ;
var openTrashContextMenu = function ( e ) {
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 ) {
$ ( el ) . hide ( ) ;
}
} ) ;
displayMenu ( e , $menu ) ;
if ( $menu . find ( 'li:visible' ) . length === 0 ) {
debug ( "No visible element in the context menu. Abort." ) ;
debug ( "No visible element in the context menu. Abort." ) ;
$m enu. hide ( ) ;
$contextMenu . hide ( ) ;
return true ;
return true ;
}
}
$menu . find ( 'a' ) . data ( 'path' , path ) ;
$contextMenu . data ( 'paths' , paths ) ;
return false ;
return false ;
} ;
} ;
} ;
var getElementName = function ( path ) {
var getElementName = function ( path ) {
var file = filesOp . find ( path ) ;
var file = filesOp . find ( path ) ;
@ -1303,11 +1392,11 @@ define([
onElementClick ( e , $element , newPath ) ;
onElementClick ( e , $element , newPath ) ;
} ) ;
} ) ;
if ( ! isTrash ) {
if ( ! isTrash ) {
$element . contextmenu ( open Directory ContextMenu) ;
$element . contextmenu ( open ContextMenu( 'tree' ) ) ;
$element . data ( 'context' , $contextMenu ) ;
$element . data ( 'context' , 'tree' ) ;
} else {
} else {
$element . contextmenu ( open Trash ContextMenu) ;
$element . contextmenu ( open ContextMenu( '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 ( open Default ContextMenu) ;
$element . contextmenu ( open ContextMenu( '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 ( open Default ContextMenu) ;
$element . contextmenu ( open ContextMenu( '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 ( open Default ContextMenu) ;
$element . contextmenu ( open ContextMenu( 'default' ) ) ;
$element . data ( 'context' , $defaultContextMenu ) ;
$element . data ( 'context' , 'default' ) ;
/ * i f ( d r a g g a b l e ) {
/ * i f ( d r a g g a b l e ) {
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 ( open Default ContextMenu) ;
$element . contextmenu ( open ContextMenu( '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 ( openConte ntConte xtMenu) ;
$dirContent . contextmenu ( openConte xtMenu( '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 ( open Directory ContextMenu) ;
. contextmenu ( open ContextMenu( '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 ( open Directory ContextMenu) ;
$element . find ( '>.cp-app-drive-element-row' ) . contextmenu ( open ContextMenu( '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 ( " C ontext 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 on Created = function ( err , info ) {
var on Folder Created = 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" ) ) {
if ( paths . length !== 1 ) { return ; }
el = filesOp . find ( paths [ 0 ] . path ) ;
var data = filesOp . getFileData ( el ) ;
if ( ! data ) { return void console . error ( "Expected to find a file" ) ; }
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' ) ) {
else if ( $ ( this ) . hasClass ( "cp-app-drive-context-newdoc" ) ) {
paths . forEach ( function ( p ) {
var ntype = $ ( this ) . data ( 'type' ) || 'pad' ;
var el = filesOp . find ( p . path ) ;
var path2 = filesOp . isPathIn ( currentPath , [ TRASH ] ) ? '' : currentPath ;
if ( filesOp . isPathIn ( p . path , [ FILES _DATA ] ) ) { el = el . href ; }
common . sessionStorage . put ( Constants . newPadPathKey , path2 , function ( ) {
if ( ! el || filesOp . isFolder ( el ) ) { return ; }
common . openURL ( '/' + ntype + '/' ) ;
var roUrl = getReadOnlyUrl ( el ) ;
openFile ( null , roUrl ) ;
} ) ;
}
else if ( $ ( this ) . hasClass ( 'cp-app-drive-context-delete' ) ) {
var pathsList = [ ] ;
paths . forEach ( function ( p ) { pathsList . push ( p . path ) ; } ) ;
if ( ! APP . loggedIn ) {
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 ) ;
} ) ;
} ) ;
return ;
}
}
moveElements ( pathsList , [ TRASH ] , false , refresh ) ;
else if ( $ ( this ) . hasClass ( "cp-app-drive-context-properties" ) ) {
}
if ( type === 'trash' ) {
else if ( $ ( this ) . hasClass ( 'cp-app-drive-context-deleteowned' ) ) {
var pPath = paths [ 0 ] . path ;
var msgD = Messages . fm _deleteOwnedPads ;
if ( paths . length !== 1 || pPath . length !== 4 ) { return ; }
UI . confirm ( msgD , function ( res ) {
var element = filesOp . find ( pPath . slice ( 0 , 3 ) ) ; // element containing the oldpath
$ ( window ) . focus ( ) ;
var sPath = stringifyPath ( element . path ) ;
if ( ! res ) { return ; }
UI . alert ( '<strong>' + Messages . fm _originalPath + "</strong>:<br>" + sPath , undefined , true ) ;
// 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 ;
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 ) {
e . stopPropagation ( ) ;
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 ) ;
log ( Messages . fm _forbidden ) ;
debug ( "Trash tree context menu on a forbidden or unexisting element. " , paths ) ;
return ;
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" , [ n ame] ) , function ( res ) {
UI . confirm ( Messages . _getKey ( "fm_restoreDialog" , [ restoreName ] ) , function ( res ) {
if ( ! res ) { return ; }
if ( ! res ) { return ; }
filesOp . restore ( p ath, 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 ( ) ;
} ) ;
} ) ;