上一节中讲到了自定义表单字段,本节继续。这一节中我们将重点讲解具体的视图操作。
当用户点击按钮的时候,系统会弹出一个模态对话框,这个对话框中的内容是确定是通过如下代码确定的:
index.php?option=com_download&view=items&layout=modal&tmpl=component&function=SelectItem
也 就是说系统会加载com_download组件的items视图的modal布局。并且指定了tmpl=component。这个tmpl很关键,它告诉 系统,不要加载joomla框架了(也就是菜单栏还有一些其他的内容)只是简单的加载组件视图就行了。并且这里还传递了 function=SelectItem这个参数。
看一下视图布局modal.php文件的代码:
<?php defined('_JEXEC') or die('你不能直接访问这个文件!'); $listOrder = $this->state->get('list.ordering'); $listDirn = $this->state->get('list.direction'); $function = JRequest::getCmd('function','selectItem'); //load tooltip behavior JHtml::_('behavior.tooltip'); ?> <form action="<?php echo JRoute::_('index.php?option=com_download&view=items&layout=modal&tmpl=component&function='.$function.'&'.JSession::getFormToken().'=1');?>" method="post" name="adminForm" id="adminForm"> <table class="adminlist"> <tr> <?php $id = JHTML::_('grid.sort',JText::_("COM_DOWNLOAD_ITEM_ORDER"),'id',$listDirn,$listOrder); $title = JHTML::_('grid.sort',JText::_("COM_DOWNLOAD_ITEM_TITLE"),'title',$listDirn,$listOrder); $published = JHTML::_('grid.sort',JText::_("COM_DOWNLOAD_ITEM_PUBLISHED"),'published',$listDirn,$listOrder); ?> <td> <?php echo $id;?> </td> <td> <?php echo $title;?> </td> <td> <?php echo $published;?> </td> </tr> <?php $n = 0; foreach ($this->items as $item): $checked = JHTML::_('grid.id',$n,$item->id); //$item->description = mb_strimwidth($item->description,0,150,'......'); $titleLink = JHTML::_('link','index.php?option=com_download&task=item.edit&id='.$item->id,$item->title); $descriptionLink = JHTML::_('link','index.php?option=com_download&task=item.edit&id='.$item->id,$item->description); ?> <tr class="<?php echo "row".$n%2; ?>"> <td> <?php echo $item->id;?> </td> <td> <a class="pointer" onclick="if(window.parent) window.parent.<?php echo $this->escape($function);?>('<?php echo $item->id;?>','<?php echo $item->title;?>','test');"> <?php echo $item->title;?> </a> </td> <td> <?php $published = JHTML::_('grid.published',$item->published, $n ,'tick.png','publish_x.png','items.');?> <?php echo $published;?> </td> </tr> <?php $n++;?> <?php endforeach;?> </table> <div> <input type="hidden" name="task" value=""/> <input type="hidden" name="option" value=""/> <input type="hidden" name="view" value=""/> <input type="hidden" name="boxchecked" value="0" /> <input type="hidden" name="filter_order" value="<?php echo $listOrder;?>" /> <input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn;?>" /> <?php echo JHtml::_('form.token');?> </div> </form>
重点说一下
<td>
<a class="pointer" onclick="if(window.parent) window.parent.<?php echo $this->escape($function);?>('<?php echo $item->id;?>','<?php echo $item->title;?>','test');">
<?php echo $item->title;?>
</a>
</td>
大概的工作就是当用户点击的时候就调用父窗口的selectItem函数。从中我们可以看到如果要在模态对话框中调用父窗口的js代码,需要使用的格式为window.parent.functionname.
到此,整个自定义表单字段算是圆满了。
评论 (0)