Skip to content

Instantly share code, notes, and snippets.

@gratzc
Last active August 29, 2015 13:56
Show Gist options
  • Save gratzc/8933933 to your computer and use it in GitHub Desktop.
Save gratzc/8933933 to your computer and use it in GitHub Desktop.
<!--- faqs event used to get Question/Answer sets for the grid in our Admin --->
<cffunction name="faqs" returntype="void" output="false" hint="I return the data struct of faqs for the grid">
<cfargument name="event" type="any" required="yes">
<cfargument name="rc" type="any" required="yes">
<cfargument name="prc" type="any" required="yes">
<cfscript>
var offset = ((rc.page-1)*rc.rows);
var sortOrder = rc.sidx & " " & rc.sord;
var qry = variables.FaqService.list(criteria={componentId=rc.componentID},offset=offset,max=rc.rows,sortOrder=sortOrder);
var count = variables.FaqService.count("componentID=#rc.componentID#");
var arCompFaqs = arrayNew(1);
var i = 0;
var totalPages = 0;
var editLink = "";
var deleteLink = "";
var question_condensed = "";
var answer_condensed = "";
//build array for our grid
for (i=1;i lte qry.recordcount;i=i+1) {
editLink = '<a href="javascript:void(0)" onclick="edit(#qry.faqID[i]#)" class="ui-icon ui-icon-document">Edit</a>';
deleteLink = '<a href="#event.buildlink("faqComponent:FaqAdmin.doDeleteFaq")#/FaqID/#qry.faqID[i]#/componentID/#rc.componentID#" onclick="confirmDelete(this.href); event.returnValue=false; return false;" class="ui-icon ui-icon-trash" alt="Remove" title="Remove">Remove</a>';
question_condensed = trim(rereplace(qry.question[i], "(<[^>]*>|#chr(10)#|#chr(13)#)", " ", "all"));
answer_condensed = trim(rereplace(qry.answer[i], "(<[^>]*>|#chr(10)#|#chr(13)#)", " ", "all"));
arCompFaqs[i] = [
qry.faqID[i],
qry.componentID[i],
editLink,
deleteLink,
htmlEditFormat(qry.question[i]),
question_condensed,
htmlEditFormat(qry.answer[i]),
answer_condensed,
qry.faqOrder[i]
];
}
//get the total pages based of the current rows
totalPages = ceiling(count/rc.rows);
//setup grid data struct
rc.gridData = {total=totalPages,page=rc.page,records=count,rows=arCompFaqs};
//return it as json data and the proxy object will convert it to JSON
event.renderData(type="json",data=rc.gridData);
</cfscript>
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment