[dev] [patch] Horde_UI_Tabs
Jason M. Felice
jfelice at cronosys.com
Fri Nov 14 05:46:50 PST 2003
Creates Horde_UI package, move whups' Actions class into Horde_UI
package as Horde_UI_Tabs, make whups use the new one. Added
documentation and a few tweaks in the process.
Patch Summary:
D whups/templates/actions.inc
M whups/lib/base.php
M whups/admin.php
M whups/details.php
M whups/query.php
M whups/runquery.php
M whups/config/html.php.dist
M config/html.php.dist
A lib/Horde_UI/Tabs.php
A lib/Horde_UI.xml
--
Jason M. Felice
Cronosys, LLC <http://www.cronosys.com/>
216.221.4600 x302
-------------- next part --------------
epm diff whups/templates/actions.inc
--- whups/templates/actions.inc 2003-11-13 19:34:46.000000000 -0500
+++ whups/templates/actions.inc 1969-12-31 19:00:00.000000000 -0500
@@ -1,84 +0,0 @@
-<?php
-/**
- * $Horde: whups/templates/actions.inc,v 1.9 2003/09/16 23:08:53 jan Exp $
- *
- * Copyright 2001 Robert E. Coyle <robertecoyle at hotmail.com>
- *
- * See the enclosed file LICENSE for license information (BSD). If you
- * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
- *
- * @package whups
- */
-class Actions {
-
- function Actions()
- {
- $this->actions = array();
- $this->preserve = array();
- }
-
- function addAction($title, $link, $action = '')
- {
- $action = array('title' => $title, 'link' => $link, 'action' => $action);
- array_push($this->actions, $action);
- }
-
- function preserve($var, $value)
- {
- $preserve = array('var' => $var, 'value' => $value);
- array_push($this->preserve, $preserve);
- }
-
- function getTitleFromAction($action)
- {
- foreach ($this->actions as $ac) {
- if ($ac['action'] == $action) {
- return $ac['title'];
- }
- }
-
- return null;
- }
-
- function render($active)
- {
-?>
-<table width="100%" cellspacing="0" cellpadding="0" border="0">
-<tr><td>
- <table width="100%" cellspacing="2" cellpadding="1" border="0">
- <tr>
-<?php
- $width = 100.0 / sizeof($this->actions);
-
- foreach ($this->actions as $action) {
- $class = 'sect';
- $title = $action['title'];
- $link = $action['link'];
- $accesskey = Horde::getAccessKey($title);
-
- foreach ($this->preserve as $preserve) {
- $link = Util::addParameter($link, $preserve['var'], $preserve['value']);
- }
-
- if (!empty($action['action'])) {
- $link = Util::addParameter($link, 'action', $action['action']);
-
- if ($active == $action['action']) {
- $class = 'cursect';
- }
- }
-
- echo "<td width=\"$width%\" align=\"center\" class=\"$class\"><b>" . Horde::link(Horde::applicationUrl($link), $title, null, null, null, null, $accesskey) . Horde::highlightAccessKey($title, $accesskey) . '</a></b></td>';
- }
-?>
- </tr>
- </table>
-</td></tr>
-</table>
-
-<br />
-
-<?php
- }
-
-}
epm diff whups/lib/base.php
--- whups/lib/base.php 2003-11-13 19:38:30.000000000 -0500
+++ whups/lib/base.php 2003-11-14 08:06:35.000000000 -0500
@@ -62,8 +62,8 @@
require_once HORDE_BASE . '/lib/Form.php';
require_once HORDE_BASE . '/lib/Form/Renderer.php';
-// Whups UI classes.
-require_once WHUPS_TEMPLATES . '/actions.inc';
+// UI classes.
+require_once HORDE_BASE . '/lib/Horde_UI/Tabs.php';
// Whups backend.
$GLOBALS['whups'] = &Whups_Driver::factory();
epm diff whups/admin.php
--- whups/admin.php 2003-11-13 19:41:26.000000000 -0500
+++ whups/admin.php 2003-11-14 08:34:39.000000000 -0500
@@ -20,12 +20,12 @@
$showExtraForm = null;
// admin actions
-$AACTIONS = &new Actions();
-$AACTIONS->addAction(_("Edit Modules"), 'admin.php', 'module');
-$AACTIONS->addAction(_("Edit Types"), 'admin.php', 'type');
-$AACTIONS->addAction(_("Edit Subjects"), 'admin.php', 'subject');
-$AACTIONS->addAction(_("Module/Type Matrix"), 'admin.php', 'mtmatrix');
-$AACTIONS->addAction(_("Send Reminders"), 'admin.php', 'reminders');
+$AACTIONS = &new Horde_UI_Tabs('action');
+$AACTIONS->addTab(_("Edit Modules"), 'admin.php', 'module');
+$AACTIONS->addTab(_("Edit Types"), 'admin.php', 'type');
+$AACTIONS->addTab(_("Edit Subjects"), 'admin.php', 'subject');
+$AACTIONS->addTab(_("Module/Type Matrix"), 'admin.php', 'mtmatrix');
+$AACTIONS->addTab(_("Send Reminders"), 'admin.php', 'reminders');
$RENDERER = &new Horde_Form_Renderer();
epm diff whups/details.php
--- whups/details.php 2003-11-13 19:41:42.000000000 -0500
+++ whups/details.php 2003-11-14 08:35:37.000000000 -0500
@@ -33,20 +33,20 @@
$showticketdetails = true;
// Ticket actions.
-$ACTIONS = &new Actions();
-$ACTIONS->addAction(_("Add Comment"), 'details.php', 'ac');
-$ACTIONS->addAction(_("Upload Attachment"), 'details.php', 'ua');
+$ACTIONS = &new Horde_UI_Tabs('action');
+$ACTIONS->addTab(_("Add Comment"), 'details.php', 'ac');
+$ACTIONS->addTab(_("Upload Attachment"), 'details.php', 'ua');
if (Auth::getAuth()) {
- $ACTIONS->addAction(_("Assign Ticket"), 'details.php', 'at');
- $ACTIONS->addAction(_("Set State"), 'details.php', 'ss');
- $ACTIONS->addAction(_("Set Priority"), 'details.php', 'sp');
+ $ACTIONS->addTab(_("Assign Ticket"), 'details.php', 'at');
+ $ACTIONS->addTab(_("Set State"), 'details.php', 'ss');
+ $ACTIONS->addTab(_("Set Priority"), 'details.php', 'sp');
} else {
- $ACTIONS->addAction(_("Set Priority"), 'details.php', 'gp');
+ $ACTIONS->addTab(_("Set Priority"), 'details.php', 'gp');
}
-$ACTIONS->addAction(_("Edit Attributes"), 'details.php', 'ea');
+$ACTIONS->addTab(_("Edit Attributes"), 'details.php', 'ea');
if (Auth::isAdmin('whups:admin')) {
- $ACTIONS->addAction(_("Set Type"), 'details.php', 'st');
- $ACTIONS->addAction(_("Delete Ticket"), 'details.php', 'dt');
+ $ACTIONS->addTab(_("Set Type"), 'details.php', 'st');
+ $ACTIONS->addTab(_("Delete Ticket"), 'details.php', 'dt');
}
$ACTIONS->preserve('id', $ticket);
epm diff whups/query.php
--- whups/query.php 2003-11-13 19:42:22.000000000 -0500
+++ whups/query.php 2003-11-14 08:35:03.000000000 -0500
@@ -22,19 +22,19 @@
$showExtraForm = null;
// Query actions.
-$QACTIONS = &new Actions();
-$QACTIONS->addAction(_("New Query"), 'query.php', 'new');
-$QACTIONS->addAction(_("Execute Query"), 'runquery.php', '');
-$QACTIONS->addAction(_("Load Query"), 'query.php', 'load');
-$QACTIONS->addAction(_("Save Query"), 'query.php', 'save');
+$QACTIONS = &new Horde_UI_Tabs('action');
+$QACTIONS->addTab(_("New Query"), 'query.php', 'new');
+$QACTIONS->addTab(_("Execute Query"), 'runquery.php', '');
+$QACTIONS->addTab(_("Load Query"), 'query.php', 'load');
+$QACTIONS->addTab(_("Save Query"), 'query.php', 'save');
// Criterion form types.
-$CACTIONS = &new Actions();
-$CACTIONS->addAction(_("Property Criteria"), 'query.php', 'props');
-$CACTIONS->addAction(_("User Criteria"), 'query.php', 'user');
-//$CACTIONS->addAction(_("Date Criteria"), 'query.php', 'date');
-$CACTIONS->addAction(_("Text Criteria"), 'query.php', 'text');
-$CACTIONS->addAction(_("Attribute Criteria"), 'query.php', 'attribs');
+$CACTIONS = &new Horde_Actions();
+$CACTIONS->addTab(_("Property Criteria"), 'query.php', 'props');
+$CACTIONS->addTab(_("User Criteria"), 'query.php', 'user');
+//$CACTIONS->addTab(_("Date Criteria"), 'query.php', 'date');
+$CACTIONS->addTab(_("Text Criteria"), 'query.php', 'text');
+$CACTIONS->addTab(_("Attribute Criteria"), 'query.php', 'attribs');
$RENDERER = &new Horde_Form_Renderer();
$QUERYRENDERER = &new QueryRenderer();
epm diff whups/runquery.php
--- whups/runquery.php 2003-11-13 19:42:47.000000000 -0500
+++ whups/runquery.php 2003-11-14 08:35:10.000000000 -0500
@@ -17,11 +17,11 @@
require WHUPS_TEMPLATES . '/searchresults.inc';
// execute actions
-$EACTIONS = new Actions();
-$EACTIONS->addAction(_("Edit Query"), 'query.php', '');
-$EACTIONS->addAction(_("Re-execute Query"), 'runquery.php', '');
-$EACTIONS->addAction(_("Load Query"), 'query.php', 'load');
-$EACTIONS->addAction(_("Save Query"), 'query.php', 'save');
+$EACTIONS = new Horde_UI_Tabs('action');
+$EACTIONS->addTab(_("Edit Query"), 'query.php', '');
+$EACTIONS->addTab(_("Re-execute Query"), 'runquery.php', '');
+$EACTIONS->addTab(_("Load Query"), 'query.php', 'load');
+$EACTIONS->addTab(_("Save Query"), 'query.php', 'save');
$RENDERER = new Horde_Form_Renderer();
$QUERYRENDERER = new QueryRenderer();
epm diff whups/config/html.php.dist
--- whups/config/html.php.dist 2003-11-13 19:58:58.000000000 -0500
+++ whups/config/html.php.dist 2003-11-13 20:01:05.000000000 -0500
@@ -9,12 +9,6 @@
$css['.res-header']['background-color'] = '#dedeee';
$css['.res-header']['color'] = 'black';
-$css['.cursect']['background-color'] = '#bbddbb';
-$css['.cursect']['color'] = '#222222';
-
-$css['.sect']['background-color'] = '#dedeee';
-$css['.sect']['color'] = '#9999cc';
-
$css['.query']['background-color'] = '#cdcdcd';
$css['.user-change']['background-color'] = '#6666cc';
epm diff config/html.php.dist
--- config/html.php.dist 2003-11-13 20:00:54.000000000 -0500
+++ config/html.php.dist 2003-11-14 08:31:22.000000000 -0500
@@ -181,3 +181,10 @@
$css['.sidebar'] = array();
$css['.sidebar-panel'] = array();
$css['a.sidebaritem'] = array();
+
+$css['.tab']['background-color'] = '#bbddbb';
+$css['.tab']['color'] = '#222222';
+
+$css['.tab-hi']['background-color'] = '#dedeee';
+$css['.tab-hi']['color'] = '#9999cc';
+
epm diff lib/Horde_UI/Tabs.php
--- lib/Horde_UI/Tabs.php 1969-12-31 19:00:00.000000000 -0500
+++ lib/Horde_UI/Tabs.php 2003-11-14 08:34:21.000000000 -0500
@@ -0,0 +1,127 @@
+<?php
+/**
+ * The Horde_UI_Tabs:: class manages and renders a tab-like interface.
+ *
+ * $Horde: whups/templates/actions.inc,v 1.9 2003/09/16 23:08:53 jan Exp $
+ *
+ * Copyright 2001 Robert E. Coyle <robertecoyle at hotmail.com>
+ *
+ * See the enclosed file LICENSE for license information (BSD). If you
+ * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
+ *
+ * @version $Revision:$
+ * @since Horde_UI 0.0.1
+ * @package Horde_UI
+ */
+class Horde_UI_Tabs {
+
+ /**
+ * Construct a new tab interface.
+ *
+ * @access public
+ *
+ * @param string $varname The name of the variable to set when a
+ * a tab is selected.
+ */
+ function Horde_UI_Tabs($varname = 'tabname')
+ {
+ $this->tabs = array();
+ $this->preserve = array();
+ $this->varname = $varname;
+ }
+
+ /**
+ * Add a tab to the interface.
+ *
+ * @access public
+ *
+ * @param string $title The text which appears on the tab.
+ * @param string $link The target page.
+ * @param string $tabname The what to set the tab variable to.
+ */
+ function addTab($title, $link, $tabname = '')
+ {
+ $tab = array('title' => $title, 'link' => $link, 'tabname' => $tabname);
+ array_push($this->tabs, $tab);
+ }
+
+ /**
+ * Instruct Horde_UI_Tab:: to preserve a variable.
+ *
+ * @access public
+ *
+ * @param string $var The name of the variable to preserve.
+ * @param mixed $value The value of the variable to preserve.
+ */
+ function preserve($var, $value)
+ {
+ $preserve = array('var' => $var, 'value' => $value);
+ array_push($this->preserve, $preserve);
+ }
+
+ /**
+ * Retreive the title of the tab with the specified name.
+ *
+ * @access public
+ *
+ * @param string $tabname The name of the tab.
+ * @return string the tab's title.
+ */
+ function getTitleFromAction($tabname)
+ {
+ foreach ($this->tabs as $tab) {
+ if ($tab['tabname'] == $tabname) {
+ return $tab['title'];
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Render the tabs.
+ *
+ * @param string $active The name of the active tab.
+ */
+ function render($active)
+ {
+?>
+<table width="100%" cellspacing="0" cellpadding="0" border="0">
+<tr><td>
+ <table width="100%" cellspacing="2" cellpadding="1" border="0">
+ <tr>
+<?php
+ $width = 100.0 / sizeof($this->tabs);
+
+ foreach ($this->tabs as $tab) {
+ $class = 'tab';
+ $title = $tab['title'];
+ $link = $tab['link'];
+ $accesskey = Horde::getAccessKey($title);
+
+ foreach ($this->preserve as $preserve) {
+ $link = Util::addParameter($link, $preserve['var'], $preserve['value']);
+ }
+
+ if (!empty($tab['tabname'])) {
+ $link = Util::addParameter($link, $this->varname, $tab['tabname']);
+
+ if ($active == $tab['tabname']) {
+ $class = 'tab-hi';
+ }
+ }
+
+ echo "<td width=\"$width%\" align=\"center\" class=\"$class\"><b>" . Horde::link(Horde::applicationUrl($link), $title, null, null, null, null, $accesskey) . Horde::highlightAccessKey($title, $accesskey) . '</a></b></td>';
+ }
+?>
+ </tr>
+ </table>
+</td></tr>
+</table>
+
+<br />
+
+<?php
+ }
+
+}
epm diff lib/Horde_UI.xml
--- lib/Horde_UI.xml 1969-12-31 19:00:00.000000000 -0500
+++ lib/Horde_UI.xml 2003-11-14 08:15:41.000000000 -0500
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!-- $Horde: horde/lib/IMAP.xml,v 1.5 2003/10/01 08:37:59 jan Exp $ -->
+<package version="1.0">
+ <name>Horde_UI</name>
+ <summary>Horde's User Interface Classes</summary>
+ <description>
+ The Horde_UI_Tabs:: class draws and manages nifty tabs.
+ </description>
+ <license>LGPL</license>
+ <maintainers>
+ <maintainer>
+ <name>Jay 'Eraserhead' Felice</name>
+ <email>jfelice at cronosys.com</email>
+ </maintainer>
+ </maintainers>
+ <release>
+ <version>0.0.1</version>
+ <state>alpha</state>
+ <date>2003-11-14</date>
+ <notes>Initial release as a PEAR package</notes>
+ <provides type="class" name="Horde_UI_Tabs" />
+ <filelist>
+ <dir role="php" name="Horde_UI">
+ <file name="Tabs.php" />
+ </dir>
+ </filelist>
+
+ <deps>
+ <dep type="pkg" rel="has">Horde_Framework</dep>
+ </deps>
+ </release>
+
+ <changelog>
+ <release>
+ <version>0.0.1</version>
+ <date>2003-11-14</date>
+ <state>alpha</state>
+ <notes>Initial release as a PEAR package</notes>
+ </release>
+ </changelog>
+</package>
More information about the dev
mailing list