Hide fields if not group admin in -dv.js
Hide fields if not group admin in -dv.js
Hello there. Please i need some help.
I created a table named : relaties. After that i created a file hooks\relaties-dv.js
Now what i want is to disable some fields if user not in Admins group.
I created this code in the relaties-dv.js file :
new AppGiniField("rel_naam").readonly();
This is working but, it lockes also for admin. thats not what i want. Please help me.
I created a table named : relaties. After that i created a file hooks\relaties-dv.js
Now what i want is to disable some fields if user not in Admins group.
I created this code in the relaties-dv.js file :
new AppGiniField("rel_naam").readonly();
This is working but, it lockes also for admin. thats not what i want. Please help me.
Re: Hide fields if not group admin in -dv.js
There is a helper function in latest AppGini Helper Javascript Library:
Code: Select all
// file: hooks/TABLENAME-dv.js
var dv = AppGiniHelper.dv;
AppGiniHelper.getMemberID(function(memberID) {
// callback function
// here you can evaluate memberID and for example show/hide fields, tabs, ...
// under given conditions, for example: ...
if (memberID != 'admin')
dv.getFields(["field1", "field2", "field3"]).hide();
});
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.14 Revision 1665 + all AppGini Helper tools
<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 readabilityAppGini 24.14 Revision 1665 + all AppGini Helper tools
Re: Hide fields if not group admin in -dv.js
If you need to evaluate more complex conditions or perhaps do database queries first, you can do this on serverside using PHP and then conditinally write a
(pseudo-code, not tested)
In some cases it may be necessary to wait for the page being loaded completety. Especially when adressing lookups, you will have to wait for loading-complete event. AppGini Helper provides a function which fires after all elements (also lookups!) have been loaded.
Note: This is different from
<script>...</script>
into the $html
variable in TABLENAME_dv
-hook.(pseudo-code, not tested)
Code: Select all
function TABLENAME_dv(...) {
$hide_fields = true; // put your condition here;
if ($hide_fields) {
$html .= "<script>AppGiniHelper.dv.getFields(["field1", "field2", "field3"]).hide();</script>"
}
}
Code: Select all
AppGiniHelper.dv.ready(function(){
// your code here
});
jQuery(document).ready(...);
which already fires even if lookups are not yet available. At document.ready event you will not be able to adress lookups because they are not available at that moment.Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.14 Revision 1665 + all AppGini Helper tools
<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 readabilityAppGini 24.14 Revision 1665 + all AppGini Helper tools
Re: Hide fields if not group admin in -dv.js
Thanks so mutch.. That helped me out... im so happy
Re: Hide fields if not group admin in -dv.js
Is this the right way ? jsetzer?
AppGiniHelper.dv.ready(function() { //Wait to load all then
AppGiniHelper.getMemberID(function(memberID) {
// callback function
// here you can evaluate memberID and for example show/hide fields, tabs, ...
// under given conditions, for example: ...
if (memberID != 'admin')
dv.getFields(["rel_naam", "field2", "field3"]).readonly();
});
});
AppGiniHelper.dv.ready(function() { //Wait to load all then
AppGiniHelper.getMemberID(function(memberID) {
// callback function
// here you can evaluate memberID and for example show/hide fields, tabs, ...
// under given conditions, for example: ...
if (memberID != 'admin')
dv.getFields(["rel_naam", "field2", "field3"]).readonly();
});
});
Re: Hide fields if not group admin in -dv.js
(Please put code between [ code ] ... [ /code ] for better readability)
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.14 Revision 1665 + all AppGini Helper tools
<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 readabilityAppGini 24.14 Revision 1665 + all AppGini Helper tools
Re: Hide fields if not group admin in -dv.js
I cannot format your code on my smartphone, so I cannot see if there are brackets missing or syntax errors. But it looks good here.
Are you sure your table has columns field2 and field3?
Does it work or do you get errors in console?
Are you sure your table has columns field2 and field3?
Does it work or do you get errors in console?
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.14 Revision 1665 + all AppGini Helper tools
<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 readabilityAppGini 24.14 Revision 1665 + all AppGini Helper tools
Re: Hide fields if not group admin in -dv.js
Yes i have to add the othet fields also. like this
var dv = AppGiniHelper.dv;
AppGiniHelper.dv.ready(function() {
AppGiniHelper.getMemberID(function(memberID) {
// callback function
// here you can evaluate memberID and for example show/hide fields, tabs, ...
// under given conditions, for example: ...
if (memberID != 'admin')
dv.getFields(["rel_naam", "rel_adres", "rel_postcode"]).readonly();
});
});
Not errors. so looks it works like a charm. Can you please explain what you meen with :
(Please put code between [ code ] ... [ /code ] for better readability) ?
var dv = AppGiniHelper.dv;
AppGiniHelper.dv.ready(function() {
AppGiniHelper.getMemberID(function(memberID) {
// callback function
// here you can evaluate memberID and for example show/hide fields, tabs, ...
// under given conditions, for example: ...
if (memberID != 'admin')
dv.getFields(["rel_naam", "rel_adres", "rel_postcode"]).readonly();
});
});
Not errors. so looks it works like a charm. Can you please explain what you meen with :
(Please put code between [ code ] ... [ /code ] for better readability) ?
Re: Hide fields if not group admin in -dv.js
Look the screenshot..
Re: Hide fields if not group admin in -dv.js
O yes JS,
is this code also working with a user group like is Admins group:
is this code also working with a user group like is Admins group:
Code: Select all
AppGiniHelper.dv.ready(function() {
AppGiniHelper.getMemberID(function(memberID) {
// callback function
// here you can evaluate memberID and for example show/hide fields, tabs, ...
// under given conditions, for example: ...
if (memberID != 'admin')
dv.getFields(["rel_naam", "rel_adres", "rel_postcode"]).readonly();
});
});
Re: Hide fields if not group admin in -dv.js
Sure: For those who try to help you, something like this is sometimes hard to read, whan you just place code as plain text right within your question text:
If you write code between [ code ] and [ /code ] it will be formatted in a more readable way and we don't have to spend too much extra time on finding matchine closing brackets etc.. Also some basic indentation helps us reading your code.
Check out the forum docs here:
app.php/help/bbcode#f2r1
Paste your code, do indentation for bracketed sections, select your code, click the code-tool in toolbar:
The wrapping tags will be placed automatically.
The result is so much more readable and therefore we can help you better and more easily:
That's what I meant by
Please put code between [ code ] ... [ /code ] for better readability
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.14 Revision 1665 + all AppGini Helper tools
<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 readabilityAppGini 24.14 Revision 1665 + all AppGini Helper tools
Re: Hide fields if not group admin in -dv.js
No, in the code you have pasted here, there is no command for checking if current user is member of Admins-group.
Did you check? What was the result?
It should only work if user's name equals "admin".
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.14 Revision 1665 + all AppGini Helper tools
<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 readabilityAppGini 24.14 Revision 1665 + all AppGini Helper tools
Re: Hide fields if not group admin in -dv.js
Ahh oke Jan,
But is it posible to do it wen a user belongs to admin group?
But is it posible to do it wen a user belongs to admin group?
Re: Hide fields if not group admin in -dv.js
Please see my answer above:
viewtopic.php?p=18478#p18467
It becomes more complex if you want more complex conditions.
viewtopic.php?p=18478#p18467
It becomes more complex if you want more complex conditions.
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.14 Revision 1665 + all AppGini Helper tools
<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 readabilityAppGini 24.14 Revision 1665 + all AppGini Helper tools
Re: Hide fields if not group admin in -dv.js
OKe thanks jan? Greetings
Re: Hide fields if not group admin in -dv.js
Jan I have a Problem. U just also purchased, AppGiniHelper Inline. Now yesterday you advised me how to do the Read only trick for non users if the name is not admin. See below te code. That works.
Now i want to inline the fields :
Now if i paste the above line under the code above like this :
It is read only but not inline for the non admin. For the admin it is?
Please advice.
Code: Select all
AppGiniHelper.getMemberID(function(memberID) {
// callback function
// here you can evaluate memberID and for example show/hide fields, tabs, ...
// under given conditions, for example: ...
if (memberID != 'admin')
dv.getFields(["rel_nr", "rel_naam", "rel_adres", "rel_postcode", "rel_plaats"]).readonly();
});
Code: Select all
new AppGiniFields(["rel_nr", "rel_naam"]).inline("Klant", [8, 4]);
Now if i paste the above line under the code above like this :
Code: Select all
// Make fields read only for non admin
AppGiniHelper.getMemberID(function(memberID) {
// callback function
// here you can evaluate memberID and for example show/hide fields, tabs, ...
// under given conditions, for example: ...
if (memberID != 'admin')
dv.getFields(["rel_nr", "rel_naam", "rel_adres", "rel_postcode", "rel_plaats"]).readonly();
});
// Inline Fields.
new AppGiniFields(["rel_nr", "rel_naam"]).inline("Klant", [8, 4]);
Please advice.
Re: Hide fields if not group admin in -dv.js
Hello Jan,
I did this, looks like it works. Is this te right way? to inline and disable fields is user is not admin?
I did this, looks like it works. Is this te right way? to inline and disable fields is user is not admin?
Code: Select all
AppGiniHelper.dv.ready(function() {
AppGiniHelper.getMemberID(function(memberID) {
// callback function
// here you can evaluate memberID and for example show/hide fields, tabs, ...
// under given conditions, for example: ...
if (memberID != 'admin')
//dv.getFields(["rel_nr", "rel_naam", "rel_adres", "rel_postcode", "rel_plaats"]).readonly(true);
document.getElementById("rel_nr").disabled = true;
document.getElementById("rel_naam").disabled = true;
document.getElementById("rel_adres").disabled = true;
document.getElementById("rel_postcode").disabled = true;
document.getElementById("rel_plaats").disabled = true;
});
});
var dv = AppGiniHelper.dv;
dv.addGroup("Private gegevens", "Informatie", ["rel_nr", "rel_naam", "rel_adres", "rel_postcode", "rel_plaats"], Variation.primary);
Re: Hide fields if not group admin in -dv.js
Javascript: if there is more than one command you will need curly brackets.
Code: Select all
if (condition) {
// ....
// ....
// ....
}
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.14 Revision 1665 + all AppGini Helper tools
<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 readabilityAppGini 24.14 Revision 1665 + all AppGini Helper tools
Re: Hide fields if not group admin in -dv.js
Thanks Jan it works like a charm.,
Greetings,
Greetings,
-
- Veteran Member
- Posts: 101
- Joined: 2019-05-26 18:38
Re: Hide fields if not group admin in -dv.js
Hi Jan. This works great, but I'm having trouble figuring out to add more than just != to admin. Can you tell me how to extend this? For instance, I want to include not only admin, but managers, and special. Lastly, is there a way to also hide the desired fields in the associated Table View as well?jsetzer wrote: ↑2021-12-09 14:06There is a helper function in latest AppGini Helper Javascript Library:
Code: Select all
// file: hooks/TABLENAME-dv.js var dv = AppGiniHelper.dv; AppGiniHelper.getMemberID(function(memberID) { // callback function // here you can evaluate memberID and for example show/hide fields, tabs, ... // under given conditions, for example: ... if (memberID != 'admin') dv.getFields(["field1", "field2", "field3"]).hide(); });
Thank you,
David
Re: Hide fields if not group admin in -dv.js
Good morning David!
(2) hiding columns of TV using AppGini Helper Javascript Library
Single column
Multiple columns
(2) hiding columns of TV using AppGini Helper Javascript Library
Single column
Code: Select all
// file: hooks/TABLENAME-tv.js
jQuery(document).ready(function () {
AppGiniHelper.TV.hide("columnname")
});
Code: Select all
// file: hooks/TABLENAME-tv.js
jQuery(document).ready(function () {
AppGiniHelper.TV.hide(["columnname_1", "columnname_2", "columnname_x"])
});
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.14 Revision 1665 + all AppGini Helper tools
<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 readabilityAppGini 24.14 Revision 1665 + all AppGini Helper tools
Re: Hide fields if not group admin in -dv.js
(1) Conditionally execute javascript
If you want to conditionally execute javascript functions on client side, obviously you need some data in javascript variables. AppGini provides a serverside function for retrieving the current user's name. I can call this serverside function from clientside javascript and so I can provide the user's login. Unfortunately there is no built-in serverside function for retrieving other information like the current user's group. If we need more data on client side, we can use AJAX for dynamically fetching data from server into client.
A while ago I have written a library named "AppGini Helper Bridge" for my own needs which makes it easy to interact with serverside hooks. The library contains a PHP script for serverside processing and and a Javascript for clientside processing.
Check out the following example for table named "files". There is a one-time initialization. Then, on client side we connect to the table "files" and write corresponding functions in serverside PHP hook and in clientside Javascript hook.
Step 1 / PHP - Initialization in hooks/header-extras.php
This is only needed once.
Step 2 / PHP- Serverside PHP hook in hooks/files.php
New PHP function named
Step 3 / Javascript - Clientside Javascript hook in hooks/files-dv.js
This is the console output:
You can see that the client retrieves exactly the same array data which I have returned from the PHP hooks function. This is very powerful.
Now I can use the return value for conditionally hiding fields, activating tabs, adding buttons or whatever I need. I don't have to care for any AJAX calls, because the lib does that job for me. So, it's only little code for full client-server interaction.
Some details
If you are or someone else is interested in this library, please contact me: mailto:[email protected]
If you want to conditionally execute javascript functions on client side, obviously you need some data in javascript variables. AppGini provides a serverside function for retrieving the current user's name. I can call this serverside function from clientside javascript and so I can provide the user's login. Unfortunately there is no built-in serverside function for retrieving other information like the current user's group. If we need more data on client side, we can use AJAX for dynamically fetching data from server into client.
A while ago I have written a library named "AppGini Helper Bridge" for my own needs which makes it easy to interact with serverside hooks. The library contains a PHP script for serverside processing and and a Javascript for clientside processing.
Check out the following example for table named "files". There is a one-time initialization. Then, on client side we connect to the table "files" and write corresponding functions in serverside PHP hook and in clientside Javascript hook.
Step 1 / PHP - Initialization in hooks/header-extras.php
This is only needed once.
Code: Select all
AppGiniHelperBridge::init();
Step 2 / PHP- Serverside PHP hook in hooks/files.php
New PHP function named
files_getGroupInfo
:
- "
files
" equals the table name - Underscore "_"
- function name, here "
getGroupInfo
"
Everything except generated functions (reserved function names) like files_init, files_after_insert, ...
Code: Select all
function files_getGroupInfo($args)
{
return [
"groupName" => getMemberInfo("group"),
"groupID" => getLoggedGroupID(),
];
}
Step 3 / Javascript - Clientside Javascript hook in hooks/files-dv.js
Code: Select all
AppGiniHelper.Bridge.connect("files").execute("getGroupInfo");
function files_getGroupInfo(data) {
console.log("Response:", data.response);
}
You can see that the client retrieves exactly the same array data which I have returned from the PHP hooks function. This is very powerful.
Now I can use the return value for conditionally hiding fields, activating tabs, adding buttons or whatever I need. I don't have to care for any AJAX calls, because the lib does that job for me. So, it's only little code for full client-server interaction.
Some details
- The library allows multiple hook-calls
Code: Select all
AppGiniHelper.Bridge .connect("files") .execute("getGroupInfo") .execute("alert_username") .execute("getNumberOfFiles");
- You can pass arguments from client to server and evaluate in PHP hooks function
Code: Select all
var payload = { a: 1, b: "test", c: jQuery("#id").val() } AppGiniHelper.Bridge .connect("files") .execute("getGroupInfo", payload);
- There is a debugmode which will help you:
Code: Select all
AppGiniHelper.Bridge.debug = true;
- You can pass a javascript function as 3rd parameter (instead of writing a separate function having the same function name)
Code: Select all
AppGiniHelper.Bridge .connect("files") .execute("getNumberOfFiles", { x: 1 }, function (data) { console.log(data); });
If you are or someone else is interested in this library, please contact me: mailto:[email protected]
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.14 Revision 1665 + all AppGini Helper tools
<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 readabilityAppGini 24.14 Revision 1665 + all AppGini Helper tools
-
- Veteran Member
- Posts: 101
- Joined: 2019-05-26 18:38
Re: Hide fields if not group admin in -dv.js
Good morning Jan and thank you very much for the quick reply. That answers the Table View question, but can you help me with the Detail View question being how can I properly add more than just the 'admin'? I'm attaching a screen shot as well, and thanks again for your help.jsetzer wrote: ↑2022-01-17 07:37Good morning David!
(2) hiding columns of TV using AppGini Helper Javascript Library
Single column
Multiple columnsCode: Select all
// file: hooks/TABLENAME-tv.js jQuery(document).ready(function () { AppGiniHelper.TV.hide("columnname") });
Code: Select all
// file: hooks/TABLENAME-tv.js jQuery(document).ready(function () { AppGiniHelper.TV.hide(["columnname_1", "columnname_2", "columnname_x"]) });
David
Re: Hide fields if not group admin in -dv.js
Code: Select all
if (memberID != 'admin' && memberID != 'batman') {
// ...
}
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.14 Revision 1665 + all AppGini Helper tools
<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 readabilityAppGini 24.14 Revision 1665 + all AppGini Helper tools
-
- Veteran Member
- Posts: 101
- Joined: 2019-05-26 18:38
Re: Hide fields if not group admin in -dv.js
Awesome Jan!jsetzer wrote: ↑2022-01-17 16:59Code: Select all
if (memberID != 'admin' && memberID != 'batman') { // ... }
Thanks again,
David