Code Effects Client-Side API

Code Effects solution comes with rich client functionality that can be used in client-centric web applications. Aside from the server-side code that helps it process business rules, the Rule Editor is written as a client-side class that encapsulates a lot of functionality, and expresses it through a relatively small number of public functions available to any other client code. Code Effects client script declares only two global (public) variables, $rule and $ce, and keeps everything else inside the scope of its instance. This makes it safe to add Rule Editor to any markup with any kind of client code.

Rule Editor is a self-contained library. It doesn't depend on any client or server frameworks or libraries. It is compatible with all modern versions of all major browsers.

The main JS file that declares Rule Editor is available here in .txt format. Refer to our demo projects for details on how to reference and use this script on each .NET web platform.

Global Shortcuts

  • $ce Returns: Instance of the Rule Editor
    Parameters:
    • id, String - client id of the hosting DIV element of Rule Editor.
    var codeeffects = $ce("divRuleEditor");

    This is a global shortcut to the $rule.Context.getControl() function that can be used to get an instance of a Rule Editor by the client id of its hosting DIV element.

  • $rule Returns: CodeEffects.Rule namespace

    This global shortcut is declared to make the footprint of CodeEffects namespace smaller.

Global Functions

  • $rule.init(String) Returns: Newly created instance of Rule Editor
    Parameters:
    • data, String - JSON string received from the RuleEditor.GetInitialSettings() method. This is a required parameter.

    Call this function once after the current DOM is loaded. Calling this function creates a brand new instance of Rule Editor. It throws an Error object with the value of CL85 in its message if an instance of Rule Editor with the same DIV.id already exists in the current context. Use the $ce shortcut instead if you need to get a reference to an existing instance of Rule Editor. Download related demo project to see implementation details of this function.

Public Instance Functions

  • clear() Returns: Rule Editor instance
    Parameters: None

    Removes all elements of the current rule from the Rule Area.

  • deleted(String) Returns: Rule Editor instance
    Parameters:
    • id, String - ID of the rule that is being deleted. Required.

    Calling this function after deleting a rule is necessary in order to remove that rule from the Rules and context menus. See the related demo project for details on managing rules in Rule Editor.

  • disable() Returns: Rule Editor instance
    Parameters: None

    Removes ability to add new rules or modify the rule currently loaded in the Rule Area.

  • dispose() Returns: Rule Editor instance
    Parameters: None

    Disposes all resources used by Rule Editor and removes it from the current context.

  • enable() Returns: Rule Editor instance
    Parameters: None

    Restores ability to add new rules or modify the rule currently loaded in the Rule Area.

  • extract() Returns: String
    Parameters: None

    Returns a JSON string that contains the current rule, and whether or not it’s valid. Returns an empty object if the Rule Area is empty.

  • isEvaluationType() Returns: Boolean
    Parameters: None

    Returns True if the loaded rule is of the evaluation type, or if the rule author selected the New evaluation type rule option from the Rules menu of the Toolbar. This function does not check what kind of rule elements the rule author has added to the Rule Area so far.

  • getRuleId() Returns: String
    Parameters: None

    Returns the string ID of the current rule assigned by Rule Editor. The editor calls .NET's System.Guid.NewGuid().ToString() to get new IDs for rules. Returns null if no rules have been loaded into the Rule Editor yet, or if Rule Editor hasn't assigned an ID to the current rule yet, or if the Rule Area is empty.

  • loadInvalids(String) Returns: Rule Editor instance
    Parameters:
    • data, String - JSON string received from the server-side GetClientInvalidData() method of the RuleEditor class. Download related demo project to see details on loading invalid rule data into the Rule Editor. This is a required parameter.

    Call this function to load data of the invalid rule into the Rule Editor.

  • loadRule(String) Returns: Rule Editor instance
    Parameters:
    • data, String - JSON string received from the server-side GetClientRuleData() method of the RuleEditor class. Download related demo project to see details of use of this function. This is a required parameter.

    Call this function to load a rule into the Rule Editor.

  • loadSettings(String) Returns: Rule Editor instance
    Parameters:
    • data, String - JSON string received from the server-side GetClientSettings() method of the RuleEditor class. Download related demo project to see details of use of this function. This is a required parameter.

    Call this function to load Rule Editor client settings. You also need to call this function every time the rule author requests a change in any of the Rule Editor settings such as Help String visibility and so on.

  • saved(String) Returns: Rule Editor instance
    Parameters:
    • id, String - ID of the rule that has been saved or updated. This parameter is required for new rules but optional for updates.

    Calling this function after saving a new rule or updating an existing one is necessary in order to refresh the Rules and context menus with the new or updated values. Download related demo project to see for details on saving rules.

  • setClientActions(Function, Function, Function) Returns: Rule Editor instance
    Parameters:
    • loadRule, Function - callback that handles loading a rule. This delegate must declare a single parameter of String type. Rule Editor calls this function and passes it the ID of the rule when rule author selects that rule from the Toolbar's Rules menu. This is a required parameter.
    • deleteRule, Function - callback that handles deleting a rule. This delegate must declare a single parameter of String type. Rule Editor calls this function and passes it the ID of the rule when rule author clicks the Delete button on the Toolbar. This is a required parameter.
    • saveRule, Function - callback that handles saving of a rule. This delegate must declare a single parameter of Object type. Rule Editor calls this function and passes it an object that contains the rule data when rule author clicks the Save button on the Toolbar. This callback works in tandem with the LoadClientData() method of RuleEditor class. See related demo project for details on rule management. This parameter is required.

    Call this function while initializing your page to tell Rule Editor which functions to call when rule author wants to load, delete, or save a rule. Don't call it if Toolbar is disabled.

Comments: 0
Post your questions about Code Effects on Stackoverflow.com
and become a part of our growing community
Name (optional):
Comment (URLs are allowed and must start with http:// or https://; all tags will be encoded):
Remaining character count: