1
Hello!
I did for my own purposes form element to set the directory (and path). But if somebody is interested in it any suggestions welcome. This is a very preliminary version (some things are hardcoded). Maybe it will be useful for someone.
I used jqueryFileTree plugin to display directories (it points uploads dir). After opening the folder the path is copied to the text box (can also be edited manually). The form sends the value of this textbox for further processing.
For demo download and install this module
pfxfp.zip/modules/pfxfp/class/formelement/formtextdirpath.php
class pf_XoopsFormDirPath extends XoopsFormText
{
function pf_XoopsFormDirPath($caption, $name, $size = 15, $value= 0)
{
//$value = !is_numeric($value) ? time() : intval($value);
$this->XoopsFormText($caption, $name, $size, 255, $value);
$this->addScript();
}
function addScript()
{
global $xoTheme, $xoopsModule;
$ele_name = $this->getName();
$dirname = XOOPS_URL.'/modules/'.$xoopsModule->getVar("dirname");
$xoTheme->addScript($dirname . '/js/jqueryFileTree/jqueryFileTree.js');
$xoTheme->addStylesheet($dirname . '/js/jqueryFileTree/jqueryFileTree.css');
$xoTheme->addScript(null, array( 'type' => 'application/x-javascript' ), '
$(document).ready( function() {
$('#uploadsdir_'.$ele_name.'').fileTree({
root: ''.XOOPS_ROOT_PATH.'/uploads/',
script: ''.$dirname.'/js/jqueryFileTree/connectors/jqueryFileTree.php',
folderclicked: function(node) { $('#'.$ele_name.'').val(node);
}
},
function(file) {
alert(file);
});
});
');
}
function render()
{
$ele_name = $this->getName();
$ele_value = $this->getValue();
return '<div id="uploadsdir_'.$ele_name.'" style="height:200px;width:50%;border:1px solid #ccc;overflow:auto;">div><input type="text" name="'.$ele_name.'" id="'.$ele_name.'" size="'.$this->getSize().'" value="'.$ele_value.'"'.$this->getExtra().' />';
}
}
usage:
/modules/pfxfp/index.php
include_once(XOOPS_ROOT_PATH."/class/xoopsformloader.php");
include_once(PFXFP_ROOT_PATH."/class/formelement/formtextdirpath.php");
$form = new XoopsThemeForm('test', 'frmCategory', 'category.php');
[...]
//DIRECTORY BROWSER
$form->addElement(new pf_XoopsFormDirPath('Destination', 'dbf_dir', 50, ''), false);
[...]
$form->display();