Skip to content

Commit 76414f2

Browse files
author
Blair McKenzie
committed
override ajax response to fix filenames
1 parent 15eeae9 commit 76414f2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

packages/formtools/image.cfc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,43 @@
33
<cfproperty name="ftShowMetadata" type="boolean" default="false" hint="If this is set to false, the file size and dimensions of the current image are not displayed to the user" />
44
<cfproperty name="dbPrecision" type="string" default="640" />
55

6+
<cffunction name="ajax" output="false" returntype="string" hint="Response to ajax requests for this formtool">
7+
<cfargument name="typename" required="true" type="string" hint="The name of the type that this field is part of.">
8+
<cfargument name="stObject" required="true" type="struct" hint="The object of the record that this field is part of.">
9+
<cfargument name="stMetadata" required="true" type="struct" hint="This is the metadata that is either setup as part of the type.cfc or overridden when calling ft:object by using the stMetadata argument.">
10+
<cfargument name="fieldname" required="true" type="string" hint="This is the name that will be used for the form field. It includes the prefix that will be used by ft:processform.">
11+
12+
<!--- NOTE: this function needs to be able to handle non-ajax responses --->
13+
<!--- The main purpose of this override is to fix the result["filename"] value --->
14+
15+
<cfset var result = super.ajax(argumentCollection=arguments) />
16+
<cfset var callback = "" />
17+
<cfset var data = {} />
18+
<cfset var sourcePath = {} />
19+
20+
<!--- Parse data produced by ajax --->
21+
<cfif refind("^([^\(]+)\((.*)\)$", result)>
22+
<cfset callback = rereplace(result, "^([^\(]+)\((.*)\)$", "\1") />
23+
<cfset result = rereplace(result, "^([^\(]+)\((.*)\)$", "\2") />
24+
</cfif>
25+
<cfif isjson(result)>
26+
<cfset data = deserializeJSON(result) />
27+
</cfif>
28+
29+
<cfif isstruct(data) and structKeyExists(data, "value") and len(data.value)>
30+
<cfset sourcePath = application.fc.lib.cloudinary.getSource(data.value) />
31+
<cfset data["filename"] = listfirst(listlast(sourcePath,'/'),"?") />
32+
<cfset result = serializeJSON(data) />
33+
</cfif>
34+
35+
<!--- Re-add callback --->
36+
<cfif len(callback)>
37+
<cfset result = callback & "(" & result & ")" />
38+
</cfif>
39+
40+
<cfreturn result />
41+
</cffunction>
42+
643
<cffunction name="handleFilePost" access="public" output="false" returntype="struct" hint="Handles image post and returns standard formtool result struct">
744
<cfargument name="objectid" type="uuid" required="true" hint="The objectid of the edited object" />
845
<cfargument name="existingfile" type="string" required="true" hint="Current value of property" />

0 commit comments

Comments
 (0)