Skip to main content
1-Visitor
April 26, 2013
Question

Handling events using ACL and javascript

  • April 26, 2013
  • 1 reply
  • 784 views
Hello experts!!

Does anybody know how can I handle my events using ACL and javascript?
For example, when I call an ACL function since clicking an XUI button,
How can I detect this event inside JavaScript?

Thank you very much for your time and support.

Regards.
Paulette Zorrilla 😃

    1 reply

    18-Opal
    April 26, 2013
    Hi Paulette--

    If you are writing code to handle custom XUI dialogs, my advice would be to stick with either ACL or Javascript, rather than trying to mix them together.

    If you want to go the Javascript route, there are a number of ways to do it. The easiest way (IMO) is to put the Javascript code directly into the XML for the control, something like this:

    <window focus="cancelButton">
    <button id="myButton" label="Click" me&quot;=">
    <script ev:event="DOMActivate" type="text/javascript">
    var control = Application.event.target
    Application.alert("You clicked button " + control.getAttribute("id") + "!");
    </script>
    </button>
    <button id="cancelButton" label="Cancel" type="cancel">
    <script ev:event="DOMActivate" type="text/javascript">
    Application.alert("Never mind!");
    </script>
    </button>
    </window>

    You can also use event handlers defined externally to get the job done. Check the programmer's reference for "Event Handlers" for details on how to define these in Java and Javascript.

    For ACL, there are also a few ways you can do it. You can attach dlgitem callbacks to specific controls in the dialog after creating it using window_create(). See help for dlgitem_add_callback() for details.

    You can also attach a single "notify" callback to the dialog window itself, which would typically use a switch tree to handle all events related to the dialog. That would look something like this:

    <window focus="cancelButton">
    <button id="myButton" label="Click" me&quot;="></button>
    <button id="cancelButton" label="Cancel" type="cancel"></button>
    </window>

    ACL code:

    $xuidoc = doc_open("cbtest.xml");
    $win = window_create("xui", 0x10, $xuidoc);
    window_show($win, 1);

    function notifycb(win, dlgitem, event, data, appdata) {
    # only interested in ITEM_CHANGED event
    if (event != "ITEM_CHANGED") {
    return;
    }

    switch (dlgitem) {
    case 'myButton':
    # click on Test button
    response("You clicked button " . dlgitem . "!");
    break
    case 'cancelButton':
    # Click on cancel button
    response("Never mind!");
    break
    }
    }
    window_add_callback($win, "notify", "notifycb");

    Hope that helps.

    --Clay

    Clay Helberg
    Senior Consultant

    TerraXML
    1380 Forest Park Circle, Suite 100
    Lafayette, CO 80027