Fix: correct reorder childrens of lines

This commit is contained in:
Regis Houssin 2012-01-24 05:23:00 +08:00
parent f352f5cba2
commit 7e5c347bb8
3 changed files with 79 additions and 41 deletions

View File

@ -1,5 +1,5 @@
<?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
* 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");
* 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();
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
foreach($roworder as $value)
{
if (!empty($value))
{
$newroworder[] = $value;
}
if (! empty($value)) $newroworder[] = $value;
}
$roworder = implode(',',$newroworder);
dol_syslog("AjaxRow roworder=".$_GET['roworder']." neworder=".$roworder." element=".$_GET['element'], LOG_DEBUG);
dol_syslog("AjaxRow roworder=".$_GET['roworder']." fk_element=".$_GET['fk_element'], LOG_DEBUG);
$row=new GenericObject($db);
$row->table_element_line = $_GET['table_element_line'];
$row->fk_element = $_GET['fk_element'];
$row->id = $_GET['element_id'];
$result=$row->line_ajaxorder($roworder);
$result=$row->line_ajaxorder($newroworder);
$result=$row->line_order(true);
}

View File

@ -890,25 +890,75 @@ abstract class CommonObject
}
if ($nl > 0)
{
$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 IS NULL';
$sql.= ' ORDER BY rang ASC, rowid '.$rowidorder;
dol_syslog(get_class($this)."::line_order sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$i=0;
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$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++;
}
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;
}
/**
* Update a line to have a lower rank
@ -966,13 +1016,11 @@ abstract class CommonObject
/**
* 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);
for ($i = 0 ; $i < $num ; $i++)
{
$this->updateRangOfLine($rows[$i], ($i+1));

View File

@ -1,5 +1,5 @@
<?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>
*
* This program is free software; you can redistribute it and/or modify
@ -21,22 +21,22 @@
<!-- BEGIN PHP TEMPLATE FOR JQUERY -->
<?php if (count($object->lines) > 1 && $_GET['action'] != 'editline') { ?>
<script>
jQuery(document).ready(function(){
jQuery(".imgup").hide();
jQuery(".imgdown").hide();
jQuery(".lineupdown").removeAttr('href');
jQuery(".tdlineupdown").css("background-image",'url(<?php echo DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/grip.png'; ?>)');
jQuery(".tdlineupdown").css("background-repeat","no-repeat");
jQuery(".tdlineupdown").css("background-position","center center");
$(document).ready(function(){
$(".imgup").hide();
$(".imgdown").hide();
$(".lineupdown").removeAttr('href');
$(".tdlineupdown").css("background-image",'url(<?php echo DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/grip.png'; ?>)');
$(".tdlineupdown").css("background-repeat","no-repeat");
$(".tdlineupdown").css("background-position","center center");
jQuery("#tablelines").tableDnD({
$("#tablelines").tableDnD({
onDrop: function(table, row) {
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 fk_element = "<?php echo $object->fk_element; ?>";
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,
table_element_line: table_element_line,
@ -47,11 +47,11 @@ jQuery(document).ready(function(){
if (reloadpage == 1) {
location.href = '<?php echo $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']; ?>';
} else {
jQuery("#tablelines .drag").each(
$("#tablelines .drag").each(
function( intIndex ) {
jQuery(this).removeClass("pair impair");
if (intIndex % 2 == 0) jQuery(this).addClass('impair');
if (intIndex % 2 == 1) jQuery(this).addClass('pair');
$(this).removeClass("pair impair");
if (intIndex % 2 == 0) $(this).addClass('impair');
if (intIndex % 2 == 1) $(this).addClass('pair');
});
}
});
@ -59,17 +59,17 @@ jQuery(document).ready(function(){
onDragClass: "dragClass",
dragHandle: "tdlineupdown"
});
jQuery(".tdlineupdown").hover( function() { jQuery(this).addClass('showDragHandle'); },
function() { jQuery(this).removeClass('showDragHandle'); }
$(".tdlineupdown").hover( function() { $(this).addClass('showDragHandle'); },
function() { $(this).removeClass('showDragHandle'); }
);
});
</script>
<?php } else { ?>
<script>
jQuery(document).ready(function(){
jQuery(".imgup").hide();
jQuery(".imgdown").hide();
jQuery(".lineupdown").removeAttr('href');
$(document).ready(function(){
$(".imgup").hide();
$(".imgdown").hide();
$(".lineupdown").removeAttr('href');
});
</script>
<?php } ?>