46 print
"Error, template page ".basename(__FILE__).
" can't be called with no object defined.";
50@phan-var-force ?string $fk_element
51@phan-var-force ?Task[] $tasksarray
56<!-- BEGIN PHP TEMPLATE SUBTOTAL_AJAXROW.TPL.PHP - Script to enable drag and drop on lines of a
table using subtotal lines -->
59$fk_element = empty(
$object->fk_element) ? $fk_element :
$object->fk_element;
60$table_element_line = (empty($table_element_line) ?
$object->table_element_line : $table_element_line);
61$nboflines = count(
$object->lines);
63$tagidfortablednd = (empty($tagidfortablednd) ?
'tablelines' : $tagidfortablednd);
64$filepath = (empty($filepath) ?
'' : $filepath);
65$langs->load(
"subtotals");
67if (
GETPOST(
'action',
'aZ09') !=
'editline' && $nboflines > 1 &&
$conf->browser->layout !=
'phone') { ?>
68<div
id=
"notification-message" hidden=
""></div>
70function openDialog() {
72 console.log(
"open dialog");
73 jQuery(
"#notification-message").dialog({
78 jQuery(
this).dialog(
'close');
86 $(
".imgupforline").hide();
87 $(
".imgdownforline").hide();
88 $(
".lineupdown").removeAttr(
'href');
90 console.log(
"init() Prepare tableDnd for #<?php echo $tagidfortablednd; ?>");
92 $(
".tdlineupdown").each(
function (tdindex, tdline) {
93 var gripimg = tdline.dataset.gripimg ??
'grip.png';
95 $(tdline).css(
"background-image",
'url(<?php echo DOL_URL_ROOT.'/theme/
'.$conf->theme.'/img/
'; ?>' + gripimg +
')');
96 $(tdline).css(
"background-repeat",
"no-repeat");
97 $(tdline).css(
"background-position",
"center center");
101 var inital_table = $(
"#<?php echo $tagidfortablednd; ?> .drag").map((_, el) => $(el)[0]).
get();
103 $(
"#<?php echo $tagidfortablednd; ?>").tableDnD({
104 onDragStart:
function (
table, row) {
105 if (row.parentNode.dataset.level > 0) {
107 $(
"#<?php echo $tagidfortablednd; ?> .drag").each(
108 function (intIndex) {
110 if ($(
this)[0].dataset.level>-row.parentNode.dataset.level && $(
this)[0].dataset.level<=row.parentNode.dataset.level) {
114 rowsToMove.unshift($(
this));
115 if (Math.abs($(
this)[0].dataset.level) <= Math.abs(row.parentNode.dataset.level)) {
119 if ($(
this)[0].
id === row.parentNode.id) {
120 rowsToMove.unshift($(this));
125 rowsToMove.forEach(
function ($hiddenRow, i) {
126 if (i<rowsToMove.length-1) {
135 onDragStop:
function(
table, row) {
136 if (rowsToMove.length !== 0) {
137 rowsToMove.forEach(
function (hiddenRow) {
138 hiddenRow.insertAfter($(
"#" + row.id));
144 if (row.dataset.desc !== undefined) {
145 checkLinePosition(row, inital_table);
147 inital_table = $(
"#<?php echo $tagidfortablednd; ?> .drag").map((_, el) => $(el)[0]).get();
149 var reloadpage =
"<?php echo $forcereloadpage; ?>";
150 console.log(
"tableDND onDrop");
151 console.log(decodeURI($(
"#<?php echo $tagidfortablednd; ?>").tableDnDSerialize()));
152 $(
'#<?php echo $tagidfortablednd; ?> tr[data-element=extrafield]').attr(
'id',
'');
153 $(
'#<?php echo $tagidfortablednd; ?> tr[data-ignoreidfordnd=1]').attr(
'id',
'');
154 var roworder = cleanSerialize(decodeURI($(
"#<?php echo $tagidfortablednd; ?>").tableDnDSerialize()));
155 var table_element_line =
"<?php echo $table_element_line; ?>";
156 var fk_element =
"<?php echo $fk_element; ?>";
157 var element_id =
"<?php echo $id; ?>";
158 var filepath =
"<?php echo urlencode($filepath); ?>";
159 var token =
"<?php echo currentToken(); ?>";
160 $.post(
"<?php echo DOL_URL_ROOT; ?>/core/ajax/row.php",
163 table_element_line: table_element_line,
164 fk_element: fk_element,
165 element_id: element_id,
170 console.log(
"tableDND end of ajax call");
171 console.log(roworder, table_element_line, fk_element, element_id, filepath, token);
172 if (reloadpage == 1) {
174 $redirectURL = empty($urltorefreshaftermove) ? ($_SERVER[
'PHP_SELF'].
'?'.
dol_escape_js($_SERVER[
'QUERY_STRING'])) : $urltorefreshaftermove;
176 $redirectURL = preg_replace(
'/(&|\?)action=[^&#]*/',
'', $redirectURL);
178 location.href =
'<?php echo dol_escape_js($redirectURL); ?>';
182 onDragClass:
"dragClass",
183 dragHandle:
"td.tdlineupdown"
185 $(
".tdlineupdown").hover(
function() { $(
this).addClass(
'showDragHandle'); },
186 function() { $(
this).removeClass(
'showDragHandle'); }
190function checkLinePosition(row, inital_table) {
191 const tbody = $(
"#<?php echo $tagidfortablednd; ?> .drag").map((_, el) => $(el)[0]).get();
193 for (var k = 0; k < tbody.length; k++) {
194 const currentRow = tbody[k];
195 if (currentRow.dataset.rang !== undefined) {
196 currentRow.dataset.rang = k+1;
200 var rowLevel = parseInt(row.dataset.level);
201 var cancelLineMove =
false;
202 var found_title = rowLevel >= 0;
203 var ignore_level = 0;
205 for (var i = row.dataset.rang-2; i >= 0; i--) {
207 if (tbody[i].dataset.desc !== undefined) {
208 const currentRowLevel1 = parseInt(tbody[i].dataset.level, 10);
209 console.log(currentRowLevel1, -rowLevel, currentRowLevel1 < -rowLevel);
212 if (currentRowLevel1 <= ignore_level && ignore_level !== 0) {
215 }
else if (-currentRowLevel1 === rowLevel) {
217 }
else if (currentRowLevel1 > 0 && currentRowLevel1 < rowLevel) {
218 if (rowLevel - currentRowLevel1 > 1) {
219 $(
"#notification-message").text(
"<?php echo $langs->trans("PreviousTitleLevelTooHigh
"); ?>");
220 cancelLineMove =
true;
225 }
else if (currentRowLevel1 === rowLevel) {
226 for (var j = row.dataset.rang; j < tbody.length; j++) {
227 if (tbody[j].dataset.desc !== undefined) {
228 const currentRowLevel2 = parseInt(tbody[j].dataset.level, 10);
229 if (tbody[i].dataset.desc === tbody[j].dataset.desc && currentRowLevel1 === -currentRowLevel2) {
230 $(
"#notification-message").text(
"<?php echo $langs->trans("TitleUnderSameLevelSTLine
"); ?>");
231 cancelLineMove =
true;
236 }
else if (currentRowLevel1 > rowLevel) {
237 for (var j = row.dataset.rang; j < tbody.length; j++) {
238 if (tbody[j].dataset.desc !== undefined) {
239 const currentRowLevel2 = parseInt(tbody[j].dataset.level, 10);
240 if (row.dataset.desc !== tbody[j].dataset.desc && currentRowLevel2 <= -rowLevel) {
241 $(
"#notification-message").text(
"<?php echo $langs->trans("TitleAfterStLineOfSameLevelTitle
"); ?>");
242 cancelLineMove =
true;
248 }
else if (currentRowLevel1 < -rowLevel) {
249 ignore_level = currentRowLevel1;
251 $(
"#notification-message").text(
"<?php echo $langs->trans("TitleUnderSameLevelOrGreater
"); ?>");
252 cancelLineMove =
true;
255 }
else if (rowLevel < 0) {
257 if (currentRowLevel1 < 0 && rowLevel <= currentRowLevel1 || currentRowLevel1 >0 && -rowLevel >= currentRowLevel1) {
258 console.log(rowLevel, currentRowLevel1);
259 if (tbody[i].dataset.desc === row.dataset.desc) {
262 }
else if (-rowLevel === currentRowLevel1) {
263 $(
"#notification-message").text(
"<?php echo $langs->trans("STLineUnderCorrespondingTitleDesc
"); ?>");
264 cancelLineMove =
true;
266 }
else if (-rowLevel > currentRowLevel1) {
267 $(
"#notification-message").text(
"<?php echo $langs->trans("STLineUnderCorrespondingTitle
"); ?>");
268 cancelLineMove =
true;
276 $(
"#notification-message").text(
"<?php echo $langs->trans("STLineUnderTitle
"); ?>");
277 cancelLineMove =
true;
280 if (cancelLineMove) {
281 const tbody_to_replace = $(row).parent()[0];
282 $(tbody_to_replace).empty();
283 $(tbody_to_replace).append(inital_table);
289$(document).ready(
function(){
296$(document).ready(
function(){
297 $(
".imgupforline").hide();
298 $(
".imgdownforline").hide();
299 $(
".lineupdown").removeAttr(
'href');
303<!-- END PHP TEMPLATE AJAXROW.TPL.PHP -->
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
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.