From 0b71aceb90e2b7460d5f5fa7bffbe37626c98e58 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 19 Mar 2012 14:06:21 +0100 Subject: [PATCH] New: Each user can remove/add its own boxes. --- ChangeLog | 1 + dev/skeletons/skeleton_page.php | 1 - htdocs/boxes.php | 68 +++++++++++++++++++++------------ htdocs/core/ajax/box.php | 18 +++++++-- htdocs/core/js/lib_head.js | 2 +- htdocs/index.php | 1 + 6 files changed, 61 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index bd91571cd60..2a2aa8006e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ WARNING: Because of a major datastructure change onto supplier prices tabkes, be to make a backup of your database before making upgrade. For users: +- New: Each user can remove/add its own boxes. - New: Can use personalized fields of products/services. - New: Can attach files on social contributions. - New: Show payments terms and conditions onto muscadet template. diff --git a/dev/skeletons/skeleton_page.php b/dev/skeletons/skeleton_page.php index ebfed4f858f..9e331e72b2f 100644 --- a/dev/skeletons/skeleton_page.php +++ b/dev/skeletons/skeleton_page.php @@ -109,7 +109,6 @@ jQuery(document).ready(function() { { jQuery("#myid").removeAttr(\'disabled\'); jQuery("#myid").attr(\'disabled\',\'disabled\'); - } } init_myfunc(); jQuery("#mybutton").click(function() { diff --git a/htdocs/boxes.php b/htdocs/boxes.php index b9652de140a..4104448a25b 100644 --- a/htdocs/boxes.php +++ b/htdocs/boxes.php @@ -1,27 +1,25 @@ * Copyright (C) 2004-2011 Laurent Destailleur -* Copyright (C) 2005-2011 Regis Houssin -* -* 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, see . -*/ + * Copyright (C) 2005-2011 Regis Houssin + * + * 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, see . + */ /** * \file htdocs/boxes.php * \brief File of class to manage widget boxes - * \author Rodolphe Qiedeville - * \author Laurent Destailleur */ @@ -46,7 +44,7 @@ function printBoxesArea($user,$areacode) if ($conf->use_javascript_ajax) { $emptyuser=new User($db); - $boxavailable=$infobox->listboxes('available',$areacode,$emptyuser,$arrayboxactivatedid); + $boxavailable=$infobox->listboxes('activated',$areacode,$emptyuser,$arrayboxactivatedid); // Available here is activated for empty user $arrayboxtoactivatelabel=array(); foreach($boxavailable as $box) @@ -54,11 +52,32 @@ function printBoxesArea($user,$areacode) $arrayboxtoactivatelabel[$box->id]=$box->boxlabel; } $form=new Form($db); - // TODO enable - //$selectboxlist=$form->selectarray('boxcombo', $arrayboxtoactivatelabel); + + $selectboxlist=$form->selectarray('boxcombo', $arrayboxtoactivatelabel,'',1); } - print load_fiche_titre($langs->trans("OtherInformationsBoxes"),$selectboxlist,'','','otherboxes'); + print ''; + + print load_fiche_titre((count($boxactivated)?$langs->trans("OtherInformationsBoxes"):''),$selectboxlist,'','','otherboxes'); if (count($boxactivated)) { @@ -151,11 +170,10 @@ function printBoxesArea($user,$areacode) }); '."\n"; print 'function updateOrder() { - var left_list = cleanSerialize(jQuery("#left").sortable("serialize" )); - var right_list = cleanSerialize(jQuery("#right").sortable("serialize" )); + var left_list = cleanSerialize(jQuery("#left").sortable("serialize")); + var right_list = cleanSerialize(jQuery("#right").sortable("serialize")); var boxorder = \'A:\' + left_list + \'-B:\' + right_list; - var userid = \''.$user->id.'\'; - jQuery.get(\''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&userid=\'+'.$user->id.'); + jQuery.get(\''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.'); }'."\n"; // For closing print 'jQuery(document).ready(function() { diff --git a/htdocs/core/ajax/box.php b/htdocs/core/ajax/box.php index 4e424a605c1..e4c5a86c338 100644 --- a/htdocs/core/ajax/box.php +++ b/htdocs/core/ajax/box.php @@ -31,6 +31,12 @@ if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); require('../../main.inc.php'); require_once(DOL_DOCUMENT_ROOT."/boxes.php"); +$boxid=GETPOST('boxid','int'); +$boxorder=GETPOST('boxorder'); +$userid=GETPOST('userid'); +$zone=GETPOST('zone','int'); +$userid=GETPOST('userid','int'); + /* * View @@ -45,14 +51,20 @@ top_httphead(); print ''."\n"; +// Add a box +if ($boxid > 0 && $zone !='' && $userid > 0) +{ + $boxorder=preg_replace('/^A:/','A:'.$boxid.',',$boxorder); // Insert id of new box into list +} + // Registering the location of boxes after a move -if (GETPOST('boxorder') && GETPOST('userid')) +if ($boxorder && $zone != '' && $userid > 0) { // boxorder value is the target order: "A:idboxA1,idboxA2,A-B:idboxB1,idboxB2,B" - dol_syslog("AjaxBox boxorder=".GETPOST('boxorder')." userid=".GETPOST('userid'), LOG_DEBUG); + dol_syslog("AjaxBox boxorder=".$boxorder." zone=".$zone." userid=".$userid, LOG_DEBUG); $infobox=new InfoBox($db); - $result=$infobox->saveboxorder("0",GETPOST('boxorder'),GETPOST('userid')); + $result=$infobox->saveboxorder($zone,$boxorder,$userid); } ?> diff --git a/htdocs/core/js/lib_head.js b/htdocs/core/js/lib_head.js index 69db488f0b7..932f131a4d9 100644 --- a/htdocs/core/js/lib_head.js +++ b/htdocs/core/js/lib_head.js @@ -578,13 +578,13 @@ function newpopup(url,title) { * ================================================================= * Purpose: * Clean values of a "Sortable.serialize". Used by drag and drop. - * Works for Scriptaculous and jQuery. * Input: expr * Author: Regis Houssin * Licence: GPL * ================================================================== */ function cleanSerialize(expr) { + if (typeof(expr) != 'string') return ''; var reg = new RegExp("(&)", "g"); var reg2 = new RegExp("[^A-Z0-9,]", "g"); var liste1 = expr.replace(reg, ","); diff --git a/htdocs/index.php b/htdocs/index.php index 4158a16b600..dbe0a74e7d3 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -31,6 +31,7 @@ require_once(DOL_DOCUMENT_ROOT."/boxes.php"); // If not defined, we select menu "home" if (! isset($_GET["mainmenu"])) $_GET["mainmenu"]="home"; +$action=GETPOST('action'); include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');