dolibarr 23.0.3
ajaxrow.tpl.php
1<?php
2/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2010-2025 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
43// Protection to avoid direct call of template
44if (empty($object) || !is_object($object)) {
45 print "Error, template page ".basename(__FILE__)." can't be called with no object defined.";
46 exit;
47}
48'
49@phan-var-force ?string $fk_element
50@phan-var-force ?Task[] $tasksarray
51';
52
53?>
54
55<!-- BEGIN PHP TEMPLATE AJAXROW.TPL.PHP - Script to enable drag and drop on lines of a table -->
56<?php
57$id = $object->id;
58$fk_element = empty($object->fk_element) ? $fk_element : $object->fk_element;
59$table_element_line = (empty($table_element_line) ? $object->table_element_line : $table_element_line);
60$nboflines = (isset($object->lines) ? count($object->lines) : (isset($tasksarray) ? count($tasksarray) : (empty($nboflines) ? 0 : $nboflines)));
61$forcereloadpage = getDolGlobalInt('MAIN_FORCE_RELOAD_PAGE');
62$tagidfortablednd = (empty($tagidfortablednd) ? 'tablelines' : $tagidfortablednd);
63$filepath = (empty($filepath) ? '' : $filepath);
64
65if (GETPOST('action', 'aZ09') != 'editline' && $nboflines > 1 && $conf->browser->layout != 'phone') { ?>
66<script>
67$(document).ready(function(){
68 $(".imgupforline").hide();
69 $(".imgdownforline").hide();
70 $(".lineupdown").removeAttr('href');
71 $(".tdlineupdown").css("background-image",'url(<?php echo DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/grip.png'; ?>)');
72 $(".tdlineupdown").css("background-repeat","no-repeat");
73 $(".tdlineupdown").css("background-position","center center");
74
75 console.log("Prepare tableDnd for #<?php echo $tagidfortablednd; ?>");
76 $("#<?php echo $tagidfortablednd; ?>").tableDnD({
77 onDrop: function(table, row) {
78 var page_y = jQuery(document).scrollTop();
79 var reloadpage = "<?php echo $forcereloadpage; ?>";
80 console.log("tableDND onDrop");
81 console.log(decodeURI($("#<?php echo $tagidfortablednd; ?>").tableDnDSerialize()));
82 $('#<?php echo $tagidfortablednd; ?> tr[data-element=extrafield]').attr('id', ''); // Set extrafields id to empty value in order to ignore them in tableDnDSerialize function
83 $('#<?php echo $tagidfortablednd; ?> tr[data-ignoreidfordnd=1]').attr('id', ''); // Set id to empty value in order to ignore them in tableDnDSerialize function
84 var roworder = cleanSerialize(decodeURI($("#<?php echo $tagidfortablednd; ?>").tableDnDSerialize()));
85 var table_element_line = "<?php echo $table_element_line; ?>";
86 var fk_element = "<?php echo $fk_element; ?>";
87 var element_id = "<?php echo $id; ?>";
88 var filepath = "<?php echo urlencode($filepath); ?>";
89 var token = "<?php echo currentToken(); ?>"; // We use old 'token' and not 'newtoken' for Ajax call because the ajax page has the NOTOKENRENEWAL constant set.
90 $.post("<?php echo DOL_URL_ROOT; ?>/core/ajax/row.php",
91 {
92 roworder: roworder,
93 table_element_line: table_element_line,
94 fk_element: fk_element,
95 element_id: element_id,
96 filepath: filepath,
97 token: token
98 },
99 function() {
100 console.log("tableDND end of ajax call, reloadpage = " + reloadpage);
101 if (reloadpage == 1) {
102 <?php
103 $redirectURL = empty($urltorefreshaftermove) ? ($_SERVER['PHP_SELF'].'?'.dol_escape_js($_SERVER['QUERY_STRING'])) : $urltorefreshaftermove;
104 // remove some parameters from URL
105 $redirectURL = preg_replace('/(&|\?)action=[^&#]*/', '', $redirectURL);
106 $redirectURL = preg_replace('/(&|\?)page_y=[^&#]*/', '', $redirectURL);
107 ?>
108 location.href = '<?php echo dol_escape_js($redirectURL); ?>&page_y='+page_y;
109 } else {
110 $("#<?php echo $tagidfortablednd; ?> .drag").each(
111 function( intIndex ) {
112 // $(this).removeClass("pair impair");
113 //if (intIndex % 2 == 0) $(this).addClass('impair');
114 //if (intIndex % 2 == 1) $(this).addClass('pair');
115 });
116 }
117 });
118 },
119 onDragClass: "dragClass",
120 dragHandle: "td.tdlineupdown"
121 });
122 $(".tdlineupdown").hover( function() { $(this).addClass('showDragHandle'); },
123 function() { $(this).removeClass('showDragHandle'); }
124 );
125});
126</script>
127<?php } else { ?>
128<script>
129$(document).ready(function(){
130 $(".imgupforline").hide();
131 $(".imgdownforline").hide();
132 $(".lineupdown").removeAttr('href');
133});
134</script>
135<?php } ?>
136<!-- END PHP TEMPLATE AJAXROW.TPL.PHP -->
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
treeview li table
No Email.