2012-09-07 13:22:37 +02:00
< ? php
2018-10-27 14:43:12 +02:00
/* Copyright ( C ) 2012 Regis Houssin < regis . houssin @ inodbox . com >
2018-10-19 12:47:59 +02:00
* Copyright ( C ) 2018 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-09-07 13:22:37 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2012-09-07 13:22:37 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2014-04-28 01:46:11 +02:00
*
2013-11-17 02:59:01 +01:00
* Output javascript for interactions code of ecm module
2021-09-26 20:35:54 +02:00
* $conf , $module , $param , $preopened , $nameforformuserfile may be defined
2012-09-07 13:22:37 +02:00
*/
2017-12-21 13:32:16 +01:00
// Protection to avoid direct call of template
2021-02-25 22:26:26 +01:00
if ( empty ( $conf ) || ! is_object ( $conf )) {
2017-12-27 20:17:08 +01:00
print " Error, template enablefiletreeajax.tpl.php can't be called as URL " ;
2017-12-21 13:32:16 +01:00
exit ;
}
2013-11-17 02:59:01 +01:00
?>
2012-09-07 13:22:37 +02:00
2014-04-28 01:46:11 +02:00
<!-- BEGIN PHP TEMPLATE ecm / tpl / enablefiletreeajax . tpl . php -->
2018-10-18 21:22:30 +02:00
<!-- Doc of fileTree plugin at https :// www . abeautifulsite . net / jquery - file - tree -->
2012-09-07 13:22:37 +02:00
2013-11-17 02:59:01 +01:00
< script type = " text/javascript " >
2012-09-07 13:33:13 +02:00
2013-11-17 02:59:01 +01:00
< ? php
2021-02-25 22:26:26 +01:00
if ( empty ( $module )) {
$module = 'ecm' ;
}
2022-06-08 20:07:16 +02:00
if ( empty ( $nameforformuserfile )) {
$nameforformuserfile = '' ;
}
2020-04-10 10:59:32 +02:00
$paramwithoutsection = preg_replace ( '/&?section=(\d+)/' , '' , $param );
2017-08-20 23:16:20 +02:00
2020-04-10 10:59:32 +02:00
$openeddir = '/' ; // The root directory shown
2018-10-18 21:22:30 +02:00
// $preopened // The dir to have preopened
2012-09-07 13:22:37 +02:00
?>
2013-11-17 02:59:01 +01:00
$ ( document ) . ready ( function () {
2014-04-28 01:46:11 +02:00
$ ( '#filetree' ) . fileTree ({
2013-11-17 02:59:01 +01:00
root : '<?php print dol_escape_js($openeddir); ?>' ,
2017-11-10 13:45:38 +01:00
// Ajax called if we click to expand a dir (not a file). Parameter 'dir' is provided as a POST parameter by fileTree code to this following URL.
2021-09-26 20:35:54 +02:00
// We must use token=currentToken() and not newToken() here because ajaxdirtree has NOTOKENRENEWAL define so there is no rollup of token so we must compare with the one valid on main page
script : '<?php echo DOL_URL_ROOT.' / core / ajax / ajaxdirtree . php ? token = '.currentToken().' & modulepart = '.urlencode($module).(empty($preopened) ? ' ' : ' & preopened = '.urlencode($preopened)).' & openeddir = '.urlencode($openeddir).(empty($paramwithoutsection) ? ' ' : $paramwithoutsection); ?>' ,
2013-11-17 02:59:01 +01:00
folderEvent : 'click' , // 'dblclick'
multiFolder : false },
// Called if we click on a file (not a dir)
2012-09-07 13:22:37 +02:00
function ( file ) {
2017-11-18 15:41:30 +01:00
console . log ( " We click on a file " );
2012-09-07 13:22:37 +02:00
$ ( " #mesg " ) . hide ();
loadandshowpreview ( file , 0 );
2013-11-17 02:59:01 +01:00
},
// Called if we click on a dir (not a file)
function ( elem ) {
2014-09-03 16:09:14 +02:00
id = elem . attr ( 'id' ) . substr ( 12 ); // We get id that is 'fmdirlia_id_xxx' (id we want is xxx)
2017-11-18 15:41:30 +01:00
rel = elem . attr ( 'rel' )
console . log ( " We click on a dir, we call the ajaxdirtree.php with modulepart=<?php echo $module ; ?>, param=<?php echo $paramwithoutsection ; ?> " );
2021-05-01 15:12:30 +02:00
console . log ( " We also save id and dir name into <?php echo $nameforformuserfile ?>_section_id|dir (vars into form to attach new file in filemanager.tpl.php) with id= " + id + " and rel= " + rel );
2017-11-18 15:41:30 +01:00
jQuery ( " #<?php echo $nameforformuserfile ?>_section_dir " ) . val ( rel );
2017-11-10 13:45:38 +01:00
jQuery ( " #<?php echo $nameforformuserfile ?>_section_id " ) . val ( id );
2017-11-18 15:41:30 +01:00
jQuery ( " #section_dir " ) . val ( rel );
jQuery ( " #section_id " ) . val ( id );
jQuery ( " #section " ) . val ( id );
2017-08-20 21:23:19 +02:00
jQuery ( '#<?php echo $nameforformuserfile ?>' ) . show ();
2017-11-18 15:41:30 +01:00
console . log ( " We also execute the loadandshowpreview() that is on the onclick of each li defined by ajaxdirtree " );
2012-09-07 13:22:37 +02:00
}
2017-11-18 15:41:30 +01:00
// The loadanshowpreview is also call by the 'onclick' set on each li return by ajaxdirtree
2012-09-07 13:22:37 +02:00
);
$ ( '#refreshbutton' ) . click ( function () {
2016-07-30 15:51:27 +02:00
console . log ( " Click on refreshbutton " );
2013-12-01 17:32:05 +01:00
$ . pleaseBePatient ( " <?php echo $langs->trans ('PleaseBePatient'); ?> " );
2021-10-10 21:11:48 +02:00
$ . get ( " <?php echo DOL_URL_ROOT.'/ecm/ajax/ecmdatabase.php'; ?> " , {
action : 'build' ,
token : '<?php echo newToken(); ?>' ,
element : 'ecm'
2013-12-01 17:32:05 +01:00
},
function ( response ) {
$ . unblockUI ();
2021-10-10 21:11:48 +02:00
location . href = '<?php echo $_SERVER[' PHP_SELF ']; ?>' ;
2013-12-01 17:32:05 +01:00
});
2012-09-07 13:22:37 +02:00
});
});
function loadandshowpreview ( filedirname , section )
{
//alert('filedirname='+filedirname);
2014-09-03 16:09:14 +02:00
//console.log(filedirname);
2019-01-15 15:04:15 +01:00
//console.log('loadandshowpreview for section='+section);
2014-09-03 16:09:14 +02:00
2012-09-07 13:22:37 +02:00
$ ( '#ecmfileview' ) . empty ();
2020-04-10 10:59:32 +02:00
var url = '<?php echo dol_buildpath(' / core / ajax / ajaxdirpreview . php ', 1); ?>?action=preview&module=<?php echo $module; ?>§ion=' + section + '&file=' + urlencode ( filedirname ) < ? php echo ( empty ( $paramwithoutsection ) ? '' : " +' " . $paramwithoutsection . " ' " ); ?> ;
2012-09-07 13:22:37 +02:00
$ . get ( url , function ( data ) {
//alert('Load of url '+url+' was performed : '+data);
pos = data . indexOf ( " TYPE=directory " , 0 );
//alert(pos);
if (( pos > 0 ) && ( pos < 20 ))
{
filediractive = filedirname ; // Save current dirname
filetypeactive = 'directory' ;
}
else
{
filediractive = filedirname ; // Save current dirname
filetypeactive = 'file' ;
}
$ ( '#ecmfileview' ) . append ( data );
});
}
</ script >
2017-11-05 02:04:05 +01:00
<!-- END PHP TEMPLATE ecm / tpl / enablefiletreeajax . tpl . php -->