Hide/Remove Add Button (Master/Detail)

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
johnberman
User
Posts: 210

Hide/Remove Add Button (Master/Detail)

Post by johnberman »

Hi

I have a a number of tables ie

meteor_events
lyrids2017
quadrantids2017
and so on
they all have event_id as the primary key

I also have event_comments

I have created a master detail relationship between the tables ie

Master - meteor_events - Detail event_comments - all linked on event_id
Master - lyrids2017 - Detail event_comments - all linked on event_id

and so on

Im using preview extensions so when go to say the list page for lyrids2017 I can hover the mouse over event comments and
there is the text

Loged in users can add event comments and it works

I want to remove the add event option on lyrids2017 so you can just see the comment but not add, adding will all be done
on the meteor_events

so on the lyrids2017 page whilst I want to have the event comments I want to hide the Add Option

Hope this makes sense

Regards
John Berman


mobhar
User
Posts: 11703

Post by mobhar »

johnberman wrote:
I want to remove the add event option on lyrids2017

Simply put the following code in "Page_Render" server event under "Server Events" -> "Table-Specific" -> "List Page" that belongs to "lyrids2017" table:

$this->OtherOptions['addedit'] = new cListOptions();
$this->OtherOptions['addedit']->Body = "";


johnberman
User
Posts: 210

Post by johnberman »

that did not seem to work - I have inspected the element and have this

<span class="glyphicon glyphicon-plus ewIcon" data-caption="Add" data-phrase="AddLink"></span>

So used

$this->OtherOptions['add'] = new cListOptions();
$this->OtherOptions['add']->Body = "";

That made no difference ?

John B


kirondedshem
User
Posts: 642

Post by kirondedshem »

Ive just noticed custom script section called preview page, so do the following

To hide add button from the list page of a table that is shown as a detail during preview extension fucntionality, paste same code in preview page->Page_Rendering
for example put code in preview page->Page_Rendering of event_comments table:
$this->OtherOptions["addedit"]->Items["add"]->Visible = FALSE;

To hide the add button on the "normal" list page put code in page_rendering:
for example put code in list page->Page_Rendering of event_comments table:
$this->OtherOptions["addedit"]->Items["add"]->Visible = FALSE;


johnberman
User
Posts: 210

Post by johnberman »

thanks for the tip - no success

I added the code on the list page for

lyrids2017

Preview Page \ Page Render

and added a whole host

$this->OtherOptions['Add'] = new cListOptions();
$this->OtherOptions['Add']->Body = "";
$this->OtherOptions["addedit"]->Items["add"]->Visible = FALSE;
$this->OtherOptions["add"]->Items["add"]->Visible = FALSE;
$this->OtherOptions["ewadd"]->Items["add"]->Visible = FALSE;
$this->OtherOptions["ewaddedit"]->Items["ewadd"]->Visible = FALSE;

and none had the desired effect ?

John B


kirondedshem
User
Posts: 642

Post by kirondedshem »

johnberman wrote>
I added the code on the list page for
lyrids2017
Preview Page \ Page Render

NO NO NO,
the whole preview section of the event_comments is drawn by the event_comments table events themselves and NOT by the lyrids2017 events
So add this code to the DETAIL TABLE and that means the event_comments table, NOT the master table, for example:
got to event_comments->preview page->Page_DataRendering and put
// Page Data Rendering event
function Page_DataRendering(&$header) {
// Example:
//$header = "your header";
$this->OtherOptions["addedit"]->Items["add"]->Visible = FALSE;
}

OTHER HINTS IF IT FAILS
I know you might have done this but:

  1. try to setup master/detail on an entirely different fresh set of tables(with not other customisations), you can even create a dummy project just to be sure.
  2. ensure you are generating all neccessary files after wards

And another thing
johnberman wrote>
$this->OtherOptions["ewadd"]->Items["add"]->Visible = FALSE;
$this->OtherOptions["ewaddedit"]->Items["ewadd"]->Visible = FALSE;

there are no such OtheOptions called ewadd and ewaddedit. If you want to see how one gets to determine the correct values manually, then use var_dump($this) ina certain event and take a look at how it looks and track down the correct values or sections from there:


johnberman
User
Posts: 210

Post by johnberman »

Well now I'm adding it in the right place it works a treat Thanks.

I have a number of list pages
Lyrids
Quantrids
Gemenids

And

Meteor events.

When logged in I want to remove the add option to all pages except meteor events which was why I was adding the code directly to the list pages. With your instructions it works but somehow I want the meteor events list page excluded ?

John


kirondedshem
User
Posts: 642

Post by kirondedshem »

With the previous solution we were hiding the add buttons manually irespective of if a person has the permission to do so or not.
But by default phpmaker generated page can disable or hide various options from specific users options by:

  1. disabling the add option in table settings, that way the add button wont be generated.
  2. (recomended) using userlevel permissions, as long a user belongs to a given group, you can revoke the add permission to any page and phpmaker generated pages will then not draw any add buttons as long as the user has no permission to do so, ofcourse the same applies to all other operations like edit,view etc

When logged in I want to remove the add option to all pages except meteor events which was why I was adding the code directly to the list pages. With your instructions it works but somehow I want the meteor events list page excluded ?

what is the relation with all these tables coz you dint specify, but as long as each of these tables is a detail table somewhere, doing the same thing on them should work.

Assuming you want to do this for some non administrator user's only, I suggest you disable the add options of all other tables except the meteor events table using group permissions.
NOTE:Please look at the demo project for a live example, also read help to understand how permissions work(Tutorial - Advanced Security - Dynamic User Level Security)

for example if you will have users falling under "data Entrant group" who you want to set restrictions as earlier mentioned.
-Enable advanced security and enable dynamic group permissions
-create the group called Entrant group wth specific ID
-Go to permissions of that group, then ensure that Add option is unticked for Lyrids,Quantrids,Gemenids, BUT ensure to tick add option for Meteor events

  • now every user you assign to this group wont be able to add to the three table but only to Meteor events.

you can hae as much variation as you want with this option so i recommend you do this unless there is a reason why you can use this


johnberman
User
Posts: 210

Post by johnberman »

Thanks for your patience - So I have taken the plunge and gone for Dynamic Security and then followed the advice

-Go to permissions of that group, then ensure that Add option is unticked for Lyrids,Quantrids,Gemenids, BUT ensure to tick add option for Meteor events

  • now every user you assign to this group wont be able to add to the three table but only to Meteor events.

I did the above but when on the Lyrids list page and hover over the comments box (which is the linked detail table ) I still have the option to ADD ?

Sorry about this - would make it so much easier if we could post images here

John B


kirondedshem
User
Posts: 642

Post by kirondedshem »

what is the relation with all these tables coz you dint specify
you did not mention that Lyrids,Quantrids,Gemenids are all master tables and that its not thier add buttons you want to hide, bu the add button for the detail table they display.

Say if say your detail table is called event_comments and you have setup master detail linking it as a detail to all three tables of (Lyrids,Quantrids,Gemenids) and meteor events being the master tables.

But since you say you want to allow the event_comments add button to still appear when users are on the Meteor events.

Solution 1: you can just call the previous function to hide the button in preview page based on if a user belongs to a group you dont want to allow to add to it.For example if say the user goup(userlevel) is called Data entrants with id = 3 and you dont want them to see the add button.
Add this code to the DETAIL TABLE and that means the event_comments table, NOT the master table, for example:
got to event_comments->preview page->Page_DataRendering and put
// Page Data Rendering event
function Page_DataRendering(&$header) {
// Example:
//$header = "your header";
//CurrentUserLevel() is a phpmaker generated function to get the user's current user_level ID, check help file for more
$user_level = CurrentUserLevel();
//Assumming Data entrant group has user_level id = 3
if($user_level == 3)
{
$this->OtherOptions["addedit"]->Items["add"]->Visible = FALSE;
}
}

Solution 2: You can create a view of event_comments so that the original event_comments is used for adding while the view is used for those who want to list but not add to it(they all have the same contents)

So create an editable view out of event_comments table.
for example create view vw_event_comment as select * from event_comments.
Now setup event_comment as the detail page for meteor events and ensure to enable add option in table settings,
Then setup vw_event_comment as a detail table for the other three tables(Lyrids,Quantrids,Gemenids) BUT do not enable add option in table settings(this means by default everywhere you see a list for vw_event comments it will never have an add option).

NOTE: learn how group permissions work coz you will sometimes need to put it into the logic when building multi user applications so that you know you will be able to use the same page but phpmkaer will help you hide and show add,edit,delete & view options depending on the user and you can take advantage of this to work faster.


johnberman
User
Posts: 210

Post by johnberman »

Thank you - works a treat


Post Reply