webCOMAND

webcomand.js

JavaScript methods used to build webCOMAND apps.

Example

<script src="https://<account>.webcomand.com/com_webcomand/js/webcomand.js"></script>
<script>
    webcomand.init({});
    webcomand.add_panel({}); 
    webcomand.post("/package/controller", {}, "Loading...", function(response){
        webcomand.alert("note", "Response", JSON.stringify(response.JSON));
    });
</script>
</body>
</html>

Methods

post

In it's simplest form, the post method is used to post an AJAX request.  However, the response can contain multiple responses for different components that will be automatically delegated to the corresponding components once the response is received.  This packs multiple responses into a single AJAX request, reducing the number of requests and responses needed to keep multiple components up to date based on a single request.

Prototype

wc.post( object settings )

Parameters

  • settings - An object with the following optional properties:
    • url - The URL to post the request to.
    • data - A JavaScript/JSON object containing the data to post.
    • msg - A message to display under a spinner animation while the request is in progress.  If not provided, no spinner will display.
    • callback - A callback that will be fired once the response is received.  It contains a single response parameter, which is an object with the following properties:
      • JSON - JSON response data dependent on the controller at the requested URL.  In many cases, the JSON response follows cJSON format.
    • log_callback - Callback to handle event logs.  This will only be called if an event log is included in the response.  An event log will automatically be included if the server logs any events to the repository while handing this request.  If no log_callback is specified, or it returns TRUE, the alert bar will automatically display the error log.  If this call back does special handling, it can return FALSE to prevent the automatic behavior.  The callback receives the same parameter as the main callback, but it will include Response.JSON.EventLog with the entire event log in HTML format.
    • fail_callback - Callback to handle a failed request, such as a 500 error from the server.  It receives three parameters (descriptions based on jQuery.ajax() error documentation):
      • jqXHR - A string describing the type of error that occurred and an optional exception object, if one occurred.
      • TextStatus - Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror".
      • ErrorThrown - When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error."

Example

wc.post({
    url: "https://<account>.webcomand.com/com_package_name/controller",
    data: {},
    msg: "Loading..."
});