Commits

Insolita Donna committed 5723c08

Some my customizing :
+ set type of label - html,text or image
+ set correct title attribute for link and alt attribute for image

  • Participants
  • Parent commits e434bda

Comments (0)

Files changed (1)

File JToggleColumn.php

     public $footerHtmlOptions = array('class' => 'toggle-column');
 
     /**
-     * @var string the label for the toggle button. Defaults to "toggle".
-     * Note that the label will not be HTML-encoded when rendering.
+     * @var string the text-label or imageUrl or or html-code for the toggle button. Defaults to "toggle".
      */
     public $checkedButtonLabel;
 
     /**
-     * @var string the label for the toggle button. Defaults to "toggle".
-     * Note that the label will not be HTML-encoded when rendering.
+     * @var string the text-label or imageUrl or html-code for the toggle button. Defaults to "toggle".
      */
     public $uncheckedButtonLabel;
+    /**
+     * @var string the title attribute for the toggle button link
+     */
+    public $checkedButtonTitle;
 
     /**
-     * @var string the image URL for the toggle button. If not set, an integrated image will be used.
-     * You may set this property to be false to render a text link instead.
+     * @var string the title attribute for the toggle button link
      */
-    public $checkedButtonImageUrl;
+    public $uncheckedButtonTitle;
 
     /**
-     * @var string the image URL for the toggle button. If not set, an integrated image will be used.
-     * You may set this property to be false to render a text link instead.
+     * @var string the type of label - may be one of "text","image","html".
      */
-    public $uncheckedButtonImageUrl;
+
+    public $labeltype='text';
+
 
     /**
      * @var array the configuration for toggle button.
      * @see name
      */
     public $sortable = true;
-    
+
     /**
-    * @var mixed the HTML code representing a filter input (eg a text field, a dropdown list)
-    * that is used for this data column. This property is effective only when
-    * {@link CGridView::filter} is set.
-    * If this property is not set, a text field will be generated as the filter input;
-    * If this property is an array, a dropdown list will be generated that uses this property value as
-    * the list options.
-    * If you don't want a filter for this data column, set this value to false.
-    * @since 1.1.1
-    */
+     * @var mixed the HTML code representing a filter input (eg a text field, a dropdown list)
+     * that is used for this data column. This property is effective only when
+     * {@link CGridView::filter} is set.
+     * If this property is not set, a text field will be generated as the filter input;
+     * If this property is an array, a dropdown list will be generated that uses this property value as
+     * the list options.
+     * If you don't want a filter for this data column, set this value to false.
+     * @since 1.1.1
+     */
     public $filter;
-    
+
     /**
      * @var string Name of the action
      */
     public $action;
-    
+
     /**
      * @var string Assets url
      */
     private $_assetsUrl;
- 
+
     /**
      * Returns assets url, where check and uncheck images are located
      * @return string
      * Initializes the default buttons (toggle).
      */
     protected function initDefaultButtons() {
-        if ($this->checkedButtonLabel === null)
-            $this->checkedButtonLabel = Yii::t('toggle_column', 'Uncheck');
-        if ($this->uncheckedButtonLabel === null)
-            $this->uncheckedButtonLabel = Yii::t('toggle_column', 'Check');
-        if ($this->checkedButtonImageUrl === null)
-            $this->checkedButtonImageUrl = $this->getAssetsUrl(). '/checked.png';
-        if ($this->uncheckedButtonImageUrl === null)
-            $this->uncheckedButtonImageUrl = $this->getAssetsUrl() . '/unchecked.png';
-            
+        switch($this->labeltype){
+            case 'image':{
+            if ($this->checkedButtonLabel === null)
+                $this->checkedButtonLabel = $this->getAssetsUrl(). '/checked.png';
+            if ($this->uncheckedButtonLabel === null)
+                $this->uncheckedButtonLabel = $this->getAssetsUrl() . '/unchecked.png';
+            break;
+            }
+            case 'html':{
+            if ($this->checkedButtonLabel === null)
+                $this->checkedButtonLabel = '<i class="icon-check"></i>';//for twitter-bootstrap most used
+            if ($this->uncheckedButtonLabel === null)
+                $this->uncheckedButtonLabel = '<i class="icon-check-empty"></i>';//for twitter-bootstrap most used
+            break;
+            }
+            default:{
+            if ($this->checkedButtonLabel === null)
+                $this->checkedButtonLabel = Yii::t('toggle_column', 'Uncheck');
+            if ($this->uncheckedButtonLabel === null)
+                $this->uncheckedButtonLabel = Yii::t('toggle_column', 'Check');
+            }
+
+        }
+        if ($this->checkedButtonTitle === null)
+            $this->checkedButtonTitle = Yii::t('toggle_column', 'Uncheck');
+        if ($this->uncheckedButtonTitle === null)
+            $this->uncheckedButtonTitle = Yii::t('toggle_column', 'Check');
+
+
         if ($this->action === null)
             $this->action = 'toggle';
 
         if ($this->name !== null)
             $checked = CHtml::value($data, $this->name);
 
-        $button['imageUrl'] = $checked ? $this->checkedButtonImageUrl : $this->uncheckedButtonImageUrl;
-        $button['label'] = $checked ? $this->checkedButtonLabel : $this->uncheckedButtonLabel;
-
-        $label = $button['label'];
+        $button['title'] = $checked ? $this->checkedButtonTitle : $this->uncheckedButtonTitle;
+        $alt =CHtml::encode($button['title']);
         $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($button['imageUrl']) && is_string($button['imageUrl']))
-            echo CHtml::link(CHtml::image($button['imageUrl'], $label), $url, $options);
-        else
-            echo CHtml::link($label, $url, $options);
+        $options=(!isset($options['title']))?array_merge($options,array('title'=>$alt)):$options;
+        switch($this->labeltype){
+            case 'image':{
+            $button['imageUrl'] = $checked ? $this->checkedButtonLabel : $this->uncheckedButtonLabel;
+            echo CHtml::link(CHtml::image($button['imageUrl'], $alt), $url, $options);
+            break;
+            }
+            case 'html':{
+            $button['label'] = $checked ? $this->checkedButtonLabel : $this->uncheckedButtonLabel;
+            echo CHtml::link($button['label'], $url, $options);
+            break;
+            }
+            default:{
+            $button['label'] = $checked ? $this->checkedButtonLabel : $this->uncheckedButtonLabel;
+            echo CHtml::link(CHtml::encode($button['label']), $url, $options);
+            }
+
+        }
+
+
     }
-    
+
     /**
-    * Renders the filter cell content.
-    * This method will render the {@link filter} as is if it is a string.
-    * If {@link filter} is an array, it is assumed to be a list of options, and a dropdown selector will be rendered.
-    * Otherwise if {@link filter} is not false, a text field is rendered.
-    * @since 1.1.1
-    */
+     * Renders the filter cell content.
+     * This method will render the {@link filter} as is if it is a string.
+     * If {@link filter} is an array, it is assumed to be a list of options, and a dropdown selector will be rendered.
+     * Otherwise if {@link filter} is not false, a text field is rendered.
+     * @since 1.1.1
+     */
     protected function renderFilterCellContent() {
- 
+
         if ($this->filter !== null) {
             if (is_string($this->filter))
                 echo $this->filter;