• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List

E:/E/GEAMP/www/openbiz/openbiz/bin/easy/HTMLTabs.php

00001 <?PHP
00026 class HTMLTabs extends MetaObject implements iUIControl
00027 {
00028     public $m_TemplateFile;
00029     public $m_TabViews = null;
00030     protected $m_CurrentTab = null;
00031     protected $m_ActiveCssClassName = null;
00032     protected $m_InactiveCssClassName = null;
00033 
00040     function __construct(&$xmlArr)
00041     {
00042         $this->readMetadata($xmlArr);
00043     }
00044 
00050     protected function readMetadata(&$xmlArr)
00051     {
00052         $this->m_Name = $xmlArr["TABS"]["ATTRIBUTES"]["NAME"];
00053         $this->m_Package = $xmlArr["TABS"]["ATTRIBUTES"]["PACKAGE"];
00054         $this->m_Class = $xmlArr["TABS"]["ATTRIBUTES"]["CLASS"];
00055         $this->m_TemplateFile = $xmlArr["TABS"]["ATTRIBUTES"]["TEMPLATEFILE"];
00056         $this->m_TabViews = new MetaIterator($xmlArr["TABS"]["TABVIEWS"]["VIEW"],"TabView");
00057         $this->m_ActiveCssClassName = "'{$xmlArr["TABS"]["ATTRIBUTES"]["ACTIVECSSCLASSNAME"]}'";
00058         $this->m_InactiveCssClassName = "'{$xmlArr["TABS"]["ATTRIBUTES"]["INACTIVECSSCLASSNAME"]}'";
00059     }
00060 
00067     private function _renderJSCodeForForms($forms)
00068     {
00069         $js_array="new Array(";
00070         if($forms)
00071         {
00072             foreach($forms as $form)
00073             {
00074                 if(!is_null($form))
00075                 {
00076                     $js_array.="new Array('{$form['NAME']}','{$form['VISIBLE']}'),";
00077                 }
00078                 else
00079                 {
00080                     // No array entry will be created
00081                 }
00082             }
00083             $js_array = rtrim($js_array,',').")";
00084         }
00085         else
00086         {
00087             $js_array = 'null';
00088         }
00089         return $js_array;
00090     }
00091 
00098     private function _renderURL($tabView)
00099     {
00100         if($tabView->hasForms())
00101         {
00102             $url = "javascript:ChangeTab(this, {$tabView->m_Name}_config)";
00103         }
00104         else if($tabView->m_URL)
00105         {
00106             $url = $tabView->m_URL;
00107         }
00108         else
00109         {
00110             $url = "javascript:Openbiz.Net.loadView('{$tabView->m_View}')";
00111         }
00112 
00113         return $url;
00114     }
00115 
00122     public function setCurrentTab($viewName)
00123     {
00124         $this->m_CurrentTab = $viewName;
00125     }
00126 
00135     public function isCurrentTab($tabView, $curViewObj, $curViewName)
00136     { //--jmmz
00137         $currentTab = false; //this variable save 'true' if is the current tab and 'false' in otherwise --jmmz
00138         if ($this->m_CurrentTab)
00139         {
00140             $currentTab = ($this->m_CurrentTab == $tabView->m_Name || $this->m_CurrentTab == $tabView->m_Tab)
00141                     ? TRUE
00142                     : FALSE;
00143         }
00144         elseif ($tabView->m_ViewSet)
00145         {
00146             if ($curViewObj)
00147             // check if current view's viewset == tview->m_ViewSet
00148                 $currentTab = ($curViewObj->getViewSet() == $tabView->m_ViewSet) ? true : false;
00149         }
00150         else
00151         {
00152             $currentTab = ($curViewName == $tabView->m_View || $curViewObj->m_Tab == $tabView->m_Name) ? true : false;
00153         }
00154 
00155         return $currentTab;
00156     }
00157 
00166     public function setCurrentTabInSession($tview, $curViewObj, $curViewName)
00167     {
00168         $sessionContext = BizSystem::sessionContext();
00169 
00170         if (!$sessionContext->varExists('CURRENT_TAB_'.$this->m_Name))
00171         {
00172             if ($this->isCurrentTab($tview,$curViewObj, $curViewName))
00173             {
00174                 $sessionContext->setVar('CURRENT_TAB_'.$this->m_Name,$tview->m_Name);
00175             }
00176             else
00177             {
00178                 //Don't set var if isn't the current var
00179             }
00180         }
00181         else
00182         {
00183             $this->setCurrentTab($sessionContext->getVar('CURRENT_TAB_'.$this->m_Name));
00184         }
00185     }
00186 
00193     public function render()
00194     {
00195         global $g_BizSystem;
00196 
00197         $curView = $g_BizSystem->getCurrentViewName();
00198         $curViewobj = ($curView) ? BizSystem::getObject($curView) : null;
00199 
00200         $profile = $g_BizSystem->getUserProfile();
00201         $svcobj = BizSystem::getService(ACCESS_SERVICE);
00202         $role = isset($profile["ROLE"]) ? $profile["ROLE"] : null;
00203 
00204         // list all views and highlight the current view
00205         // pass $tabs(caption, url, target, icon, current) to template
00206         $smarty = BizSystem::getSmartyTemplate();
00207         $tabs = array();
00208         $i = 0;
00209         $hasForms = false;
00210         foreach ($this->m_TabViews as $tview)
00211         {
00212             // tab is renderd if  no definition  is found in accessservice.xml (default)
00213             if ($svcobj->allowViewAccess($tview->m_View, $role))
00214             {
00215 
00216                 $tabs[$i]['name']=$tview->m_Name; //Name of each tab--jmmz
00217                 $tabs[$i]['forms']=$this->_renderJSCodeForForms($tview->m_Forms);//Configuration of the forms to hide or show--jmmz
00218                 $tabs[$i]['caption'] = $tview->m_Caption;
00219 
00220                 $tabs[$i]['url'] = $this->_renderURL($tview); //Call the method to render the url--jmmz
00221 
00222                 //If I have forms to hide or show I add the event because I don't need an URL, I need an event
00223                 if( (bool) $tview->hasForms() )
00224                 {
00225                     $tabs[$i]['event']=$tabs[$i]['url']; //Assign The url rendered to the event on click
00226                     $tabs[$i]['url']='javascript:void(0)'; //If I put url in '' then the href want send me to another direction
00227                     $this->setCurrentTabInSession($tview, $curViewobj, $curView); //I set the current tab wrote in session
00228                     $hasForms = TRUE;
00229                 }
00230 
00231                 $tabs[$i]['target'] = $tview->m_Target;
00232                 $tabs[$i]['icon'] = $tview->m_Icon;
00233                 $tabs[$i]['current'] = $this->isCurrentTab($tview,$curViewobj, $curView); //I get the current tab.
00234                 $i++;
00235             }
00236         }
00237         $this->setClientScripts($tabs, $hasForms);
00238         $smarty->assign("tabs", $tabs);
00239         $smarty->assign("tabs_Name",$this->m_Name);
00240 
00241         return $smarty->fetch(BizSystem::getTplFileWithPath($this->m_TemplateFile, $this->m_Package));
00242     }
00243 
00249     public function rerender()
00250     {
00251         return $this->render();
00252     }
00253 
00261     protected function setClientScripts($tabs, $hasForms)
00262     {
00263         global $g_BizSystem;
00264 
00265         BizSystem::clientProxy()->appendScripts("tabs", "tabs.js");
00266         BizSystem::clientProxy()->appendStyles("tabs", "tabs.css");
00267 
00268         if ($hasForms)
00269         {
00270             $tab_script = '<script type = "text/javascript">'.PHP_EOL;
00271             foreach ($tabs as $tab)
00272             {
00273                 $tab_script .=   'var '.$tab['name'].'_config = '.$tab['forms'].';'.PHP_EOL;
00274             }
00275             $tab_script .=   'var '.$this->m_Name.'_active = '.$this->m_ActiveCssClassName.';'.PHP_EOL;
00276             $tab_script .=   'var '.$this->m_Name.'_inactive = '.$this->m_InactiveCssClassName.';'.PHP_EOL;
00277             $tab_script .= '</script>';
00278             BizSystem::clientProxy()->appendScripts("tab_forms_$this->m_Name", $tab_script, FALSE);
00279         }
00280     }
00281 
00282 }
00283 
00293 class TabView
00294 {
00295     public $m_Name;
00296     public $m_View;
00297     public $m_ViewSet;
00298     public $m_Caption;
00299     public $m_URL;
00300     public $m_Target;
00301     public $m_Icon;
00302     public $m_Forms; //Forms for hide or show in a BizView
00303 
00311     private function _getForms($forms)
00312     {
00313         $recArr=array();
00314         if (count($forms) == 0 )
00315             return $recArr;
00316 
00317         foreach($forms as $form)
00318         {
00319             if(!is_null($form["ATTRIBUTES"]))
00320                 $recArr[]=$form["ATTRIBUTES"];
00321             else
00322                 $recArr[]=$form;
00323         }
00324         return $recArr;
00325     }
00326 
00333     function __construct(&$xmlArr)
00334     {
00335         $this->m_Name = $xmlArr["ATTRIBUTES"]["NAME"];
00336         $this->m_View = $xmlArr["ATTRIBUTES"]["VIEW"];
00337         if(array_key_exists("VIEWSET", $xmlArr["ATTRIBUTES"]))
00338             $this->m_ViewSet = $xmlArr["ATTRIBUTES"]["VIEWSET"];
00339         $this->m_Caption = $this->translate($xmlArr["ATTRIBUTES"]["CAPTION"]);
00340         if(array_key_exists("URL", $xmlArr["ATTRIBUTES"]))
00341             $this->m_URL = $xmlArr["ATTRIBUTES"]["URL"];
00342         if(array_key_exists("TARGET", $xmlArr["ATTRIBUTES"]))
00343             $this->m_Target = $xmlArr["ATTRIBUTES"]["TARGET"];
00344         if(array_key_exists("ICON", $xmlArr["ATTRIBUTES"]))
00345             $this->m_Icon = $xmlArr["ATTRIBUTES"]["ICON"];
00346 
00347 
00348         $this->m_Forms = NULL;
00349         if(array_key_exists("FORM", $xmlArr))
00350             $this->m_Forms = $this->_getForms($xmlArr["FORM"]);     //Get form or forms to hide or show
00351 
00352         //$this->m_Forms = (!is_null($xmlArr["FORM"]))?$this->getForms($xmlArr["FORM"]):null;
00353     }
00354 
00360     function hasForms()
00361     {
00362         return (bool) $this->m_Forms;
00363     }
00364 
00365     protected function translate($caption)
00366     {
00367        $module = $this->getModuleName($this->m_Name);
00368               return I18n::t($caption, $this->getTransKey(caption), $module);
00369     }
00370     
00371     protected function getTransKey($name)
00372     {
00373        $shortFormName = substr($this->m_Name,intval(strrpos($this->m_Name,'.'))+1);
00374        return strtoupper($shortFormName.'_'.$name);
00375     }
00376 }
00377 ?>

Generated on Thu Apr 19 2012 17:09:13 for openbiz by  doxygen 1.7.2