Files
JiboOs/docs/rendering/gui/actions/ActionData.js
2026-03-16 13:53:01 +02:00

414 lines
11 KiB
JavaScript

/**
* @interface jibo.face.views.ActionData~ActionDescriptor
* @description Interface for an Object to be turned into instance of an ActionData class.
* @prop {String} type - The type of the action.
* @prop {any} [data] - Additional data for action, requited data depends on type.
*/
/**
* Use to pass actions across the view architecture.
* @class ActionData
* @memberof jibo.face.views
*/
/**
* The type of the action.
* Supported types are this class's constants.
* @name jibo.face.views.ActionData#type
* @type {String}
*/
/**
* The data Object that is passed with the action.
* Not all action types require data.
* Refer to this class's constants for action type requirements.
* @name jibo.face.views.ActionData#data
* @type {Object}
*/
/**
* Change view by specifying view change options.
* Data requirements include [ChangeOptions]{@link jibo.face.views~ChangeOptions}
* @example
* <caption>JSON format</caption>
* "action": {
* "type": "changeView",
* "data": {
* "options": {
* "removeAll": true,
* "leaveEmpty": true
* }
* }
* }
* @constant jibo.face.views.ActionData.CHANGE_VIEW
* @type {String}
*/
/**
* Add a view.
* Data requirements include a path to view configuration to be opened.
* @example
* <caption>JSON format</caption>
* "action": {
* "type": "openView",
* "data": {
* "configPath": "resources/menus/myMenu.json"
* }
* }
* @constant jibo.face.views.ActionData.OPEN_VIEW
* @type {String}
* @readOnly
*/
/**
* Remove the current view.
* This action has no data requirements.
* @example
* <caption>JSON format</caption>
* "action": {
* "type": "closeView",
* }
* @constant jibo.face.views.ActionData.CLOSE_VIEW
* @type {String}
* @readOnly
*/
/**
* Remove the current view and not open the next view in the hierarchy.
* Will leave the display empty and the current view equal to null.
* This action has no data requirements.
* @example
* <caption>JSON format</caption>
* "action": {
* "type": "closeViewEmpty",
* }
* @constant jibo.face.views.ActionData.CLOSE_VIEW_EMPTY
* @type {String}
* @readOnly
*/
/**
* Remove all the views up to, but not including, the root view.
* @example
* <caption>JSON format</caption>
* "action": {
* "type": "closeAll"
* }
* @constant jibo.face.views.ActionData.CLOSE_ALL
* @type {String}
* @readOnly
*/
/**
* Remove all the views and clear hierarchy up to but not including root, then add view.
* Added view will be one above the root view.
* Data requirements include a path to view configuration to be opened.
* @example
* <caption>JSON format</caption>
* "action": {
* "type": "closeAllOpen",
* "data": {
* "configPath": "resources/menus/myMenu.json"
* }
* }
* @constant jibo.face.views.ActionData.CLOSE_ALL_OPEN
* @type {String}
* @readOnly
*/
/**
* Close all the views and clear hierarchy up to but not including root,
* but do not add the root view to the display.
* Added view will be one above the root view.
* Data requirements include a path to view configuration to be opened.
* @example
* <caption>JSON format</caption>
* "action": {
* "type": "closeAllEmpty"
* }
* @constant jibo.face.views.ActionData.CLOSE_ALL_EMPTY
* @type {String}
* @readOnly
*/
/**
* Emulate a swipe right gesture.
* @example
* <caption>JSON format</caption>
* "action": {
* "type": "swipeRight"
* }
* @constant jibo.face.views.ActionData.SWIPE_RIGHT
* @type {String}
* @readOnly
*/
/**
* Emulate a swipe left gesture.
* @example
* <caption>JSON format</caption>
* "action": {
* "type": "swipeLeft"
* }
* @constant jibo.face.views.ActionData.SWIPE_LEFT
* @type {String}
* @readOnly
*/
/**
* Emulate a swipe down.
* @example
* <caption>JSON format</caption>
* "action": {
* "type": "swipeDown"
* }
* @constant jibo.face.views.ActionData.SWIPE_DOWN
* @type {String}
* @readOnly
*/
/**
* Emulate a swipe up.
* @example
* <caption>JSON format</caption>
* "action": {
* "type": "swipeUp"
* }
* @constant jibo.face.views.ActionData.SWIPE_UP
* @type {String}
* @readOnly
*/
/**
* Go to first page of a list.
* Enact action on [List]{@link jibo.face.views.List} to take effect.
* @example
* <caption>JSON format</caption>
* "action": {
* "type": "goToBeginning"
* }
* @constant jibo.face.views.ActionData.GO_TO_BEGINNING
* @type {String}
* @readOnly
*/
/**
* Go to last page of a list.
* Enact action on [List]{@link jibo.face.views.List} to take effect.
* @example
* <caption>JSON format</caption>
* "action": {
* "type": "goToEnd"
* }
* @constant jibo.face.views.ActionData.GO_TO_END
* @type {String}
* @readOnly
*/
/**
* Emit an event from the owning View when triggered.
* Required data is an event string.
*
* @example
* <caption>JSON format</caption>
* "action": {
* "type": "event",
* "data": {
* "event": "danceParty"
* }
* }
*
* @example
* <caption> To listen for these events just add a listener to
* the View that contains the action. </caption>
*
* myView.on('danceParty', getDown);
*
* @example
* <caption>You must specify the event string for the event to fire,
* but can include as much additional data as needed.
* The entire data Object is returned when the event is fired.
* Here we add another value to the data Object in JSON:</caption>
*
* "action": {
* "type": "event",
* "data": {
* "event": "danceParty"
* "dance": "funkyChicken"
* }
* }
*
* @example
* <caption>Then in your code you can listen for the event,
* which will pass back the data Object:</caption>
*
* myView.on('danceParty', (eventData) => {
* if(eventData.dance === 'funkyChicken'){
* console.log('Booo');
* }
* });
*
* @constant jibo.face.views.ActionData.EVENT
* @type {String}
* @readOnly
*/
/**
* Play a sound.
* Within data, provide either the type of sound or the URI for the sound file.
* @example
*
* <caption>JSON format. Playing a preloaded or gloabl sound by giving the the ID.</caption>
* "action": {
* "type": "sound",
* "data": {
* "id": "button"
* }
* }
* @example
* <caption>JSON format. Playing sound by just giving src of sound asset.</caption>
* "action": {
* "type": "sound",
* "data": {
* "src": "resources/sfx/button_sfx.m4a"
* }
* }
* @example
* <caption>JSON format. Loading a sound and giving it an ID for repeat usage.</caption>
* "action": {
* "type": "sound",
* "data": {
* "id": "unique_sound"
* "src": "resources/sfx/button_sfx.m4a"
* }
* }
*
* @name jibo.face.views.ActionData#SOUND
* @type {String}
* @readOnly
*/
/**
* Spoof an utterance that will be used as the result of the current MIM listen. Strings are
* handled as the result intent, otherwise a properly formatted NLU result must be provided
* @example
* <caption>JSON format with string</caption>
* "action": {
* "type": "utterance",
* "data": {
* "utterance": "whatIsWeather"
* }
* }
* @example
* <caption>JSON format with full result</caption>
* "action": {
* "type": "utterance",
* "data": {
* "utterance": {
* "intent": "whatIsWeather",
* "entities": {
* "time": "tomorrow"
* }
* }
* }
* @constant jibo.face.views.ActionData.UTTERANCE
* @type {String}
* @readOnly
*/
/**
* Results passed from the MIM systems.
* @example
* <caption>JSON format for select elements on a page</caption>
* "action": {
* "type": "verbalCommand",
* "data": {
* "intent": "selectItem",
* "entities": {
* "itemPosition": "first"
* }
* }
* }
*
* <caption>JSON format tp control pages</caption>
* "action": {
* "type": "verbalCommand",
* "data": {
* "intent": "right",
* }
* }
*
*
* @constant jibo.face.views.ActionData.VERBAL_COMMAND
* @type {String}
* @readOnly
*/
/**
* Immediately end the currently active MIM.
* @example
* <caption>JSON format for ending a MIM</caption>
* "action": {
* "type": "mimEnd"
* }
*
* @constant jibo.face.views.ActionData.MIM_END
* @type {String}
* @readOnly
*/
/**
* Immediately show the available GUI for the currently active MIM.
* @example
* <caption>JSON format for showing a MIM's GUI</caption>
* "action": {
* "type": "mimShowGUI"
* }
*
* @constant jibo.face.views.ActionData.MIM_SHOW_GUI
* @type {String}
* @readOnly
*/
/**
* Call a method when action is triggered.
* Not something easily defined via JSON; more likely to be defined in code.
* @example
* <caption>Creating in code</caption>
* new ActionData( ActionData.CALLBACK, {
* callback: this.foo.bind(this)
* });
* <caption>Adding to a Component</caption>
* component.addAction(ActionData.CALLBACK, {callback: this.foo.bind(this)});
* @constant jibo.face.views.ActionData.CALLBACK
* @type {String}
* @readOnly
*/
/**
* Create an ActionData object from a configuration Object.
* Generally derived from JSON.
* @method jibo.face.views.ActionData.createFromConfig
* @example
* <caption>JSON format</caption>
* {
* "type": "openView",
* "data": {
* "configPath": "assets/menu/myMenu.json"
* }
* }
* @param {jibo.face.views.ActionData~ActionDescriptor} configData Object defining the action.
* @returns {jibo.face.views.ActionData} A new ActionData with values specified by given configuration.
*/
/**
* Constructor for ActionData.
* @param {String} [type] The type of action.
* @param {Object} [data] The data Object with action values.
*/
/**
* Apply the configuration Object's values to this ActionData class.
* @method jibo.face.views.ActionData#applyConfig
* @param {jibo.face.views.ActionData~ActionDescriptor} configData Object defining the action.
*/