ajaxrow.tpl.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2010-2016 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 <https://www.gnu.org/licenses/>.
  17. *
  18. * Javascript code to activate drag and drop on lines
  19. * You can use this if you want to be able to drag and drop rows of a table.
  20. * You must add id="tablelines" on table level tag
  21. * and $object and $object->id is defined
  22. * and $object->fk_element or $fk_element is defined
  23. * and have ($nboflines or count($object->lines) or count($taskarray) > 0)
  24. * and have $table_element_line = 'tablename' or $object->table_element_line with line to move
  25. *
  26. */
  27. // Protection to avoid direct call of template
  28. if (empty($object) || !is_object($object)) {
  29. print "Error, template page ".basename(__FILE__)." can't be called with no object defined.";
  30. exit;
  31. }
  32. ?>
  33. <!-- BEGIN PHP TEMPLATE AJAXROW.TPL.PHP - Script to enable drag and drop on lines of a table -->
  34. <?php
  35. $id = $object->id;
  36. $fk_element = empty($object->fk_element) ? $fk_element : $object->fk_element;
  37. $table_element_line = (empty($table_element_line) ? $object->table_element_line : $table_element_line);
  38. $nboflines = (isset($object->lines) ?count($object->lines) : (isset($tasksarray) ?count($tasksarray) : (empty($nboflines) ? 0 : $nboflines)));
  39. $forcereloadpage = empty($conf->global->MAIN_FORCE_RELOAD_PAGE) ? 0 : 1;
  40. $tagidfortablednd = (empty($tagidfortablednd) ? 'tablelines' : $tagidfortablednd);
  41. $filepath = (empty($filepath) ? '' : $filepath);
  42. if (GETPOST('action', 'aZ09') != 'editline' && $nboflines > 1 && $conf->browser->layout != 'phone') { ?>
  43. <script>
  44. $(document).ready(function(){
  45. $(".imgupforline").hide();
  46. $(".imgdownforline").hide();
  47. $(".lineupdown").removeAttr('href');
  48. $(".tdlineupdown").css("background-image",'url(<?php echo DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/grip.png'; ?>)');
  49. $(".tdlineupdown").css("background-repeat","no-repeat");
  50. $(".tdlineupdown").css("background-position","center center");
  51. console.log("Prepare tableDnd for #<?php echo $tagidfortablednd; ?>");
  52. $("#<?php echo $tagidfortablednd; ?>").tableDnD({
  53. onDrop: function(table, row) {
  54. var reloadpage = "<?php echo $forcereloadpage; ?>";
  55. console.log("tableDND onDrop");
  56. console.log(decodeURI($("#<?php echo $tagidfortablednd; ?>").tableDnDSerialize()));
  57. $('#<?php echo $tagidfortablednd; ?> tr[data-element=extrafield]').attr('id', ''); // Set extrafields id to empty value in order to ignore them in tableDnDSerialize function
  58. $('#<?php echo $tagidfortablednd; ?> tr[data-ignoreidfordnd=1]').attr('id', ''); // Set id to empty value in order to ignore them in tableDnDSerialize function
  59. var roworder = cleanSerialize(decodeURI($("#<?php echo $tagidfortablednd; ?>").tableDnDSerialize()));
  60. var table_element_line = "<?php echo $table_element_line; ?>";
  61. var fk_element = "<?php echo $fk_element; ?>";
  62. var element_id = "<?php echo $id; ?>";
  63. var filepath = "<?php echo urlencode($filepath); ?>";
  64. var token = "<?php echo currentToken(); ?>"; // We use old 'token' and not 'newtoken' for Ajax call because the ajax page has the NOTOKENRENEWAL constant set.
  65. $.post("<?php echo DOL_URL_ROOT; ?>/core/ajax/row.php",
  66. {
  67. roworder: roworder,
  68. table_element_line: table_element_line,
  69. fk_element: fk_element,
  70. element_id: element_id,
  71. filepath: filepath,
  72. token: token
  73. },
  74. function() {
  75. console.log("tableDND end of ajax call");
  76. if (reloadpage == 1) {
  77. <?php
  78. $redirectURL = empty($urltorefreshaftermove) ? ($_SERVER['PHP_SELF'].'?'.dol_escape_js($_SERVER['QUERY_STRING'])) : $urltorefreshaftermove;
  79. // remove action parameter from URL
  80. $redirectURL = preg_replace('/(&|\?)action=[^&#]*/', '', $redirectURL);
  81. ?>
  82. location.href = '<?php echo dol_escape_js($redirectURL); ?>';
  83. } else {
  84. $("#<?php echo $tagidfortablednd; ?> .drag").each(
  85. function( intIndex ) {
  86. // $(this).removeClass("pair impair");
  87. //if (intIndex % 2 == 0) $(this).addClass('impair');
  88. //if (intIndex % 2 == 1) $(this).addClass('pair');
  89. });
  90. }
  91. });
  92. },
  93. onDragClass: "dragClass",
  94. dragHandle: "td.tdlineupdown"
  95. });
  96. $(".tdlineupdown").hover( function() { $(this).addClass('showDragHandle'); },
  97. function() { $(this).removeClass('showDragHandle'); }
  98. );
  99. });
  100. </script>
  101. <?php } else { ?>
  102. <script>
  103. $(document).ready(function(){
  104. $(".imgupforline").hide();
  105. $(".imgdownforline").hide();
  106. $(".lineupdown").removeAttr('href');
  107. });
  108. </script>
  109. <?php } ?>
  110. <!-- END PHP TEMPLATE AJAXROW.TPL.PHP -->