SPEL: Register custom webengine OP

Document created by cdtj Champion on Jun 11, 2015Last modified by cdtj Champion on Sep 2, 2015
Version 5Show Document
  • View in full screen mode

Hello,

I wish to resolve how to use custom webengine operations,

actually I make it work but there is still a lot of question,

so I ask community for assistance.

 

 

    How Webengine OPs are used?

 

Webengine can perform various operations like SPEL execute directly from URL without triggering any activities.

Most common operations are:

    - SEARCH

    - UPDATE

    - SHOW_DETAIL

    - DISPLAY_FORM

but there is a lot of "special" operations, all of them could be found in "bopcfg\www", within op_*.cfg files.

 

Basic infromation could be found in op_table.cfg file.

 

 

    How to make custom operation?


    1. Register new Webengine OP:

Create new file and call it op_custom.cfg, locate it in site/mods/www folder.

Add the followed text to recently created file:

#    Z_TEST - new OP; (Uppercase)
#    z_test - SPEL function;
#    MODIFY - factory access type;
#    UPDATE - type of request;
Z_TEST z_test MODIFY UPDATE























Reminder: SPL file with used functions should be located in the same folder as .cfg file.

 

    2. Create link to call your OP

I've used detail_cr form to call my function,

here is code to make button with test function:

var url = cfgCgi +
"?SID=" + cfgSID +
"+FID=" + fid_generator() +
"+OP=Z_TEST" +
"+FACTORY=cr" +
"+PERSID=" + argPersistentID +
"+TEST_VAL=123";
<PDM_MACRO name=button Caption="TEST OP" Func="display_new_page(url, ahdframeset.workframe);" hotkey_name="TEST_OP[P]" ID=TEST_OP>



















Note: I've called my function to background (workframe) page.

 

    3. Create SPL function

Create new file and call it z_test.spl, locate it in site/mods/www (as .cfg file) folder.

Here test code:

z_test(...)
{
  logf(SIGNIFICANT, "argc = '%d'", argc);
  logf(SIGNIFICANT, "event = %s", event());
  int arg0;
  object arg1;
  arg0 = argv[0];
  arg1 = argv[1];
  dump_args(arg1); //
  upd_val(arg1.FACTORY, format("persistent_id = '%s'", arg1.PERSID), 1, 1, "summary", arg1.TEST_VAL);
}


















Note: I've used my upd_val function from this document: SPEL: Object update.

Regular SPEL installation tip:

    a. Copy SPL file from majic folder to folder where your op_*.cfg file is located;

    b. Remove factory (ex: marco:: ) from function name.

 

    4. Useful tips:

- spl and cfg files are not affected by spel_srvr proccess, so you can debug them by killing webengine (pdm_kill webengine);

- use pdm_logstat -n web:locat 1000 to see what dump_args(arg1) returns;

- OP functions returns object but it was NULL in all of my tries.

 

 

    CALLBACK function

 

spel:

z_test(...)
{
  int some_id; // You should pass the same value to next functions
  some_id = argv[0]; // here it is
  object new_obj; // Received object
  new_obj = argv[1];
  new_obj.CALLBACK="alert(myMsg)";
  string new_js; // our callback js code
  new_js = "var myMsg='Hello World!';";
  logf(SIGNIFICANT, "PERSID = %s", new_obj.PERSID);
  logf(SIGNIFICANT, "CALLBACK = %s", new_obj.CALLBACK);
  logf(SIGNIFICANT, "HTMPL = %s", new_obj.HTMPL);
  logf(SIGNIFICANT, format_to_js(new_js)); // You can use format_to_js function to unescape quotes
  send_frame_resp((long)some_id, (object)new_obj, (string)new_js);
}








 

htmpl:

var url = cfgCgi +
"?SID=" + cfgSID +
"+FID=" + fid_generator() +
"+OP=Z_TEST" +
"+FACTORY=cr" +
"+PERSID=" + argPersistentID +
"+POPUP_NAME=" + '$args.KEEP.POPUP_NAME' +
"+KEEP.POPUP_NAME=" + '$args.KEEP.POPUP_NAME' +
"+CALLBACK=test";
<PDM_MACRO name=button Caption="TEST OP" Func="display_new_page(url, ahdframeset.workframe);" hotkey_name="TEST_OP[P]" ID=TEST_OP>








 

Result:

this code loads to workframe frame:

<html><head><script language="JavaScript" src="/CAisd/scripts/window_manager.js"></script><style type="text/css"></style>
<script>
var myMsg='Hello World!';var ahdtop = get_ahdtop(true);
if ( typeof ahdtop == 'object' ) {
  var win = ahdtop.AHD_Windows['USD1435149643020'];
  if ( typeof win == 'object' )  win.alert(myMsg);
}
</script>


</head><body marginwidth="0" marginheight="0"></body></html>







 

 

    What is still unresolved


Each WebEngine Operation manages 2 arguments:

argv[0] - long integer, such as session id or something like it, which should be passed to the next function, if you call it.

argv[1] - object which contains all attributes passed via link, (can be dumped by dump_args(argv[1])).

So If you need to call another method you shall pass 2 args to it, argv[0] that you already got and object with new attributes.

I can't find a way how to create new object, this is my main question.

Sure you can predefine all of attributes in first object and then update them but this causes excess data.

 

 

     Useful examples


Custom WebEngine OP : Who is currently watching object

4 people found this helpful

Attachments

    Outcomes