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-23 14:29:56 +01:00
|
|
|
file_preview_list: {
|
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
|
|
|
],
|
|
|
|
},
|
2020-01-29 06:07:00 +01:00
|
|
|
file_reader: null,
|
2020-01-07 03:35:50 +01:00
|
|
|
files: [],
|
2020-01-09 06:35:38 +01:00
|
|
|
node: {
|
|
|
|
|
|
|
|
accept: function( e, i ) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
drag: function( e, i ) {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
drop: function( e, i ) {
|
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
let drag = i.helper[0];
|
|
|
|
let drop = e.target;
|
|
|
|
|
|
|
|
$( drop ).removeClass( "drag_over" );
|
|
|
|
|
2020-01-23 14:29:56 +01:00
|
|
|
if( ! $( drop ).attr( "data-path" ) ) {
|
|
|
|
|
|
|
|
drop = $( drop ).children( 'a' );
|
|
|
|
}
|
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
console.log( drop );
|
|
|
|
console.log( drag );
|
|
|
|
|
|
|
|
let drop_path = $( drop ).attr( "data-path" );
|
|
|
|
let drag_path = $( drag ).children( "a" ).attr( "data-path" );
|
|
|
|
let path = drag_path;
|
|
|
|
let newPath = `${drop_path}/` + path.split( "/" ).pop();
|
|
|
|
|
|
|
|
console.log( path, newPath );
|
|
|
|
_this.rename_node( path, newPath );
|
|
|
|
},
|
|
|
|
|
|
|
|
out: function( e, i ) {
|
|
|
|
|
|
|
|
let drag = i.helper[0];
|
|
|
|
let drop = e.target;
|
|
|
|
|
|
|
|
$( drop ).removeClass( "drag_over" );
|
|
|
|
},
|
|
|
|
|
|
|
|
over: function( e, i ) {
|
|
|
|
|
|
|
|
let drag = i.helper[0];
|
|
|
|
let drop = e.target;
|
|
|
|
|
|
|
|
$( drop ).addClass( "drag_over" );
|
|
|
|
},
|
|
|
|
|
|
|
|
start: function( e, i ) {
|
|
|
|
|
|
|
|
let drag = i.helper[0];
|
|
|
|
$( drag ).addClass( "drag_start" );
|
|
|
|
$( drag ).children( 'a' ).removeClass( "a:hover" );
|
|
|
|
},
|
|
|
|
|
|
|
|
stop: function( e, i ) {
|
|
|
|
|
|
|
|
let drag = i.helper[0];
|
|
|
|
$( drag ).removeClass( "drag_start" );
|
|
|
|
//$( drag ).removeClass( "hover" );
|
|
|
|
},
|
|
|
|
},
|
2020-01-07 03:35:50 +01:00
|
|
|
opened_folders: [],
|
|
|
|
post_max_size: ( 1024*1024 ),
|
2020-01-24 17:03:03 +01:00
|
|
|
preview_window: null,
|
2020-01-07 03:35:50 +01:00
|
|
|
refresh_interval: null,
|
|
|
|
selected: [],
|
|
|
|
|
|
|
|
init: async function() {
|
2019-10-16 16:20:09 +02:00
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
let _this = codiad.filemanager;
|
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
|
|
|
|
2020-01-24 17:03:03 +01:00
|
|
|
codiad.editor.getActive().addEventListener( "change", _this.refresh_preview );
|
2019-05-01 22:21:45 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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();
|
|
|
|
_this.node_listeners();
|
2020-01-23 14:29:56 +01:00
|
|
|
|
|
|
|
$( document ).on( 'dragenter', function( e ) {
|
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
let d = e.originalEvent.dataTransfer;
|
|
|
|
|
2020-02-03 20:25:32 +01:00
|
|
|
if( d && e.target.className !== "ace_scroller" ) {
|
2020-01-29 06:07:00 +01:00
|
|
|
|
|
|
|
let files = d.files;
|
|
|
|
let items = d.items;
|
|
|
|
|
2020-02-03 20:25:32 +01:00
|
|
|
console.log( 'dragenter', e, e.target, files, items, items[0].webkitGetAsEntry() );
|
2020-01-29 06:07:00 +01:00
|
|
|
_this.upload_overlay_on();
|
|
|
|
}
|
2020-01-23 14:29:56 +01:00
|
|
|
});
|
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
$( '.drop-overlay' ).on( 'drag dragstart dragend dragover dragenter dragleave drop', function( e ) {
|
2020-01-23 14:29:56 +01:00
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
//console.log( 'drag dragstart dragend dragover dragenter dragleave drop', e );
|
2020-01-23 14:29:56 +01:00
|
|
|
})
|
|
|
|
.on( 'dragover dragenter', function( e ) {
|
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
//console.log( 'dragover dragenter', e );
|
2020-01-23 14:29:56 +01:00
|
|
|
})
|
2020-01-29 06:07:00 +01:00
|
|
|
.on( 'dragleave dragend drop dragdrop', function( e ) {
|
2020-01-23 14:29:56 +01:00
|
|
|
|
|
|
|
//e.preventDefault();
|
|
|
|
//e.stopPropagation();
|
2020-01-29 06:07:00 +01:00
|
|
|
_this.upload_overlay_off();
|
|
|
|
})
|
|
|
|
.on( 'drop dragdrop', async function( e ) {
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
let d = e.originalEvent.dataTransfer;
|
|
|
|
|
|
|
|
if( d ) {
|
|
|
|
|
|
|
|
let files = [];
|
|
|
|
let items = [];
|
|
|
|
|
|
|
|
let file_list = d.files;
|
|
|
|
let item_list = d.items;
|
|
|
|
let total_items = item_list.length;
|
|
|
|
|
|
|
|
if( item_list && item_list[0].webkitGetAsEntry ) {
|
|
|
|
|
|
|
|
for( let i = 0;i < total_items;i++ ) {
|
|
|
|
|
|
|
|
items.push( item_list[i].webkitGetAsEntry() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log( files, items );
|
|
|
|
|
|
|
|
let project = $( '#file-manager a[data-type="root"]' ).attr( 'data-path' );
|
|
|
|
let path = await _this.open_file_selector( project, {type: "directory"}, 1, {} );
|
|
|
|
|
|
|
|
if( items.length ) {
|
|
|
|
|
|
|
|
for( let i = items.length;i--; ) {
|
|
|
|
|
|
|
|
let j = await _this.upload_load_files( items[i], path );
|
|
|
|
files = files.concat( j );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
files = file_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( let i = files.length;i--; ) {
|
|
|
|
|
|
|
|
let status = await _this.upload( files[i] );
|
2020-02-03 20:25:32 +01:00
|
|
|
//console.log( status );
|
2020-01-29 06:07:00 +01:00
|
|
|
}
|
|
|
|
console.log( 'drop', files, items );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
codiad.message.error( i18n( 'Your browser does not seem to support dragging and dropping files' ) );
|
|
|
|
}
|
2020-01-23 14:29:56 +01:00
|
|
|
});
|
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
$( '.drop-overlay' ).on( 'click', _this.upload_overlay_off );
|
2020-02-07 19:01:04 +01:00
|
|
|
|
|
|
|
$( "#uploads-button" ).on( 'click' , _this.toggle_uploads );
|
|
|
|
$( "#uploads-close" ).on( 'click', function() {
|
|
|
|
|
|
|
|
$( ".uploads-container" ).slideUp();
|
|
|
|
});
|
|
|
|
|
|
|
|
amplify.subscribe( 'editor.changeCursor', function() {
|
|
|
|
|
|
|
|
$( "#uploads-button" ).css( "right", ( $( "#cursor-position" ).width() + 36 ) + 'px' );
|
|
|
|
});
|
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 05:53:35 +01:00
|
|
|
context_menu_track_mouse: function( e ) {
|
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
|
2020-01-22 16:14:01 +01:00
|
|
|
})
|
|
|
|
.then( function( container ) {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
$( '#modal-content form' )
|
|
|
|
.on( 'submit', function( e ) {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
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();
|
|
|
|
let createPath = path + '/' + shortName;
|
|
|
|
|
|
|
|
$.get( codiad.filemanager.controller + '?action=create&path=' + encodeURIComponent( createPath ) + '&type=' + type, function( data ) {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
let createResponse = codiad.jsend.parse( data );
|
|
|
|
if( createResponse != 'error' ) {
|
|
|
|
|
|
|
|
codiad.message.success( type.charAt( 0 )
|
|
|
|
.toUpperCase() + type.slice( 1 ) + ' Created' );
|
|
|
|
codiad.modal.unload();
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
if( type == 'file' ) {
|
|
|
|
|
|
|
|
codiad.filemanager.openFile( createPath, true );
|
|
|
|
}
|
|
|
|
codiad.filemanager.rescan( path );
|
|
|
|
|
|
|
|
/* Notify listeners. */
|
|
|
|
amplify.publish( 'filemanager.onCreate', {
|
|
|
|
createPath: createPath,
|
|
|
|
path: path,
|
|
|
|
shortName: shortName,
|
|
|
|
type: type
|
|
|
|
});
|
2019-09-23 03:35:26 +02:00
|
|
|
}
|
2020-01-09 06:35:38 +01: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_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
|
2020-01-22 16:14:01 +01:00
|
|
|
})
|
|
|
|
.then( function( container ) {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
$( '#modal-content form' )
|
|
|
|
.on( 'submit', function( e ) {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
e.preventDefault();
|
|
|
|
$.get( _this.controller + '?action=delete&path=' + encodeURIComponent( path ), function( data ) {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
let response = codiad.jsend.parse( data );
|
|
|
|
if( response != 'error' ) {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
let node = $( '#file-manager a[data-path="' + path + '"]' );
|
|
|
|
let parent_path = node.parent().parent().children( 'a' ).attr( 'data-path' );
|
|
|
|
node.parent( 'li' ).remove();
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
// Close any active files
|
|
|
|
$( '#active-files a' ).each( function() {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
let curPath = $( this ).attr( 'data-path' );
|
|
|
|
|
|
|
|
console.log( curPath, curPath.indexOf( path ) );
|
|
|
|
|
|
|
|
if( curPath.indexOf( path ) == 0 ) {
|
|
|
|
|
|
|
|
codiad.active.remove( curPath );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Notify listeners. */
|
|
|
|
amplify.publish( 'filemanager.onDelete', {
|
|
|
|
deletePath: path,
|
|
|
|
path: parent_path
|
|
|
|
});
|
|
|
|
}
|
|
|
|
codiad.modal.unload();
|
|
|
|
});
|
2019-05-01 22:21:45 +02:00
|
|
|
});
|
2020-01-22 16:14:01 +01: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
|
2020-01-29 06:07:00 +01:00
|
|
|
})
|
|
|
|
.then( function() {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
$( '#modal-content form' )
|
|
|
|
.on( 'submit', function( e ) {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
e.preventDefault();
|
|
|
|
$.get( _this.controller + '?action=delete_children&path=' + encodeURIComponent( path ), function( data ) {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
console.log( data );
|
|
|
|
let response = codiad.jsend.parse( data );
|
|
|
|
if( response != 'error' ) {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
let node = $( '#file-manager a[data-path="' + path + '"]' );
|
|
|
|
let parent_path = node.parent().parent().prev().attr( 'data-path' );
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
_this.toggle_directory( node, [], [], true );
|
|
|
|
node.parent( 'li' ).children( 'span' ).remove();
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
// Close any active files
|
|
|
|
$( '#active-files a' ).each( function() {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
let curPath = $( this ).attr( 'data-path' );
|
|
|
|
|
|
|
|
console.log( curPath, curPath.indexOf( path ) );
|
|
|
|
|
|
|
|
if( path.indexOf( curPath ) == 0 ) {
|
|
|
|
|
|
|
|
codiad.active.remove( curPath );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Notify listeners. */
|
|
|
|
amplify.publish( 'filemanager.onDelete', {
|
|
|
|
path: path
|
|
|
|
});
|
|
|
|
}
|
|
|
|
codiad.modal.unload();
|
|
|
|
});
|
2019-09-23 03:35:26 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
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();
|
|
|
|
},
|
|
|
|
|
2020-01-07 05:53:35 +01:00
|
|
|
get_index: function( path, files ) {
|
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
if( ! files ) {
|
|
|
|
|
|
|
|
files = _this.files;
|
|
|
|
}
|
|
|
|
|
2020-01-07 05:53:35 +01:00
|
|
|
return new Promise( async function( resolve, reject ) {
|
|
|
|
|
|
|
|
let index = {};
|
|
|
|
let total = ( !!files ) ? files.length : 0;
|
|
|
|
|
|
|
|
for( let i = 0;i < total;i++ ) {
|
|
|
|
|
|
|
|
if( path == files[i].dirname ) {
|
|
|
|
|
|
|
|
index = files[i];
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
|
2020-01-23 14:29:56 +01:00
|
|
|
if( files[i].children !== undefined && files[i].children !== null ) {
|
|
|
|
|
2020-02-03 20:25:32 +01:00
|
|
|
//console.log( path );
|
|
|
|
//console.log( files[i] );
|
2020-01-07 05:53:35 +01:00
|
|
|
|
|
|
|
index = await _this.get_index( path, files[i].children );
|
|
|
|
|
|
|
|
if( Object.keys( index ).length > 0 ) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resolve( index );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
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;
|
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
if( files[i].type == "directory" ) {
|
2019-10-29 14:37:19 +01:00
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
let existing_data = await _this.get_index( files[i].path );
|
2019-10-29 14:37:19 +01:00
|
|
|
|
2020-02-03 20:25:32 +01:00
|
|
|
//console.log( "opened?", existing_data, files[i] );
|
2020-01-09 06:35:38 +01:00
|
|
|
|
|
|
|
if( existing_data.open ) {
|
|
|
|
|
|
|
|
files[i].open = true;
|
|
|
|
let data = await _this.get_indexes( files[i].path );
|
|
|
|
let response = codiad.jsend.parse( data );
|
|
|
|
_this.set_children( files[i].path, files, response.index );
|
|
|
|
|
|
|
|
let children = await _this.get_opened_indexes( response.index );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
files[i].open = false;
|
|
|
|
}
|
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;
|
|
|
|
},
|
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
get_parent: function( path ) {
|
|
|
|
|
|
|
|
let parent = path.split( '/' );
|
|
|
|
parent.pop();
|
|
|
|
return parent.join( '/' );
|
|
|
|
},
|
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
get_file_reader: function() {
|
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
|
|
|
|
if( ! _this.reader ) {
|
|
|
|
|
|
|
|
_this.reader = new FileReader();
|
|
|
|
}
|
|
|
|
return _this.reader;
|
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
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-09 06:35:38 +01:00
|
|
|
index: async function( path, rescan = false, node = null, filters = {}, callbacks = {} ) {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-02-03 20:25:32 +01:00
|
|
|
path.replace( /\/$/, '' );
|
|
|
|
|
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 = [];
|
|
|
|
let root = false;
|
2019-10-29 14:37:19 +01:00
|
|
|
let total_saved = _this.files.length;
|
2020-01-07 05:53:35 +01:00
|
|
|
let file = await _this.get_index( path );
|
2020-01-07 03:35:50 +01:00
|
|
|
rescan = !!rescan;
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
if( node === null ) {
|
|
|
|
|
|
|
|
node = $( '#file-manager a[data-path="' + path + '"]' );
|
|
|
|
}
|
|
|
|
|
|
|
|
let parentNode = node.parent();
|
|
|
|
let span = node.prev();
|
|
|
|
|
2020-01-23 14:29:56 +01:00
|
|
|
if( node.attr( 'data-type' ) == "root" ) {
|
|
|
|
|
2020-02-07 19:01:04 +01:00
|
|
|
node.addClass( "open" );
|
2020-01-23 14:29:56 +01:00
|
|
|
node.droppable({
|
|
|
|
accept: _this.node.accept,
|
|
|
|
drop: _this.node.drop,
|
|
|
|
over: _this.node.over,
|
|
|
|
out: _this.node.out
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
if( ! callbacks.directory ) {
|
|
|
|
|
|
|
|
callbacks.directory = [_this.index_directory_callback];
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ! callbacks.file ) {
|
|
|
|
|
|
|
|
callbacks.file = [_this.index_file_callback];
|
|
|
|
}
|
|
|
|
|
2019-10-29 14:37:19 +01:00
|
|
|
node.addClass( 'loading' );
|
2019-10-25 04:27:51 +02:00
|
|
|
|
2020-01-07 05:53:35 +01:00
|
|
|
if( Object.keys( file ).length == 0 ) {
|
|
|
|
|
|
|
|
children = file.children;
|
|
|
|
}
|
|
|
|
|
2020-02-03 20:25:32 +01:00
|
|
|
//console.log( file.children, file )
|
|
|
|
|
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 );
|
2020-01-24 17:03:03 +01:00
|
|
|
|
2020-02-03 20:25:32 +01:00
|
|
|
//console.log( data );
|
2020-01-24 17:03:03 +01:00
|
|
|
|
2019-11-07 04:42:33 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-01-09 06:35:38 +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 05:53:35 +01:00
|
|
|
files = await _this.get_opened_indexes( files );
|
2020-01-09 06:35:38 +01:00
|
|
|
|
|
|
|
if( total_saved == 0 ) {
|
|
|
|
|
|
|
|
_this.files = files;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
_this.set_children( path, _this.files, files );
|
|
|
|
}
|
|
|
|
|
2020-02-03 20:25:32 +01:00
|
|
|
//console.log( _this.files, files )
|
2020-01-09 06:35:38 +01:00
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
_this.index_nodes(
|
|
|
|
path,
|
|
|
|
node,
|
|
|
|
files,
|
2020-01-09 06:35:38 +01:00
|
|
|
filters,
|
|
|
|
callbacks,
|
2020-01-07 03:35:50 +01:00
|
|
|
);
|
2019-11-07 04:42:33 +01:00
|
|
|
|
|
|
|
/* Notify listener */
|
|
|
|
amplify.publish( "filemanager.onIndex", {
|
|
|
|
path: path,
|
|
|
|
files: files
|
|
|
|
});
|
2020-01-09 06:35:38 +01:00
|
|
|
return files;
|
2019-11-07 04:42:33 +01:00
|
|
|
},
|
|
|
|
|
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;
|
2020-01-24 17:03:03 +01:00
|
|
|
entry.children( 'a' ).droppable({
|
2020-01-09 06:35:38 +01:00
|
|
|
accept: _this.node.accept,
|
|
|
|
drop: _this.node.drop,
|
|
|
|
over: _this.node.over,
|
2020-01-23 14:29:56 +01:00
|
|
|
out: _this.node.out,
|
|
|
|
|
|
|
|
start: _this.node.start,
|
|
|
|
stop: _this.node.stop,
|
2020-01-07 03:35:50 +01:00
|
|
|
});
|
2020-01-24 17:03:03 +01:00
|
|
|
entry.draggable({
|
|
|
|
opacity: 0.85,
|
|
|
|
revert: true,
|
|
|
|
start: _this.node.start,
|
|
|
|
stop: _this.node.stop,
|
|
|
|
zIndex: 100,
|
|
|
|
});
|
2020-01-07 03:35:50 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
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-11-07 04:42:33 +01:00
|
|
|
opacity: 0.85,
|
|
|
|
revert: true,
|
2020-01-09 06:35:38 +01:00
|
|
|
start: _this.node.start,
|
|
|
|
stop: _this.node.stop,
|
2020-01-23 14:29:56 +01:00
|
|
|
zIndex: 100,
|
2019-11-07 04:42:33 +01:00
|
|
|
});
|
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-09 06:35:38 +01:00
|
|
|
let _this = codiad.filemanager;
|
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;
|
2020-01-09 06:35:38 +01:00
|
|
|
let parent = node.parent();
|
|
|
|
let ul = parent.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-09 06:35:38 +01:00
|
|
|
entry.append( span, link );
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
if( v.type == "file" ) {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-01-07 05:53:35 +01:00
|
|
|
if( filters.type == "directory" ) {
|
2019-11-07 04:42:33 +01:00
|
|
|
|
|
|
|
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 05:53:35 +01:00
|
|
|
if( filters.type == "file" ) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
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";
|
2020-01-09 06:35:38 +01:00
|
|
|
console.log( "loading children", v.path, link, v.children, filters, callbacks, link.parent() );
|
2020-02-07 19:01:04 +01:00
|
|
|
link.addClass( "open" );
|
2020-01-07 03:35:50 +01:00
|
|
|
_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
|
|
|
}
|
2020-01-07 05:53:35 +01:00
|
|
|
|
|
|
|
name = v.basename;
|
|
|
|
type = 'directory';
|
2019-10-25 04:27:51 +02:00
|
|
|
}
|
|
|
|
|
2020-02-03 20:25:32 +01:00
|
|
|
//console.log( v.path, v.type );
|
2020-01-07 05:53:35 +01:00
|
|
|
|
|
|
|
span.addClass( node_class );
|
2019-10-25 04:27:51 +02:00
|
|
|
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 );
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
2020-01-07 05:53:35 +01:00
|
|
|
container.insertAfter( node );
|
2020-01-07 03:35:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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' ) ) {
|
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
_this.toggle_directory( $( this ) );
|
2019-09-23 03:35:26 +02:00
|
|
|
} else {
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2020-01-07 05:53:35 +01:00
|
|
|
_this.open_file( $( 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' ) {
|
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
_this.toggle_directory( $( this ).parent().children( "a" ) );
|
2019-11-07 04:42:33 +01:00
|
|
|
} else {
|
|
|
|
|
2020-01-24 17:03:03 +01:00
|
|
|
_this.open_file( $( this ).parent().children( "a" ).attr( 'data-path' ) );
|
2019-11-07 04:42:33 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.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' ) ) {
|
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
_this.toggle_directory( $( this ) );
|
2019-09-23 03:35:26 +02:00
|
|
|
} else {
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2020-01-07 05:53:35 +01:00
|
|
|
_this.open_file( $( 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 + '"]' );
|
2020-01-07 05:53:35 +01:00
|
|
|
let ext = _this.get_extension( path );
|
2020-01-23 14:29:56 +01:00
|
|
|
let preview = [];
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-01-23 14:29:56 +01:00
|
|
|
$.each( _this.file_preview_list, function( id, value ) {
|
|
|
|
|
|
|
|
preview.concat( value );
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log( ext, preview );
|
|
|
|
|
|
|
|
if( $.inArray( ext.toLowerCase(), preview ) < 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-23 14:29:56 +01:00
|
|
|
let download = [];
|
|
|
|
download.concat( files );
|
|
|
|
|
|
|
|
if( $.inArray( ext.toLowerCase(), download ) < 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-22 16:14:01 +01:00
|
|
|
_this.open_in_modal( 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-09 06:35:38 +01:00
|
|
|
open_file_selector: function( path, filters = {}, limit = 1, callbacks ) {
|
|
|
|
|
|
|
|
let _this = this;
|
|
|
|
return new Promise( function( resolve, reject ) {
|
|
|
|
|
|
|
|
codiad.modal.load(
|
|
|
|
300,
|
|
|
|
_this.dialog,
|
|
|
|
{
|
|
|
|
action: 'selector',
|
2020-01-22 16:14:01 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
.then( async function( container ) {
|
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
2020-01-29 06:07:00 +01:00
|
|
|
let div = null;
|
2020-01-22 16:14:01 +01:00
|
|
|
let select = $( '<button class="btn-left">Select</button>' );
|
|
|
|
let cancel = $( '<button class="btn-right">Cancel</button>' );
|
|
|
|
|
|
|
|
if( ! path ) {
|
2020-01-09 06:35:38 +01:00
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
path = codiad.project.getCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Object.keys( filters ).length == 0 ) {
|
2020-01-09 06:35:38 +01:00
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
filters = {
|
2020-01-09 06:35:38 +01:00
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
type: 'directory',
|
2020-01-09 06:35:38 +01:00
|
|
|
}
|
2020-01-22 16:14:01 +01:00
|
|
|
}
|
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
div = $( '#file-manager a[data-path="' + path + '"]' ).parent().parent().parent().clone();
|
|
|
|
let node = $( div ).find( 'a[data-path="' + path + '"]' );
|
2020-01-22 16:14:01 +01:00
|
|
|
|
2020-02-03 20:25:32 +01:00
|
|
|
console.log( div, node );
|
|
|
|
|
|
|
|
node.off();
|
|
|
|
node.children().off();
|
|
|
|
|
|
|
|
_this.selector_listeners( div, limit, filters, callbacks );
|
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
let result = await _this.index(
|
|
|
|
path,
|
|
|
|
false,
|
2020-01-29 06:07:00 +01:00
|
|
|
node,
|
2020-01-22 16:14:01 +01:00
|
|
|
filters,
|
2020-01-29 06:07:00 +01:00
|
|
|
callbacks,
|
2020-01-22 16:14:01 +01:00
|
|
|
);
|
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
console.log( result );
|
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
container.html( div );
|
|
|
|
container.append( select );
|
|
|
|
container.append( cancel );
|
|
|
|
|
|
|
|
select.on( 'click', function( e ) {
|
2020-01-09 06:35:38 +01:00
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
codiad.modal.unload();
|
|
|
|
resolve( _this.selected );
|
|
|
|
});
|
|
|
|
cancel.on( 'click', function( e ) {
|
2020-01-09 06:35:38 +01:00
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
codiad.modal.unload();
|
|
|
|
reject({
|
|
|
|
status: "error",
|
|
|
|
message: "User canceled action."
|
2020-01-09 06:35:38 +01:00
|
|
|
});
|
2020-01-22 16:14:01 +01:00
|
|
|
});
|
|
|
|
})
|
2020-01-29 06:07:00 +01:00
|
|
|
.catch( reject );
|
2020-01-22 16:14:01 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
open_in_modal: function( path ) {
|
|
|
|
|
|
|
|
let type = "";
|
|
|
|
let ext = this.getExtension( path ).toLowerCase();
|
|
|
|
|
2020-01-23 14:29:56 +01:00
|
|
|
if( this.file_preview_list.images.includes( ext ) ) {
|
2020-01-22 16:14:01 +01:00
|
|
|
|
|
|
|
type = 'music_preview';
|
2020-01-23 14:29:56 +01:00
|
|
|
} else if( this.file_preview_list.images.includes( ext ) ) {
|
2020-01-22 16:14:01 +01:00
|
|
|
|
|
|
|
type = 'preview';
|
|
|
|
}
|
|
|
|
|
|
|
|
codiad.modal.load( 250, this.dialog, {
|
|
|
|
action: type,
|
|
|
|
path: path
|
2020-01-09 06:35:38 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
open_rename: function( path ) {
|
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
let shortName = this.get_short_name( path );
|
|
|
|
let type = this.getType( path );
|
|
|
|
|
|
|
|
codiad.modal.load( 250, this.dialog, {
|
|
|
|
action: 'rename',
|
|
|
|
path: path,
|
|
|
|
short_name: shortName,
|
|
|
|
type: type
|
2020-01-22 16:14:01 +01:00
|
|
|
})
|
|
|
|
.then( function( content ) {
|
2020-01-09 06:35:38 +01:00
|
|
|
|
|
|
|
$( content ).find( 'form' )
|
|
|
|
.on( 'submit', function( e ) {
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
let new_name = $( '#modal-content form input[name="object_name"]' ).val();
|
|
|
|
let arr = path.split( '/' );
|
|
|
|
let temp = new Array();
|
|
|
|
for( i = 0; i < arr.length - 1; i++ ) {
|
|
|
|
temp.push( arr[i] )
|
|
|
|
}
|
|
|
|
let new_path = temp.join( '/' ) + '/' + new_name;
|
|
|
|
_this.rename_node( path, new_path );
|
|
|
|
codiad.modal.unload();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
paste_node: function( path ) {
|
|
|
|
|
|
|
|
let _this = this;
|
2020-01-24 17:03:03 +01:00
|
|
|
let replace = false;
|
|
|
|
let clipboard = this.clipboard;
|
|
|
|
console.log( path, clipboard )
|
2020-01-22 16:14:01 +01:00
|
|
|
|
2020-01-24 17:03:03 +01:00
|
|
|
if( clipboard == '' ) {
|
2020-01-22 16:14:01 +01:00
|
|
|
|
|
|
|
codiad.message.error( i18n( 'Nothing in Your Clipboard' ) );
|
2020-01-24 17:03:03 +01:00
|
|
|
} else if( path == clipboard ) {
|
2020-01-22 16:14:01 +01:00
|
|
|
|
|
|
|
codiad.message.error( i18n( 'Cannot Paste Directory Into Itself' ) );
|
|
|
|
} else {
|
|
|
|
|
2020-01-24 17:03:03 +01:00
|
|
|
let short_name = _this.get_short_name( clipboard );
|
2020-01-22 16:14:01 +01:00
|
|
|
let new_path = path + '/' + short_name
|
2020-01-24 17:03:03 +01:00
|
|
|
let existing_node = $( '#file-manager a[data-path="' + new_path + '"]' );
|
2020-01-22 16:14:01 +01:00
|
|
|
|
2020-01-24 17:03:03 +01:00
|
|
|
console.log( existing_node );
|
|
|
|
|
|
|
|
if( existing_node.length ) {
|
2020-01-22 16:14:01 +01:00
|
|
|
|
2020-01-24 17:03:03 +01:00
|
|
|
// Confirm replace?
|
2020-01-22 16:14:01 +01:00
|
|
|
codiad.modal.load( 400, this.dialog, {
|
2020-01-24 17:03:03 +01:00
|
|
|
action: 'replace',
|
2020-01-22 16:14:01 +01:00
|
|
|
path: new_path
|
2020-01-24 17:03:03 +01:00
|
|
|
})
|
|
|
|
.then( function( container ) {
|
2020-01-22 16:14:01 +01:00
|
|
|
|
2020-01-24 17:03:03 +01:00
|
|
|
$( '#modal-content form' )
|
|
|
|
.on( 'submit', function( e ) {
|
2020-01-22 16:14:01 +01:00
|
|
|
|
2020-01-24 17:03:03 +01:00
|
|
|
e.preventDefault();
|
|
|
|
codiad.modal.unload();
|
|
|
|
|
|
|
|
if( $( '#modal-content form select[name="or_action"]' ).val() == 1 ) {
|
2020-01-22 16:14:01 +01:00
|
|
|
|
2020-01-24 17:03:03 +01:00
|
|
|
replace = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: _this.controller + '?action=copy',
|
|
|
|
data: {
|
2020-01-22 16:14:01 +01:00
|
|
|
|
2020-01-24 17:03:03 +01:00
|
|
|
path: clipboard,
|
|
|
|
destination: new_path,
|
|
|
|
replace: replace,
|
|
|
|
},
|
|
|
|
success: async function( data ) {
|
2020-01-22 16:14:01 +01:00
|
|
|
|
|
|
|
|
2020-01-24 17:03:03 +01:00
|
|
|
amplify.publish( 'filemanager.onPaste', {
|
|
|
|
path: path,
|
|
|
|
shortName: shortName,
|
|
|
|
duplicate: duplicate
|
|
|
|
});
|
|
|
|
|
|
|
|
let dir = await _this.is_dir( new_path );
|
|
|
|
|
|
|
|
if( dir ) {
|
|
|
|
|
|
|
|
_this.rescan( new_path );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
_this.rescan( _this.get_parent( new_path ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( path !== new_path ) {
|
|
|
|
|
|
|
|
_this.rescan( path );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function( data ) {
|
|
|
|
|
|
|
|
console.log( data );
|
|
|
|
},
|
|
|
|
});
|
2020-01-22 16:14:01 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: _this.controller + '?action=copy',
|
|
|
|
data: {
|
|
|
|
|
2020-01-24 17:03:03 +01:00
|
|
|
path: clipboard,
|
2020-01-22 16:14:01 +01:00
|
|
|
destination: new_path,
|
2020-01-24 17:03:03 +01:00
|
|
|
replace: replace,
|
2020-01-22 16:14:01 +01:00
|
|
|
},
|
|
|
|
success: async function( data ) {
|
|
|
|
|
|
|
|
|
|
|
|
amplify.publish( 'filemanager.onPaste', {
|
|
|
|
path: path,
|
|
|
|
shortName: shortName,
|
|
|
|
duplicate: duplicate
|
|
|
|
});
|
|
|
|
|
|
|
|
let dir = await _this.is_dir( new_path );
|
|
|
|
|
|
|
|
if( dir ) {
|
|
|
|
|
|
|
|
_this.rescan( new_path );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
_this.rescan( _this.get_parent( new_path ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( path !== new_path ) {
|
|
|
|
|
|
|
|
_this.rescan( path );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function( data ) {
|
|
|
|
|
|
|
|
console.log( data );
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
refresh_preview: function( event ) {
|
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When reloading after every change, we encounter performance issues
|
|
|
|
* in the editor. Therefore, we implement the same logic as the
|
|
|
|
* auto_save module where we only reload after the user has finished
|
|
|
|
* changing their document.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if( _this.refresh_interval !== null ) {
|
|
|
|
|
|
|
|
clearTimeout( _this.refresh_interval );
|
|
|
|
_this.refresh_interval = null;
|
|
|
|
}
|
|
|
|
_this.refresh_interval = setTimeout( function() {
|
|
|
|
|
2020-01-24 17:03:03 +01:00
|
|
|
if( _this.preview_window == null ) {
|
2020-01-22 16:14:01 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
2020-01-24 17:03:03 +01:00
|
|
|
if( ( typeof _this.preview_window.location.reload ) == "undefined" ) {
|
2020-01-22 16:14:01 +01:00
|
|
|
|
2020-01-24 17:03:03 +01:00
|
|
|
_this.preview_window = null;
|
|
|
|
codiad.editor.getActive().removeEventListener( "change", _this.refresh_preview );
|
2020-01-22 16:14:01 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-01-24 17:03:03 +01:00
|
|
|
_this.preview_window.location.reload( true );
|
2020-01-22 16:14:01 +01:00
|
|
|
} catch ( e ) {
|
|
|
|
|
|
|
|
console.log( e );
|
|
|
|
codiad.message.error( 'Please close your previously opened preview window.' );
|
2020-01-24 17:03:03 +01:00
|
|
|
_this.preview_window = null;
|
|
|
|
codiad.editor.getActive().removeEventListener( "change", _this.refresh_preview );
|
2020-01-22 16:14:01 +01:00
|
|
|
}
|
2020-01-24 17:03:03 +01:00
|
|
|
}, 1000 );
|
2020-01-22 16:14:01 +01:00
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
rename: function( path, new_path ) {
|
2019-09-23 03:35:26 +02:00
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
let _this = codiad.filemanager;
|
|
|
|
|
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,
|
2020-01-09 06:35:38 +01:00
|
|
|
destination: new_path
|
2020-01-07 03:35:50 +01:00
|
|
|
},
|
|
|
|
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-09 06:35:38 +01:00
|
|
|
rename_node: async function( path, new_path ) {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
let short_name = this.get_short_name( path );
|
2019-10-29 14:37:19 +01:00
|
|
|
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();
|
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
let arr = path.split( '/' );
|
|
|
|
let message = "Successfully Renamed."
|
|
|
|
let new_parent = new_path.split( '/' );
|
|
|
|
let parent = path.split( '/' );
|
|
|
|
let temp = [];
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
parent.pop();
|
|
|
|
new_parent.pop();
|
|
|
|
|
|
|
|
for( i = 0; i < arr.length - 1; i++ ) {
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
temp.push( arr[i] )
|
|
|
|
}
|
|
|
|
|
|
|
|
let result = codiad.jsend.parse( await _this.rename( path, new_path ) );
|
|
|
|
|
|
|
|
if( result != 'error' ) {
|
2019-11-24 04:56:19 +01:00
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
if( type !== undefined ) {
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
let node = $( '#file-manager a[data-path="' + path + '"]' );
|
|
|
|
|
|
|
|
node.attr( 'data-path', new_path ).html( new_path.split( "/" ).pop() );
|
|
|
|
message = type.charAt( 0 ).toUpperCase() + type.slice( 1 ) + ' Renamed'
|
|
|
|
codiad.message.success( message );
|
|
|
|
|
|
|
|
// Change icons for file
|
|
|
|
let current_class = 'ext-' + _this.get_extension( path );
|
|
|
|
let new_class = 'ext-' + _this.get_extension( new_path );
|
|
|
|
|
|
|
|
$( '#file-manager a[data-path="' + new_path + '"]' )
|
|
|
|
.removeClass( current_class )
|
|
|
|
.addClass( new_class );
|
|
|
|
codiad.active.rename( path, new_path );
|
|
|
|
|
|
|
|
codiad.filemanager.rescan( parent.join( '/' ) );
|
|
|
|
|
|
|
|
if( parent !== new_parent ) {
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
console.log( parent, new_parent );
|
|
|
|
codiad.filemanager.rescan( new_parent.join( '/' ) );
|
2020-01-07 03:35:50 +01:00
|
|
|
}
|
2020-01-09 06:35:38 +01:00
|
|
|
|
|
|
|
/* Notify listeners. */
|
|
|
|
amplify.publish( 'filemanager.onRename', {
|
|
|
|
path: path,
|
|
|
|
newPath: new_path,
|
|
|
|
project: project
|
|
|
|
});
|
2019-11-07 04:42:33 +01:00
|
|
|
}
|
2020-01-09 06:35:38 +01:00
|
|
|
}
|
2019-11-07 04:42:33 +01:00
|
|
|
},
|
|
|
|
|
2020-01-24 17:03:03 +01:00
|
|
|
preview: function( path ) {
|
2019-11-07 04:42:33 +01:00
|
|
|
|
2020-01-29 00:14:01 +01:00
|
|
|
let _this = this;
|
2019-11-24 04:56:19 +01:00
|
|
|
|
2020-01-29 00:14:01 +01:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: _this.controller + '?action=preview&path=' + encodeURIComponent( path ),
|
|
|
|
success: function( data ) {
|
|
|
|
|
|
|
|
console.log( data );
|
|
|
|
let r = JSON.parse( data );
|
|
|
|
|
|
|
|
if( r.status === "success" ) {
|
|
|
|
|
|
|
|
_this.preview = window.open( r.data, '_newtab' );
|
|
|
|
|
|
|
|
let editor = codiad.editor.getActive();
|
|
|
|
|
|
|
|
if( _this.auto_reload && editor !== null ) {
|
|
|
|
|
|
|
|
editor.addEventListener( "change", _this.refresh_preview );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
codiad.message.error( i18n( r.message ) );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function( data ) {
|
|
|
|
|
|
|
|
codiad.message.error( i18n( r.message ) );
|
|
|
|
},
|
|
|
|
});
|
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;
|
2020-02-03 20:25:32 +01:00
|
|
|
return _this.index( path, true );
|
2019-11-07 04:42:33 +01:00
|
|
|
},
|
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
save_file: function( path, data, display_messages = true ) {
|
|
|
|
|
|
|
|
return new Promise( function( resolve, reject ) {
|
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: _this.controller + '?action=modify',
|
|
|
|
data: {
|
|
|
|
|
|
|
|
path: path,
|
|
|
|
data: JSON.stringify( data ),
|
|
|
|
},
|
|
|
|
success: function( data ) {
|
|
|
|
|
|
|
|
console.log( data );
|
|
|
|
let r = JSON.parse( data );
|
|
|
|
|
|
|
|
if( r.status === "success" ) {
|
|
|
|
|
|
|
|
if( display_messages === true ) {
|
|
|
|
|
|
|
|
codiad.message.success( i18n( 'File saved' ) );
|
|
|
|
}
|
2020-01-23 14:29:56 +01:00
|
|
|
resolve( r );
|
2020-01-22 16:14:01 +01:00
|
|
|
} else if( r.message == 'Client is out of sync' ) {
|
|
|
|
|
|
|
|
let reload = confirm(
|
|
|
|
"Server has a more updated copy of the file. Would " +
|
|
|
|
"you like to refresh the contents ? Pressing no will " +
|
|
|
|
"cause your changes to override the server's copy upon " +
|
|
|
|
"next save."
|
|
|
|
);
|
|
|
|
if( reload ) {
|
|
|
|
|
|
|
|
codiad.active.close( path );
|
|
|
|
codiad.active.removeDraft( path );
|
|
|
|
_this.openFile( path );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
let session = codiad.editor.getActive().getSession();
|
|
|
|
session.serverMTime = null;
|
|
|
|
session.untainted = null;
|
|
|
|
}
|
2020-01-23 14:29:56 +01:00
|
|
|
resolve( r );
|
2020-01-22 16:14:01 +01:00
|
|
|
} else {
|
|
|
|
|
|
|
|
codiad.message.error( i18n( r.message ) );
|
|
|
|
reject( data );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function( data ) {
|
|
|
|
|
|
|
|
codiad.message.error( i18n( 'File could not be saved' ) );
|
|
|
|
reject( data );
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2019-11-15 05:16:07 +01:00
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
search: async function( path ) {
|
|
|
|
|
|
|
|
let _this = this;
|
|
|
|
let container = await codiad.modal.load( 500, this.dialog, {
|
|
|
|
action: 'search',
|
|
|
|
path: path
|
|
|
|
});
|
|
|
|
codiad.modal.hideOverlay();
|
|
|
|
$( '#modal-content form' )
|
|
|
|
.on( 'submit', function( e ) {
|
|
|
|
$( '#filemanager-search-processing' ).show();
|
|
|
|
e.preventDefault();
|
|
|
|
searchString = $( '#modal-content form input[name="search_string"]' ).val();
|
|
|
|
fileExtensions = $( '#modal-content form input[name="search_file_type"]' ).val();
|
|
|
|
searchFileType = $.trim( fileExtensions );
|
|
|
|
if( searchFileType != '' ) {
|
|
|
|
//season the string to use in find command
|
|
|
|
searchFileType = "\\(" + searchFileType.replace( /\s+/g, "\\|" ) + "\\)";
|
|
|
|
}
|
|
|
|
searchType = $( '#modal-content form select[name="search_type"]' )
|
|
|
|
.val();
|
|
|
|
let options = {
|
|
|
|
filetype: fileExtensions,
|
|
|
|
};
|
|
|
|
$.post( _this.controller + '?action=search', {
|
|
|
|
path: path,
|
|
|
|
query: searchString,
|
|
|
|
options: JSON.stringify( options )
|
|
|
|
}, function( data ) {
|
|
|
|
|
|
|
|
let searchResponse = codiad.jsend.parse( data );
|
|
|
|
let results = '';
|
|
|
|
|
|
|
|
console.log( data );
|
|
|
|
console.log( searchResponse );
|
|
|
|
|
|
|
|
if( searchResponse != 'error' ) {
|
|
|
|
$.each( searchResponse.index, function( key, val ) {
|
|
|
|
// Cleanup file format
|
|
|
|
if( val['file'].substr( -1 ) == '/' ) {
|
|
|
|
val['file'] = val['file'].substr( 0, str.length - 1 );
|
|
|
|
}
|
|
|
|
val['file'] = val['file'].replace( '//', '/' );
|
|
|
|
// Add result
|
|
|
|
results += '<div><a onclick="codiad.filemanager.openFile(\'' + val['result'] + '\');setTimeout( function() { codiad.active.gotoLine(' + val['line'] + '); }, 500);codiad.modal.unload();">Line ' + val['line'] + ': ' + val['file'] + '</a></div>';
|
|
|
|
});
|
|
|
|
$( '#filemanager-search-results' )
|
|
|
|
.slideDown()
|
|
|
|
.html( results );
|
|
|
|
} else {
|
|
|
|
$( '#filemanager-search-results' )
|
|
|
|
.slideUp();
|
|
|
|
}
|
|
|
|
$( '#filemanager-search-processing' )
|
|
|
|
.hide();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
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-29 06:07:00 +01:00
|
|
|
selector_listeners: function( node, limit, filters, callbacks ) {
|
2020-01-09 06:35:38 +01:00
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
|
|
|
|
$( node )
|
|
|
|
.on( 'click', 'a', async function( e ) {
|
|
|
|
|
|
|
|
let i = $( e.target );
|
|
|
|
|
|
|
|
// Select or Expand
|
|
|
|
if( codiad.editor.settings.fileManagerTrigger ) {
|
|
|
|
|
2020-02-03 20:25:32 +01:00
|
|
|
_this.toggle_directory( i, filters, callbacks );
|
2020-01-09 06:35:38 +01:00
|
|
|
} else {
|
|
|
|
|
|
|
|
_this.toggle_select_node( $( e.target ), limit );
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.on( 'click', 'span', async function( e ) {
|
|
|
|
|
|
|
|
let i = $( e.target ).parent().children( 'a' );
|
2020-02-03 20:25:32 +01:00
|
|
|
_this.toggle_directory( i, {type: 'directory'} );
|
2020-01-09 06:35:38 +01:00
|
|
|
})
|
|
|
|
.on( 'dblclick', 'a', async function( e ) {
|
|
|
|
|
|
|
|
let i = $( e.target );
|
|
|
|
|
|
|
|
if( ! codiad.editor.settings.fileManagerTrigger ) {
|
|
|
|
|
2020-02-03 20:25:32 +01:00
|
|
|
_this.toggle_directory( i, {type: 'directory'} );
|
2020-01-09 06:35:38 +01:00
|
|
|
} else {
|
|
|
|
|
2020-02-03 20:25:32 +01:00
|
|
|
_this.toggle_select_node( i, limit );
|
2020-01-09 06:35:38 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.on( 'selectstart', false );
|
|
|
|
},
|
|
|
|
|
2020-01-07 05:53:35 +01:00
|
|
|
set_index: function( path, files, data ) {
|
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
let index = false;
|
|
|
|
let total = ( !!files ) ? files.length : 0;
|
|
|
|
|
|
|
|
for( let i = 0;i < total;i++ ) {
|
|
|
|
|
|
|
|
if( path == files[i].dirname ) {
|
|
|
|
|
|
|
|
files[i] = data;
|
|
|
|
index = files[i];
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if( files[i].children !== undefined ) {
|
|
|
|
|
|
|
|
index = _this.set_index( path, files[i].children, data );
|
|
|
|
|
|
|
|
if( index ) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
},
|
|
|
|
|
2020-01-09 06:35:38 +01:00
|
|
|
toggle_directory: async function( node, filters, callbacks, open ) {
|
2020-01-07 05:53:35 +01:00
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
|
|
|
|
node.addClass( "loading" );
|
2020-01-09 06:35:38 +01:00
|
|
|
let path = node.attr( "data-path" );
|
2020-02-07 19:01:04 +01:00
|
|
|
let type = node.attr( "data-type" );
|
2020-01-07 05:53:35 +01:00
|
|
|
let i = await _this.get_index( path, _this.files );
|
|
|
|
let span = node.parent().children( 'span' );
|
|
|
|
let link = node.parent().children( 'a' );
|
|
|
|
|
|
|
|
console.log( i );
|
|
|
|
|
|
|
|
if( Object.keys( i ).length == 0 ) {
|
|
|
|
|
|
|
|
let result = await _this.index( path );
|
|
|
|
i = {
|
|
|
|
open: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-07 19:01:04 +01:00
|
|
|
if( type == "root" ) {
|
|
|
|
|
|
|
|
console.log( node.parent().children( 'ul' ).find( ".open" ) );
|
|
|
|
|
|
|
|
node.parent().children( 'ul' ).find( ".open" ).each( function( id, n ) {
|
|
|
|
|
|
|
|
console.log( id, n );
|
|
|
|
|
|
|
|
let i = $( n );
|
|
|
|
_this.toggle_directory( i, [], [], true );
|
|
|
|
});
|
|
|
|
|
|
|
|
node.removeClass( "loading" );
|
|
|
|
return;
|
|
|
|
} else if( i.open || open ) {
|
2020-01-07 05:53:35 +01:00
|
|
|
|
|
|
|
node.parent().children( 'ul' )
|
|
|
|
.slideUp( 300, function() {
|
|
|
|
|
|
|
|
$( this ).remove();
|
|
|
|
|
|
|
|
span.removeClass( 'minus' );
|
|
|
|
node.removeClass( 'open' );
|
|
|
|
|
|
|
|
span.addClass( 'plus' );
|
|
|
|
|
|
|
|
if( typeof close_callback == "function" ) {
|
|
|
|
|
|
|
|
close_callback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if( typeof open_callback == "function" ) {
|
|
|
|
|
|
|
|
close_callback( node );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
span.removeClass( 'plus' );
|
|
|
|
|
|
|
|
span.addClass( 'minus' );
|
|
|
|
link.addClass( 'open' );
|
|
|
|
|
|
|
|
_this.index( path );
|
|
|
|
}
|
|
|
|
|
|
|
|
i.open = !i.open
|
|
|
|
_this.set_index( path, _this.files, i );
|
|
|
|
|
|
|
|
console.log( i, await _this.get_index( path, _this.files ) );
|
|
|
|
node.removeClass( "loading" );
|
|
|
|
},
|
|
|
|
|
2020-01-29 06:07:00 +01:00
|
|
|
toggle_select_node: function( node, limit = 0 ) {
|
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
let selected = false;
|
|
|
|
let path = node.attr( 'data-path' );
|
|
|
|
let i = 1;
|
|
|
|
|
|
|
|
for( i = _this.selected.length;i--; ) {
|
|
|
|
|
|
|
|
if( _this.selected[i] == path ) {
|
|
|
|
|
|
|
|
selected = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( limit > 0 && _this.selected.length >= limit ) {
|
|
|
|
|
|
|
|
for( i = _this.selected.length;i--; ) {
|
|
|
|
|
|
|
|
$( `[data-path='${_this.selected[i]}']` ).css( "background", "" );
|
|
|
|
}
|
|
|
|
_this.selected = [];
|
|
|
|
_this.selected.push( path );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if( selected ) {
|
|
|
|
|
|
|
|
_this.selected.splice( i, 1 );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
_this.selected.push( path );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log( path, _this.selected );
|
|
|
|
},
|
|
|
|
|
2020-02-07 19:01:04 +01:00
|
|
|
toggle_uploads: function() {
|
|
|
|
|
|
|
|
let b = $( "#uploads-button" );
|
|
|
|
let c = $( ".uploads-container" );
|
|
|
|
|
|
|
|
if( c.css( "display" ) == "none" ) {
|
|
|
|
|
|
|
|
c.slideDown();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
c.slideUp();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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-29 06:07:00 +01:00
|
|
|
upload: function( file ) {
|
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
let blob_size = 1024*1024*4;
|
|
|
|
let total_size = file.size;
|
|
|
|
let upload_status = null;
|
|
|
|
let total_blobs = 0;
|
|
|
|
let current = 0;
|
|
|
|
let index = 0;
|
|
|
|
|
|
|
|
console.log( file, file.size );
|
|
|
|
|
|
|
|
return new Promise( function( resolve, reject ) {
|
|
|
|
|
|
|
|
if( total_size < blob_size ) {
|
|
|
|
|
|
|
|
blob_size = total_size;
|
2020-01-29 23:19:53 +01:00
|
|
|
total_blobs = 1;
|
2020-01-29 06:07:00 +01:00
|
|
|
} else {
|
|
|
|
|
|
|
|
total_blobs = ( Math.round( ( total_size / blob_size ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log( blob_size, _this.uploads.cache, total_size );
|
|
|
|
|
|
|
|
let timeout = setInterval( function() {
|
|
|
|
|
|
|
|
if( ( index == total_blobs || current == total_size ) && _this.uploads.cache.length == 0 ) {
|
|
|
|
|
|
|
|
_this.upload_stitch( file.path );
|
|
|
|
clearTimeout( timeout );
|
|
|
|
resolve( true );
|
|
|
|
} else if( ( index != total_blobs && current != total_size ) && _this.uploads.cache.length < _this.uploads.max ) {
|
|
|
|
|
|
|
|
console.log( "Adding new blob: ", ( index + 1 ) + "/" + total_blobs, current + blob_size + "/" + total_size );
|
|
|
|
let reader = new FileReader();
|
|
|
|
let blob = file.slice( current, current + blob_size );
|
|
|
|
reader.onload = async function( e ) {
|
|
|
|
|
|
|
|
current = current + blob_size;
|
|
|
|
_this.uploads.cache.push({
|
|
|
|
|
|
|
|
blob: e.target.result,
|
|
|
|
path: file.path,
|
|
|
|
status: "queued",
|
|
|
|
index: index,
|
|
|
|
});
|
|
|
|
index++;
|
|
|
|
_this.upload_clear_cache();
|
|
|
|
}
|
|
|
|
reader.readAsDataURL( blob );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
_this.upload_clear_cache();
|
|
|
|
}
|
|
|
|
}, 100 );
|
|
|
|
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
uploads: {
|
|
|
|
|
|
|
|
cache: [],
|
|
|
|
max: 4,
|
|
|
|
},
|
|
|
|
|
|
|
|
upload_blob: function( blob, path, index, o ) {
|
|
|
|
|
|
|
|
return new Promise( function( resolve, reject ) {
|
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
let form = new FormData();
|
|
|
|
|
|
|
|
form.append( 'path', path );
|
|
|
|
form.append( 'index', index );
|
|
|
|
form.append( 'data', blob );
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: _this.controller + "?action=upload_blob",
|
|
|
|
data: form,
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
success: function( data ) {
|
|
|
|
|
|
|
|
|
|
|
|
console.log( data );
|
|
|
|
let d = JSON.parse( data );
|
|
|
|
|
|
|
|
if( d.status == "success" ) {
|
|
|
|
|
|
|
|
o.status = "success";
|
|
|
|
resolve( data );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
o.status = "error";
|
|
|
|
reject( data );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function( data ) {
|
|
|
|
|
|
|
|
o.status = "error";
|
|
|
|
reject( data );
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
upload_clear_cache: function() {
|
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
for( let i = _this.uploads.cache.length;i--; ) {
|
|
|
|
|
|
|
|
if( _this.uploads.cache[i].status == "success" ) {
|
|
|
|
|
|
|
|
_this.uploads.cache.splice( i, 1 );
|
|
|
|
} else if( _this.uploads.cache[i].status == "error" ) {
|
|
|
|
|
|
|
|
_this.uploads.cache[i].status = "retrying";
|
|
|
|
_this.upload_blob( _this.uploads.cache[i].blob, _this.uploads.cache[i].path, _this.uploads.cache[i].index, _this.uploads.cache[i] );
|
|
|
|
} else if( _this.uploads.cache[i].status == "queued" ) {
|
|
|
|
|
|
|
|
_this.uploads.cache[i].status = "uploading";
|
|
|
|
_this.upload_blob( _this.uploads.cache[i].blob, _this.uploads.cache[i].path, _this.uploads.cache[i].index, _this.uploads.cache[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
upload_load_files: async function( item, path, files = null ) {
|
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
|
|
|
|
if( files === null ) {
|
|
|
|
|
|
|
|
files = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise( function( resolve, reject ) {
|
|
|
|
|
|
|
|
if( item.isFile ) {
|
|
|
|
|
|
|
|
// Get file
|
|
|
|
item.file( function( file ) {
|
|
|
|
|
|
|
|
if( ( `${path}` ).charAt( path.length - 1 ) != "/" ) {
|
|
|
|
|
|
|
|
path += "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
file.path = path + file.name;
|
|
|
|
files.push( file );
|
|
|
|
resolve( files );
|
|
|
|
});
|
|
|
|
} else if( item.isDirectory ) {
|
|
|
|
|
|
|
|
// Get folder contents
|
|
|
|
let dirReader = item.createReader();
|
|
|
|
dirReader.readEntries( async function( entries ) {
|
|
|
|
|
|
|
|
if( ( `${path}` ).charAt( path.length - 1 ) != "/" ) {
|
|
|
|
|
|
|
|
path += "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
let total = entries.length;
|
|
|
|
for( let i = 0;i < total; i++ ) {
|
|
|
|
|
|
|
|
let children = await _this.upload_load_files( entries[i], path + item.name + "/", files );
|
|
|
|
files.concat( children );
|
|
|
|
}
|
|
|
|
resolve( files );
|
|
|
|
}, reject );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
upload_overlay_off: function() {
|
|
|
|
|
|
|
|
$( '.drop-overlay' ).css( 'display', 'none' );
|
|
|
|
},
|
|
|
|
|
|
|
|
upload_overlay_on: function( e ) {
|
|
|
|
|
|
|
|
$( '.drop-overlay' ).css( 'display', 'block' );
|
|
|
|
},
|
|
|
|
|
|
|
|
upload_stitch: function( path ) {
|
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
let form = new FormData();
|
|
|
|
|
|
|
|
form.append( 'path', path );
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: _this.controller + "?action=upload_stitch",
|
|
|
|
data: form,
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
success: function( data ) {
|
|
|
|
|
|
|
|
console.log( data );
|
|
|
|
parent = path.split( '/' );
|
2020-02-03 20:25:32 +01:00
|
|
|
|
|
|
|
parent.pop();
|
2020-01-29 06:07:00 +01:00
|
|
|
parent.pop();
|
|
|
|
|
|
|
|
console.log( path, parent.join( '/' ) );
|
|
|
|
|
|
|
|
_this.rescan( parent.join( '/' ) );
|
|
|
|
},
|
|
|
|
error: function( data ) {
|
|
|
|
|
|
|
|
console.log( data );
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
2019-11-24 04:56:19 +01:00
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
upload_to_node: function( path ) {
|
|
|
|
|
|
|
|
let _this = codiad.filemanager;
|
|
|
|
codiad.modal.load(
|
|
|
|
500,
|
|
|
|
this.dialog, {
|
|
|
|
action: 'upload',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.then( function( container ) {
|
|
|
|
|
|
|
|
let text = $( '<p style="max-width: 40vw;"></p>' );
|
|
|
|
let input = $( '<input type="file" multiple style="display: none;">' );
|
|
|
|
|
|
|
|
text.html( `<h2>Drag and drop files or folders anywhere or click here to upload a file!</h2>` );
|
|
|
|
|
|
|
|
input.on( 'change', function( e ) {
|
|
|
|
|
|
|
|
console.log( e );
|
|
|
|
|
|
|
|
let items = e.target.files;
|
|
|
|
_this.upload( items, path );
|
|
|
|
});
|
|
|
|
text.on( 'click', function( e ) {
|
|
|
|
|
|
|
|
input.click();
|
|
|
|
});
|
|
|
|
|
|
|
|
container.html( '' );
|
|
|
|
container.append( text );
|
|
|
|
container.append( input );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-01-07 03:35:50 +01:00
|
|
|
//Compatibility functions
|
2020-01-22 16:14:01 +01:00
|
|
|
//these may be needed more after updating the new functions to newer standards
|
2020-01-07 03:35:50 +01:00
|
|
|
|
2020-01-22 16:14:01 +01:00
|
|
|
copyNode: function( path ) {return this.copy_node( path )},
|
2020-01-07 05:53:35 +01:00
|
|
|
createNode: function( path, type ) {return this.create_node( path, type )},
|
2020-01-22 16:14:01 +01:00
|
|
|
deleteNode: function( path ) {return this.delete_node( path )},
|
2020-01-09 06:35:38 +01:00
|
|
|
getExtension: function( path ) {return this.get_extension( path )},
|
2020-01-07 05:53:35 +01:00
|
|
|
getShortName: function( path ) {return this.get_short_name( path )},
|
|
|
|
getType: function( path ) {return this.get_type( path )},
|
|
|
|
openFile: function( path ) {return this.open_file( path )},
|
2020-01-22 16:14:01 +01:00
|
|
|
openInBrowser: function( path ) {return this.preview( path )},
|
|
|
|
pasteNode: function( path ) {return this.paste_node( path )},
|
|
|
|
renameNode: function( path ) {return this.rename_node( path )},
|
|
|
|
saveFile: function( path, data, display_messages ) {return this.save_file( path, data, display_messages )},
|
|
|
|
uploadToNode: function( path ) {return this.upload_to_node( path )},
|
2019-05-01 22:21:45 +02:00
|
|
|
};
|
|
|
|
})( this, jQuery );
|