list.tpl.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. /* Copyright (C) 2017-2022 Regis Houssin <regis.houssin@inodbox.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, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. */
  19. // Protection to avoid direct call of template
  20. if (empty($conf) || !is_object($conf)) {
  21. print "Error, template page can't be called as URL";
  22. exit;
  23. }
  24. dol_include_once('/multicompany/admin/tpl/switch.tpl.php');
  25. $colHidden = (!empty($conf->global->MULTICOMPANY_COLHIDDEN) ? implode(",", json_decode($conf->global->MULTICOMPANY_COLHIDDEN, true)) : null);
  26. $colOrder = (!empty($conf->global->MULTICOMPANY_COLORDER) ? json_decode($conf->global->MULTICOMPANY_COLORDER, true) : array('id' => 0, 'direction' => 'asc'));
  27. $columns = array();
  28. $columns['id'] = array(
  29. 'label' => 'ID',
  30. 'sortable' => true,
  31. 'searchable' => true,
  32. 'priority' => 12,
  33. 'center' => 'dt-center'
  34. );
  35. $columns['label'] = array(
  36. 'label' => 'Label',
  37. 'sortable' => true,
  38. 'searchable' => true,
  39. 'priority' => 1,
  40. );
  41. $columns['description'] = array(
  42. 'label' => 'Description',
  43. 'sortable' => true,
  44. 'searchable' => true,
  45. 'priority' => 11,
  46. );
  47. $columns['name'] = array(
  48. 'label' => 'Name',
  49. 'priority' => 10,
  50. 'center' => 'dt-center'
  51. );
  52. $columns['zip'] = array(
  53. 'label' => 'Zip',
  54. 'priority' => 9,
  55. 'center' => 'dt-center'
  56. );
  57. $columns['town'] = array(
  58. 'label' => 'Town',
  59. 'priority' => 8,
  60. 'center' => 'dt-center'
  61. );
  62. $columns['country'] = array(
  63. 'label' => 'Country',
  64. 'priority' => 7,
  65. 'center' => 'dt-center'
  66. );
  67. $columns['currency'] = array(
  68. 'label' => 'Currency',
  69. 'priority' => 6,
  70. 'center' => 'dt-center'
  71. );
  72. $columns['language'] = array(
  73. 'label' => 'DefaultLanguageShort',
  74. 'priority' => 5,
  75. 'center' => 'dt-center'
  76. );
  77. if (!empty($this->tpl['extrafields']->attribute_label)) {
  78. foreach ($this->tpl['extrafields']->attribute_label as $key => $value)
  79. {
  80. $columns[$key] = array(
  81. 'label' => $value,
  82. 'center' => 'dt-center'
  83. );
  84. }
  85. }
  86. $columns['visible'] = array(
  87. 'label' => 'Visible',
  88. 'width' => '20px',
  89. 'priority' => 3,
  90. 'center' => 'dt-center'
  91. );
  92. $columns['active'] = array(
  93. 'label' => 'Status',
  94. 'width' => '20px',
  95. 'priority' => 2,
  96. 'center' => 'dt-center'
  97. );
  98. $columns['tools'] = array(
  99. 'label' => 'Tools',
  100. 'width' => '50px',
  101. 'priority' => 4,
  102. 'center' => 'dt-center'
  103. );
  104. //var_dump($columns);
  105. ?>
  106. <!-- BEGIN PHP TEMPLATE -->
  107. <script type="text/javascript">
  108. $(document).ready(function() {
  109. $("#multicompany_entity_list").dataTable( {
  110. "dom": 'B<"clear">lfrtip',
  111. //"responsive": true,
  112. "buttons": [
  113. {
  114. "extend": "colvis",
  115. "text": "<?php echo $langs->transnoentities('ShowHideColumns'); ?>"
  116. }
  117. ],
  118. "pagingType": "full_numbers",
  119. "columns": [
  120. <?php foreach($columns as $key => $values) { ?>
  121. {
  122. "name": "entity_<?php echo $key; ?>",
  123. "data": "entity_<?php echo $key; ?>",
  124. <?php if (!empty($values['sortable'])) { ?>
  125. "sortable": true,
  126. <?php } ?>
  127. <?php if (!empty($values['searchable'])) { ?>
  128. "searchable": true,
  129. <?php } ?>
  130. <?php if (!empty($values['width'])) { ?>
  131. "width": "<?php echo $values['width']; ?>",
  132. <?php } ?>
  133. <?php if (!empty($values['center'])) { ?>
  134. "class": "<?php echo $values['center']; ?>",
  135. <?php } ?>
  136. <?php //if (!empty($values['priority'])) { ?>
  137. //"responsivePriority": <?php //echo $values['priority']; ?>,
  138. <?php //} ?>
  139. },
  140. <?php } ?>
  141. ],
  142. "columnDefs": [
  143. { "targets": '_all', "sortable": false },
  144. { "targets": '_all', "searchable": false },
  145. <?php if (!empty($colHidden)) { ?>
  146. { "visible": false, "targets": [ <?php echo $colHidden; ?> ] }
  147. <?php } ?>
  148. ],
  149. "language": {
  150. "lengthMenu": "<?php echo $langs->transnoentities('Showing'); ?> _MENU_ <?php echo $langs->transnoentities('LineEntries'); ?>",
  151. "search": "<?php echo $langs->transnoentities('Search'); ?>:",
  152. "processing": "<?php echo $langs->transnoentities('Processing'); ?>",
  153. "zeroRecords": "<?php echo $langs->transnoentities('NoRecordsToDisplay'); ?>",
  154. "infoEmpty": "<?php echo $langs->transnoentities('NoEntriesToShow'); ?>",
  155. "infoFiltered": "(<?php echo $langs->transnoentities('FilteredFrom'); ?> _MAX_ <?php echo $langs->transnoentities('TotalEntries'); ?>)",
  156. "info": "<?php echo $langs->transnoentities('ShowingOf'); ?> _START_ <?php echo $langs->transnoentities('To'); ?> _END_ <?php echo $langs->transnoentities('TotalOf'); ?> _TOTAL_ <?php echo $langs->transnoentities('LineEntries'); ?>",
  157. "paginate": {
  158. "first": "<?php echo $langs->transnoentities('First'); ?>",
  159. "last": "<?php echo $langs->transnoentities('Last'); ?>",
  160. "previous": "<?php echo $langs->transnoentities('Previous'); ?>",
  161. "next": "<?php echo $langs->transnoentities('Next'); ?>"
  162. }
  163. },
  164. "processing": true,
  165. "serverSide": true,
  166. "deferRender": true,
  167. "pageLength": 25,
  168. <?php if (!empty($colOrder)) { ?>
  169. "order": [[ <?php echo $colOrder['id']; ?>,"<?php echo $colOrder['direction']; ?>" ]],
  170. <?php } ?>
  171. "ajax": {
  172. "url": "<?php echo dol_buildpath('/multicompany/core/ajax/list.php', 1); ?>",
  173. "type": "POST"
  174. }
  175. });
  176. $('#multicompany_entity_list').on( 'order.dt', function ( e, settings, column ) {
  177. //console.log(column);
  178. var newid = column[0]['col'];
  179. var newdir = column[0]['dir'];
  180. var currentid = <?php echo $colOrder['id']; ?>;
  181. var currentdir = "<?php echo $colOrder['direction']; ?>";
  182. if (currentid != newid || currentdir != newdir) {
  183. $.post( "<?php echo dol_buildpath('/multicompany/core/ajax/functions.php',1); ?>", {
  184. "action" : "setColOrder",
  185. "id" : newid,
  186. "dir" : newdir,
  187. "token": "<?php echo currentToken(); ?>"
  188. },
  189. function (result) {
  190. }
  191. );
  192. }
  193. });
  194. $('#multicompany_entity_list').on( 'column-visibility.dt', function ( e, settings, column, state ) {
  195. //console.log('Column '+ column +' has changed to '+ (state ? 'visible' : 'hidden'));
  196. $.post( "<?php echo dol_buildpath('/multicompany/core/ajax/functions.php',1); ?>", {
  197. "action" : "setColHidden",
  198. "id" : column,
  199. "state" : (state ? 'visible' : 'hidden'),
  200. "token": "<?php echo currentToken(); ?>"
  201. },
  202. function (result) {
  203. }
  204. );
  205. });
  206. });
  207. </script>
  208. <table width="100%" id="multicompany_entity_list">
  209. <thead>
  210. <tr>
  211. <?php
  212. foreach($columns as $key => $values) {
  213. //$moreattr = (!empty($values['priority'])?'data-priority="'.$values['priority'].'"':'');
  214. echo getTitleFieldOfList($values['label'], 1, '', '', '', '', '', '', '', 'entity_' . $key . ' ');
  215. }
  216. ?>
  217. </tr>
  218. </thead>
  219. <tbody>
  220. <tr>
  221. <td colspan="5" class="dataTables_empty"><?php echo $langs->trans('LoadingDataFromServer'); ?></td>
  222. </tr>
  223. </tbody>
  224. </table></div>
  225. <div class="tabsAction">
  226. <a class="butAction" href="<?php echo $_SERVER["PHP_SELF"]; ?>?action=create"><?php echo $langs->trans('AddEntity'); ?></a>
  227. </div>
  228. <!-- END PHP TEMPLATE -->