dolibarr 24.0.0-beta
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<!-- BEGIN PHP TEMPLATE AJAXROW.TPL.PHP - Script to enable drag and drop on lines of a table -->
55<?php
56
57$redirectURL = empty($urltorefreshaftermove) ? ($_SERVER['PHP_SELF'].'?'.dol_escape_js($_SERVER['QUERY_STRING'])) : $urltorefreshaftermove;
58// remove some parameters from URL
59$redirectURL = preg_replace('/(&|\?)action=[^&#]*/', '', $redirectURL);
60$redirectURL = preg_replace('/(&|\?)page_y=[^&#]*/', '', $redirectURL);
61
62$nboflines = (isset($object->lines) ? count($object->lines) : (isset($tasksarray) ? count($tasksarray) : (empty($nboflines) ? 0 : $nboflines)));
63
64$jsConf = [
65 'object' => [
66 'id' => $object->id,
67 'fkElement' => empty($object->fk_element) ? $fk_element : $object->fk_element,
68 'tableElementLine' => (empty($table_element_line) ? $object->table_element_line : $table_element_line),
69 'nbOfLines' => $nboflines,
70 ],
71 'forceReloadPage' => getDolGlobalInt('MAIN_FORCE_RELOAD_PAGE'),
72 'tagIdForTableDND' => (empty($tagidfortablednd) ? 'tablelines' : $tagidfortablednd),
73 'filePath' => (empty($filepath) ? '' : $filepath),
74 'activeAjaxReorder' => GETPOST('action', 'aZ09') != 'editline' && $nboflines > 1 && $conf->browser->layout != 'phone',
75 'gripImg' => DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/grip.png',
76 'token' => currentToken(), // We use old 'token' and not 'newtoken' for Ajax call because the ajax page has the NOTOKENRENEWAL constant set.
77 'DOL_URL_ROOT' => DOL_URL_ROOT,
78 'redirectURL' => $redirectURL
79];
80
81?>
82<script nonce="<?php print getNonce(); ?>">
83Dolibarr.on('Ready', function() {
105 const jsConf = <?php print json_encode($jsConf); ?>;
106
107 const applyCssAndDisplay = function() {
108 $(".imgupforline").hide();
109 $(".imgdownforline").hide();
110 $(".lineupdown").removeAttr('href');
111
112 if(jsConf.activeAjaxReorder) {
113 $(".tdlineupdown").css("background-image",`url(${jsConf.gripImg})`);
114 $(".tdlineupdown").css("background-repeat","no-repeat");
115 $(".tdlineupdown").css("background-position","center center");
116 }
117 }
118
119
120 let tableDnDInstance = null;
121
122 function initTableDnD() {
123 if (!jsConf.activeAjaxReorder) return;
124
125 Dolibarr.log("Prepare tableDnd for #" + jsConf.tagIdForTableDND);
126 // TODO : replace old tableDnD with modern SortableJS
127 tableDnDInstance = $("#" + jsConf.tagIdForTableDND).tableDnD({
128 onDrop: function (table, row) {
129 var page_y = jQuery(document).scrollTop();
130 var reloadpage = jsConf.forceReloadPage;
131 Dolibarr.log("tableDND onDrop");
132 Dolibarr.log(decodeURI($("#" + jsConf.tagIdForTableDND).tableDnDSerialize()));
133 $(`#${jsConf.tagIdForTableDND} tr[data-element=extrafield]`).attr('id', ''); // Set extrafields id to empty value in order to ignore them in tableDnDSerialize function
134 $(`#${jsConf.tagIdForTableDND} tr[data-ignoreidfordnd=1]`).attr('id', ''); // Set id to empty value in order to ignore them in tableDnDSerialize function
135 var roworder = cleanSerialize(decodeURI($(`#${jsConf.tagIdForTableDND}`).tableDnDSerialize()));
136 var table_element_line = jsConf.object.tableElementLine;
137 var fk_element = jsConf.object.fkElement;
138 var element_id = jsConf.object.id;
139 var filepath = decodeURIComponent(jsConf.filePath);
140
141 let postData = {
142 roworder: roworder,
143 table_element_line: table_element_line,
144 fk_element: fk_element,
145 element_id: element_id,
146 filepath: filepath,
147 token: jsConf.token
148 };
149
150 $.post(`${jsConf.DOL_URL_ROOT}/core/ajax/row.php`,
151 postData,
152 function () {
153 Dolibarr.log("tableDND end of ajax call, reloadpage = " + reloadpage);
154
155 Dolibarr.executeHook('documentRowMoved', postData)
156
157 if (reloadpage == 1) {
158 location.href = jsConf.redirectURL + '&page_y=' + page_y;
159 }
160 }
161 );
162 },
163 onDragClass: "dragClass",
164 dragHandle: "td.tdlineupdown"
165 });
166
167 $(".tdlineupdown").on("mouseenter", function () {
168 $(this).addClass("showDragHandle");
169 }).on("mouseleave", function () {
170 $(this).removeClass("showDragHandle");
171 });
172 }
173
174 applyCssAndDisplay();
175 initTableDnD();
176
177 Dolibarr.on('reloadDocumentLine', function (data) {
178 Dolibarr.log('triggered by hook reloadDocumentLine : TEMPLATE AJAXROW.TPL.PHP')
179 applyCssAndDisplay();
180 initTableDnD();
181 });
182
183});
184</script>
185<!-- END PHP TEMPLATE AJAXROW.TPL.PHP -->
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.