From a8931db30da93bbb306287b71f9c00e8f7baf4c6 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Fri, 20 Jun 2008 15:52:15 +0000 Subject: [PATCH] =?UTF-8?q?-=20LSview=20/=20LSselect=20:=20=20=20->=20Ajou?= =?UTF-8?q?t=20d'une=20fonctionnalit=C3=A9=20de=20trie=20par=20colonne=20?= =?UTF-8?q?=20=20->=20template/code=20:=20modification=20du=20principe=20d?= =?UTF-8?q?e=20tr.bis=20=20=20->=20LSselect.js=20:=20correction=20d'un=20b?= =?UTF-8?q?ug=20dans=20la=20m=C3=A9thode=20oncheckboxChange()=20-=20LSsess?= =?UTF-8?q?ion=20:=20=20=20->=20Ajout=20d'une=20m=C3=A9thode=20isSubDnLSob?= =?UTF-8?q?ject()=20=20=20->=20Correction=20d'un=20bug=20dans=20la=20m?= =?UTF-8?q?=C3=A9thode=20getSortSubDnLdapServer()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trunk/includes/class/class.LSsession.php | 22 +++++++ trunk/includes/js/LSselect.js | 19 ++++++ trunk/select.php | 79 ++++++++++++++++++----- trunk/templates/css/base.css | 19 +++++- trunk/templates/images/ASC.png | Bin 0 -> 224 bytes trunk/templates/images/DESC.png | Bin 0 -> 267 bytes trunk/templates/select_table.tpl | 9 +-- trunk/templates/viewList.tpl | 9 +-- trunk/view.php | 69 ++++++++++++++++---- 9 files changed, 191 insertions(+), 35 deletions(-) create mode 100644 trunk/templates/images/ASC.png create mode 100644 trunk/templates/images/DESC.png diff --git a/trunk/includes/class/class.LSsession.php b/trunk/includes/class/class.LSsession.php index 6975514e..752a059e 100644 --- a/trunk/includes/class/class.LSsession.php +++ b/trunk/includes/class/class.LSsession.php @@ -620,6 +620,9 @@ class LSsession { return $_SESSION['LSsession']['LSview_subDnLdapServer']; } $subDnLdapServer = $this -> getSubDnLdapServer(); + if (!$subDnLdapServer) { + return array(); + } uksort($subDnLdapServer,"compareDn"); $_SESSION['LSsession']['LSview_subDnLdapServer']=$subDnLdapServer; return $subDnLdapServer; @@ -1283,6 +1286,25 @@ class LSsession { return ''; } + /** + * L'objet est t-il utilisé pour listé les subDnS + * + * @param[in] $type string Le type d'objet + * + * @return boolean true si le type d'objet est un subDnObject, false sinon + */ + function isSubDnLSobject($type) { + debug('seach : '.$type); + $result = false; + if (is_array($this -> ldapServer['subDn']['LSobject'])) { + foreach($this -> ldapServer['subDn']['LSobject'] as $key => $value) { + if ($key==$type) { + $result=true; + } + } + } + return $result; + } } ?> diff --git a/trunk/includes/js/LSselect.js b/trunk/includes/js/LSselect.js index 978f80d0..3c3ca177 100644 --- a/trunk/includes/js/LSselect.js +++ b/trunk/includes/js/LSselect.js @@ -29,6 +29,14 @@ var LSselect = new Class({ $$('a.LSobject-list-page').each(function(el) { el.addEvent('click',this.onChangePageClick.bindWithEvent(this,el)); }, this); + + $$('.sortBy_displayValue').each(function(el) { + el.addEvent('click',this.sortBy.bind(this,'displayValue')); + }, this); + + $$('.sortBy_subDn').each(function(el) { + el.addEvent('click',this.sortBy.bind(this,'subDn')); + }, this); }, oncheckboxChange: function(checkbox){ @@ -114,5 +122,16 @@ var LSselect = new Class({ input.setProperty('type','hidden'); input.injectInside(this.LSselect_search_form); this.submitSearchForm(); + input.remove(); + }, + + sortBy: function(value) { + var input = new Element('input'); + input.setProperty('name','orderby'); + input.setProperty('type','hidden'); + input.setProperty('value',value); + input.injectInside(this.LSselect_search_form); + this.submitSearchForm(); + input.remove(); } }); diff --git a/trunk/select.php b/trunk/select.php index 97da2847..42d54285 100644 --- a/trunk/select.php +++ b/trunk/select.php @@ -36,6 +36,8 @@ if($LSsession -> startLSsession()) { $GLOBALS['Smarty']->assign('pagetitle',$object -> getLabel()); $GLOBALS['Smarty']->assign('LSobject_list_objectname',$object -> getLabel()); + $subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer(); + if (isset($_SESSION['LSsession']['LSsearch'][$LSobject])) { $filter = $_SESSION['LSsession']['LSsearch'][$LSobject]['filter']; if (isCompatibleDNs($_SESSION['LSsession']['LSsearch'][$LSobject]['topDn'],$GLOBALS['LSsession'] -> topDn)) { @@ -51,6 +53,9 @@ if($LSsession -> startLSsession()) { $recur = $_SESSION['LSsession']['LSsearch'][$LSobject]['recur']; $approx = $_SESSION['LSsession']['LSsearch'][$LSobject]['approx']; $selectedTopDn = $_SESSION['LSsession']['LSsearch'][$LSobject]['selectedTopDn']; + $orderby = $_SESSION['LSsession']['LSsearch'][$LSobject]['orderby']; + $ordersense = $_SESSION['LSsession']['LSsearch'][$LSobject]['ordersense']; + $doSubDn = $_SESSION['LSsession']['LSsearch'][$LSobject]['doSubDn']; } else { $filter = NULL; @@ -60,6 +65,9 @@ if($LSsession -> startLSsession()) { $recur = false; $approx = false; $selectedTopDn = $GLOBALS['LSsession'] -> topDn; + $orderby = false; + $ordersense = 'ASC'; + $doSubDn = (($subDnLdapServer)&&(!$GLOBALS['LSsession']->isSubDnLSobject($LSobject))); } if (isset($_REQUEST['LSview_search_submit'])) { @@ -113,6 +121,23 @@ if($LSsession -> startLSsession()) { } } + $sort=false; + if ((isset($_REQUEST['orderby']))) { + $possible_values= array('displayValue','subDn'); + if (in_array($_REQUEST['orderby'],$possible_values)) { + $sort=true; + if ($orderby==$_REQUEST['orderby']) { + $ordersense = ($ordersense=='ASC')?'DESC':'ASC'; + } + else { + $ordersense = 'ASC'; + } + $orderby=$_REQUEST['orderby']; + } + } + + $GLOBALS['Smarty']->assign('LSobject_list_subDn',$doSubDn); + // Sauvegarde en Session $_SESSION['LSsession']['LSsearch'][$LSobject] = array( 'filter' => $filter, @@ -121,7 +146,10 @@ if($LSsession -> startLSsession()) { 'pattern' => $pattern, 'recur' => $recur, 'approx' => $approx, - 'selectedTopDn' => $selectedTopDn + 'selectedTopDn' => $selectedTopDn, + 'orderby' => $orderby, + 'ordersense' => $ordersense, + 'doSubDn' => $doSubDn ); $GLOBALS['Smarty']->assign('LSview_search_pattern',$pattern); @@ -175,7 +203,6 @@ if($LSsession -> startLSsession()) { $c=0; - $subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer(); foreach($list as $thisObject) { if ($GLOBALS['LSsession'] -> canAccess($LSobject,$thisObject->getValue('dn'))) { @@ -183,10 +210,12 @@ if($LSsession -> startLSsession()) { unset($actions); $subDn_name=false; - reset($subDnLdapServer); - while (!$subDn_name && next($subDnLdapServer)) { - if (isCompatibleDNs(key($subDnLdapServer),$thisObject -> getValue('dn'))) { - $subDn_name=current($subDnLdapServer); + if ($doSubDn) { + reset($subDnLdapServer); + while (!$subDn_name && next($subDnLdapServer)) { + if (isCompatibleDNs(key($subDnLdapServer),$thisObject -> getValue('dn'))) { + $subDn_name=current($subDnLdapServer); + } } } @@ -208,6 +237,34 @@ if($LSsession -> startLSsession()) { } $GLOBALS['Smarty']->assign('LSobject_list_nbresult',$searchData['LSobject_list_nbresult']); + // Order by if $sort + if ($sort) { + function sortBy($a,$b) { + global $ordersense; + global $orderby; + + if ($ordersense=='ASC') { + $sense = -1; + } + else { + $sense = 1; + } + + if ($a == $b) return 0; + $sort = array($a[$orderby],$b[$orderby]); + sort($sort); + if ($sort[0]==$a[$orderby]) + return 1*$sense; + return -1*$sense; + } + if (!uasort($searchData['objectList'],'sortBy')) { + debug('Erreur durant le trie.'); + } + $_SESSION['LSsession']['LSsearch'][$hash]=$searchData; + } + $GLOBALS['Smarty']->assign('LSobject_list_orderby',$orderby); + $GLOBALS['Smarty']->assign('LSobject_list_ordersense',$ordersense); + // Pagination if ($searchData['LSobject_list_nbresult'] > NB_LSOBJECT_LIST) { if (isset($_REQUEST['page'])) { @@ -223,16 +280,8 @@ if($LSsession -> startLSsession()) { $GLOBALS['Smarty']->assign('LSobject_list_nbpage',$searchData['LSobject_list_nbpage']); } - // Bis/Pas Bis + Select/Pas Select + // Select/Pas Select for($i=0;$i93w#6z^X@?Aq0byC4>ot~3Mq~_ z{c6!SL6^I%1@gO>^u-r3KXYK85_QJSPyYeK8YPwwY)ft*xXAh7lL*jF44$rjF6*2U FngFOoVAB8q literal 0 HcmV?d00001 diff --git a/trunk/templates/select_table.tpl b/trunk/templates/select_table.tpl index b845c7fb..b1bc75ac 100644 --- a/trunk/templates/select_table.tpl +++ b/trunk/templates/select_table.tpl @@ -1,14 +1,15 @@ - - {if $label_level}{/if} + + {if $LSobject_list_subDn}{/if} +{assign var='bis' value=false} {foreach from=$LSobject_list item=object} - + - {if $label_level}{/if} + {if $LSobject_list_subDn}{/if} {foreachelse} diff --git a/trunk/templates/viewList.tpl b/trunk/templates/viewList.tpl index 79350721..5819b581 100644 --- a/trunk/templates/viewList.tpl +++ b/trunk/templates/viewList.tpl @@ -24,14 +24,15 @@
{$LSobject_list_objectname}{$label_level}{if $LSobject_list_orderby == 'displayValue'}{$LSobject_list_objectname}{$LSobject_list_ordersense}{else}{$LSobject_list_objectname}{/if}{if $LSobject_list_orderby == 'subDn'}{$label_level}{$LSobject_list_ordersense}{else}{$label_level}{/if}
{$object.displayValue}{$object.subDn}{$object.subDn}
- - {if $label_level}{/if} + + {if $LSobject_list_subDn}{/if} + {assign var='bis' value=false} {foreach from=$LSobject_list item=object} - + - {if $label_level}{/if} + {if $LSobject_list_subDn}{/if}
{$LSobject_list_objectname}{$label_level}{if $LSobject_list_orderby == 'displayValue'}{$LSobject_list_objectname}{$LSobject_list_ordersense}{else}{$LSobject_list_objectname}{/if}{if $LSobject_list_orderby == 'subDn'}{$label_level}{$LSobject_list_ordersense}{else}{$label_level}{/if}{$_Actions}
{$object.displayValue} {$object.subDn}{$object.subDn} {if $object.actions!=''} {foreach from=$object.actions item=item} diff --git a/trunk/view.php b/trunk/view.php index c6fdc9cd..2456219a 100644 --- a/trunk/view.php +++ b/trunk/view.php @@ -145,6 +145,8 @@ if($LSsession -> startLSsession()) { $GLOBALS['Smarty']->assign('pagetitle',$object -> getLabel()); $GLOBALS['Smarty']->assign('LSobject_list_objectname',$object -> getLabel()); + $subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer(); + if (isset($_SESSION['LSsession']['LSsearch'][$LSobject])) { $filter = $_SESSION['LSsession']['LSsearch'][$LSobject]['filter']; $params = $_SESSION['LSsession']['LSsearch'][$LSobject]['params']; @@ -157,6 +159,9 @@ if($LSsession -> startLSsession()) { $topDn = $object -> config['container_dn'].','.$GLOBALS['LSsession'] -> topDn; } $approx = $_SESSION['LSsession']['LSsearch'][$LSobject]['approx']; + $orderby = $_SESSION['LSsession']['LSsearch'][$LSobject]['orderby']; + $ordersense = $_SESSION['LSsession']['LSsearch'][$LSobject]['ordersense']; + $doSubDn = $_SESSION['LSsession']['LSsearch'][$LSobject]['doSubDn']; } else { $filter = NULL; @@ -165,6 +170,9 @@ if($LSsession -> startLSsession()) { $pattern = false; $recur = false; $approx = false; + $orderby = false; + $ordersense = 'ASC'; + $doSubDn = (($subDnLdapServer)&&(!$GLOBALS['LSsession']->isSubDnLSobject($LSobject))); } if (isset($_REQUEST['LSview_search_submit'])) { @@ -204,6 +212,23 @@ if($LSsession -> startLSsession()) { } } + $sort=false; + if ((isset($_REQUEST['orderby']))) { + $possible_values= array('displayValue','subDn'); + if (in_array($_REQUEST['orderby'],$possible_values)) { + $sort=true; + if ($orderby==$_REQUEST['orderby']) { + $ordersense = ($ordersense=='ASC')?'DESC':'ASC'; + } + else { + $ordersense = 'ASC'; + } + $orderby=$_REQUEST['orderby']; + } + } + + $GLOBALS['Smarty']->assign('LSobject_list_subDn',$doSubDn); + // Sauvegarde en Session $_SESSION['LSsession']['LSsearch'][$LSobject] = array( 'filter' => $filter, @@ -211,7 +236,10 @@ if($LSsession -> startLSsession()) { 'params' => $params, 'pattern' => $pattern, 'recur' => $recur, - 'approx' => $approx + 'approx' => $approx, + 'orderby' => $orderby, + 'ordersense' => $ordersense, + 'doSubDn' => $doSubDn ); $GLOBALS['Smarty']->assign('LSview_search_pattern',$pattern); @@ -269,11 +297,10 @@ if($LSsession -> startLSsession()) { $c=0; - $subDnLdapServer = $GLOBALS['LSsession'] -> getSortSubDnLdapServer(); foreach($list as $thisObject) { if ($GLOBALS['LSsession'] -> canAccess($LSobject,$thisObject->getValue('dn'))) { $subDn_name=false; - if ($subDnLdapServer) { + if ($doSubDn) { reset($subDnLdapServer); while (!$subDn_name && next($subDnLdapServer)) { if (isCompatibleDNs(key($subDnLdapServer),$thisObject -> getValue('dn'))) { @@ -314,18 +341,10 @@ if($LSsession -> startLSsession()) { ); } - if (count($objectList)%2==0) { - $tr='bis'; - } - else { - $tr=''; - } - $objectList[]=array( 'dn' => $thisObject->getValue('dn'), 'displayValue' => $thisObject->getDisplayValue(), 'actions' => $actions, - 'tr' => $tr, 'subDn' => $subDn_name ); } @@ -342,6 +361,34 @@ if($LSsession -> startLSsession()) { $GLOBALS['Smarty']->assign('LSobject_list_nbresult',$searchData['LSobject_list_nbresult']); + // Order by if $sort + if ($sort) { + function sortBy($a,$b) { + global $ordersense; + global $orderby; + + if ($ordersense=='ASC') { + $sense = -1; + } + else { + $sense = 1; + } + + if ($a == $b) return 0; + $sort = array($a[$orderby],$b[$orderby]); + sort($sort); + if ($sort[0]==$a[$orderby]) + return 1*$sense; + return -1*$sense; + } + if (!uasort($searchData['objectList'],'sortBy')) { + debug('Erreur durant le trie.'); + } + $_SESSION['LSsession']['LSsearch'][$hash]=$searchData; + } + $GLOBALS['Smarty']->assign('LSobject_list_orderby',$orderby); + $GLOBALS['Smarty']->assign('LSobject_list_ordersense',$ordersense); + // Pagination if ($searchData['LSobject_list_nbresult'] > NB_LSOBJECT_LIST) { if (isset($_REQUEST['page'])) {