adaptiveDataError(..)
Returns: (undefined)
Call this function from the menuCallback of the Adaptive Source if the request for the next menu failed. The editor closes the Loading... menu and shows the message in the Help String (or, if the Help String is hidden, in a notification).
Parameters
- message (
String) - The error message to show. Optional. If omitted, the editor shows its default error text.
browseWhileDisabled(..)
Returns: (Object) - Rule Editor instance
Opt-in behavior for a disabled editor. When turned on, a disabled editor still moves its current element on a click and with the arrow keys (it opens no menus and cannot change the rule), so your code can follow it with onCurrentChange(..). A disabled editor otherwise reacts to nothing.
Parameters
- on (
Boolean) - true to turn the behavior on, false to turn it off.
Example
var editor = $ce("divEditor");
editor.disable();
editor.browseWhileDisabled(true);
editor.onCurrentChange(function (el) { console.log(el); });
clear()
Returns: (Object) - Rule Editor instance
Removes all elements of the current rule from the Rule Area and resets the value returned by isAltered().
Parameters
deleted(..)
Returns: (Object) - Rule Editor instance
Calling this function after deleting a rule is necessary to clear editor's cache and remove the deleted rule from the Rules menu (if the Toolbar is displayed) and context menus.
Parameters
- id (
String) - ID of the rule that is being deleted. This parameter is required.
disable()
Returns: (Object) - Rule Editor instance
Prevents users from adding new rules or modifying the rule currently loaded in the Rule Area.
Parameters
Example
var editor = $ce("divEditor");
editor.disable();
dispose()
Returns: (Object) - Rule Editor instance
Disposes all resources used by Rule Editor, removes the event handlers it registered, empties its hosting div element, and removes the editor from the current context. After the call, $ce(..) no longer returns this instance, and you can call $rule.init(..) again with the same element id.
Parameters
enable()
Returns: (Object) - Rule Editor instance
Restores ability to add new rules or modify the rule currently loaded in the Rule Area.
Parameters
-
Returns: (String) - JSON string
Returns a JSON string containing the current rule and a value indicating whether it is valid. If the Rule Area contains a value that the user has not finished typing, the editor shows a warning and the function returns the JSON null. If the Rule Area is empty, returns an empty JSON.
Parameters
Example
var json = $ce("divEditor").extract();
getCalls()
Returns: (Array)
Returns the calls to methods and actions of the source that the current rule makes, in the order they are written. The function reads the Rule Area and does not change it. Calls to reusable rules are not included; use getRuleCalls() to get them. Returns an empty array if the editor is not initialized.
Each array item is an object with the following properties:
- scope (
String) - "0" for the rule itself, then "0.1", "0.2", and so on for its collection conditions in the order they appear ("0.1.1" for a nested one).
- position (
Integer) - The one-based position of the call within its scope.
- kind (
String) - "method" or "action".
- source (
String) - The name of the source that declares the member.
- value (
String) - The token of the member.
- name (
String) - The display name of the member.
- elements (
Array) - The DOM elements the call consists of: its name, parameters, commas, and end.
Parameters
getElementInfo(..)
Returns: (Object) - Description of the member, or null
Returns what a rule element refers to in the source of the editor. The function does not change the editor. It returns null for elements that refer to nothing in the source, such as operators, clauses, parentheses, values that are not enumeration members, and calls to reusable rules. A field that is passed to a method, used in a calculation, or used as a value is reported as that field. A value of an enumeration is reported as the enumeration.
The returned object has these properties:
- kind (
String) - One of "field", "collection", "method", "action", or "enum".
- source (
String) - The name of the source.
- value (
String) - The value of the member in the settings: the declared path of a field, the token of a method, or the class of an enumeration.
- name (
String) - The display name of the member. null for "enum".
- enumType (
String) - The class of the enumeration, if the member is one. Otherwise, null.
Parameters
- el (
HTMLElement) - An element of the Rule Area, for example, one of the elements returned by getCalls() or the element passed to the onCurrentChange(..) callback.
Example
var editor = $ce("divEditor");
editor.onCurrentChange(function (el)
{
var info = el ? editor.getElementInfo(el) : null;
if (info) console.log(info.kind + ": " + info.name);
});
getParts()
Returns: (Object)
Returns the conditions, setters, and collection conditions of the current rule, in the order they are written, each with the elements it is made of. The function reads the Rule Area and does not change it. The scopes are the same as in getCalls(), and the positions are counted for each kind within its scope.
The returned object has three arrays, conditions, setters, and collections. Each item has the following properties:
- scope (
String) - The scope in which the part is written.
- position (
Integer) - The one-based position of the part among parts of its kind in the scope.
- elements (
Array) - The DOM elements the part consists of.
Parameters
getRuleCalls()
Returns: (Array)
Returns the calls to reusable rules that the current rule makes, in the order they are written. The function reads the Rule Area and does not change it. Returns an empty array if the editor is not initialized.
Each array item is an object with the following properties:
- scope (
String) - The scope in which the call is written, as described for getCalls().
- ruleId (
String) - The ID of the called rule.
- name (
String) - The name of the rule as the Rule Area shows it.
- source (
String) - The name of the source on which the call is made.
- elements (
Array) - The DOM element of the call.
Parameters
getRuleId()
Returns: (String) - String value of the Rule ID (.NET System.Guid)
Returns the string ID of the current rule assigned by the Rule Editor. The editor generates new rule IDs by calling .NET’s System.Guid.NewGuid().ToString(). Returns null if no rules have been loaded into the editor, if the current rule has not yet been assigned an ID, or if the Rule Area is empty.
Parameters
getRuleText()
Returns: (String)
Returns the current rule as plain text, the way the editor shows it: the label of every element in order, one space between two elements, a line break for each new line, and a tab character for each tab at the start of a line. An unfinished rule is returned unfinished. Returns an empty string if the Rule Area is empty. The function works on a disabled editor as well.
Parameters
Example
var text = $ce("divEditor").getRuleText();
getSourceDefinitions()
Returns: (Array)
Returns a copy of the sources the editor was given, as the settings describe them. Changing the copy changes nothing in the editor. Returns an empty array if the editor has no sources yet.
Each array item is an object with the following properties:
- n (
String) - The name of the source.
- fds (
Array) - The fields and methods of the source.
- acs (
Array) - The actions of the source.
- irs (
Array) - The reusable rules of the source, as objects with the v (rule ID) and n (name) properties.
Each item of fds and acs has the properties v (value), n (display name), t (type), o (data type), cv (the name of the source of a collection of a source type), e (the class of an enumeration), and ir (true for a reusable rule). Properties that do not apply are null.
Parameters
isAltered()
Returns: (Boolean)
Returns true if the user has modified an existing rule after it was loaded into the Rule Area or a new rule after its creation was initiated. Otherwise, returns false.
Parameters
isEmpty(..)
Returns: (Boolean)
Returns true if the Rule Area currently contains no rule elements. Otherwise, returns false.
Parameters
- includeFormattingElements (
Boolean) - Indicates whether formatting elements of the rule, such as tabs and new lines, should be counted. Optional. Default value is true.
isEvaluationType()
Returns: (Boolean)
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 which rule elements the author has added to the Rule Area so far. Returns true if the editor has not been initialized with settings yet.
Parameters
loadAdaptiveData(..)
Returns: (undefined)
Call this function from the menuCallback of the Adaptive Source to hand the requested menu data to the editor.
Parameters
- data (
Object) - The menu data received from the server-side source provider. This parameter is required.
loadInvalids(..)
Returns: (Object) – Rule Editor instance
Call this function to load invalid rule elements into the Rule Editor.
Parameters
loadRule(..)
Returns: (Object) – Rule Editor instance
Call this function to load a rule into the Rule Editor. The function returns undefined if the parameter is not defined.
Parameters
loadSettings(..)
Returns: (Object) – Rule Editor instance
Call this function to load the Rule Editor client settings. You should also call it whenever the rule author changes any of the editor’s settings, such as the visibility of the Toolbar, Help String, and similar options.
Parameters
redraw()
Returns: (Object) - Rule Editor instance
Recalculates the size and layout of the editor. Call it after your code changes the size of the hosting div element or shows a hidden one.
Parameters
saved(..)
Returns: (Object) – Rule Editor instance
Call this function after saving a new rule or updating an existing one to refresh the Rules menu of the Toolbar and context menus of the editor with the new or updated values. If the rule has no name, nothing is added to the menus, and a rule that is already in them keeps its name.
Parameters
- id (
String) - ID of the rule that has been saved or updated. This parameter is required for new rules and optional for updates.
- name (
String) - Name of the rule. Optional. If omitted, the editor reads the name from the name box of the Toolbar (if the Toolbar is displayed).
Example
var editor = $ce("divEditor");
editor.saved("3f2b7c1e-9d8a-4f55-b6a1-0c2d4e6f8a10", "Adult patients");
setAdaptiveSource(..)
Returns: (Object) – Rule Editor instance
Turns on the Adaptive Source model and sets its client-side settings. Use it for the server-centric initialization, which has no way to pass the callback to $rule.init(..); call it after loadSettings(..). For the client-centric initialization, pass the adaptiveSource object to $rule.init(..) instead.
Parameters
- args (
Object) - An object with the same properties as the adaptiveSource object described in the initialization article: menuCallback (required), behavior, min, and max. The last three default to the values of $rule.defaults. This parameter is required.
Example
editor.setAdaptiveSource(
{
menuCallback: menu,
behavior: $rule.behavior.merge
});
setCallbacks(..)
Returns: (Object) – Rule Editor instance
Call this function during page initialization to specify which functions the Rule Editor should call when the rule author wants to load, delete, or save a rule, and when the editor needs to show a notification. Do not call it for the rule management callbacks if the Toolbar is disabled. The function replaces all four callbacks, so pass undefined or null for those you do not use.
Parameters
- loadRuleCallback (
Function) - Callback function that handles loading a rule. This function must declare a single parameter of type string. The Rule Editor calls this function and passes it the rule ID when the rule author selects that rule from the Toolbar’s Rules menu.
- deleteRuleCallback (
Function) - Callback function that handles deleting a rule. This function must declare a single parameter of type string. The Rule Editor calls this function and passes it the rule ID when the rule author clicks the Delete button on the Toolbar.
- saveRuleCallback (
Function) - Callback function that handles saving a rule. The Rule Editor calls this function, without parameters, when the rule author clicks the Save button on the Toolbar. Call extract() inside the callback to get the rule data.
- notifyCallback (
Function) - Callback function that displays notifications. The editor passes it the notification text and the notification type ("warning" or "error"). Optional. The editor calls alert if it is not set.
Example
var editor = $ce("divEditor");
editor.setCallbacks(
function (id) { /* load the rule with this id */ },
function (id) { /* delete the rule with this id */ },
function () { var json = editor.extract(); /* save json */ },
function (message, type) { console.log(type + ": " + message); });
setClientActions()
Returns: (undefined)
Deprecated. Use setCallbacks(..) instead. The function no longer sets anything: calling it throws an error.
Parameters
setNotifyCallback(..)
Returns: (Object) – Rule Editor instance
Sets or replaces only the notification callback. Pass null to go back to the default alert call.
Parameters
- notifyCallback (
Function) - Callback function that displays notifications. The editor passes it the notification text (String) and the notification type (String, "warning" or "error").
Example
$ce("divEditor").setNotifyCallback(function (message, type)
{
console.log(type + ": " + message);
});
setRefData(..)
Returns: (undefined)
Changes the custom data that the editor passes to your Adaptive Source menuCallback as args.context.refData. The function throws an error if the editor has no settings yet, so call it after $rule.init(..) and loadSettings(..) (or after a client-centric $rule.init(..)).
Parameters
- refData (
Object) - Any value. It replaces the refData value passed to $rule.init(..).