Logic Machine Forum
Hide an object in a plan when an user is entering on it - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Hide an object in a plan when an user is entering on it (/showthread.php?tid=2381)



Hide an object in a plan when an user is entering on it - SigmaTec - 05.12.2019

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.


RE: Hide an object in a plan when an user is entering on it - Erwin van der Zwart - 05.12.2019

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


RE: Hide an object in a plan when an user is entering on it - SigmaTec - 05.12.2019

(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.


RE: Hide an object in a plan when an user is entering on it - Erwin van der Zwart - 05.12.2019

Hi,

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

See this for hide by object: https://forum.logicmachine.net/showthread.php?tid=702&pid=3935#pid3935


BR,

Erwin


RE: Hide an object in a plan when an user is entering on it - Erwin van der Zwart - 05.12.2019

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


RE: Hide an object in a plan when an user is entering on it - SigmaTec - 06.12.2019

Hi Erwan,

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