how to get details for current logged in user via javascript?

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • jamie
    replied
    Originally posted by rabii
    o i see so you can customise one entity's view, interesting, and yeah, i can see the use of it

    but what i was doing was a compact view for multiple entities controlled by a user-defined toggle

    at the time of posting, i think the user api endpoint on my host was stuck and was only showing the first user. After rebooting Docker, i found that it would serve the current logged-in user so i was able to use those details to turn on and off a style sheet via js

    here is how i did it

    <the call>
    Code:
    document.addEventListener('DOMContentLoaded', () => {
    Espo.loader.require('hiden:User', async function (User) {
    const myInstance = new User();
    const isCompact = await myInstance.checkIsCompact();
    if (isCompact) {
    loadCSS('client/custom/css/compact.css');
    }
    });
    });
    <the lib>
    Code:
    define('hiden:User', [], function () {
    class User {
    async checkIsCompact() {
    const response = await fetch('api/v1/App/user');
    const data = await response.json();
    return data.user.cCompactView;
    }
    }
    return User;
    });
    function loadCSS(url) {
    const link = document.createElement('link');
    link.rel = 'stylesheet';
    link.href = url;
    document.head.appendChild(link);
    }
    ​

    Leave a comment:


  • rabii
    replied
    can you share what your trying to do with your code?



    or creating a view see below

    Leave a comment:


  • jamie
    replied
    Originally posted by rabii
    If you are extending a view then you can do something as below

    PHP Code:
    this.getUser().get('teamsNames') // get the user's teams names
    this.getUser().id // get current logged in user's id
    
    const userModel = this.getUser() // this the current logged in model instance​ 
    
    no i am just doing vanilla JS. Do you know any good examples of extending a view? It's been 15 years since I worked with vanilla JS

    Leave a comment:


  • rabii
    replied
    If you are extending a view then you can do something as below

    PHP Code:
    this.getUser().get('teamsNames') // get the user's teams names
    this.getUser().id​ // get current logged in user's id
    
    const userModel = this.getUser() // this the current logged in model instance​ 
    

    Leave a comment:


  • how to get details for current logged in user via javascript?

    I am trying to get some details for the current logged-in user via JavaScript so i can make some interface changes but i can't find a way to get the id
Working...