You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2019/03/30 08:03:53 UTC

svn commit: r1856611 - in /ofbiz/ofbiz-framework/branches/release18.12: ./ themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl themes/common-theme/webapp/common/js/util/OfbizUtil.js themes/common-theme/webapp/common/js/util/combobox.js

Author: adityasharma
Date: Sat Mar 30 08:03:53 2019
New Revision: 1856611

URL: http://svn.apache.org/viewvc?rev=1856611&view=rev
Log:
Applied fix from trunk for revision: 1856610 
===

Improved: Replace Inline js with External js in renderDropDownField macro.
(OFBIZ-9849)
Silghtly modified patch as Specify-other Dropdown field were not working. Refactored code in combobox.js file
Thanks Dhaval Wagela for the initial patch

Modified:
    ofbiz/ofbiz-framework/branches/release18.12/   (props changed)
    ofbiz/ofbiz-framework/branches/release18.12/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl
    ofbiz/ofbiz-framework/branches/release18.12/themes/common-theme/webapp/common/js/util/OfbizUtil.js
    ofbiz/ofbiz-framework/branches/release18.12/themes/common-theme/webapp/common/js/util/combobox.js

Propchange: ofbiz/ofbiz-framework/branches/release18.12/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Mar 30 08:03:53 2019
@@ -10,4 +10,4 @@
 /ofbiz/branches/json-integration-refactoring:1634077-1635900
 /ofbiz/branches/multitenant20100310:921280-927264
 /ofbiz/branches/release13.07:1547657
-/ofbiz/ofbiz-framework/trunk:1849931,1850015,1850023,1850530,1850647,1850685,1850694,1850711,1850914,1850918,1850921,1850948,1850953,1851006,1851013,1851068,1851074,1851130,1851158,1851200,1851224,1851247,1851254,1851315,1851319,1851350,1851353,1851433,1851500,1851805,1851885,1851998,1852503,1852587,1852818,1852882,1853070,1853109,1853691,1853745,1853750,1854306,1854457,1854683,1855078,1855083,1855287,1855371,1855403,1855488,1855492,1855497,1855501,1855898,1856212,1856405,1856455,1856459-1856460,1856484,1856598
+/ofbiz/ofbiz-framework/trunk:1849931,1850015,1850023,1850530,1850647,1850685,1850694,1850711,1850914,1850918,1850921,1850948,1850953,1851006,1851013,1851068,1851074,1851130,1851158,1851200,1851224,1851247,1851254,1851315,1851319,1851350,1851353,1851433,1851500,1851805,1851885,1851998,1852503,1852587,1852818,1852882,1853070,1853109,1853691,1853745,1853750,1854306,1854457,1854683,1855078,1855083,1855287,1855371,1855403,1855488,1855492,1855497,1855501,1855898,1856212,1856405,1856455,1856459-1856460,1856484,1856598,1856610

Modified: ofbiz/ofbiz-framework/branches/release18.12/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl?rev=1856611&r1=1856610&r2=1856611&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl Sat Mar 30 08:03:53 2019
@@ -140,12 +140,17 @@ under the License.
   </span>
 </#macro>
 
-<#macro renderDropDownField name className alert id formName otherFieldName action explicitDescription options fieldName otherFieldName otherValue otherFieldSize ajaxEnabled ajaxOptions frequency minChars choices autoSelect partialSearch partialChars ignoreCase fullSearch conditionGroup="" tabindex="" multiple="" event="" size="" firstInList="" currentValue="" allowEmpty="" dDFCurrent="" noCurrentSelectedKey="">
+<#macro renderDropDownField name className alert id formName action explicitDescription options fieldName otherFieldName otherValue otherFieldSize ajaxEnabled ajaxOptions frequency minChars choices autoSelect partialSearch partialChars ignoreCase fullSearch conditionGroup="" tabindex="" multiple="" event="" size="" firstInList="" currentValue="" allowEmpty="" dDFCurrent="" noCurrentSelectedKey="">
   <#if conditionGroup?has_content>
     <input type="hidden" name="${name}_grp" value="${conditionGroup}"/>
   </#if>
   <span class="ui-widget">
-    <select name="${name?default("")}<#rt/>" <@renderClass className alert /><#if id?has_content> id="${id}"</#if><#if multiple?has_content> multiple="multiple"</#if><#if otherFieldSize gt 0> onchange="process_choice(this,document.${formName}.${otherFieldName})"</#if><#if event?has_content> ${event}="${action}"</#if><#if size?has_content> size="${size}"</#if><#if tabindex?has_content> tabindex="${tabindex}"</#if><#rt/>>
+    <select name="${name?default("")}<#rt/>" <@renderClass className alert /><#if id?has_content> id="${id}"</#if><#if multiple?has_content> multiple="multiple"</#if><#if ajaxEnabled> class="autoCompleteDropDown"</#if><#if event?has_content> ${event}="${action}"</#if><#if size?has_content> size="${size}"</#if><#if tabindex?has_content> tabindex="${tabindex}"</#if><#rt/>
+    <#if otherFieldName?has_content>
+    data-other-field-name="${otherFieldName}"
+    data-other-field-value='${otherValue?js_string}'
+    data-other-field-size='${otherFieldSize}'
+    </#if>>
       <#if firstInList?has_content && currentValue?has_content && !multiple?has_content>
         <option selected="selected" value="${currentValue}">${explicitDescription?replace("&#x5c;&#x27;","&#x27;")}</option><#rt/><#-- replace("&#x5c;&#x27;","&#x27;") related to OFBIZ-6504 -->
       </#if>
@@ -165,23 +170,6 @@ under the License.
   </span>
   <#if otherFieldName?has_content>
     <noscript><input type='text' name='${otherFieldName}' /></noscript>
-    <script type='application/javascript'><!--
-      disa = ' disabled';
-      if(other_choice(document.${formName}.${fieldName}))
-        disa = '';
-      document.write("<input type='text' name='${otherFieldName}' value='${otherValue?js_string}' size='${otherFieldSize}'"+disa+" onfocus='check_choice(document.${formName}.${fieldName})' />");
-      if(disa && document.styleSheets)
-      document.${formName}.${otherFieldName}.style.visibility  = 'hidden';
-    //--></script>
-  </#if>
-
-  <#if ajaxEnabled>
-    <script type="application/javascript">
-      ajaxAutoCompleteDropDown();
-      jQuery(function() {
-        jQuery("#${id}").combobox();
-      });
-    </script>
   </#if>
 </#macro>
 

Modified: ofbiz/ofbiz-framework/branches/release18.12/themes/common-theme/webapp/common/js/util/OfbizUtil.js
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/themes/common-theme/webapp/common/js/util/OfbizUtil.js?rev=1856611&r1=1856610&r2=1856611&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/themes/common-theme/webapp/common/js/util/OfbizUtil.js (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/themes/common-theme/webapp/common/js/util/OfbizUtil.js Sat Mar 30 08:03:53 2019
@@ -25,6 +25,8 @@ var AJAX_REQUEST_TIMEOUT = 5000;
 
 // Add observers on DOM ready.
 $(document).ready(function() {
+    //initializing UI combobox dropdown by overriding its methods.
+    ajaxAutoCompleteDropDown();
     // bindObservers will add observer on passed html section when DOM is ready.
     bindObservers("body");
 });
@@ -63,6 +65,30 @@ function bindObservers(bind_element) {
         var mask = element.data('mask');
         element.mask(mask);
     });
+    jQuery(bind_element).find('.autoCompleteDropDown').each(function(){
+        jQuery(this).combobox();
+    });
+    jQuery(bind_element).find('[data-other-field-name]').each(function(){
+        var element = jQuery(this);
+        var otherFieldName = element.data("other-field-name");
+        var otherFieldValue = element.data("other-field-value");
+        var otherFieldSize = element.data("other-field-size");
+        var disabled = true;
+        if(other_choice(this))
+            disabled = false;
+        var $input = jQuery("<input>", {type: "text", name: otherFieldName})
+            .attr("size", otherFieldSize)
+            .val(otherFieldValue)
+            .on("focus", function(e){
+                check_choice(element);
+            })
+            .css('visibility', 'hidden');
+            $input.prop("disabled", disabled);
+        $input.insertAfter(element.closest(".ui-widget"));
+        element.on("change", function(e) {
+            process_choice(element[0], $input);
+        })
+    });
     jQuery(bind_element).find(".visual-editor").each(function(){
         var element = jQuery(this);
         var toolbar = element.data('toolbar');
@@ -830,6 +856,13 @@ function ajaxAutoCompleteDropDown() {
                         });
                     },
                     change: function( event, ui ) {
+                        var element = jQuery(this);
+                        if (element.data('other-field-name') != undefined) {
+                            var otherField = (element.form()).find("input[name=" + element.data('other-field-name') + "]");
+                            if (otherField != undefined) {
+                                process_choice(element, jQuery(otherField));
+                            }
+                        }
                         if ( !ui.item ) {
                             var matcher = new RegExp( "^" + jQuery.ui.autocomplete.escapeRegex( jQuery(this).val() ) + "$", "i" ),
                                 valid = false;

Modified: ofbiz/ofbiz-framework/branches/release18.12/themes/common-theme/webapp/common/js/util/combobox.js
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/branches/release18.12/themes/common-theme/webapp/common/js/util/combobox.js?rev=1856611&r1=1856610&r2=1856611&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/branches/release18.12/themes/common-theme/webapp/common/js/util/combobox.js (original)
+++ ofbiz/ofbiz-framework/branches/release18.12/themes/common-theme/webapp/common/js/util/combobox.js Sat Mar 30 08:03:53 2019
@@ -18,26 +18,21 @@
  */
 
 function other_choice(dropDown) {
-    opt = dropDown.options[dropDown.selectedIndex];
-    ret = false;
-    if (opt.value == "_OTHER_") ret = true;
-    return ret;
+    var optValue = jQuery(dropDown).children("option:selected").val();
+    return optValue == "_OTHER_";
 }
 
 function activate(field) {
-  field.disabled=false;
-  if(document.styleSheets)field.style.visibility  = 'visible';
-  field.focus();
+  field.prop("disabled",false)
+      .css('visibility', 'visible')
+      .focus();
 }
 
 function process_choice(selection,textfield) {
-  b = other_choice(selection);
-  if(b) {
-    activate(textfield); }
-  else {
-    textfield.disabled = true;
-    if(document.styleSheets)textfield.style.visibility  = 'hidden';
-    textfield.value = '';
+  if(other_choice(selection)) {
+    activate(textfield);
+  } else {
+    textfield.prop("disabled", true).val('').css('visibility', 'hidden');
   }
 }