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 jQuery(
"#notification-message").dialog({
77 jQuery(
this).dialog(
'close');
85 $(
".imgupforline").hide();
86 $(
".imgdownforline").hide();
87 $(
".lineupdown").removeAttr(
'href');
88 console.log($(
".tdlineupdown"));
89 $(
".tdlineupdown").each(
function (tdindex, tdline) {
90 var gripimg = tdline.dataset.gripimg ??
'grip.png';
92 $(tdline).css(
"background-image",
'url(<?php echo DOL_URL_ROOT.'/theme/
'.$conf->theme.'/img/
'; ?>' + gripimg +
')');
93 $(tdline).css(
"background-repeat",
"no-repeat");
94 $(tdline).css(
"background-position",
"center center");
95 console.log($(
".tdlineupdown")[tdindex], tdline);
98 console.log(
"Prepare tableDnd for #<?php echo $tagidfortablednd; ?>");
99 var inital_table = $(
"#<?php echo $tagidfortablednd; ?> .drag").map((_, el) => $(el)[0]).get();
101 $(
"#<?php echo $tagidfortablednd; ?>").tableDnD({
102 onDragStart:
function (
table, row) {
103 if (row.parentNode.dataset.level > 0) {
105 $(
"#<?php echo $tagidfortablednd; ?> .drag").each(
106 function (intIndex) {
108 if ($(
this)[0].dataset.level>-row.parentNode.dataset.level && $(
this)[0].dataset.level<=row.parentNode.dataset.level) {
112 rowsToMove.unshift($(
this));
113 if (Math.abs($(
this)[0].dataset.level) <= Math.abs(row.parentNode.dataset.level)) {
117 if ($(
this)[0].
id === row.parentNode.id) {
118 rowsToMove.unshift($(this));
123 rowsToMove.forEach(
function ($hiddenRow, i) {
124 if (i<rowsToMove.length-1) {
133 onDragStop:
function(
table, row) {
134 if (rowsToMove.length !== 0) {
135 rowsToMove.forEach(
function (hiddenRow) {
136 hiddenRow.insertAfter($(
"#" + row.id));
142 if (row.dataset.desc !== undefined) {
143 checkLinePosition(row, inital_table);
145 inital_table = $(
"#<?php echo $tagidfortablednd; ?> .drag").map((_, el) => $(el)[0]).get();
147 var reloadpage =
"<?php echo $forcereloadpage; ?>";
148 console.log(
"tableDND onDrop");
149 console.log(decodeURI($(
"#<?php echo $tagidfortablednd; ?>").tableDnDSerialize()));
150 $(
'#<?php echo $tagidfortablednd; ?> tr[data-element=extrafield]').attr(
'id',
'');
151 $(
'#<?php echo $tagidfortablednd; ?> tr[data-ignoreidfordnd=1]').attr(
'id',
'');
152 var roworder = cleanSerialize(decodeURI($(
"#<?php echo $tagidfortablednd; ?>").tableDnDSerialize()));
153 var table_element_line =
"<?php echo $table_element_line; ?>";
154 var fk_element =
"<?php echo $fk_element; ?>";
155 var element_id =
"<?php echo $id; ?>";
156 var filepath =
"<?php echo urlencode($filepath); ?>";
157 var token =
"<?php echo currentToken(); ?>";
158 $.post(
"<?php echo DOL_URL_ROOT; ?>/core/ajax/row.php",
161 table_element_line: table_element_line,
162 fk_element: fk_element,
163 element_id: element_id,
168 console.log(
"tableDND end of ajax call");
169 console.log(roworder, table_element_line, fk_element, element_id, filepath, token);
170 if (reloadpage == 1) {
172 $redirectURL = empty($urltorefreshaftermove) ? ($_SERVER[
'PHP_SELF'].
'?'.
dol_escape_js($_SERVER[
'QUERY_STRING'])) : $urltorefreshaftermove;
174 $redirectURL = preg_replace(
'/(&|\?)action=[^&#]*/',
'', $redirectURL);
176 location.href =
'<?php echo dol_escape_js($redirectURL); ?>';
180 onDragClass:
"dragClass",
181 dragHandle:
"td.tdlineupdown"
183 $(
".tdlineupdown").hover(
function() { $(
this).addClass(
'showDragHandle'); },
184 function() { $(
this).removeClass(
'showDragHandle'); }
188function checkLinePosition(row, inital_table) {
189 const tbody = $(
"#<?php echo $tagidfortablednd; ?> .drag").map((_, el) => $(el)[0]).get();
191 for (var k = 0; k < tbody.length; k++) {
192 const currentRow = tbody[k];
193 if (currentRow.dataset.rang !== undefined) {
194 currentRow.dataset.rang = k+1;
198 var rowLevel = parseInt(row.dataset.level);
199 var cancelLineMove =
false;
200 var found_title = rowLevel >= 0;
201 var ignore_level = 0;
203 for (var i = row.dataset.rang-2; i >= 0; i--) {
205 if (tbody[i].dataset.desc !== undefined) {
206 const currentRowLevel1 = parseInt(tbody[i].dataset.level, 10);
207 console.log(currentRowLevel1, -rowLevel, currentRowLevel1 < -rowLevel);
210 if (currentRowLevel1 <= ignore_level && ignore_level !== 0) {
213 }
else if (-currentRowLevel1 === rowLevel) {
215 }
else if (currentRowLevel1 > 0 && currentRowLevel1 < rowLevel) {
216 if (rowLevel - currentRowLevel1 > 1) {
217 $(
"#notification-message").text(
"<?php echo $langs->trans("PreviousTitleLevelTooHigh
"); ?>");
218 cancelLineMove =
true;
223 }
else if (currentRowLevel1 === rowLevel) {
224 for (var j = row.dataset.rang; j < tbody.length; j++) {
225 if (tbody[j].dataset.desc !== undefined) {
226 const currentRowLevel2 = parseInt(tbody[j].dataset.level, 10);
227 if (tbody[i].dataset.desc === tbody[j].dataset.desc && currentRowLevel1 === -currentRowLevel2) {
228 $(
"#notification-message").text(
"<?php echo $langs->trans("TitleUnderSameLevelSTLine
"); ?>");
229 cancelLineMove =
true;
234 }
else if (currentRowLevel1 > rowLevel) {
235 for (var j = row.dataset.rang; j < tbody.length; j++) {
236 if (tbody[j].dataset.desc !== undefined) {
237 const currentRowLevel2 = parseInt(tbody[j].dataset.level, 10);
238 if (row.dataset.desc !== tbody[j].dataset.desc && currentRowLevel2 <= -rowLevel) {
239 $(
"#notification-message").text(
"<?php echo $langs->trans("TitleAfterStLineOfSameLevelTitle
"); ?>");
240 cancelLineMove =
true;
246 }
else if (currentRowLevel1 < -rowLevel) {
247 ignore_level = currentRowLevel1;
249 $(
"#notification-message").text(
"<?php echo $langs->trans("TitleUnderSameLevelOrGreater
"); ?>");
250 cancelLineMove =
true;
253 }
else if (rowLevel < 0) {
255 if (currentRowLevel1 < 0 && rowLevel <= currentRowLevel1 || currentRowLevel1 >0 && -rowLevel >= currentRowLevel1) {
256 console.log(rowLevel, currentRowLevel1);
257 if (tbody[i].dataset.desc === row.dataset.desc) {
260 }
else if (-rowLevel === currentRowLevel1) {
261 $(
"#notification-message").text(
"<?php echo $langs->trans("STLineUnderCorrespondingTitleDesc
"); ?>");
262 cancelLineMove =
true;
264 }
else if (-rowLevel > currentRowLevel1) {
265 $(
"#notification-message").text(
"<?php echo $langs->trans("STLineUnderCorrespondingTitle
"); ?>");
266 cancelLineMove =
true;
274 $(
"#notification-message").text(
"<?php echo $langs->trans("STLineUnderTitle
"); ?>");
275 cancelLineMove =
true;
278 if (cancelLineMove) {
279 const tbody_to_replace = $(row).parent()[0];
280 $(tbody_to_replace).empty();
281 $(tbody_to_replace).append(inital_table);
287$(document).ready(
function(){
294$(document).ready(
function(){
295 $(
".imgupforline").hide();
296 $(
".imgdownforline").hide();
297 $(
".lineupdown").removeAttr(
'href');
301<!-- END PHP TEMPLATE AJAXROW.TPL.PHP -->
$id
Support class for third parties, contacts, members, users or resources.
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...