Framework  3.9
TabBar Class Reference

The TabBar class is a user-interface control that manages a line of tabs for multi-page dialogs. More...

+ Inheritance diagram for TabBar:

Public Member Functions

 TabBar ($id, $tabs, $queryString="", $useQueryString=true, $showNumber=false)
 Construct a new TabBar control. More...
 
 preserveQueryString ()
 Preserve the current query string in tab links. More...
 
 dynamicLoad ($container)
 
 writeScript ()
 
 writeHTML ()
 Writes the HTML for this control to standard output. More...
 
 appendQueryString ($url, $qs)
 Appends a query string to the supplied URL. More...
 
 getNextPage ()
 Get the next page in the tab list after the current page. More...
 
 getPage ($idx, $appendQueryString=true)
 Return the URL for the page at the specified tab index. More...
 
 findPage ($page)
 Finds the tab containing the specified URL. More...
 
 next ()
 Move to the next page in the tab list. More...
 
 drawCheckList ()
 
 drawCheckListEntry ($title, $form)
 
 setDefaultStateImage ($img)
 

Public Attributes

 $id
 The DOM ID of the TabBar container element. More...
 
 $tabs = array()
 The tab records in this tab bar. More...
 
 $queryString = null
 The query string parameters to append to the navigation links. More...
 
 $useQueryString = true
 Whether a query string is being used as the navigation key. More...
 
 $page = ""
 The current page (for display purposes). This can be set explicitly to force the correct tab display when in a sub-page, for instance. More...
 
 $showNumber
 True to display the step number, false if not. More...
 
 $states = array()
 Array of display states to apply, indexed by tab. More...
 
 $flags = array()
 Array of flags to apply, indexed by tab. More...
 
 $anchor = ""
 Anchor name to generate (leave empty for no anchor tag) More...
 
 $cssClass = ""
 CSS class to apply to the top level container for the tabs. More...
 
 $defaultStateImage
 Image to show in the default tab state. More...
 
 $showStates = true
 true to show tab states, false to ignore them More...
 
 $dynamic = false
 true to indicate dynamic (AJAX-based) loading More...
 
 $container = ""
 The DOM ID of the container that will contain dynamically loaded content. More...
 
 $dynamicLoadHandler = null
 Javascript function to call to handle dynamic content load (optional) More...
 
 $dynamicLoadFirstTab = true
 By default, dynamically loaded tab bars will do a request for the content of the first tab on page load. Set to false to disable this. More...
 
 $disabled = false
 Set to true to generate disabled tab navigation. More...
 

Detailed Description

The TabBar class is a user-interface control that manages a line of tabs for multi-page dialogs.

Definition at line 39 of file tab_bar.inc.

Member Function Documentation

◆ appendQueryString()

TabBar::appendQueryString (   $url,
  $qs 
)

Appends a query string to the supplied URL.

Parameters
string$url
string$qs
Returns
string

Definition at line 311 of file tab_bar.inc.

312  {
313  if ($url[0] == "&")
314  {
315  $url = $qs.$url;
316  }
317  else
318  {
319  $url .= (strstr($url, "?") !== false) ? "&$qs" : "?$qs";
320  }
321  return $url;
322  }

◆ drawCheckList()

TabBar::drawCheckList ( )

Definition at line 446 of file tab_bar.inc.

447  {
448  ?>
449  <table class="checklist">
450  <?
451  foreach($this->tabs as $title => $form)
452  {
453  $this->drawCheckListEntry($title, $form);
454  }
455  ?>
456  </table>
457  <?
458  }
drawCheckListEntry($title, $form)
Definition: tab_bar.inc:460

◆ drawCheckListEntry()

TabBar::drawCheckListEntry (   $title,
  $form 
)

Definition at line 460 of file tab_bar.inc.

461  {
462  if (get_class($form) == "TabBar")
463  {
464 ?>
465  <tr>
466  <td colspan="2" class="title"><b><?echo $title?></b></td>
467  </tr>
468 <?
469  foreach($form->tabs as $t => $f)
470  {
471  $this->drawCheckListEntry($t, $f);
472  }
473  }
474  else
475  {
476  $status = $this->flags[$form];
477 
478  if ($status && $this->states[$status])
479  {
480  $img = "<img src='{$this->states[$status]}' alt='$status'/>";
481  }
482  else if ($this->defaultStateImage)
483  {
484  $img = "<img src='{$this->defaultStateImage}' alt=''/>";
485  }
486  ?>
487  <tr>
488  <td class="status"><?echo $img ?></td>
489  <td class="link"><a href="<?echo $form ?>?<?echo $this->queryString?>"><?echo $title ?></a></td>
490  </tr>
491  <?
492 
493  }
494  }

◆ dynamicLoad()

TabBar::dynamicLoad (   $container)

Definition at line 104 of file tab_bar.inc.

105  {
106  $this->container = $container;
107  $this->dynamic = true;
108  }
$container
The DOM ID of the container that will contain dynamically loaded content.
Definition: tab_bar.inc:55

◆ findPage()

TabBar::findPage (   $page)

Finds the tab containing the specified URL.

Parameters
$pageThe page to find
Returns
mixed returns the name of the tab if found, false otherwise

Reimplemented in TwoLevelTabBar.

Definition at line 411 of file tab_bar.inc.

412  {
413  foreach($this->tabs as $text => $url)
414  {
415  if ($this->comparePaths($url, $page))
416  {
417  return $text;
418  }
419  }
420 
421  return false;
422  }
$page
The current page (for display purposes). This can be set explicitly to force the correct tab display ...
Definition: tab_bar.inc:45

◆ getNextPage()

TabBar::getNextPage ( )

Get the next page in the tab list after the current page.

Returns
string

Reimplemented in TwoLevelTabBar.

Definition at line 329 of file tab_bar.inc.

330  {
331  $found = false;
332 
333  foreach($this->tabs as $text => $url)
334  {
335  trace("getNextPage::text is $text and url is $url; this page is {$this->page}", 3);
336  if ($found)
337  {
338  $dest = ($this->queryString!="") ? $this->appendQueryString($url, $this->queryString) : $url;
339  trace("getNextPage::found; dest is$dest", 3);
340  return $dest;
341  }
342  else if ($this->comparePaths($url, $this->page))
343  {
344  $found = true;
345  trace("getNextPage::url is this page", 3);
346  }
347  }
348 
349  return ($found) ? "" : false;
350  }
appendQueryString($url, $qs)
Appends a query string to the supplied URL.
Definition: tab_bar.inc:311
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
Definition: functions.inc:1010

◆ getPage()

TabBar::getPage (   $idx,
  $appendQueryString = true 
)

Return the URL for the page at the specified tab index.

Parameters
string$idxthe index of the tab for which we require the URL

Definition at line 357 of file tab_bar.inc.

358  {
359  $i = 0;
360 
361  foreach($this->tabs as $text => $entry)
362  {
363  if (is_object($entry) && get_class($entry) == "TabBar")
364  {
365  $num = count($entry->tabs);
366 
367  if ($num >= $idx - $i)
368  {
369  $entry->queryString = $this->queryString;
370  return $entry->getPage($idx - $i);
371  }
372  else
373  {
374  $i += $num;
375  continue;
376  }
377  }
378  else
379  {
380  $url = $entry;
381  }
382 
383  if ($i == $idx) break;
384  $i++;
385  }
386 
387  $dest = ($appendQueryString && $this->queryString!="") ? $this->appendQueryString($url, $this->queryString) : $url;
388  return $dest;
389  }
$queryString
The query string parameters to append to the navigation links.
Definition: tab_bar.inc:43

◆ next()

TabBar::next ( )

Move to the next page in the tab list.

If the current tab is the last in the set, redirect to the first tab in the list (wraparound).

Definition at line 428 of file tab_bar.inc.

429  {
430  $next = $this->getNextPage();
431  if (!$next)
432  {
433  $next = $this->getPage(0);
434  }
435 
436  /*
437  * JDG 6/15/2010, insert "/" before identifier but not if
438  * the page is *.php
439  */
440  //if(!preg_match("/.php/i", $next))
441  // $next = "/". $next;
442  trace("tabbar::next:: next is $next",3);
443  redirect($next);
444  }
getPage($idx, $appendQueryString=true)
Return the URL for the page at the specified tab index.
Definition: tab_bar.inc:357
getNextPage()
Get the next page in the tab list after the current page.
Definition: tab_bar.inc:329
redirect($page)
Simplified redirect.
Definition: functions.inc:930

◆ preserveQueryString()

TabBar::preserveQueryString ( )

Preserve the current query string in tab links.

Definition at line 89 of file tab_bar.inc.

90  {
91  $qs = getCleanQueryString();
92  if ($qs)
93  {
94  $this->queryString = $qs;
95  $this->useQueryString = true;
96  }
97  else
98  {
99  $this->queryString = null;
100  $this->useQueryString = false;
101  }
102  }
getCleanQueryString()
Returns the query string for the current page, cleaned of any Fakoli-related navigation parameters.
Definition: functions.inc:986

◆ setDefaultStateImage()

TabBar::setDefaultStateImage (   $img)

Definition at line 496 of file tab_bar.inc.

497  {
498  foreach($this->tabs as $text => $entry)
499  {
500  if (is_object($entry) && get_class($entry) == "TabBar")
501  {
502  $entry->defaultStateImage = $img;
503  }
504  }
505 
506  $this->defaultStateImage = $img;
507  }

◆ TabBar()

TabBar::TabBar (   $id,
  $tabs,
  $queryString = "",
  $useQueryString = true,
  $showNumber = false 
)

Construct a new TabBar control.

Parameters
string$queryStringthe Query String portion of the page URIs
array$tabsthe steps in the workflow
string$queryStringthe query string to append to the links
bool$useQueryStringflag to indicate whether a query string is required. If so, and none is provided, then all tabs except the first are disabled.
bool$showNumberflag to indicate whether to display step numbers

Definition at line 71 of file tab_bar.inc.

72  {
73  global $config;
74  global $isAdmin;
75 
76  $this->id = $id;
77  $this->tabs = $tabs;
78  $this->page = ($config['prettyURLs'] === false) ? basename($_SERVER["PHP_SELF"]) : $_REQUEST['identifier'];
79  if ($isAdmin) $this->page = "/admin/{$this->page}";
80  $this->queryString = $queryString;
81  $this->useQueryString = $useQueryString;
82  $this->showNumber = $showNumber;
83  trace("PAGE: **** {$this->page}", 4);
84  }
$showNumber
True to display the step number, false if not.
Definition: tab_bar.inc:46
$useQueryString
Whether a query string is being used as the navigation key.
Definition: tab_bar.inc:44
$tabs
The tab records in this tab bar.
Definition: tab_bar.inc:42
$id
The DOM ID of the TabBar container element.
Definition: tab_bar.inc:41

◆ writeHTML()

TabBar::writeHTML ( )

Writes the HTML for this control to standard output.

Reimplemented in WizardBar.

Definition at line 192 of file tab_bar.inc.

193  {
194  foreach($this->tabs as $text => $entry)
195  {
196  if (is_object($entry) && get_class($entry) == "TabBar")
197  {
198  $entry->page = $this->page;
199  $entry->queryString = $this->queryString;
200  }
201  }
202 
203  $first = true;
204  $future = false;
205 
206  if ($this->anchor) echo "<a name='<?echo $this->anchor?>'></a>";
207 
208  echo "<div id='{$this->id}'";
209 
210  if ($this->cssClass) echo " class='{$this->cssClass}'";
211 
212  echo "><ul>";
213 
214  foreach ($this->tabs as $text => $entry)
215  {
216  ++$count;
217  $active = "";
218  $style = "";
219 
220  //AJG - make it easier to have conditional tabs.
221  if ($entry === null) continue;
222 
223  if (is_string($entry))
224  {
225  $url = $entry;
226  }
227  else if (is_object($entry) && get_class($entry) == "TabBar")
228  {
229  if ($entry->findPage($this->page))
230  {
231  $url = $this->page;
232  }
233  else
234  {
235  $url = $entry->getPage(0, false);
236  }
237  }
238 
239  if (!$first)
240  {
241  echo $this->spacer;
242  }
243  else
244  {
245  $first = false;
246  }
247 
248  $isMatch = $this->comparePaths($url, $this->page);
249  // JDG 12/01/09, get the basename of the url, in case we need a
250  // longer path in the tab include file, as with digital movies
251  if ($isMatch)
252  {
253  $style = " class='current'";
254  }
255 
256  if (($this->disabled || ($this->queryString == "" && $this->useQueryString)) && $count > 1)
257  {
258  $active = " class='disabled'";
259  }
260 
261  if ($this->showNumber) $text = "$count.&nbsp;$text";
262 
263  if ($this->useQueryString)
264  {
265  $dest = ($this->queryString!="") ? $this->appendQueryString($url, $this->queryString) :"#";
266  }
267  else
268  {
269  $dest = ($isMatch && !$this->dynamic) ? "#" : $url;
270  }
271 
272  if ($this->anchor)
273  {
274  $dest = ($dest != "#") ? "$dest#{$this->anchor}" : "#{$this->anchor}";
275  }
276 
277  if ($this->showStates)
278  {
279  if (array_key_exists($url, $this->flags))
280  {
281  $text = "<img src='{$this->states[$this->flags[$url]]}' style='border: none; display: inline-block;vertical-align: middle'/>&nbsp;$text";
282  }
283  else if ($this->defaultStateImage)
284  {
285  $text = "<img src='{$this->defaultStateImage}' style='border: none; display: inline-block;vertical-align: middle'/>&nbsp;$text";
286  }
287  }
288  echo "<li$style><a href=\"$dest\"$active>$text</a></li>";
289  }
290 
291  echo "</ul></div>\n";
292 
293  foreach($this->tabs as $text => $entry)
294  {
295  if (is_object($entry) && get_class($entry) == "TabBar" &&
296  $entry->findPage($this->page))
297  {
298  $entry->useQueryString = $this->useQueryString;
299  $entry->writeHTML();
300  }
301  }
302  }
$dynamic
true to indicate dynamic (AJAX-based) loading
Definition: tab_bar.inc:54

◆ writeScript()

TabBar::writeScript ( )

Definition at line 110 of file tab_bar.inc.

111  {
112  $script = "";
113  if (!$this->dynamic) return $script;
114 
115  $script .= <<<ENDSCRIPT
116  <script type="text/javascript">
117  window.addEvent('domready', function()
118  {
119  document.id('{$this->id}').getElements("a").each(function(a)
120  {
121  a.loadTab = function(override)
122 ENDSCRIPT;
123  if ($this->dynamicLoadHandler)
124  {
125  $script .= <<<ENDSCRIPT
126  {
127  var url = override ? override : this.href;
128  {$this->dynamicLoadHandler}(url);
129  };
130 ENDSCRIPT;
131  }
132  else
133  {
134  $script .= <<<ENDSCRIPT
135  {
136  var request = new Request.HTML(
137  {
138  evalScripts: false,
139  evalResponse: false,
140  method: 'get',
141  url: override ? override : this.href,
142  onSuccess: function(tree, elements, html, script)
143  {
144  var container = document.id('{$this->container}');
145  container.set('text', '');
146  container.adopt(tree);
147 
148  Browser.exec(script);
149 
150  }.bind(this)
151  });
152 
153  request.send();
154  };
155 ENDSCRIPT;
156  }
157 
158  $script .= <<<ENDSCRIPT
159 
160  a.addEvent('click', function(e)
161  {
162  new DOMEvent(e).stop();
163  var url = a.href;
164  var parent = a.getParent();
165  document.id('{$this->id}').getElements("li").each(function(l) { l.removeClass("current"); });
166  parent.addClass('current');
167 
168  a.loadTab();
169  });
170  });
171 ENDSCRIPT;
172 
173  if ($this->dynamicLoadFirstTab)
174  {
175  $script .= <<<ENDSCRIPT
176  document.id('{$this->id}').getElements("li.current a").each(function(a)
177  {
178  a.loadTab();
179  });
180 ENDSCRIPT;
181  }
182 
183  $script .= <<<ENDSCRIPT
184  });
185  </script>
186 ENDSCRIPT;
187  return $script;
188  }

Member Data Documentation

◆ $anchor

TabBar::$anchor = ""

Anchor name to generate (leave empty for no anchor tag)

Definition at line 49 of file tab_bar.inc.

◆ $container

TabBar::$container = ""

The DOM ID of the container that will contain dynamically loaded content.

Definition at line 55 of file tab_bar.inc.

◆ $cssClass

TabBar::$cssClass = ""

CSS class to apply to the top level container for the tabs.

Definition at line 50 of file tab_bar.inc.

◆ $defaultStateImage

TabBar::$defaultStateImage

Image to show in the default tab state.

Definition at line 51 of file tab_bar.inc.

◆ $disabled

TabBar::$disabled = false

Set to true to generate disabled tab navigation.

Definition at line 59 of file tab_bar.inc.

◆ $dynamic

TabBar::$dynamic = false

true to indicate dynamic (AJAX-based) loading

Definition at line 54 of file tab_bar.inc.

◆ $dynamicLoadFirstTab

TabBar::$dynamicLoadFirstTab = true

By default, dynamically loaded tab bars will do a request for the content of the first tab on page load. Set to false to disable this.

Definition at line 57 of file tab_bar.inc.

◆ $dynamicLoadHandler

TabBar::$dynamicLoadHandler = null

Javascript function to call to handle dynamic content load (optional)

Definition at line 56 of file tab_bar.inc.

◆ $flags

TabBar::$flags = array()

Array of flags to apply, indexed by tab.

Definition at line 48 of file tab_bar.inc.

◆ $id

TabBar::$id

The DOM ID of the TabBar container element.

Definition at line 41 of file tab_bar.inc.

◆ $page

TabBar::$page = ""

The current page (for display purposes). This can be set explicitly to force the correct tab display when in a sub-page, for instance.

Definition at line 45 of file tab_bar.inc.

◆ $queryString

TabBar::$queryString = null

The query string parameters to append to the navigation links.

Definition at line 43 of file tab_bar.inc.

◆ $showNumber

TabBar::$showNumber

True to display the step number, false if not.

Definition at line 46 of file tab_bar.inc.

◆ $showStates

TabBar::$showStates = true

true to show tab states, false to ignore them

Definition at line 52 of file tab_bar.inc.

◆ $states

TabBar::$states = array()

Array of display states to apply, indexed by tab.

Definition at line 47 of file tab_bar.inc.

◆ $tabs

TabBar::$tabs = array()

The tab records in this tab bar.

Definition at line 42 of file tab_bar.inc.

◆ $useQueryString

TabBar::$useQueryString = true

Whether a query string is being used as the navigation key.

Definition at line 44 of file tab_bar.inc.


The documentation for this class was generated from the following file: