Welcome, Guest
Username: Password: Remember me

TOPIC: Add a new SAVE task

Add a new SAVE task 27 Oct 2015 12:06 #13617

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
I need to register a new type of save task, alongside apply,save2new,save etc

I want to create a new task apply2other

Basically its just redirects to a different place

I have copied the APPLY code i.e
case 'creategenre.apply':
                $this->applyRedirection($result, array(
                    'stay',
                    'com_mycomponent.genre.creategenre'
                ), array(
                    'cid[]' => $model->getState('genre.id')
                ));
                break;

and based my new one on this.. basically same thing, but it a new task bar button that drives the save to a new layout
case 'creategenre.apply2new':
                $this->applyRedirection($result, array(
                    'stay',
                    'com_mycomponent.object.createobject'
                ), array(
                    'cid[]' => null)
                ));
                break;


I get no errors, but the task skips to the catch all at the end (default) and ignores this tasks existance (I have forked it by the way)

I tried to register the task in the classes/controller/item.php in the admin section with no joy

How can I register a new task?

I can make alterations to the normal tasks and they work ok, just not create new ones
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.

Add a new SAVE task 27 Oct 2015 12:40 #13619

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
In your intro text you say "apply2other", but in your code it states "apply2new"
Can that be the problem?

Can you otherwise past the code from your button? Is the task filled correctly?
The administrator has disabled public write access.

Add a new SAVE task 27 Oct 2015 13:50 #13628

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
Sorry that was a typo.. the code is as it is, and I am calling the task the same way as apply.. i.e a button with
Joomla.submitform('genre.apply');" // This works as expected.. its the out of the box code

becomes
Joomla.submitform('genre.apply2new');"  // This is my attempt to call my personal task

Just to clarify, when you click on the NEW button, it saves the record and then shoot of to another view where this new record is then available to use in the FK list.

Its kinda like a cheap 'in form fk update', but is really just to allow user to get to the next screen they want with minimal key presses (nothing to do with the next previous thing I raised a week or so back), this is just a connivence thing
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.

Add a new SAVE task 27 Oct 2015 15:34 #13634

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
Sorry, I mean the php code which creates your custom button ;)

The most easy way is to add it in the view.html.php forked file in the displayYourView function;

CkJToolBarHelper::custom('genre.apply2new', null,null, "Text for button");
Last Edit: 27 Oct 2015 15:36 by Romkabouter.
The administrator has disabled public write access.

Add a new SAVE task 27 Oct 2015 15:52 #13635

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
Just for ease, I redid the whole thing and here it is

In my controller (genre.php) in the
        //Define the redirections
        switch($this->getLayout() .'.'. $this->getTask())
        {
            case 'creategenre.save':
                $this->applyRedirection($result, array(
                    'stay',
                    'com_mycomponent.genre.default'
                ), array(
                    'cid[]' => null
                ));
                break;

            case 'creategenre.apply':
                $this->applyRedirection($result, array(
                    'stay',
                    'com_mycomponent.genre.creatgenre'
                ), array(
                    'cid[]' => $model->getState('bid.id')
                ));
                break;

// New Task
            case 'creategenre.apply2':
                $this->applyRedirection($result, array(
                    'stay',
                    'com_mycomponent.object.createobject'
                ), array(
                    'cid[]' => null
                ));
                break;


In my view.html.php
if (($isNew && $model->canCreate()) || (!$isNew && $item->params->get('access-edit')))
            CkJToolBarHelper::apply('genre.apply2', "MYCOMPONENT_JTOOLBAR_SAVE2");


The new button just fires the catchall default process in the public function save right at the end of the switch
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.

Add a new SAVE task 27 Oct 2015 15:56 #13636

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
I also tried
// Save and step
        if (($isNew && $model->canCreate()) || (!$isNew && $item->params->get('access-edit')))
            CkJToolBarHelper::custom('genre.apply2', null,null, "Save and Create object");

The program just shoots off to the default collection view.

I even tried leaveing the genre.apply2 task as a simple apply.. doesnt even do that. Its almost as though I have to register this new task somewhere for it to be accepted
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.

Add a new SAVE task 27 Oct 2015 15:57 #13637

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
Looks ok, but your task is 'creategenre.apply2', your button says 'genre.apply2'

For debugging I would print the task just before

switch($this->getLayout() .'.'. $this->getTask())
var_dump($this->getTask());
Last Edit: 27 Oct 2015 15:58 by Romkabouter.
The administrator has disabled public write access.

Add a new SAVE task 27 Oct 2015 16:22 #13638

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
The task is in the save function in the genre controller

creategenre is the layout calling the button

Here is the code output by the system (I have just left the SAVE and the custom button) and it all looks sweet.. these buttons are in the layout 'creategenre'
        <li class="btn-success input-medium btn btn-small " style="list-style:none; " id="toolbar-genre.apply" onclick="return Joomla.submitform('genre.apply');">
	<div class="" style="cursor:pointer">
	<i class="icon-apply icomoon"></i>
	<span class="text" style="white-space:nowrap">Save</span>

	</div></li>

	<li class="btn btn-small " style="list-style:none; " id="toolbar-genre.apply2" onclick="return Joomla.submitform('genre.apply2');">
	<div class="" style="cursor:pointer">
	<i class="icon- icomoon"></i>
	<span class="text" style="white-space:nowrap">Save 2</span>

	</div></li>
	</ul>

but the save function just skips over apply2.. cant match the task and just fires 'genre.default' which is the catch all..

maybe you cant fork custom tasks.. dunno.. but if you dont think that there is anything wrong, and create custom tasks should be just adding the button and adding the task in the save list, then I will just have to leave for now and do at a later time.

Maybe admin can shed some light on the custom save task not working
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.

Add a new SAVE task 27 Oct 2015 18:59 #13639

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
I am going to look into this one, I have created something similar :)
Is this wanted in frontend or backend?
Last Edit: 27 Oct 2015 19:00 by Romkabouter.
The administrator has disabled public write access.

Add a new SAVE task 27 Oct 2015 19:26 #13640

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
I do all my stuff front end where possible, don't like to give users admin access unless they are super admin

Thanks
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.

Add a new SAVE task 27 Oct 2015 21:19 #13641

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
When driving home from work, it struck me that I was thinking in the wrong direction.

The task you assign to the button ('genre.apply2') is not only a task, but has to have a corresponding function in the controller.
Apply works, because the root controller of an item (joomla) has the apply function, and calls the save function
The save function then can provide different function to the task, such as save or apply.

So, if you want to have a button with calls genre.apply2, fork the controller and add a function apply2.
You can off course copy the save function and rename it to apply2 or do some other code.

- fork the item controller of genre
- add function apply2, be sure to add key and $urlVar
public function apply2($key = null, $urlVar = null)
{
}
The administrator has disabled public write access.
The following user(s) said Thank You: MorganL

Add a new SAVE task 27 Oct 2015 21:40 #13642

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
Do you know something.. i was reading the article about creating a custom task (used an example called shout) and this is pretty much how they called it as well.

I copied the entire of save (already forked), renamed the process, stripped out all the case stuff and just left the default in.. and altered that to be my process and then added the apply2 button to the view.html.php file

and yup.. works a treat!

Well done, and thanks
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.

Add a new SAVE task 29 Oct 2015 12:21 #13645

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Thank you again Romkabouter,
K++

By the way, I would like to add that the redirector is under rewrite.
In the 'Pure' version, it will be handled in a trigger 'onAfterXxx'
Coding is now a piece of cake
The administrator has disabled public write access.
Time to create page: 0.100 seconds

Get Started