[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/etemplate/inc/ -> class.tab_widget.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare - eTemplate Extension - Tab Widget                            *
   4      * http://www.egroupware.org                                                *
   5      * Written by Ralf Becker <RalfBecker@outdoor-training.de>                  *
   6      * --------------------------------------------                             *
   7      *  This program is free software; you can redistribute it and/or modify it *
   8      *  under the terms of the GNU General Public License as published by the   *
   9      *  Free Software Foundation; either version 2 of the License, or (at your  *
  10      *  option) any later version.                                              *
  11      \**************************************************************************/
  12  
  13      /* $Id: class.tab_widget.inc.php 19711 2005-11-09 20:50:45Z ralfbecker $ */
  14  
  15      /**
  16       * eTemplate Extension: widget that shows one row of tabs and an other row with the eTemplate of the selected tab
  17       *
  18       * See the example in 'etemplate.tab_widget.test'
  19       *
  20       * This widget is independent of the UI as it only uses etemplate-widgets and has therefor no render-function
  21       *
  22       * @package etemplate
  23       * @subpackage extensions
  24       * @author RalfBecker-AT-outdoor-training.de
  25       * @license GPL
  26       */
  27      class tab_widget
  28      {
  29          /** 
  30           * exported methods of this class
  31           * @var array
  32           */
  33          var $public_functions = array(
  34              'pre_process' => True,
  35              'post_process' => True
  36          );
  37          /**
  38           * availible extensions and there names for the editor
  39           * @var string
  40           */
  41          var $human_name = 'Tabs';    // this is the name for the editor
  42  
  43          /**
  44           * Constructor of the extension
  45           *
  46           * @param string $ui '' for html
  47           */
  48  		function tab_widget($ui)
  49          {
  50          }
  51  
  52          /**
  53           * pre-processing of the extension
  54           *
  55           * This function is called before the extension gets rendered
  56           *
  57           * @param string $name form-name of the control
  58           * @param mixed &$value value / existing content, can be modified
  59           * @param array &$cell array with the widget, can be modified for ui-independent widgets 
  60           * @param array &$readonlys names of widgets as key, to be made readonly
  61           * @param mixed &$extension_data data the extension can store persisten between pre- and post-process
  62           * @param object &$tmpl reference to the template we belong too
  63           * @return boolean true if extra label is allowed, false otherwise
  64           */
  65  		function pre_process($form_name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
  66          {
  67              //echo "<p>tab_widget::pre_process('$form_name',$value,,$extension_data)</p>\n";
  68  
  69              if (!$cell['onchange'])    // onchange allows to use the old behavior (submit for each new tab)
  70              {
  71                  $dom_enabled = isset($GLOBALS['egw_info']['etemplate']['dom_enabled']) ? $GLOBALS['egw_info']['etemplate']['dom_enabled'] : true;
  72              }
  73              $labels = explode('|',$cell['label']);
  74              $helps = explode('|',$cell['help']);
  75              $names = explode('|',$cell['name']);
  76  
  77              // disable tab mentioned in readonlys
  78              foreach(is_array($readonlys) ? $readonlys : array($readonlys => true) as $name => $disable)
  79              {
  80                  if($name && $disable && ($key = array_search($name,$names)) !== false)
  81                  {
  82                      unset($names[$key]);
  83                      $names = array_values($names);
  84                      unset($helps[$key]);
  85                      $helps = array_values($helps);
  86                      unset($labels[$key]);
  87                      $labels = array_values($labels);
  88                  }
  89              }
  90              $all_names = implode('|',$names);
  91  
  92              $tab_widget =& new etemplate('etemplate.tab_widget');
  93              $tab_widget->no_onclick = true;
  94      
  95              if ($value && !strstr($value,'.'))
  96              {
  97                  $value = $tmpl->name . '.' . $value;
  98              }
  99              foreach($names as $k => $name)
 100              {
 101                  if (!strstr($name,'.'))
 102                  {
 103                      $name = $names[$k] = $tmpl->name . '.' . $name;
 104                  }
 105                  if ($value == $name)
 106                  {
 107                      $selected_tab = $name;
 108                  }
 109              }
 110              if (empty($selected_tab))
 111              {
 112                  $value = $selected_tab = $names[0];
 113              }
 114              $extension_data = $value;    // remember the active tab in the extension_data
 115  
 116              foreach($names as $k => $name)
 117              {
 118                  if (!strstr($name,'.'))
 119                  {
 120                      $name = $names[$k] = $tmpl->name . '.' . $name;
 121                  }
 122                  $tcell =& $tab_widget->empty_cell();
 123                  if ($value == $name)
 124                  {
 125                      $tcell['span'] = ',etemplate_tab_active th';
 126                  }
 127                  else
 128                  {
 129                      $tcell['span'] = ',etemplate_tab row_on';
 130                  }
 131                  if ($dom_enabled)
 132                  {
 133                      $tcell['onclick'] = "activate_tab('$name','$all_names','$form_name');";
 134                      $tcell['id'] = $name.'-tab';
 135                  }
 136                  elseif ($value != $name)
 137                  {
 138                      $tcell['type'] = 'button';
 139                      $tcell['onchange'] = '1';
 140                      $tcell['name'] = $cell['name'].'['.$name.']';
 141                  }
 142                  $tcell['label'] = $labels[$k];
 143                  $tcell['help'] = $helps[$k];
 144  
 145                  $tab_widget->set_cell_attribute('tabs',1+$k,$tcell);
 146              }
 147              $tab_widget->set_cell_attribute('tabs','type','hbox');
 148              $tab_widget->set_cell_attribute('tabs','size',count($names));
 149              $tab_widget->set_cell_attribute('tabs','name','');
 150  
 151              if ($dom_enabled)
 152              {
 153                  foreach($names as $n => $name)
 154                  {
 155                      $bcell = $tab_widget->empty_cell('template',$name);
 156                      $bcell['obj'] =& new etemplate($name,$tmpl->as_array());
 157                      $tab_widget->set_cell_attribute('body',$n+1,$bcell);
 158                  }
 159                  $tab_widget->set_cell_attribute('body','type','deck');
 160                  $tab_widget->set_cell_attribute('body','size',count($names));
 161                  $tab_widget->set_cell_attribute('body','span',',tab_body');
 162                  $tab_widget->set_cell_attribute('body','name',$cell['name']);
 163              }
 164              else
 165              {
 166                  $stab =& new etemplate($selected_tab,$tmpl->as_array());
 167                  $tab_widget->set_cell_attribute('body','type','template');
 168                  $tab_widget->set_cell_attribute('body','size','');    // the deck has a '1' there
 169                  $tab_widget->set_cell_attribute('body','obj',$stab);
 170              }
 171              $tab_widget->set_cell_attribute('body','name',$selected_tab);
 172  
 173              $cell['type'] = 'template';
 174              $cell['obj'] = &$tab_widget;
 175              $cell['label'] = $cell['help'] = '';
 176  
 177              return False;    // NO extra Label
 178          }
 179  
 180          /**
 181           * postprocessing method, called after the submission of the form
 182           *
 183           * It has to copy the allowed/valid data from $value_in to $value, otherwise the widget
 184           * will return no data (if it has a preprocessing method). The framework insures that
 185           * the post-processing of all contained widget has been done before.
 186           *
 187           * Only used by select-dow so far
 188           *
 189           * @param string $name form-name of the widget
 190           * @param mixed &$value the extension returns here it's input, if there's any
 191           * @param mixed &$extension_data persistent storage between calls or pre- and post-process
 192           * @param boolean &$loop can be set to true to request a re-submision of the form/dialog
 193           * @param object &$tmpl the eTemplate the widget belongs too
 194           * @param mixed &value_in the posted values (already striped of magic-quotes)
 195           * @return boolean true if $value has valid content, on false no content will be returned!
 196           */
 197  		function post_process($name,&$value,&$extension_data,&$loop,&$tmpl,$value_in)
 198          {
 199              //echo "<p>tab_widget::post_process($name): value_in = "; _debug_array($value_in);
 200  
 201              if (is_array($value_in))
 202              {
 203                  foreach ($value_in as $tab => $button_pressed)
 204                  {
 205                      if ($button_pressed)
 206                      {
 207                          $value = $tab;
 208                          $loop = True;
 209                      }
 210                  }
 211              }
 212              else
 213              {
 214                  $value = $value_in;
 215              }
 216              // if value not set (other button pressed), set the value we remembered in the extension_data
 217              if (!$value)
 218              {
 219                  $value = $extension_data;    
 220              }
 221              return True;
 222          }
 223      }


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7