Skip to content
Snippets Groups Projects
Commit 7e5c347b authored by Regis Houssin's avatar Regis Houssin
Browse files

Fix: correct reorder childrens of lines

parent f352f5cb
No related branches found
No related tags found
No related merge requests found
<?php <?php
/* Copyright (C) 2010-2011 Regis Houssin <regis@dolibarr.fr> /* Copyright (C) 2010-2012 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -35,11 +35,6 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/genericobject.class.php"); ...@@ -35,11 +35,6 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/genericobject.class.php");
* View * View
*/ */
// Ajout directives pour resoudre bug IE
//header('Cache-Control: Public, must-revalidate');
//header('Pragma: public');
//top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
top_httphead(); top_httphead();
print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n"; print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
...@@ -52,21 +47,16 @@ if((isset($_GET['roworder']) && !empty($_GET['roworder'])) && (isset($_GET['tabl ...@@ -52,21 +47,16 @@ if((isset($_GET['roworder']) && !empty($_GET['roworder'])) && (isset($_GET['tabl
foreach($roworder as $value) foreach($roworder as $value)
{ {
if (!empty($value)) if (! empty($value)) $newroworder[] = $value;
{
$newroworder[] = $value;
}
} }
$roworder = implode(',',$newroworder); dol_syslog("AjaxRow roworder=".$_GET['roworder']." fk_element=".$_GET['fk_element'], LOG_DEBUG);
dol_syslog("AjaxRow roworder=".$_GET['roworder']." neworder=".$roworder." element=".$_GET['element'], LOG_DEBUG);
$row=new GenericObject($db); $row=new GenericObject($db);
$row->table_element_line = $_GET['table_element_line']; $row->table_element_line = $_GET['table_element_line'];
$row->fk_element = $_GET['fk_element']; $row->fk_element = $_GET['fk_element'];
$row->id = $_GET['element_id']; $row->id = $_GET['element_id'];
$result=$row->line_ajaxorder($roworder); $result=$row->line_ajaxorder($newroworder);
$result=$row->line_order(true); $result=$row->line_order(true);
} }
......
...@@ -890,24 +890,74 @@ abstract class CommonObject ...@@ -890,24 +890,74 @@ abstract class CommonObject
} }
if ($nl > 0) if ($nl > 0)
{ {
$rows=array();
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id; $sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
$sql.= ' AND fk_parent_line IS NULL';
$sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder;
dol_syslog(get_class($this)."::line_order sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::line_order sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
$i=0;
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num) while ($i < $num)
{ {
$row = $this->db->fetch_row($resql); $row = $this->db->fetch_row($resql);
$this->updateRangOfLine($row[0], ($i+1)); $rows[] = $row[0];
$childrens = $this->getChildrensOfLine($row[0]);
if (! empty($childrens))
{
foreach($childrens as $child)
{
array_push($rows, $child);
}
}
$i++; $i++;
} }
if (! empty($rows))
{
foreach($rows as $key => $row)
{
$this->updateRangOfLine($row, ($key+1));
}
}
}
}
}
/**
* Get childrens of line
*
* @param int $id Id of parent line
*/
function getChildrensOfLine($id)
{
$rows=array();
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
$sql.= ' AND fk_parent_line = '.$id;
$sql.= ' ORDER BY rang ASC';
dol_syslog(get_class($this)."::getChildrenOfLines sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$i=0;
$num = $this->db->num_rows($resql);
while ($i < $num)
{
$row = $this->db->fetch_row($resql);
$rows[$i] = $row[0];
$i++;
} }
} }
return $rows;
} }
/** /**
...@@ -966,13 +1016,11 @@ abstract class CommonObject ...@@ -966,13 +1016,11 @@ abstract class CommonObject
/** /**
* Update position of line with ajax (rang) * Update position of line with ajax (rang)
* *
* @param int $roworder * @param array $rows Array of rows
*/ */
function line_ajaxorder($roworder) function line_ajaxorder($rows)
{ {
$rows = explode(',',$roworder);
$num = count($rows); $num = count($rows);
for ($i = 0 ; $i < $num ; $i++) for ($i = 0 ; $i < $num ; $i++)
{ {
$this->updateRangOfLine($rows[$i], ($i+1)); $this->updateRangOfLine($rows[$i], ($i+1));
......
<?php <?php
/* Copyright (C) 2010-2011 Regis Houssin <regis@dolibarr.fr> /* Copyright (C) 2010-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2010-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2010-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -21,22 +21,22 @@ ...@@ -21,22 +21,22 @@
<!-- BEGIN PHP TEMPLATE FOR JQUERY --> <!-- BEGIN PHP TEMPLATE FOR JQUERY -->
<?php if (count($object->lines) > 1 && $_GET['action'] != 'editline') { ?> <?php if (count($object->lines) > 1 && $_GET['action'] != 'editline') { ?>
<script> <script>
jQuery(document).ready(function(){ $(document).ready(function(){
jQuery(".imgup").hide(); $(".imgup").hide();
jQuery(".imgdown").hide(); $(".imgdown").hide();
jQuery(".lineupdown").removeAttr('href'); $(".lineupdown").removeAttr('href');
jQuery(".tdlineupdown").css("background-image",'url(<?php echo DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/grip.png'; ?>)'); $(".tdlineupdown").css("background-image",'url(<?php echo DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/grip.png'; ?>)');
jQuery(".tdlineupdown").css("background-repeat","no-repeat"); $(".tdlineupdown").css("background-repeat","no-repeat");
jQuery(".tdlineupdown").css("background-position","center center"); $(".tdlineupdown").css("background-position","center center");
jQuery("#tablelines").tableDnD({ $("#tablelines").tableDnD({
onDrop: function(table, row) { onDrop: function(table, row) {
var reloadpage = "<?php echo $conf->global->MAIN_FORCE_RELOAD_PAGE; ?>"; var reloadpage = "<?php echo $conf->global->MAIN_FORCE_RELOAD_PAGE; ?>";
var roworder = cleanSerialize(jQuery("#tablelines").tableDnDSerialize()); var roworder = cleanSerialize($("#tablelines").tableDnDSerialize());
var table_element_line = "<?php echo $object->table_element_line; ?>"; var table_element_line = "<?php echo $object->table_element_line; ?>";
var fk_element = "<?php echo $object->fk_element; ?>"; var fk_element = "<?php echo $object->fk_element; ?>";
var element_id = "<?php echo $object->id; ?>"; var element_id = "<?php echo $object->id; ?>";
jQuery.get("<?php echo DOL_URL_ROOT; ?>/core/ajax/row.php", $.get("<?php echo DOL_URL_ROOT; ?>/core/ajax/row.php",
{ {
roworder: roworder, roworder: roworder,
table_element_line: table_element_line, table_element_line: table_element_line,
...@@ -47,11 +47,11 @@ jQuery(document).ready(function(){ ...@@ -47,11 +47,11 @@ jQuery(document).ready(function(){
if (reloadpage == 1) { if (reloadpage == 1) {
location.href = '<?php echo $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']; ?>'; location.href = '<?php echo $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']; ?>';
} else { } else {
jQuery("#tablelines .drag").each( $("#tablelines .drag").each(
function( intIndex ) { function( intIndex ) {
jQuery(this).removeClass("pair impair"); $(this).removeClass("pair impair");
if (intIndex % 2 == 0) jQuery(this).addClass('impair'); if (intIndex % 2 == 0) $(this).addClass('impair');
if (intIndex % 2 == 1) jQuery(this).addClass('pair'); if (intIndex % 2 == 1) $(this).addClass('pair');
}); });
} }
}); });
...@@ -59,17 +59,17 @@ jQuery(document).ready(function(){ ...@@ -59,17 +59,17 @@ jQuery(document).ready(function(){
onDragClass: "dragClass", onDragClass: "dragClass",
dragHandle: "tdlineupdown" dragHandle: "tdlineupdown"
}); });
jQuery(".tdlineupdown").hover( function() { jQuery(this).addClass('showDragHandle'); }, $(".tdlineupdown").hover( function() { $(this).addClass('showDragHandle'); },
function() { jQuery(this).removeClass('showDragHandle'); } function() { $(this).removeClass('showDragHandle'); }
); );
}); });
</script> </script>
<?php } else { ?> <?php } else { ?>
<script> <script>
jQuery(document).ready(function(){ $(document).ready(function(){
jQuery(".imgup").hide(); $(".imgup").hide();
jQuery(".imgdown").hide(); $(".imgdown").hide();
jQuery(".lineupdown").removeAttr('href'); $(".lineupdown").removeAttr('href');
}); });
</script> </script>
<?php } ?> <?php } ?>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment