cancel
Showing results for 
Search instead for 
Did you mean: 

site-webscript: Determine if a SURF module is enabled

jpfi
Champ in-the-making
Champ in-the-making
Hi guys,
I've developed a custom Share module using Share's/SURF's new extensions mechanism.
I'm wondering to how to determine within a site-webscript if a specific module is enabled or not?
Thx,
Jan
5 REPLIES 5

ddraper
World-Class Innovator
World-Class Innovator
Hi Jan,

It is possible to determine whether or not a module is deployed, but what is not possible is to determine whether or not it will be applied. This is because the extensions are not evaluated until AFTER the base WebScript has been run. HOWEVER…

Extension Modules are only evaluated once per request and this information can be retrieved by calling the getEvaluatedModules() method. This means that providing your WebScript is NOT the first one run on the page you can determine the evaluated modules… HOWEVER…

This is still not a guarantee that the module will have any effect on the WebScript since there are further evaluations within the module (e.g. path matching for customizations and SubComponent evaluations).

I would need to check whether or not you can access the evaluated modules data directly from within the WebScript JavaScript controller or FreeMarker template, but you'd certainly be able do this from a Java-backed WebScript (because the module handler is a Spring bean which you can configure as a property of your controller).

This isn't a use-case that I'd previously considered but I can certainly look at making this easier. It might be worth raising an issue for this to track the work-item properly to capture requirements and for you to track progress as it's not something I'll be able to make a start on immediately.

Regards,
Dave

jpfi
Champ in-the-making
Champ in-the-making
Hi,
Ok, what's about submitting the evaluation result of each deployed into a global client-side JS variable, e.g.
Alfresco.constants.MODULES = {
"moduleA":true, //active
"moduleB":false //not active
}

Cheers, Jan

ddraper
World-Class Innovator
World-Class Innovator
If by active you mean "deployed" (as opposed to "evaluated) then that should be fairly straight-forward, although I'd actually set this as an entry in the WebScript model first (this of course could then be used to create a client-side JS constant in "resources.get.html.ftl". This approach wouldn't work for trying to determine which module will be evaluated to have an effect on each WebScript because the data isn't available and will be different for each WebScript run on the page.

I'm assuming from your question though it will be sufficient to just know which modules have been deployed?

Regards,
Dave

jpfi
Champ in-the-making
Champ in-the-making
Hi,
yub, for my use case it is sufficient to now if a module is deployed.
Thx, jan

lotharmärkle
Champ in-the-making
Champ in-the-making
Hello,

+1 for a ootb solution!

However, you can already push this to the client JS layer by adding a subcomponent to the global scoped head-resources region:

in a module extension file:

<extension>
   <modules>
     <module>
       <components>
   <component>
      <scope>global</scope>
      <region-id>head-resources</region-id>
      <source-id>global</source-id>
      <sub-components>
         <sub-component id="my-module-active-indicator">
               <url>/ecm4u/components/module-indicator</url>
              </sub-component>
      </sub-components>
   </component>


and configured a webscript at /ecm4u/components/module-indicator to add this script snippet to the page:

<script type="text/javascript">//<![CDATA[
// namespace
if (typeof ecm4u == "undefined" || !ecm4u) {
   var ecm4u = {};
}

ecm4u.mymoduleisactive = true;

//]]></script>

then in client JS test like

if(ecm4u.mymoduleisactive) {
….
}

Regards,
  lothar