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

Modification du déplacement des boites, la page n'est plus rechargée. (Ajax)

parent be0e0999
No related branches found
No related tags found
No related merge requests found
<?php
/* Copyright (C) 2005-2007 Regis Houssin <regis.houssin@cap-networks.com>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/
/**
\file htdocs/ajaxbox.php
\brief Fichier de reponse sur evenement Ajax
\version $Revision$
*/
require('master.inc.php');
require_once(DOL_DOCUMENT_ROOT."/boxes.php");
// Enregistrement de la position des boxes
if((isset($_GET['boxorder']) && !empty($_GET['boxorder'])) && (isset($_GET['boxid']) && !empty($_GET['boxid'])) && (isset($_GET['userid']) && !empty($_GET['userid'])))
{
$infobox=new InfoBox($db);
dolibarr_syslog("InfoBox::Ajax.Request list=".$_GET['boxorder']." boxid=".$_GET['boxid']." userid=".$_GET['userid'], LOG_DEBUG);
$boxid = explode(',',$_GET['boxid']);
$boxorder = explode(',',$_GET['boxorder']);
$infobox->saveboxorder("0",$boxid,$boxorder,$_GET['userid']);
}
?>
......@@ -147,15 +147,18 @@ class InfoBox
/**
* \brief Sauvegarde sequencement des boites pour la zone et le user
* \param $zone ID de la zone (0 pour la Homepage, ...)
* \param $boxarray Tableau des boites dans le bon ordre
* \param $user Objet user
* \param $boxid Id des boites
* \param $boxorder Liste des boites dans le bon ordre
* \param $userid Id du user
* \return int <0 si ko, >= 0 si ok
*/
function saveboxorder($zone,$boxarray,$user)
function saveboxorder($zone,$boxid,$boxorder,$userid=0)
{
dolibarr_syslog("InfoBoxes::saveboxorder zone=".$zone." user=".$user->id);
dolibarr_syslog("InfoBoxes::saveboxorder zone=".$zone." user=".$userid);
if (! $userid || $userid == 0) return 0;
if (! is_object($user) || ! $user->id) return 0;
$user = new User($this->db,$userid);
$this->db->begin();
......@@ -170,22 +173,20 @@ class InfoBox
}
$sql ="DELETE FROM ".MAIN_DB_PREFIX."boxes";
$sql.=" WHERE fk_user = ".$user->id;
$sql.=" WHERE fk_user = ".$userid;
$sql.=" AND position = ".$zone;
$result = $this->db->query($sql);
if ($result)
{
for ($ii=0, $ni=sizeof($boxarray); $ii < $ni; $ii++)
for ($ii=0, $ni=sizeof($boxid); $ii < $ni; $ii++)
{
//print "box_id".$boxarray[$ii]->box_id.'<br>';
//print "box_order".$boxarray[$ii]->box_order.'<br>';
$sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes";
$sql.= "(box_id, position, box_order, fk_user)";
$sql.= " values (";
$sql.= " ".$boxarray[$ii]->box_id.",";
$sql.= " ".$boxid[$ii].",";
$sql.= " ".$zone.",";
$sql.= " ".$boxarray[$ii]->box_order.",";
$sql.= " ".$user->id;
$sql.= " ".$boxorder[$ii].",";
$sql.= " ".$userid;
$sql.= ")";
$result = $this->db->query($sql);
if ($result < 0)
......
......@@ -539,109 +539,100 @@ print '</td></tr></table>';
*
*/
$boxarray=$infobox->listboxes("0",$user); // 0=valeur pour la page accueil
$boxjavascriptids=array();
//print_r($boxarray);
// Gestion deplacement des boxes
if (eregi('boxobject_([0-9]+)',$_GET["switchfrom"],$regfrom)
&& eregi('boxto_([0-9]+)',$_GET["switchto"],$regto))
if (sizeof($boxarray))
{
/*
print "Modif ordre box: ";
print $boxarray[$regfrom[1]]->box_id."(".$boxarray[$regfrom[1]]->box_order.")";
print " <-> ";
print $boxarray[$regto[1]]->box_id."(".$boxarray[$regto[1]]->box_order.")";
print "<br>\n";
*/
print '<br>';
print_fiche_titre($langs->trans("OtherInformationsBoxes"));
print '<table width="100%" class="notopnoleftnoright">';
print '<td>'."\n";
// Permutation boites
$switchii=$boxarray[$regto[1]];
$boxarray[$regto[1]]=$boxarray[$regfrom[1]];
$boxarray[$regfrom[1]]=$switchii;
$box_id = Array();
// Permutation box_order
$switchbox_order=$boxarray[$regto[1]]->box_order;
$boxarray[$regto[1]]->box_order=$boxarray[$regfrom[1]]->box_order;
$boxarray[$regfrom[1]]->box_order=$switchbox_order;
// Cration de la liste des id
for ($ii=0, $ni=sizeof($boxarray); $ii < $ni; $ii++)
{
//print 'box_id '.$boxarray[$ii]->box_id.' ';
//print 'box_order '.$boxarray[$ii]->box_order.'<br>';
/*
print "Modif ordre box: ";
print $boxarray[$regfrom[1]]->box_id."(".$boxarray[$regfrom[1]]->box_order.")";
print " <-> ";
print $boxarray[$regto[1]]->box_id."(".$boxarray[$regto[1]]->box_order.")";
print "<br>\n";
*/
$box_id[$ii] = $boxarray[$ii]->box_id;
}
$boxid = join(',',$box_id);
// Sauvegarde nouvel ordre pour l'utilisateur
$result=$infobox->saveboxorder("0",$boxarray,$user);
if ($result < 0)
// Affichage colonne gauche (boites paires)
print '<div id="left" style="width: 50%; padding: 0px; margin: 0px; float: left;">'."\n";
for ($ii=0, $ni=sizeof($boxarray); $ii < $ni; $ii++)
{
dolibarr_print_error($db,$infobox->error);
}
}
if ($ii%2 != 1)
{
print '<div id="boxto_'.$ii.'">';
// Affichage boite ii
$box=$boxarray[$ii];
$box->loadBox();
$box->boxid="$ii";
$box->showBox();
$NBCOLS=2; // Nombre de colonnes pour les boites
print '</div>';
}
}
print '</div>';
print "\n";
if (sizeof($boxarray))
{
print '<br>';
print_fiche_titre($langs->trans("OtherInformationsBoxes"));
print '<table width="100%" class="notopnoleftnoright">';
// Affichage colonne droite (boites impaires)
print '<div id="right" style="width: 50%; padding: 0px; margin: 0px; float: left;">'."\n";
for ($ii=0, $ni=sizeof($boxarray); $ii < $ni; $ii++)
{
$boxjavascriptids[$ii]='"box_'.$ii.'"';
if ($ii % $NBCOLS == 0) print "<tr>\n";
print '<td valign="top" width="50%">';
if ($ii%2 == 1)
{
print '<div id="boxto_'.$ii.'">';
if ($conf->use_ajax && $conf->browser->firefox)
{
print '<ul class="nocellnopadd" height="100px" id="box_'.$ii.'">';
print '<li class="nocellnopadd" height="100px">';
}
// Affichage boite ii
$box=$boxarray[$ii];
$box->loadBox();
$box->boxid="$ii";
$box->showBox();
if ($conf->use_ajax && $conf->browser->firefox)
{
print '</li>';
print '</ul>';
}
print '</div>';
print "</td>";
if ($ii % $NBCOLS == ($NBCOLS-1)) print "</tr>\n";
}
}
print '</div>';
print "\n";
if ($ii % $NBCOLS == ($NBCOLS-1)) print "</tr>\n";
print "</td></tr>";
print "</table>";
}
if ($conf->use_ajax && $conf->browser->firefox)
{
print '<script type="text/javascript" language="javascript">'."\n";
print '<script type="text/javascript" language="javascript">
function updateOrder(){
var left_list = cleanSerialize(Sortable.serialize(\'left\'));
var right_list = cleanSerialize(Sortable.serialize(\'right\'));
var boxid = \''.$boxid.'\';
var boxorder = left_list + \',\' + right_list;
var userid = \''.$user->id.'\';
var url = "ajaxbox.php";
o_options = new Object();
o_options = {asynchronous:true,method: \'get\',parameters: \'boxorder=\' + boxorder + \'&boxid=\' + boxid + \'&userid=\' + userid};
var myAjax = new Ajax.Request(url, o_options);
}'."\n";
print '// <![CDATA['."\n";
for ($ii=0, $ni=sizeof($boxarray); $ii < $ni; $ii++)
{
/*
print 'Sortable.create(';
print '\'box_'.$ii.'\', ';
print '{hoverclass:\'grey\', ';
print 'onUpdate:function(element, dropon, event){ alert( "X "+element+" Z " ); }, ';
print 'ghosting:true, dropOnEmpty:true, ';
print 'containment:['.join(',',$boxjavascriptids).'], ';
print 'constraint:false}';
print ");\n";
*/
print 'new Draggable(\'boxobject_'.$ii.'\', {revert:false});'."\n";
//print 'Droppables.add(\'boxto_'.$ii.'\', {onDrop:function(element,dropon){alert(\'From: \' + encodeURIComponent(element.id) + \' - To: \' + encodeURIComponent(dropon.id))}});'."\n";
print 'Droppables.add(\'boxto_'.$ii.'\', {onDrop:function(element,dropon){ window.location.href=\''.$_SERVER["PHP_SELF"].'?switchfrom=\'+encodeURIComponent(element.id)+\'&switchto=\'+encodeURIComponent(dropon.id); }});'."\n";
//print 'Droppables.add(\'box_'.$ii.'\', {onDrop:function(element,dropon){alert(\'w/o hoverclass, should be:\' + encodeURIComponent(element.id) )}});'."\n";
}
print 'Sortable.create(\'left\', {'."\n";
print 'tag:\'div\', '."\n";
print 'containment:["left","right"], '."\n";
print 'constraint:false, '."\n";
print 'onUpdate:updateOrder';
print "});\n";
print 'Sortable.create(\'right\', {'."\n";
print 'tag:\'div\', '."\n";
print 'containment:["right","left"], '."\n";
print 'constraint:false, '."\n";
print 'onUpdate:updateOrder';
print "});\n";
print '// ]]>'."\n";
print '</script>'."\n";
}
......@@ -657,13 +648,3 @@ $db->close();
llxFooter('$Date$ - $Revision$');
?>
\ No newline at end of file
......@@ -635,3 +635,17 @@ function ac_return(field, item){
// dlai exprim en millisecondes avant le dclenchement de l'action
setTimeout(funct,delay);
}
/*=================================================================
Purpose: Nettoie les valeurs d'un "Sortable.serialize"
Input: expr
Author: Regis Houssin
Licence: GPL
==================================================================*/
function cleanSerialize(expr) {
var reg = new RegExp("(&)", "g");
var reg2 = new RegExp("[^0-9,]", "g");
var liste1 = expr.replace(reg, ",");
var liste = liste1.replace(reg2, "");
return liste;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment