16.md 16 KB

["9. ao_module"]

“ao_module.js” Float Window and System Utilities Wrapper

ao_module.js is a javascript file located under AOR/script/.

This wrapper provides functions that are most commonly used for developers when developing a module. Here is the list of functions that is included in ao_module.js on v2-4-2019 Edition of ArOZ Online System. For the full examples, please refer to Appendix for ao_module wrapper usage examples.

ao_module wrapper and direct AJAX call to system scripts

As the in-code statement suggested, you can also bypass this wrapper and access ArOZ Online System via AJAX requests. However, it is still unsure if the script IO will be backward compatible in the future build of ArOZ Online System, the ao_module API will definitely be backward compatibility in the coming versions.For faster development, please include this script into your module and call through this script instead of calling via AJAX requests to the php scripts.

Usage Guidance of ao_module.js

  1. ao_module.js requires jquery to work. A copy of jquery can be found in AOR/script/jquery.min.js

  2. ao_module.js cannot be included within an iframe inside a Float Windows.

  3. Use the function inside the wrapper if possible as this wrapper is officially supported and guaranteed to be compatible with future updates on Float Window System.

Global Variables

Type Variable Name Usage
Boolean ao_module_virtualDesktop Check if the user is calling the script in normal mode or VDI mode
String ao_module_windowID Current window ID, similar to Linux pid
String ao_module_parentID Current window parent ID, similar to Linux ppid
String ao_module_callback Callback function name for child to call in parent window

FloatWindows Functions

Function Name Parameters Usage
ao_module_setWindowIcon Icon Set the current FloatWindow with specified icon
ao_module_setWindowTitle Title Set the current FloatWindow with specified title tag
ao_module_setGlassEffectMode Set the current FloatWindow to GlassEffect Window (Cannot switch back to original mode)
ao_module_setFixedWindowSize Set the current FloatWindow to Fixed Size Window (Non-resizable), default Resizable
ao_module_setWindowSize w,h,cache=false,exact=false Set the current FloatWindow size (width, height, Enable window size caching, exact URL required)
ao_module_close Close the current window
ao_module_hideAllControls Hide all control elements of this float window
ao_module_declareCrash Not implemented
ao_module_newfw Src,Windowname,Icon,Uid,sizex = undefined,sizey = undefined,posx = undefined,posy = undefined,fixsize = undefined,glassEffect = undefined,parentUID=null, callbackFunct=null Example 1: opening the Memo index with the following code:ao_module_newfw('Memo/index.php','Memo','sticky note outline','memoEmbedded',475,700); Example 2: opening the Memo index with minimal parameter:ao_module_newfw('Memo/index.php','Memo','sticky note outline','memoEmbedded'); Example 3: opening a sub-module and tell the sub-module the parent's window id that is not yourself:ao_module_newfw('Memo/index.php','Memo','sticky note outline','memoEmbedded',undefined,undefined,undefined,undefined,undefined,undefined,"someoneElseUID"); Example 4: opening a sub-module and ask for a callback: (Default parentUID is set to this module's WindowID and hence, the call back will be called to this content window)ao_module_newfw('Memo/index.php','Memo','sticky note outline','memoEmbedded',undefined,undefined,undefined,undefined,undefined,undefined,undefined,"callBackFunctionName");
ao_module_launchModule moduleName Example: ao_module_launchModule("Audio");
ao_module_fullScreen Request fullscreen access from VDI module
ao_module_getWidth Get current floatWindow width
ao_module_getHeight Get current floatWindow height
ao_module_getLeft Get current floatWindow left (x)
ao_module_getTop Get current floatWindow top (y)

File Select, Access or Opening API

Tips: All paths for the file access API are starting from AOR.

Function Name Parameters Usage
ao_module_openFileSelector Uid,callBackFunctionName, windowWidth = 1080, windowHeight = 645, allowMultiple = false, selectMode = "file", newfname = "newfile.txt", umf = true ao_module_openFileSelector({uid},{call back function name in String},{window Width},{windowHeight},{allowMultipleFiles},{selectMode (file / folder / mix / new},{newfilename if new mode},{new file encoding if new mode}); To catch the callback of the selector, you can receive the data as a JSON array with objects that contain attributes “filename” and “filepath”.
ao_module_openFileSelectorTab Uid, aor,allowMultiple = false, selectMode = "file",callBack=console.log, newfname = "newfile.txt", umf = true Assume we have a module at AOR/Dummy/index.php, the script running in that module has an aor = ../ For other parameters, please refer to ao_module_openFileSelector
ao_module_openPath targetPath, windowWidth = 1080, windowHeight = 580,posx = undefined,posy = undefined,resizable = true,glassEffect = true For example, if you want to open the folder:"AOR/Audio/uploads/"Then you can call this function as follows:ao_module_openPath("Audio/uploads");
ao_module_openFile targetPath,filename The targetpath can be something different from the filename (display name)

File Operation API

All functions in this section should be called with the class name “ao_module_fs”.

Example: ao_module_fs.isFile(...)

Function Name Parameters Usage
isFile source ao_module_fs.isFile(“demo.txt”);//Return trueao_module_fs.isFile(“directory/”);//Return false
unlink source, callback = null, overrideConfirm = false ao_module_fs.unlink(“demo.txt”); Set overrideConfirm to true for hiding the popup confirm window.
move source,target, callback = null ao_module_fs.move(“demo.txt”, “demo2.txt”);
rename source,target, callback = null Alias of move function
copy source, target, callback = null ao_module_fs.copy(“demo.txt”, “demo2.txt”);

All the callback functions are performed after the asynchronize request has been sent, not after the file operation completes.

User Notification and Focus

Function Name Parameters Usage
ao_module_msgbox warningMsg,title="",redirectpath="",autoclose=true ao_module_msgbox("This is a demo message from the aroz online module.","Hello World",{onClick redirect path},{auto_close}); If auto close = false, the sidebar will not get hidden after 4 seconds.
ao_module_focus This function brings the current floatWindow content to the front of all FloatWindows.
ao_module_callToInterface Return the object in which the main interface iframe (Aka the most background iframe)

Storage and Cross Frame Data Transfer

Function Name Parameters Usage
ao_module_parentCallback data This function can send data to the parent callback function from the child if necessary. Data has to be an object.
ao_module_getStorage moduleName,itemname ao_module_getStorage("MusicMixer","Admin","songList");
ao_module_saveStorage moduleName,Itemname,value ao_module_saveStorage("MusicMixer","Admin","songList","{some JSON string here}");
ao_module_writeTmp Uid,value Write value as tmp in localStorage
ao_module_readTmp uid Read value from tmp from localStorage
ao_module_removeTmp uid Remove tmp value from localStorage
ao_module_checkStorage id Check if a given storage id exists

ArOZ Cluster Services

Function Name Parameters Usage
ao_module_openClusterSelector Uid,callBackFunctionName,windowWidth = 1080, windowHeight = 645, allowMultiple = false, selectMode = "node" Example (Node Selection)ao_module_openClusterSelector(uid,"clusterProcess"); Example (Disk Selection)ao_module_openClusterSelector(uid,"diskProcess",undefined,undefined,undefined,"disk");
ao_module_openClusterSelectorTab uid, aor,allowMultiple = false, selectMode = "node",callBack=console.log Example (Node Selection)ao_module_openClusterSelectorTab(uid,"../",undefined,undefined,clusterProcess); Example (Disk Selection)ao_module_openClusterSelectorTab(uid,"../",undefined,"disk",diskProcess);

ArOZ Online Input Method Editor

All functions in this section should be called with the class name “ao_module_inputs”.

Example: ao_module_inputs.defineInputMethod(...)

Function Name Parameters Usage
defineInputMethod keyHandlerFunct A function(e) should be passed in.e is the event handler which should be passed through to this iframe by typing target window
undefineInputMethod Undefined this module window as an Input Method
hookStdIn localFunction Example:ao_module_inputs.hookStdIn(function(text){ //text variable is the string that the user typed via the IME $("#input").append(text); });
stdOut text Sent output text to the current focused Windows. Example:ao_module_inputs.stdOut(text);
hookKeyHandler event Function call by the webapp that accept your input method outputDo not include the following function into your code. This is used for callback purpose only

ArOZ Online System Utils

All functions in this section should be called with the class name “ao_module_utils”.

Example: ao_module_utils.getRandomUID()

Function Name Parameters Usage
objectToAttr object Convert an object to html safe text to be put into an element as attribute
attrToObject attr Convert an html attribute back to an object for javascript
getRandomUID Get a random id for a new floatWindow
getIconFromExt ext Get the icon of a file with given extension (ext)

ArOZ Online Encode and Decoder

All functions in this section should be called with the class name “ao_module_codec”.

Example: ao_module_codec.decodeUmFilename(...)

Function Name Parameters Usage
decodeUmFilename umfilename Decode umfilename into standard filename in utf-8, which umfilename usually start with "inith"
encodeUMFilename filename Encode filename to UMfilename
decodeHexFoldername folderName, prefix=true Decode hexFoldername into standard folder name in utf-8, return the original name if it is not a hex folder nameEnable prefix to add an “*” icon in front of the decoded string for identification
encodeHexFoldername folderName Encode folder name into hexfoldername

ao_module.js Wrapper Function List

Here is a list of functions included in the ao_module.js wrapper.

Standard Functions

  • ao_module_setWindowIcon
  • ao_module_setWindowTitle
  • ao_module_setGlassEffectMode
  • ao_module_setFixedWindowSize
  • ao_module_setWindowSize
  • ao_module_close
  • ao_module_getProcessID
  • ao_module_declareCrash
  • ao_module_openFileSelector
  • ao_module_openFileSelectorTab
  • ao_module_listenFileSelectionInput
  • ao_module_openPath
  • ao_module_openFile
  • ao_module_newfw
  • ao_module_fullScreen
  • ao_module_getWidth
  • ao_module_getHeight
  • ao_module_getLeft
  • ao_module_getTop
  • ao_module_msgbox
  • ao_module_focus
  • ao_module_callToInterface
  • ao_module_parentCallback
  • ao_module_getStorage
  • ao_module_saveStorage
  • ao_module_writeTmp
  • ao_module_readTmp
  • ao_module_removeTmp
  • ao_module_checkStorage

Input Method Editor / System Inputs

  • ao_module_inputs.defineInputMethod
  • ao_module_inputs.undefineInputMethod
  • ao_module_inputs.hookStdIn
  • ao_module_inputs.hookKeyHandler
  • ao_module_inputs.stdOut

System Utilities Functions

  • ao_module_utils.objectToAttr
  • ao_module_utils.attrToObject
  • ao_module_utils.getRandomUID
  • ao_module_utils.getIconFromExt

ArOZ File System Codec

  • ao_module_codec.decodeUmFilename
  • ao_module_codec.decodeHexFoldername
  • ao_module_codec.hex2bin
  • ao_module_codec.decode_utf8