46 print
"Error, template page ".basename(__FILE__).
" can't be called with no object defined.";
50@phan-var-force CommonObject $object
51@phan-var-force ?string $fk_element
52@phan-var-force ?Task[] $tasksarray
57<!-- BEGIN PHP TEMPLATE SUBTOTAL_AJAXROW.TPL.PHP - Script to enable drag and drop on lines of a
table using subtotal lines -->
60$fk_element = empty(
$object->fk_element) ? $fk_element :
$object->fk_element;
61$table_element_line = (empty($table_element_line) ?
$object->table_element_line : $table_element_line);
62$nboflines = count(
$object->lines);
64$tagidfortablednd = (empty($tagidfortablednd) ?
'tablelines' : $tagidfortablednd);
65$filepath = (empty($filepath) ?
'' : $filepath);
66$langs->load(
"subtotals");
68if (
GETPOST(
'action',
'aZ09') !=
'editline' && $nboflines > 1 &&
$conf->browser->layout !=
'phone') { ?>
69<div
id=
"notification-message" hidden=
""></div>
71function openDialog() {
73 console.log(
"open dialog");
74 jQuery(
"#notification-message").dialog({
79 jQuery(
this).dialog(
'close');
87 $(
".imgupforline").hide();
88 $(
".imgdownforline").hide();
89 $(
".lineupdown").removeAttr(
'href');
91 console.log(
"init() Prepare tableDnd for #<?php echo $tagidfortablednd; ?>");
93 $(
".tdlineupdown").each(
function (tdindex, tdline) {
94 var gripimg = tdline.dataset.gripimg ??
'grip.png';
96 $(tdline).css(
"background-image",
'url(<?php echo DOL_URL_ROOT.'/theme/
'.$conf->theme.'/img/
'; ?>' + gripimg +
')');
97 $(tdline).css(
"background-repeat",
"no-repeat");
98 $(tdline).css(
"background-position",
"center center");
102 var inital_table = $(
"#<?php echo $tagidfortablednd; ?> .drag").map((_, el) => $(el)[0]).
get();
104 $(
"#<?php echo $tagidfortablednd; ?>").tableDnD({
105 onDragStart:
function (
table, row) {
106 if (row.parentNode.dataset.level > 0) {
108 $(
"#<?php echo $tagidfortablednd; ?> .drag").each(
109 function (intIndex) {
111 if ($(
this)[0].dataset.level>-row.parentNode.dataset.level && $(
this)[0].dataset.level<=row.parentNode.dataset.level) {
115 rowsToMove.unshift($(
this));
116 if (Math.abs($(
this)[0].dataset.level) <= Math.abs(row.parentNode.dataset.level)) {
120 if ($(
this)[0].
id === row.parentNode.id) {
121 rowsToMove.unshift($(this));
126 rowsToMove.forEach(
function ($hiddenRow, i) {
127 if (i<rowsToMove.length-1) {
136 onDragStop:
function(
table, row) {
137 if (rowsToMove.length !== 0) {
138 rowsToMove.forEach(
function (hiddenRow) {
139 hiddenRow.insertAfter($(
"#" + row.id));
145 if (row.dataset.desc !== undefined) {
146 checkLinePosition(row, inital_table);
148 inital_table = $(
"#<?php echo $tagidfortablednd; ?> .drag").map((_, el) => $(el)[0]).get();
150 var reloadpage =
"<?php echo $forcereloadpage; ?>";
151 console.log(
"tableDND onDrop");
152 console.log(decodeURI($(
"#<?php echo $tagidfortablednd; ?>").tableDnDSerialize()));
153 $(
'#<?php echo $tagidfortablednd; ?> tr[data-element=extrafield]').attr(
'id',
'');
154 $(
'#<?php echo $tagidfortablednd; ?> tr[data-ignoreidfordnd=1]').attr(
'id',
'');
155 var roworder = cleanSerialize(decodeURI($(
"#<?php echo $tagidfortablednd; ?>").tableDnDSerialize()));
156 var table_element_line =
"<?php echo $table_element_line; ?>";
157 var fk_element =
"<?php echo $fk_element; ?>";
158 var element_id =
"<?php echo $id; ?>";
159 var filepath =
"<?php echo urlencode($filepath); ?>";
160 var token =
"<?php echo currentToken(); ?>";
161 $.post(
"<?php echo DOL_URL_ROOT; ?>/core/ajax/row.php",
164 table_element_line: table_element_line,
165 fk_element: fk_element,
166 element_id: element_id,
171 console.log(
"tableDND end of ajax call");
172 console.log(roworder, table_element_line, fk_element, element_id, filepath, token);
173 if (reloadpage == 1) {
175 $redirectURL = empty($urltorefreshaftermove) ? ($_SERVER[
'PHP_SELF'].
'?'.
dol_string_nohtmltag($_SERVER[
'QUERY_STRING'])) : $urltorefreshaftermove;
177 $redirectURL = preg_replace(
'/(&|\?)action=[^&#]*/',
'', $redirectURL);
180 location.href = <?php echo
"'".dol_escape_js($redirectURL).
"'"; ?>;
184 onDragClass:
"dragClass",
185 dragHandle:
"td.tdlineupdown"
187 $(
".tdlineupdown").hover(
function() { $(
this).addClass(
'showDragHandle'); },
188 function() { $(
this).removeClass(
'showDragHandle'); }
192function checkLinePosition(row, inital_table) {
193 const tbody = $(
"#<?php echo $tagidfortablednd; ?> .drag").map((_, el) => $(el)[0]).get();
195 for (var k = 0; k < tbody.length; k++) {
196 const currentRow = tbody[k];
197 if (currentRow.dataset.rang !== undefined) {
198 currentRow.dataset.rang = k+1;
202 var rowLevel = parseInt(row.dataset.level);
203 var cancelLineMove =
false;
204 var found_title = rowLevel >= 0;
205 var ignore_level = 0;
207 for (var i = row.dataset.rang-2; i >= 0; i--) {
209 if (tbody[i].dataset.desc !== undefined) {
210 const currentRowLevel1 = parseInt(tbody[i].dataset.level, 10);
211 console.log(currentRowLevel1, -rowLevel, currentRowLevel1 < -rowLevel);
214 if (currentRowLevel1 <= ignore_level && ignore_level !== 0) {
217 }
else if (-currentRowLevel1 === rowLevel) {
219 }
else if (currentRowLevel1 > 0 && currentRowLevel1 < rowLevel) {
220 if (rowLevel - currentRowLevel1 > 1) {
221 $(
"#notification-message").text(
"<?php echo $langs->trans("PreviousTitleLevelTooHigh
"); ?>");
222 cancelLineMove =
true;
227 }
else if (currentRowLevel1 === rowLevel) {
228 for (var j = row.dataset.rang; j < tbody.length; j++) {
229 if (tbody[j].dataset.desc !== undefined) {
230 const currentRowLevel2 = parseInt(tbody[j].dataset.level, 10);
231 if (tbody[i].dataset.desc === tbody[j].dataset.desc && currentRowLevel1 === -currentRowLevel2) {
232 $(
"#notification-message").text(
"<?php echo $langs->trans("TitleUnderSameLevelSTLine
"); ?>");
233 cancelLineMove =
true;
238 }
else if (currentRowLevel1 > rowLevel) {
239 for (var j = row.dataset.rang; j < tbody.length; j++) {
240 if (tbody[j].dataset.desc !== undefined) {
241 const currentRowLevel2 = parseInt(tbody[j].dataset.level, 10);
242 if (row.dataset.desc !== tbody[j].dataset.desc && currentRowLevel2 <= -rowLevel) {
243 $(
"#notification-message").text(
"<?php echo $langs->trans("TitleAfterStLineOfSameLevelTitle
"); ?>");
244 cancelLineMove =
true;
250 }
else if (currentRowLevel1 < -rowLevel) {
251 ignore_level = currentRowLevel1;
253 $(
"#notification-message").text(
"<?php echo $langs->trans("TitleUnderSameLevelOrGreater
"); ?>");
254 cancelLineMove =
true;
257 }
else if (rowLevel < 0) {
259 if (currentRowLevel1 < 0 && rowLevel <= currentRowLevel1 || currentRowLevel1 >0 && -rowLevel >= currentRowLevel1) {
260 console.log(rowLevel, currentRowLevel1);
261 if (tbody[i].dataset.desc === row.dataset.desc) {
264 }
else if (-rowLevel === currentRowLevel1) {
265 $(
"#notification-message").text(
"<?php echo $langs->trans("STLineUnderCorrespondingTitleDesc
"); ?>");
266 cancelLineMove =
true;
268 }
else if (-rowLevel > currentRowLevel1) {
269 $(
"#notification-message").text(
"<?php echo $langs->trans("STLineUnderCorrespondingTitle
"); ?>");
270 cancelLineMove =
true;
278 $(
"#notification-message").text(
"<?php echo $langs->trans("STLineUnderTitle
"); ?>");
279 cancelLineMove =
true;
282 if (cancelLineMove) {
283 const tbody_to_replace = $(row).parent()[0];
284 $(tbody_to_replace).empty();
285 $(tbody_to_replace).append(inital_table);
291$(document).ready(
function(){
298$(document).ready(
function(){
299 $(
".imgupforline").hide();
300 $(
".imgdownforline").hide();
301 $(
".lineupdown").removeAttr(
'href');
305<!-- END PHP TEMPLATE AJAXROW.TPL.PHP -->
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_sanitizeUrl($stringtoclean, $type=1)
Clean a string to use it as an URL (into a href or src attribute, or into a js string that is a locat...
treeview li table
No Email.