Modifying the Detail View With a Hook

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
gmusgrave
Posts: 25
Joined: 2013-08-15 17:27
Location: Mexico

Modifying the Detail View With a Hook

Post by gmusgrave » 2013-10-10 18:41

Here's some code I want to share that gives an example of changing the display of the detail view form through a hook function.

In this case, I wanted to hide the "Print Preview" button.

This code goes in the TABLENAME_dv() function in the TABLENAME.php file in the hooks directory. This function is called after displaying the table view, and just before displaying the detail view (the comments should explain it):

Code: Select all

function TABLENAME_dv($selectedID, $memberInfo, &$html, &$args){
    // ****************************************************************
    // Remove "PRINT PREVIEW" button from the detail view editing form 
    // ****************************************************************
    // HTML for detail view PRINT PREVIEW button as generated by AppGini: 
    //		<button tabindex="2" type="submit" id="dvprint" name="dvprint_x" value="1" 
    //    	onclick="$$('form')[0].writeAttribute('novalidate', 'novalidate'); document.myform.reset(); 
    //     	return true;"><img src="print-preview.gif" /> __BUTTON LABEL TEXT__</button>
    //
    // Get the global variable for language text
    global $Translation;

    // Get the text of the button label
    $buttLabel = $Translation['Print Preview'];

    // Delete it!
    $html = str_replace("<button tabindex=\"2\" type=\"submit\" id=\"dvprint\" name=\"dvprint_x\" value=\"1\" onclick=\"$$('form')[0].writeAttribute('novalidate', 'novalidate'); document.myform.reset(); return true;\"><img src=\"print-preview.gif\" /> $buttLabel</button>","",$html);
}
This will always hide the button whenever anybody is looking at the detail view. If, however, you want to hide buttons based on specific users, you could surround this code with an if statement that tested for the class of users you don't want to see the button. For example:

Code: Select all

    if ($memberInfo['group'] == 'anonymous') {
        // Disable detail view button
        CODE FROM ABOVE GOES HERE
    }
You can use these examples to hide any buttons you want, based on user groups. You can also adapt this concept to hide certain fields in the editing form for certain groups of users.

Hope this helps someone,
Garry

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: Modifying the Detail View With a Hook

Post by toconnell » 2013-11-19 19:06

gmusgrave,

Can you help me with the hiding fields a bit? I really want to keep the normal view of my table called bus_status but I would like an alternate view for my phone users on the go. That view should be bus_move.

I would only like to show the fields 7 of the 23 fields in the table that it takes to move the bus from one location to another.

What file should be edited? Just the hook file? where you have edited yours above? The fields are bus_status.move_date, bus_status.move_reason, bus_status.move_from, bus_status.move_to, bus_status.move_authby, bus_status.yard, bus_status.county

Your help is greatly appreciated.

Thank you so much, Tina
Tina O'Connell
Web Dev & Appgini FAN

Post Reply