Sending Code to the Browser
The answer lies in the AddShow method. When we call a server-side method, such as AddShow, it can return code for execution by the browser. In this case, it returns a single line of JavaScript. This code refers to the location property of the Order frame, which contains the URL of the page displayed by that frame. By setting it equal to “Order.csp”, we cause an updated copy of the page to be requested from the Web server.
Note that the line of code is enclosed in
&js < ... >
which tells Caché to send the contents, as JavaScript, to the browser.
Utils.AddShow
ClassMethod AddShow(ShowID As %String)
{
// Use an existing Order object or create a new one
If ($D(%session.Data("Order"))) {
Set ord = %session.Data("Order")
}
Else {
Set ord = ##class(TicketOrder).%New()
Set %session.Data("Order") = ord
}
// Create a new TicketItem object
Set itm = ##class(Cinema.TicketItem).%New()
// Connect to a Show object
Set shw = ##class(Cinema.Show).%OpenId(ShowID)
Set itm.Show = shw
// Connect to the Order object
Set itm.TicketOrder = ord
// Add the cost of this new item to the total
Set ord.Total = ord.Total
+ (itm.AdultTickets * itm.Show.Theater.AdultPrice)
+ (itm.ChildTickets * itm.Show.Theater.ChildPrice)
// Save incomplete order and remember its Id in %session.
Do ord.%Save()
Set %session.Data("Order") = ord.%Id()
// Send javascript back to the browser, causing it to display
// the updated order page
&js<parent.Order.location = "Order.csp">
Quit
}