Advertisement
Guest User

usersAutocomplete2.ftl

a guest
Dec 15th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.97 KB | None | 0 0
  1. <#include "/org/alfresco/components/form/controls/common/utils.inc.ftl" />
  2.  
  3. <#-- set global freemarker properties -->
  4.  
  5. <#assign fieldValue=field.value>
  6.  
  7. <#assign el=args.htmlid?html>
  8.  
  9. <#-- CSS style definition -->
  10.  
  11. <style media="screen" type="text/css">
  12.  
  13.     .autocomplete-container {
  14.         height: 3em;
  15.     }
  16.  
  17.     .autocomplete-container input{
  18.         outline: none;
  19.     }
  20.  
  21.     .autocomplete-container ul li{
  22.         padding: 0!important;
  23.     }
  24.  
  25.     .autocomplete-container ul li div.autocomplete-item{
  26.         padding: 3px 3px 3px 6px;
  27.     }
  28.  
  29.     .autocomplete-container ul li:not(:first-child) div.autocomplete-item{
  30.         border-top: solid 1px #ccc;
  31.     }
  32.  
  33. </style>
  34.  
  35. <#-- javascript functions definition -->
  36.  
  37. <script type="text/javascript">//<![CDATA[
  38. (function() {
  39.  
  40.    // After html input element is generated
  41.    YAHOO.util.Event.onAvailable("${fieldHtmlId}", function() {
  42.  
  43.        // Parse and update date input value function
  44.        var setDate = function(date, id) {
  45.        
  46.            var d = new Date(date);
  47.            var input = Dom.get(id);
  48.            if (!isNaN(d)) {
  49.                input.value = d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear();
  50.  
  51.            } else {
  52.                input.value = "";
  53.            }
  54.            YAHOO.util.UserAction.keyup(input);
  55.        };
  56.  
  57.        
  58.        <#if field.control.params.webscript?? && field.control.params.webscript?string != "">
  59.            var dataSource = new YAHOO.util.XHRDataSource(Alfresco.constants.PROXY_URI + "${field.control.params.webscript}" + "?site=" + Alfresco.constants.SITE);
  60.        <#else>
  61.            var dataSource = new YAHOO.util.LocalDataSource();
  62.        </#if>
  63.        // Create and configure new datasource
  64.        
  65.  
  66.        dataSource.responseSchema = {
  67.            resultsList: "results", // String pointer to result data
  68.            fields: [
  69.                 "cm_userName",
  70.                 "cm_firstName",
  71.                 "cm_lastName",
  72.            ]
  73.        };
  74.  
  75.        // Create and configure new autocomplete
  76.        var autocomplete = new YAHOO.widget.AutoComplete("${fieldHtmlId}", "${fieldHtmlId}-autocomplete-options", dataSource);
  77.  
  78.        autocomplete.generateRequest = function(sQuery) {
  79.            return "&query=" + sQuery;
  80.        };
  81.        
  82.     // Create formatted options from filterred results
  83.        autocomplete.formatResult = function(oResultItem, sQuery) {
  84.  
  85.            // If some of values are empty, show message that there were not filled in datalist
  86.            var item = '<div class="autocomplete-item">';
  87.            item += '<div><b>${msg("users-autocomplete.prop_cm_userName")}:</b> ' + oResultItem[0] + '</div>';
  88.            item += '<div><b>${msg("users-autocomplete.prop_cm_firstName")}:</b> ' + oResultItem[1] + '</div>';
  89.            item += '<div><b>${msg("users-autocomplete.prop_cm_lastName")}:</b> ' + oResultItem[2] + '</div>';
  90.            item += '</div>';
  91.  
  92.            return item;
  93.        };
  94.  
  95.        // Listen to event of item selection
  96.        autocomplete.itemSelectEvent.subscribe(function(sType, aArgs) {
  97.            Dom.get("${el}_prop_swm2_specialSchvalovatele").value = aArgs[2][0];
  98.        });
  99.  
  100.        // Container will expand and collapse vertically
  101.        autocomplete.animVert = false;
  102.  
  103.        // Container will expand and collapse horizontally
  104.        autocomplete.animHoriz = false;
  105.  
  106.        // Container animation will take 0 seconds to complete
  107.        autocomplete.animSpeed = 0;
  108.  
  109.        // Remove autohighlight after options are showed
  110.        autocomplete.autoHighlight = false
  111.  
  112.        // Container shows max 5 results
  113.        autocomplete.maxResultsDisplayed = 10;
  114.  
  115.    });
  116. })();
  117.  
  118. //]]> </script>
  119.  
  120. <div class="form-field">
  121.    <#if form.mode == "view">
  122.       <div class="viewmode-field">
  123.          <#if field.mandatory && !(field.value?is_number) && field.value == "">
  124.             <span class="incomplete-warning"><img src="${url.context}/res/components/form/images/warning-16.png" title="${msg("form.field.incomplete")}" /><span>
  125.          </#if>
  126.          <span class="viewmode-label">${field.label?html}:</span>
  127.          <#if field.control.params.activateLinks?? && field.control.params.activateLinks == "true">
  128.             <#assign fieldValue=field.value?html?replace("((http|ftp|https):\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?\\^=%&:\\/~\\+#]*[\\w\\-\\@?\\^=%&\\/~\\+#])?)", "<a href=\"$1\" target=\"_blank\">$1</a>", "r")>
  129.          <#else>
  130.             <#if field.value?is_number>
  131.                <#assign fieldValue=field.value?c>
  132.             <#else>
  133.                <#assign fieldValue=field.value?html>
  134.             </#if>
  135.          </#if>
  136.          <span class="viewmode-value"><#if fieldValue == "">${msg("form.control.novalue")}<#else>${fieldValue}</#if></span>
  137.       </div>
  138.    <#else>
  139.      <div class="autocomplete-container">
  140.         <label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
  141.         <input id="${fieldHtmlId}" name="${field.name}" tabindex="0" size="8" autocomplete="off"
  142.             <#if field.control.params.password??>type="password"<#else>type="text"</#if>
  143.              <#if field.control.params.styleClass??>class="${field.control.params.styleClass}"</#if>
  144.              <#if field.control.params.style??>style="${field.control.params.style}"</#if>
  145.              <#if field.value?is_number>value="${field.value?c}"<#else>value="${field.value?html}"</#if>
  146.              <#if field.description??>title="${field.description}"</#if>
  147.              <#if field.control.params.maxLength??>maxlength="${field.control.params.maxLength}"<#else>maxlength="1024"</#if>
  148.              <#if field.disabled && !(field.control.params.forceEditable?? && field.control.params.forceEditable == "true")>disabled="true"</#if> />
  149.         <@formLib.renderFieldHelp field=field />
  150.  
  151.         <div id="${fieldHtmlId}-autocomplete-options"></div>
  152.       </div>
  153.    </#if>
  154. </div>
  155.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement