Javascript API
The Javascript API for TACTIC is a full featured API to access TACTIC functionalities.
There is a simple quick start example to connect and query TACTIC using Javascript. Please review the example first if you haven't done so.
Available methods.
The methods defined in the API that are available will depend on which secuity mode the server is set to. These modes are described in the security modes document.
The main methods for accessing TACTIC from external sources will be through the "get_widget" and the "execute_cmd" methods.
execute_cmd
Execute command will run an arbitraty TACTIC command on the server. This command on the server must be derived from the TACTIC Command class (for both security and interface reasons). The TACTIC server makes this a strict requirement ensuring that only permitted commands may be run on the server.
var class_name = 'test.MyTextCmd':
var kwargs = {
'first_arg': first_value,
'second_arg': second_value,
'third_arg': third_value,
}
// get a handle to the TACTIC server
var server = TACTIC.get();
ret_val server.execute_cmd(class_name, kwargs);
info = ret_val.info;
The ret_val is a dictionary which contains the status of the command execution and an info package which is data returned from the command.
Command key
Many commands require a command key to execute. This is the method server uses to ensure that only particular interface elements can run a command. When the widget is created on the server, it will store a command key. This command key is then used to call the appropriate callback on the server when the client executes a command. Some commands are restricted such that they can only be run with a command key.
var server = TACTIC.get();
// get key from behavior
var key = bvr.kwargs.get("key")
// or get it from the appropriate element
var key = bvr.src_el.getAttribute("key")
var kwargs = {"a": 123};
var ret_val = server.execute_cmd(key, kwargs);
A command key must be set up properly on the server side. This server will make an association between the class and an exeucte key. This ties the execution of the callback intimately with the widget that is created. For more detailed information on how to set up a command key on the server side, refer to API Security
Promises
Many of the TACTIC API functions have an equivalent function that returns a promise instead of a return value from the server. Promises are a great way to introduce clearer asynchrounous execution of methods. Methods that return a promise have a prefix of "p_". Thus p_execute_cmd does the same as execute_cmd except it returns a promise.
var server = TACTIC()
var class_name = "TestCmd";
var kwargs = {
search_key: search_key
}
server.p_execute_cmd(cmd, kwargs)
.then( function(ret_val) {
var info = ret_val.info;
} )
catch( function(e) {
spt.notify.show_message(e);
} );
Python example of a command class
class TestCmd(Command):
def execute(self):
pass