Magento – Adding .phtml with JavaScript into Adminhtml Grid

adminhtml

I have been tasked with creating some custom html ( a drop down with button ) in the adminhtml – grid.php. On button click (or update) an ajax call will then update the record in the database. I have a file called warrantyClaim.phtml that I have placed in the \app\design\adminhtml\default\default\template\myapp\warrantyclaim folder

here is what the html looks like in the grid:

<select name="warrantyStatus" id="warrantyStatus" claim="33329">
<option value="0">Not Submitted</option>
<option value="1">Submitted</option>
<option value="2">Pending Approval</option>
<option value="3">Approved</option>
<option value="4" selected="">Partially Approved</option>
<option value="5">Declined</option>
</select>

<button style="display: inline-block;" onclick="updateTitle(this, 33329); return false">Update</button>

Here is the code for my warrantyClaim.phtm file:

<script type="text/javascript">
function updateTitle(button, fieldId)
{
new Ajax.Request('<?php echo Mage::helper('adminhtml')->getUrl('*/*/updateTitle') ?>', {
    method: 'post',
    parameters: { id: fieldId, title: $(button).previous('warrantyStatus').getValue() }
});
}

On button click, I get a javascript error, stating the function updateTitle is not defined, which tells me that my warrantyClaim.phtml is missing.
Did I miss another step? I just placed the warrantyClaim.phtml file into the folder.

Best Answer

phtml files only get called as a template for blocks. Unless you define so in the layout.xml or call it in the php class of the block, it won't be loaded. Since it is all javascript, though, I would make it a .js file and add it with the local.xml into the head of the page with the addJs method.

Related Topic