AnsweredAssumed Answered

Alfresco Share Advanced Search Customization

Question asked by queiros on May 29, 2012
Latest reply on Jun 5, 2012 by queiros
Hi,

I have followed this example exactly as mentioned: http://wiki.alfresco.com/wiki/Share_Advanced_Search , to configure my Alfresco Advanced Search.
I try to customize the share advanced search by introducing my type xxx:entidade using web scripting that implements YAHOO.widget.AutoComplete
(autocomplete.ftl, autocomplete.get.desc.xml, autocomplete.get.html.ftl, autocomplete.get.js e autocomplete.get.config.xml) web scripting not working.

I have my share-config-custom.xml :

    …
    <!– xxx:comercial type (new nodes) –>
    <config evaluator="model-type" condition="xxx:comercial">
      <forms>
         <form>
            <field-visibility>
               <show id="cm:name" />
               <show id="cm:content" force="true" />
            </field-visibility>
            <appearance>
               <field id="cm:content">
                  <control>
                     <control-param name="editorAppearance">explorer</control-param>
                  </control>
               </field>
            </appearance>
         </form>
         <form id="search">
            <field-visibility>
               <show id="cm:name" />
               <show id="cm:title" force="true" />
               <show id="cm:description" force="true" />
            <show id="cm:taggable" force="true" />         
               <show id="xxx:entidadeNome" force="true"/>
            </field-visibility>
            <appearance>
            
             <field id="xxx:entidadeNome">
              <control template="/xxx/controls/autocomplete.ftl">
                 <control-param name="ds">/share/service/ds/autocomplete/google</control-param>
              </control>
                </field>

            
              <field id="cm:taggable">
                    <control>
                            <control-param name="compactMode">true</control-param>
                            <control-param name="params">aspect=cm:taggable</control-param>
                            <control-param name="createNewItemIcon">tag</control-param>
                    </control>
                </field>            
            </appearance>
         </form>
      </forms>
   </config>

   I have web scripts autocomplete.ftl :
  
        <#if field.control.params.ds?exists><#assign ds=field.control.params.ds><#else><#assign ds=&#39;&#39;></#if>
      <#if field.control.params.width?exists><#assign width=field.control.params.width><#else><#assign width=&#39;35em&#39;></#if>

      <style type="text/css">
      #${fieldHtmlId}-AutoComplete {
         width:${width}; /* set width here or else widget will expand to fit its container */
         padding-bottom:2em;
      }
      </style>

      <div class="form-field">
         <#if form.mode == "view">
           <div class="viewmode-field">
             <#if field.mandatory && !(field.value?is_number) && field.value == "">
               <span class="incomplete-warning"><img src="${url.context}/components/form/images/warning-16.png" title="${msg("form.field.incomplete")}" /><span>
             </#if>
             <span class="viewmode-label">${field.label?html}:</span>
             <span class="viewmode-value">${field.value?html}</span>
           </div>
         <#else>
           <label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
           <div id="${fieldHtmlId}-AutoComplete">
              <input id="${fieldHtmlId}" type="text" name="${field.name}"
                <#if field.control.params.styleClass?exists>class="${field.control.params.styleClass}"</#if>
                <#if field.value?is_number>value="${field.value?c}"<#else>value="${field.value}"</#if>
                <#if field.description?exists>title="${field.description}"</#if>
                <#if field.control.params.maxLength?exists>maxlength="${field.control.params.maxLength}"</#if>
                <#if field.control.params.size?exists>size="${field.control.params.size}"</#if>
                <#if field.disabled>disabled="true"</#if> />
              <div id="${fieldHtmlId}-Container"></div>      
           </div>
         </#if>
      </div>

      <script type="text/javascript">//<![CDATA[
      (function()
      {
            // Use an XHRDataSource
            var oDS = new YAHOO.util.XHRDataSource("${ds}");
            // Set the responseType
            oDS.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
            // Define the schema of the JSON results
            oDS.responseSchema = {
               resultsList : "result",
               fields : ["value"]
            };

            // Instantiate the AutoComplete
            var oAC = new YAHOO.widget.AutoComplete("${fieldHtmlId}", "${fieldHtmlId}-Container", oDS);
            // Throttle requests sent
            oAC.queryDelay = .5;
            // The webservice needs additional parameters
            oAC.generateRequest = function(sQuery) {
               <#if ds?contains("?")>
                  return "&q=" + sQuery ;
               <#else>
                  return "?q=" + sQuery ;
               </#if>
            };

            return {
               oDS: oDS,
               oAC: oAC
            };
      })();
      //]]></script>


   I have web scripts autocomplete.get.desc.xml :

      <webscript>
         <shortname>Data web script for auto complete widget</shortname>
         <description>Data web script for auto complete widget</description>
         <url template="/ds/autocomplete/{resource}"/>
         <format default="html">extension</format>
         <authentication>user</authentication>
         <transaction>required</transaction>
      </webscript>  

   I have web scripts autocomplete.get.html.ftl :

      ${result}
      
   I have web scripts autocomplete.get.js :
  
      var results = {};
      var result= new Array();
      var resource = "" + url.extension;
      var query  = args.q;
      var status = "succeed";

      switch (resource)
      {
         case "google":

           var googleServiceUrl = "http://google.com/complete/search?output=toolbar&q='+query;
           var connector = remote.connect("http");
           var str = new String(connector.call(googleServiceUrl));

           //Javascript E4X module has problems with XML header
           if ( str.substr(0,5).indexOf("?xml") != -1 )
           {
             positionRootElement = str.indexOf("<", 10);//get first real tag
             str = str.substr( positionRootElement, str.length - 1 );
           }

           var suggestions = new XML(str);
           var suggestion;
           for each (suggestion in suggestions.CompleteSuggestion)
           {
             var resultItem = {};
             resultItem.name  = suggestion.suggestion.@data.toString();
             resultItem.value = suggestion.suggestion.@data.toString();
             result.push(resultItem);
           }
        
           break;
        
         case "yahoo":
        
           // get appid from configuration
           var s = new XML(config.script);
           var appid = s.yahoo.appid;

           var yahooServiceUrl = "http://search.yahooapis.com/WebSearchService/V1/relatedSuggestion?query='+query+'&appid='+appid+'&output=json";
           var connector = remote.connect("http");
           var jsonStr = eval("(" + connector.call(yahooServiceUrl) + ")");

           var suggestion;
           for each (suggestion in jsonStr.ResultSet.Result)
           {
             var resultItem = {};
             resultItem.name  = suggestion;
             resultItem.value = suggestion;
             result.push(resultItem);
           }
        
           break;
        
         default :
           status="failed";
      }

      results.result = result;
      model.result = jsonUtils.toJSONString(results);


    I have web scripts autocomplete.get.config.xml :
  
      <config>
         <yahoo>
           <appid>WNahF8rV34HQsGMzvTM2x4BlTWF20xihgvnxkrIzyIvO5HDQuyI8hkT0IXGvkPdmzw–</appid>
         </yahoo>   
      </config>


    Web scripting autocomplete no working.
   Could you have any ideas about this issue? How we can configure the advanced search customized with my web scripting?
   
   Thanks,

Outcomes