cancel
Showing results for 
Search instead for 
Did you mean: 

why is me.isAdmin not working?

jriker1
Champ in-the-making
Champ in-the-making
I am trying to update Alfresco/root/projects/slingshot/source/web/components/site-members/site-members.js as below


if (me.isAdmin)
//         if (me.options.currentUserRole !== undefined &&
//             me.options.currentUserRole === "SiteManager")
         {
             this.isCurrentUserSiteAdmin = true;
         }

Will include the SiteManager piece also however for testing just took it out. As a system admin I do not have the ability to edit user's roles in a site so it doesn't seem to be honoring the isAdmin piece like it does in other JS files.  Am I doing something wrong?

Thanks.

JR


Note:  Also should be noted that I do not get any javascript errors on the page with this so it seems it thinks it's a valid object/method maybe.
4 REPLIES 4

mikeh
Star Contributor
Star Contributor
That's client-side JavaScript, so unless you've passed the value in it doesn't have access to any "isAdmin" property. the usual "Share" way of doing this is to add it to the setOptions call in the Freemarker template and pick it up in the JavaScript from there ("me.options.isAdmin").

The reason the code isn't failing is because it's just being returned as "undefined" and so the if statement fails.

Thanks,
Mike

jriker1
Champ in-the-making
Champ in-the-making
That's client-side JavaScript, so unless you've passed the value in it doesn't have access to any "isAdmin" property. the usual "Share" way of doing this is to add it to the setOptions call in the Freemarker template and pick it up in the JavaScript from there ("me.options.isAdmin").

The reason the code isn't failing is because it's just being returned as "undefined" and so the if statement fails.

Thanks,
Mike

Thanks for the reply Mike.  Don't see a lot on the setOptions value for FreeMarker in any documentation however here is my thought.  Let me know if it's right before I recompile and push to the dev server for testing.

1. Edit Alfresco/root/projects/slingshot/config/alfresco/site-webscripts/org/alfresco/components/site-members/site-members.get.html.ftl and add to the top:

<#assign areAdmin = (user.name=='admin') />

2. In same file add

isAdmin: areAdmin,
or maybe
isAdmin: ${areAdmin},

after


<script type="text/javascript">//<![CDATA[
   new Alfresco.SiteMembers("${args.htmlid}").setOptions(
   {
      siteId: "${page.url.templateArgs.site!""}",
      currentUser: "${user.id}",
      currentUserRole: "${currentUserRole}",

Then reference it from the site-members.js as you say.

Let me know if I got this right or am off base.   

Thanks

JR

mikeh
Star Contributor
Star Contributor
Why not just
<script type="text/javascript">//<![CDATA[
   new Alfresco.SiteMembers("${args.htmlid}").setOptions(
   {
      siteId: "${page.url.templateArgs.site!""}",
      currentUser: "${user.id}",
      currentUserRole: "${currentUserRole}",
      isAdmin: ${user.isAdmin?string}
      …

Mike

jriker1
Champ in-the-making
Champ in-the-making
Mike, that was the ticket.  Only had to add a comma to the end of your line.  The reason I didn't do it that way is I can't find any good documentation to explain what I was supposed to use in this case to pull the information I needed.  Any ideas where I should be looking?

Thanks.

JR