簡體   English   中英

在joomla 1.5組件中添加工具欄菜單項。

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM