Class checklist
Represents a checklist.
Each checklist contains an array of checklist items and an active checklist item. The active checklist item indicates the currently executed checklist item.
Callbacks can be added to react to the checklist getting started, stopped and completed.
Info:
- Copyright: 2022 Patrick Lang
- Author: Patrick Lang
Methods
| checklist:new (title) | Creates a new checklist. |
| checklist:getTitle () | Gets the title of the checklist. |
| checklist:setState (state) | Sets the state of the checklist. |
| checklist:getState () | Gets the current state of the checklist. |
| checklist:addItem (checklistItem) | Adds an item to the checklist. |
| checklist:getAllItems () | Gets all items of the checklist. |
| checklist:getActiveItem () | Gets the active checklist item. |
| checklist:setActiveItemNumber (itemNumber) | Sets the active checklist item number. |
| checklist:hasNextItem () | Checks whether there is another checklist item after the active checklist item. |
| checklist:setNextItemActive () | Activates the next checklist item. |
| checklist:reset () | Resets the state of the checklist and its checklist items. |
| checklist:addStartedCallback (callback) | Adds a callback which is executed if the checklist is started. |
| checklist:addCancelledCallback (callback) | Adds a callback which is executed if the checklist is cancelled. |
| checklist:addCompletedCallback (callback) | Adds a callback which is executed if the checklist is completed. |
| checklist:onStarted () | Executes the started callbacks. |
| checklist:onCancelled () | Executes the cancelled callbacks. |
| checklist:onCompleted () | Executes the completed callbacks. |
Methods
- checklist:new (title)
-
Creates a new checklist.
Parameters:
- title string The title of the checklist.
Returns:
-
checklist
The created checklist.
- checklist:getTitle ()
-
Gets the title of the checklist.
Returns:
-
string
The title of the checklist.
- checklist:setState (state)
-
Sets the state of the checklist.
Parameters:
- state number The new state.
- checklist:getState ()
-
Gets the current state of the checklist.
Returns:
-
number
state The state of the checklist.
- checklist:addItem (checklistItem)
-
Adds an item to the checklist.
Parameters:
- checklistItem checklistItem The item to add.
- checklist:getAllItems ()
-
Gets all items of the checklist.
Returns:
-
tab
An array which contains all checklist items.
- checklist:getActiveItem ()
-
Gets the active checklist item.
Returns:
-
optional checklistItem
The active checklist item.
- checklist:setActiveItemNumber (itemNumber)
-
Sets the active checklist item number.
Parameters:
- itemNumber number The new active checklist item number.
Raises:
An error is thrown if the itemNumber does not point to an existing item. - checklist:hasNextItem ()
-
Checks whether there is another checklist item after the active checklist item.
Returns:
-
bool
Trueif there are still checklist items left, otherwisefalse. - checklist:setNextItemActive ()
-
Activates the next checklist item.
If there is no checklist item after the current active checklist item, then the active checklist item becomes
nil.Raises:
An error is thrown if the active item is the last item - checklist:reset ()
- Resets the state of the checklist and its checklist items. The active checklist item is set to the first checklist item.
- checklist:addStartedCallback (callback)
-
Adds a callback which is executed if the checklist is started.
Parameters:
- callback func The callback to add.
Usage:
myChecklist:addStartedCallback(function() end)
- checklist:addCancelledCallback (callback)
-
Adds a callback which is executed if the checklist is cancelled.
Parameters:
- callback func The callback to add.
Usage:
myChecklist:addCancelledCallback(function() end)
- checklist:addCompletedCallback (callback)
-
Adds a callback which is executed if the checklist is completed.
Parameters:
- callback func The callback to add.
Usage:
myChecklist:addCompletedCallback(function() end)
- checklist:onStarted ()
- Executes the started callbacks.
- checklist:onCancelled ()
- Executes the cancelled callbacks.
- checklist:onCompleted ()
- Executes the completed callbacks.