cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco Share Advanced Search Customization

queiros
Champ in-the-making
Champ in-the-making
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+'&ou...";
           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,
2 REPLIES 2

erikwinlof
Confirmed Champ
Confirmed Champ
Hi,

COuld you please what it is that is not working?

If the problem is that the form isn't showing up in the search drop down menu, my bet would be that you have forgot to follow the parts of the instruction that tells you to override the search's menu items. You must add in an a custom <form> element for your custom form by using a config like below:

   <config evaluator="string-compare" condition="AdvancedSearch" replace="true">
      <advanced-search>
         <!– Forms for the advanced search type list –>
         <forms>
            <!–
               The 'form' config element contains the name of the model type
               of the form to display.
              
               The element supports the following optional attributes:
                  id = form id, the id of "search" will be assumed if not set
                  label = label text to display - defaults to model type if not set
                  labelId = I18N message id of label text to display
                  description = description text to display
                  descriptionId = I18N message id of description text to display
            –>
            <form labelId="search.form.label.cm_content" descriptionId="search.form.desc.cm_content">cm:content</form>
            <form labelId="search.form.label.cm_folder" descriptionId="search.form.desc.cm_folder">cm:folder</form>

           <!– Add  an extra menu item on the advanced search page –>
           <form labelId="xxx.search.form.label.xxx_comercial" descriptionId="xxx.search.form.desc.xxx_comercial">xxx:comercial</form>

         </forms>
      </advanced-search>
   </config>

Hope it helps!

Cheers, Erik

queiros
Champ in-the-making
Champ in-the-making
Hi,

Thank you for your answer, I already have the share-config-custom.xml the drop menu that has appeared, but my problem is that 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)  not working.

Thank you,
Alfredo Queiros