cancel
Showing results for 
Search instead for 
Did you mean: 

JavaScript - Finding Current Site.

cedorfm
Champ in-the-making
Champ in-the-making
Hello,

I am trying to search the repository according to what site the user is currently in. There are several sites and I wan't to avoid creating a seperate webscript for each dashlet. If i had the current site, the search for a specific folder can be updated according to the current site. This would make my webscript very versatile, reusable, and would end the need for multiple webscripts.

EXAMPLE:

var currentSite = HR;

var folder = userhome.childByNamePath("/sites/" + currentSite);
6 REPLIES 6

loftux
Star Contributor
Star Contributor
Have a look at the webscripts in share, many (most?) of them support this scenario.
For client side javascript you also have a constant for this
Alfresco.constants.SITE = "currentsitename";
Do a view source to get available constants.

Once you have the site name, it has to be passed to your webscript in the repository, either as you suggested as a url template or as an argument.

cedorfm
Champ in-the-making
Champ in-the-making
Hello,

I am uncertain about what you mean by "client side javascript".

Are you refering to webscripting in Alfresco share or Alfresco explorer.

My Alfresco SHARE .js uses remote.connect() to connect to the EXPLORER webscript.

My Alfresco EXPLORER .js is as follows…


var name = "Hello "
var site = Alfresco.constants.USERNAME;

model.name = name;
model.site = site;

I get a reference error saying "Alfresco" is not defined. Bear in mind without Alfresco.constants.USERNAME   it works and prints hello just fine.

I appreciate your assistance in the matter.

cedorfm
Champ in-the-making
Champ in-the-making
Can anyone simply direct me to an example, where it's clear how to pass Alfresco.constants FROM SHARE TO DATA WEBSCRIPTS IN ALFRESCO EXPLORER.

THATS ALL I ASK.

Please and thank you.

Can anybody help, I'm new to Alfresco. I've read several pages of documentation etc… I just can't wrap my head around this concept from what i've seen in current samples.

mikeh
Star Contributor
Star Contributor
No need to shout.

It's all over our existing code, but here's some further explanation:

- all the Alfresco.constants.* are within client-side JavaScript only. By "client-side" I mean code that is run by the browser.
- you seem to be working with web-tier JavaScript, i.e. code that is run by the Rhino JS engine that we embed with Surf. In other words, running on the web server.

Without further details, it's not possible to tell exactly how you're implementing the search, but I'm presuming your user POSTs a form containing the search term to your webscript which then calls the Repository via remote.call. You need to also POST the user's current site which, as Peter pointed out, is held within Alfresco.constants.SITE. If the HTML mark-up for the form is being generated on the web server, you can populate a hidden form field with the current site using a bit of Freemarker: ${(page.url.templateArgs.site!"")?html}

Thanks,
Mike

cedorfm
Champ in-the-making
Champ in-the-making
Thank you Mike,

Sorry about that, this whole thing is just very frustrating at times.

Thank you for the reply.  Smiley Happy

cedorfm
Champ in-the-making
Champ in-the-making
So, I understand what you are trying say! Finally.

Unfortunately there is nothing in the current Surf Plateform API that will give me the Site Name, however, I can retreive the site name using the HTTP Client API.

I didn't realize webscripts were available on several plateforms. I didn't even realize there were other plateforms!

Though i did read over the Web Script Wiki. I don't know how I missed that part.  :shock: