Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Create custom task button for multi items in grid?

Create custom task button for multi items in grid? 12 Oct 2012 14:59 #4437

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi Cooks,

Been a quiet day in the forum today! Things must be working well, eh? ;)

OK, apologies if this has been asked/discussed previously however, my search for custom task & tasks didn't reveal any answers...

Basically, in a bunch of my list views, I need to be able to invoke a custom function via a task button on multiple selected checkboxes, to take their ids and store each of them in another table as a foreign key.

Let's just say for the moment I have the following tables & fields where each project could have 1 or more clients associated with it;
  • projects - id, title
  • clients - id, title, region
  • project_clients - id, client_id, project_id, qty_places
here's the workflow I'm trying to achieve;
  1. In my projects item view, on successful save, I want to redirect to my clients grid view reusing the newly created id from the projects table
  2. select one or more clients from the grid using the checkboxes
  3. pass each of the selected ids (clients) as an array in addition to the reused project id to a custom function addprojectclients using a custom task button
  4. The addprojectclients function then loops through the array to store the project_id & client_id for each of them in a loop
This is my first step...

There's 1 other that I'd like to achieve ultimately; Generating a form on the fly that would allow me to set some other data on each new row of project clients before saving them all. For example, the field qty_places. I'll probably look to do this in jQuery and in a modal window or something but first, I need to get the basics out of the way.

The looping and writing the function itself is no problem, I just have no idea how to add a custom task/button.

Any help on this would be greatly appreciated.

many thanks!!!

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.
The following user(s) said Thank You: Tomaselli

Re: Create custom task button for multi items in grid? 13 Oct 2012 01:33 #4438

  • BTB300
  • BTB300's Avatar
  • Offline
  • Moderator
  • Posts: 415
  • Thank you received: 132
  • Karma: 47
Hi Gez,
I am working on similar custom buttons at present when I get back to my PC I will give you some starting points
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy

Re: Create custom task button for multi items in grid? 13 Oct 2012 05:51 #4439

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi @BTB3000,

Somebody had a late one, eh? ;)

That's very kind of you - I would appreciate it very much!

Look forward to reading it...

Many thanks,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Create custom task button for multi items in grid? 13 Oct 2012 10:17 #4452

  • BTB300
  • BTB300's Avatar
  • Offline
  • Moderator
  • Posts: 415
  • Thank you received: 132
  • Karma: 47
Late one? nah it was mid afternoon here it's now only 11:00pm for me but yes but like you my main job is not coding... But I usually run on little sleep working till early hours of the morning - less disruptions when everyone's asleep!

Anyhow back at my PC now will post again shortly
The administrator has disabled public write access.

Re: Create custom task button for multi items in grid? 13 Oct 2012 10:25 #4453

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
You in Oz then?

Yes, it is difficult getting round to all this stuff when it's not your main job. My main problem is I work for myself so things can become a bit blurred sometimes... Asking myself, "Should I be doing actual work or coding?".

Anyway, look forward to your post! I also hope to also use it on the import/export script I wrote and publish a tut about it.

Catch you soon & many thanks!

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Create custom task button for multi items in grid? 13 Oct 2012 17:08 #4458

  • VeCrea
  • VeCrea's Avatar
  • Offline
  • Platinum Member
  • Absolute JCook fan
  • Posts: 473
  • Thank you received: 100
  • Karma: 30
BTB300 wrote:
But I usually run on little sleep working till early hours of the morning - less disruptions when everyone's asleep!
Same here... Read an article once about working late night, saying the same as you, about no disruptions. It added that being just a little bit tired helps the mind focusing on the task.
The administrator has disabled public write access.

Re: Create custom task button for multi items in grid? 14 Oct 2012 06:39 #4462

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi @BTB3000,

Sorry to bother you when i know you're probably busy... Just wondering if there was any news?

Many thanks in advance!!!

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Create custom task button for multi items in grid? 14 Oct 2012 07:21 #4464

  • BTB300
  • BTB300's Avatar
  • Offline
  • Moderator
  • Posts: 415
  • Thank you received: 132
  • Karma: 47
It seems that the project i downloaded last night is missing some standard buttons... ??? in the frontend i only have delete when logged in as an admin... even in sandbox.
In fact i thought it was my code for a while until i realized that some code that i had in my notes were missing...

I wonder if our wonderful "Master Chef" is up to something with the toolbar?
The administrator has disabled public write access.

Re: Create custom task button for multi items in grid? 14 Oct 2012 08:09 #4466

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
I did pose some queries about the publishing wizard, specifically trash, checkin and archive state task buttons/functions which I understand, some of which is working locally in admin's local environment.

Maybe that's it!

Just about to go load my project so will see if I get same symptoms as you describe.

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Create custom task button for multi items in grid? 14 Oct 2012 08:11 #4467

  • BTB300
  • BTB300's Avatar
  • Offline
  • Moderator
  • Posts: 415
  • Thank you received: 132
  • Karma: 47
Hi Gez,
Here's what i have so far - its not 100% finished or fully tested really its just a work in progress... but its a start i will continue to update this post.
Most of the areas where you need to add the custom button code i have used [custombutton] or [CUSTOMBUTTON] to highlight where the "custombutton" name needs to be defined DONT include the braces [ ] :lol:

Some of the below may not be needed - you may get away with just creating the task behind the button and registering the task but it depends on your needs

Before you start
To find what may already be possible without reinventing the wheel, have a look at the Standard tool bar icons in your standard bluestork template there are many predefined buttons and methods in the core for standard operations such as upload, forward, back...

Search for "toolbar icon styles" (or scroll to about line 2095) there you will find a list of button icons used for the toolbars
/administrator/templates/bluestork/css/template.css

TASKBAR ICONS - create your taskbar icon
BACKEND => administrator/templates/[YOUR SITE TEMPLATE]/images...
(there may be specific directory for toolbar icons)
create your icons and place them in the images file of your site template such as
icon-32-[custombutton].png

TASKBAR ICON CSS - Add icon details to your site template css
You maybe able to create template overrides but I prefer to create the icon and place in the relative template file and modify the template css - the choice is yours

BACKEND => administrator/templates/[YOUR TEMPLATE]/css/template.css
add icon details to your template css file such as
.icon-32-[custombutton] { background-image: url('../images/icon-32-[custombutton].png'); }

LANGUAGE FILES - Add custom button name
FRONTEND => \language\en-GB\en-GB.com_yourcomponentname.ini
BACKEND => \administrator\language\en-GB\en-GB.com_yourcomponentname.ini
//such as
[YOURCOMPONENTNAME]_JTOOLBAR_[CUSTOMBUTTON]="Custom Button"

VIEW.HTML.PHP - Define the custom button in the view.html.php file of respective view

NOTE: notice the difference between collection and item layouts when checking view access
COLLECTION LAYOUTS - use if($model->canEdit())
ITEM LAYOUTS - use if ($item->params->get('access-edit'))

FOR ITEM LAYOUTS - look for similar and define custom button
REMEMBER - use if ($item->params->get('access-edit'))
TAKE NOTE - The "TASK" is the same for both custom button definitions!
what to do when the button is pressed is determined by the switch function in the custombutton function of the item controller
//Toolbar initialization
	JToolBarHelper::title(JText::_('YOURCOMPONENTNAME_LAYOUT_NAME_ITEM'), 'yourcomponentname_yourviewname');
......
......

// Custom button
if ($item->params->get('access-edit'))
	JToolBarHelper::custom('tableitem.[custombutton]', '[custombutton].png', '[custombutton].png', JText::_("[YOURCOMPONENTNAME]_JTOOLBAR_[CUSTOMBUTTON]"),  false, false);

// ANOTHER Custom button
// Take Note the "TASK" is the same for both custom button definitions!
if ($item->params->get('access-edit'))
	JToolBarHelper::custom('tableitem.[custombutton]', '[anothercustombutton].png', '[anothercustombutton].png', JText::_("[YOURCOMPONENTNAME]_JTOOLBAR_[ANOTHERCUSTOMBUTTON]"),  false, false);

FOR COLLECTION LAYOUTS
REMEMBER - use $model->canEdit() to determine view access
// CUSTOM BUTTON
if ($model->canEdit())
	JToolBarHelper::custom('tableitem.[custombutton]', '[custombutton].png', '[custombutton].png', JText::_("[YOURCOMPONENTNAME]_JTOOLBAR_[CUSTOMBUTTON]"),  false, false);

For reference on how to define custom buttons
From Joomla Docs - docs.joomla.org/How_to_create_a_custom_button
/**
* Writes a custom option and task button for the button bar
* @param string The task to perform (picked up by the switch($task) blocks
* @param string The image to display
* @param string The image to display when moused over
* @param string The alt text for the icon image
* @param boolean True if required to check that a standard list item is checked
* @param boolean True if required to include callinh hideMainMenu() 
*/
 
JToolBarHelper::custom( 'task', 'icon', 'icon over', 'alt', boolean, boolean );

ALSO - Found this tutorial today has good how create custom toolbar buttons
www.tutsforu.com/adding-toolbar-at-backe...oomla-component.html

ITEM CONTROLLER - Create the task function and redirect in the respective item controller
(at present i believe that all of the redirects are defined in the item controller)
public function [custombutton]()
{
	JRequest::checkToken() or JRequest::checkToken('get') or jexit(JText::_('JINVALID_TOKEN'));

	//Check the ACLs
	$model = $this->getModel();
	$item = $model->getItem();
	if (!$model->canEdit($item))
		return false;

	//Catch the initializated JModel trough postSaveHook()
	$model = $this->model;

	//Define the redirections
	switch($this->getLayout() .'.'. $this->getTask())
	{
		case 'yourviewname.[custombutton]':
			$this->applyRedirection($result, array(
				'com_yourcomponentname.yourviewname.yourcurrentlayoutname',
				'com_yourcomponentname.redirecttoyourviewname.redirecttolayoutname'
			), array(
			'cid[]' => null,
				'filter_some_id' => $model->getState('yourcurrentlayoutname.id')
			));
		break;
		
		
		// add additional custom button redirects here such as
		case 'yourviewname.[anothercustombutton]':
			$this->applyRedirection($result, array(
				'com_yourcomponentname.yourviewname.yourcurrentlayoutname',
				...........
				...........
				));
		break;		
	}
}

CREATE THE SUBMIT - in administrator/components/com_yourcomponent/dom/html/toolbar/button.php
switch ($this->getTaskExec())
{
	case 'save':
	case 'apply':
		if (!defined('JQUERY'))
			$submitAction = "return document.formvalidator.submitform (document.adminForm, '" . $taskCtrl . "', function(pressbutton){return " . $jsSubmitForm . "(pressbutton);});";
			$cmd = "javascript:" . $submitAction;
	break;
				
	case '[custombutton]';
		if (!defined('JQUERY'))
			$submitAction = "return document.formvalidator.submitform (document.adminForm, '" . $taskCtrl . "', function(pressbutton){return " . $jsSubmitForm . "(pressbutton);});";
		$cmd = "javascript:" . $submitAction;
	break;

TASK SWITCH - create case for the custom button
in administrator/components/com_yourcomponent/dom/dom.php
function accessTask($task)
{
	$aclAccess = $this->getOption('aclAccess');

	if ($aclAccess)
		return $this->access();

	switch ($task)
	{
		case 'new':
			$access = 'core.create';
			break;
		
		case '[custombutton]':
			$access = 'core.edit';
			break;

		case 'edit':
		...........
		...........
Last Edit: 15 Oct 2012 15:46 by BTB300.
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy

Re: Create custom task button for multi items in grid? 14 Oct 2012 08:21 #4469

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Thanks for this, I'm sure I'll have a question or two if you don't mind! I really appreciate it...

Will check it out as soon as I've completed the 2 tables I'm wishing to use it on.

BTW - ultimately, is this something you think could be added in a custom JDom class? I mean, would that make re-using it easier?

Thanks again!!!

K+1

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Create custom task button for multi items in grid? 14 Oct 2012 08:57 #4470

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi @BTB3000BTB3000 wrote:
It seems that the project i downloaded last night is missing some standard buttons... ??? in the frontend i only have delete when logged in as an admin... even in sandbox.

OK, I just checked some of my front-end grids;
  1. One of them only displays the delete button as you describe (it should also have New & Edit options
  2. Another appears correctly
  3. PLUS
  4. Forms seem to be ok
***CORRECTION***
I believe this is my mistake actually!!!

On the grid where I have only delete, I have no form view to go to yet which is probably why the other tasks/buttons don't exist....

Are you still getting this error?

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Create custom task button for multi items in grid? 14 Oct 2012 08:58 #4471

  • BTB300
  • BTB300's Avatar
  • Offline
  • Moderator
  • Posts: 415
  • Thank you received: 132
  • Karma: 47
Gez you will see that i am working on integrating it into the jdom class almost there and yes always willing to help

As for the toolbar issue i recreated the toolbar and applied some redirects and it didn't change could be my mistake i think chrome is caching on me for some reason (even after clearing it) perhaps i need to clear firefox cache before building for download again... but its been a busy weekend for me will check again tomorrow

EDIT: As I said has been a busy weekend... and yes there should have only been a delete button as both of my tables in the frontend used fly views only !!!
Last Edit: 14 Oct 2012 12:03 by BTB300.
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy

Re: Create custom task button for multi items in grid? 14 Oct 2012 09:19 #4472

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi, that's awesome!

RE: your cache issue
It seems weird how sometimes I get no issues with it and others, nothing seems to work... That said, I always find completely closing the builder project helps eventually...

Thanks again for sharing this!!!

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Create custom task button for multi items in grid? 14 Oct 2012 11:43 #4475

  • BTB300
  • BTB300's Avatar
  • Offline
  • Moderator
  • Posts: 415
  • Thank you received: 132
  • Karma: 47
audibleid wrote:
I did pose some queries about the publishing wizard, specifically trash, checkin and archive state task buttons/functions which I understand, some of which is working locally in admin's local environment.

Thats correct there are many predefined buttons and methods for standard operations such as upload, forward, back... in the core

For those looking to add a button that does not turn tricks and do a hand stand at the same time...

To find what may already be possible without reinventing the wheel,
have a look at the Standard tool bar icons in your standard bluestork template
/administrator/templates/bluestork/css/template.css
search for "toolbar icon styles" (or scroll to about line 2095) there you will find a list of button icons used for the toolbars
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy
  • Page:
  • 1
  • 2
Time to create page: 0.235 seconds

Get Started