Skip to content

Commit

Permalink
regression file uploading manually was not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
lmajano committed Oct 20, 2023
1 parent 8480409 commit 25f14a9
Show file tree
Hide file tree
Showing 5 changed files with 283 additions and 266 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ component extends="cbadmin.handlers.baseHandler" {
// exit handlers
prc.xehFBBrowser = "#prc.fbModEntryPoint#/filelisting";
prc.xehFBDownload = "#prc.fbModEntryPoint#/download";
prc.xehFBUpload = "#prc.fbModEntryPoint#/upload";
prc.xehFBNewFolder = "#prc.fbModEntryPoint#/createfolder";
prc.xehFBRemove = "#prc.fbModEntryPoint#/remove";
prc.xehFBUpload = "#prc.fbModEntryPoint#/upload";
prc.xehFBRename = "#prc.fbModEntryPoint#/rename";

// Detect Widget Mode.
Expand Down Expand Up @@ -115,6 +115,7 @@ component extends="cbadmin.handlers.baseHandler" {

// Exit handlers
prc.xehFBDownload = "#prc.fbModEntryPoint#/download";
prc.xehFBUpload = "#prc.fbModEntryPoint#/upload";

// Store directory roots and web root
prc.fbDirRoot = prc.fbSettings.directoryRoot;
Expand Down Expand Up @@ -379,6 +380,8 @@ component extends="cbadmin.handlers.baseHandler" {
// param values
event.paramValue( "path", "" ).paramValue( "manual", false );

systemoutput( "path: [#rc.path#]", true );

// clean incoming path for destination directory
rc.path = cleanIncomingPath( urlDecode( trim( rc.path ) ) );

Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
<cfscript>
/**
* --------------------------------------------------------------------------
* CODLFUSION HELPER METHODS
* --------------------------------------------------------------------------
*/
function $getBackPath( inPath ){
arguments.inPath = replace( arguments.inPath, "\", "/", "all" );
var backPath = listToArray( arguments.inPath, "/" );
backPath.deleteAt( backPath.len() );
return URLEncodedFormat( backPath.toList( "/" ) );
}
function $getUrlRelativeToPath( required basePath, required filePath, encodeURL=false ){
var URLOut = "";
var strURLOut = "/";
var arrPath = [];
var p = "";
URLOut = replace( replacenocase( arguments.filePath, arguments.basePath, "/", "one" ), "\", "/", "all" );
if ( arguments.encodeURL ){
arrPath=listtoarray( URLOut, "/" );
for( p in arrPath ){
strURLOut = listAppend( strURLOut, replacenocase( urlencodedformat( p ), "%2e", ".", "all" ), "/" );
}
URLOut = strURLOut;
/**
* --------------------------------------------------------------------------
* CODLFUSION HELPER METHODS
* --------------------------------------------------------------------------
*/
function $getBackPath( inPath ){
arguments.inPath = replace( arguments.inPath, "\", "/", "all" );
var backPath = listToArray( arguments.inPath, "/" );
backPath.deleteAt( backPath.len() );
return URLEncodedFormat( backPath.toList( "/" ) );
}
function $getUrlRelativeToPath( required basePath, required filePath, encodeURL=false ){
var URLOut = "";
var strURLOut = "/";
var arrPath = [];
var p = "";
URLOut = replace( replacenocase( arguments.filePath, arguments.basePath, "/", "one" ), "\", "/", "all" );
if ( arguments.encodeURL ){
arrPath=listtoarray( URLOut, "/" );
for( p in arrPath ){
strURLOut = listAppend( strURLOut, replacenocase( urlencodedformat( p ), "%2e", ".", "all" ), "/" );
}
URLOut = replacenocase( URLOut, "//", "", "all" );
return URLOut;
URLOut = strURLOut;
}
function $getURLMediaPath( required fbDirRoot, required filePath ){
var URLOut = replaceNoCase( arguments.filePath, arguments.fbDirRoot, "", "all" );
if( len( URLOut ) ){
// set our drive prefix and trim leading slashes on the path
URLOut = prc.fbSettings.mediaPath & "/" & prc.activeDisk.getName() & ":" & listToArray( URLOut, "/" ).toList( "/" );
}
return URLOut;
URLOut = replacenocase( URLOut, "//", "", "all" );
return URLOut;
}
function $getURLMediaPath( required fbDirRoot, required filePath ){
var URLOut = replaceNoCase( arguments.filePath, arguments.fbDirRoot, "", "all" );
if( len( URLOut ) ){
// set our drive prefix and trim leading slashes on the path
URLOut = prc.fbSettings.mediaPath & "/" & prc.activeDisk.getName() & ":" & listToArray( URLOut, "/" ).toList( "/" );
}
function validQuickView( ext ){
return ( listFindNoCase( "png,jpg,jpeg,bmp,gif", arguments.ext ) ? true : false );
}
function getImageFile( ext ){
switch( arguments.ext ){
case "doc" : case "docx" : case "pages" : { return "word.png"; }
case "ppt" : case "pptx" : case "keynote" : { return "ppt.png"; }
case "xls" : case "xlsx" : case "numbers" : { return "xls.png"; }
case "pdf" : { return "pdf.png"; }
case "png": case "jpg" : case "jpeg" : case "gif" : case "bmp" : { return "Picture.png"; }
case "cfc": case "cfm" : case "cfml" : { return "coldfusion.png"; }
case "html" : case "htm" : case "aspx" : case "asp" : case "php" : case "rb" : case "py" : case "xml" :{ return "code.png"; }
default : return "file.png";
}
return URLOut;
}
function validQuickView( ext ){
return ( listFindNoCase( "png,jpg,jpeg,bmp,gif", arguments.ext ) ? true : false );
}
function getImageFile( ext ){
switch( arguments.ext ){
case "doc" : case "docx" : case "pages" : { return "word.png"; }
case "ppt" : case "pptx" : case "keynote" : { return "ppt.png"; }
case "xls" : case "xlsx" : case "numbers" : { return "xls.png"; }
case "pdf" : { return "pdf.png"; }
case "png": case "jpg" : case "jpeg" : case "gif" : case "bmp" : { return "Picture.png"; }
case "cfc": case "cfm" : case "cfml" : { return "coldfusion.png"; }
case "html" : case "htm" : case "aspx" : case "asp" : case "php" : case "rb" : case "py" : case "xml" :{ return "code.png"; }
default : return "file.png";
}
}
</cfscript>
<cfoutput>
<div class="clear-both">
Expand Down Expand Up @@ -255,6 +255,18 @@

#announce( "fb_postFileListing" )#
</div>
<!--- Hidden upload iframe --->
<iframe name="upload-iframe" id="upload-iframe" style="display: none"></iframe>
<form id="upload-form"
name="upload-form"
enctype="multipart/form-data"
method="POST"
target="upload-iframe"
action="#event.buildLink( prc.xehFBUpload )#"
>
<input type="hidden" name="path" value='#prc.fbSafeCurrentRoot#' />
<input type="hidden" name="manual" value="true" />
</form>
<script>
( () => {
// activate tooltips
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,13 @@ www.coldbox.org | www.luismajano.com | www.ortussolutions.com
</div>

<div class="col-md-12">
<span id="file_uploader_button" class="btn btn-block btn-primary hidden">Upload</span>
<button
type="button"
id="file_uploader_button"
class="btn btn-block btn-primary hidden"
>
Upload
</button>
</div>

</div>
Expand Down Expand Up @@ -311,19 +317,4 @@ www.coldbox.org | www.luismajano.com | www.ortussolutions.com
</div>
</div>
#announce( "fb_postQuickViewBar" )#

<!--- Hidden upload iframe --->
<iframe name="upload-iframe" id="upload-iframe" style="display: none"></iframe>
<form id="upload-form"
name="upload-form"
enctype="multipart/form-data"
method="POST"
target="upload-iframe"
action="#event.buildLink( prc.xehFBUpload )#"
>
<input type="hidden" name="path" value='#prc.fbSafeCurrentRoot#' />
<input type="hidden" name="manual" value="true" />
</form>
<!---Cancel: #rc.cancelCallBack#, Choose: #rc.callBack#
<cfdump var="#flash.getScope()#">--->
</cfoutput>
</cfoutput>
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,22 @@ function fbRename(){
var thisID = $selectedItemID.val();
var target = $( "##"+thisID);
// prompt for new name
bootbox.prompt( { title: '#$r( "jsmessages.newname@fb" )#',
inputType: "text",
value: target.attr( "data-name" ),
callback: function(result){
// do renaming if prompt not empty
if( result != null){
$fileLoaderBar.slideDown();
$.post( '#event.buildLink( prc.xehFBRename )#',
{ name : result, path : target.attr( "data-fullURL" ) },
function( data ){
if( data.errors ){ alert( data.messages ); }
fbRefresh();
}, "json" );
}
}
bootbox.prompt( {
title: '#$r( "jsmessages.newname@fb" )#',
inputType: "text",
value: target.attr( "data-name" ),
callback: function( result ){
// do renaming if prompt not empty
if( result != null){
$fileLoaderBar.slideDown();
$.post( '#event.buildLink( prc.xehFBRename )#',
{ name : result, path : target.attr( "data-fullURL" ) },
function( data ){
if( data.errors ){ alert( data.messages ); }
fbRefresh();
}, "json" );
}
}
});
}
Expand Down Expand Up @@ -308,31 +309,39 @@ fbInit = () => {
}
} );
$( '##file_uploader_button' ).on('click', function(){
$( '##file_uploader_button' ).on( "click", function(){
var iframe = $( '##upload-iframe' );
var form = $( '##upload-form' );
var field = $( '##filewrapper' );
var wrapper = $( '##manual_upload_wrapper' );
var thisButton = $( this );
// UI prep
thisButton.prop( "disabled", true );
wrapper.append( '<p id="upload_message"><i class="fa fa-spinner fa-spin fa-2x fa-fw"></i> Uploading your file...</p>' );
// move to target form
field.appendTo( form );
field.hide();
field.clone().appendTo( form ).hide();
// submit the form; it's target is the iframe, so AJAX-ish upload style
form.submit();
fbRefresh();
// handle load method of iframe
iframe.load(function(){
iframe.on( "load", function(){
// try to get JSON response from server in textfield
var results = $.parseJSON( iframe.contents().text() );
if( !results.errors ) {
adminNotifier( "info", results.messages );
thisButton.prop( "disabled", false );
$( "##upload_message" ).remove();
$( "##uploadBar" ).slideToggle();
fbRefresh();
} else {
adminNotifier( "error", results.messages );
wrapper.append( "<div class='alert alert-danger'>" + results.messages + "</div>" );
$( '##upload_message' ).remove();
field.prependTo( wrapper );
field.show();
field.prependTo( wrapper ).show();
}
$( "##filewrapper" ).fileinput( "reset" );
} );
} );
Expand Down Expand Up @@ -371,6 +380,8 @@ fbInit = () => {
$.data( file ).addClass( 'done' );
if( response.ERRORS ){
alert( response.MESSAGES );
} else {
adminNotifier( "info", "File Uploaded!" );
}
fbRefresh();
},
Expand Down
Loading

0 comments on commit 25f14a9

Please sign in to comment.