[英]adding toolbar menu item in joomla 1.5 component.
我在joomla 1.5组件的工具栏菜单中添加工具栏添加按钮时遇到问题。 我需要以标准方式添加添加自定义按钮,因此我的按钮已添加到菜单中,但无法正常工作,我需要一个函数来帮助我从按钮中获取参数,例如我的情况下的任务( aaaa)。
/*
ToolBarHelper::custom('aaaa', 'new', 'new', 'Add Article', 'add_article', false);
*/
这是整个工具栏类,如何获取任务参数。
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
/**
* @package Joomla
* @subpackage Config
*/
class TOOLBAR_video
{
function _DEFAULT() {
/*
* DEVNOTE: This should make sense by itself now...
*/
JToolBarHelper::title( JText::_( 'Video Manager' ), 'generic.png' );
JToolBarHelper::custom('aaaa', 'new', 'new', 'Add Article', 'add_article', false);
JToolBarHelper::help( 'screen.video' );
);
}
}
它开始需要做的就是覆盖功能commitbutton函数此函数位于includes / js / joomla.javascript.js中,因此您应该覆盖此函数以将其用作自定义函数
submitbutton(pressbutton) {
submitform(pressbutton);
}
经过研究,我在此处输入链接描述中找到了joomla usfull文章,因此我以这种方式编写。
function submitbutton(pressbutton) {
// Some conditions
document.adminForm.task.value=pressbutton;
// More conditions
submitform(pressbutton);
}
所以最终结果是这样
<script>
/**
* Function is Overwriting native submitbutton() function.
* A Custom button relies on javascript from
* includes/js/joomla.javascript.js to execute the task indicated by the user:
*/
function submitbutton(pressbutton) {
var url = '';
if (pressbutton == 'add_article') {
url = '<?php echo JURI::root(); ?>'+'administrator/index.php?option=com_video&controller=video&action=add_article';
post_to_url(url,{'add_article': 'add_article'} );
}
if (pressbutton == 'delete_article') {
url = '<?php echo JURI::root(); ?>'+'administrator/index.php?option=com_video&controller=articlelisting&action=delete_article';
post_to_url(url,{'add_article': 'add_article'} );
}
}
/**
* Function is creating form and submitting using given url
* @var url string //Joomla admin component constructor path with action
* @var params string //it has {'var1': 'value1','var2': 'value2'} notation
*/
function post_to_url(url, params) {
var form = document.createElement('form');
form.action = url;
form.method = 'POST';
for (var i in params) {
if (params.hasOwnProperty(i)) {
var input = document.createElement('input');
input.type = 'hidden';
input.name = i;
input.value = params[i];
form.appendChild(input);
}
}
form.submit();
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.