From 3ad1602b92abfa2bb34f4db76ca58a41a3bba3ed Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sun, 30 Oct 2022 18:37:41 +0100 Subject: [PATCH] Improve Output_Html : row , tab and accordean --- include/lib/output_html_tab.class.php | 51 +++++++++++++++++++-------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/include/lib/output_html_tab.class.php b/include/lib/output_html_tab.class.php index 1eff7f605..89ff75cde 100644 --- a/include/lib/output_html_tab.class.php +++ b/include/lib/output_html_tab.class.php @@ -166,23 +166,28 @@ class Output_Html_Tab } /** - * set the mode , possible values are row or tabs - * @param mixed $mode + * @brief set the mode , possible values : row , tabs or accordeon + * @param string $mode possible values : row , tabs or accordeon */ public function set_mode($mode) { - if ($mode != "row" && $mode != "tab") { + if (! in_array($mode,['tab','row','accordeon'] )) { throw new Exception(_("OUTPUTHTML070 Mode invalide")); } $this->mode = $mode; if ($mode == "row") { $this->set_class_tab_selected("tab_row_selected"); $this->set_class_tab("tab_row"); - } - if ( $mode == "tab") { + + }elseif ( $mode == "tab") { $this->set_class_tab_selected("tabs_selected"); $this->set_class_tab("tabs"); + }elseif ($mode == "accordeon") { + $this->set_class_tab_selected(""); + $this->set_class_tab("tab_row"); + } else { + throw new \Exception("OH186.unknow mode [$mode]"); } return $this; } @@ -244,9 +249,15 @@ class Output_Html_Tab { $r=""; $nb=count($this->a_tabs); + $mode=$this->get_mode(); + if ($mode=="accordeon") { + $r .= \Icon_Action::toggle_hide(uniqid(), sprintf("div%s", $p_not_hidden)); + + return $r; + } for ($i =0 ; $i < $nb;$i++) { - if ($this->get_mode()=="tab") { + if ($mode=="tab") { if ( $this->a_tabs[$i]->get_id() != $p_not_hidden) { $r .= sprintf("$('div%s').hide();",$this->a_tabs[$i]->get_id() ); @@ -256,7 +267,7 @@ class Output_Html_Tab $r .= sprintf("$('tab%s').className='%s';",$p_not_hidden ,$this->class_tab_selected); } - } elseif ($this->get_mode()=="row") { + } elseif ($mode=="row") { if ( $this->a_tabs[$i]->get_id() != $p_not_hidden) { $r .= sprintf("Effect.BlindUp('div%s',{duration : 0.7});",$this->a_tabs[$i]->get_id() ); $r .= sprintf("$('tab%s').className='%s';",$this->a_tabs[$i]->get_id(),$this->class_tab ); @@ -265,6 +276,8 @@ class Output_Html_Tab $r .= sprintf("$('tab%s').className='%s';",$p_not_hidden ,$this->class_tab_selected); } + } else { + throw new \Exception("OH283.unknow mode [$mode]"); } } return $r; @@ -294,6 +307,7 @@ class Output_Html_Tab } printf('
',$this->class_div); printf ( ''; echo '
'; - if ( $this->get_mode()=="tab" ) { + if ( $mode=="tab" ) { for ($i=0;$i<$nb;$i++) { $this->print_div($i); @@ -363,10 +383,13 @@ class Output_Html_Tab private function print_div($p_index) { $class=""; - if ( $this->get_mode() == "row") { + if ( $this->get_mode() == "row" ) { $class="tab_row"; + } elseif ( $this->get_mode() == 'accordeon') { + $class=""; } + printf('