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

TOPIC: duplicate instead of new

duplicate instead of new 19 Oct 2012 06:26 #4655

Hi,

First of all congratulations with jcook. It is fantastic to start !!
I am used to code components, and this way speeds a lot the beginning. But now it is a little more complicated to me because i am not familiar with the code.

My problem is the following:
I did a frontend collection and a frontend item. It works fine for editing, delete and create a new one.
On the grid of the collection i did a button (just like the edit one) to 'replicate'. I want to create a new component but using some values of the selected item (not all of them).

So in the grid i use:
task' => "samplesitem.replicate",

then in the controller i do:
public function replicate()
	{
            JRequest::setVar('replicate', 'yes' );
            $this->applyRedirection($result, array(
					'com_samplestracking.samplesitem.samplesitem',
					'com_samplestracking.samplesitem.samplesitem'
				), array(
					'cid[]' => $model->getState('samplesitem.id')
				));
            return true;
        }

Then i arrive to the view.html.php that is where i have problems
                $this->item		= $item		= $this->get('Item');
                $this->form		= $form		= $this->get('Form');
               if ($replicate == 'yes'):
                    $item_backup = $item;                   
                    $this->state->set('samplesitem.id', '0');
                    $item = $this->get('Item');             
                    $item->sample = $item_backup->sample;
                    $item->sample_code = $item_backup->sample_code;
                    $this->item	= $item;
                    $this->form		= $form		= $this->get('Form');
                endif;
I try everything but the form always appear with all ancient parameters or just like a brand new !
There is any way to add ceratin values to the form or to do what i am doing ore easily ?

thanks in advance
Last Edit: 24 Oct 2012 07:52 by JoomGuy. Reason: added code tags
The administrator has disabled public write access.

Re: duplicate instead of new 19 Oct 2012 11:25 #4675

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Did you tried 'save as copy' task ?

If you want to create a new task button, follow here :
j-cook.pro/forum/7-design-your-applicati...ems-in-grid?limit=10
Coding is now a piece of cake
Last Edit: 19 Oct 2012 11:25 by admin.
The administrator has disabled public write access.

Re: duplicate instead of new 19 Oct 2012 12:37 #4677

Hi
i could use save as a copy, but still i need to change something
in fact i have 2 select box and 2 textfields,
and i want
new selectbox a <- old selectbox b
new selectbox b <- empty
new textfield a <- old textfield a
new textfield b <- empty

How could i do it by using copy as new !?
The administrator has disabled public write access.

Re: duplicate instead of new 19 Oct 2012 12:56 #4678

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
You did well, but do it in the save() function.

Write in the correct switch() context (layout + task)

The vars you must set in the redirector are filter_myfk1, filter_myfk2, ...
Coding is now a piece of cake
The administrator has disabled public write access.

Re: duplicate instead of new 22 Oct 2012 12:33 #4691

Hi,

Sorrry to disturb, but something it is not working !

i repeat again the problem:
i have a table named samples with the following variables:
id (integer)
sample (text)
samplecode (text)
exchange_date (date)
origin_id (select box)
destination_id (select box)

I did a collection view, an item view, edit, delete, etc.. everything fine !

On the grid view i want an icon (or text) on each line to create a new entry taking some values of the selected item on the following way:
sample = old sample
samplecode = old samplecode
exchange_date = empty
origin_id = old destination_id
destination_id = empty
so i want to take this values and to display the item view in edit mode to fullfil the date, destination,etc..

so, i tried everything, it must be simple but it doesn't work !

I followed the link you passed to me:
on the item controller:
public function duplicate()
        {
                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;
                
		$result = parent::save();
                //Catch the initializated JModel trough postSaveHook()
                $model = $this->model;

                //Define the redirections
                switch($this->getLayout() .'.'. $this->getTask())
                {
                        case 'samplesitem.duplicate':
                                $this->applyRedirection($result, array(
                                        'com_samplestracking.samplesitem.samplesitem',
                                        'com_samplestracking.samplesitem.samplesitem'
                                ), array(
                                    'cid[]' => $model->getState('samplesitem.id')
                                    //'filter_some_id' => $model->getState('yourcurrentlayoutname.id')
                                ));
                        break;	
                }
        }

I CREATE THE SUBMIT - in administrator/components/com_yourcomponent/dom/html/toolbar/button.php

and TASK SWITCH - create case for the custom button
in administrator/components/com_yourcomponent/dom/dom.php

and i obtain blank

on the other hand i try to work as you advice me on the save case, but i do not arrive there easily, and on the other hand i can't modify fields.

Sorry to derange you, but it should be easy, but i do not know how.
In case i do not solve, i will do a separate view with home made code !! but it is a pity having your powerful structure already done.

thanks in advance
Last Edit: 24 Oct 2012 07:52 by JoomGuy. Reason: added code tags
The administrator has disabled public write access.

Re: duplicate instead of new 22 Oct 2012 12:49 #4692

I forgot to tell you that by using on the default grid:
<td style="text-align:center">
					<?php echo JDom::_('html.grid.task.task', array(
											'num' => $i,
											'task' => "samplesitem.save2copy",
											'label' => "SAMPLESTRACKING_JTOOLBAR_EDIT",
											'view'	=> "icon"
												));
					?>
			</td>

it makes a good copy, but i do not know where and how to modify the variables. I tried on the save fucntion as you said by doing a :
if ($this->getTask() == 'save2copy'):
                    $item->samplecode = 'Test value';
                endif;

before the save, but it never takes the correct value !
always remain the old one !

public function save()
	{
		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;
              
                if ($this->getTask() == 'save2copy'):
                    $item->samplecode = 'Test value';
                endif;
                
		$result = parent::save();
		//Catch the initializated JModel trough postSaveHook()
		$model = $this->model;

		//Define the redirections
		switch($this->getLayout() .'.'. $this->getTask())
		{
			case 'samplesitem.save':
				$this->applyRedirection($result, array(
					'com_samplestracking.samplesitem.samplesitem',
					'com_samplestracking.samples.default'
				), array(
					'cid[]' => null
				));
				break;

			case 'samplesitem.apply':
				$this->applyRedirection($result, array(
					'com_samplestracking.samplesitem.samplesitem',
					'com_samplestracking.samplesitem.samplesitem'
				), array(
					'cid[]' => $model->getState('samplesitem.id')
				));
				break;
                                                             
		}
                
                
	}
This could be a good option too

regards,
Albert
Last Edit: 24 Oct 2012 07:50 by JoomGuy. Reason: added code tags
The administrator has disabled public write access.

Re: duplicate instead of new 24 Oct 2012 07:43 #4704

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Can you please use the 'code' and 'quotes' tags for lisibility ?

You will get more answers from the community ;-) if it is more understandable.

Thanks
Coding is now a piece of cake
The administrator has disabled public write access.

Re: duplicate instead of new 24 Oct 2012 07:54 #4707

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
I was interested in this thread so added the code tags as @admin suggested.

@robertocook - I think you'll agree it's now far easier to read right?

Hope it helps,

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: admin

Re: duplicate instead of new 24 Oct 2012 08:01 #4711

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Can you keep it in stand by a little bit ?

Because I realize it is not so easy to add a simple task in JDom.
I want to simplify it in Cook, and then to give you a good explanation.
Can you wait few days please ?
Coding is now a piece of cake
The administrator has disabled public write access.

Re: duplicate instead of new 24 Oct 2012 11:11 #4713

thanks to both of you !
i will wait for a few days !!
The administrator has disabled public write access.

Re: duplicate instead of new 02 Nov 2012 11:02 #4922

any new?
The administrator has disabled public write access.

Re: duplicate instead of new 02 Nov 2012 11:05 #4923

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Have you seen @BTB3000's post on creating a custom task button?

If not, check it out here: www.j-cook.pro/forum/7-design-your-appli...i-items-in-grid#4467

Hope it helps!

Good luck,

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: duplicate instead of new 02 Nov 2012 16:48 #4945

Yes i did, but it did not work. In fact admin told us that it was not so easy and that he would prepare a tutorial or so.
The administrator has disabled public write access.

Re: duplicate instead of new 02 Nov 2012 16:51 #4948

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Sure, I saw admins message in the thread.

I believe that the code is all fine - what were your errors?

@admin was referring to creating a JDom class to be able to handle the rendering of a custom button as opposed to stating that BTB300's tutorial didn't work.
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: duplicate instead of new 02 Nov 2012 20:26 #4965

You can see my problem on my posts. But basically is that via save2copy or wharever i havs to copy the selected item but changing some values. And i can't acces to modify it.

I also tried doing a diferent task, but i can't modify the values to save neither the values that appear on the form.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 0.161 seconds

Get Started