Reputation: 11
I want to try using scala.js
on a SalesForce
project.
SalesForce automatically injects the Visualforce.remoting.Manager.invokeAction(...)
function to enable querying data and doing dml
.
How can I call this function from scala.js?
Upvotes: 1
Views: 395
Reputation: 2481
You should be able to call any exposed javascript method from scala-js using
scala.scalajs.js.eval(x: String)
Example for calling a bootbox modal:
import scala.scalajs.js.annotation.JSExportTopLevel
import scala.scalajs.js
@JSExportTopLevel("myCallBack")
protected def confirmCallback() = // do stuff
def askAQuestion(): Unit = {
js.eval("bootbox.confirm(\"Your question goes here.\", function(result) { if (result == true) { myCallBack(); }});")
}
Of course for this to work you have to include the javascript libary in your project.
Since this is a quite messy solution, you might consider writing your own facade.
Upvotes: 0
Reputation: 2659
In the crudest sense, you could just invoke it directly from global scope using js.Dynamic
, something like:
js.Dynamic.global.Visualforce.remoting.Manager.invokeAction(...)
That works for a one-off, but if you're going to be working more with this Manager, I'd probably recommend creating a Scala.js facade for the Manager, and assigning the Manager object to that -- it'll probably result in better code in the long run.
Upvotes: 1