cancel
Showing results for 
Search instead for 
Did you mean: 

problem of linking a javascript to a webscript

seraphon
Champ in-the-making
Champ in-the-making
Hi

I ve wanted to put a copy of the files used for the new myspace webscript in the Alfresco space webscripts extension so that I could do some customisation to those files while keeping the originals untouched.
I though that the myspace webscript was a good start to see how to do a custom GUI for Alfresco.
So I ve created the subspaces org/alfresco/sample/test in webscripts extension and I put the following files in it
myspaces2.get.desc.xml
myspaces2.get.html.ftl
myspaces2.js
myspaces_preview_panel2.ftl
myspacespanel2.get.desc.xml
myspacespanel2.get.html.ftl
myspaces-webscript2.jsp
After updating in these files the new file's names I did the update webscript service and thus I got 42 webscript detected.

When I went to http://localhost:8080/alfresco/wcs/sample/myspaces2

I got the page myspaces but without the icons for the spaces or content.
I think it must be because I ve put a wrong path in myspaces2.get.html.ftl in order to integrate myspaces2.js

<script type="text/javascript" src="/org/alfresco/sample/test/myspaces2.js"></script>

Can someone please tell me what I should put? I ve tried a lot of different path but I seem to misunderstand something
Any help would be appreciated
Regards Seraphon
14 REPLIES 14

davidc
Star Contributor
Star Contributor
myspaces.js is a client-side javascript - copying it to the webscript folder won't help - it needs to be accessed via a public web server url e.g. /scripts/ajax/myspaces.js

myspaces-webscript2.jsp is a java server page - copying it to the webscript folder won't help - web scripts do not support .jsp customisation in this way.

seraphon
Champ in-the-making
Champ in-the-making
So is there no way to do some custom .js or .jsp without touching to the normally untouchable files within the webapp? Is the only solution for adding some javascript, to add those said javascript in the folder scripts/ajax ?

From what I understood about the myspaces webscripts all the interesting stuff are implemented by the javascripts so I think its kind of bothersome there is no way to do some kind of javascript extension.

In my own experience from Alfresco it is never a good idea to add or change things in the webapp folder because it always face the risks of being overwritten.

Regards
Seraphon

davidc
Star Contributor
Star Contributor
Please be aware that there is javascript that can run on the server-side (i.e. in the Alfresco server) and javascript that can run on the client-side (i.e. in the Browser).

myspaces.js is executed in the browser and loaded into the browser via a URL.  That URL needs to be supported by the Alfresco server.  Now, in the case of the myspaces portlet, it's using /scripts/ajax, a URL that's exposed natively by the Alfresco web server.  If you wish to move myspaces.js into the Respository, you can put it in any folder you like and then refer to via the "Content Download" Webscript

e.g. if you put myspaces.js in Company Home, you can use

/alfresco/service/api/path/content/workspace/SpacesStore/Company%20Home/myspaces.js

instead of

/scripts/ajax/myspaces.js

JSP page customisation is NOT supported by the Web Script f/w.

seraphon
Champ in-the-making
Champ in-the-making
Thank you very much for the explanation.
I didnt really understood what the Content Download Webscript did nor do I really understand all the subtilities lying with javascripts and URL.
I try my very best to understand it but my time on this project is short and I must learn everything from scratch when it comes to javascript.

Anyways I have another problem
When I do what you wrote, meaning I have my javascript file in company home and I put the good path, it works, but when I put my file the subspace
Data Dictionary\Web Scripts Extensions\org\alfresco\sample\test\myspaces2.js it doesnt work anymore.
I ve put the path :/alfresco/service/api/path/content/workspace/SpacesStore/Company%20Home/Dictionary%20Data/Web%20Scripts%20Extensions/org/alfresco/sample/test/myspaces2.js
What did I do wrong? Is my path incorrect?
I ve even tried the path :
/alfresco/service/api/path/content/workspace/SpacesStore/e5330e88-2916-11dc-a0c2-8d2c96e3c1ff/myspaces2.js
given by one of the links in the detail page of the test space. but weirdly it points toward the myspaces in companyhome…



Regards Seraphon

seraphon
Champ in-the-making
Champ in-the-making
Hi

I have some new questions
Using /alfresco/service/api/path/content/workspace/SpacesStore/Company%20Home/myspaces.js
works but I ve discovered some things that are somewhat problematic. I tried to "ignore" them at first but I think I have to make them dissapear.

The first thing is that this "service/api"  only works with file in company home. When I put my javascript file in another space it doesnt work anymore.
For example when I put
/alfresco/service/api/path/content/workspace/SpacesStore/Company%20Home/Data%20Dictionary/Web%20Scripts%20Extensions/org/alfresco/sample/test/myspaces2.js
it doesnt work. I can still put files in company home but I think it s not very good. I dont understand why I can only read files in company home using the service application.

The other problem is when you log in for the first time and try to enter my custom portlet. There is the first normal loggin page but after you logged once there is another window that pops up asking for yet again a login and password. I suspect that it is this last line I was talking about that launch this. My webscript somehow needs to log in in order to go fetch my javascript.
So is there a way to insert inside my webscript a login and password that it will always use for the service application that is reaching for custom javascript in Alfresco's repisetory?

It is not vital to do this but it would greatly improve the user friendly feeling of the portlet.

Regards
Seraphon

mikeh
Star Contributor
Star Contributor
Hi,

The /alfresco/service set of URLs use HTTP BASIC authentication. Your Freemarker template is probably using web client/session-based authentication. The two are quite separate.

Your easiest option is either to use the /alfresco/wcservice URL for the client-side jaavascript, or to append the /alfresco/service URL with
ticket=$(session.ticket)
when building the page within the Freemarker template.

Thanks,
Mike

seraphon
Champ in-the-making
Champ in-the-making
mmmm

Thx for the reply mike and I dont want to seem impertinent but could you please rephrase this in another way because I understood nothing of it.
It seems to me you are suggesting me to use the login or Getloginticket webscripts but I have absolutely have no idea how it works.

Must I implement this "ticket" in javasctript or directly in the freematker file?
Sorry for abusing your good will but I searched so much on this matter that I think I have mixed everything wrongly. For exemple in http://wiki.alfresco.com/wiki/Authentication_Web_Service
I dont even understand where you should put those method.


Regards
Seraphon

mikeh
Star Contributor
Star Contributor
In your Freemarker template, you need to include the client-side javascript files like this:
<script type="text/javscript" src="/alfresco/path/to/javscript/myspaces.js?ticket=${session.ticket}"></script>

Although the problem is occurring because you're mixing the two authentication types.

Mike

seraphon
Champ in-the-making
Champ in-the-making
Hi

I tried putting the ticket=${session.ticket but there is no change
In my first loging I still have to do 2 authentification.

Although the problem is occurring because you're mixing the two authentication types.
What do you mean by that?


Regards
Seraphon