cancel
Showing results for 
Search instead for 
Did you mean: 

Packaging client-side Javascript in AMP/WAR

lawrencei
Champ in-the-making
Champ in-the-making
Hello,

As part of a small Share customization project I added a few extra properties to the site model and displayed them for editing in the "Create Site" dialog. I had to modify the client-side JS code in create-site.js; things are working largely as expected, but I have a couple of issues I haven't been able to solve:

1) How do I package the modified create-site.js in the Share AMP so I can overwrite the existing one in share/modules? I tried placing in under main/amp/web/modules but to no avail (I'm using the Maven AMP archetype for development).

2) Is there a more elegant way of implementing this extension other than direct modification of the create-site.js file?

Thank you,

LawrenceI
3 REPLIES 3

lementree
Champ on-the-rise
Champ on-the-rise
Hi,

1. the easy way to do this is modify sample amp file with winRAR.

2. there is no other easy way than this

oleh
Champ in-the-making
Champ in-the-making
To have stuff in src/main/amp/web end up in the right place, you'll need to add a file called file-mapping.properties in src/main/amp. The file should look like this:

include.default=true
/web=/


This tells the MMT tool (which the Alfresco Maven SDK uses to apply your AMP on the share.war file) that everything in src/main/amp should end up in the root. This will allow you to put the file in src/main/amp/web/modules/.

As for a more elegant way to customize create-site.js, it's a tough one, because usually when extending Share's clientside javascript there would be a freemarker template or web script controller that you could extend and tell it to use your own customized version of Alfresco.module.CreateSite where you would create a new object that would extend Alfresco.module.CreateSite. See http://docs.alfresco.com/4.0/tasks/tu-share-JS-customize.html for details on how to extend web scripts and freemarker templates.

However, with the new header the object is initialized from js/alfresco/services/SiteService.js so there seems to be no clean way to tell Share to use your custom object instead of the standard one.

When walking through the process if clicking the "Create site" button, it fires off an event to the pub/sub system in the header, which SiteService picks up on and calls createSite in SiteService. In theory you could make a custom component that listens in on the event and intercepts it before it reaches SiteService, but I'm not sure if this is actually possible.

This is an interesting use case, it seems to be a bit too hardcoded, unless I'm missing something obvious. Hope this clears things up a bit

lawrencei
Champ in-the-making
Champ in-the-making
Thanks a lot, it did clear up things! As you could tell, I'm new to Alfresco Share development and far from a JavaScript expert, so I appreciate the explanation.