Hide Table View and Give Detail View Only

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Hide Table View and Give Detail View Only

Post by sathukorala » 2021-04-12 02:29

Is there a way to hide table view for users and only view the first or selected record of the table in detail view only?

There is a way to hide table view for a group but that doesn't let the user to view the record if he presses back or goes to home screen.
That method is putting this in hooks/tablename.php for the init function as the below code block
Wanted_Group is the group we target
tablename is the table we hide

Code: Select all

function tablename_init(&$options, $memberInfo, &$args) {

		if ($memberInfo['group'] == 'Wanted_Group') 
		{
			$options->AllowCSV = 0; 
			$options->RecordsPerPage = 1;
			$options->HideTableView = 1;
			
		}
		return TRUE;
}
But my use case is to hide or disable the access to the table and only able to view the selected record in detail view. There needs to be a link on the home page to redirect to that record.
How can we do it?

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Hide Table View and Give Detail View Only

Post by sathukorala » 2021-04-12 02:42

There is a way to put a link in the home page as AppGini default shows like
By puting this in hooks/links-home.php

Code: Select all

$homeLinks[] = array(
			'url' => 'tablename.php?SelectedID=1', 
			'title' => 'Tablename', 
			'description' => '<br/>Tablename Record',
			'groups' => array('*')
		    );

and
putting this in hooks/links-navmenu.php

Code: Select all

$navLinks[] = array(
			'url' => tablename.php?SelectedID=1', 
			'title' => 'Tablename', 
			'groups' => array('*')
			);
But how to make a user-specific "SelectedID=1" be made?
The ID is not constant as 1 always. The ID of the record which the logged in user owns is needed to be available dynamically.

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Hide Table View and Give Detail View Only

Post by sathukorala » 2021-04-12 04:40

The above got fixed
Insert below in hooks/links-home.php
The logged-in user will see only his record

Code: Select all

$memberID = getLoggedMemberID();
$recid = sqlValue("select id FROM tablename WHERE memberID = '$memberID'");

$homeLinks[] = array(
			'url' => "tablename_view.php?SelectedID=$recid", 
			'title' => 'My Record', 
			'description' => '<br/>Your own Record',
			'groups' => array('*')
		    );

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Hide Table View and Give Detail View Only

Post by sathukorala » 2021-04-12 05:40

I tried this method to hide table links for the group but it seems to be not working...
https://bigprof.com/blog/appgini/preven ... n-appgini/

Can someone correct me with this code block please (for hooks/footer-extras.php)

Code: Select all

<?php
    $mi = getMemberInfo();
    // hide the table only if the user belongs to this group
    if($mi['group'] == 'CustomerSupport') {
        ?>
        <script>$j(funtion() {
           $j('#orders-tile').remove();
           $j('.nav a[href^=orders_view]').remove();
        })</script>
        <?php
    }
?>

User avatar
ronwill
Veteran Member
Posts: 228
Joined: 2015-08-08 10:12
Location: Cheltenham UK +Weatherford USA

Re: Hide Table View and Give Detail View Only

Post by ronwill » 2021-04-14 19:19

When I want user to jump straight to a single detailed view page - bypassing the table view I add the following code to the Tablename hooks.php file:

Code: Select all

	function page_1_header($contentType, $memberInfo, &$args) {
		$header='';

		switch($contentType) {
			case 'tableview':
				header('Location: page_1_view.php?SelectedID=1');
				break;
This example takes them to record 1 - Pls note I also insert a record first, before changing the hooks file or you get an error that record does not exist. I go a bit further and also remove the back button from the detailed view...

cheers, Ron
Ron - Gloucestershire, UK: AppGini Pro V 23.15 Rev 1484 - LOVING IT!
Plugins: Mass Update + Search Page Maker + Summary Reports + Calendar + Messages
Bizzworxx: AppGiniHelper + Inline Detail View
Alejandro Landini: To-Do List + MPI + TV Field Editor
Other: Udemy Course

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Hide Table View and Give Detail View Only

Post by sathukorala » 2021-04-15 07:14

sathukorala wrote:
2021-04-12 05:40
I tried this method to hide table links for the group but it seems to be not working...
https://bigprof.com/blog/appgini/preven ... n-appgini/

Can someone correct me with this code block please (for hooks/footer-extras.php)

Code: Select all

<?php
    $mi = getMemberInfo();
    // hide the table only if the user belongs to this group
    if($mi['group'] == 'CustomerSupport') {
        ?>
        <script>$j(funtion() {
           $j('#orders-tile').remove();
           $j('.nav a[href^=orders_view]').remove();
        })</script>
        <?php
    }
?>

Can someone correct this code block please 🙏😔

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Hide Table View and Give Detail View Only

Post by jsetzer » 2021-04-15 09:32

Here you are:
Typo "funtion" instead of "function"

93mr8VBN7t.gif
93mr8VBN7t.gif (35.59 KiB) Viewed 3535 times

Once again, I strongly recommend using a state-of-the-art code editor (like VSCode [ https://code.visualstudio.com/download ]) which automatically highlights syntax errors on the fly.

When all syntax errors have been fixed but the result is unexpected, still, use more debugging like console.log("your message") or console.warn("your message") or console.error("your message") or alert("your message") or throw an exception which will stop further processing.

For example:

Code: Select all

var element = $j("#orders-tile");
if (element.length<1) throw "tile not found";
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Hide Table View and Give Detail View Only

Post by sathukorala » 2021-04-16 15:20

jsetzer wrote:
2021-04-15 09:32
Here you are:
Typo "funtion" instead of "function"


93mr8VBN7t.gif


Once again, I strongly recommend using a state-of-the-art code editor (like VSCode [ https://code.visualstudio.com/download ]) which automatically highlights syntax errors on the fly.

When all syntax errors have been fixed but the result is unexpected, still, use more debugging like console.log("your message") or console.warn("your message") or console.error("your message") or alert("your message") or throw an exception which will stop further processing.

For example:

Code: Select all

var element = $j("#orders-tile");
if (element.length<1) throw "tile not found";
Thanks Jan. You are always a lifesaver.
Please suggest a way to prevent users clicking on back button or table name on title of the detail view to go back to table view Please

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Hide Table View and Give Detail View Only

Post by sathukorala » 2021-04-17 04:08

We can remove back button by deleting <%%DESELECT_BUTTON%%> line in templates/tablename_templateDV.html
But it removes Back button for everybody.
Is there a way to remove it for a selected group only?

We can remove the Tablename link in detail view by creating a file in hooks by the name of tablename-dv.js and putting below code block

Code: Select all

$j(function() {
  $j("form > .page-header").remove()
});
But it removes Table name link at the top for everybody.
Is there a way to remove it for a selected group only?

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Hide Table View and Give Detail View Only

Post by sathukorala » 2021-04-17 06:02

With some extensive research, I found the solution to the above questions.
This solution does the following

1. Remove Table Tile and link to Table in Nav-bar for a selected Group in Home Screen
2. Make fields read-only to a selected Group
3. Remove Tablename Header link and Back button in detail view for a selected Group

Simply add the following to hooks/footer-extras.php
Selected_Group = Your group needs to be restricted
tablename = wanted table to be hidden
fieldname = wanted field to be made read-only

Code: Select all

<?php
    $mi = getMemberInfo();
    // do all the functions if the user belongs to this Selected_Group
    if($mi['group'] == 'Selected_Group') {
        ?>
        <script>
	$j(function() {
        $j('#tablename-tile').remove();
        $j('.nav a[href^=tablename_view]').remove(); 
        })
	$j(function(){
	document.getElementById("fieldname").readOnly = true;
	})
	$j(function(){
	$j("form > .page-header").hide();
	$j('#deselect').hide();
	})
	</script>
        <?php
    }
?>

Post Reply