⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

add_action return not working



mavershim
  • profile picture
  • Member

Posted 17 April 2013 - 07:48 AM

Hi,

 

I have a condition on my add_action but everytime i look at the action column I still see the button

 

if ($this->bitauth->has_role('OLA-AO'))
        {    
            return site_url('closecases').'/'.$row->caseno.'/add';
        }
        else{
            return '';
        }

 

in my action column i always have a button and its link is always the first. how can i make the action button disapear when the condition is not met.


davidoster
  • profile picture
  • Member

Posted 18 April 2013 - 06:36 AM

This is not related to Grocery CRUD actually.

You need to check what this bitauth library is supposed to return and if you called it correctly.

So you need to check what it gives you the 

$this->bitauth->has_role('OLA-AO') part of your code.

I wish I could help you more but I haven't used the bitauth library!


mavershim
  • profile picture
  • Member

Posted 18 April 2013 - 07:44 AM

the url is changed but the button is still showing in the action column


davidoster
  • profile picture
  • Member

Posted 18 April 2013 - 08:49 AM

Ok let me explain in more detail.

You are using this format to call your callback function,

 

$crud->add_action('Photos', '', '','ui-icon-image',array($this,'just_a_test'));

 

right?

When you call this function add_action (no matter what the callback does) it will display an icon, because of the 'ui-icon-image' css definition.

If we assume that this needs to be displayed only when 

$this->bitauth->has_role('OLA-AO') == true

 

I would change your code like this 

within your controller

if ($this->bitauth->has_role('OLA-AO')) // your add_action;
    

 

and then at your callback I would just havereturn site_url('closecases').'/'.$row->caseno.'/add';

It's just a matter of logic and point of view.

 

What I said before is NOT on a per row basis. If you needed on a per row basis then this code needs to be changed.


mavershim
  • profile picture
  • Member

Posted 18 April 2013 - 08:51 AM

thanks for the reply but i'm looking on a per row basis...


davidoster
  • profile picture
  • Member

Posted 18 April 2013 - 09:04 AM

It didn't show on your original post though!

 

 

controller:

$crud->add_action('Photos', '', '','',array($this,'just_a_test'));

 

callback

/* somewhere here you need to mix and match the if statement with the $primary_key, $row data
   only like this you get on a per row definition of the returning url
   within style='' put anything you want or within class/id for the css definition
*/
if ($this->bitauth->has_role('OLA-AO') && $primary_key == 1)
        {    
            return "<a href='' class='' id='' style=''>the text you want</a>";
        }
        else{
            return "whatever you need";
        }

 

 

 


mavershim
  • profile picture
  • Member

Posted 18 April 2013 - 09:33 AM

hi davidoster,

 

thanks. but the problem with this is that it will always be enclosed on the href. grocerycrud has a default of

 

<a href=''" class=" crud-action" title="Closed"></a>   

 

so if I return something  like this

 

<a href="<a href=.... class="Closedcrud-action"><image></image></a>" " class=" crud-action" title="Closed"></a>    


davidoster
  • profile picture
  • Member

Posted 18 April 2013 - 10:01 AM

This is the first time I noticed that! I didn't suspect that you can't do it!

I was hopping that the callback allows you to completely replace the full <a /> structure.

 

Have you tried using (instead of all these) the callback_column function?

different logic but it will work!


mavershim
  • profile picture
  • Member

Posted 18 April 2013 - 10:04 AM

no but I have to recreate the action column where the other button is located (edit,..)