I am making a filter for a dashboard page with a bunch of charts being fed from an ajax call to my database and making a json struct out of it. I am getting a little lost with the filter because basically every field is optional. Right now I am submitting the from with jquery and formvalidator.io. Which sends the from values to a function that originally drew my charts. The place I am getting lost at is in my coldfusion handeler that passes the data to a coldfusion function. How do I pass a dynamic number of arguments?
Code:
Submit form with jquery:
$('#overviewFilter').formValidation({
framework: 'bootstrap4'
}).on("success.form.fv", function(e) {
// Prevent form submission
e.preventDefault();
projectOverview();
});
Json part of the projectOverview function. I have the serializeArray() bit in there but I was just experimenting that might be way off base.
function projectOverview() {
var formString = $('#overview_filter').serializeArray();
$.getJSON('/a_assets/ajax/a_cms.cfm',{cms_action:'task_complete_history',form_data:formString}, function (data) {
//charts
});
Coldfusion Handeler code. I have the #url# parameter in the function because I was experimenting.
<cfif structKeyExists(url,"cms_action") and url.cms_action eq 'task_complete_history'>
<cfobject name="cms" component="a_assets.cfc.cms">
<cfset TaskHistoryNewComplete = cms.fnTaskHistoryNewComplete(#url#)>
<cfoutput>#TaskHistoryNewComplete#</cfoutput>
</cfif>
Coldfusion CFC. I have the one formData argument for now. Each call to a function is a query that needs the values I am looking for to filter the charts.
<cffunction name="fnTaskHistoryNewComplete" returntype="any" output="false">
<cfargument name="formData" required="false">
<cfset mydata = []>
<cfset mydatatemp = structNew()>
<cfset progressObj = []>
<cfset TaskIntake = fnTaskIntake()>
<cfloop query="TaskIntake">
<cfset mydatatemp2 = structNew()>
<cfset mydatatemp2['Month'] = Month>
<cfset mydatatemp2['Completed'] = Completed>
<cfset mydatatemp2['Opened'] = Opened>
<cfset mydatatemp2['Late'] = Late>
<cfset arrayAppend(progressObj, mydatatemp2)>
</cfloop>
<cfset mydatatemp['progress'] = progressObj>
<cfset userObj = []>
<cfset TaskUserIntake = fnTaskUserIntake()>
<cfloop query="TaskUserIntake">
<cfset mydatatemp2 = structNew()>
<cfset mydatatemp2['UserId'] = UserRcId>
<cfset mydatatemp2['Fname'] = Fname>
<cfset mydatatemp2['Lname'] = Lname>
<cfset mydatatemp2['Assigned'] = TaskCount>
<cfset arrayAppend(userObj,mydatatemp2)>
</cfloop>
<cfset mydatatemp['users'] = userObj>
<cfset typeObj = []>
<cfset TaskTypeIntake = fnTaskTypeIntake()>
<cfloop query="TaskTypeIntake">
<cfset mydatatemp2 = structNew()>
<cfset mydatatemp2['TypeId'] = NFTypeRcId>
<cfset mydatatemp2['Name'] = NFTDescription>
<cfset mydatatemp2['TypeCount'] = TaskCount>
<cfset arrayAppend(typeObj,mydatatemp2)>
</cfloop>
<cfset mydatatemp['types'] = typeObj>
<cfset tagObj = []>
<cfset TaskTagIntake = fnTaskTagIntake()>
<cfloop query="TaskTagIntake">
<cfset mydatatemp2 = structNew()>
<cfset mydatatemp2['TagId'] = TagRcId>
<cfset mydatatemp2['Name'] = Name>
<cfset mydatatemp2['TagCount'] = TaskCount>
<cfset arrayAppend(tagObj,mydatatemp2)>
</cfloop>
<cfset mydatatemp['tags'] = tagObj>
<cfset gameObj = []>
<cfset TaskGameIntake = fnTaskGameIntake()>
<cfloop query="TaskGameIntake">
<cfset mydatatemp2 = structNew()>
<cfset mydatatemp2['GameId'] = GameRcId>
<cfset mydatatemp2['Name'] = GameName>
<cfset mydatatemp2['GameCount'] = TaskCount>
<cfset arrayAppend(gameObj,mydatatemp2)>
</cfloop>
<cfset mydatatemp['games'] = gameObj>
<cfset platformObj = []>
<cfset TaskPlatformIntake = fnTaskPlatformIntake()>
<cfloop query="TaskPlatformIntake">
<cfset mydatatemp2 = structNew()>
<cfset mydatatemp2['PlatformId'] = PlatformRcId>
<cfset mydatatemp2['Name'] = Name>
<cfset mydatatemp2['PlatformCount'] = TaskCount>
<cfset arrayAppend(platformObj,mydatatemp2)>
</cfloop>
<cfset mydatatemp['platforms'] = platformObj>
<cfset genreObj = []>
<cfset TaskGenreIntake = fnTaskGenreIntake()>
<cfloop query="TaskGenreIntake">
<cfset mydatatemp2 = structNew()>
<cfset mydatatemp2['GenreId'] = GenreRcId>
<cfset mydatatemp2['Name'] = Name>
<cfset mydatatemp2['GenreCount'] = TaskCount>
<cfset arrayAppend(genreObj,mydatatemp2)>
</cfloop>
<cfset mydatatemp['genres'] = genreObj>
<cfset arrayAppend(mydata,mydatatemp)>
<cfset data = structNew()>
<cfset data['data'] = mydata>
<cfset TaskHistoryNewComplete = serializeJson(mydata)>
<cfreturn TaskHistoryNewComplete>
</cffunction>
I am sure I have done this before but I can not remember for the life of me how I did it.