This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Hide an object in a plan when an user is entering on it
#1
Hi all,

is anyone could purpse to me a method to Hide an object in a plan when an user is entering on it ?

A have only one plan and few users, each one have got rights or not to visualize objects.
I would to write a "js" script  (or other ?) managing this.

Many thank's in advance.

Have a good end of week.

Best regards from France.
Reply
#2
Hi,

Why don’t you just duplicate your page for each user and assing the adjusted page(s) to each user? 

It can be done by JS but it requires a .lp to detect the user, custom JS and custom classes on the objects.

Duplication is much faster to do.

BR,

Erwin
Reply
#3
(05.12.2019, 13:16)Erwin van der Zwart Wrote: Hi,

Why don’t you just duplicate your page for each user and assing the adjusted page(s) to each user? 

It can be done by JS but it requires a .lp to detect the user, custom JS and custom classes on the objects.

Duplication is much faster to do.

BR,

Erwin

Hi Erwin,

because my end customer wants to be able to assign objects to the different users. I think it is easier to propose to modify a script "js" (with "array" to manage) rather than to make several pages that it will not be able to modify easily.

BR,
Dominique.

I know it is more complex to detect the user since it requires a ".lp". I thought I'd do it by creating as many 0/1 objects as user and setting PINs. So I will have in ".js" only to detect the object and not the User.
Reply
#4
Hi,

You need to identify the user by .lp otherwise it will never work..

See this for hide by object: https://forum.logicmachine.net/showthrea...35#pid3935


BR,

Erwin
Reply
#5
Hi,

Try this:

Give each element a unique additional class like first object "hideobject_1", second object "hideobject_2" etcetera.

Run this script once to create the user.lp:
Code:
dst = '/www/user/user.lp'
io.writefile(dst, [[
<?
   require('apps')
   clientuser = request.username or 'anonymous'
   print(clientuser)
?>
]])
script.disable(_SCRIPTNAME)
Add this to your custom Javascript:
Code:
$(function(){
 
  var configtable = [
    { username:"admin", hideobject: [1,2] },
    { username:"erwin", hideobject: [1,2,3,4,5,6,7,8,9,10,11] },
  ];
 
  // Function to hide objects
  function hideObject(objnr){
    $(".hideobject_" + objnr).addClass("hide");
  }
 
  $.get("/user/user.lp", function(data, status){
    if (status === "success"){
      var username = data.trim();   
      for (var i in configtable) {
        if(username == configtable[i].username){
          for (var j in configtable[i].hideobject) {
            hideObject(configtable[i].hideobject[j]);
          }    
         }
      }
    }
  });

})
By adding the corresponding numbers hideobject_# in the hideobject array (next to the username) you can change the visibility of a object that is mapped to a user.

Have fun (:

BR,

Erwin
Reply
#6
Hi Erwan,

many thank's. I will try this...
Reply


Forum Jump: