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' );
);
}
}
It start woking all you have to do is to overwrite function submitbutton function This function is located in includes/js/joomla.javascript.js, so you should override this function to use it as custom
submitbutton(pressbutton) {
submitform(pressbutton);
}
After some research I found the joomla usfull article in enter link description here so I write in this way.
function submitbutton(pressbutton) {
// Some conditions
document.adminForm.task.value=pressbutton;
// More conditions
submitform(pressbutton);
}
So the final result is this
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.