2
0
forked from Wavyzz/dolibarr

Work on the feature to select which field to show

This commit is contained in:
Laurent Destailleur
2015-10-14 18:48:03 +02:00
parent 225313d8ac
commit e9aed15bed
6 changed files with 111 additions and 40 deletions

View File

@@ -0,0 +1,48 @@
<?php
/* Copyright (C) 2014 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 3 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 <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
* \file htdocs/core/actions_changeselectedfields.inc.php
* \brief Code for actions when we change list of fields on a list page
*/
// $action must be defined
// $db must be defined
// $conf must be defined
// $object must be defined (object is loaded in this file with fetch)
// Save selection
if (GETPOST('formfilteraction') == 'listafterchangingselectedfields')
{
$tabparam=array();
$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
if (GETPOST("selectedfields")) $tabparam["MAIN_SELECTEDFIELDS_".$varpage]=GETPOST("selectedfields");
else $tabparam["MAIN_SELECTEDFIELDS_".$varpage]='';
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$result=dol_set_user_param($db, $conf, $user, $tabparam);
//$action='list';
//var_dump($tabparam);exit;
}

View File

@@ -4671,37 +4671,51 @@ class Form
* Show a multiselect form from an array. * Show a multiselect form from an array.
* *
* @param string $htmlname Name of select * @param string $htmlname Name of select
* @param array $array Array with array to show * @param array $array Array with array of fields we could show
* @param string $varpage Id of context for page. Can be set with $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
* @return string HTML multiselect string * @return string HTML multiselect string
* @see selectarray * @see selectarray
*/ */
static function multiSelectArrayWithCheckbox($htmlname, $array) static function multiSelectArrayWithCheckbox($htmlname, $array, $varpage)
{ {
global $user;
$tmpvar="MAIN_SELECTEDFIELDS_".$varpage;
if (! empty($user->conf->$tmpvar))
{
$tmparray=explode(',', $user->conf->$tmpvar);
foreach($array as $key => $val)
{
//var_dump($key);
//var_dump($tmparray);
if (in_array($key, $tmparray)) $array[$key]['checked']=1;
else $array[$key]['checked']=0;
}
}
//var_dump($array);
$lis=''; $lis='';
$liststring=''; $listcheckedstring='';
foreach($array as $key => $val) foreach($array as $key => $val)
{ {
if (isset($val['cond']) && ! $val['cond']) continue; if (isset($val['cond']) && ! $val['cond']) continue;
if ($val['label']) if ($val['label'])
{ {
$lis.='<li><input type="checkbox" value="'.$key.'"'.($val['checked']?' checked="checked"':'').'/>'.dol_escape_htmltag($val['label']).'</li>'; $lis.='<li><input type="checkbox" value="'.$key.'"'.(empty($val['checked'])?'':' checked="checked"').'/>'.dol_escape_htmltag($val['label']).'</li>';
$liststring.=$key.','; $listcheckedstring.=(empty($val['checked'])?'':$key.',');
} }
} }
$out ='<!-- Component multiSelectArrayWithCheckbox '.$htmlname.' --> $out ='<!-- Component multiSelectArrayWithCheckbox '.$htmlname.' -->
<dl class="dropdown"> <dl class="dropdown">
<dt> <dt>
<a href="#"> <a href="#">
'.img_picto('','list').' '.img_picto('','list').'
<input type="hidden" class="'.$htmlname.'" name="'.$htmlname.'" value="'.$liststring.'"> <input type="hidden" class="'.$htmlname.'" name="'.$htmlname.'" value="'.$listcheckedstring.'">
</a> </a>
</dt> </dt>
<dd> <dd>
<div class="multiselectcheckbox'.$htmlname.'"> <div class="multiselectcheckbox'.$htmlname.'">
<ul> <ul>
@@ -4730,9 +4744,9 @@ class Form
}); });
$(\'.multiselectcheckbox'.$htmlname.' input[type="checkbox"]\').on(\'click\', function () { $(\'.multiselectcheckbox'.$htmlname.' input[type="checkbox"]\').on(\'click\', function () {
console.log("A new field was added/removed")
$("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\')
var title = $(this).val() + ","; var title = $(this).val() + ",";
if ($(this).is(\':checked\')) { if ($(this).is(\':checked\')) {
$(\'.'.$htmlname.'\').val(title + $(\'.'.$htmlname.'\').val()); $(\'.'.$htmlname.'\').val(title + $(\'.'.$htmlname.'\').val());
} }

View File

@@ -55,3 +55,5 @@ ALTER TABLE llx_adherent ADD COLUMN pass_crypted varchar(128) after pass;
ALTER TABLE llx_paiement ADD COLUMN ref varchar(30) NOT NULL AFTER rowid; ALTER TABLE llx_paiement ADD COLUMN ref varchar(30) NOT NULL AFTER rowid;
ALTER TABLE llx_socpeople ADD COLUMN photo varchar(255) AFTER skype; ALTER TABLE llx_socpeople ADD COLUMN photo varchar(255) AFTER skype;
ALTER TABLE llx_user_param MODIFY COLUMN value text NOT NULL;

View File

@@ -23,7 +23,7 @@ create table llx_user_param
fk_user integer NOT NULL, fk_user integer NOT NULL,
entity integer DEFAULT 1 NOT NULL, -- multi company id entity integer DEFAULT 1 NOT NULL, -- multi company id
param varchar(64) NOT NULL, param varchar(64) NOT NULL,
value varchar(255) NOT NULL value text NOT NULL
)ENGINE=innodb; )ENGINE=innodb;
-- --

View File

@@ -89,7 +89,7 @@ else $result=restrictedArea($user,'produit|service','','','','','',$objcanvas);
* Actions * Actions
*/ */
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
{ {
$sref=""; $sref="";
$sbarcode=""; $sbarcode="";

View File

@@ -75,7 +75,8 @@ $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('thirdpartylist')); $contextpage='thirdpartylist';
$hookmanager->initHooks(array($contextpage));
$extrafields = new ExtraFields($db); $extrafields = new ExtraFields($db);
@@ -83,6 +84,8 @@ $extrafields = new ExtraFields($db);
* Actions * Actions
*/ */
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// special search // special search
if ($mode == 'search') if ($mode == 'search')
{ {
@@ -168,7 +171,7 @@ llxHeader('',$langs->trans("ThirdParty"),$help_url);
// Do we click on purge search criteria ? // Do we click on purge search criteria ?
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
{ {
$search_categ=''; $search_categ='';
$search_sale=''; $search_sale='';
@@ -197,12 +200,14 @@ if ($socname)
/* /*
* Mode List * Mode List
*/ */
/* /*
REM: Regle sur droits "Voir tous les clients" REM: Rules on permissions to see thirdparties
Utilisateur interne socid=0 + Droits voir tous clients => Voit toute societe Internal or External user + No permission to see customers => See nothing
Utilisateur interne socid=0 + Pas de droits voir tous clients => Ne voit que les societes liees comme commercial Internal user socid=0 + Permission to see ALL customers => See all thirdparties
Utilisateur externe socid=x + Droits voir tous clients => Ne voit que lui meme Internal user socid=0 + No permission to see ALL customers => See only thirdparties linked to user that are sale representative
Utilisateur externe socid=x + Pas de droits voir tous clients => Ne voit que lui meme External user socid=x + Permission to see ALL customers => Can see only himself
External user socid=x + No permission to see ALL customers => Can see only himself
*/ */
$title=$langs->trans("ListOfThirdParties"); $title=$langs->trans("ListOfThirdParties");
@@ -315,6 +320,7 @@ if ($resql)
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">'; print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">'; if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
// Filter on categories // Filter on categories
/* Not possible in this page because list is for ALL third parties type /* Not possible in this page because list is for ALL third parties type
@@ -362,7 +368,8 @@ if ($resql)
); );
if ($conf->global->MAIN_FEATURES_LEVEL >= 2) if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
{ {
$selectotherfields=$form->multiSelectArrayWithCheckbox('selectotherfields', $arrayfields); $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);
} }
print '<table class="liste '.($moreforfilter?"listwithfilterbefore":"").'">'; print '<table class="liste '.($moreforfilter?"listwithfilterbefore":"").'">';
@@ -382,7 +389,7 @@ if ($resql)
$reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"s.status","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"s.status","",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre($selectotherfields, $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch '); print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch ');
print "</tr>\n"; print "</tr>\n";
// Fields title search // Fields title search