Documentation

ShowScript

CAdminFileDialog::ShowScript(
 Array arConfig
)

Method receives an array of configuration parameters and generates scripts, necessary to show file dialog. Static method.

Function parameters

Sole method parameter is the associative array, which keys are parameters of a dialog call. Keys and their descriptions are provided in the table below.

Key Description
event String, containing name of Javascript function, which calls file dialog. Function should be specified in global scope.
arResultDest Associative array that defines the way of file dialog result is returning. The following variants of the task are possible.
  1. Result of selection made by user is returned into function.

    In this case, the array should have the FUNCTION_NAME key with the value, equal to the name of Javascript-function, specified in the global scope.

    If operation = "O" (Latin letter "О"), function returns 3 parameters in case if user has selected the file :

    • filename - name of selected file;
    • path - path to selected file;
    • site - site ID.

    In case if operation = "S", then 2 more parameters are passed additionally:

    • title - title of saved page;
    • menu - associative array, determining necessity to save page in menu.
  2. User selection result is returned into specified form element.

    To pass user selection result to specific form element, the following keys must be determined in the array:

    • FORM_NAME - form id;
    • FORM_ELEMENT_NAME - name of form element.
  3. User selection result is returned into the element with specified ID.

    In this case, the ELEMENT_ID key must be equal to element ID. Value attribute of this element will contain the result.

arPath Associative array that specifies a path. The array can be empty or contain one of the following keys:
  • PATH - specified path;
  • SITE - site id.
select Specifies which objects can be selected by user in dialog:
  • "F" - select only files;
  • "D" - select only directories.
operation Determines file dialog operation mode:
  • "O" - open files or directories
  • "S" - save files
showUploadTab Specifies to show file upload tab (enabled only if operation = "O"):
  • true - show;
  • false - do not show.
showAddToMenuTab Specifies to show page add to menu tab (enabled only if operation = "S"):
  • true - show;
  • false - do not show.
fileFilter File filter by extension, can have the following values:
  • "" - filter is unavailable (dropdown list won't be displayed);
  • "image" - preset file filter option ("All images");
  • "ext1,ext2,ext3" - string with file extensions list (this example has ext1,ext2,ext3), comma-separated.
allowAllFiles Specifies for users to use the "All files(*.*)" option in the filter filter (only enabled if the fileFilter parameter is not equal ""):
  • true - allow;
  • false - do not allow.
SaveConfig Specifies to save user settings for dialog (type, sorting, path):
  • true - save;
  • false - do not save.

Example of calling dialog to open file:


CAdminFileDialog::ShowScript(Array
	(
		"event" => "OpenImage",
		"arResultDest" => Array("FUNCTION_NAME" => "SetImageUrl"),
		"arPath" => Array(),
		"select" => 'F',
		"operation" => 'O',
		"showUploadTab" => true,
		"showAddToMenuTab" => false,
		"fileFilter" => 'image',
		"allowAllFiles" => true,
		"saveConfig" => true
	)
);

<script>
document.getElementById("open_dialog_button").oncl ick = OpenImage;
var SetImageUrl = function(filename,path,site)
{
	// Result processing
	alert("filename = "+filename+"; /n path = "+path+"; /n site = "+site);
}
</script>


© «Bitrix24», 2001-2024
Up