<%@ page language = "java" %>
<%@ page import = "ilog.webui.dhtml.IlxWPort" %>
<%@ page import = "ilog.webui.dhtml.components.IlxWActionHolder" %>
<%@ page import = "gov.vha.edb.rules.web.builder.WebBuilder" %>

<%
// Get the port in the current request.
WebBuilder builder = WebBuilder.getInstance(request);
IlxWPort port = (IlxWPort)request.getAttribute("web.builder.port");
IlxWActionHolder ah = builder.getActionMap().getActionHolder();
%>

<%ah.print(port);%>

<script>

function WebAction(name) {
  this.name = name;
  this.perform = WebAction_perform;
  this.checkPageLoaded = WebAction_checkPageLoaded;
  this.call = WebAction_call;
}

function WebAction_perform(args) {
  if (arguments.length==0) {
    <%=ah.getJSPerformCall(port, "this.name")%>;
  } else if (arguments.length==1) {
    <%=ah.getJSPerformCall(port, "this.name", "arguments[0]")%>;
  } else if (arguments.length==2) {
    <%=ah.getJSPerformCall(port, "this.name", "arguments[0]", "arguments[1]")%>;
  }
}

/**
 * Checks whether the page has been completely loaded.
 * If this is not the case, the action holder's action cannot not be 
 * trigerred, ie the JavaScript code generated by the getJSPerformCall
 * method cannot be executed.
 */
function WebAction_checkPageLoaded() {
  return <%= ah.getJSIsAvailable(port) %>;
}

function WebAction_call(fun) {
  if (this.checkPageLoaded()) {
    fun(this);
  }
}

</script>
