2018-07-13 18:39:55 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) Codiad & Kent Safranski (codiad.com), distributed
|
|
|
|
* as-is and without warranty under the MIT License. See
|
|
|
|
* [root]/license.txt for more. This information must remain intact.
|
|
|
|
*/
|
2019-05-01 22:21:45 +02:00
|
|
|
( function( global, $ ) {
|
2018-07-18 23:00:52 +02:00
|
|
|
|
2019-10-29 14:37:19 +01:00
|
|
|
let codiad = global.codiad;
|
2019-05-01 22:21:45 +02:00
|
|
|
|
|
|
|
$( window ).load( function() {
|
2018-07-18 23:00:52 +02:00
|
|
|
|
2019-05-01 22:21:45 +02:00
|
|
|
codiad.filemanager.init();
|
|
|
|
});
|
2018-07-18 23:00:52 +02:00
|
|
|
|
2019-05-01 22:21:45 +02:00
|
|
|
codiad.filemanager = {
|
2019-02-07 19:55:17 +01:00
|
|
|
|
|
|
|
auto_reload: false,
|
2019-05-01 22:21:45 +02:00
|
|
|
clipboard: '',
|
|
|
|
controller: 'components/filemanager/controller.php',
|
|
|
|
dialog: 'components/filemanager/dialog.php',
|
2020-01-07 03:35:50 +01:00
|
|
|
filelist: {
|
2019-05-01 22:21:45 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
audio: [
|
2018-07-18 23:00:52 +02:00
|
|
|
'aac',
|
|
|
|
'aif',
|
|
|
|
'mp3',
|
|
|
|
'mp4',
|
|
|
|
'wav',
|
|
|
|
'ogg',
|
2020-01-07 03:35:50 +01:00
|
|
|
],
|
|
|
|
files: [
|
2018-07-18 23:00:52 +02:00
|
|
|
'exe',
|
|
|
|
'pdf',
|
|
|
|
'zip',
|
|
|
|
'tar',
|
|
|
|
'tar.gz',
|
2020-01-07 03:35:50 +01:00
|
|
|
],
|
|
|
|
image: [
|
2018-07-18 23:00:52 +02:00
|
|
|
'ico',
|
|
|
|
'icon',
|
|
|
|
'jpg',
|
|
|
|
'jpeg',
|
|
|
|
'png',
|
|
|
|
'gif',
|
|
|
|
'bmp',
|
2020-01-07 03:35:50 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
files: [],
|
|
|
|
opened_folders: [],
|
|
|
|
post_max_size: ( 1024*1024 ),
|
|
|
|
preview: null,
|
|
|
|
refresh_interval: null,
|
|
|
|
selected: [],
|
|
|
|
|
|
|
|
init: async function() {
|
2019-10-16 16:20:09 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let _this = this;
|
2019-05-01 22:21:45 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
/* Reload the page when saving auto reload preview */
|
2019-05-01 22:21:45 +02:00
|
|
|
amplify.subscribe( 'settings.save', async function() {
|
|
|
|
|
|
|
|
let option = ( await codiad.settings.get_option( "codiad.filemanager.autoReloadPreview" ) == "true" );
|
|
|
|
if( option != codiad.filemanager.auto_reload ) {
|
|
|
|
|
|
|
|
window.location.reload( true );
|
|
|
|
}
|
2019-02-07 19:55:17 +01:00
|
|
|
});
|
2019-05-01 22:21:45 +02:00
|
|
|
|
|
|
|
/* Subscribe to know when a file become active. */
|
2019-02-07 19:55:17 +01:00
|
|
|
amplify.subscribe( 'active.onFocus', async function( path ) {
|
|
|
|
|
|
|
|
let editor = codiad.editor.getActive();
|
2019-05-01 22:21:45 +02:00
|
|
|
|
2019-02-07 19:55:17 +01:00
|
|
|
if( _this.auto_reload && editor !== null ) {
|
2019-05-01 22:21:45 +02:00
|
|
|
|
|
|
|
codiad.editor.getActive().addEventListener( "change", _this.refreshPreview );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
/*
|
|
|
|
maybe we should have this calcualted as the file is being uploaded.
|
|
|
|
this may allow for a more dynamic upload speed for faster
|
|
|
|
connections and a more stable upload for slower connections.
|
|
|
|
*/
|
|
|
|
_this.calculate_upload_variables();
|
2019-05-01 22:21:45 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
_this.node_listeners();
|
2019-05-01 22:21:45 +02:00
|
|
|
},
|
2019-01-22 20:21:20 +01:00
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
archive: function( path ) {
|
|
|
|
|
2019-09-23 04:40:02 +02:00
|
|
|
let _this = this;
|
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
$.get( _this.controller + '?action=archive&path=' + encodeURIComponent( path ), function( data ) {
|
|
|
|
|
|
|
|
console.log( data );
|
2019-09-23 04:40:02 +02:00
|
|
|
let response = codiad.jsend.parse( data );
|
|
|
|
parent = path.split( '/' );
|
|
|
|
parent.pop();
|
|
|
|
_this.rescan( parent.join( '/' ) );
|
|
|
|
console.log( response );
|
2019-09-23 03:35:26 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
calculate_upload_variables: async function() {
|
2019-10-25 04:27:51 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let _this = codiad.filemanager;
|
|
|
|
let result = await codiad.system.get_ini_setting( 'post_max_size' );
|
|
|
|
result = result.toLowerCase()
|
2019-10-25 04:27:51 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
console.log( result, result.includes( 'g' ), result.includes( 'm' ), result.includes( 'k' ) );
|
|
|
|
|
|
|
|
if( result.includes( 'g' ) ) {
|
2019-10-25 04:27:51 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let integer = result.replace( /^\D+/g, '' );
|
|
|
|
|
|
|
|
console.log( integer, 1024*1024*1024*integer );
|
|
|
|
result = 1024*1024*1024*integer;
|
|
|
|
} else if( result.includes( 'm' ) ) {
|
|
|
|
|
|
|
|
let integer = result.replace( /^\D+/g, '' );
|
|
|
|
console.log( integer, 1024*1024*integer );
|
|
|
|
result = 1024*1024*integer;
|
|
|
|
} else if( result.includes( 'k' ) ) {
|
|
|
|
|
|
|
|
let integer = result.replace( /^\D+/g, '' );
|
|
|
|
console.log( integer, 1024*integer );
|
|
|
|
result = 1024*integer;
|
|
|
|
}
|
|
|
|
|
|
|
|
_this.post_max_size = result;
|
|
|
|
console.log( _this.post_max_size );
|
2019-10-25 04:27:51 +02:00
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
context_menu_track_mouse: function() {
|
2019-05-01 22:21:45 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let _this = codiad.filemanager;
|
2019-05-01 22:21:45 +02:00
|
|
|
let offset = $( '#context-menu' ).offset();
|
|
|
|
let bottom = offset.top + $( '#context-menu' ).outerHeight( true ) + 20;
|
|
|
|
let left = offset.left - 20;
|
|
|
|
let right = offset.left + $( '#context-menu' ).outerWidth( true ) + 20;
|
|
|
|
let top = offset.top - 20;
|
|
|
|
|
|
|
|
if( ( e.clientX > right || e.clientX < left ) || ( e.clientY > bottom || e.clientY < top ) ) {
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
$( '#file-manager, #editor-region' ).off( 'mousemove', codiad.filemanager.context_menu_track_mouse );
|
2019-05-01 22:21:45 +02:00
|
|
|
$( '#context-menu, #editor-region' ).off( 'paste', codiad.editor.paste );
|
2020-01-07 03:35:50 +01:00
|
|
|
_this.hide_context_menu();
|
2019-05-01 22:21:45 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2019-09-23 03:35:26 +02:00
|
|
|
// Copy to Clipboard
|
2019-05-01 22:21:45 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
copy_node: function( path ) {
|
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
this.clipboard = path;
|
|
|
|
codiad.message.success( i18n( 'Copied to Clipboard' ) );
|
2019-05-01 22:21:45 +02:00
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
create_node: function( path, type ) {
|
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
codiad.modal.load( 250, this.dialog, {
|
|
|
|
action: 'create',
|
|
|
|
type: type,
|
|
|
|
path: path
|
|
|
|
});
|
|
|
|
$( '#modal-content form' )
|
2020-01-07 03:35:50 +01:00
|
|
|
.on( 'submit', function( e ) {
|
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
e.preventDefault();
|
2020-01-07 03:35:50 +01:00
|
|
|
let shortName = $( '#modal-content form input[name="object_name"]' ).val();
|
|
|
|
let path = $( '#modal-content form input[name="path"]' ).val();
|
|
|
|
let type = $( '#modal-content form input[name="type"]' ).val();
|
2019-10-29 14:37:19 +01:00
|
|
|
let createPath = path + '/' + shortName;
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
$.get( codiad.filemanager.controller + '?action=create&path=' + encodeURIComponent( createPath ) + '&type=' + type, function( data ) {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2019-10-29 14:37:19 +01:00
|
|
|
let createResponse = codiad.jsend.parse( data );
|
2019-09-23 03:35:26 +02:00
|
|
|
if( createResponse != 'error' ) {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
codiad.message.success( type.charAt( 0 )
|
|
|
|
.toUpperCase() + type.slice( 1 ) + ' Created' );
|
|
|
|
codiad.modal.unload();
|
2020-01-07 03:35:50 +01:00
|
|
|
|
|
|
|
codiad.filemanager.rescan( path );
|
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
if( type == 'file' ) {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
codiad.filemanager.openFile( createPath, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Notify listeners. */
|
|
|
|
amplify.publish( 'filemanager.onCreate', {
|
|
|
|
createPath: createPath,
|
|
|
|
path: path,
|
|
|
|
shortName: shortName,
|
|
|
|
type: type
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2019-05-01 22:21:45 +02:00
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
delete_node: function( path ) {
|
|
|
|
|
2019-05-01 22:21:45 +02:00
|
|
|
let _this = this;
|
2019-09-23 03:35:26 +02:00
|
|
|
codiad.modal.load( 400, this.dialog, {
|
|
|
|
action: 'delete',
|
|
|
|
path: path
|
|
|
|
});
|
|
|
|
$( '#modal-content form' )
|
|
|
|
.live( 'submit', function( e ) {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
e.preventDefault();
|
|
|
|
$.get( _this.controller + '?action=delete&path=' + encodeURIComponent( path ), function( data ) {
|
2019-06-21 15:27:25 +02:00
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let response = codiad.jsend.parse( data );
|
|
|
|
if( response != 'error' ) {
|
|
|
|
|
2019-10-29 14:37:19 +01:00
|
|
|
let node = $( '#file-manager a[data-path="' + path + '"]' );
|
2020-01-07 03:35:50 +01:00
|
|
|
let parent_path = node.parent().parent().children( 'a' ).attr( 'data-path' );
|
2019-09-23 03:35:26 +02:00
|
|
|
node.parent( 'li' ).remove();
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
// Close any active files
|
2020-01-07 03:35:50 +01:00
|
|
|
$( '#active-files a' ).each( function() {
|
|
|
|
|
|
|
|
let curPath = $( this ).attr( 'data-path' );
|
|
|
|
|
|
|
|
console.log( curPath, curPath.indexOf( path ) );
|
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
if( curPath.indexOf( path ) == 0 ) {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
codiad.active.remove( curPath );
|
2019-05-01 22:21:45 +02:00
|
|
|
}
|
2019-09-23 03:35:26 +02:00
|
|
|
});
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
/* Notify listeners. */
|
|
|
|
amplify.publish( 'filemanager.onDelete', {
|
|
|
|
deletePath: path,
|
|
|
|
path: parent_path
|
|
|
|
});
|
2019-05-01 22:21:45 +02:00
|
|
|
}
|
2019-09-23 03:35:26 +02:00
|
|
|
codiad.modal.unload();
|
2019-05-01 22:21:45 +02:00
|
|
|
});
|
2019-09-23 03:35:26 +02:00
|
|
|
});
|
2019-05-01 22:21:45 +02:00
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
delete_children_nodes: function( path ) {
|
|
|
|
|
2019-05-01 22:21:45 +02:00
|
|
|
let _this = this;
|
2019-09-23 03:35:26 +02:00
|
|
|
codiad.modal.load( 400, this.dialog, {
|
|
|
|
action: 'delete',
|
|
|
|
path: path
|
|
|
|
});
|
|
|
|
$( '#modal-content form' )
|
2020-01-07 03:35:50 +01:00
|
|
|
.on( 'submit', function( e ) {
|
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
e.preventDefault();
|
2020-01-07 03:35:50 +01:00
|
|
|
$.get( _this.controller + '?action=delete_children&path=' + encodeURIComponent( path ), function( data ) {
|
|
|
|
|
|
|
|
|
|
|
|
let response = codiad.jsend.parse( data );
|
|
|
|
if( response != 'error' ) {
|
|
|
|
|
|
|
|
let node = $( '#file-manager a[data-path="' + path + '"]' );
|
|
|
|
let parent_path = node.parent().parent().prev().attr( 'data-path' );
|
|
|
|
node.parent( 'li' ).remove();
|
2019-09-23 03:35:26 +02:00
|
|
|
|
|
|
|
// Close any active files
|
2020-01-07 03:35:50 +01:00
|
|
|
$( '#active-files a' ).each( function() {
|
|
|
|
|
|
|
|
let curPath = $( this ).attr( 'data-path' );
|
|
|
|
|
|
|
|
console.log( curPath, curPath.indexOf( path ) );
|
|
|
|
|
|
|
|
if( path.indexOf( curPath ) == 0 ) {
|
|
|
|
|
2019-09-23 03:35:26 +02:00
|
|
|
codiad.active.remove( curPath );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Notify listeners. */
|
|
|
|
amplify.publish( 'filemanager.onDelete', {
|
|
|
|
path: path
|
|
|
|
});
|
|
|
|
}
|
|
|
|
codiad.modal.unload();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
display_context_menu: function( e, path, type, name ) {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
|
|
|
let _this = this;
|
2020-01-07 03:35:50 +01:00
|
|
|
let top = e.pageY;
|
2019-10-29 14:37:19 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
$( '#context-menu a, #context-menu hr' ).hide();
|
|
|
|
|
|
|
|
// Selective options
|
|
|
|
switch ( type ) {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
case 'directory':
|
2019-10-29 14:37:19 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
$( '#context-menu .directory-only, #context-menu .non-root, #context-menu .both' ).show();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'file':
|
2019-10-29 14:37:19 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
$( '#context-menu .file-only, #context-menu .non-root, #context-menu .both' ).show();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'root':
|
|
|
|
|
|
|
|
$( '#context-menu .directory-only, #context-menu .root-only' ).show();
|
|
|
|
$( '#context-menu .non-root' ).hide();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'editor':
|
|
|
|
|
|
|
|
$( '#context-menu .editor-only' ).show();
|
|
|
|
break;
|
2019-10-29 14:37:19 +01:00
|
|
|
}
|
2020-01-07 03:35:50 +01:00
|
|
|
|
|
|
|
if( codiad.project.isAbsPath( $( '#file-manager a[data-type="root"]' ).attr( 'data-path' ) ) ) {
|
|
|
|
|
|
|
|
$( '#context-menu .no-external' ).hide();
|
|
|
|
} else if( type == "editor" ) {
|
|
|
|
|
|
|
|
$( '#context-menu .no-external' ).hide();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$( '#context-menu .no-external' ).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show menu
|
|
|
|
|
|
|
|
if( top > $( window ).height() - $( '#context-menu' ).height() ) {
|
|
|
|
|
|
|
|
top -= $( '#context-menu' ).height();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( top < 10 ) {
|
|
|
|
|
|
|
|
top = 10;
|
|
|
|
}
|
|
|
|
let max = $( window ).height() - top - 10;
|
|
|
|
|
|
|
|
$( '#context-menu' )
|
|
|
|
.css( {
|
|
|
|
'top': top + 'px',
|
|
|
|
'left': e.pageX + 'px',
|
|
|
|
'max-height': max + 'px'
|
|
|
|
})
|
|
|
|
.fadeIn( 200 )
|
|
|
|
.attr( 'data-path', path )
|
|
|
|
.attr( 'data-type', type )
|
|
|
|
.attr( 'data-name', name );
|
|
|
|
|
|
|
|
// Show faded 'paste' if nothing in clipboard
|
|
|
|
if( this.clipboard === '' ) {
|
|
|
|
|
|
|
|
$( '#context-menu a[content="Paste"]' )
|
|
|
|
.addClass( 'disabled' );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$( '#context-menu a[data-action="paste"]' )
|
|
|
|
.removeClass( 'disabled' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hide menu
|
|
|
|
/**
|
|
|
|
* make sure that the user has moved their mouse far enough
|
|
|
|
* away from the context menu to warrant a close.
|
|
|
|
*/
|
|
|
|
$( '#file-manager, #editor-region' ).on( 'mousemove', codiad.filemanager.context_menu_track_mouse );
|
|
|
|
$( '#context-menu, #editor-region' ).on( 'paste', codiad.editor.paste );
|
|
|
|
$( '#context-menu, #editor-region' ).on( 'click', _this.hide_context_menu );
|
|
|
|
|
|
|
|
/* Notify listeners. */
|
|
|
|
amplify.publish( 'context-menu.onShow', {
|
|
|
|
e: e,
|
|
|
|
path: path,
|
|
|
|
type: type
|
|
|
|
});
|
|
|
|
|
|
|
|
// Hide on click
|
|
|
|
$( '#context-menu a' ).on( 'click', _this.hide_context_menu );
|
2019-10-29 14:37:19 +01:00
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
download: function( path ) {
|
2019-10-29 14:37:19 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let type = this.getType( path );
|
|
|
|
$( '#download' )
|
|
|
|
.attr( 'src', 'components/filemanager/download.php?path=' + encodeURIComponent( path ) + '&type=' + type );
|
2019-10-29 14:37:19 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
get_extension: function( path ) {
|
|
|
|
|
|
|
|
return path.split( '.' ).pop();
|
|
|
|
},
|
|
|
|
|
|
|
|
get_indexes: async function( path ) {
|
|
|
|
|
|
|
|
let r = await $.get( this.controller + '?action=index&path=' + encodeURIComponent( path ) );
|
|
|
|
return r;
|
|
|
|
},
|
|
|
|
|
|
|
|
get_opened_indexes: async function( files ) {
|
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
|
|
|
|
for( let i = files.length;i--; ) {
|
2019-10-29 14:37:19 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
files[i].name = files[i].path;
|
|
|
|
|
|
|
|
if( files[i].type == "directory" && _this.opened_folders.includes( files[i].path ) ) {
|
2019-10-29 14:37:19 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
files[i].opened = true;
|
2019-10-29 14:37:19 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let data = await _this.get_indexes( files[i].path );
|
|
|
|
let response = codiad.jsend.parse( data );
|
|
|
|
let children = _this.get_opened_indexes( response );
|
|
|
|
_this.set_children( path, children, response );
|
2019-10-29 14:37:19 +01:00
|
|
|
}
|
2019-09-23 03:35:26 +02:00
|
|
|
}
|
2020-01-07 03:35:50 +01:00
|
|
|
return files;
|
|
|
|
},
|
|
|
|
|
|
|
|
get_short_name: function( path ) {
|
|
|
|
|
|
|
|
return path.split( '/' ).pop();
|
|
|
|
},
|
|
|
|
|
|
|
|
get_type: function( path ) {
|
|
|
|
|
|
|
|
if( path.match( /\\/g ) ) {
|
|
|
|
|
|
|
|
path = path.replace( '\\', '\\\\' );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $( '#file-manager a[data-path="' + path + '"]' ).attr( 'data-type' );
|
|
|
|
},
|
|
|
|
|
|
|
|
hide_context_menu: function() {
|
|
|
|
|
|
|
|
$( '#context-menu' ).fadeOut( 200 );
|
|
|
|
$( '#file-manager a' ).removeClass( 'context-menu-active' );
|
|
|
|
|
|
|
|
/* Notify listeners. */
|
|
|
|
amplify.publish( 'context-menu.onHide' );
|
2019-10-29 14:37:19 +01:00
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
index: async function( path, rescan = false ) {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2019-10-29 14:37:19 +01:00
|
|
|
let _this = codiad.filemanager;
|
2020-01-07 03:35:50 +01:00
|
|
|
|
|
|
|
let children = 0;
|
|
|
|
let container = $( '<ul></ul>' );
|
|
|
|
let files = [];
|
2019-09-23 03:35:26 +02:00
|
|
|
let node = $( '#file-manager a[data-path="' + path + '"]' );
|
|
|
|
let parentNode = node.parent();
|
2020-01-07 03:35:50 +01:00
|
|
|
let root = false;
|
2019-10-29 14:37:19 +01:00
|
|
|
let span = node.prev();
|
|
|
|
let total_saved = _this.files.length;
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
rescan = !!rescan;
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2019-10-29 14:37:19 +01:00
|
|
|
node.addClass( 'loading' );
|
2019-10-25 04:27:51 +02:00
|
|
|
|
2019-11-07 04:42:33 +01:00
|
|
|
if( rescan || total_saved == 0 || ! children ) {
|
2019-10-29 14:37:19 +01:00
|
|
|
|
2019-11-07 04:42:33 +01:00
|
|
|
let data = await _this.get_indexes( path );
|
|
|
|
let response = codiad.jsend.parse( data );
|
2019-12-11 17:23:33 +01:00
|
|
|
let result = [];
|
2019-10-29 14:37:19 +01:00
|
|
|
|
2019-11-07 04:42:33 +01:00
|
|
|
if( response != 'error' ) {
|
2019-10-29 14:37:19 +01:00
|
|
|
|
2019-11-07 04:42:33 +01:00
|
|
|
result = response.index;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( total_saved == 0 ) {
|
2019-10-29 14:37:19 +01:00
|
|
|
|
2019-11-07 04:42:33 +01:00
|
|
|
_this.files = result;
|
|
|
|
files = result;
|
|
|
|
} else {
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
_this.set_children( path, _this.files, result );
|
2019-11-07 04:42:33 +01:00
|
|
|
files = result;
|
|
|
|
}
|
2019-10-29 14:37:19 +01:00
|
|
|
} else {
|
|
|
|
|
|
|
|
files = file.children;
|
2019-11-07 04:42:33 +01:00
|
|
|
}
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
files = _this.get_opened_indexes( files );
|
|
|
|
_this.index_nodes(
|
|
|
|
path,
|
|
|
|
node,
|
|
|
|
files,
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
directory: [_this.index_directory_callback],
|
|
|
|
file: [_this.index_file_callback],
|
|
|
|
}
|
|
|
|
);
|
2019-11-07 04:42:33 +01:00
|
|
|
|
|
|
|
/* Notify listener */
|
|
|
|
amplify.publish( "filemanager.onIndex", {
|
|
|
|
path: path,
|
|
|
|
files: files
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
index_directory_callback: function( entry, container, i, files ) {
|
2019-10-25 04:27:51 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let _this = codiad.filemanager;
|
|
|
|
entry.children( 'a' ).droppable({
|
|
|
|
accept: _this.object_accept,
|
|
|
|
drop: _this.object_drop,
|
|
|
|
over: _this.object_over,
|
|
|
|
out: _this.object_out
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
index_file_callback: function( entry, container, i, files ) {
|
2019-10-29 14:37:19 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let _this = codiad.filemanager;
|
|
|
|
entry.draggable({
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2019-11-07 04:42:33 +01:00
|
|
|
opacity: 0.85,
|
|
|
|
revert: true,
|
|
|
|
start: _this.object_start,
|
|
|
|
stop: _this.object_stop,
|
|
|
|
zIndex: 100
|
|
|
|
});
|
2019-10-25 04:27:51 +02:00
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
index_nodes: function( path, node, files, filters, callbacks ) {
|
2019-10-25 04:27:51 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let container = $( '<ul></ul>' );
|
2019-10-29 14:37:19 +01:00
|
|
|
let total_files = files.length;
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let link = node.children( 'a' );
|
|
|
|
let ul = node.parent( 'li' ).children( 'ul' );
|
2019-10-25 04:27:51 +02:00
|
|
|
|
2019-10-29 14:37:19 +01:00
|
|
|
for( let i = 0;i < total_files;i++ ) {
|
2019-10-25 04:27:51 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let v = files[i];
|
2019-10-25 04:27:51 +02:00
|
|
|
let ext = '';
|
|
|
|
let name = '';
|
2020-01-07 03:35:50 +01:00
|
|
|
let node_class = 'none';
|
2019-10-25 04:27:51 +02:00
|
|
|
let entry = $( "<li></li>" );
|
|
|
|
let span = $( "<span></span>" );
|
|
|
|
let link = $( "<a></a>" );
|
|
|
|
let type = null;
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
if( v.type == "file" ) {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2019-11-07 04:42:33 +01:00
|
|
|
if( filters.type == "directories" ) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2019-10-25 04:27:51 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
ext = "ext-" + v.extension;
|
|
|
|
name = v.basename;
|
2019-10-25 04:27:51 +02:00
|
|
|
type = 'file';
|
|
|
|
link.addClass( ext );
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
} else if( v.type == "directory" ) {
|
2019-10-25 04:27:51 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
if( v.children ) {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
if( v.open ) {
|
2019-10-29 14:37:19 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
node_class = "minus";
|
|
|
|
_this.index_nodes( v.path, link, v.children, filters, callbacks );
|
2019-10-29 14:37:19 +01:00
|
|
|
} else {
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
node_class = "plus";
|
2019-10-29 14:37:19 +01:00
|
|
|
}
|
2019-09-23 03:35:26 +02:00
|
|
|
}
|
2019-10-25 04:27:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
span.addClass( nodeClass );
|
|
|
|
link.addClass( type );
|
|
|
|
link.attr( "data-type", type );
|
2020-01-07 03:35:50 +01:00
|
|
|
link.attr( "data-path", v.path );
|
2019-10-25 04:27:51 +02:00
|
|
|
link.text( name );
|
|
|
|
|
|
|
|
entry.append( span, link );
|
|
|
|
container.append( entry );
|
2019-11-07 04:42:33 +01:00
|
|
|
|
|
|
|
if( typeof callbacks == "function" ) {
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
callbacks( entry, container, v, files );
|
2019-11-07 04:42:33 +01:00
|
|
|
} else if( Array.isArray( callbacks ) ) {
|
|
|
|
|
|
|
|
let total_callbacks = callbacks.length;
|
|
|
|
for( let j = 0;j < total_callbacks;j++ ) {
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
callbacks[j]( entry, container, v, files );
|
|
|
|
}
|
|
|
|
} else if( callbacks === Object( callbacks ) ) {
|
|
|
|
|
|
|
|
if( typeof callbacks[v.type] == "function" ) {
|
|
|
|
|
|
|
|
callbacks[v.type]( entry, container, v, files );
|
|
|
|
} else if( Array.isArray( callbacks[v.type] ) ) {
|
|
|
|
|
|
|
|
let total_callbacks = callbacks[v.type].length;
|
|
|
|
for( let j = 0;j < total_callbacks;j++ ) {
|
|
|
|
|
|
|
|
callbacks[v.type][j]( entry, container, v, files );
|
|
|
|
}
|
2019-11-07 04:42:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-07 03:35:50 +01:00
|
|
|
|
|
|
|
if( ul.length ) {
|
|
|
|
|
|
|
|
ul.replaceWith( container );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$( container ).insertAfter( node );
|
|
|
|
}
|
|
|
|
|
|
|
|
node.removeClass( 'loading' );
|
2019-11-07 04:42:33 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
is_child: function( parent, child ) {
|
|
|
|
|
|
|
|
if( child === parent ) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let parentTokens = parent.split( '/' ).filter( i => i.length );
|
|
|
|
return parentTokens.every( ( t, i ) => child.split( '/' )[i] === t )
|
2019-09-23 03:35:26 +02:00
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
node_listeners: function() {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
|
|
|
let _this = this;
|
|
|
|
|
2019-11-07 04:42:33 +01:00
|
|
|
$( '#file-manager' )
|
|
|
|
.on( 'click', 'a', function() {
|
|
|
|
|
|
|
|
// Open or Expand
|
|
|
|
if( codiad.editor.settings.fileManagerTrigger ) {
|
|
|
|
|
|
|
|
if( $( this ).hasClass( 'directory' ) ) {
|
|
|
|
|
|
|
|
_this.index( $( this ).attr( 'data-path' ) );
|
2019-09-23 03:35:26 +02:00
|
|
|
} else {
|
2019-11-07 04:42:33 +01:00
|
|
|
|
|
|
|
_this.openFile( $( this ).attr( 'data-path' ) );
|
2019-09-23 03:35:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2019-11-07 04:42:33 +01:00
|
|
|
.on( 'click', 'span', function() {
|
|
|
|
|
|
|
|
// Open or Expand
|
|
|
|
if( $( this ).parent().children( "a" ).attr( 'data-type' ) == 'directory' ) {
|
|
|
|
|
|
|
|
_this.index( $( this ).parent().children( "a" ).attr( 'data-path' ) );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
_this.openFile( $( this ).parent().children( "a" ).attr( 'data-path' ) );
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.on( "contextmenu", 'a', function( e ) {
|
|
|
|
|
|
|
|
// Context Menu
|
|
|
|
e.preventDefault();
|
2020-01-07 03:35:50 +01:00
|
|
|
_this.display_context_menu(
|
2019-11-07 04:42:33 +01:00
|
|
|
e,
|
|
|
|
$( this ).attr( 'data-path' ),
|
|
|
|
$( this ).attr( 'data-type' ),
|
|
|
|
$( this ).html()
|
|
|
|
);
|
|
|
|
$( this ).addClass( 'context-menu-active' );
|
|
|
|
})
|
|
|
|
.on( 'dblclick', 'a', function() {
|
|
|
|
|
|
|
|
// Open or Expand
|
|
|
|
if( ! codiad.editor.settings.fileManagerTrigger ) {
|
|
|
|
|
|
|
|
if( $( this ).hasClass( 'directory' ) ) {
|
|
|
|
|
|
|
|
_this.index( $( this ).attr( 'data-path' ) );
|
2019-09-23 03:35:26 +02:00
|
|
|
} else {
|
2019-11-07 04:42:33 +01:00
|
|
|
|
|
|
|
_this.openFile( $( this ).attr( 'data-path' ) );
|
2019-09-23 03:35:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2019-11-07 04:42:33 +01:00
|
|
|
.on( 'selectstart', false );
|
2019-09-23 03:35:26 +02:00
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
open_file: function( path, focus = true ) {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
/* Notify listeners. */
|
|
|
|
amplify.publish( 'filemanager.onFileWillOpen', {
|
|
|
|
path: path
|
|
|
|
});
|
2019-09-23 03:35:26 +02:00
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
2020-01-07 03:35:50 +01:00
|
|
|
let node = $( '#file-manager a[data-path="' + path + '"]' );
|
|
|
|
let ext = _this.getExtension( path );
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
if( $.inArray( ext.toLowerCase(), _this.noOpen ) < 0 ) {
|
2019-07-02 22:46:32 +02:00
|
|
|
|
2019-05-01 22:21:45 +02:00
|
|
|
node.addClass( 'loading' );
|
2020-01-07 03:35:50 +01:00
|
|
|
$.get( _this.controller + '?action=open&path=' + encodeURIComponent( path ), function( data ) {
|
2019-07-02 22:46:32 +02:00
|
|
|
|
2019-10-29 14:37:19 +01:00
|
|
|
let openResponse = codiad.jsend.parse( data );
|
2019-05-01 22:21:45 +02:00
|
|
|
if( openResponse != 'error' ) {
|
2019-07-02 22:46:32 +02:00
|
|
|
|
2019-05-01 22:21:45 +02:00
|
|
|
node.removeClass( 'loading' );
|
2019-07-02 22:46:32 +02:00
|
|
|
codiad.active.open( path, openResponse.content, openResponse.mtime, false, focus, openResponse.read_only );
|
2019-05-01 22:21:45 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2019-07-02 22:46:32 +02:00
|
|
|
|
|
|
|
if( ! codiad.project.isAbsPath( path ) ) {
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
if( $.inArray( ext.toLowerCase(), _this.noBrowser ) < 0 ) {
|
2019-07-02 22:46:32 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
_this.download( path );
|
2019-05-01 22:21:45 +02:00
|
|
|
} else {
|
2019-07-02 22:46:32 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
_this.openInModal( path );
|
2019-05-01 22:21:45 +02:00
|
|
|
}
|
|
|
|
} else {
|
2019-07-02 22:46:32 +02:00
|
|
|
|
2019-05-01 22:21:45 +02:00
|
|
|
codiad.message.error( i18n( 'Unable to open file in Browser while using absolute path.' ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
rename: function( path, new_path ) {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
return new Promise( function( resolve, reject ) {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: _this.controller + '?action=rename',
|
|
|
|
data: {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
path: path,
|
|
|
|
destination: newPath
|
|
|
|
},
|
|
|
|
success: function( data ) {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
resolve( data );
|
|
|
|
},
|
|
|
|
error: function( data ) {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
reject( data );
|
|
|
|
},
|
|
|
|
});
|
2019-09-23 03:35:26 +02:00
|
|
|
});
|
2019-05-01 22:21:45 +02:00
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
rename_node: function( path, new_path ) {
|
|
|
|
|
2019-10-29 14:37:19 +01:00
|
|
|
let shortName = this.getShortName( path );
|
|
|
|
let type = this.getType( path );
|
2019-05-01 22:21:45 +02:00
|
|
|
let _this = this;
|
2020-01-07 03:35:50 +01:00
|
|
|
let project = codiad.project.getCurrent();
|
|
|
|
|
2019-05-01 22:21:45 +02:00
|
|
|
codiad.modal.load( 250, this.dialog, {
|
|
|
|
action: 'rename',
|
|
|
|
path: path,
|
|
|
|
short_name: shortName,
|
|
|
|
type: type
|
|
|
|
});
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2019-05-01 22:21:45 +02:00
|
|
|
$( '#modal-content form' )
|
2020-01-07 03:35:50 +01:00
|
|
|
.on( 'submit', async function( e ) {
|
|
|
|
|
2019-05-01 22:21:45 +02:00
|
|
|
e.preventDefault();
|
2019-10-29 14:37:19 +01:00
|
|
|
let arr = path.split( '/' );
|
2020-01-07 03:35:50 +01:00
|
|
|
let message = "Successfully Renamed."
|
|
|
|
let newName = $( '#modal-content form input[name="object_name"]' ).val();
|
|
|
|
let newParent = newPath.split( '/' );
|
|
|
|
let parent = path.split( '/' );
|
|
|
|
let temp = [];
|
|
|
|
|
2019-05-01 22:21:45 +02:00
|
|
|
for( i = 0; i < arr.length - 1; i++ ) {
|
2019-05-01 22:29:46 +02:00
|
|
|
temp.push( arr[i] )
|
2019-05-01 22:21:45 +02:00
|
|
|
}
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let newPath = temp.join( '/' ) + '/' + newName;
|
|
|
|
let result = codiad.jsend.parse( await _this.rename( path, newPath ) );
|
|
|
|
codiad.modal.unload();
|
2019-11-24 04:56:19 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
if( result != 'error' ) {
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
if( type !== undefined ) {
|
2019-11-24 04:56:19 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let node = $( '#file-manager a[data-path="' + path + '"]' );
|
2019-11-24 04:56:19 +01:00
|
|
|
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
node.attr( 'data-path', newPath ).html( newPath.split( "/" ).pop() );
|
|
|
|
message = type.charAt( 0 ).toUpperCase() + type.slice( 1 ) + ' Renamed'
|
|
|
|
codiad.message.success( message );
|
2019-11-24 04:56:19 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
// Change icons for file
|
|
|
|
let current_class = 'ext-' + _this.get_extension( path );
|
|
|
|
let new_class = 'ext-' + _this.get_extension( newPath );
|
|
|
|
|
|
|
|
$( '#file-manager a[data-path="' + newPath + '"]' )
|
|
|
|
.removeClass( current_class )
|
|
|
|
.addClass( new_class );
|
|
|
|
codiad.active.rename( path, newPath );
|
|
|
|
|
|
|
|
parent = parent.pop();
|
|
|
|
newParent = newParent.pop();
|
|
|
|
|
|
|
|
codiad.filemanager.rescan( parent.join( '/' ) );
|
|
|
|
codiad.filemanager.rescan( newParent.join( '/' ) );
|
|
|
|
|
|
|
|
/* Notify listeners. */
|
|
|
|
amplify.publish( 'filemanager.onRename', {
|
|
|
|
path: path,
|
|
|
|
newPath: newPath,
|
|
|
|
project: project
|
|
|
|
});
|
|
|
|
}
|
2019-11-07 04:42:33 +01:00
|
|
|
}
|
2020-01-07 03:35:50 +01:00
|
|
|
});
|
2019-11-07 04:42:33 +01:00
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
preview_path: function( path ) {
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2019-11-24 04:56:19 +01:00
|
|
|
|
2019-11-07 04:42:33 +01:00
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
rescan: function( path ) {
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let _this = codiad.filemanager;
|
|
|
|
_this.index( path, true );
|
2019-11-07 04:42:33 +01:00
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
save_file: function() {},
|
2019-05-01 22:21:45 +02:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
save_modifications: function() {},
|
2019-11-15 05:16:07 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
save_patch: function() {},
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
set_children: function( path, files, children ) {
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let _this = this;
|
|
|
|
let index = {};
|
|
|
|
let total = ( !!files ) ? files.length : 0;
|
2019-11-24 04:56:19 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
for( let i = 0;i < total;i++ ) {
|
2019-11-15 05:16:07 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
if( path == files[i].dirname ) {
|
2019-11-15 05:16:07 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
files[i].children = children;
|
|
|
|
index = files[i];
|
|
|
|
break;
|
|
|
|
} else {
|
2019-11-24 04:56:19 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
if( files[i].children !== undefined ) {
|
2019-12-10 20:09:24 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
index = _this.set_children( path, files[i].children, children );
|
2019-12-12 14:22:43 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
if( Object.keys( index ).length > 0 ) {
|
2019-12-12 14:22:43 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
break;
|
2019-12-12 14:22:43 +01:00
|
|
|
}
|
2019-12-10 20:09:24 +01:00
|
|
|
}
|
2019-11-24 04:56:19 +01:00
|
|
|
}
|
|
|
|
}
|
2020-01-07 03:35:50 +01:00
|
|
|
return index;
|
2019-11-07 04:42:33 +01:00
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
unarchive: function( path ) {
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
let _this = this;
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
$.get( _this.controller + '?action=unarchive&path=' + encodeURIComponent( path ), function( data ) {
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
console.log( data );
|
|
|
|
let response = codiad.jsend.parse( data );
|
|
|
|
console.log( response );
|
|
|
|
parent = path.split( '/' );
|
|
|
|
parent.pop();
|
|
|
|
_this.rescan( parent.join( '/' ) );
|
|
|
|
});
|
2019-11-07 04:42:33 +01:00
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
upload: function() {},
|
2019-11-24 04:56:19 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
//Compatibility functions
|
|
|
|
|
|
|
|
copyNode: this.copy_node,
|
|
|
|
createNode: this.create_node,
|
|
|
|
createObject: this.create_object,
|
|
|
|
deleteNode: this.delete_node,
|
|
|
|
getExtension: this.get_extension,
|
|
|
|
getShortName: this.get_short_name,
|
|
|
|
getType: this.get_type,
|
|
|
|
openFile: this.open_file,
|
|
|
|
openInBrowser: this.preview,
|
|
|
|
pasteNode: this.paste_node,
|
|
|
|
renameNode: this.rename_node,
|
|
|
|
saveFile: this.save_file,
|
2019-05-01 22:21:45 +02:00
|
|
|
};
|
|
|
|
})( this, jQuery );
|