fix list issue

This commit is contained in:
Alexis Algoud
2016-12-16 16:09:02 +01:00
parent 4d375bcf95
commit 79867a85d0
6 changed files with 152 additions and 107 deletions

View File

@@ -40,7 +40,7 @@ class Listview {
if(!isset($TParam['link']))$TParam['link']=array(); if(!isset($TParam['link']))$TParam['link']=array();
if(!isset($TParam['type']))$TParam['type']=array(); if(!isset($TParam['type']))$TParam['type']=array();
if(!isset($TParam['orderby']['noOrder']))$TParam['orderby']['noOrder']=array(); if(!isset($TParam['orderby']['noOrder']))$TParam['orderby']['noOrder']=array();
if(!isset($TParam['no-select'])) $TParam['no-select'] = 1; if(!isset($TParam['allow-fields-select'])) $TParam['allow-fields-select'] = 0;
if(!isset($TParam['list']))$TParam['list']=array(); if(!isset($TParam['list']))$TParam['list']=array();
$TParam['list'] = array_merge(array( $TParam['list'] = array_merge(array(
@@ -53,7 +53,7 @@ class Listview {
,'orderUp'=>'' ,'orderUp'=>''
,'id'=>$this->id ,'id'=>$this->id
,'head_search'=>'' ,'head_search'=>''
,'export'=>array() ,'export'=>array() //TODO include native export
,'view_type'=>'' //TODO to include graph or kanban instead of list ,'view_type'=>'' //TODO to include graph or kanban instead of list
),$TParam['list']); ),$TParam['list']);
@@ -133,7 +133,7 @@ class Listview {
} }
} }
private function addSqlFromOther(&$TSQLMore, &$value, &$TParam, $sKey, $sBindKey, $key) private function addSqlFromOther(&$TSQLMore, &$value, &$TParam, $sKey, $key)
{ {
if(isset($TParam['operator'][$key])) if(isset($TParam['operator'][$key]))
@@ -272,38 +272,40 @@ class Listview {
//$fsearch=$form->calendrier('','Listview['.$this->id.'][search]['.$key.']',$value,10,10,' listviewtbs="calendar" '); //$fsearch=$form->calendrier('','Listview['.$this->id.'][search]['.$key.']',$value,10,10,' listviewtbs="calendar" ');
} }
else if($typeRecherche==='calendars') { else if($typeRecherche==='calendars') {
$fsearch=$form->calendrier('','Listview['.$this->id.'][search]['.$key.'][start]',isset($value['start'])?$value['start']:'',10,10,' listviewtbs="calendars" ')
.' '.$form->calendrier('','Listview['.$this->id.'][search]['.$key.'][end]',isset($value['end'])?$value['end']:'',10,10,' listviewtbs="calendars" '); $fsearch = $form->select_date(isset($value['start'])?$value['start']:'', 'Listview['.$this->id.'][search]['.$key.'][start]',0, 0, 1, "", 1, 0, 1)
. $form->select_date(isset($value['end'])?$value['end']:'', 'Listview['.$this->id.'][search]['.$key.'][end]',0, 0, 1, "", 1, 0, 1);
} }
else if(is_string($typeRecherche)) { else if(is_string($typeRecherche)) {
$fsearch=$TParam['search'][$key]; $fsearch=$TParam['search'][$key];
} }
else { else {
$fsearch=$form->texte('','Listview['.$this->id.'][search]['.$key.']',$value,15,255,' listviewtbs="input" '); $fsearch='<input type="text" name="Listview['.$this->id.'][search]['.$key.']" id="Listview['.$this->id.'][search]['.$key.']" value="'.$value.'" size="15" />';
} }
if(!empty($param_search['allow_is_null'])) { if(!empty($param_search['allow_is_null'])) {
$valueNull = isset($_REQUEST['Listview'][$this->id]['search_on_null'][$key]) ? 1 : 0; $valueNull = isset($ListPOST[$this->id]['search_on_null'][$key]) ? 1 : 0;
$fsearch.=' '.$form->checkbox1('', 'Listview['.$this->id.'][search_on_null]['.$key.']',1, $valueNull,' onclick=" if($(this).is(\':checked\')){ $(this).prev().val(\'\'); }" ').img_help(1, $langs->trans('SearchOnNUllValue')); $fsearch.=' '.$form->checkbox1('', 'Listview['.$this->id.'][search_on_null]['.$key.']',1, $valueNull,' onclick=" if($(this).is(\':checked\')){ $(this).prev().val(\'\'); }" ').img_help(1, $langs->trans('SearchOnNUllValue'));
} }
if(!empty($THeader[$key]) || $this->getViewType($TParam) == 'chart') { if(!empty($THeader[$key])) {
$TSearch[$key] = $fsearch; $TSearch[$key] = $fsearch;
$nb_search_in_bar++; $nb_search_in_bar++;
} }
else { else {
$libelle = !empty($TParam['title'][$key]) ? $TParam['title'][$key] : $key ; $label = !empty($TParam['title'][$key]) ? $TParam['title'][$key] : $key ;
$TParam['liste']['head_search'].='<div>'.$libelle.' '.$fsearch.'</div>'; $TParam['list']['head_search'].='<div><span style="min-width:200px;display:inline-block;">'.$libelle.'</span> '.$fsearch.'</div>';
} }
} }
$search_button = ' <a href="#" onclick="Listview_submitSearch(this);" class="list-search-link">'.$TParam['liste']['picto_search'].'</a>'; $search_button = ' <a href="#" onclick="Listview_submitSearch(this);" class="list-search-link">'.img_search().'</a>';
if(!empty($TParam['liste']['head_search'])) { if(!empty($TParam['list']['head_search'])) {
$TParam['liste']['head_search'].='<div align="right">'.$langs->trans('Search').' '.$search_button.'</div>'; $TParam['list']['head_search']='<div style="float:right;">'.$search_button.'</div>'.$TParam['list']['head_search'];
} }
if($nb_search_in_bar>0) { if($nb_search_in_bar>0) {
@@ -364,7 +366,7 @@ class Listview {
return array($TTotal,$TTotalGroup); return array($TTotal,$TTotalGroup);
} }
private function getJS(&$TParam) { private function getJS() {
$javaScript = '<script language="javascript"> $javaScript = '<script language="javascript">
if(typeof(Listview_include)=="undefined") { if(typeof(Listview_include)=="undefined") {
document.write("<script type=\"text/javascript\" src=\"'.DOL_URL_ROOT.'/core/js/listview.js?version='.DOL_VERSION.'\"></scr"); document.write("<script type=\"text/javascript\" src=\"'.DOL_URL_ROOT.'/core/js/listview.js?version='.DOL_VERSION.'\"></scr");
@@ -467,34 +469,32 @@ class Listview {
private function renderList(&$THeader, &$TField, &$TTotal,&$TTotalGroup, &$TParam) { private function renderList(&$THeader, &$TField, &$TTotal,&$TTotalGroup, &$TParam) {
$javaScript = $this->getJS($TParam);
/*$TPagination=array(
'pagination'=>array('pageSize'=>$TParam['limit']['nbLine'], 'pageNum'=>$TParam['limit']['page'], 'blockName'=>'champs', 'totalNB'=>count($TField))
);*/
$TSearch = $this->setSearch($THeader, $TParam); $TSearch = $this->setSearch($THeader, $TParam);
$TExport=$this->setExport($TParam, $TField, $THeader); $TExport=$this->setExport($TParam, $TField, $THeader);
$TField = $this->addTotalGroup($TField,$TTotalGroup); $TField = $this->addTotalGroup($TField,$TTotalGroup);
$out = $javaScript; $out = $this->getJS();
$out.=load_fiche_titre($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $TParam['limit']['page'], count($TField), 'title_products.png', 0, '', '', $limit); $out.=load_fiche_titre($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $TParam['limit']['page'], count($TField), 'title_products.png', 0, '', '', $limit);
$out.='<table id="'.$this->id.'" class="liste" width="100%"> $out.='<table id="'.$this->id.'" class="liste" width="100%">
<thead>'; <thead>';
if(!empty($TParam['liste']['head_search'])) { if(!empty($TParam['list']['head_search'])) {
$out.='<tr class="liste_titre barre-recherche-head"> $out.='<tr class="liste_titre barre-recherche-head">
<td colspan="'.$TParam['liste']['nb_columns'].'">'.$TParam['liste']['head_search'].'</td> <td colspan="'.count($THeader).'">'.$TParam['list']['head_search'].'</td>
</tr>'; </tr>';
} }
$out.='<tr class="liste_titre">'; $out.='<tr class="liste_titre">';
foreach($THeader as $head) { foreach($THeader as $field=>$head) {
if(empty($head['width']))$head['width']='auto';
$out.='<th style="width:'.$head['width'].';text-align:'.$head['text-align'].'" class="liste_titre">'.$head['libelle']; $out.='<th style="width:'.$head['width'].';text-align:'.$head['text-align'].'" class="liste_titre">'.$head['libelle'];
if($head['order']) $out.='<span class="nowrap">[onshow;block=span; when [entete.order]==1]<a href="javascript:Listview_OrderDown(\'[liste.id]\',\'[entete.$;strconv=js]\')">'.img_down().'</a> if($head['order']) $out.='<span class="nowrap">
<a href="javascript:Listview_OrderUp(\'[liste.id]\', \'[entete.$;strconv=js]\')">'.img_up().'</a></span>'; <a href="javascript:Listview_OrderDown(\''.$this->id.'\',\''.$field.'\')">'.img_down().'</a>
<a href="javascript:Listview_OrderUp(\''.$this->id.'\', \''.$field.'\')">'.img_up().'</a>
</span>';
$out.=$head['more']; $out.=$head['more'];
$out.='</th>'; $out.='</th>';
@@ -517,7 +517,7 @@ class Listview {
if(empty($TField)) { if(empty($TField)) {
$out.='<tr class="'.$class.'"> $out.='<tr class="'.$class.'">
<td colspan="'.$TParam['liste']['nb_columns'].'">'.$TParam['liste']['messageNothing'].'</td></tr>'; <td colspan="'.$TParam['list']['nb_columns'].'">'.$TParam['list']['messageNothing'].'</td></tr>';
} }
else{ else{
@@ -537,7 +537,7 @@ class Listview {
$out.='</tbody>'; $out.='</tbody>';
if(!empty($TParam['liste']['haveTotal'])) { if(!empty($TParam['list']['haveTotal'])) {
$out.='<tfoot> $out.='<tfoot>
<tr class="liste_total">'; <tr class="liste_total">';
@@ -584,8 +584,8 @@ class Listview {
foreach($TParam['orderBy'] as $field=>$order) { foreach($TParam['orderBy'] as $field=>$order) {
if(!$first) $sql.=','; if(!$first) $sql.=',';
if($order=='DESC')$TParam['liste']['orderDown'] = $field; if($order=='DESC')$TParam['list']['orderDown'] = $field;
else $TParam['liste']['orderUp'] = $field; else $TParam['list']['orderUp'] = $field;
if(strpos($field,'.')===false) $sql.='`'.$field.'` '.$order; if(strpos($field,'.')===false) $sql.='`'.$field.'` '.$order;
else $sql.=$field.' '.$order; else $sql.=$field.' '.$order;
@@ -610,7 +610,7 @@ class Listview {
foreach($TField as $row) { foreach($TField as $row) {
if($first) { if($first) {
$this->init_entete($THeader, $TParam, $row); $this->initHeader($THeader, $TParam, $row);
$first=false; $first=false;
} }
@@ -619,7 +619,7 @@ class Listview {
} }
private function init_entete(&$THeader, &$TParam, $currentLine) { private function initHeader(&$THeader, &$TParam, $currentLine) {
$TField=$TFieldVisibility=array(); $TField=$TFieldVisibility=array();
@@ -630,9 +630,9 @@ class Listview {
global $user; global $user;
$contextpage=md5($_SERVER['PHP_SELF']); $contextpage=md5($_SERVER['PHP_SELF']);
if(empty($TParam['no-select'])) { if(!empty($TParam['allow-field-select'])) {
dol_include_once('/core/class/html.form.class.php'); include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
global $db,$conf,$user; global $db,$conf,$user;
$form=new Form($db); $form=new Form($db);
@@ -693,7 +693,7 @@ class Listview {
$lastfield = $field; $lastfield = $field;
$THeader[$field] = array( $THeader[$field] = array(
'libelle'=>$libelle 'libelle'=>$libelle
,'order'=>((in_array($field, $TParam['orderby']['noOrder']) || $this->typeRender != 'sql') ? 0 : 1) ,'order'=>(in_array($field, $TParam['orderby']['noOrder']) ? 0 : 1)
,'width'=>(!empty($TParam['size']['width'][$field]) ? $TParam['size']['width'][$field] : 'auto') ,'width'=>(!empty($TParam['size']['width'][$field]) ? $TParam['size']['width'][$field] : 'auto')
,'text-align'=>(!empty($TParam['position']['text-align'][$field]) ? $TParam['position']['text-align'][$field] : 'auto') ,'text-align'=>(!empty($TParam['position']['text-align'][$field]) ? $TParam['position']['text-align'][$field] : 'auto')
,'more'=>'' ,'more'=>''
@@ -843,7 +843,7 @@ class Listview {
$first=true; $first=true;
while($currentLine = $this->db->fetch_object($res)) { while($currentLine = $this->db->fetch_object($res)) {
if($first) { if($first) {
$this->init_entete($THeader, $TParam, $currentLine); $this->initHeader($THeader, $TParam, $currentLine);
$first = false; $first = false;
} }

View File

@@ -85,7 +85,15 @@ function Listview_GoToPage(idListe,pageNumber){
} }
function Listview_submitSearch(obj) { function Listview_submitSearch(obj) {
$(obj).closest('form').submit(); $form = $(obj).closest('form');
console.log($form);
if($form.length>0){
$form.submit();
}
else{
//There is no form for search action
null;
}
} }
function Listview_launch_downloadAs(mode,url,token,session_name) { function Listview_launch_downloadAs(mode,url,token,session_name) {

View File

@@ -250,7 +250,7 @@ class modinventory extends DolibarrModules
'titre'=>'ListInventory', 'titre'=>'ListInventory',
'mainmenu'=>'inventory', 'mainmenu'=>'inventory',
'leftmenu'=>'inventory', 'leftmenu'=>'inventory',
'url'=>'/inventory/inventory.php?action=list', 'url'=>'/inventory/list.php',
'langs'=>'inventory', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. 'langs'=>'inventory', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>100, 'position'=>100,
'enabled'=>'$conf->inventory->enabled', // Define condition to show or hide menu entry. Use '$conf->inventory->enabled' if entry must be visible if module is enabled. 'enabled'=>'$conf->inventory->enabled', // Define condition to show or hide menu entry. Use '$conf->inventory->enabled' if entry must be visible if module is enabled.

View File

@@ -362,7 +362,7 @@ class Inventory extends CoreObject
if($type=='All') { if($type=='All') {
$sql="SELECT i.rowid, e.label, i.date_inventory, i.fk_warehouse, i.datec, i.tms, i.status $sql="SELECT i.rowid,i.title, e.label, i.date_inventory, i.fk_warehouse, i.datec, i.tms, i.status
FROM ".MAIN_DB_PREFIX."inventory i FROM ".MAIN_DB_PREFIX."inventory i
LEFT JOIN ".MAIN_DB_PREFIX."entrepot e ON (e.rowid = i.fk_warehouse) LEFT JOIN ".MAIN_DB_PREFIX."entrepot e ON (e.rowid = i.fk_warehouse)
WHERE i.entity=".(int) $conf->entity; WHERE i.entity=".(int) $conf->entity;

View File

@@ -53,11 +53,6 @@ function _action()
$action=GETPOST('action'); $action=GETPOST('action');
switch($action) { switch($action) {
case 'list':
_list();
break;
case 'create': case 'create':
if (!$user->rights->inventory->create) accessforbidden(); if (!$user->rights->inventory->create) accessforbidden();
@@ -264,7 +259,7 @@ function _action()
setEventMessage($langs->trans('InventoryDeleted')); setEventMessage($langs->trans('InventoryDeleted'));
header('Location: '.dol_buildpath('/inventory/inventory.php?action=list', 1)); header('Location: '.dol_buildpath('/inventory/list.php', 1));
exit; exit;
break; break;
@@ -296,67 +291,6 @@ function _action()
} }
function _list()
{
global $db, $conf, $langs, $user;
llxHeader('',$langs->trans('inventoryListTitle'),'','');
$inventory = new Inventory($db);
$l = new ListView($db,'listInventory');
$THide = array('label');
echo $l->render(Inventory::getSQL('All'), array(
'link'=>array(
'fk_warehouse'=>'<a href="'.DOL_URL_ROOT.'/product/stock/card.php?id=@val@">'.img_picto('','object_stock.png','',0).' @label@</a>'
)
,'translate'=>array()
,'hide'=>$THide
,'type'=>array(
'datec'=>'date'
,'tms'=>'datetime'
,'date_inventory'=>'date'
)
,'liste'=>array(
'titre'=>$langs->trans('inventoryListTitle')
,'image'=>img_picto('','title.png', '', 0)
,'picto_precedent'=>img_picto('','back.png', '', 0)
,'picto_suivant'=>img_picto('','next.png', '', 0)
,'noheader'=> (int)isset($_REQUEST['fk_soc']) | (int)isset($_REQUEST['fk_product'])
,'messageNothing'=>$langs->trans('inventoryListEmpty')
,'picto_search'=>img_picto('','search.png', '', 0)
)
,'title'=>array(
'rowid'=>$langs->trans('Title')
,'fk_warehouse'=>$langs->trans('Warehouse')
,'date_inventory'=>$langs->trans('InventoryDate')
,'datec'=>$langs->trans('DateCreation')
,'tms'=>$langs->trans('DateUpdate')
,'status'=>$langs->trans('Status')
)
,'eval'=>array(
'status' => '(@val@ ? img_picto("'.$langs->trans("inventoryValidate").'", "statut4") : img_picto("'.$langs->trans("inventoryDraft").'", "statut3"))'
,'rowid'=>'Inventory::getLink(@val@)'
)
,'search'=>array(
'date_inventory'=>'calendar'
)
));
if ($user->rights->inventory->create)
{
print '<div class="tabsAction">';
print '<a class="butAction" href="inventory.php?action=create">'.$langs->trans('inventoryCreate').'</a>';
print '</div>';
}
llxFooter('');
}
function _card_warehouse(&$inventory) function _card_warehouse(&$inventory)
{ {
global $langs,$conf,$db, $user, $form; global $langs,$conf,$db, $user, $form;

103
htdocs/inventory/list.php Normal file
View File

@@ -0,0 +1,103 @@
<?php
/* Copyright (C) 2016 ATM Consulting <support@atm-consulting.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
* 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/>.
*/
/**
* \file htdocs/inventory/inventory.php
* \ingroup product
* \brief File of class to manage inventory
*/
require_once '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/listview.class.php';
require_once DOL_DOCUMENT_ROOT.'/inventory/class/inventory.class.php';
require_once DOL_DOCUMENT_ROOT.'/inventory/lib/inventory.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
include_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
$langs->load("stock");
$langs->load("inventory");
if(!$user->rights->inventory->read) accessforbidden();
_list();
function _list()
{
global $db, $conf, $langs, $user;
llxHeader('',$langs->trans('inventoryListTitle'),'','');
echo '<form name="formListInvetory" action="'.$_SERVER['PHP_SELF'].'" method="post" >';
$inventory = new Inventory($db);
$l = new ListView($db,'listInventory');
$THide = array('label','title');
echo $l->render(Inventory::getSQL('All'), array(
'link'=>array(
'fk_warehouse'=>'<a href="'.DOL_URL_ROOT.'/product/stock/card.php?id=@val@">'.img_picto('','object_stock.png','',0).' @label@</a>'
)
,'translate'=>array()
,'hide'=>$THide
,'type'=>array(
'datec'=>'date'
,'tms'=>'datetime'
,'date_inventory'=>'date'
)
,'list'=>array(
'title'=>$langs->trans('inventoryListTitle')
,'messageNothing'=>$langs->trans('inventoryListEmpty')
)
,'title'=>array(
'rowid'=>$langs->trans('Title')
,'fk_warehouse'=>$langs->trans('Warehouse')
,'date_inventory'=>$langs->trans('InventoryDate')
,'datec'=>$langs->trans('DateCreation')
,'tms'=>$langs->trans('DateUpdate')
,'status'=>$langs->trans('Status')
)
,'eval'=>array(
'status' => '(@val@ ? img_picto("'.$langs->trans("inventoryValidate").'", "statut4") : img_picto("'.$langs->trans("inventoryDraft").'", "statut3"))'
,'rowid'=>'Inventory::getLink(@val@)'
)
,'search'=>array(
'date_inventory'=>'calendar'
,'title'=>true
)
));
if ($user->rights->inventory->create)
{
print '<div class="tabsAction">';
print '<a class="butAction" href="inventory.php?action=create">'.$langs->trans('inventoryCreate').'</a>';
print '</div>';
}
echo '</form>';
llxFooter('');
}