Project Management-Cats, Control and Conductors
April 13, 2019VS 2 Live Share Plugin
May 14, 2019This is just a quick post showing how to use any of the MXUnit decorators, including the new ORM transaction decorator designed for ColdBox ORM Services, in pure cfscript. It took me a second to get the syntax correct so I thought I would share and keep this for my own reference.
<!--- 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>