Set Lookup field to open parent on Table View

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Set Lookup field to open parent on Table View

Post by DevGiu » 2016-09-13 12:10

I'm a little surprised this can't be done, because AFAIR (maybe I was drunk or something lol) I saw it somewhere.

Is not possible to set a lookup field, to open parent record from a related table view?
/Giuseppe
Professional Outsourcing Services

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Set Lookup field to open parent on Table View

Post by grimblefritz » 2016-09-14 13:13

On the road with my Chromebook, so can't check it, but I'm pretty sure there's an option to allow that.

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Set Lookup field to open parent on Table View

Post by a.gneady » 2016-09-14 14:04

Is this what you mean?
2016-09-14_1601.png
2016-09-14_1601.png (22.67 KiB) Viewed 10949 times
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: Set Lookup field to open parent on Table View

Post by DevGiu » 2016-09-14 14:09

Yes, but this is the link in detail view, Im talking about table view
/Giuseppe
Professional Outsourcing Services

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Set Lookup field to open parent on Table View

Post by grimblefritz » 2016-09-14 14:13

Ah, I misread your original question. Nope, don't think so, but you could use tablename_init() or tablename-dv.js to do it. Or should I say, I THINK you can.

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: Set Lookup field to open parent on Table View

Post by DevGiu » 2016-09-14 14:19

Maybe seting Up to no link, and wrapping on an "a" tag. Could be better to allow to open in modal and so on, like options for detail view, but meanwhile is a solution
/Giuseppe
Professional Outsourcing Services

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Set Lookup field to open parent on Table View

Post by grimblefritz » 2016-09-14 14:42

Ahmad can probably give you the secret sauce for opening modal.

Noha Eshra
Moderator
Posts: 82
Joined: 2013-11-11 19:21

Re: Set Lookup field to open parent on Table View

Post by Noha Eshra » 2016-09-19 14:55

We plan to support this in future releases. For now, you could do it via hooks by first disabling the link (from the "Link options" dialog in your screenshot above, select "No action"). After generating the application, modify the query using the tablename_init hook to wrap the display text in an anchor tag <a href ... Please refer to this article on how to modify the table view query, https://bigprof.com/appgini/tips-and-tu ... sing-hooks

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: Set Lookup field to open parent on Table View

Post by DevGiu » 2016-09-21 15:43

I'm trying and I had to do something like this to detect the field (too ugly)

Code: Select all

		$old_options = $options->QueryFieldsTV;
		foreach($old_options as $field => $caption){
			/* Keep all fields as-is except for the phone field */
			if($field == "IF(CHAR_LENGTH(`entidad1`.`ref`) || CHAR_LENGTH(`entidad1`.`nombreComercial`), CONCAT_WS('',`entidad1`.`ref`, '-', `entidad1`.`nombreComercial`), '') /* Entidad */"){
				/* Display only the first four digits of the phone field */
				$new_options["CONCAT('<a href=\'entidad_view.php?SelectedID=\'', `entidad1`.`id`, '\'>',`entidad1`.`nombreComercial`,'</a>')"] = $caption;
			}else{
				/* Keep all other fields as-is */
				$new_options[$field] = $caption;
			}

			$options->QueryFieldsTV = $new_options;
		}
And is not changed anyway
t1YeTzoWCF.png
t1YeTzoWCF.png (44.58 KiB) Viewed 10901 times
Some idea?
/Giuseppe
Professional Outsourcing Services

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Set Lookup field to open parent on Table View

Post by grimblefritz » 2016-09-21 16:08

I'll toss this out, as I've been thinking of trying it, but haven't had the time.

https://github.com/tburry/pquery

If I'm understanding correctly, this allows HTML to be processed on the server side, in much the same was jquery does on the client side.

Utilized in the functions that have $html passed to them (that is, the html of the page), it looks as if it would provide a nice way to munge the generated html.

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: Set Lookup field to open parent on Table View

Post by DevGiu » 2016-09-22 07:17

Yes, looks interesting, the problem is we need something like a on_record hook, because you can't use this lib to parse every field and guess where have to link.

Meanwile we don't have an on_record hook, solution could be like explained, but is half-working (probably because I did some mistake)
/Giuseppe
Professional Outsourcing Services

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: Set Lookup field to open parent on Table View

Post by DevGiu » 2016-09-22 18:39

Ok, now it works with a direct link,

Code: Select all

$new_options["CONCAT('<a href=\'entidad_view.php?SelectedID=', `entidad1`.`id`, '\'>',`entidad1`.`nombreComercial`,'</a>')"] = $caption;
but I'm trying to change the behaviour to an onclick event on a tag, trying to pass a param, but I always fail in something, and "a" seems not builded correctly

This, on SQL works.

Code: Select all

select CONCAT('<a href=\'#\' onClick=\'openDetailModal(\"entidad\",' , `entidad1`.`id`, ');return false;\'>',`entidad1`.`nombreComercial`,'</a>') from bla bla bla

<a href='#' onClick='openModal("entidad",2);return false;'>My Company Name</a>
But something happens if I use this CONCAT in my code.

Code: Select all

$new_options["CONCAT('<a href=\'#\' onclick=\"javascript:openDetailModal(\'entidad\',' , `entidad1`.`id`, ');return false;\">',`entidad1`.`nombreComercial`,'</a>')"] = $caption;
My a tag is builded without onclick part, and my queryfieldsTV is ok apparently

Code: Select all

[CONCAT('<a href=\'#\' onclick="javascript:openDetailModal(\'entidad\',' , `entidad1`.`id`, ');return false;">',`entidad1`.`nombreComercial`,'</a>')] => entidad_id
If I take this concat and use it on my SQL tool, the output is as expected.

Code: Select all

select CONCAT('<a href=\'#\' onclick="javascript:openDetailModal(\'entidad\',' , `entidad1`.`id`, ');return false;">',`entidad1`.`nombreComercial`,'</a>') from bla bla bla

<a href='#' onclick="javascript:openDetailModal('entidad',2);return false;">My Company Name</a>
Seriously, I'm booking in the madhouse
/Giuseppe
Professional Outsourcing Services

thecomputerchap
Veteran Member
Posts: 47
Joined: 2016-08-28 10:37

Re: Set Lookup field to open parent on Table View

Post by thecomputerchap » 2016-10-14 23:19

DevGiu wrote:Ok, now it works with a direct link,

Code: Select all

$new_options["CONCAT('<a href=\'entidad_view.php?SelectedID=', `entidad1`.`id`, '\'>',`entidad1`.`nombreComercial`,'</a>')"] = $caption;
but I'm trying to change the behaviour to an onclick event on a tag, trying to pass a param, but I always fail in something, and "a" seems not builded correctly

This, on SQL works.

Code: Select all

select CONCAT('<a href=\'#\' onClick=\'openDetailModal(\"entidad\",' , `entidad1`.`id`, ');return false;\'>',`entidad1`.`nombreComercial`,'</a>') from bla bla bla

<a href='#' onClick='openModal("entidad",2);return false;'>My Company Name</a>
But something happens if I use this CONCAT in my code.

Code: Select all

$new_options["CONCAT('<a href=\'#\' onclick=\"javascript:openDetailModal(\'entidad\',' , `entidad1`.`id`, ');return false;\">',`entidad1`.`nombreComercial`,'</a>')"] = $caption;
My a tag is builded without onclick part, and my queryfieldsTV is ok apparently

Code: Select all

[CONCAT('<a href=\'#\' onclick="javascript:openDetailModal(\'entidad\',' , `entidad1`.`id`, ');return false;">',`entidad1`.`nombreComercial`,'</a>')] => entidad_id
If I take this concat and use it on my SQL tool, the output is as expected.

Code: Select all

select CONCAT('<a href=\'#\' onclick="javascript:openDetailModal(\'entidad\',' , `entidad1`.`id`, ');return false;">',`entidad1`.`nombreComercial`,'</a>') from bla bla bla

<a href='#' onclick="javascript:openDetailModal('entidad',2);return false;">My Company Name</a>
Seriously, I'm booking in the madhouse
Devgiu, I'm trying to fix this too. I've noticed that if I place escape characters in the CONCAT string i.e...

$new_options["CONCAT('<a href=\"#\" \o\n\C\l\i\c\k=\"openDetailModal(\'invoices\',' , `attendance`.`invoiceno`, ');return false;\">',`attendance`.`invoiceno`,'</a>')"] = $caption;

I am getting...

<a href="#"
Click="openDetailModal('invoices',100);return false;">100</a></td>

Something somewhere is replacing the 'o' with a newline! Perhaps something to do with security to prevent SQL Injection.

I'll keep working on it.

thecomputerchap
Veteran Member
Posts: 47
Joined: 2016-08-28 10:37

Re: Set Lookup field to open parent on Table View

Post by thecomputerchap » 2016-10-15 01:35

Hi DevGiu,

I've managed to fix this problem now. But I'm a bit confused as there is no built-in js function called openDetailModal(). Is this a function that you have written? If so I'd love to have a copy of the code so I can get the Modal link working on my install too!

Anyway, this is the only way I could fix it - and I had to do it this way in order to bypass the code that strips the onClick tag. Here's what I did...

I edited tablename_init() and completely removed the method described above, e.g...

$old_options = $options->QueryFieldsTV;
foreach($old_options as $field => $caption){
/* Keep all fields as-is except for the phone field */
if($field == "IF(CHAR_LENGTH(`entidad1`.`ref`) || CHAR_LENGTH(`entidad1`.`nombreComercial`), CONCAT_WS('',`entidad1`.`ref`, '-', `entidad1`.`nombreComercial`), '') /* Entidad */"){
/* Display only the first four digits of the phone field */
$new_options["CONCAT('<a href=\'entidad_view.php?SelectedID=\'', `entidad1`.`id`, '\'>',`entidad1`.`nombreComercial`,'</a>')"] = $caption;
}else{
/* Keep all other fields as-is */
$new_options[$field] = $caption;
}

$options->QueryFieldsTV = $new_options;
}

And I replaced it with...

//Modify the Table View Template on-the-fly so that it includes the onClick event even after being overwritten
$NormalLink = "<%%VALUE(id)%%>";
$NewLink = "<a href='#' onclick=\"javascript:openDetailModal('entidad',<%%VALUE(id)%%>);return false;\"><%%VALUE(id)%%></a>";
//Read the template file contents
$str=file_get_contents('templates/tablename_templateTV.html'); //You need to change 'tablename_templateTV.html' to your table name
//Replace the normal link if it exists with the onClick version
$str=str_replace("$NormalLink", "$NewLink",$str);
//Write the changes to the server
file_put_contents('templates/attendance_templateTV.html', $str);

The template file itself is tiny so there is hardly any server load using this method. And the great thing is that even when you regenerate the template file via AppGini, it always gets updated on the server when you view the table.

Now, about that openDetailModal() code!... ;)

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: Set Lookup field to open parent on Table View

Post by DevGiu » 2016-10-15 10:22

Thanks for share ;)

Today is my kid birthday and probably i will not not open my laptop, but I will test and share ASAP
/Giuseppe
Professional Outsourcing Services

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: Set Lookup field to open parent on Table View

Post by DevGiu » 2016-10-16 17:22

thecomputerchap wrote:
$new_options["CONCAT('<a href=\"#\" \o\n\C\l\i\c\k=\"openDetailModal(\'invoices\',' , `attendance`.`invoiceno`, ');return false;\">',`attendance`.`invoiceno`,'</a>')"] = $caption;

I am getting...

<a href="#"
Click="openDetailModal('invoices',100);return false;">100</a></td>

Something somewhere is replacing the 'o' with a newline! Perhaps something to do with security to prevent SQL Injection.

I'll keep working on it.
You get the new line because \n from "onClick"

Your other code, looks great first time, problem is, as you can see, if you refresh several times your page :D

About my functions, is not tested yet, but looks something like:
Idea is to call createModalForTVView() once in your init table hook (in TV view mode)

Code: Select all

function createModalForTVView(){
	?>
			<div class="modal fade" >
				<div class="modal-dialog modal-lg">
					<div class="modal-content" >
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal">&times;</button>
							<h4 class="modal-title">Mi modal</h4>
						</div>
						<div class="modal-body">

							<div class="loading">Please wait</div>
						<iframe src="" frameborder="0"></iframe>

						</div>
					</div>

				</div>
			</div>
			<script>
				function openDetailModal(table, selectedid, title){
					$j('.modal').on('shown.bs.modal',function(){
							$j(this).find('iframe').attr({
							src: table + '_view.php?SelectedID=' + selectedid + "&Embedded=1",
							width: '100%'
						});
					});
				}
			</script>
	<?php
}
/Giuseppe
Professional Outsourcing Services

Post Reply