svn commit: r675103 - in /ofbiz/trunk/framework: example/widget/example/ images/webapp/images/ images/webapp/images/prototypejs/ widget/src/org/ofbiz/widget/html/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r675103 - in /ofbiz/trunk/framework: example/widget/example/ images/webapp/images/ images/webapp/images/prototypejs/ widget/src/org/ofbiz/widget/html/

apatel-2
Author: apatel
Date: Tue Jul  8 23:15:23 2008
New Revision: 675103

URL: http://svn.apache.org/viewvc?rev=675103&view=rev
Log:
enhancements to the Autocompleter integration with form widget dropdown.

Modified:
    ofbiz/trunk/framework/example/widget/example/ExampleForms.xml
    ofbiz/trunk/framework/example/widget/example/ExampleScreens.xml
    ofbiz/trunk/framework/images/webapp/images/prototypejs/controls.js
    ofbiz/trunk/framework/images/webapp/images/selectall.js
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java

Modified: ofbiz/trunk/framework/example/widget/example/ExampleForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/widget/example/ExampleForms.xml?rev=675103&r1=675102&r2=675103&view=diff
==============================================================================
--- ofbiz/trunk/framework/example/widget/example/ExampleForms.xml (original)
+++ ofbiz/trunk/framework/example/widget/example/ExampleForms.xml Tue Jul  8 23:15:23 2008
@@ -82,8 +82,9 @@
         <field use-when="example!=null" name="exampleId" title="${uiLabelMap.ExampleExampleId}" tooltip="${uiLabelMap.CommonNotModifRecreat}"><display/></field>
         <field use-when="example==null&amp;&amp;exampleId==null" name="exampleId" title="${uiLabelMap.ExampleExampleId}"><ignored/></field>
         <field use-when="example==null&amp;&amp;exampleId!=null" name="exampleId" title="${uiLabelMap.ExampleExampleId}"><display description="${uiLabelMap.CommonCannotBeFound}: [${exampleId}]" also-hidden="false"/></field>
-        <field name="exampleTypeId" title="${uiLabelMap.CommonType}">
+        <field name="exampleTypeId" title="${uiLabelMap.CommonType}" id-name="exampleTypeId">
             <drop-down allow-empty="false">
+                <auto-complete/>
                 <entity-options entity-name="ExampleType" description="${description}">
                     <entity-order-by field-name="description"/>
                 </entity-options>
@@ -125,14 +126,6 @@
         have these settings. -->
     <form name="EditExampleBackgroundSubmit" type="single" extends="EditExample" target="updateExampleAjax">
         <alt-target use-when="example==null" target="createExampleAjax"/>
-        <field name="exampleTypeId" title="${uiLabelMap.CommonType}" id-name="exampleTypeId">
-            <drop-down allow-empty="false">
-                <auto-complete/>
-                <entity-options entity-name="ExampleType" description="${description}">
-                    <entity-order-by field-name="description"/>
-                </entity-options>
-            </drop-down>
-        </field>
         <field name="statusId" use-when="example==null" title="${uiLabelMap.CommonStatus}" id-name="statusId">
             <drop-down allow-empty="false">
                 <auto-complete/>

Modified: ofbiz/trunk/framework/example/widget/example/ExampleScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/widget/example/ExampleScreens.xml?rev=675103&r1=675102&r2=675103&view=diff
==============================================================================
--- ofbiz/trunk/framework/example/widget/example/ExampleScreens.xml (original)
+++ ofbiz/trunk/framework/example/widget/example/ExampleScreens.xml Tue Jul  8 23:15:23 2008
@@ -62,6 +62,7 @@
     <screen name="EditExample">
         <section>
             <actions>
+                <set field="layoutSettings.styleSheets[+0]" value="/images/prototypejs/scriptaculouscontrols.css" global="true"/>
                 <set field="titleProperty" value="PageTitleEditExample"/>
                 <set field="tabButtonItem" value="EditExample"/>
                 <set field="exampleId" from-field="parameters.exampleId"/>

Modified: ofbiz/trunk/framework/images/webapp/images/prototypejs/controls.js
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/images/webapp/images/prototypejs/controls.js?rev=675103&r1=675102&r2=675103&view=diff
==============================================================================
--- ofbiz/trunk/framework/images/webapp/images/prototypejs/controls.js (original)
+++ ofbiz/trunk/framework/images/webapp/images/prototypejs/controls.js Tue Jul  8 23:15:23 2008
@@ -407,9 +407,9 @@
 // you support them.
 
 Autocompleter.Local = Class.create(Autocompleter.Base, {
-  initialize: function(element, update, array, options) {
+  initialize: function(element, update, data, options) {
     this.baseInitialize(element, update, options);
-    this.options.array = array;
+    this.options.data = data;
   },
 
   getUpdatedChoices: function() {
@@ -429,38 +429,75 @@
         var entry     = instance.getToken();
         var count     = 0;
 
-        for (var i = 0; i < instance.options.array.length &&  
-          ret.length < instance.options.choices ; i++) {
-
-          var elem = instance.options.array[i];
-          var foundPos = instance.options.ignoreCase ?
-            elem.toLowerCase().indexOf(entry.toLowerCase()) :
-            elem.indexOf(entry);
-
-          while (foundPos != -1) {
-            if (foundPos == 0 && elem.length != entry.length) {
-              ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
-                elem.substr(entry.length) + "</li>");
-              break;
-            } else if (entry.length >= instance.options.partialChars &&
-              instance.options.partialSearch && foundPos != -1) {
-              if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
-                partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
-                  elem.substr(foundPos, entry.length) + "</strong>" + elem.substr(
-                  foundPos + entry.length) + "</li>");
+        if (Object.isHash(instance.options.data)) {
+          var keys = [];
+          keys = instance.options.data.keys();
+          for (var i = 0; i < keys.length &&  
+            ret.length < instance.options.choices ; i++) {
+
+            var elem = instance.options.data.get(keys[i]);
+            var foundPos = instance.options.ignoreCase ?
+              elem.toLowerCase().indexOf(entry.toLowerCase()) :
+              elem.indexOf(entry);
+
+            while (foundPos != -1) {
+              if (foundPos == 0 && elem.length != entry.length) {
+                ret.push("<li id=" + '"' + keys[i] + '"' + "><strong>" + elem.substr(0, entry.length) + "</strong>" +
+                  elem.substr(entry.length) + "</li>");
                 break;
+              } else if (entry.length >= instance.options.partialChars &&
+                instance.options.partialSearch && foundPos != -1) {
+                if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
+                  partial.push("<li id=" + '"' + keys[i] + '"' + ">" + elem.substr(0, foundPos) + "<strong>" +
+                    elem.substr(foundPos, entry.length) + "</strong>" + elem.substr(
+                    foundPos + entry.length) + "</li>");
+                  break;
+                }
               }
+
+              foundPos = instance.options.ignoreCase ?
+                elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
+                elem.indexOf(entry, foundPos + 1);
+
             }
+          }
+          if (partial.length)
+            ret = ret.concat(partial.slice(0, instance.options.choices - ret.length))
+          return "<ul>" + ret.join('') + "</ul>";
+        } else {
+          for (var i = 0; i < instance.options.data.length &&  
+            ret.length < instance.options.choices ; i++) {
+
+            var elem = instance.options.data[i];
+            var foundPos = instance.options.ignoreCase ?
+              elem.toLowerCase().indexOf(entry.toLowerCase()) :
+              elem.indexOf(entry);
+
+            while (foundPos != -1) {
+              if (foundPos == 0 && elem.length != entry.length) {
+                ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
+                  elem.substr(entry.length) + "</li>");
+                break;
+              } else if (entry.length >= instance.options.partialChars &&
+                instance.options.partialSearch && foundPos != -1) {
+                if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
+                  partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
+                    elem.substr(foundPos, entry.length) + "</strong>" + elem.substr(
+                    foundPos + entry.length) + "</li>");
+                  break;
+                }
+              }
 
-            foundPos = instance.options.ignoreCase ?
-              elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
-              elem.indexOf(entry, foundPos + 1);
+              foundPos = instance.options.ignoreCase ?
+                elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
+                elem.indexOf(entry, foundPos + 1);
 
+            }
           }
+          if (partial.length)
+            ret = ret.concat(partial.slice(0, instance.options.choices - ret.length))
+          return "<ul>" + ret.join('') + "</ul>";
         }
-        if (partial.length)
-          ret = ret.concat(partial.slice(0, instance.options.choices - ret.length))
-        return "<ul>" + ret.join('') + "</ul>";
       }
     }, options || { });
   }

Modified: ofbiz/trunk/framework/images/webapp/images/selectall.js
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/images/webapp/images/selectall.js?rev=675103&r1=675102&r2=675103&view=diff
==============================================================================
--- ofbiz/trunk/framework/images/webapp/images/selectall.js (original)
+++ ofbiz/trunk/framework/images/webapp/images/selectall.js Tue Jul  8 23:15:23 2008
@@ -322,26 +322,20 @@
     }
 }
 
-/** Enable auto-completion for dorp-down elements.
-  * @param areaId The id of the drop-down
-  * @param data Choices for Autocompleter.Local
+/** Enable auto-completion for drop-down elements.
+  * @param descriptionElement The id of the text field
+  * @param hiddenElement The id of the drop-down.  Used as the id of hidden field inserted.
+  * @param data Choices for Autocompleter.Local, form of: {key: 'description',.......}
   * @param options
 */
 
-function ajaxAutoCompleteDropDown(element, data, options) {
-    var key = [];
-    var description = [];
-    for (var i=0; i < data.length; i++) {
-        currData = data[i];
-        key[i] = currData[0];
-        description[i] = currData[1];
-    }
- var update = element + "_autoCompleterOptions";
-    $(element).insert({after: '<div class="autocomplete"' + 'id=' + update + '></div>'});
-    new Autocompleter.Local($(element), update, description, {autoSelect: options.autoSelect, frequency: options.frequency, minChars: options.minChars, choices: options.choices, partialSearch: options.partialSearch, partialChars: options.partialChars, ignoreCase: options.ignoreCase, fullSearch: options.fullSearch, afterUpdateElement: setKeyAsParameter});
+function ajaxAutoCompleteDropDown(descriptionElement, hiddenElement, data, options) {
+    var update = hiddenElement + "_autoCompleterOptions";
+    $(descriptionElement).insert({after: '<div class="autocomplete"' + 'id=' + update + '></div>'});
+    new Autocompleter.Local($(descriptionElement), update, $H(data), {autoSelect: options.autoSelect, frequency: options.frequency, minChars: options.minChars, choices: options.choices, partialSearch: options.partialSearch, partialChars: options.partialChars, ignoreCase: options.ignoreCase, fullSearch: options.fullSearch, afterUpdateElement: setKeyAsParameter});
     
-    function setKeyAsParameter() {
-        $(element).value = key[description.indexOf($F(element))];
+    function setKeyAsParameter(text, li) {
+        $(hiddenElement).value = li.id;
     }
 }
 

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java?rev=675103&r1=675102&r2=675103&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java Tue Jul  8 23:15:23 2008
@@ -588,6 +588,8 @@
 
         String event = modelFormField.getEvent();
         String action = modelFormField.getAction(context);
+        
+        String currentValue = modelFormField.getEntry(context);
 
         if (ajaxEnabled) {
          writer.append("<input type=\"text\"");
@@ -599,40 +601,82 @@
 
         writer.append(" name=\"");
         writer.append(modelFormField.getParameterName(context));
-        writer.append('"');
 
         String idName = modelFormField.getIdName();
-        if (UtilValidate.isNotEmpty(idName)) {
-            writer.append(" id=\"");
-            writer.append(idName);
-            writer.append('"');
-        }
         
         if (ajaxEnabled) {
-         writer.append("/>");
-        
-         appendWhitespace(writer);
+            writer.append("_description\"");
+
+            String textFieldIdName = idName;
+            if (UtilValidate.isNotEmpty(textFieldIdName)) {
+                textFieldIdName += "_description";
+                writer.append(" id=\"");
+                writer.append(textFieldIdName);
+                writer.append('"');
+            }
+            
+            if (UtilValidate.isNotEmpty(currentValue)) {
+                writer.append(" value=\"");
+                String explicitDescription = dropDownField.getCurrentDescription(context);
+                if (UtilValidate.isNotEmpty(explicitDescription)) {
+                    writer.append(explicitDescription);
+                } else {
+                    writer.append(ModelFormField.FieldInfoWithOptions.getDescriptionForOptionKey(currentValue, allOptionValues));
+                }
+                writer.append('"');
+            }
+            writer.append("/>");
+            
+            appendWhitespace(writer);
+            writer.append("<input type=\"hidden\"");
+            writer.append(" name=\"");
+            writer.append(modelFormField.getParameterName(context));
+            writer.append('"');
+            if (UtilValidate.isNotEmpty(idName)) {
+             writer.append(" id=\"");
+                writer.append(idName);
+                writer.append('"');
+            }
+            
+            if (UtilValidate.isNotEmpty(currentValue)) {
+                writer.append(" value=\"");
+                String explicitDescription = dropDownField.getCurrentDescription(context);
+                writer.append(currentValue);
+                writer.append('"');
+            }
+            
+            writer.append("/>");
+
+            appendWhitespace(writer);
             writer.append("<script language=\"JavaScript\" type=\"text/javascript\">");
             appendWhitespace(writer);
-            writer.append("var data = [");
+            writer.append("var data = {");
             Iterator optionValueIter = allOptionValues.iterator();
             int count = 0;
             while (optionValueIter.hasNext()) {
              count++;
                 ModelFormField.OptionValue optionValue = (ModelFormField.OptionValue) optionValueIter.next();
-                writer.append("['"+optionValue.getKey()+"',");
-                writer.append(" '"+optionValue.getDescription()+"']");
+                writer.append(""+optionValue.getKey()+": ");
+                writer.append(" '"+optionValue.getDescription()+"'");
                 if (count != allOptionValues.size()) {
                  writer.append(", ");
                 }
             }
-            writer.append("];");
+            writer.append("};");
             appendWhitespace(writer);
-            writer.append("ajaxAutoCompleteDropDown('"+idName+"', data, {autoSelect: "+autoComplete.getAutoSelect()+", frequency: "+autoComplete.getFrequency()+", minChars: "+autoComplete.getMinChars()+", choices: "+autoComplete.getChoices()+", partialSearch: "+autoComplete.getPartialSearch()+", partialChars: "+autoComplete.getPartialChars()+", ignoreCase: "+autoComplete.getIgnoreCase()+", fullSearch: "+autoComplete.getFullSearch()+"});");
+            writer.append("ajaxAutoCompleteDropDown('"+textFieldIdName+"', '"+idName+"', data, {autoSelect: "+autoComplete.getAutoSelect()+", frequency: "+autoComplete.getFrequency()+", minChars: "+autoComplete.getMinChars()+", choices: "+autoComplete.getChoices()+", partialSearch: "+autoComplete.getPartialSearch()+", partialChars: "+autoComplete.getPartialChars()+", ignoreCase: "+autoComplete.getIgnoreCase()+", fullSearch: "+autoComplete.getFullSearch()+"});");
             appendWhitespace(writer);
             writer.append("</script>");
         } else {
-         if (dropDownField.isAllowMultiple()) {
+         writer.append('"');
+
+            if (UtilValidate.isNotEmpty(idName)) {
+                writer.append(" id=\"");
+                writer.append(idName);
+                writer.append('"');
+            }
+
+            if (dropDownField.isAllowMultiple()) {
                 writer.append(" multiple=\"multiple\"");
             }
             
@@ -659,8 +703,6 @@
 
             writer.append(" size=\"" + dropDownField.getSize() + "\">");
 
-            String currentValue = modelFormField.getEntry(context);
-
             // if the current value should go first, stick it in
             if (UtilValidate.isNotEmpty(currentValue) && "first-in-list".equals(dropDownField.getCurrent())) {
                 writer.append("<option");