This is an automated email from the ASF dual-hosted git repository.

pgil pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new a37d5cc  Fixed: Jgrowl label are not well retrieved showing 
'undefined' button (OFBIZ-12299)
a37d5cc is described below

commit a37d5cc5d550835bb90d63578bbd91691443bd0b
Author: Gil Portenseigne <p...@apache.org>
AuthorDate: Fri Jul 16 17:49:04 2021 +0200

    Fixed: Jgrowl label are not well retrieved showing 'undefined' button 
(OFBIZ-12299)
    
    Thanks to Xin Wang comments in https://s.apache.org/trrkk we discover
    that label retrieval through javascript are not working.
    
    One example exists, but is not functionnal and do not use jgrowl.
    
    This commit allow jgrowl use directly from javascript 
(showjGrowlMessage(...))
    while making label retrieval synchronous for Jgrowl and fromDate/thruDate 
existing
    feature.
    
    Clean up showErrorAlertLoadUiLabel that became orphan.
---
 .../common/js/plugins/date/FromThruDateCheck.js    |  12 +-
 .../webapp/common/js/util/OfbizUtil.js             | 163 ++++++++-------------
 2 files changed, 70 insertions(+), 105 deletions(-)

diff --git 
a/themes/common-theme/webapp/common/js/plugins/date/FromThruDateCheck.js 
b/themes/common-theme/webapp/common/js/plugins/date/FromThruDateCheck.js
index 4aa4b8a..1c41e0b 100644
--- a/themes/common-theme/webapp/common/js/plugins/date/FromThruDateCheck.js
+++ b/themes/common-theme/webapp/common/js/plugins/date/FromThruDateCheck.js
@@ -17,12 +17,22 @@
  * under the License.
  */
 
+var labelObject
 
 //this code needs modifications yet its specific.
 
 jQuery(document).ready( function() {
   jQuery("input[name*='fromDate']").on('focusout', checkDate);
   jQuery("input[name*='thruDate']").on('focusout', checkDate);
+  if (jQuery("input[name*='fromDate']").length !== 0) {
+    // retrieve label for date control
+    labelObject = {
+      "CommonUiLabels" : ["CommonFromDateThruDateCheck"],
+    };
+    getJSONuiLabels(labelObject, function(result){
+      labelObject   = result.responseJSON;
+    });
+  }
 });
 
 function checkDate() {
@@ -31,7 +41,7 @@ function checkDate() {
 
   if(a.val() !="" && b.val() !="") {
     if (a.val() >= b.val()) {
-      showErrorAlertLoadUiLabel("", "", "CommonUiLabels", 
"CommonFromDateThruDateCheck")
+      showjGrowlMessage(labelObject.CommonUiLabels[0], 'errorMessageJGrowl', 
true, null, null, null, "center");
     }
   }
 }
diff --git a/themes/common-theme/webapp/common/js/util/OfbizUtil.js 
b/themes/common-theme/webapp/common/js/util/OfbizUtil.js
index 847cd6f..dc5c13a 100644
--- a/themes/common-theme/webapp/common/js/util/OfbizUtil.js
+++ b/themes/common-theme/webapp/common/js/util/OfbizUtil.js
@@ -1203,50 +1203,67 @@ function submitFormDisableSubmits(form) {
 }
 
 function showjGrowl(showAllLabel, collapseLabel, hideAllLabel, jGrowlPosition, 
jGrowlWidth, jGrowlHeight, jGrowlSpeed) {
+    var contentMessages = jQuery("#content-messages");
+    if (contentMessages.length) {
+        jQuery("#content-messages").hide();
+        var errMessage = jQuery("#content-messages").html();
+        var classEvent = "";
+        var classList = jQuery("#content-messages").attr('class').split(/\s+/);
+        var stickyValue = false;
+        jQuery(classList).each(function (index) {
+            var localClass = classList[index];
+            if (localClass === "eventMessage" || localClass === 
"errorMessage") {
+                classEvent = localClass + "JGrowl";
+            }
+        });
+        if (classEvent === "errorMessageJGrowl") {
+            stickyValue = true;
+        }
+
+        if (errMessage == null || errMessage === "" || errMessage === 
undefined) {
+            // No Error Message Information is set, Error Msg Box can't be 
created
+            return;
+        }
+        showjGrowlMessage(errMessage, classEvent, stickyValue, showAllLabel, 
collapseLabel, hideAllLabel, jGrowlPosition, jGrowlWidth, jGrowlHeight, 
jGrowlSpeed);
+        contentMessages.remove();
+    }
+}
+
+function showjGrowlMessage(errMessage, classEvent, stickyValue, showAllLabel, 
collapseLabel, hideAllLabel, jGrowlPosition, jGrowlWidth, jGrowlHeight, 
jGrowlSpeed) {
+    if (!showAllLabel || !collapseLabel || !hideAllLabel) {
+        var jGrowlLabelObject = {
+            "CommonUiLabels": ["CommonHideAllNotifications", "CommonShowAll", 
"CommonCollapse"],
+        };
+        getJSONuiLabels(jGrowlLabelObject, function (result) {
+            jGrowlLabelObject = result.responseJSON.CommonUiLabels;
+        });
+
+        if (!showAllLabel) showAllLabel = jGrowlLabelObject[2];
+        if (!collapseLabel) collapseLabel = jGrowlLabelObject[1];
+        if (!hideAllLabel) hideAllLabel = jGrowlLabelObject[0];
+    }
+
     var libraryFiles = 
["/common/js/jquery/plugins/Readmore.js-master/readmore.js",
         "/common/js/jquery/plugins/jquery-jgrowl/jquery.jgrowl-1.4.6.min.js"];
     importLibrary(libraryFiles, function() {
-        var contentMessages = jQuery("#content-messages");
-        if (contentMessages.length) {
-            jQuery("#content-messages").hide();
-            var errMessage = jQuery("#content-messages").html();
-            var classEvent = "";
-            var classList = 
jQuery("#content-messages").attr('class').split(/\s+/);
-            var stickyValue = false;
-            jQuery(classList).each(function (index) {
-                var localClass = classList[index];
-                if (localClass == "eventMessage" || localClass == 
"errorMessage") {
-                    classEvent = localClass + "JGrowl";
-                }
-            });
-            if (classEvent == "errorMessageJGrowl") {
-                stickyValue = true;
-            }
+        $.jGrowl.defaults.closerTemplate = '<div class="closeAllJGrowl">' + 
hideAllLabel + '</div>';
+        if (jGrowlPosition !== null && jGrowlPosition !== undefined) 
$.jGrowl.defaults.position = jGrowlPosition;
+        $.jGrowl(errMessage, {
+            theme: classEvent, sticky: stickyValue,
+            beforeOpen: function (e, m, o) {
+                if (jGrowlWidth !== null && jGrowlWidth !== undefined) 
$(e).width(jGrowlWidth + 'px');
+                if (jGrowlHeight !== null && jGrowlHeight !== undefined) 
$(e).height(jGrowlHeight + 'px');
+            },
+            afterOpen: function (e, m) {
+                jQuery(".jGrowl-message").readmore({
+                    moreLink: '<a href="#" style="display: block; width: auto; 
padding: 0px;text-align: right; margin-top: 10px; color: #ffffff; font-size: 
0.8em">' + showAllLabel + '</a>',
+                    lessLink: '<a href="#" style="display: block; width: auto; 
padding: 0px;text-align: right; margin-top: 10px; color: #ffffff; font-size: 
0.8em">' + collapseLabel + '</a>',
 
-            if (errMessage == null || errMessage == "" || errMessage == 
undefined) {
-                // No Error Message Information is set, Error Msg Box can't be 
created
-                return;
-            }
-            $.jGrowl.defaults.closerTemplate = '<div class="closeAllJGrowl">' 
+ hideAllLabel + '</div>';
-            if (jGrowlPosition !== null && jGrowlPosition !== undefined) 
$.jGrowl.defaults.position = jGrowlPosition;
-            $.jGrowl(errMessage, {
-                theme: classEvent, sticky: stickyValue,
-                beforeOpen: function (e, m, o) {
-                    if (jGrowlWidth !== null && jGrowlWidth !== undefined) 
$(e).width(jGrowlWidth + 'px');
-                    if (jGrowlHeight !== null && jGrowlHeight !== undefined) 
$(e).height(jGrowlHeight + 'px');
-                },
-                afterOpen: function (e, m) {
-                    jQuery(".jGrowl-message").readmore({
-                        moreLink: '<a href="#" style="display: block; width: 
auto; padding: 0px;text-align: right; margin-top: 10px; color: #ffffff; 
font-size: 0.8em">' + showAllLabel + '</a>',
-                        lessLink: '<a href="#" style="display: block; width: 
auto; padding: 0px;text-align: right; margin-top: 10px; color: #ffffff; 
font-size: 0.8em">' + collapseLabel + '</a>',
-
-                        maxHeight: 75
-                    });
-                },
-                speed: jGrowlSpeed
-            });
-            contentMessages.remove();
-        }
+                    maxHeight: 75
+                });
+            },
+            speed: jGrowlSpeed
+        });
     });
 }
 
@@ -1356,6 +1373,7 @@ function getJSONuiLabels(requiredLabels, callback) {
         jQuery.ajax({
             url: "getJSONuiLabelArray",
             type: "POST",
+            async: false,
             data: {"requiredLabels" : requiredLabelsStr},
             complete: function(data) {
                 callback(data);
@@ -1380,6 +1398,7 @@ function getJSONuiLabel(uiResource, errUiLabel) {
         jQuery.ajax({
             url: "getJSONuiLabel",
             type: "POST",
+            async: false,
             data: {"requiredLabel" : requiredLabelStr},
             success: function(data) {
                 returnVal = data;
@@ -1390,70 +1409,6 @@ function getJSONuiLabel(uiResource, errUiLabel) {
 }
 
 /**
- * Opens an alert alert box with an i18n error message
- * @param errBoxTitleResource String - Can be empty
- * @param errBoxTitleLabel String - Can be empty
- * @param uiResource String - Required
- * @param errUiLabel String - Required
- */
-function showErrorAlertLoadUiLabel(errBoxTitleResource, errBoxTitleLabel, 
uiResource, errUiLabel) {
-    if (uiResource == null || uiResource == "" || uiResource == undefined || 
errUiLabel == null || errUiLabel == "" || errUiLabel == undefined) {
-        // No Label Information are set, Error Msg Box can't be created
-        return;
-    }
-
-    var labels = {};
-    var useTitle = false;
-    // title can only be set when the resource and the label are set
-    if (errBoxTitleResource != null && errBoxTitleResource != "" && 
errBoxTitleLabel != null && errBoxTitleLabel != "") {
-        // create the JSON Object
-        if (errBoxTitleResource == uiResource) {
-            labels[errBoxTitleResource] = [errBoxTitleLabel, errUiLabel];
-        } else {
-            labels[errBoxTitleResource] = [errBoxTitleLabel];
-            labels[uiResource] = [errUiLabel];
-        }
-        useTitle = true;
-    } else {
-        labels[uiResource] = [errUiLabel];
-    }
-    // request the labels
-    getJSONuiLabels(labels, function(result){
-        labels = result.responseJSON;
-    });
-
-    var errMsgBox = jQuery("#contentarea").after(jQuery("<div 
id='errorAlertBox'></div>"));
-
-    if (errMsgBox.length) {
-        errMsgBox.dialog({
-            modal: true,
-            title: function() {
-                if (useTitle) {
-                    return labels[errBoxTitleResource][0]
-                } else {
-                    return ""
-                }
-            },
-            open : function() {
-                var positionInArray = 0;
-                if (errBoxTitleResource == uiResource) {
-                    positionInArray = 1;
-                }
-                errMsgBox.html(labels[uiResource][positionInArray]);
-            },
-            buttons: {
-                Ok: function() {
-                    errMsgBox.remove();
-                    jQuery( this ).dialog( "close" );
-                }
-            }
-        });
-    } else {
-      alert(labels[uiResource][0]);
-    }
-}
-
-/**
  * Opens an alert alert box. This function is for a direct call from the ftl 
files where you can direcetly resolve youre labels
  * @param errBoxTitle String - Can be empty
  * @param errMessage String - Required - i18n Error Message

Reply via email to