0

I have problem in adding toolbar add button in toolbar menu in joomla 1.5 component. I need to add an add custom button in the standard way so with this my button is added to my menu but it is not functional I need a function wich will help me to take the parameter from the button for example the task in my case(aaaa).

/*
ToolBarHelper::custom('aaaa', 'new', 'new', 'Add Article', 'add_article', false);
*/

Here is the entire toolbar class how I can get the task parameter.

// 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' );


 );
}
}
4

1 回答 1

0

它开始工作你所要做的就是覆盖函数提交按钮函数这个函数位于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>
于 2012-08-02T07:38:56.757 回答