$html = get_storage_html(parameter array);
get_storage_html returns a ready html dropdown including JavaScript to select external storage configured by the user in the LoxBerry widgets (network, usb, local). The selected storage can be submitted in your HTML form, or directly used in JavaScript. It makes it easy for the user and the developer to select and integrate storage devices into the plugin UI.
LoxBerry Compatibility
This features is available starting with LoxBerry 1.2.1. Use that version as your minimum version in your plugin.cfg.
To simplify parameter readability and usage, the function needs to be called with an array of named parameters.
Using the parameters, you can adjust the behaviour and design of the HTML dropdown.
The function can be used multiple times on every page, but the formid
parameter must be unique for every call.
Parameter
Parameter list of get_storage_html (Perl and PHP)
Parameter | Optional | Default | Function |
---|---|---|---|
formid | Name of the HTML form element including the resulting path. This id is used as id and name of the element. The input field is hidden in the form, but updated on every user change. | ||
currentpath | x | undef | Giving a path, this is the pre-defined path of the dropdown element. Read the path from your config file and insert it here. Omitting this parameter will set an empty path. |
custom_folder | x | undef | undef - The user is not allowed to add an additional subfolder to the selected storage. 1 - Behind the selected storage, the user can enter an own subfolder tree. But keep in mind that the plugin code has to care about the existance and creation of that folder. |
readwriteonly | x | undef | If this parameter is omitted (default), all storage points are shown. To only show writeable storage points, set readwriteonly => 1. |
show_browse | x | undef | Displays an eye symbol right to the select box to open the current path in LoxBerry's File Manager. The eye symbol is disabled if the base path is outside of /opt/loxberry, as this is not allowed in LoxBerry's File Manager. (available from LoxBerry 2.0.0.4) |
Formating | |||
label | x | System-Phrase | This is the string label in front of the dropdown. Usually, set the label to a string from your plugin language phrases. Without this parameter, the system default string "Storage path" (language specific) will be used. |
data_mini | x | undef | This flag corresponds to the jQuery Mobile flag data-mini="true" . The controls are displayed in the data-mini="true" behaviour if set to 1. |
Types of storage to show | |||
type_all | x | 1 oder 0 | Using type_all => 1 (or omitting this parameter), all of the folloing storage types are shown. If you set at least one other type to 1, type_all is disabled. |
type_usb | x | undef | USB storage devices are selectable. |
type_net | x | undef | Network shares are selectable. |
type_local | x | undef | The local plugin data directory ($lbpdatadir) is selectable. |
type_custom | x | undef | The user can alternatively enter an own path. Take care: If you want to prevent a custom path by type_custom = 0, and the sent |
Return value
The function returns a string with html, that can be directly echoed to the output. In the case that anything fails, it returns nothing.
Usage with html form processing
Echo the generated html inside <form></form> tags. On submission, the formid
name contains the full path (including folders) of the user selection. The path is the absolute path on LoxBerry.
A trailing / is always removed, also if you deliver it with currentpath
.
Usage with JavaScript
the current, combined path can be accessed everytime, and every change can be monitored:
Usage
require_once "loxberry_storage.php"; # Define the parameter array $params = array( "formid" => "mystorage", "currentpath" => $lbpdatadir, "readwriteonly" => 1, "label" => "Please enter the destination", ); # This uses the id 'mystorage', sends the plugin datadir as currently configured directory, and only returns writable storages. echo get_storage_html($params); # Show only USB and network storage, allow custom path but no custom folder $params = array( "formid" => "mystorage", "type_usb" => 1, "type_net" => 1, "type_custom" => 1, ); echo get_storage_html($params);