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