mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-16 06:21:28 +01:00
Modification du dplacement des boites, la page n'est plus recharge. (Ajax)
This commit is contained in:
46
htdocs/ajaxbox.php
Normal file
46
htdocs/ajaxbox.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?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
|
* \brief Sauvegarde sequencement des boites pour la zone et le user
|
||||||
* \param $zone ID de la zone (0 pour la Homepage, ...)
|
* \param $zone ID de la zone (0 pour la Homepage, ...)
|
||||||
* \param $boxarray Tableau des boites dans le bon ordre
|
* \param $boxid Id des boites
|
||||||
* \param $user Objet user
|
* \param $boxorder Liste des boites dans le bon ordre
|
||||||
|
* \param $userid Id du user
|
||||||
* \return int <0 si ko, >= 0 si ok
|
* \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 (! is_object($user) || ! $user->id) return 0;
|
if (! $userid || $userid == 0) return 0;
|
||||||
|
|
||||||
|
$user = new User($this->db,$userid);
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
@@ -170,22 +173,20 @@ class InfoBox
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sql ="DELETE FROM ".MAIN_DB_PREFIX."boxes";
|
$sql ="DELETE FROM ".MAIN_DB_PREFIX."boxes";
|
||||||
$sql.=" WHERE fk_user = ".$user->id;
|
$sql.=" WHERE fk_user = ".$userid;
|
||||||
$sql.=" AND position = ".$zone;
|
$sql.=" AND position = ".$zone;
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
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 = "INSERT INTO ".MAIN_DB_PREFIX."boxes";
|
||||||
$sql.= "(box_id, position, box_order, fk_user)";
|
$sql.= "(box_id, position, box_order, fk_user)";
|
||||||
$sql.= " values (";
|
$sql.= " values (";
|
||||||
$sql.= " ".$boxarray[$ii]->box_id.",";
|
$sql.= " ".$boxid[$ii].",";
|
||||||
$sql.= " ".$zone.",";
|
$sql.= " ".$zone.",";
|
||||||
$sql.= " ".$boxarray[$ii]->box_order.",";
|
$sql.= " ".$boxorder[$ii].",";
|
||||||
$sql.= " ".$user->id;
|
$sql.= " ".$userid;
|
||||||
$sql.= ")";
|
$sql.= ")";
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result < 0)
|
if ($result < 0)
|
||||||
|
|||||||
155
htdocs/index.php
155
htdocs/index.php
@@ -539,109 +539,100 @@ print '</td></tr></table>';
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
$boxarray=$infobox->listboxes("0",$user); // 0=valeur pour la page accueil
|
$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))
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
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";
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Permutation boites
|
|
||||||
$switchii=$boxarray[$regto[1]];
|
|
||||||
$boxarray[$regto[1]]=$boxarray[$regfrom[1]];
|
|
||||||
$boxarray[$regfrom[1]]=$switchii;
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
/*
|
|
||||||
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";
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Sauvegarde nouvel ordre pour l'utilisateur
|
|
||||||
$result=$infobox->saveboxorder("0",$boxarray,$user);
|
|
||||||
if ($result < 0)
|
|
||||||
{
|
|
||||||
dolibarr_print_error($db,$infobox->error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$NBCOLS=2; // Nombre de colonnes pour les boites
|
|
||||||
|
|
||||||
if (sizeof($boxarray))
|
if (sizeof($boxarray))
|
||||||
{
|
{
|
||||||
print '<br>';
|
print '<br>';
|
||||||
print_fiche_titre($langs->trans("OtherInformationsBoxes"));
|
print_fiche_titre($langs->trans("OtherInformationsBoxes"));
|
||||||
print '<table width="100%" class="notopnoleftnoright">';
|
print '<table width="100%" class="notopnoleftnoright">';
|
||||||
|
print '<td>'."\n";
|
||||||
|
|
||||||
|
$box_id = Array();
|
||||||
|
|
||||||
|
// Cr<43>ation de la liste des id
|
||||||
for ($ii=0, $ni=sizeof($boxarray); $ii < $ni; $ii++)
|
for ($ii=0, $ni=sizeof($boxarray); $ii < $ni; $ii++)
|
||||||
{
|
{
|
||||||
$boxjavascriptids[$ii]='"box_'.$ii.'"';
|
//print 'box_id '.$boxarray[$ii]->box_id.' ';
|
||||||
|
//print 'box_order '.$boxarray[$ii]->box_order.'<br>';
|
||||||
|
|
||||||
if ($ii % $NBCOLS == 0) print "<tr>\n";
|
$box_id[$ii] = $boxarray[$ii]->box_id;
|
||||||
print '<td valign="top" width="50%">';
|
}
|
||||||
|
$boxid = join(',',$box_id);
|
||||||
|
|
||||||
|
// 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++)
|
||||||
|
{
|
||||||
|
if ($ii%2 != 1)
|
||||||
|
{
|
||||||
print '<div id="boxto_'.$ii.'">';
|
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
|
// Affichage boite ii
|
||||||
$box=$boxarray[$ii];
|
$box=$boxarray[$ii];
|
||||||
$box->loadBox();
|
$box->loadBox();
|
||||||
$box->boxid="$ii";
|
$box->boxid="$ii";
|
||||||
$box->showBox();
|
$box->showBox();
|
||||||
if ($conf->use_ajax && $conf->browser->firefox)
|
|
||||||
{
|
|
||||||
print '</li>';
|
|
||||||
print '</ul>';
|
|
||||||
}
|
|
||||||
|
|
||||||
print '</div>';
|
print '</div>';
|
||||||
print "</td>";
|
|
||||||
if ($ii % $NBCOLS == ($NBCOLS-1)) print "</tr>\n";
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
print '</div>';
|
||||||
|
print "\n";
|
||||||
|
|
||||||
if ($ii % $NBCOLS == ($NBCOLS-1)) print "</tr>\n";
|
// 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++)
|
||||||
|
{
|
||||||
|
if ($ii%2 == 1)
|
||||||
|
{
|
||||||
|
print '<div id="boxto_'.$ii.'">';
|
||||||
|
|
||||||
|
// Affichage boite ii
|
||||||
|
$box=$boxarray[$ii];
|
||||||
|
$box->loadBox();
|
||||||
|
$box->boxid="$ii";
|
||||||
|
$box->showBox();
|
||||||
|
|
||||||
|
print '</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print '</div>';
|
||||||
|
print "\n";
|
||||||
|
|
||||||
|
print "</td></tr>";
|
||||||
print "</table>";
|
print "</table>";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($conf->use_ajax && $conf->browser->firefox)
|
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";
|
print '// <![CDATA['."\n";
|
||||||
for ($ii=0, $ni=sizeof($boxarray); $ii < $ni; $ii++)
|
|
||||||
{
|
print 'Sortable.create(\'left\', {'."\n";
|
||||||
/*
|
print 'tag:\'div\', '."\n";
|
||||||
print 'Sortable.create(';
|
print 'containment:["left","right"], '."\n";
|
||||||
print '\'box_'.$ii.'\', ';
|
print 'constraint:false, '."\n";
|
||||||
print '{hoverclass:\'grey\', ';
|
print 'onUpdate:updateOrder';
|
||||||
print 'onUpdate:function(element, dropon, event){ alert( "X "+element+" Z " ); }, ';
|
print "});\n";
|
||||||
print 'ghosting:true, dropOnEmpty:true, ';
|
|
||||||
print 'containment:['.join(',',$boxjavascriptids).'], ';
|
print 'Sortable.create(\'right\', {'."\n";
|
||||||
print 'constraint:false}';
|
print 'tag:\'div\', '."\n";
|
||||||
print ");\n";
|
print 'containment:["right","left"], '."\n";
|
||||||
*/
|
print 'constraint:false, '."\n";
|
||||||
print 'new Draggable(\'boxobject_'.$ii.'\', {revert:false});'."\n";
|
print 'onUpdate:updateOrder';
|
||||||
//print 'Droppables.add(\'boxto_'.$ii.'\', {onDrop:function(element,dropon){alert(\'From: \' + encodeURIComponent(element.id) + \' - To: \' + encodeURIComponent(dropon.id))}});'."\n";
|
print "});\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 '// ]]>'."\n";
|
print '// ]]>'."\n";
|
||||||
print '</script>'."\n";
|
print '</script>'."\n";
|
||||||
}
|
}
|
||||||
@@ -657,13 +648,3 @@ $db->close();
|
|||||||
|
|
||||||
llxFooter('$Date$ - $Revision$');
|
llxFooter('$Date$ - $Revision$');
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -635,3 +635,17 @@ function ac_return(field, item){
|
|||||||
// d<>lai exprim<69> en millisecondes avant le d<>clenchement de l'action
|
// d<>lai exprim<69> en millisecondes avant le d<>clenchement de l'action
|
||||||
setTimeout(funct,delay);
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user