I'm working on a customer's existing CSP page. I want to add a button that will make a request back to the server to create a CSV blob, set the content-type to "text/csv" and respond. I've been working in PHP and HTML the last couple of years and that's a no-brainer. In the existing page (that doesn't live in .../csp/...) I blort-out a table of data. That works, yay. I want to add a link to get the same report (from another class because I don't want to disturb the original code too much) as a CSV.
In the PHP world you'd do something like:
<div>
<button name="getCSV" id="getCSV" style="float: right;">Download</button>
</div>
and add a quickie script like
<script type="text/javascript">
$("#getCSV").click(
function() {
window.location.href="somepage.php?startdate="+<?php echo $startDate; ?>+"&enddate="+<?php echo $endDate; ?>
}
);
</script>
Clicking that (somewhat poor example) button would cause a request to the server that would respond with the content type set to 'text/csv' (because I set the content-type in the response header) and that would cause the browser to pop up a dialog box asking whether to run or save the content. Fait accompli.
I'm working on a 2009 system at the moment. I have another "do the same report but respond as text/csv" class that extends %CSP.Page but that isn't living in the namespace's CSP directory. That class lives next to the original report in the same (not-CSP) package. In here I have
ClassMethod OnPreHTTP() As %Boolean [ ServerOnly = 1 ]
{
do %response.setHeader("content-type", "text/csv")
}
and
Parameter CONTENTTYPE = "text/csv";
ClassMethod OnPage() As %Status
{
set startdate=$get(%request.Data("startdate",1))
set sd=$s(startdate>0:$zdh(startdate,8),1:"")
set enddate=$get(%request.Data("enddate",1))
set ed=$s(enddate>0:$zdh(enddate,8),1:"")
//do other COS and MV thingies here
// write, write, write output thingies
Q $$$OK
}
(Don't freak out, Rich -- yes, I'm actually writing a good bit of COS with MV. I can be wrong about "never" <lol>)
Here's the question:
If I make a class that extends %CSP.Page when the request link is built, Cache just blorts out the class code. It doesn't run it. If I leave the class in its original package the CSP server can't find it.
I know I've done a similar thing before and it worked nicely.
Here's the brainfart: How do I make a call to a server-side method and construct a link in the original page (as in the PHP example above) in my starting class and how do I construct the CSP page/responder/class other than the way I have it and where do I put it so the server can find it? All the reports live in a homegrown package called TVM now. Oh yeah, I'd like to pass start date and end date in via the query string. It doesn't have to be that way. If I can just call the server-side method, pass the parms in, and get a browser dialog box out asking me where to save the result, I really don't care how I get there.
I know I'm close but I can't remember how I did this in Caché before.
Thanks,
(A slightly confused and baffled) Bill