Varien_Data_Form_Element_Multiselect Class Reference

Inheritance diagram for Varien_Data_Form_Element_Multiselect:

Varien_Data_Form_Element_Abstract Varien_Data_Form_Abstract Varien_Object Mage_Adminhtml_Block_Catalog_Category_Helper_Sortby_Available Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Apply

List of all members.

Public Member Functions

 __construct ($attributes=array())
 getName ()
 getElementHtml ()
 getHtmlAttributes ()
 getDefaultHtml ()
 getJsObjectName ()

Protected Member Functions

 _optionToHtml ($option, $selected)


Detailed Description

Definition at line 34 of file Multiselect.php.


Constructor & Destructor Documentation

__construct ( attributes = array()  ) 

Enter description here...

Parameters:
array $attributes

Reimplemented from Varien_Data_Form_Element_Abstract.

Definition at line 36 of file Multiselect.php.

00037     {
00038         parent::__construct($attributes);
00039         $this->setType('select');
00040         $this->setExtType('multiple');
00041         $this->setSize(10);
00042     }


Member Function Documentation

_optionToHtml ( option,
selected 
) [protected]

Definition at line 133 of file Multiselect.php.

00134     {
00135         $html = '<option value="'.$this->_escape($option['value']).'"';
00136         $html.= isset($option['title']) ? 'title="'.$option['title'].'"' : '';
00137         $html.= isset($option['style']) ? 'style="'.$option['style'].'"' : '';
00138         if (in_array($option['value'], $selected)) {
00139             $html.= ' selected="selected"';
00140         }
00141         $html.= '>'.$option['label']. '</option>'."\n";
00142         return $html;
00143     }

getDefaultHtml (  ) 

Reimplemented from Varien_Data_Form_Element_Abstract.

Definition at line 92 of file Multiselect.php.

00093     {
00094         $result = ( $this->getNoSpan() === true ) ? '' : '<span class="field-row">'."\n";
00095         $result.= $this->getLabelHtml();
00096         $result.= $this->getElementHtml();
00097 
00098 
00099         if($this->getSelectAll() && $this->getDeselectAll()) {
00100             $result.= '<a href="#" onclick="return ' . $this->getJsObjectName() . '.selectAll()">' . $this->getSelectAll() . '</a> <span class="separator">&nbsp;|&nbsp;</span>';
00101             $result.= '<a href="#" onclick="return ' . $this->getJsObjectName() . '.deselectAll()">' . $this->getDeselectAll() . '</a>';
00102         }
00103 
00104         $result.= ( $this->getNoSpan() === true ) ? '' : '</span>'."\n";
00105 
00106 
00107         $result.= '<script type="text/javascript">' . "\n";
00108         $result.= '   var ' . $this->getJsObjectName() . ' = {' . "\n";
00109         $result.= '     selectAll: function() { ' . "\n";
00110         $result.= '         var sel = $("' . $this->getHtmlId() . '");' . "\n";
00111         $result.= '         for(var i = 0; i < sel.options.length; i ++) { ' . "\n";
00112         $result.= '             sel.options[i].selected = true; ' . "\n";
00113         $result.= '         } ' . "\n";
00114         $result.= '         return false; ' . "\n";
00115         $result.= '     },' . "\n";
00116         $result.= '     deselectAll: function() {' . "\n";
00117         $result.= '         var sel = $("' . $this->getHtmlId() . '");' . "\n";
00118         $result.= '         for(var i = 0; i < sel.options.length; i ++) { ' . "\n";
00119         $result.= '             sel.options[i].selected = false; ' . "\n";
00120         $result.= '         } ' . "\n";
00121         $result.= '         return false; ' . "\n";
00122         $result.= '     }' . "\n";
00123         $result.= '  }' . "\n";
00124         $result.= "\n</script>";
00125 
00126         return $result;
00127     }

getElementHtml (  ) 

Reimplemented from Varien_Data_Form_Element_Abstract.

Reimplemented in Mage_Adminhtml_Block_Catalog_Category_Helper_Sortby_Available, and Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Apply.

Definition at line 53 of file Multiselect.php.

00054     {
00055         $this->addClass('select multiselect');
00056         $html = '';
00057         if ($this->getCanBeEmpty()) {
00058             $html .= '<input type="hidden" name="' . parent::getName() . '" value="" />';
00059         }
00060         $html .= '<select id="'.$this->getHtmlId().'" name="'.$this->getName().'" '.$this->serialize($this->getHtmlAttributes()).' multiple="multiple">'."\n";
00061 
00062         $value = $this->getValue();
00063         if (!is_array($value)) {
00064             $value = explode(',', $value);
00065         }
00066 
00067         if ($values = $this->getValues()) {
00068             foreach ($values as $option) {
00069                 if (is_array($option['value'])) {
00070                     $html.='<optgroup label="'.$option['label'].'">'."\n";
00071                     foreach ($option['value'] as $groupItem) {
00072                         $html.= $this->_optionToHtml($groupItem, $value);
00073                     }
00074                     $html.='</optgroup>'."\n";
00075                 }
00076                 else {
00077                     $html.= $this->_optionToHtml($option, $value);
00078                 }
00079             }
00080         }
00081 
00082         $html.= '</select>'."\n";
00083         $html.= $this->getAfterElementHtml();
00084         return $html;
00085     }

getHtmlAttributes (  ) 

Reimplemented from Varien_Data_Form_Element_Abstract.

Definition at line 87 of file Multiselect.php.

00088     {
00089         return array('title', 'class', 'style', 'onclick', 'onchange', 'disabled', 'size');
00090     }

getJsObjectName (  ) 

Definition at line 129 of file Multiselect.php.

00129                                       {
00130          return $this->getHtmlId() . 'ElementControl';
00131     }

getName (  ) 

Reimplemented from Varien_Data_Form_Element_Abstract.

Definition at line 44 of file Multiselect.php.

00045     {
00046         $name = parent::getName();
00047         if (strpos($name, '[]') === false) {
00048             $name.= '[]';
00049         }
00050         return $name;
00051     }


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

Generated on Sat Jul 4 17:25:00 2009 for Magento by  doxygen 1.5.8