2019-01-02 15:54:12 +05:30
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
2021-01-04 15:34:45 +05:30
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
2019-01-02 15:54:12 +05:30
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
2016-05-13 00:04:28 +05:30
/ * *
* Filemanager JS core
*
* filemanager . js
*
* @ license MIT License
* @ author Jason Huck - Core Five Labs
* @ author Simon Georget < simon ( at ) linea21 ( dot ) com >
* @ copyright Authors
* /
2018-01-12 12:59:51 +05:30
define ( [
2019-10-10 12:05:28 +05:30
'jquery' , 'underscore' , 'pgadmin.alertifyjs' ,
2018-01-12 12:59:51 +05:30
'sources/gettext' , 'sources/url_for' , 'dropzone' , 'sources/pgadmin' ,
2019-11-01 15:00:34 +00:00
'sources/csrf' , 'tablesorter' , 'tablesorter-metric' ,
2020-07-16 19:53:39 +05:30
] , function ( $ , _ , Alertify , gettext , url _for , Dropzone , pgAdmin , csrf ) {
2018-01-12 12:59:51 +05:30
2020-10-23 16:14:55 +05:30
pgAdmin . Browser = pgAdmin . Browser || { } ;
2018-01-12 12:59:51 +05:30
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Define functions used for various operations
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - * /
2019-05-28 10:59:51 +05:30
// Set the CSRF Token
2020-07-16 19:53:39 +05:30
csrf . setPGCSRFToken ( pgAdmin . csrf _token _header , pgAdmin . csrf _token ) ;
2018-01-12 12:59:51 +05:30
// Return file extension
var getFileExtension = function ( name ) {
var found = name . lastIndexOf ( '.' ) + 1 ;
return ( found > 0 ? name . substr ( found ) : '' ) ;
} ;
/ * C o m m o n f u n c t i o n t o l o a d :
2019-01-03 14:50:24 +00:00
* en . json language file
2018-01-12 12:59:51 +05:30
* file _manager _config . js config file
* return transaction id
* /
var loadData = function ( url ) {
return $ . ajax ( {
async : false ,
cache : false ,
url : url ,
2018-06-29 15:14:37 +01:00
dataType : 'json' ,
2018-01-12 12:59:51 +05:30
contentType : 'application/json; charset=utf-8' ,
} ) ;
} ;
2021-04-08 12:23:57 +05:30
var getFileFormat = function ( data ) {
// Get last selected file format
return $ . ajax ( {
async : false ,
cache : false ,
url : url _for ( 'settings.get_file_format_setting' ) ,
data : $ . extend ( { } , data ) ,
dataType : 'json' ,
contentType : 'application/json; charset=utf-8' ,
} ) ;
} ;
2018-01-12 12:59:51 +05:30
// Set enable/disable state of list and grid view
var setViewButtonsFor = function ( viewMode ) {
if ( viewMode == 'grid' ) {
2016-05-21 15:01:47 +05:30
$ ( '.grid' ) . addClass ( 'ON' ) ;
$ ( '.list' ) . removeClass ( 'ON' ) ;
2018-01-12 12:59:51 +05:30
} else {
2016-05-21 15:01:47 +05:30
$ ( '.list' ) . addClass ( 'ON' ) ;
$ ( '.grid' ) . removeClass ( 'ON' ) ;
2018-01-12 12:59:51 +05:30
}
} ;
var save _file _dialog _view = function ( view , trans _id ) {
return $ . ajax ( {
url : url _for ( 'file_manager.save_file_dialog_view' , {
'trans_id' : trans _id ,
} ) ,
type : 'POST' ,
async : true ,
data : JSON . stringify ( {
'view' : view ,
} ) ,
contentType : 'application/json' ,
} ) ;
} ;
2016-05-14 15:29:03 +05:30
2018-01-12 12:59:51 +05:30
var save _show _hidden _file _option = function ( option , trans _id ) {
return $ . ajax ( {
url : url _for ( 'file_manager.save_show_hidden_file_option' , {
'trans_id' : trans _id ,
} ) ,
type : 'PUT' ,
async : true ,
data : JSON . stringify ( {
'show_hidden' : option ,
} ) ,
contentType : 'application/json' ,
} ) ;
} ;
// nameFormat (), separate filename from extension
var nameFormat = function ( input ) {
var filename = '' ;
if ( input . lastIndexOf ( '.' ) != - 1 ) {
filename = input . substr ( 0 , input . lastIndexOf ( '.' ) ) ;
filename += '.' + input . split ( '.' ) . pop ( ) ;
} else {
filename = input ;
2016-05-13 00:04:28 +05:30
}
return filename ;
2018-01-12 12:59:51 +05:30
} ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
/ *
* Test if Data structure has the 'cap' capability
* 'cap' is one of 'select' , 'rename' , 'delete' , 'download'
* /
var has _capability = function ( data , cap ) {
if ( typeof ( data . Capabilities ) == 'undefined' ) {
return true ;
} else {
return ( $ . inArray ( cap , data . Capabilities ) > - 1 ) ;
}
} ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
// return filename extension
var getExtension = function ( filename ) {
if ( filename . split ( '.' ) . length == 1 ) {
return '' ;
}
return filename . split ( '.' ) . pop ( ) ;
} ;
/ *
* Binds specific actions to the toolbar based on capability .
* and show / hide buttons
* /
var bindToolbar = function ( data ) {
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
// hide/show rename, upload and create button
if ( _ . has ( data , 'Capabilities' ) ) {
_ . each ( data . Capabilities , function ( cap ) {
var target _btn = 'button.' + cap ,
$target _el = $ ( '.file_manager' ) . find ( target _btn ) ;
if ( ! has _capability ( data , cap ) || pgAdmin . FileUtils . hideButtons ( ) ) {
$target _el . hide ( ) ;
2016-05-14 15:29:03 +05:30
} else {
2018-01-12 12:59:51 +05:30
$target _el . show ( ) ;
2016-05-13 00:04:28 +05:30
}
2018-01-12 12:59:51 +05:30
} ) ;
}
if ( ! has _capability ( data , 'delete' ) || pgAdmin . FileUtils . hideButtons ( ) ) {
$ ( '.file_manager' ) . find ( 'button.delete' ) . hide ( ) ;
} else {
2018-05-25 16:26:37 +01:00
$ ( '.file_manager' ) . find ( 'button.delete' ) . on ( 'click' , ( ) => {
2018-01-12 12:59:51 +05:30
// hide dimmer
$ ( '.fileinfo .delete_item, .fm_dimmer' ) . show ( ) ;
} ) ;
// take action based on pressed button yes or no
2018-05-25 16:26:37 +01:00
$ ( '.fileinfo .delete_item button.btn_yes' ) . off ( ) . on ( 'click' , function ( ) {
2018-01-12 12:59:51 +05:30
var path ;
if ( $ ( '.fileinfo' ) . data ( 'view' ) == 'grid' ) {
path = decodeURI ( $ ( '.fileinfo' ) . find ( '#contents li.selected .clip span' ) . attr ( 'data-alt' ) ) ;
if ( path . lastIndexOf ( '/' ) == path . length - 1 ) {
data . Path = path ;
deleteItem ( data ) ;
} else {
deleteItem ( data ) ;
}
2016-05-14 15:29:03 +05:30
} else {
2018-01-12 12:59:51 +05:30
path = $ ( '.fileinfo' ) . find ( 'table#contents tbody tr.selected td:first-child' ) . attr ( 'title' ) ;
if ( path . lastIndexOf ( '/' ) == path . length - 1 ) {
data . Path = path ;
deleteItem ( data ) ;
} else {
deleteItem ( data ) ;
}
2016-05-13 00:04:28 +05:30
}
2018-01-12 12:59:51 +05:30
// hide dimmer
$ ( '.fileinfo .fm_dimmer' ) . hide ( ) ;
} ) ;
2016-05-13 00:04:28 +05:30
}
2018-01-12 12:59:51 +05:30
// Download file on download button click
if ( ! has _capability ( data , 'download' ) || pgAdmin . FileUtils . hideButtons ( ) ) {
$ ( '.file_manager' ) . find ( 'button.download' ) . hide ( ) ;
} else {
2018-06-29 15:14:37 +01:00
$ ( '.file_manager' ) . find ( 'button.download' ) . off ( ) . on ( 'click' , function ( ) {
2020-10-23 16:14:55 +05:30
var path ,
params = { } ;
params [ pgAdmin . csrf _token _header ] = pgAdmin . csrf _token ;
2018-01-12 12:59:51 +05:30
if ( $ ( '.fileinfo' ) . data ( 'view' ) == 'grid' ) {
path = $ ( '.fileinfo li.selected' ) . find ( '.clip span' ) . attr ( 'data-alt' ) ;
} else {
path = $ ( '.fileinfo' ) . find ( 'table#contents tbody tr.selected td:first-child' ) . attr ( 'title' ) ;
}
2020-10-23 16:14:55 +05:30
download _file ( path ) ;
2018-01-12 12:59:51 +05:30
} ) ;
2016-05-13 00:04:28 +05:30
}
2018-01-12 12:59:51 +05:30
} ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
// enable/disable button when files/folder are loaded
var enable _disable _btn = function ( ) {
if ( $ ( '.fileinfo' ) . data ( 'view' ) == 'grid' ) {
var $grid _file = $ ( '.file_manager' ) . find ( '#contents li.selected' ) ;
$grid _file . removeClass ( 'selected' ) ;
$ ( '.file_manager' ) . find ( 'button.delete' ) . prop ( 'disabled' , true ) ;
$ ( '.file_manager' ) . find ( 'button.download' ) . prop ( 'disabled' , true ) ;
$ ( '.file_manager' ) . find ( 'button.rename' ) . prop ( 'disabled' , true ) ;
if ( $grid _file . length > 0 ) {
$ ( '.file_manager_ok' ) . addClass ( 'disabled' ) ;
$ ( '.file_manager_ok' ) . attr ( 'disabled' , true ) ;
2016-05-13 00:04:28 +05:30
}
2018-01-12 12:59:51 +05:30
} else {
var $list _file = $ ( '.fileinfo' ) . find ( 'table#contents tbody tr.selected' ) ;
$list _file . removeClass ( 'selected' ) ;
$ ( '.file_manager' ) . find ( 'button.delete' ) . prop ( 'disabled' , true ) ;
$ ( '.file_manager' ) . find ( 'button.download' ) . prop ( 'disabled' , true ) ;
$ ( '.file_manager' ) . find ( 'button.rename' ) . prop ( 'disabled' , true ) ;
if ( $list _file . length > 0 ) {
$ ( '.file_manager_ok' ) . addClass ( 'disabled' ) ;
$ ( '.file_manager_ok' ) . attr ( 'disabled' , true ) ;
}
}
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
$ ( '.delete_item' ) . hide ( ) ;
// clear address bar
$ ( '.file_manager #uploader .input-path' ) . show ( ) ;
$ ( '.file_manager #uploader .show_selected_file' ) . remove ( ) ;
} ;
/ *
* Rename the current item and returns the new name .
* by double clicking or by clicking the "Rename" button in
* table ( list ) views .
* /
var renameItem = function ( data ) {
var finalName = '' ,
lg = pgAdmin . FileUtils . lg ,
getNewName = function ( rname ) {
if ( rname !== '' ) {
var givenName = nameFormat ( rname ) ,
suffix = getExtension ( data . Filename ) ;
if ( suffix . length > 0 ) {
givenName = givenName + '.' + suffix ;
}
var oldPath = data . Path ,
post _data = {
'mode' : 'rename' ,
'old' : data . Path ,
'new' : givenName ,
} ;
$ . ajax ( {
type : 'POST' ,
data : JSON . stringify ( post _data ) ,
url : pgAdmin . FileUtils . fileConnector ,
dataType : 'json' ,
contentType : 'application/json; charset=utf-8' ,
async : false ,
2018-07-09 13:54:00 +01:00
} )
2019-03-14 15:11:16 +00:00
. done ( function ( resp ) {
var result = resp . data . result ;
if ( result . Code === 1 ) {
var newPath = result [ 'New Path' ] ,
newName = result [ 'New Name' ] ,
title = $ ( '#preview h1' ) . attr ( 'title' ) ;
if ( typeof title != 'undefined' && title == oldPath ) {
$ ( '#preview h1' ) . text ( newName ) ;
}
if ( $ ( '.fileinfo' ) . data ( 'view' ) == 'grid' ) {
$ ( '.fileinfo span[data-alt="' + oldPath + '"]' ) . parent ( ) . next ( 'div span' ) . text ( newName ) ;
$ ( '.fileinfo span[data-alt="' + oldPath + '"]' ) . attr ( 'data-alt' , newPath ) ;
} else {
$ ( '.fileinfo td[title="' + oldPath + '"]' ) . text ( newName ) ;
$ ( '.fileinfo td[title="' + oldPath + '"]' ) . attr ( 'title' , newPath ) ;
}
$ ( '#preview h1' ) . html ( newName ) ;
// actualized data for binding
data . Path = newPath ;
data . Filename = newName ;
// UnBind toolbar functions.
$ ( '.fileinfo' ) . find ( 'button.rename, button.delete, button.download' ) . off ( ) ;
Alertify . success ( lg . successful _rename ) ;
2018-01-12 12:59:51 +05:30
} else {
2019-03-14 15:11:16 +00:00
Alertify . error ( result . Error ) ;
2018-01-12 12:59:51 +05:30
}
2018-07-09 13:54:00 +01:00
2019-03-14 15:11:16 +00:00
finalName = result [ 'New Name' ] ;
} ) ;
2018-01-12 12:59:51 +05:30
}
} ;
getNewName ( data . NewFilename ) ;
return finalName ;
} ;
/ *
* delete the folder or files by clicking the "Delete" button
* in table ( list ) view
* /
var deleteItem = function ( data ) {
var isDeleted = false ,
lg = pgAdmin . FileUtils . lg ;
2020-07-09 18:35:04 +05:30
var doDelete = function ( sel _data ) {
2018-01-12 12:59:51 +05:30
var post _data = {
'mode' : 'delete' ,
2020-07-09 18:35:04 +05:30
'path' : sel _data . Path ,
2018-01-12 12:59:51 +05:30
} ;
2016-05-13 00:04:28 +05:30
$ . ajax ( {
type : 'POST' ,
data : JSON . stringify ( post _data ) ,
2017-07-18 15:13:16 +01:00
url : pgAdmin . FileUtils . fileConnector ,
2016-05-13 00:04:28 +05:30
dataType : 'json' ,
2018-01-12 12:59:51 +05:30
contentType : 'application/json; charset=utf-8' ,
2016-05-13 00:04:28 +05:30
async : false ,
2018-07-09 13:54:00 +01:00
} )
2019-03-14 15:11:16 +00:00
. done ( function ( resp ) {
var result = resp . data . result ;
if ( result . Code === 1 ) {
isDeleted = true ;
if ( isDeleted ) {
Alertify . success ( lg . successful _delete ) ;
var rootpath = result . Path . substring ( 0 , result . Path . length - 1 ) ; // removing the last slash
rootpath = rootpath . substr ( 0 , rootpath . lastIndexOf ( '/' ) + 1 ) ;
getFolderInfo ( rootpath ) ;
}
} else {
isDeleted = false ;
Alertify . error ( result . Error ) ;
2016-05-13 00:04:28 +05:30
}
2019-03-14 15:11:16 +00:00
} ) ;
2018-01-12 12:59:51 +05:30
return isDeleted ;
} ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
doDelete ( data ) ;
return isDeleted ;
} ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Functions to Retrieve File and Folder Details
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - * /
/ *
* Retrieves information about the specified file as a JSON
* object and uses that data to populate a template for
* list views . Binds the toolbar for that file / folder to
* enable specific actions . Called whenever an item is
* clicked in list views .
* /
var getFileInfo = function ( file ) {
// Update location for status, upload, & new folder functions.
pgAdmin . FileUtils . setUploader ( file ) ;
var capabilities = pgAdmin . FileUtils . data . capabilities ,
is _file _valid = false ,
post _data = {
'path' : file ,
'mode' : 'getinfo' ,
} ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
// Retrieve the data & populate the template.
2016-05-13 00:04:28 +05:30
$ . ajax ( {
type : 'POST' ,
data : JSON . stringify ( post _data ) ,
2017-07-18 15:13:16 +01:00
url : pgAdmin . FileUtils . fileConnector ,
2016-05-13 00:04:28 +05:30
dataType : 'json' ,
2018-01-12 12:59:51 +05:30
contentType : 'application/json; charset=utf-8' ,
2016-05-13 00:04:28 +05:30
async : false ,
2018-07-09 13:54:00 +01:00
} )
2019-03-14 15:11:16 +00:00
. done ( function ( resp ) {
var data = resp . data . result ;
if ( data . Code === 1 ) {
$ ( '.file_manager_ok' ) . removeClass ( 'disabled' ) ;
$ ( '.file_manager_ok' ) . attr ( 'disabled' , false ) ;
data . Capabilities = capabilities ;
bindToolbar ( data ) ;
if ( data . FileType == 'Directory' ) {
2018-07-09 13:54:00 +01:00
// Enable/Disable level up button
2019-03-14 15:11:16 +00:00
enab _dis _level _up ( ) ;
$ ( '.file_manager_ok' ) . addClass ( 'disabled' ) ;
$ ( '.file_manager_ok' ) . attr ( 'disabled' , true ) ;
$ ( '.file_manager button.delete, .file_manager button.rename' ) . attr ( 'disabled' , 'disabled' ) ;
$ ( '.file_manager button.download' ) . attr ( 'disabled' , 'disabled' ) ;
2018-01-12 12:59:51 +05:30
2019-03-14 15:11:16 +00:00
if ( file . charAt ( file . length - 1 ) != '/' && file . charAt ( file . length - 1 ) != '\\' ) {
file += '/' ;
}
getFolderInfo ( file ) ;
} else {
is _file _valid = true ;
2016-05-13 00:04:28 +05:30
}
} else {
2019-03-14 15:11:16 +00:00
$ ( '.file_manager_ok' ) . addClass ( 'disabled' ) ;
$ ( '.file_manager_ok' ) . attr ( 'disabled' , true ) ;
Alertify . error ( data . Error ) ;
2016-05-13 00:04:28 +05:30
}
2021-06-28 18:46:41 +05:30
// Disable select button if user select file.
if ( pgAdmin . FileUtils . data . Capabilities . includes ( 'select_folder' ) ) {
$ ( '.file_manager_ok' ) . addClass ( 'disabled' ) ;
$ ( '.file_manager_ok' ) . attr ( 'disabled' , true ) ;
}
2019-03-14 15:11:16 +00:00
} ) ;
2018-01-12 12:59:51 +05:30
return is _file _valid ;
2016-05-13 00:04:28 +05:30
} ;
2018-01-12 12:59:51 +05:30
var checkPermission = function ( path ) {
var permission = false ,
post _data = {
'path' : path ,
'mode' : 'permission' ,
} ;
2017-02-03 10:51:36 +01:00
2018-01-12 12:59:51 +05:30
$ . ajax ( {
type : 'POST' ,
data : JSON . stringify ( post _data ) ,
url : pgAdmin . FileUtils . fileConnector ,
dataType : 'json' ,
contentType : 'application/json; charset=utf-8' ,
async : false ,
2018-07-09 13:54:00 +01:00
} )
2019-03-14 15:11:16 +00:00
. done ( function ( resp ) {
var data = resp . data . result ;
if ( data . Code === 1 ) {
permission = true ;
} else {
$ ( '.file_manager_ok' ) . addClass ( 'disabled' ) ;
$ ( '.file_manager_ok' ) . attr ( 'disabled' , true ) ;
Alertify . error ( data . Error ) ;
}
} )
. fail ( function ( ) {
2017-02-03 10:51:36 +01:00
$ ( '.file_manager_ok' ) . addClass ( 'disabled' ) ;
2017-12-05 13:43:02 +09:00
$ ( '.file_manager_ok' ) . attr ( 'disabled' , true ) ;
2019-03-14 15:11:16 +00:00
Alertify . error (
gettext ( 'Error occurred while checking access permission.' )
) ;
} ) ;
2018-01-12 12:59:51 +05:30
return permission ;
} ;
2017-02-03 10:51:36 +01:00
2020-01-10 12:53:32 +05:30
var getNoDataView = function ( data ) {
var lg = pgAdmin . FileUtils . lg ;
var cap _no _folders = [ 'upload' , 'create' ] ;
data . Capabilities = cap _no _folders ;
bindToolbar ( data ) ;
return ` <div class="no_folder_found"> ${ lg . could _not _retrieve _folder } </div> ` ;
} ;
var getGridView = function ( data , capabilities ) {
let ret _ele = '<ul id="contents" class="grid">' ,
no _data = _ . isEmpty ( data ) ;
if ( ! no _data ) {
ret _ele += Object . keys ( data ) . sort ( function keyOrder ( x , y ) {
return pgAdmin . natural _sort ( x . toLowerCase ( ) , y . toLowerCase ( ) ) ;
} ) . map ( function ( key ) {
let item _data = data [ key ] ,
props = item _data . Properties ,
filename = _ . escape ( item _data . Filename ) ,
icon _type = '' ,
cap _classes = '' ;
cap _classes = Object . keys ( capabilities ) . map ( function ( cap ) {
if ( has _capability ( item _data , capabilities [ cap ] ) ) {
return 'cap_' + capabilities [ cap ] ;
}
} ) . join ( ' ' ) ;
item _data . Capabilities = capabilities ;
bindToolbar ( item _data ) ;
2017-02-03 10:51:36 +01:00
2020-01-10 12:53:32 +05:30
if ( item _data . file _type == 'dir' ) {
icon _type = 'fa fa-folder-open fm_folder_grid' ;
} else if ( item _data . file _type == 'drive' ) {
2020-08-13 12:04:00 +05:30
icon _type = 'fa fa-hdd fm_drive' ;
2020-01-10 12:53:32 +05:30
} else {
2020-08-13 12:04:00 +05:30
icon _type = 'fa fa-file-alt fm_file_grid' ;
2020-01-10 12:53:32 +05:30
}
/* For the html ele */
let item _ele =
2020-01-31 11:43:30 +05:30
` <li class=" ${ cap _classes } " tabindex="0">
2020-01-10 12:53:32 +05:30
< div class = "clip" >
< span data - alt = "${_.escape(item_data.Path)}" class = "${icon_type}" > < / s p a n > ` ;
if ( item _data . Protected == 1 ) {
item _ele += '<span class="fa fa-lock fm_lock_icon" data-protected="protected" role="img"></span>' ;
}
item _ele += '</div>' ;
if ( ! has _capability ( item _data , 'rename' ) ) {
item _ele += ` <span> ${ filename } </span> ` ;
} else {
item _ele +=
` <div>
< input type = "text" class = "fm_file_rename" / >
< span class = "less_text" title = "${filename}" > $ { filename } < / s p a n >
< / d i v > ` ;
}
if ( props . Width && props . Width != '' ) {
item _ele += ` <span class="meta dimensions"> ${ props . Width } x ${ props . Height } </span> ` ;
}
if ( props . Size && props . Size != '' ) {
item _ele += ` <span class="meta size"> ${ props . Size } </span> ` ;
}
if ( props [ 'Date Created' ] && props [ 'Date Created' ] != '' ) {
item _ele += ` <span class="meta created"> ${ props [ 'Date Created' ] } </span> ` ;
}
if ( props [ 'Date Modified' ] && props [ 'Date Modified' ] != '' ) {
item _ele += ` <span class="meta modified"> ${ props [ 'Date Modified' ] } </span> ` ;
}
item _ele += '</li>' ;
return item _ele ;
} ) . join ( '\n' ) ;
}
ret _ele += '</ul>' ;
if ( no _data ) {
ret _ele += getNoDataView ( data ) ;
}
return ret _ele ;
} ;
var getListView = function ( data , capabilities ) {
let lg = pgAdmin . FileUtils . lg ;
let no _data = _ . isEmpty ( data ) ;
/ * f i l e _ l i s t i n g _ t a b l e c l a s s m a k e s h e i g h t 1 0 0 % , b e c a u s e o f w h i c h N o f o l d e r m e s s a g e i s n o t d i s p l a y e d
* file _listing _table _no _data will be removed when new folder is created
* /
let ret _ele =
` <table id="contents" class="table table-bordered table-noouter-border table-bottom-border table-right-border table-hover tablesorter file_listing_table ${ no _data ? 'file_listing_table_no_data' : '' } ">
< thead >
< tr >
2020-01-31 11:43:30 +05:30
< th tabindex = "0" >
2020-01-10 12:53:32 +05:30
< span > $ { lg . name } < / s p a n >
< / t h >
< th class = "sorter-metric" data - metric - name - full = "byte|Byte|BYTE" data - metric - name - abbr = "b|B" >
< span > $ { lg . size } < / s p a n >
< / t h >
< th class = "sorter-shortDate" >
< span > $ { lg . modified } < / s p a n >
< / t h >
< / t r >
< / t h e a d >
< tbody > ` ;
if ( ! no _data ) {
ret _ele += Object . keys ( data ) . sort ( function keyOrder ( x , y ) {
return pgAdmin . natural _sort ( x . toLowerCase ( ) , y . toLowerCase ( ) ) ;
} ) . map ( function ( key ) {
let item _data = data [ key ] ,
props = item _data . Properties ,
icon _type = '' ,
class _type = '' ,
cap _classes = '' ;
cap _classes = Object . keys ( capabilities ) . map ( function ( cap ) {
if ( has _capability ( item _data , capabilities [ cap ] ) ) {
return 'cap_' + capabilities [ cap ] ;
}
} ) . join ( ' ' ) ;
item _data . Capabilities = capabilities ;
bindToolbar ( item _data ) ;
if ( item _data . file _type == 'dir' ) {
class _type = 'tbl_folder' ;
icon _type = 'fa fa-folder-open fm_folder_list' ;
} else if ( item _data . file _type == 'drive' ) {
class _type = 'tbl_drive' ;
2020-08-13 12:04:00 +05:30
icon _type = 'fa fa-hdd' ;
2020-01-10 12:53:32 +05:30
} else {
class _type = 'tbl_file' ;
2020-08-13 12:04:00 +05:30
icon _type = 'fa fa-file-alt' ;
2020-01-10 12:53:32 +05:30
}
/* For the html ele */
let item _ele =
2020-01-31 11:43:30 +05:30
` <tr class=" ${ cap _classes } " tabindex="0">
2020-01-10 12:53:32 +05:30
< td title = "${_.escape(item_data.Path)}" class = "${class_type}" > ` ;
let data _protected = '' ;
if ( item _data . Protected == 1 ) {
data _protected = '<i class="fa fa-lock tbl_lock_icon" data-protected="protected" role="img"></i>' ;
}
if ( ! has _capability ( data [ key ] , 'rename' ) ) {
item _ele +=
` ${ data _protected } ;
< span title = "${item_data.Filename}" > $ { _ . escape ( item _data . Filename ) } < / s p a n > ` ;
} else {
item _ele +=
` <div>
2020-09-15 13:03:18 +05:30
< input aria - label = "file_rename" type = "text" class = "fm_file_rename" / >
2020-01-10 12:53:32 +05:30
< div class = "fm_file_name" >
< div class = "d-flex" >
< span class = "fm_file_list ${icon_type}" > < / s p a n >
$ { data _protected }
< span class = "less_text ml-2" title = "${item_data.Filename}" > $ { _ . escape ( item _data . Filename ) } < / s p a n >
< / d i v >
< div >
< / d i v > ` ;
}
item _ele += '</td>' ;
if ( props . Size && props . Size != '' ) {
item _ele += ` <td><span class="less_text" title=" ${ props . Size } "> ${ props . Size } </span></td> ` ;
} else {
item _ele += '<td></td>' ;
}
if ( props [ 'Date Modified' ] && props [ 'Date Modified' ] != '' ) {
item _ele += ` <td> ${ props [ 'Date Modified' ] } </td> ` ;
} else {
item _ele += '<td></td>' ;
}
item _ele += '</tr>' ;
return item _ele ;
} ) . join ( '\n' ) ;
}
ret _ele +=
` </tbody>
< / t a b l e > ` ;
if ( no _data ) {
ret _ele += getNoDataView ( data ) ;
}
return ret _ele ;
} ;
2016-05-13 00:04:28 +05:30
2021-07-06 19:00:08 +05:30
var enableSelect = function ( ) {
// Enable select button if user select folder.
if ( pgAdmin . FileUtils . data && pgAdmin . FileUtils . data . Capabilities . includes ( 'select_folder' ) ) {
$ ( '.file_manager_ok' ) . removeClass ( 'disabled' ) ;
$ ( '.file_manager_ok' ) . attr ( 'disabled' , false ) ;
}
} ;
var disableSelect = function ( ) {
// Disable select button if user select file.
$ ( '.file_manager_ok' ) . addClass ( 'disabled' ) ;
$ ( '.file_manager_ok' ) . attr ( 'disabled' , true ) ;
} ;
2018-01-12 12:59:51 +05:30
/ *
* Retrieves data for all items within the given folder and
* creates a list view .
* /
2020-01-10 12:53:32 +05:30
var getFolderInfo = function ( path , file _type , user _input ) {
2018-01-12 12:59:51 +05:30
$ ( '.storage_dialog #uploader .input-path' ) . prop ( 'disabled' , true ) ;
if ( ! file _type ) {
file _type = '' ;
}
var capabilities = pgAdmin . FileUtils . data . Capabilities ;
2021-07-06 19:00:08 +05:30
enableSelect ( ) ;
2021-06-28 18:46:41 +05:30
2018-01-12 12:59:51 +05:30
// Update location for status, upload, & new folder functions.
pgAdmin . FileUtils . setUploader ( path ) ;
2020-01-10 12:53:32 +05:30
if ( user _input ) {
$ ( '.storage_dialog #uploader .input-path' ) . val ( path + user _input ) ;
}
2017-02-03 10:51:36 +01:00
2018-01-12 12:59:51 +05:30
// set default selected file type
if ( file _type === '' ) {
file _type = $ ( '.change_file_types select' ) . val ( ) ;
}
2017-02-03 10:51:36 +01:00
2018-01-12 12:59:51 +05:30
// navigate to directory or path when clicked on breadcrumbs
2018-05-25 16:26:37 +01:00
$ ( '.file_manager a.breadcrumbs' ) . off ( ) . on ( 'click' , function ( ) {
2018-01-12 12:59:51 +05:30
var curr _path = $ ( this ) . attr ( 'data-path' ) ,
2016-05-13 00:04:28 +05:30
current _dir = $ ( this ) . html ( ) ,
2016-05-14 15:29:03 +05:30
move _to = curr _path . substring (
0 , curr _path . lastIndexOf ( current _dir )
) + current _dir ;
2018-01-12 12:59:51 +05:30
getFolderInfo ( move _to ) ;
enab _dis _level _up ( ) ;
} ) ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
// hide select file if we are listing drives in windows.
if ( pgAdmin . FileUtils . hideButtons ( ) ) {
$ ( '.allowed_file_types .change_file_types' ) . hide ( ) ;
} else {
$ ( '.allowed_file_types .change_file_types' ) . show ( ) ;
}
2016-05-14 15:29:03 +05:30
2018-01-12 12:59:51 +05:30
var loading _icon _url = url _for (
'static' , {
2019-09-13 11:03:12 +05:30
'filename' : 'js/generated/load-root.gif' ,
2016-05-14 15:29:03 +05:30
}
2018-01-12 12:59:51 +05:30
) ;
// Display an activity indicator.
$ ( '.fileinfo' ) . find ( 'span.activity' ) . html (
'<img src="' + loading _icon _url + '" alt="' + gettext ( 'Loading...' ) + '/>'
) ;
var post _data = {
'path' : path ,
'mode' : 'getfolder' ,
'file_type' : file _type || '*' ,
'show_hidden' : $ ( '#show_hidden' ) . prop ( 'checked' ) ,
} ;
$ . ajax ( {
type : 'POST' ,
data : JSON . stringify ( post _data ) ,
url : pgAdmin . FileUtils . fileConnector ,
dataType : 'json' ,
contentType : 'application/json; charset=utf-8' ,
async : false ,
2018-07-09 13:54:00 +01:00
} )
2019-03-14 15:11:16 +00:00
. done ( function ( resp ) {
$ ( '.storage_dialog #uploader .input-path' ) . prop ( 'disabled' , false ) ;
var result = '' ,
data = resp . data . result ;
2020-01-31 11:43:30 +05:30
let isGridView = false ;
2019-03-14 15:11:16 +00:00
// hide activity indicator
$ ( '.fileinfo' ) . find ( 'span.activity' ) . hide ( ) ;
if ( data . Code === 0 ) {
Alertify . error ( data . Error ) ;
return ;
}
2016-05-13 00:04:28 +05:30
2019-03-14 15:11:16 +00:00
var $this , orig _value , newvalue ;
// generate HTML for files/folder and render into container
2020-01-10 12:53:32 +05:30
if ( $ ( '.fileinfo' ) . data ( 'view' ) == 'grid' ) {
result += getGridView ( data , capabilities ) ;
2020-01-31 11:43:30 +05:30
isGridView = true ;
2020-01-10 12:53:32 +05:30
} else {
result += getListView ( data , capabilities ) ;
}
2016-05-13 00:04:28 +05:30
2020-01-10 12:53:32 +05:30
// Add the new markup to the DOM.
$ ( '.fileinfo .file_listing' ) . html ( result ) ;
Improvement in the look and feel of the whole application
Changed the SCSS/CSS for the below third party libraries to adopt the
new look 'n' feel:
- wcDocker
- Alertify dialogs, and notifications
- AciTree
- Bootstrap Navbar
- Bootstrap Tabs
- Bootstrap Drop-Down menu
- Backgrid
- Select2
Adopated the new the look 'n' feel for the dialogs, wizard, properties,
tab panels, tabs, fieldset, subnode control, spinner control, HTML
table, and other form controls.
- Font is changed to Roboto
- Using SCSS variables to define the look 'n' feel
- Designer background images for the Login, and Forget password pages in
'web' mode
- Improved the look 'n' feel for the key selection in the preferences
dialog
- Table classes consistency changes across the application
- File Open and Save dialog list view changes
Author(s): Aditya Toshniwal & Khushboo Vashi
2018-12-21 17:14:55 +05:30
2020-01-10 12:53:32 +05:30
let $listing _table = $ ( '.fileinfo .file_listing .file_listing_table' ) ;
2016-05-13 00:04:28 +05:30
2020-01-10 12:53:32 +05:30
$listing _table . tablesorter ( {
widgets : [ 'resizable' , 'stickyHeaders' ] ,
widgetOptions : {
stickyHeaders _attachTo : '.file_listing' ,
stickyHeaders _offset : 0 ,
resizable _widths : [ '400px' , '100px' , '175px' ] ,
} ,
} ) ;
2016-05-13 00:04:28 +05:30
2020-01-10 12:53:32 +05:30
/ * I n o r d e r t o f i t o u r U I , s o m e t h i n g s n e e d t o b e e x p l i c i t l y s e t
* as tablesorter resizable is creating trouble .
* /
$listing _table . on ( 'resizableComplete' , function ( ) {
let wo = this . config . widgetOptions ;
$ . tablesorter . resizable . setWidth ( $listing _table . find ( 'th[data-column="2"]' ) , wo . resizable _widths [ 2 ] ) ;
} ) ;
2016-05-14 15:29:03 +05:30
2020-01-31 11:43:30 +05:30
/* Role of this function is to click or double click on element when user is doing keyboard navigation*/
var clickOnFileFolderManually = function ( event ) {
let self = this ;
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
// if file/folder is protected do nothing
if ( $ ( this ) . find ( '.fa-lock' ) . length )
return ;
2020-11-19 10:33:05 +05:30
if ( $ ( this ) . find ( '.fa-file-alt' ) . length || $ ( this ) . find ( '.tbl_folder_rename' ) . length > 0 )
2020-01-31 11:43:30 +05:30
$ ( this ) . click ( ) ;
2020-02-07 11:13:41 +05:30
// If folder then first select and then double click to open folder/drive
2020-08-13 12:04:00 +05:30
else if ( $ ( this ) . find ( '.fa-folder-open' ) . length || $ ( this ) . find ( '.fa-hdd' ) . length ) {
2020-01-31 11:43:30 +05:30
$ ( this ) . click ( ) ;
setTimeout ( ( ) => { $ ( self ) . trigger ( 'dblclick' ) ; } , 10 ) ;
}
} ;
2020-01-10 12:53:32 +05:30
$listing _table . on ( 'tablesorter-ready' , function ( ) {
let wo = this . config . widgetOptions ;
if ( $ . tablesorter . storage ( $listing _table [ 0 ] , 'tablesorter-table-resized-width' ) === '' ) {
$ . tablesorter . resizable . setWidth ( $listing _table , $ ( '.fileinfo .file_listing' ) . width ( ) ) ;
2018-07-09 13:54:00 +01:00
}
2020-01-10 12:53:32 +05:30
$ . tablesorter . resizable . setWidth ( $listing _table . find ( 'th[data-column="2"]' ) , wo . resizable _widths [ 2 ] ) ;
$listing _table . trigger ( 'resizableUpdate' ) ;
2020-01-31 11:43:30 +05:30
// Table Sorter writes table elements randomly so we need to handle some corner cases manually
$ ( '#show_hidden' ) . off ( 'keydown' ) . on ( 'keydown' , function ( event ) {
if ( ! isGridView && event . keyCode == 9 && event . shiftKey ) {
event . preventDefault ( ) ;
$listing _table . find ( 'tbody tr:last' ) . trigger ( 'focus' ) ;
}
} ) ;
$listing _table . find ( 'tbody tr' ) . off ( 'keydown' ) . on ( 'keydown' , function ( event ) {
// If key is pressed then we need to trigger click so that it can select file
if ( event . keyCode == 13 || event . keyCode == 32 ) {
clickOnFileFolderManually . call ( this , event ) ;
} else if ( event . keyCode == 9 ) {
if ( event . shiftKey ) {
// When first tr losses focus and shift + tab > we need to set focus on header
if ( $ ( this ) . prev ( ) . length == 0 ) {
event . preventDefault ( ) ;
$listing _table . find ( 'th.tablesorter-header:last' ) . trigger ( 'focus' ) ;
}
} else {
// When last tr losses focus and Tab was pressed > we need to set focus on checkbox
if ( $ ( this ) . next ( ) . length == 0 ) {
event . preventDefault ( ) ;
$ ( '#show_hidden' ) . trigger ( 'focus' ) ;
}
}
}
} ) ;
$listing _table . find ( 'th.tablesorter-header' ) . off ( 'keydown' ) . on ( 'keydown' , function ( event ) {
// If key is pressed then we need to trigger click so that it can sort
if ( event . keyCode == 13 || event . keyCode == 32 ) {
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
$ ( this ) . trigger ( 'click' ) ;
}
} ) ;
2020-01-10 12:53:32 +05:30
} ) ;
2018-07-09 13:54:00 +01:00
2020-01-31 11:43:30 +05:30
if ( isGridView ) {
$ ( '.file_manager' ) . find ( '#contents li' ) . off ( 'keydown' ) . on ( 'keydown' , function ( event ) {
// If key is pressed then we need to trigger click so that it can sort
if ( event . keyCode == 13 || event . keyCode == 32 ) {
clickOnFileFolderManually . call ( this , event ) ;
}
} ) ;
}
2019-03-14 15:11:16 +00:00
// rename file/folder
$ ( '.file_manager button.rename' ) . off ( ) . on ( 'click' , function ( e ) {
2016-05-14 15:29:03 +05:30
2019-03-14 15:11:16 +00:00
if ( $ ( '.fileinfo' ) . data ( 'view' ) == 'grid' ) {
e . stopPropagation ( ) ;
$this = $ ( '.file_manager' ) . find ( '#contents li.selected div' ) ;
orig _value = decodeURI ( $this . find ( 'span.less_text' ) . attr ( 'title' ) ) ;
newvalue = orig _value . substring ( 0 , orig _value . indexOf ( '.' ) ) ;
2016-05-21 15:01:47 +05:30
2019-03-14 15:11:16 +00:00
if ( newvalue === '' ) {
newvalue = decodeURI ( orig _value ) ;
2018-07-09 13:54:00 +01:00
}
2019-03-14 15:11:16 +00:00
$this . find ( 'input' ) . toggle ( ) . val ( newvalue ) . trigger ( 'focus' ) ;
$this . find ( 'span' ) . toggle ( ) ;
2018-07-09 13:54:00 +01:00
2019-03-14 15:11:16 +00:00
// Rename folder/file on pressing enter key
2020-06-30 17:26:18 +05:30
$ ( '.file_manager' ) . off ( ) . on ( 'keyup' , function ( event ) {
if ( event . keyCode == 13 ) {
event . stopPropagation ( ) ;
2019-03-14 15:11:16 +00:00
$ ( '.fileinfo #contents li.selected div' ) . find (
'input'
) . trigger ( 'blur' ) ;
}
} ) ;
} else if ( $ ( '.fileinfo' ) . data ( 'view' ) == 'list' ) {
e . stopPropagation ( ) ;
$this = $ ( '.fileinfo' ) . find (
2020-01-10 12:53:32 +05:30
'table#contents tbody tr.selected td.tbl_file'
2018-01-12 12:59:51 +05:30
) ;
2020-11-19 10:33:05 +05:30
if ( $this . length == 0 ) {
$this = $ ( '.fileinfo' ) . find (
'table#contents tbody tr.selected td.tbl_folder'
) ;
// putting temporary class to distiguish between folder rename & double click.
$this . addClass ( 'tbl_folder_rename' ) ;
}
2020-06-18 16:17:55 +05:30
orig _value = decodeURI ( $this . find ( 'span.less_text' ) . html ( ) ) ;
2019-03-14 15:11:16 +00:00
newvalue = orig _value . substring ( 0 , orig _value . lastIndexOf ( '.' ) ) ;
2016-05-14 15:29:03 +05:30
2020-11-19 10:33:05 +05:30
if ( orig _value . lastIndexOf ( '/' ) == orig _value . length - 1 || ( _ . isEmpty ( newvalue ) || _ . isUndefined ( newvalue ) || _ . isNull ( newvalue ) ) ) {
2019-03-14 15:11:16 +00:00
newvalue = decodeURI ( orig _value ) ;
2018-07-09 13:54:00 +01:00
}
2016-05-13 00:04:28 +05:30
2020-01-10 12:53:32 +05:30
$this . find ( '.fm_file_rename' ) . toggle ( ) . val ( newvalue ) . trigger ( 'focus' ) ;
$this . find ( '.fm_file_name' ) . toggle ( ) ;
2016-05-13 00:04:28 +05:30
2019-03-14 15:11:16 +00:00
// Rename folder/file on pressing enter key
2020-06-30 17:26:18 +05:30
$ ( '.file_manager' ) . off ( ) . on ( 'keyup' , function ( event ) {
if ( event . keyCode == 13 ) {
event . stopPropagation ( ) ;
2020-11-19 10:33:05 +05:30
$this . find ( 'fm_file_rename' ) . trigger ( 'blur' ) ;
2019-03-14 15:11:16 +00:00
}
} ) ;
2018-07-09 13:54:00 +01:00
}
2019-03-14 15:11:16 +00:00
} ) ;
// Rename UI handling
$ ( '.fileinfo #contents li div' ) . on ( 'blur dblclick' , 'input' , function ( e ) {
2018-01-12 12:59:51 +05:30
e . stopPropagation ( ) ;
2016-05-13 00:04:28 +05:30
2020-09-29 11:03:38 +05:30
var old _name = decodeURI ( $ ( this ) . siblings ( 'div' ) . find ( '.less_text' ) . attr ( 'title' ) ) ;
2019-03-14 15:11:16 +00:00
newvalue = old _name . substring ( 0 , old _name . indexOf ( '.' ) ) ;
var last = getFileExtension ( old _name ) ,
2020-07-09 18:35:04 +05:30
file _data , new _name , file _path , full _name ;
2019-03-14 15:11:16 +00:00
2018-01-12 12:59:51 +05:30
if ( old _name . indexOf ( '.' ) == 0 ) {
last = '' ;
}
2016-05-14 15:29:03 +05:30
2018-01-12 12:59:51 +05:30
if ( newvalue == '' ) {
2019-03-14 15:11:16 +00:00
newvalue = decodeURI ( old _name ) ;
2016-05-14 15:29:03 +05:30
}
2016-05-13 00:04:28 +05:30
2019-03-14 15:11:16 +00:00
if ( e . type == 'keydown' ) {
if ( e . which == 13 ) {
full _name = decodeURI ( $ ( this ) . val ( ) ) + (
2018-01-12 12:59:51 +05:30
last !== '' ? '.' + last : ''
) ;
2019-03-14 15:11:16 +00:00
2018-01-12 12:59:51 +05:30
$ ( this ) . toggle ( ) ;
$ ( this ) . siblings ( 'span' ) . toggle ( ) . html ( full _name ) ;
2019-03-14 15:11:16 +00:00
new _name = decodeURI ( $ ( this ) . val ( ) ) ;
2020-07-09 18:35:04 +05:30
file _path = decodeURI ( $ ( this ) . parent ( ) . parent ( ) . find (
2019-03-14 15:11:16 +00:00
'span'
) . attr ( 'data-alt' ) ) ;
2020-07-09 18:35:04 +05:30
file _data = {
2019-03-14 15:11:16 +00:00
'Filename' : old _name ,
2020-07-09 18:35:04 +05:30
'Path' : file _path ,
2019-03-14 15:11:16 +00:00
'NewFilename' : new _name ,
} ;
2018-01-12 12:59:51 +05:30
if ( newvalue !== new _name ) {
2020-07-09 18:35:04 +05:30
renameItem ( file _data ) ;
2019-03-14 15:11:16 +00:00
var parent = $ ( '.currentpath' ) . val ( ) ;
2018-01-12 12:59:51 +05:30
getFolderInfo ( parent ) ;
}
2019-03-14 15:11:16 +00:00
e . stopPropagation ( ) ;
}
if (
e . which == 38 || e . which == 40 || e . which == 37 ||
e . which == 39 || e . keyCode == 32
) {
e . stopPropagation ( ) ;
}
} else if ( e . type == 'focusout' ) {
if ( $ ( this ) . css ( 'display' ) == 'inline-block' || $ ( this ) . css ( 'display' ) == 'inline' ) {
full _name = decodeURI (
$ ( this ) . val ( )
) + ( last !== '' ? '.' + last : '' ) ;
2020-11-19 10:33:05 +05:30
if ( newvalue !== new _name ) {
2019-03-14 15:11:16 +00:00
2020-11-19 10:33:05 +05:30
$ ( this ) . toggle ( ) ;
$ ( this ) . siblings ( 'span' ) . toggle ( ) . html ( full _name ) ;
//check if user is trying to rename folder
let isFolder = $ ( this ) . closest ( '.tbl_folder' ) . length > 0 ;
new _name = decodeURI ( $ ( this ) . val ( ) ) ;
file _path = decodeURI ( $ ( this ) . parent ( ) . parent ( ) . find (
'span'
) . attr ( 'data-alt' ) ) ;
file _data = {
'Filename' : old _name ,
'Path' : file _path ,
'NewFilename' : new _name ,
'isFolder' : isFolder ,
} ;
2019-03-14 15:11:16 +00:00
2020-07-09 18:35:04 +05:30
renameItem ( file _data ) ;
2021-01-18 13:02:19 +05:30
let current _path = $ ( '.currentpath' ) . val ( ) ;
2020-11-19 10:33:05 +05:30
if ( isFolder == true ) {
// if its folder rename, remove the temporary added class
$ ( this ) . closest ( '.tbl_folder' ) . removeClass ( 'tbl_folder_rename' ) ;
2021-01-18 13:02:19 +05:30
if ( current _path . includes ( '\\' ) ) {
current _path = $ ( '.currentpath' ) . val ( ) . split ( '\\' ) . slice ( 0 , - 2 ) . join ( '\\' ) + '\\' ;
2020-11-19 10:33:05 +05:30
}
else {
2021-01-18 13:02:19 +05:30
current _path = $ ( '.currentpath' ) . val ( ) . split ( '/' ) . slice ( 0 , - 2 ) . join ( '/' ) + '/' ;
2020-11-19 10:33:05 +05:30
}
}
2021-01-18 13:02:19 +05:30
getFolderInfo ( current _path ) ;
2019-03-14 15:11:16 +00:00
}
2018-01-12 12:59:51 +05:30
}
} else {
e . stopPropagation ( ) ;
}
} ) ;
2016-05-13 00:04:28 +05:30
2019-03-14 15:11:16 +00:00
$ ( '.fileinfo table#contents tr td div' ) . on (
'blur dblclick' , 'input' ,
function ( e ) {
2020-09-29 11:03:38 +05:30
var old _name = decodeURI ( $ ( this ) . siblings ( 'div' ) . find ( '.less_text' ) . attr ( 'title' ) ) ,
2020-07-09 18:35:04 +05:30
new _value = old _name . substring ( 0 , old _name . indexOf ( '.' ) ) ,
2019-03-14 15:11:16 +00:00
last = getFileExtension ( old _name ) ;
if ( old _name . indexOf ( '.' ) == 0 ) {
last = '' ;
}
2020-07-09 18:35:04 +05:30
if ( new _value == '' ) {
new _value = old _name ;
2019-03-14 15:11:16 +00:00
}
if ( e . type == 'focusout' ) {
if ( $ ( this ) . css ( 'display' ) == 'inline-block' || $ ( this ) . css ( 'display' ) == 'inline' ) {
var full _name = decodeURI ( $ ( this ) . val ( ) ) + (
last !== '' ? '.' + last : ''
) ;
2020-07-09 18:35:04 +05:30
if ( new _value !== new _name ) {
2020-11-19 10:33:05 +05:30
$ ( this ) . toggle ( ) ;
$ ( this ) . siblings ( 'span' ) . toggle ( ) . html ( full _name ) ;
let isFolder = $ ( this ) . closest ( '.tbl_folder' ) . length > 0 ;
var new _name = decodeURI ( $ ( this ) . val ( ) ) ,
file _path = decodeURI ( $ ( this ) . parent ( ) . parent ( ) . attr ( 'title' ) ) ,
file _data = {
'Filename' : old _name ,
'Path' : file _path ,
'NewFilename' : new _name ,
'isFolder' : isFolder ,
} ;
2020-07-09 18:35:04 +05:30
renameItem ( file _data ) ;
2021-01-18 13:02:19 +05:30
let current _path = $ ( '.currentpath' ) . val ( ) ;
2020-11-19 10:33:05 +05:30
if ( isFolder == true ) {
// if its folder rename, remove the temporary added class
$ ( this ) . closest ( '.tbl_folder' ) . removeClass ( 'tbl_folder_rename' ) ;
2021-01-18 13:02:19 +05:30
if ( current _path . includes ( '\\' ) ) {
current _path = $ ( '.currentpath' ) . val ( ) . split ( '\\' ) . slice ( 0 , - 2 ) . join ( '\\' ) + '\\' ;
2020-11-19 10:33:05 +05:30
}
else {
2021-01-18 13:02:19 +05:30
current _path = $ ( '.currentpath' ) . val ( ) . split ( '/' ) . slice ( 0 , - 2 ) . join ( '/' ) + '/' ;
2020-11-19 10:33:05 +05:30
}
}
2021-01-18 13:02:19 +05:30
getFolderInfo ( current _path ) ;
2019-03-14 15:11:16 +00:00
}
}
} else {
e . stopPropagation ( ) ;
}
} ) ;
var data _cap = { } ;
data _cap . Capabilities = capabilities ;
/ *
2018-07-09 13:54:00 +01:00
* Bind click events
* Select items - afolder dblclick
* /
2019-03-14 15:11:16 +00:00
if ( $ ( '.fileinfo' ) . data ( 'view' ) == 'grid' ) {
2018-07-09 13:54:00 +01:00
// Get into folder on dblclick
2019-03-14 15:11:16 +00:00
$ ( '.fileinfo' ) . find ( '#contents li' ) . dblclick ( function ( e ) {
e . stopPropagation ( ) ;
// Enable/Disable level up button
enab _dis _level _up ( ) ;
2016-05-13 00:04:28 +05:30
2020-07-09 18:35:04 +05:30
var file _path = decodeURI ( $ ( this ) . find ( 'span' ) . attr ( 'data-alt' ) ) ;
2016-05-13 00:04:28 +05:30
2020-07-09 18:35:04 +05:30
if ( file _path . lastIndexOf ( '/' ) == file _path . length - 1 || file _path . lastIndexOf ( '\\' ) == file _path . length - 1 ) {
2019-03-14 15:11:16 +00:00
$ ( '.file_manager_ok' ) . addClass ( 'disabled' ) ;
$ ( '.file_manager_ok' ) . attr ( 'disabled' , true ) ;
$ ( '.file_manager button.delete, .file_manager button.rename' ) . attr ( 'disabled' , 'disabled' ) ;
$ ( '.file_manager button.download' ) . attr ( 'disabled' , 'disabled' ) ;
2018-01-12 12:59:51 +05:30
2020-07-09 18:35:04 +05:30
getFolderInfo ( file _path ) ;
2016-05-14 15:29:03 +05:30
2019-03-14 15:11:16 +00:00
} else {
2020-07-09 18:35:04 +05:30
var is _valid _file = getFileInfo ( file _path ) ;
2019-03-14 15:11:16 +00:00
if ( is _valid _file && check _file _capability ( e , data _cap , 'grid' ) ) {
$ ( '.file_manager_ok' ) . trigger ( 'click' ) ;
}
2018-07-09 13:54:00 +01:00
}
2019-03-14 15:11:16 +00:00
} ) ;
2016-05-14 15:29:03 +05:30
2019-03-14 15:11:16 +00:00
$ ( '.fileinfo' ) . find ( '#contents li' ) . on ( 'click' , function ( e ) {
e . stopPropagation ( ) ;
2020-07-09 18:35:04 +05:30
var file _path = decodeURI ( $ ( this ) . find ( '.clip span' ) . attr ( 'data-alt' ) ) ,
2019-03-14 15:11:16 +00:00
is _protected = $ ( this ) . find (
'.clip span.fm_lock_icon'
) . attr ( 'data-protected' ) ;
2020-07-09 18:35:04 +05:30
if ( file _path . lastIndexOf ( '/' ) == file _path . length - 1 || file _path . lastIndexOf ( '\\' ) == file _path . length - 1 ) {
2019-03-14 15:11:16 +00:00
if (
has _capability ( data _cap , 'select_folder' ) &&
2018-07-09 13:54:00 +01:00
is _protected == undefined
2019-03-14 15:11:16 +00:00
) {
$ ( this ) . parent ( ) . find ( 'li.selected' ) . removeClass ( 'selected' ) ;
$ ( this ) . addClass ( 'selected' ) ;
$ ( '.file_manager_ok' ) . removeClass ( 'disabled' ) ;
$ ( '.file_manager_ok' ) . attr ( 'disabled' , false ) ;
2020-11-19 10:33:05 +05:30
$ ( '.file_manager button.delete, .file_manager button.rename' ) . removeAttr (
2019-03-14 15:11:16 +00:00
'disabled' , 'disabled'
) ;
$ ( '.file_manager button.download' ) . attr (
'disabled' , 'disabled'
) ;
// set selected folder name in breadcrums
$ ( '.file_manager #uploader .input-path' ) . hide ( ) ;
$ ( '.file_manager #uploader .show_selected_file' ) . remove ( ) ;
2020-07-09 18:35:04 +05:30
$ ( '<span class="show_selected_file">' + file _path + '</span>' ) . appendTo (
2019-03-14 15:11:16 +00:00
'.file_manager #uploader .filemanager-path-group'
) ;
}
2020-07-09 18:35:04 +05:30
pgAdmin . FileUtils . setUploader ( file _path ) ;
2019-03-14 15:11:16 +00:00
} else {
if (
has _capability ( data _cap , 'select_file' ) &&
2018-07-09 13:54:00 +01:00
is _protected == undefined
2019-03-14 15:11:16 +00:00
) {
$ ( this ) . parent ( ) . find ( 'li.selected' ) . removeClass ( 'selected' ) ;
$ ( this ) . addClass ( 'selected' ) ;
$ ( '.file_manager_ok' ) . removeClass ( 'disabled' ) ;
$ ( '.file_manager_ok' ) . attr ( 'disabled' , false ) ;
$ ( '.file_manager button.delete, .file_manager button.download, .file_manager button.rename' ) . removeAttr (
'disabled'
) ;
// set selected folder name in breadcrums
$ ( '.file_manager #uploader .show_selected_file' ) . remove ( ) ;
}
2016-05-14 15:29:03 +05:30
2020-07-09 18:35:04 +05:30
getFileInfo ( file _path ) ;
2016-05-14 15:29:03 +05:30
}
2019-03-14 15:11:16 +00:00
} ) ;
} else {
$ ( '.fileinfo table#contents tbody tr' ) . on ( 'click' , function ( e ) {
e . stopPropagation ( ) ;
2020-07-09 18:35:04 +05:30
var file _path = decodeURI ( $ ( 'td:first-child' , this ) . attr ( 'title' ) ) ,
2019-03-14 15:11:16 +00:00
is _protected = $ ( 'td:first-child' , this ) . find (
'i.tbl_lock_icon'
) . attr ( 'data-protected' ) ;
2020-07-09 18:35:04 +05:30
if ( file _path . lastIndexOf ( '/' ) == file _path . length - 1 || file _path . lastIndexOf ( '\\' ) == file _path . length - 1 ) {
2019-03-14 15:11:16 +00:00
if ( has _capability ( data _cap , 'select_folder' ) && is _protected == undefined ) {
$ ( this ) . parent ( ) . find ( 'tr.selected' ) . removeClass ( 'selected' ) ;
$ ( 'td:first-child' , this ) . parent ( ) . addClass ( 'selected' ) ;
$ ( '.file_manager_ok' ) . removeClass ( 'disabled' ) ;
$ ( '.file_manager_ok' ) . attr ( 'disabled' , false ) ;
$ ( '.file_manager button.download' ) . attr ( 'disabled' , 'disabled' ) ;
2020-11-19 10:33:05 +05:30
$ ( '.file_manager button.delete, .file_manager button.rename' ) . removeAttr ( 'disabled' ) ;
2019-03-14 15:11:16 +00:00
// set selected folder name in breadcrums
$ ( '.file_manager #uploader .input-path' ) . hide ( ) ;
$ ( '.file_manager #uploader .show_selected_file' ) . remove ( ) ;
2020-07-09 18:35:04 +05:30
$ ( '<span class="show_selected_file">' + file _path + '</span>' ) . appendTo (
2019-03-14 15:11:16 +00:00
'.file_manager #uploader .filemanager-path-group'
) ;
}
2020-07-09 18:35:04 +05:30
pgAdmin . FileUtils . setUploader ( file _path ) ;
2019-03-14 15:11:16 +00:00
} else {
if ( has _capability ( data _cap , 'select_file' ) && is _protected == undefined ) {
$ ( this ) . parent ( ) . find ( 'tr.selected' ) . removeClass ( 'selected' ) ;
$ ( 'td:first-child' , this ) . parent ( ) . addClass ( 'selected' ) ;
$ ( '.file_manager button.delete, .file_manager button.download, .file_manager button.rename' ) . removeAttr (
'disabled'
) ;
// set selected folder name in breadcrums
$ ( '.file_manager #uploader .show_selected_file' ) . remove ( ) ;
}
2016-05-13 00:04:28 +05:30
2020-07-09 18:35:04 +05:30
getFileInfo ( file _path ) ;
2019-03-14 15:11:16 +00:00
}
} ) ;
2016-05-13 00:04:28 +05:30
2019-03-14 15:11:16 +00:00
$ ( '.fileinfo table#contents tbody tr' ) . on ( 'dblclick' , function ( e ) {
e . stopPropagation ( ) ;
// Enable/Disable level up button
enab _dis _level _up ( ) ;
2020-07-09 18:35:04 +05:30
var file _path = $ ( 'td:first-child' , this ) . attr ( 'title' ) ;
2018-07-09 13:54:00 +01:00
2020-07-09 18:35:04 +05:30
if ( file _path . lastIndexOf ( '/' ) == file _path . length - 1 || file _path . lastIndexOf ( '\\' ) == file _path . length - 1 ) {
2019-03-14 15:11:16 +00:00
$ ( '.file_manager_ok' ) . addClass ( 'disabled' ) ;
$ ( '.file_manager_ok' ) . attr ( 'disabled' , true ) ;
$ ( '.file_manager button.download' ) . attr ( 'disabled' , 'disabled' ) ;
$ ( '.file_manager button.delete, .file_manager button.rename' ) . attr ( 'disabled' , 'disabled' ) ;
2020-07-09 18:35:04 +05:30
getFolderInfo ( file _path ) ;
2019-03-14 15:11:16 +00:00
} else {
2020-07-09 18:35:04 +05:30
var is _valid _file = getFileInfo ( file _path ) ;
2019-03-14 15:11:16 +00:00
if (
is _valid _file && check _file _capability ( e , data _cap , 'table' )
) {
$ ( '.file_manager_ok' ) . trigger ( 'click' ) ;
}
2017-12-18 09:48:14 +00:00
}
2019-03-14 15:11:16 +00:00
} ) ;
2016-05-13 00:04:28 +05:30
2019-03-14 15:11:16 +00:00
}
2018-07-09 13:54:00 +01:00
//input_object.set_cap(data_cap);
2019-03-14 15:11:16 +00:00
} )
. fail ( function ( ) {
$ ( '.storage_dialog #uploader .input-path' ) . prop ( 'disabled' , false ) ;
} ) ;
2018-01-12 12:59:51 +05:30
} ;
2020-05-04 12:40:19 +05:30
var homedir = '/' ;
2018-01-12 12:59:51 +05:30
// Enable/Disable level up button
var enab _dis _level _up = function ( ) {
$ ( '.file_manager #uploader .input-path' ) . show ( ) ;
$ ( '.show_selected_file' ) . remove ( ) ;
2016-05-14 15:29:03 +05:30
2018-01-12 12:59:51 +05:30
setTimeout ( function ( ) {
var b = $ ( '.currentpath' ) . val ( ) ,
2016-05-14 00:38:58 +05:30
$level _up = $ ( '.file_manager' ) . find ( 'button.level-up' ) ,
2016-05-13 00:04:28 +05:30
$home _btn = $ ( '.file_manager' ) . find ( 'button.home' ) ;
2016-05-14 15:29:03 +05:30
2020-05-04 12:40:19 +05:30
( b === '/' ) ? $level _up . attr ( 'disabled' , 'disabled' ) : $level _up . removeAttr ( 'disabled' ) ;
( b === homedir ) ? $home _btn . attr ( 'disabled' , 'disabled' ) : $home _btn . removeAttr ( 'disabled' ) ;
2018-01-12 12:59:51 +05:30
} , 100 ) ;
} ;
// Check if user can Select file
var check _file _capability = function ( event , data _cap , view _type ) {
var current _element = event . currentTarget ,
is _protected ;
if ( view _type == 'grid' ) {
is _protected = $ ( current _element ) . find (
'.clip span.fm_lock_icon'
) . attr ( 'data-protected' ) ;
2016-05-14 15:29:03 +05:30
} else {
2018-01-12 12:59:51 +05:30
is _protected = $ ( current _element ) . find ( 'td:first-child' ) . find (
'i.tbl_lock_icon'
) . attr ( 'data-protected' ) ;
2016-05-13 00:04:28 +05:30
}
2018-01-12 12:59:51 +05:30
return has _capability ( data _cap , 'select_file' ) &&
is _protected == undefined ;
} ;
2020-10-23 16:14:55 +05:30
// Download selected file
var download _file = function ( path ) {
var data = { 'path' : path , 'mode' : 'download' } ,
params = { } ;
params [ pgAdmin . csrf _token _header ] = pgAdmin . csrf _token ;
$ . ajax ( {
type : 'POST' ,
url : pgAdmin . FileUtils . fileConnector ,
contentType : false ,
headers : params ,
xhrFields : {
responseType : 'blob' ,
} ,
cache : false ,
data : JSON . stringify ( data ) ,
success : function ( blob , status , xhr ) {
// check for a filename
var filename = xhr . getResponseHeader ( 'filename' ) ;
if ( typeof window . navigator . msSaveBlob !== 'undefined' ) {
// IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed."
window . navigator . msSaveBlob ( blob , filename ) ;
} else {
var URL = window . URL || window . webkitURL ;
var downloadUrl = URL . createObjectURL ( blob ) ;
if ( filename ) {
// use HTML5 a[download] attribute to specify filename
var a = document . createElement ( 'a' ) ;
// safari doesn't support this yet
if ( typeof a . download === 'undefined' ) {
window . location . href = downloadUrl ;
} else {
a . href = downloadUrl ;
a . download = filename ;
document . body . appendChild ( a ) ;
a . click ( ) ;
}
} else {
window . location . href = downloadUrl ;
}
setTimeout ( function ( ) { URL . revokeObjectURL ( downloadUrl ) ; } , 100 ) ; // cleanup
}
} ,
error : function ( error ) {
Alertify . error ( error ) ;
} ,
} ) ;
} ;
2018-01-12 12:59:51 +05:30
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Initialization - Entry point
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - * /
/ *
* get transaction id to generate request url and
* to generate config files on runtime
* /
pgAdmin . FileUtils = {
init : function ( ) {
var fm _url = url _for ( 'file_manager.get_trans_id' ) ,
2017-07-18 15:13:16 +01:00
transId = loadData ( fm _url ) ,
t _res ,
t _id ;
2018-01-12 12:59:51 +05:30
if ( transId . readyState == 4 ) {
t _res = JSON . parse ( transId . responseText ) ;
}
2020-06-18 16:20:34 +01:00
t _id = _ . isUndefined ( t _res ) ? 0 : t _res . data . fileTransId ;
2018-01-12 12:59:51 +05:30
var root _url = url _for ( 'file_manager.index' ) ,
file _manager _config _json = root _url + t _id + '/file_manager_config.json' ,
fileConnector = root _url + 'filemanager/' + t _id + '/' ,
2017-07-18 15:13:16 +01:00
cfg = loadData ( file _manager _config _json ) ,
config ;
2018-01-12 12:59:51 +05:30
this . fileConnector = fileConnector ;
this . transId = t _id ;
// load user configuration file
if ( cfg . readyState == 4 ) {
this . config = config = JSON . parse ( cfg . responseText ) ;
2020-05-04 12:40:19 +05:30
homedir = config . options . homedir ;
2018-01-12 12:59:51 +05:30
}
2016-05-13 00:04:28 +05:30
2020-06-18 16:20:34 +01:00
if ( _ . isUndefined ( config ) )
return ;
2018-01-12 12:59:51 +05:30
// set main url to filemanager and its capabilites
var fileRoot = config . options . fileRoot ,
2017-07-18 15:13:16 +01:00
capabilities = config . options . capabilities ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
/ *
* Get localized messages from file
* through culture var or from URL
* /
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
var lg = [ ] ,
2019-01-03 14:50:24 +00:00
enjson = url _for ( 'file_manager.index' ) + 'en.json' ,
lgf = loadData ( enjson ) ;
2017-02-03 10:51:36 +01:00
2018-01-12 12:59:51 +05:30
if ( lgf . readyState == 4 ) {
this . lg = lg = JSON . parse ( lgf . responseText ) ;
}
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
// create and enable user to create new file
if (
config . options . dialog _type == 'select_file' ||
config . options . dialog _type == 'create_file' ||
config . options . dialog _type == 'storage_dialog'
) {
// Create file selection dropdown
var allowed _types = config . options . allowed _file _types ,
2017-07-18 15:13:16 +01:00
types _len = allowed _types . length ,
2018-01-12 12:59:51 +05:30
select _box = '' ;
2017-07-18 15:13:16 +01:00
2018-01-12 12:59:51 +05:30
if ( types _len > 0 ) {
var i = 0 ,
t ,
2017-07-18 15:13:16 +01:00
have _all _types = false ;
Improvement in the look and feel of the whole application
Changed the SCSS/CSS for the below third party libraries to adopt the
new look 'n' feel:
- wcDocker
- Alertify dialogs, and notifications
- AciTree
- Bootstrap Navbar
- Bootstrap Tabs
- Bootstrap Drop-Down menu
- Backgrid
- Select2
Adopated the new the look 'n' feel for the dialogs, wizard, properties,
tab panels, tabs, fieldset, subnode control, spinner control, HTML
table, and other form controls.
- Font is changed to Roboto
- Using SCSS variables to define the look 'n' feel
- Designer background images for the Login, and Forget password pages in
'web' mode
- Improved the look 'n' feel for the key selection in the preferences
dialog
- Table classes consistency changes across the application
- File Open and Save dialog list view changes
Author(s): Aditya Toshniwal & Khushboo Vashi
2018-12-21 17:14:55 +05:30
let fileFormats = '' ;
2021-04-08 12:23:57 +05:30
let response = getFileFormat ( config . options . allowed _file _types ) ;
let lastSelectedFormat = response . responseJSON . info ;
2018-01-12 12:59:51 +05:30
while ( i < types _len ) {
t = allowed _types [ i ] ;
2021-04-08 12:23:57 +05:30
if ( ( types _len == 1 || t != '*' ) ) {
if ( t === lastSelectedFormat )
fileFormats += '<option value=' + t + ' selected >' + t + '</option>' ;
else
fileFormats += '<option value=' + t + ' >' + t + '</option>' ;
2018-01-12 12:59:51 +05:30
have _all _types = ( have _all _types || ( t == '*' ) ) ;
2021-04-08 12:23:57 +05:30
} else if ( ( lastSelectedFormat === '*' ) ) {
fileFormats += '<option value="' + t + '" selected >' +
2018-01-12 12:59:51 +05:30
( t == '*' ? gettext ( 'All Files' ) : t ) + '</option>' ;
have _all _types = ( have _all _types || ( t == '*' ) ) ;
}
i ++ ;
2017-07-18 15:13:16 +01:00
}
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
if ( ! have _all _types ) {
Improvement in the look and feel of the whole application
Changed the SCSS/CSS for the below third party libraries to adopt the
new look 'n' feel:
- wcDocker
- Alertify dialogs, and notifications
- AciTree
- Bootstrap Navbar
- Bootstrap Tabs
- Bootstrap Drop-Down menu
- Backgrid
- Select2
Adopated the new the look 'n' feel for the dialogs, wizard, properties,
tab panels, tabs, fieldset, subnode control, spinner control, HTML
table, and other form controls.
- Font is changed to Roboto
- Using SCSS variables to define the look 'n' feel
- Designer background images for the Login, and Forget password pages in
'web' mode
- Improved the look 'n' feel for the key selection in the preferences
dialog
- Table classes consistency changes across the application
- File Open and Save dialog list view changes
Author(s): Aditya Toshniwal & Khushboo Vashi
2018-12-21 17:14:55 +05:30
fileFormats += '<option value="*">' + gettext ( 'All Files' ) + '</option>' ;
2018-01-12 12:59:51 +05:30
}
Improvement in the look and feel of the whole application
Changed the SCSS/CSS for the below third party libraries to adopt the
new look 'n' feel:
- wcDocker
- Alertify dialogs, and notifications
- AciTree
- Bootstrap Navbar
- Bootstrap Tabs
- Bootstrap Drop-Down menu
- Backgrid
- Select2
Adopated the new the look 'n' feel for the dialogs, wizard, properties,
tab panels, tabs, fieldset, subnode control, spinner control, HTML
table, and other form controls.
- Font is changed to Roboto
- Using SCSS variables to define the look 'n' feel
- Designer background images for the Login, and Forget password pages in
'web' mode
- Improved the look 'n' feel for the key selection in the preferences
dialog
- Table classes consistency changes across the application
- File Open and Save dialog list view changes
Author(s): Aditya Toshniwal & Khushboo Vashi
2018-12-21 17:14:55 +05:30
select _box = ` <div class='change_file_types d-flex align-items-center p-1'>
2020-03-24 11:14:05 +05:30
< div > ` +
gettext ( 'Show hidden files and folders?' ) +
2020-09-15 13:03:18 +05:30
` <input aria-label="Show hidden files and folders" type='checkbox' id='show_hidden' onclick='pgAdmin.FileUtils.handleClick(this)' tabindex='0'>
Improvement in the look and feel of the whole application
Changed the SCSS/CSS for the below third party libraries to adopt the
new look 'n' feel:
- wcDocker
- Alertify dialogs, and notifications
- AciTree
- Bootstrap Navbar
- Bootstrap Tabs
- Bootstrap Drop-Down menu
- Backgrid
- Select2
Adopated the new the look 'n' feel for the dialogs, wizard, properties,
tab panels, tabs, fieldset, subnode control, spinner control, HTML
table, and other form controls.
- Font is changed to Roboto
- Using SCSS variables to define the look 'n' feel
- Designer background images for the Login, and Forget password pages in
'web' mode
- Improved the look 'n' feel for the key selection in the preferences
dialog
- Table classes consistency changes across the application
- File Open and Save dialog list view changes
Author(s): Aditya Toshniwal & Khushboo Vashi
2018-12-21 17:14:55 +05:30
< / d i v >
< div class = "ml-auto" >
2020-03-24 11:14:05 +05:30
< label class = "my-auto" > ` + gettext('Format') + ` < / l a b e l >
2020-09-15 13:03:18 +05:30
< select aria - label = "select" name = 'type' tabindex = '0' > $ { fileFormats } < / s e l e c t >
Improvement in the look and feel of the whole application
Changed the SCSS/CSS for the below third party libraries to adopt the
new look 'n' feel:
- wcDocker
- Alertify dialogs, and notifications
- AciTree
- Bootstrap Navbar
- Bootstrap Tabs
- Bootstrap Drop-Down menu
- Backgrid
- Select2
Adopated the new the look 'n' feel for the dialogs, wizard, properties,
tab panels, tabs, fieldset, subnode control, spinner control, HTML
table, and other form controls.
- Font is changed to Roboto
- Using SCSS variables to define the look 'n' feel
- Designer background images for the Login, and Forget password pages in
'web' mode
- Improved the look 'n' feel for the key selection in the preferences
dialog
- Table classes consistency changes across the application
- File Open and Save dialog list view changes
Author(s): Aditya Toshniwal & Khushboo Vashi
2018-12-21 17:14:55 +05:30
< div > ` ;
2017-07-18 15:13:16 +01:00
}
2016-05-14 15:29:03 +05:30
2018-01-12 12:59:51 +05:30
$ ( '.allowed_file_types' ) . html ( select _box ) ;
2017-07-18 15:13:16 +01:00
2018-01-12 12:59:51 +05:30
$ ( '.allowed_file_types select' ) . on ( 'change' , function ( ) {
var selected _val = $ ( this ) . val ( ) ,
2020-01-10 12:53:32 +05:30
curr _path = $ ( '.currentpath' ) . val ( ) ,
user _input _file = null ,
input _path = $ ( '.storage_dialog #uploader .input-path' ) . val ( ) ;
2021-04-08 12:23:57 +05:30
config . options . selectedFormat = selected _val ;
$ . ajax ( {
url : url _for ( 'settings.save_file_format_setting' ) ,
type : 'POST' ,
contentType : 'application/json' ,
data : JSON . stringify ( config . options ) ,
} ) ;
2020-01-10 12:53:32 +05:30
if ( curr _path . endsWith ( '/' ) ) {
user _input _file = input _path . substring ( curr _path . lastIndexOf ( '/' ) + 1 ) ;
} else {
user _input _file = input _path . substring ( curr _path . lastIndexOf ( '\\' ) + 1 ) ;
}
getFolderInfo ( curr _path , selected _val , user _input _file ) ;
2018-01-12 12:59:51 +05:30
} ) ;
2017-09-28 10:02:33 +01:00
2018-01-12 12:59:51 +05:30
// If user have preference to show hidden files
if ( config . options . show _hidden _files ) {
setTimeout ( function ( ) {
2018-05-25 16:26:37 +01:00
$ ( '#show_hidden' ) . trigger ( 'click' ) ;
2018-01-12 12:59:51 +05:30
} , 10 ) ;
2017-09-28 10:02:33 +01:00
}
2018-01-12 12:59:51 +05:30
// handle show hidden files functionality
this . handleClick = function ( cb ) {
2020-06-18 16:20:34 +01:00
var tmp _data = {
2018-01-12 12:59:51 +05:30
'is_checked' : false ,
} ;
if ( cb . checked ) {
2019-01-21 16:22:59 +05:30
$ ( 'div.allowed_file_types select' ) . trigger ( 'change' ) ;
2020-06-18 16:20:34 +01:00
tmp _data [ 'is_checked' ] = true ;
2018-01-12 12:59:51 +05:30
} else {
// User wants to hide it again
2019-01-21 16:22:59 +05:30
$ ( 'div.allowed_file_types select' ) . trigger ( 'change' ) ;
2020-06-18 16:20:34 +01:00
tmp _data [ 'is_checked' ] = false ;
2018-01-12 12:59:51 +05:30
}
// Save it in preference
2020-06-18 16:20:34 +01:00
save _show _hidden _file _option ( tmp _data [ 'is_checked' ] , pgAdmin . FileUtils . transId ) ;
2018-01-12 12:59:51 +05:30
return ;
} ;
2017-09-28 10:02:33 +01:00
}
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Item Actions - Object events
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - * /
2016-05-13 00:04:28 +05:30
2019-05-03 11:58:06 +05:30
$ ( '.file_manager' ) . attr ( 'data-platform' , config . options . platform _type ) ;
2018-01-12 12:59:51 +05:30
// Switch to folder view
$ ( '.file_manager .fileinfo' ) . on ( 'click' , function ( ) {
enable _disable _btn ( ) ;
} ) ;
2020-01-31 11:43:30 +05:30
2018-01-12 12:59:51 +05:30
// Refresh current directory
$ ( '.file_manager .refresh' ) . on ( 'click' , function ( ) {
enable _disable _btn ( ) ;
var curr _path = $ ( '.currentpath' ) . val ( ) ,
path ;
2016-05-13 00:04:28 +05:30
2017-07-18 15:13:16 +01:00
$ ( '.file_manager #uploader .input-path' ) . val ( curr _path ) ;
2018-01-12 12:59:51 +05:30
if ( curr _path . endsWith ( '/' ) ) {
path = curr _path . substring ( 0 , curr _path . lastIndexOf ( '/' ) ) + '/' ;
2017-07-18 15:13:16 +01:00
} else {
2018-01-12 12:59:51 +05:30
path = curr _path . substring ( 0 , curr _path . lastIndexOf ( '\\' ) ) + '\\' ;
2017-07-18 15:13:16 +01:00
}
2018-01-12 12:59:51 +05:30
getFolderInfo ( path ) ;
} ) ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
// hide message prompt and dimmer if clicked no
$ ( '.delete_item button.btn_no' ) . on ( 'click' , function ( ) {
$ ( '.delete_item, .fileinfo .fm_dimmer' ) . hide ( ) ;
} ) ;
2016-05-13 00:04:28 +05:30
2020-05-04 12:40:19 +05:30
// Disable button on load
2018-01-12 12:59:51 +05:30
$ ( '.file_manager' ) . find ( 'button.rename' ) . attr ( 'disabled' , 'disabled' ) ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
// stop click event on dimmer click
$ ( '.fileinfo .fm_dimmer' ) . on ( 'click' , function ( e ) {
e . stopPropagation ( ) ;
} ) ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
$ ( '.fileinfo .replace_file' ) . not (
$ ( this ) . find ( 'span.pull-right' )
) . on (
'click' ,
function ( e ) {
2018-05-25 16:26:37 +01:00
$ ( '#uploader .filemanager-btn-group' ) . off ( ) . on (
2018-01-12 12:59:51 +05:30
'click' ,
function ( ) {
$ ( '.fileinfo .delete_item, .fileinfo .replace_file, .fileinfo .fm_dimmer' ) . hide ( ) ;
} ) ;
e . stopPropagation ( ) ;
2017-07-18 15:13:16 +01:00
} ) ;
2016-05-14 00:38:58 +05:30
2018-01-12 12:59:51 +05:30
// Set initial view state.
$ ( '.fileinfo' ) . data ( 'view' , config . options . defaultViewMode ) ;
setViewButtonsFor ( config . options . defaultViewMode ) ;
// Upload click event
$ ( '.file_manager .uploader' ) . on ( 'click' , 'a' , function ( e ) {
e . preventDefault ( ) ;
var b = $ ( '.currentpath' ) . val ( ) ,
node _val = $ ( this ) . next ( ) . text ( ) ,
parent = b . substring ( 0 , b . slice ( 0 , - 1 ) . lastIndexOf ( node _val ) ) ;
getFolderInfo ( parent ) ;
} ) ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
// re-render the home view
2018-06-29 15:14:37 +01:00
$ ( '.file_manager .home' ) . on ( 'click' , function ( ) {
2018-01-12 12:59:51 +05:30
var currentViewMode = $ ( '.fileinfo' ) . data ( 'view' ) ;
$ ( '.fileinfo' ) . data ( 'view' , currentViewMode ) ;
2020-05-04 12:40:19 +05:30
getFolderInfo ( homedir ) ;
2018-01-12 12:59:51 +05:30
enab _dis _level _up ( ) ;
} ) ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
// Go one directory back
2018-06-29 15:14:37 +01:00
$ ( '.file_manager .level-up' ) . on ( 'click' , function ( ) {
2018-01-12 12:59:51 +05:30
var b = $ ( '.currentpath' ) . val ( ) ;
// Enable/Disable level up button
enab _dis _level _up ( ) ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
if ( b . endsWith ( '\\' ) || b . endsWith ( '/' ) ) {
b = b . substring ( 0 , b . length - 1 ) ;
}
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
if ( b != '/' ) {
var parent ;
if ( b . lastIndexOf ( '/' ) > b . lastIndexOf ( '\\' ) ) {
parent = b . substring ( 0 , b . slice ( 0 , - 1 ) . lastIndexOf ( '/' ) ) + '/' ;
2017-07-18 15:13:16 +01:00
} else {
2018-01-12 12:59:51 +05:30
parent = b . substring ( 0 , b . slice ( 0 , - 1 ) . lastIndexOf ( '\\' ) ) + '\\' ;
2017-07-18 15:13:16 +01:00
}
2017-02-03 10:51:36 +01:00
2018-01-12 12:59:51 +05:30
var d = $ ( '.fileinfo' ) . data ( 'view' ) ;
$ ( '.fileinfo' ) . data ( 'view' , d ) ;
2017-07-18 15:13:16 +01:00
getFolderInfo ( parent ) ;
2018-01-12 12:59:51 +05:30
}
} ) ;
2017-02-03 10:51:36 +01:00
2018-01-12 12:59:51 +05:30
// set buttons to switch between grid and list views.
2018-05-25 16:26:37 +01:00
$ ( '.file_manager .grid' ) . on ( 'click' , ( ) => {
2018-01-12 12:59:51 +05:30
setViewButtonsFor ( 'grid' ) ;
$ ( '.fileinfo' ) . data ( 'view' , 'grid' ) ;
enable _disable _btn ( ) ;
getFolderInfo ( $ ( '.currentpath' ) . val ( ) ) ;
save _file _dialog _view ( 'grid' , pgAdmin . FileUtils . transId ) ;
} ) ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
// Show list mode
2018-05-25 16:26:37 +01:00
$ ( '.file_manager .list' ) . on ( 'click' , ( ) => {
2018-01-12 12:59:51 +05:30
setViewButtonsFor ( 'list' ) ;
$ ( '.fileinfo' ) . data ( 'view' , 'list' ) ;
enable _disable _btn ( ) ;
getFolderInfo ( $ ( '.currentpath' ) . val ( ) ) ;
save _file _dialog _view ( 'list' , pgAdmin . FileUtils . transId ) ;
} ) ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
// Provide initial values for upload form, status, etc.
pgAdmin . FileUtils . setUploader ( fileRoot ) ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
var data ;
this . data = data = {
'Capabilities' : capabilities ,
} ;
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
function InputObject ( ) {
this . init = function ( cap ) {
var self = this ,
2017-07-18 15:13:16 +01:00
check _obj = function ( path , check ) {
2018-01-12 12:59:51 +05:30
path = decodeURI ( path ) ;
2017-07-18 15:13:16 +01:00
if ( path . lastIndexOf ( '/' ) == path . length - 1 || path . lastIndexOf ( '\\' ) == path . length - 1 ) {
if (
has _capability ( self . data _cap , 'select_folder' )
) {
$ ( '.file_manager_ok' ) . removeClass ( 'disabled' ) ;
2017-12-05 13:43:02 +09:00
$ ( '.file_manager_ok' ) . attr ( 'disabled' , false ) ;
2020-10-23 16:14:55 +05:30
$ ( '.file_manager button.delete' ) . removeAttr (
2017-07-18 15:13:16 +01:00
'disabled' , 'disabled'
) ;
$ ( '.file_manager button.download' ) . attr (
'disabled' , 'disabled'
) ;
2020-10-23 16:14:55 +05:30
$ ( '.file_manager button.rename' ) . attr ( 'disabled' , 'disabled' ) ;
2017-07-18 15:13:16 +01:00
// set selected folder name in breadcrums
$ ( '.file_manager #uploader .show_selected_file' ) . remove ( ) ;
2018-01-12 12:59:51 +05:30
$ ( '<span class="show_selected_file">' + path + '</span>' ) . appendTo (
2017-07-18 15:13:16 +01:00
'.file_manager #uploader .filemanager-path-group'
) ;
} else {
$ ( '.file_manager_ok' ) . addClass ( 'disabled' ) ;
2017-12-05 13:43:02 +09:00
$ ( '.file_manager_ok' ) . attr ( 'disabled' , true ) ;
2018-01-12 12:59:51 +05:30
if ( check ) {
2017-07-18 15:13:16 +01:00
// Enable/Disable level up button
enab _dis _level _up ( ) ;
$ ( '.file_manager button.delete, .file_manager button.rename' ) . attr ( 'disabled' , 'disabled' ) ;
$ ( '.file_manager button.download' ) . attr ( 'disabled' , 'disabled' ) ;
getFolderInfo ( path ) ;
}
}
} else {
2021-07-06 19:00:08 +05:30
if ( has _capability ( self . data _cap , 'select_folder' ) ) {
disableSelect ( ) ;
}
2017-07-18 15:13:16 +01:00
if (
has _capability ( self . data _cap , 'select_file' )
) {
$ ( '.file_manager_ok' ) . removeClass ( 'disabled' ) ;
2017-12-05 13:43:02 +09:00
$ ( '.file_manager_ok' ) . attr ( 'disabled' , false ) ;
2017-07-18 15:13:16 +01:00
$ ( '.file_manager button.delete, .file_manager button.download, .file_manager button.rename' ) . removeAttr (
'disabled'
) ;
2019-03-14 15:48:21 +00:00
// set selected folder name in breadcrumbs
2017-07-18 15:13:16 +01:00
$ ( '.file_manager #uploader .show_selected_file' ) . remove ( ) ;
}
2016-05-13 00:04:28 +05:30
2018-01-12 12:59:51 +05:30
if ( check ) {
2017-07-18 15:13:16 +01:00
if ( config . options . dialog _type == 'create_file' ) {
2018-01-12 12:59:51 +05:30
var status = checkPermission ( path ) ;
2017-07-18 15:13:16 +01:00
if ( status ) {
2021-01-11 17:40:13 +05:30
//$('.file_manager').trigger('enter-key');
$ ( '.file_manager_ok' ) . trigger ( 'click' ) ;
2017-07-18 15:13:16 +01:00
}
2018-01-12 12:59:51 +05:30
} else if ( config . options . dialog _type == 'select_file' ) {
2017-07-18 15:13:16 +01:00
var file _status = getFileInfo ( path ) ;
if ( file _status ) {
2021-01-11 17:40:13 +05:30
$ ( '.file_manager_ok' ) . trigger ( 'click' ) ;
//$('.file_manager').trigger('enter-key');
2017-07-18 15:13:16 +01:00
}
}
}
}
} ;
2017-02-03 10:51:36 +01:00
2018-01-12 12:59:51 +05:30
self . data _cap = cap ;
2017-02-03 10:51:36 +01:00
2018-07-10 10:59:53 +01:00
$ ( '.storage_dialog #uploader .input-path' ) . on ( 'keyup' , function ( e ) {
2018-01-12 12:59:51 +05:30
if ( e . keyCode == 13 ) {
e . stopPropagation ( ) ;
var path = $ ( this ) . val ( ) ;
if ( path == '' ) {
path = '/' ;
}
2017-02-03 10:51:36 +01:00
2019-05-03 11:58:06 +05:30
if ( config . options . platform _type === 'win32' ) {
2018-01-12 12:59:51 +05:30
path = path . replace ( /\//g , '\\' ) ;
} else {
path = path . replace ( /\\/g , '/' ) ;
2019-10-10 12:05:28 +05:30
if ( ! path . startsWith ( '/' ) ) {
2018-01-12 12:59:51 +05:30
path = '/' + path ;
}
2017-02-03 10:51:36 +01:00
}
2018-01-12 12:59:51 +05:30
$ ( this ) . val ( path ) ;
setTimeout ( function ( ) {
check _obj ( path , true ) ;
} ) ;
2017-02-03 10:51:36 +01:00
2018-01-12 12:59:51 +05:30
return ;
}
check _obj ( $ ( this ) . val ( ) , false ) ;
} ) ;
} ;
this . set _cap = function ( cap ) {
this . data _cap = cap ;
} ;
2017-07-18 15:13:16 +01:00
}
2018-01-12 12:59:51 +05:30
var input _object = new InputObject ( ) ;
input _object . init ( data ) ;
// Upload file
if ( has _capability ( data , 'upload' ) ) {
Dropzone . autoDiscover = false ;
// we remove simple file upload element
$ ( '.file-input-container' ) . remove ( ) ;
$ ( '.upload' ) . remove ( ) ;
2020-09-15 13:03:18 +05:30
$ ( '.create' ) . before ( '<button aria-label="Upload" value="Upload" type="button" title="Upload File" name="upload" id="upload" class="btn btn-sm btn-primary-icon upload" tabindex="0"><span class="fa fa-upload sql-icon-lg"></span></button> ' ) ;
2018-01-12 12:59:51 +05:30
2018-06-29 15:14:37 +01:00
$ ( '#uploader .upload' ) . off ( ) . on ( 'click' , function ( ) {
2018-01-12 12:59:51 +05:30
// we create prompt
Improvement in the look and feel of the whole application
Changed the SCSS/CSS for the below third party libraries to adopt the
new look 'n' feel:
- wcDocker
- Alertify dialogs, and notifications
- AciTree
- Bootstrap Navbar
- Bootstrap Tabs
- Bootstrap Drop-Down menu
- Backgrid
- Select2
Adopated the new the look 'n' feel for the dialogs, wizard, properties,
tab panels, tabs, fieldset, subnode control, spinner control, HTML
table, and other form controls.
- Font is changed to Roboto
- Using SCSS variables to define the look 'n' feel
- Designer background images for the Login, and Forget password pages in
'web' mode
- Improved the look 'n' feel for the key selection in the preferences
dialog
- Table classes consistency changes across the application
- File Open and Save dialog list view changes
Author(s): Aditya Toshniwal & Khushboo Vashi
2018-12-21 17:14:55 +05:30
var msg = '<div id="dropzone-container" class="d-flex flex-column flex-grow-1">' +
2020-01-31 11:43:30 +05:30
'<button class="fa fa-times fa-lg dz_cross_btn ml-auto" tabindex="0"></button>' +
Improvement in the look and feel of the whole application
Changed the SCSS/CSS for the below third party libraries to adopt the
new look 'n' feel:
- wcDocker
- Alertify dialogs, and notifications
- AciTree
- Bootstrap Navbar
- Bootstrap Tabs
- Bootstrap Drop-Down menu
- Backgrid
- Select2
Adopated the new the look 'n' feel for the dialogs, wizard, properties,
tab panels, tabs, fieldset, subnode control, spinner control, HTML
table, and other form controls.
- Font is changed to Roboto
- Using SCSS variables to define the look 'n' feel
- Designer background images for the Login, and Forget password pages in
'web' mode
- Improved the look 'n' feel for the key selection in the preferences
dialog
- Table classes consistency changes across the application
- File Open and Save dialog list view changes
Author(s): Aditya Toshniwal & Khushboo Vashi
2018-12-21 17:14:55 +05:30
'<div id="multiple-uploads" class="dropzone flex-grow-1 d-flex p-1">' +
'<div class="dz-default dz-message d-none"></div>' +
'</div>' +
2020-04-20 11:19:09 +05:30
'<div class="prompt-info">' + gettext ( 'Drop files here to upload.' ) + ' ' + lg . file _size _limit +
2018-01-12 12:59:51 +05:30
config . upload . fileSizeLimit + ' ' + lg . mb + '.</div>' ,
path = $ ( '.currentpath' ) . val ( ) ,
filesizelimit = config . upload . fileSizeLimit ,
// default dropzone value
fileSize = ( filesizelimit != 'auto' ) ? filesizelimit : 256 ,
acceptFiles ;
if ( config . security . uploadPolicy == 'DISALLOW_ALL' ) {
acceptFiles = '.' + config . security . uploadRestrictions . join ( ',.' ) ;
} else {
// We allow any extension since we have no easy way to handle the the
// built-in `acceptedFiles` params would be handled later by the
// connector.
acceptFiles = null ;
}
2016-05-13 00:04:28 +05:30
Improvement in the look and feel of the whole application
Changed the SCSS/CSS for the below third party libraries to adopt the
new look 'n' feel:
- wcDocker
- Alertify dialogs, and notifications
- AciTree
- Bootstrap Navbar
- Bootstrap Tabs
- Bootstrap Drop-Down menu
- Backgrid
- Select2
Adopated the new the look 'n' feel for the dialogs, wizard, properties,
tab panels, tabs, fieldset, subnode control, spinner control, HTML
table, and other form controls.
- Font is changed to Roboto
- Using SCSS variables to define the look 'n' feel
- Designer background images for the Login, and Forget password pages in
'web' mode
- Improved the look 'n' feel for the key selection in the preferences
dialog
- Table classes consistency changes across the application
- File Open and Save dialog list view changes
Author(s): Aditya Toshniwal & Khushboo Vashi
2018-12-21 17:14:55 +05:30
$ ( '.file_manager .upload_file' ) . toggleClass ( 'd-none' ) ;
$ ( '.file_manager .file_listing' ) . toggleClass ( 'd-none' ) ;
2018-01-12 12:59:51 +05:30
$ ( '.file_manager .upload_file' ) . html ( msg ) ;
var previewTemplate = '<div class="file_upload_main dz-preview dz-file-preview">' +
'<div class="show_error">' +
'<p class="size dz-size" data-dz-size></p>' +
'<p class="name dz-filename" data-dz-name></p>' +
'</div>' +
'<div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>' +
'<div class="dz-success-mark"><span></span></div>' +
'<div class="dz-error-mark"><span></span></div>' +
'<div class="dz-error-message"><span data-dz-errormessage></span></div>' +
'<a href="javascript:void(0);" class="fa fa-trash dz_file_remove" data-dz-remove></a>' +
'</div>' ;
2019-06-12 13:52:18 +01:00
// We need to append our csrf token with dropzone's ajax request header
let csrfToken = { } ;
csrfToken [ pgAdmin . csrf _token _header ] = pgAdmin . csrf _token ;
2018-01-12 12:59:51 +05:30
$ ( 'div#multiple-uploads' ) . dropzone ( {
paramName : 'newfile' ,
url : pgAdmin . FileUtils . fileConnector ,
2019-06-12 13:52:18 +01:00
headers : csrfToken ,
2018-01-12 12:59:51 +05:30
maxFilesize : fileSize ,
maxFiles : config . upload . number ,
addRemoveLinks : true ,
previewTemplate : previewTemplate ,
parallelUploads : config . upload . number ,
dictMaxFilesExceeded : lg . dz _dictMaxFilesExceeded . replace (
'%s' , config . upload . number
) ,
dictDefaultMessage : lg . dz _dictDefaultMessage ,
dictInvalidFileType : lg . dz _dictInvalidFileType ,
dictFileTooBig : lg . file _too _big + ' ' + lg . file _size _limit +
config . upload . fileSizeLimit + ' ' + lg . mb ,
acceptedFiles : acceptFiles ,
autoProcessQueue : true ,
init : function ( ) {
2018-05-25 16:26:37 +01:00
$ ( '.dz_cross_btn' ) . off ( ) . on ( 'click' , function ( ) {
Improvement in the look and feel of the whole application
Changed the SCSS/CSS for the below third party libraries to adopt the
new look 'n' feel:
- wcDocker
- Alertify dialogs, and notifications
- AciTree
- Bootstrap Navbar
- Bootstrap Tabs
- Bootstrap Drop-Down menu
- Backgrid
- Select2
Adopated the new the look 'n' feel for the dialogs, wizard, properties,
tab panels, tabs, fieldset, subnode control, spinner control, HTML
table, and other form controls.
- Font is changed to Roboto
- Using SCSS variables to define the look 'n' feel
- Designer background images for the Login, and Forget password pages in
'web' mode
- Improved the look 'n' feel for the key selection in the preferences
dialog
- Table classes consistency changes across the application
- File Open and Save dialog list view changes
Author(s): Aditya Toshniwal & Khushboo Vashi
2018-12-21 17:14:55 +05:30
$ ( '.file_manager .upload_file' ) . toggleClass ( 'd-none' ) ;
$ ( '.file_manager .file_listing' ) . toggleClass ( 'd-none' ) ;
2018-01-12 12:59:51 +05:30
} ) ;
} ,
sending : function ( file , xhr , formData ) {
formData . append ( 'mode' , 'add' ) ;
formData . append ( 'currentpath' , path ) ;
$ ( '.upload_file .dz_cross_btn' ) . attr ( 'disabled' , 'disabled' ) ;
setTimeout ( function ( ) { } , 10000 ) ;
} ,
success : function ( file , response ) {
2020-06-18 16:20:34 +01:00
var resp _data = response . data . result ,
2018-01-12 12:59:51 +05:30
$this = $ ( file . previewTemplate ) ;
2020-06-18 16:20:34 +01:00
if ( resp _data . Code == 1 ) {
2018-01-12 12:59:51 +05:30
setTimeout ( function ( ) {
$this . find ( '.dz-upload' ) . addClass ( 'success' ) ;
} , 1000 ) ;
$this . find ( '.dz-upload' ) . css ( 'width' , '100%' ) . html ( '100%' ) ;
Alertify . success ( lg . upload _success ) ;
} else {
$this . find ( '.dz-upload' ) . addClass ( 'error' ) ;
$this . find ( '.dz-upload' ) . css ( 'width' , '0%' ) . html ( '0%' ) ;
2020-06-18 16:20:34 +01:00
Alertify . error ( resp _data . Error ) ;
2018-01-12 12:59:51 +05:30
}
getFolderInfo ( path ) ;
} ,
totaluploadprogress : function ( ) { } ,
complete : function ( file ) {
if ( file . status == 'error' ) {
Alertify . error ( lg . upload _error ) ;
}
$ ( '.upload_file .dz_cross_btn' ) . removeAttr ( 'disabled' ) ;
getFolderInfo ( path ) ;
} ,
} ) ;
2016-05-21 15:01:47 +05:30
} ) ;
2018-01-12 12:59:51 +05:30
}
2016-05-21 15:01:47 +05:30
2018-01-12 12:59:51 +05:30
this . getDetailView ( fileRoot ) ;
} ,
/ *
* Sets the folder status , upload , and new folder functions
* to the path specified . Called on initial page load and
* whenever a new directory is selected .
* /
setUploader : function ( path ) {
var config = this . config ;
var lg = this . lg ;
$ ( '.storage_dialog #uploader' ) . find ( 'a' ) . remove ( ) ;
$ ( '.storage_dialog #uploader' ) . find ( 'b' ) . remove ( ) ;
2019-05-03 11:58:06 +05:30
if ( config . options . platform _type === 'win32' ) {
2018-01-12 12:59:51 +05:30
path = path . replace ( /\//g , '\\' ) ;
} else {
path = path . replace ( /\\/g , '/' ) ;
}
path = decodeURI ( path ) ;
2019-05-03 11:58:06 +05:30
if ( config . options . platform _type === 'win32' ) {
2018-01-12 12:59:51 +05:30
if ( config . options . show _volumes && path == '\\' ) {
$ ( '.storage_dialog #uploader .input-path' ) . val ( '' ) ;
2016-05-21 15:01:47 +05:30
} else {
2018-01-12 12:59:51 +05:30
$ ( '.storage_dialog #uploader .input-path' ) . val ( path ) ;
2016-05-21 15:01:47 +05:30
}
2020-06-18 16:20:34 +01:00
} else if ( ( config . options . platform _type !== 'win32' ) &&
2019-10-10 12:05:28 +05:30
( path == '' || ! path . startsWith ( '/' ) ) ) {
2018-01-12 12:59:51 +05:30
path = '/' + path ;
$ ( '.storage_dialog #uploader .input-path' ) . val ( path ) ;
} else {
$ ( '.storage_dialog #uploader .input-path' ) . val ( path ) ;
2016-05-21 15:01:47 +05:30
}
2017-07-18 15:13:16 +01:00
2018-01-12 12:59:51 +05:30
if ( path . lastIndexOf ( '\\' ) == - 1 && path . lastIndexOf ( '/' ) == - 1 ) {
$ ( '.currentpath' ) . val ( path ) ;
} else if ( path . lastIndexOf ( '/' ) > path . lastIndexOf ( '\\' ) ) {
$ ( '.currentpath' ) . val ( path . substr ( 0 , path . lastIndexOf ( '/' ) + 1 ) ) ;
2017-07-18 15:13:16 +01:00
} else {
2018-01-12 12:59:51 +05:30
$ ( '.currentpath' ) . val ( path . substr ( 0 , path . lastIndexOf ( '\\' ) + 1 ) ) ;
2017-07-18 15:13:16 +01:00
}
2018-01-12 12:59:51 +05:30
enab _dis _level _up ( ) ;
if ( $ ( '.storage_dialog #uploader h1 span' ) . length === 0 ) {
$ ( '<span>' + lg . current _folder + '</span>' ) . appendTo ( $ ( '.storage_dialog #uploader h1' ) ) ;
}
2017-07-18 15:13:16 +01:00
2018-01-12 12:59:51 +05:30
$ ( '.storage_dialog #uploader .input-path' ) . attr ( 'title' , path ) ;
$ ( '.storage_dialog #uploader .input-path' ) . attr ( 'data-path' , path ) ;
2021-07-06 19:00:08 +05:30
enableSelect ( ) ;
2017-07-18 15:13:16 +01:00
2018-01-12 12:59:51 +05:30
// create new folder
2018-06-29 15:14:37 +01:00
$ ( '.create' ) . off ( ) . on ( 'click' , function ( ) {
2018-01-12 12:59:51 +05:30
var foldername = lg . new _folder ;
var $file _element ,
2017-07-18 15:13:16 +01:00
$file _element _list ,
folder _div ;
2018-01-12 12:59:51 +05:30
$ ( '.file_manager button.create' ) . attr ( 'disabled' , 'disabled' ) ;
2019-01-16 11:55:08 +05:30
$ ( '.no_folder_found' ) . addClass ( 'd-none' ) ;
2018-01-12 12:59:51 +05:30
if ( $ ( '.fileinfo' ) . data ( 'view' ) == 'grid' ) {
2017-07-18 15:13:16 +01:00
2018-01-12 12:59:51 +05:30
// template for creating new folder
folder _div =
2020-01-31 11:43:30 +05:30
'<li tabIndex="0" class=\'cap_download cap_delete cap_select_file cap_select_folder cap_rename cap_create cap_upload\'>' +
2019-12-17 13:22:36 +05:30
'<div class=\'clip\'><span data-alt=\'\' class=\'fa fa-folder-open fm_folder_grid\' role="img"></span></div>' +
2019-01-07 16:03:54 +05:30
'<div><input type=\'text\' class=\'fm_file_rename\'><span class="less_text" title=\'\'>New_Folder</span></div>' +
2018-01-12 12:59:51 +05:30
'<span class=\'meta size\'></span><span class=\'meta created\'></span><span class=\'meta modified\'></span></li>' ;
2017-07-18 15:13:16 +01:00
path = $ ( '.currentpath' ) . val ( ) ;
2018-01-12 12:59:51 +05:30
$file _element = $ ( folder _div ) ;
2019-01-07 16:03:54 +05:30
$ ( '.fileinfo #contents.grid' ) . prepend ( $file _element ) ;
$file _element . find ( 'div span.less_text' ) . toggle ( ) ;
$file _element . find ( 'div input' ) . toggle ( ) . val ( lg . new _folder ) . select ( ) ;
2017-07-18 15:13:16 +01:00
2018-01-12 12:59:51 +05:30
// rename folder/file on pressing enter key
2018-07-10 10:59:53 +01:00
$ ( '.file_manager' ) . on ( 'keyup' , function ( e ) {
2018-01-12 12:59:51 +05:30
if ( e . keyCode == 13 ) {
e . stopPropagation ( ) ;
2019-01-07 16:03:54 +05:30
$file _element . find ( 'div input' ) . trigger ( 'blur' ) ;
2018-01-12 12:59:51 +05:30
}
} ) ;
2017-07-18 15:13:16 +01:00
2018-01-12 12:59:51 +05:30
// rename folder/file on blur
2019-01-07 16:03:54 +05:30
$file _element . find ( 'div input' ) . on ( 'blur' , function ( ) {
2018-01-12 12:59:51 +05:30
$ ( '.file_manager button.create' ) . removeAttr ( 'disabled' ) ;
2019-01-07 16:03:54 +05:30
var text _value = $file _element . find ( 'div input' ) . val ( ) ;
2017-07-18 15:13:16 +01:00
2018-01-12 12:59:51 +05:30
path = $ ( '.currentpath' ) . val ( ) ;
2017-07-18 15:13:16 +01:00
2019-01-07 16:03:54 +05:30
$file _element . find ( 'div input' ) . toggle ( ) ;
$file _element . find ( 'div span.less_text' ) . toggle ( ) . html ( text _value ) ;
2018-01-12 12:59:51 +05:30
if ( text _value === undefined ) {
text _value = lg . new _folder ;
}
getFolderName ( text _value ) ;
getFolderInfo ( path ) ;
} ) ;
2017-07-18 15:13:16 +01:00
2018-01-12 12:59:51 +05:30
} else if ( $ ( '.fileinfo' ) . data ( 'view' ) == 'list' ) {
// template to create new folder in table view
folder _div = $ (
2020-01-10 12:53:32 +05:30
` <tr class= \' cap_download cap_delete cap_select_file cap_select_folder cap_rename cap_create cap_upload \' >
< td title = \ '\' class=\' tbl_folder\' >
< div >
< input type = "text" class = "fm_file_rename" / >
< div class = "fm_file_name" >
< div class = "d-flex" >
< span class = "fa fa-folder-open fm_folder_list" role = "img" > < / s p a n >
< span class = "less_text ml-2" > $ { lg . new _folder } < / s p a n >
< / d i v >
< div >
< / d i v >
< / t d >
< td > < span title = \ '\' > < / s p a n > < / t d >
< td > < / t d >
< / t r > `
2018-01-12 12:59:51 +05:30
) ;
$file _element _list = $ ( folder _div ) ;
2019-01-16 11:55:08 +05:30
let tableEl = $ ( '.fileinfo #contents.file_listing_table' ) ;
tableEl . removeClass ( 'file_listing_table_no_data' ) ;
tableEl . find ( 'tbody' ) . prepend ( $file _element _list ) ;
2020-01-10 12:53:32 +05:30
$file _element _list . find ( 'td .fm_file_name' ) . toggle ( ) ;
2019-01-07 16:03:54 +05:30
$file _element _list . find ( 'td input' ) . toggle ( ) . val ( lg . new _folder ) . select ( ) ;
2018-01-12 12:59:51 +05:30
// rename folder/file on pressing enter key
2018-07-10 10:59:53 +01:00
$ ( '.file_manager' ) . on ( 'keyup' , function ( e ) {
2018-01-12 12:59:51 +05:30
if ( e . keyCode == 13 ) {
e . stopPropagation ( ) ;
2019-01-07 16:03:54 +05:30
$file _element _list . find ( 'td input' ) . trigger ( 'blur' ) ;
2018-01-12 12:59:51 +05:30
}
} ) ;
2017-07-18 15:13:16 +01:00
2018-01-12 12:59:51 +05:30
// rename folder/file on blur
2019-01-07 16:03:54 +05:30
$file _element _list . find ( 'td input' ) . on ( 'blur' , function ( ) {
2018-01-12 12:59:51 +05:30
$ ( '.file_manager button.create' ) . removeAttr ( 'disabled' ) ;
2019-01-07 16:03:54 +05:30
var text _value = $file _element _list . find ( 'td input' ) . val ( ) ;
2018-01-12 12:59:51 +05:30
path = $ ( '.currentpath' ) . val ( ) ;
2019-01-07 16:03:54 +05:30
$file _element _list . find ( 'td input' ) . toggle ( ) ;
2020-01-10 12:53:32 +05:30
$file _element _list . find ( 'td .fm_file_name span.less_text' ) . html ( text _value ) ;
$file _element _list . find ( 'td .fm_file_name' ) . toggle ( ) ;
2018-01-12 12:59:51 +05:30
if ( text _value === undefined ) {
text _value = lg . new _folder ;
2017-07-18 15:13:16 +01:00
}
2018-01-12 12:59:51 +05:30
getFolderName ( text _value ) ;
getFolderInfo ( path ) ;
2017-07-18 15:13:16 +01:00
} ) ;
}
2018-01-12 12:59:51 +05:30
// create a new folder
var getFolderName = function ( value ) {
var fname = value ;
if ( fname != '' ) {
foldername = fname ;
// Add _ variable in URL for avoiding the caching
$ . getJSON (
2018-03-19 10:58:12 +00:00
pgAdmin . FileUtils . fileConnector + '?_=' + Date . now ( ) + '&mode=addfolder&path=' + $ ( '.currentpath' ) . val ( ) + '&name=' + foldername ,
2018-01-12 12:59:51 +05:30
function ( resp ) {
var result = resp . data . result ;
if ( result . Code === 1 ) {
Alertify . success ( lg . successful _added _folder ) ;
getFolderInfo ( result . Parent ) ;
} else {
Alertify . error ( result . Error ) ;
}
}
) ;
} else {
Alertify . error ( lg . no _foldername ) ;
}
} ;
} ) ;
} ,
/ * D e c i d e s w h e t h e r t o r e t r i e v e f i l e o r f o l d e r i n f o b a s e d o n
* the path provided .
* /
getDetailView : function ( path ) {
if ( path . lastIndexOf ( '/' ) == path . length - 1 || path . lastIndexOf ( '\\' ) == path . length - 1 ) {
var allowed _types = this . config . options . allowed _file _types ;
2021-04-08 12:23:57 +05:30
let set _type ;
let response = getFileFormat ( this . config . options . allowed _file _types ) ;
let lastSelectedFormat = response . responseJSON . info ;
if ( _ . isUndefined ( lastSelectedFormat ) )
set _type = allowed _types [ 0 ] ;
else
set _type = lastSelectedFormat ;
2018-01-12 12:59:51 +05:30
getFolderInfo ( path , set _type ) ;
2017-07-18 15:13:16 +01:00
}
2018-01-12 12:59:51 +05:30
} ,
// helpful in show/hide toolbar button for Windows
hideButtons : function ( ) {
2017-07-18 15:13:16 +01:00
return (
2019-05-03 11:58:06 +05:30
this . config . options . platform _type === 'win32' &&
2017-07-18 15:13:16 +01:00
$ ( '.currentpath' ) . val ( ) === ''
) ;
2018-01-12 12:59:51 +05:30
} ,
2017-07-18 15:13:16 +01:00
2018-01-12 12:59:51 +05:30
} ;
return pgAdmin . FileUtils ;
2017-07-18 15:13:16 +01:00
} ) ;
2016-05-21 15:01:47 +05:30
//@ sourceURL=utility.js