[Tickets #1242] NEW: tableset, a table-like set variable

bugs at bugs.horde.org bugs at bugs.horde.org
Mon Jan 24 13:34:35 PST 2005


DO NOT REPLY TO THIS MESSAGE. THIS EMAIL ADDRESS IS NOT MONITORED.

Ticket URL: http://bugs.horde.org/ticket/?id=1242
-----------------------------------------------------------------------
 Ticket     | 1242
 Created By | allen.zhao at camilion.com
 Summary    | tableset, a table-like set variable
 Queue      | Horde Framework Packages
 State      | New
 Priority   | 1. Low
 Type       | Enhancement
 Owners     | 
-----------------------------------------------------------------------


allen.zhao at camilion.com (2005-01-24 13:34) wrote:

I am trying to use Horde_UI_Table, but I was so frustrated. Then I found set
is a good choice for me. Only with some other problems ....

Then the tableset coming:

In Horde/Form.php
add:
class Horde_Form_Type_tableset extends Horde_Form_Type {

    var $_values;
    var $_header;

    function init(&$values, &$header)
    {
        $this->_values = $values;
        $this->_header = $header;
    }

    function isValid(&$var, &$vars, $value, &$message)
    {
        if (count($this->_values) == 0 || count($value) == 0) {
            return true;
        }
        foreach ($value as $item) {
            if (!isset($this->_values[$item])) {
                $error = true;
                break;
            }
        }
        if (!isset($error)) {
            return true;
        }

        $message = _("Invalid data submitted.");
        return false;
    }

    function getHeader() {
        return $this->_header;
    }

    function getValues()
    {
        return $this->_values;
    }
    /**
     * Return info about field type.
     */
    function about()
    {
        $about = array();
        $about['name'] = _("Table Set");
        $about['params'] = array(
            'values' => array('label' => _("Values"),
                              'type'  => 'stringlist'),
            'header' => array('label' => _("Values"),
                              'type'  => 'stringlist')
                              );
        return $about;
    }
}

In Horde/UI/VarRenderer/html.php add:
    function _renderVarInput_tableset(&$form, &$var, &$vars)
    {
        $header = $var->type->getHeader();
        $name   = $var->getVarName();
        $values = $var->getValues();
        $checkedValues = $var->getValue($vars);
        $actions = $this->_getActionScripts($form, $var);

        $html = '<table width="100%" border="0" cellspacing="0"
cellpadding="0"><tr><td class="item">';
        $html .= '<table border="0" cellpadding="2" cellspacing="1"><tr
class="selected">';
        $html .= '<th  class="widget" align="right"
width="1%%">&nbsp;</th>';
        foreach ($header as $col_title) {
            $html .= sprintf('<th align="left" class="widget">%s</th>',
$col_title);
        }
        $html .= '</tr>';

        if (!is_array($checkedValues)) {
            $checkedValues = array();
        }
        $i = 0;
        foreach ($values as $value => $displays) {
            $class   = 'item' . ($i+1) % 2;
            $checked = (in_array($value, $checkedValues)) ? '
checked="checked"' : '';
            $html   .= sprintf('<tr class="%s">', $class);
            $html   .= sprintf('<td align="center"><input id="%s%s"
type="checkbox" name="%s[]" value="%s"%s%s /></td>',
                               $name,
                               $i,
                               $name,
                               $value,
                               $checked,
                               $actions);
            foreach ($displays as $col)
                $html .= sprintf('<td align="left">&nbsp;%s</td>', $col);
            $html   .= '</tr>';
            $i++;
        }

        return $html . '</table></td></tr></table>';
    }

    function _renderVarDisplay_tableset(&$form, &$var, &$vars)
    {
        $header = $var->type->getHeader();
        $name   = $var->getVarName();
        $values = $var->getValues();
        $checkedValues = $var->getValue($vars);
        $actions = $this->_getActionScripts($form, $var);

        $html = '<table width="100%" border="0" cellspacing="0"
cellpadding="0"><tr><td>';
        $html .= '<table border="0" cellpadding="2" cellspacing="1"><tr
class="selected">';
        $html .= '<th  class="widget" align="right"
width="1%%">&nbsp;</th>';
        foreach ($header as $col_title) {
            $html .= sprintf('<th align="left" class="widget">%s</th>',
$col_title);
        }
        $html .= '</tr>';

        if (!is_array($checkedValues)) {
            $checkedValues = array();
        }
        $i = 0;
        foreach ($values as $value => $displays) {
            $class   = 'item' . ($i+1) % 2;
            $checked = (in_array($value, $checkedValues)) ? '[ <b><font
color=green>V</font></b> ]' : '[ <b><font color=red>X</font></b> ]';
            $html   .= sprintf('<tr class="%s">', $class);
            $html   .= sprintf('<td align="center">%s</td>', $checked);
            foreach ($displays as $col)
                $html .= sprintf('<td align="left">&nbsp;%s</td>', $col);
            $html   .= '</tr>';
            $i++;
        }

        return $html . '</table></td></tr></table>';
    }

As you saw, just a simple change of set





More information about the bugs mailing list