Issue #92 on hold

BootDropDownButtonColumn

Anonymous created an issue

My variant of ButtonColumn with Bootstrap {{{

!php

Yii::import('bootstrap.BootButtonColumn');

/* * Bootstrap button column widget. * Used to set buttons to use Glyphicons instead of the defaults images. / class BootDropDownButtonColumn extends BootButtonColumn {

/* * @var string - define prioritet button action - can be 'view','update', ''delete'' or some custom button / public $mainid='update';

/**
 * Initializes the default buttons (view, update and delete).
 */

protected function renderDataCellContent($row,$data)
    {
        $str='<div class="btn-group">';
        ob_start();
        $this->renderButton($this->mainid,$this->buttons[$this->mainid],$row,$data,'main');
        $str.=ob_get_contents();
        ob_end_clean();
        $str.='<button class="btn dropdown-toggle" data-toggle="dropdown">
            <span class="caret"></span>
          </button><ul class="dropdown-menu pull-right">';
        ob_start();
        foreach($this->buttons as $id=>$button)
        {
            $this->renderButton($id,$button,$row,$data);
            $str.=ob_get_contents();
            ob_clean();
        }
        $str.='</ul></div>';
        ob_end_clean();
        echo $str;
    }

/**
 * Renders a link button.
 * @param string $id the ID of the button
 * @param array $button the button configuration which may contain 'label', 'url', 'imageUrl' and 'options' elements.
 * @param integer $row the row number (zero-based)
 * @param mixed $data the data object associated with the row
 * @param can be 'drop' or 'main' type of button
 */
protected function renderButton($id, $button, $row, $data,$type='drop')
{
    if (isset($button['visible']) && !$this->evaluateExpression($button['visible'], array('row'=>$row, 'data'=>$data)))
        return;

    $label = isset($button['label']) ? $button['label'] : $id;
    $url = isset($button['url']) ? $this->evaluateExpression($button['url'], array('data'=>$data, 'row'=>$row)) : '#';
    $options = isset($button['options']) ? $button['options'] : array();

    if (!isset($options['title']))
        $options['title'] = $label;

    if (!isset($options['rel']))
        $options['rel'] = 'tooltip';

if($type!='drop') $options['class'] = 'btn'; else $options['style'].= 'text-align:left;';

    if (isset($button['icon']))
    {
        if (strpos($button['icon'], 'icon') === false)
            $button['icon'] = 'icon-'.implode(' icon-', explode(' ', $button['icon']));
        echo ($type=='drop')?CHtml::tag('li',array(), CHtml::link('<i class="'.$button['icon'].'"></i>&nbsp;'.$label, $url, $options),true):CHtml::link('<i class="'.$button['icon'].'"></i>', $url, $options).'&nbsp;';

    }
    else if (isset($button['imageUrl']) && is_string($button['imageUrl']))
        echo ($type=='drop')?CHtml::tag('li',array(),CHtml::link(CHtml::image($button['imageUrl'], $label), $url, $options),true):CHtml::link(CHtml::image($button['imageUrl'], $label), $url, $options);
    else
        echo ($type=='drop')?CHtml::tag('li',array(),CHtml::link($label, $url, $options),true):CHtml::link($label, $url, $options);
}

}

}}}

Donna Insolita

Comments (2)

  1. Log in to comment