*/ class Varien_Data_Form_Element_Gallery extends Varien_Data_Form_Element_Abstract { public function __construct($data) { parent::__construct($data); $this->setType('file'); } public function getElementHtml() { $gallery = $this->getValue(); $html = ''; $html .= ''; $widgetButton = $this->getForm()->getParent()->getLayout(); $buttonHtml = $widgetButton->createBlock('adminhtml/widget_button') ->setData( array( 'label' => 'Add New Image', 'onclick' => 'addNewImg()', 'class' => 'add')) ->toHtml(); $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $i = 0; if (!is_null($this->getValue())) { foreach ($this->getValue() as $image) { $i++; $html .= ''; foreach ($this->getValue()->getAttributeBackend()->getImageTypes() as $type) { $url = $image->setType($type)->getSourceUrl(); $html .= ''; } $html .= ''; $html .= ''; $html .= ''; } } if ($i==0) { $html .= ''; } $html .= ''; /* $html .= ''; */ $name = $this->getName(); $parentName = parent::getName(); $html .= << id = 0; function addNewImg(){ document.getElementById("gallery_thead").style.visibility="visible"; id--; new_file_input = ''; // Sort order input var new_row_input = document.createElement( 'input' ); new_row_input.type = 'text'; new_row_input.name = '{$parentName}[position]['+id+']'; new_row_input.size = '3'; new_row_input.value = '0'; // Delete button var new_row_button = document.createElement( 'input' ); new_row_button.type = 'checkbox'; new_row_button.value = 'Delete'; table = document.getElementById( "gallery" ); // no of rows in the table: noOfRows = table.rows.length; // no of columns in the pre-last row: noOfCols = table.rows[noOfRows-2].cells.length; // insert row at pre-last: var x=table.insertRow(noOfRows-1); // insert cells in row. for (var j = 0; j < noOfCols; j++) { newCell = x.insertCell(j); newCell.align = "center"; newCell.valign = "middle"; if (j==3) { newCell.appendChild( new_row_input ); } else if (j==4) { newCell.appendChild( new_row_button ); } else { newCell.innerHTML = new_file_input.replace(/%j%/g, j).replace(/%id%/g, id); } } // Delete function new_row_button.onclick= function(){ this.parentNode.parentNode.parentNode.removeChild( this.parentNode.parentNode ); // Appease Safari // without it Safari wants to reload the browser window // which nixes your already queued uploads return false; }; } EndSCRIPT; $html.= $this->getAfterElementHtml(); return $html; } public function getName() { return $this->getData('name'); } public function getParentName() { return parent::getName(); } }