{select_type} |
{select_name} |
{add} |
';
var $_optionList = array();
var $_itemsName;
function HTML_QuickForm_AddItem($elementName, $elementLabel, $options, $itemsName, $attributes=array())
{
$this->_options = $options;
$this->_itemsName = $itemsName;
parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
}
function setTemplate($template)
{
$this->_template = $template;
}
function toHtml()
{
$JS = '
';
$types = array();
$arrayVSNames = "var AddItem_nameList = Array();\n";
// vdie($this->_options);
foreach ($this->_options as $key => $type){
$types[$key] = $type['title'];
$arrayVSNames .= "AddItem_nameList['$key'] = Array();\n";
$arrayVSNames .= "AddItem_nameList['$key']['editable'] = {$type['editable']};\n";
$arrayVSNames .= "AddItem_nameList['$key']['names'] = Array();\n";
foreach ((array)$type['items'] as $name => $title){
$arrayVSNames .= "AddItem_nameList['$key']['names']['$name'] = '".addslashes($title)."';\n";
}
}
// vdie($arrayVSNames);
// var name = document.getElementsByName("_Name")[0];
$add = new HTML_QuickForm_button('add', 'Add', array('onClick'=>'AddItem_addSelectedItem();' ));
$type = new HTML_QuickForm_select('_Type', null, $types, array('onchange' => 'AddItem_reloadNames();'));
$type->setValue( array_shift(array_keys($this->_options)) );
$name = new HTML_QuickForm_select('_Name', null, $optionsOut);
$html = str_replace(array('{select_type}', '{select_name}', '{add}', ),
array($type->toHtml(),$name->toHtml(), $add->toHtml()),
$this->_template);
$html .= str_replace(array('{arrayVSNames}', '{itemsName}'),
array($arrayVSNames, $this->_itemsName.'[]'),
$JS );
/* $options = $this->_options;
$optionsOut = array();
foreach ($options as $otp){
$optionsOut[$otp['attr']['value']] = $otp['text'];
}
$hide = new HTML_QuickForm_select($this->getName(), null, $optionsOut);
$hide->setMultiple(true);
$hide->setValue(array_keys($optionsOut));
$hide->updateAttributes(array('style' => 'visibility:hidden;width:1px; height:1px;'));
$name = $this->getName();
$this->setName('_'.$name);
$showHtml = parent::toHtml();
$this->setName($name);
$html = $hide->toHtml();
$html .= str_replace('{select}', $showHtml, $this->_template);
$actionsJsFunctions = '';
foreach ($this->getActions() as $name => $action) {
if (method_exists($action['button'], 'toHtml')){
$buttonHtml = str_replace('{name}', $this->getName().'[]', $action['button']->toHtml());
}else {
$buttonHtml = '';
}
$html = str_replace('{'.$name.'}', $buttonHtml, $html);
$actionsJsFunctions .= $action['function'];
}
$JS = '
';
$html .= str_replace('{actions_js_functions}', $actionsJsFunctions, $JS);
*/
return $html;
}
}
?>