Skip to content
guiled edited this page Jun 7, 2021 · 35 revisions

Let's Role Enhanced !

What is LRE ?

LRE (for Let's role enhanced) is a utility to facilitate use of some features of Let's role that are a bit tricky. LRE adds some more features to enhance let's role scripting experience.

Usage

The simplest LRE usage is as following

init = lre(function (sheet) {
};

sheet parameter is an object extending Let's Role sheet component. Every component retrieved with sheet.get() is an LRE component, every component retrieved with lreComponent.find() is an LRE component.

Sheet

Sheet is an LRE extension of Sheet basic component with some more features :

  • raw() : get the original Sheet component
  • get(id) : return an LRE component
  • initChoice(id) : return an LRE Choice
  • initMultichoice(id) : return an LRE Multichoice
  • data(name[, value[, isPersistent]) : set or get a data attached to the component.
  • hasData(name) : test if a component has a data attached (volatile or persistent)
  • deleteData(name) : remove a data attached to the component (volatile or persistent)
  • setData(object) : this existing method has been modified in order to bypass the limitation of 20 sets. This method is now asynchronous (data arre saved few ms after setData() call.

Component

Component is an LRE extension of basic Component with some more features :

  • raw() : get the original component
  • realId() : get the id of an element for direct access through sheet.get(id). Useful for component inside repeaters (generate an id like repeaterId.entryId.componentId)
  • sheet() : return the sheet extended with LRE of the component
  • parent() : return the parent extended with LRE of the component
  • data(name[, value[, isPersistent]) : set or get a data attached to the component.
  • hasData(name) : test if a component has a data attached (volatile or persistent)
  • deleteData(name) : remove a data attached to the component (volatile or persistent)
  • toggle() : display/hide the component
  • on(eventName, function) : it is possible to have more than one function attached to an event. Automatically enable events of eventName
  • on(eventName, subComponent, function) : it is possible to have more than one function attached to an delegated event. Automatically enable events of eventName.
  • off(eventName[, function]) : detach all event handler or a specific one only
  • off(eventName, subComponent[, function]) : detach all event handler or a specific one only delegated to a subComponent
  • disableEvent(eventName) : disable events without removing previously defined event handlers
  • enableEvent(eventName) : enable events with the previously defined event handlers
  • value([mixed]) : this method has been changed and is now async (you can notice the changes after a very short delay). Moreover it may be lighter in usage with Let's Role servers.

Choice

Choice is an LRE extension of Choice basic component with some more features :

  • populate(function) : fill the Choice with the data return by the function passed as argument, which must return a valid array of objects for setChoices
  • populate(tableName, labelField) : populate the Choice with data from table called 'tableName' using the column named 'labelField' as a label
  • repopulate() : set back the choices set with previous populate() method.
  • getChoices() : returns all available Choices (). (Choice.populate needs to be called)
  • label() : get the label of the chosen choice
  • row() : get the row content from the Table of the chosen choice. (Choice.populate needs to be called with the tableName

Multichoice

Multichoice is an LRE extension of Choice LRE component with some more features :

  • maxChoiceNb(int) : define a max number of selected choice. If 0, no limit.
  • clear(), unselectAll(), selectNone() : select no choice
  • selectAll() : select all choices. (Multichoice.populate needs to be called)
  • invert() : invert the selection of choice (if the number of new choices is greater than maxChoiceNb, then invert is cancelled ). (Multichoice.populate needs to be called)

Events

  • limit : when user try to chose more that allowed choice number (see maxChoiceNb)

Repeater is an LRE extension of Repeater basic component with some more features :

  • each(function) : browse every entries and run the function passed as argument. The function has three arguments : entry LRE component, entryData, entryId
  • each(componentName, function) : like each(function) but the function receive the component inside each entry instead of the entry itself

Events

  • init : callback parameters (repeater, entry, entryId, data). This event is triggered when you click on "Add…" button
  • delete : callback parameters (repeater, entryId, oldData). This event is triggered when an entry is deleted
  • edit : callback parameters (repeater, entry, entryId, data). This event is triggered when you click on "Edit" button
  • change : callback parameters (repeater, entry, entryId, newData, oldData). This event is triggered when you click on "Save" button.

Various functions

  • isObject(any):boolean
  • strlen(String):int : because of SB-62 String.length always returns 0, strlen compute it. Don't use it too much as it a quite slow.
  • isNaN(any):boolean : this basic javascript function is not defined in Let's Role, it returns true if the parameter is not a number
  • firstInit : this function can be declared like init and will be ran only once in whole life of a sheet. It takes one argument : an LRE Sheet
firstInit = function (sheet) {
  // do something like data intialisation
};

Clone this wiki locally