dolibarr  9.0.0
enablefiletreeajax.tpl.php
1 <?php
2 /* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
3  * Copyright (C) 2018 Laurent Destailleur <eldy@users.sourceforge.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Output javascript for interactions code of ecm module
19  */
20 
21 // Protection to avoid direct call of template
22 if (empty($conf) || ! is_object($conf))
23 {
24  print "Error, template enablefiletreeajax.tpl.php can't be called as URL";
25  exit;
26 }
27 
28 ?>
29 
30 <!-- BEGIN PHP TEMPLATE ecm/tpl/enablefiletreeajax.tpl.php -->
31 <!-- Doc of fileTree plugin at https://www.abeautifulsite.net/jquery-file-tree -->
32 
33 <script type="text/javascript">
34 
35 <?php
36 if (empty($module)) $module='ecm';
37 $paramwithoutsection=preg_replace('/&?section=(\d+)/', '', $param);
38 
39 $openeddir='/'; // The root directory shown
40 // $preopened // The dir to have preopened
41 
42 ?>
43 
44 $(document).ready(function() {
45 
46  $('#filetree').fileTree({
47  root: '<?php print dol_escape_js($openeddir); ?>',
48  // 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.
49  script: '<?php echo DOL_URL_ROOT.'/core/ajax/ajaxdirtree.php?modulepart='.$module.(empty($preopened)?'':'&preopened='.urlencode($preopened)).'&openeddir='.urlencode($openeddir).(empty($paramwithoutsection)?'':$paramwithoutsection); ?>',
50  folderEvent: 'click', // 'dblclick'
51  multiFolder: false },
52  // Called if we click on a file (not a dir)
53  function(file) {
54  console.log("We click on a file");
55  $("#mesg").hide();
56  loadandshowpreview(file,0);
57  },
58  // Called if we click on a dir (not a file)
59  function(elem) {
60  id=elem.attr('id').substr(12); // We get id that is 'fmdirlia_id_xxx' (id we want is xxx)
61  rel=elem.attr('rel')
62  console.log("We click on a dir, we call the ajaxdirtree.php with modulepart=<?php echo $module; ?>, param=<?php echo $paramwithoutsection; ?>");
63  console.log("We also save dir name or id into <?php echo $nameforformuserfile ?>_section_... with name section_... id="+id+" rel="+rel);
64  jQuery("#<?php echo $nameforformuserfile ?>_section_dir").val(rel);
65  jQuery("#<?php echo $nameforformuserfile ?>_section_id").val(id);
66  jQuery("#section_dir").val(rel);
67  jQuery("#section_id").val(id);
68  jQuery("#section").val(id);
69  jQuery('#<?php echo $nameforformuserfile ?>').show();
70  console.log("We also execute the loadandshowpreview() that is on the onclick of each li defined by ajaxdirtree");
71  }
72  // The loadanshowpreview is also call by the 'onclick' set on each li return by ajaxdirtree
73  );
74 
75  $('#refreshbutton').click( function() {
76  console.log("Click on refreshbutton");
77  $.pleaseBePatient("<?php echo $langs->trans('PleaseBePatient'); ?>");
78  $.get( "<?php echo DOL_URL_ROOT . '/ecm/ajax/ecmdatabase.php'; ?>", {
79  action: "build",
80  element: "ecm"
81  },
82  function(response) {
83  $.unblockUI();
84  location.href="<?php echo $_SERVER['PHP_SELF']; ?>";
85  });
86  });
87 });
88 
89 function loadandshowpreview(filedirname,section)
90 {
91  //alert('filedirname='+filedirname);
92  //console.log(filedirname);
93  //console.log(section);
94 
95  $('#ecmfileview').empty();
96 
97  var url = '<?php echo dol_buildpath('/core/ajax/ajaxdirpreview.php',1); ?>?action=preview&module=<?php echo $module; ?>&section='+section+'&file='+urlencode(filedirname)<?php echo (empty($paramwithoutsection)?'':"+'".$paramwithoutsection."'"); ?>;
98  $.get(url, function(data) {
99  //alert('Load of url '+url+' was performed : '+data);
100  pos=data.indexOf("TYPE=directory",0);
101  //alert(pos);
102  if ((pos > 0) && (pos < 20))
103  {
104  filediractive=filedirname; // Save current dirname
105  filetypeactive='directory';
106  }
107  else
108  {
109  filediractive=filedirname; // Save current dirname
110  filetypeactive='file';
111  }
112  $('#ecmfileview').append(data);
113  });
114 }
115 
116 </script>
117 <!-- END PHP TEMPLATE ecm/tpl/enablefiletreeajax.tpl.php -->
print
Draft customers invoices.
Definition: index.php:91
type
Definition: viewcat.php:284