details:   http://code.openbravo.com/erp/devel/cyclone/rev/489a3ebd767c
changeset: 4594:489a3ebd767c
user:      David Baz Fayos <david.baz <at> openbravo.com>
date:      Thu Aug 13 19:22:42 2009 +0200
summary:   [Numberformat] Added documentation to new utils.js functions

diffstat:

 web/js/utils.js |  1229 
+++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 696 insertions(+), 533 deletions(-)

diffs (truncated from 1262 to 300 lines):

diff -r 470433e0bb28 -r 489a3ebd767c web/js/utils.js
--- a/web/js/utils.js   Thu Aug 13 19:26:23 2009 +0200
+++ b/web/js/utils.js   Thu Aug 13 19:22:42 2009 +0200
@@ -3954,562 +3954,725 @@
 
   // Numeric formatting functions
 
+/**
+* Returns the global decimal separator
+* @returns The global decimal separator
+* @type String
+*/
 function getGlobalDecSeparator() {
   var m = getFrame('frameMenu');
   return m.decSeparator_global;
 }
 
+/**
+* Returns the global group separator
+* @returns The global group separator
+* @type String
+*/
 function getGlobalGroupSeparator() {
   var m = getFrame('frameMenu');
   return m.groupSeparator_global;
 }
 
+/**
+* Returns the global group interval
+* @returns The global group interval
+* @type String
+*/
 function getGlobalGroupInterval() {
   var m = getFrame('frameMenu');
   return m.groupInterval_global;
 }
 
-  function isJavaMask() {
-    var isJavaMask = true;
-    return isJavaMask;
-  }
-
-  function getDefaultMaskNumeric() {
-    var m = getFrame('frameMenu');
-    var maskNumeric_default = m.maskNumeric_default;
-    if (isJavaMask()) {
-      decSeparator = getGlobalDecSeparator();
-      groupSeparator = getGlobalGroupSeparator();
-      maskNumeric_default = returnMaskChange(maskNumeric_default, ".", ",", 
decSeparator, groupSeparator);
-    }
-    return maskNumeric_default;
-  }
-
+/**
+* Returns a boolean specifing if the returned mask is in java format ("," for 
group separator and "." for decimal separator)
+* @returns True since returned masks are always in java format
+* @type Boolean
+*/
+function isJavaMask() {
+  var isJavaMask = true;
+  return isJavaMask;
+}
+
+/**
+* Returns the default mask numeric
+* @returns The default mask numeric
+* @type String
+*/
+function getDefaultMaskNumeric() {
+  var m = getFrame('frameMenu');
+  var maskNumeric_default = m.maskNumeric_default;
+  if (isJavaMask()) {
+    decSeparator = getGlobalDecSeparator();
+    groupSeparator = getGlobalGroupSeparator();
+    maskNumeric_default = returnMaskChange(maskNumeric_default, ".", ",", 
decSeparator, groupSeparator);
+  }
+  return maskNumeric_default;
+}
+
+/**
+* Return the mask needed in a given input
+* @param {Object} obj The input to obtain the mask
+* @returns The mask of the input
+* @type String
+*/
   function getInputNumberMask(obj) {
     var outputformat = obj.getAttribute('outputformat');
     outputformat = formatNameToMask(outputformat);
     return outputformat;
   }
 
-  /**
-   * Returns the output format for a given format defined in Format.xml
-   * @param formatName One of the defined format names in Format.xml
-   * @return The outputFormat for the formatName
-   */
-  function formatNameToMask(formatName) {
-    var maskNumeric = "";
-    var decSeparator = "";
-    var groupSeparator = "";
-    var F = getFrame('frameMenu').F;
-    if(typeof F === 'undefined') {
-        return maskNumeric;
-    }
-    if(formatName == null || formatName == "" || formatName == "null") {
-      formatName = "qtyEdition";
-    }
-    maskNumeric = F.getFormat(formatName);
-    if (isJavaMask()) {
-      //decSeparator = F.getDecSeparator(formatName);
-      //groupSeparator = F.getGroupSeparator(formatName);
-      decSeparator = getGlobalDecSeparator();
-      groupSeparator = getGlobalGroupSeparator();
-      maskNumeric = returnMaskChange(maskNumeric, ".", ",", decSeparator, 
groupSeparator);
-    }
-    return maskNumeric;
-  }
-
-  function focusNumberInput(obj, maskNumeric, decSeparator, groupSeparator, 
groupInterval) {
-    if (maskNumeric == null || maskNumeric == "") maskNumeric = 
getDefaultMaskNumeric();
-    if (decSeparator == null || decSeparator == "") decSeparator = 
getGlobalDecSeparator();
-    if (groupSeparator == null || groupSeparator == "") groupSeparator = 
getGlobalGroupSeparator();
-    if (groupInterval == null || groupInterval == "") groupInterval = 
getGlobalGroupInterval();
-
-    var oldCaretPosition = getCaretPosition(obj).start;
-    var newCaretPosition = returnNewCaretPosition(obj, oldCaretPosition, 
groupSeparator);
-
-    var number = obj.value;
-    var isValid = checkNumber(number, maskNumeric, decSeparator, 
groupSeparator, groupInterval);
-    if (!isValid) {
-      return false;
-    }
-    var plainNumber = returnPlainNumber(number, decSeparator, groupSeparator);
-    obj.value = plainNumber;
-    setCaretToPos(obj, newCaretPosition);
-  }
-
-  function returnNewCaretPosition(obj, oldCaretPosition, groupSeparator) {
-    var newCaretPosition = oldCaretPosition;
-    for (var i=oldCaretPosition; i>0; i--) {
-      if (obj.value.substring(i-1, i) == groupSeparator) {
-        newCaretPosition = newCaretPosition - 1;
-      }
-    }
-    return newCaretPosition;
-  }
-
-  function returnPlainNumber(number, decSeparator, groupSeparator) {
-    number = number.toString();
-    var plainNumber = number;
-
-    // Remove group separators
-    var groupRegExp = new RegExp("\\" + groupSeparator,"g");
-    plainNumber = plainNumber.replace(groupRegExp,"");
-
-    // Catch sign
-    var numberSign = "";
-    if (plainNumber.substring(0, 1) == "+") {
-      numberSign = "";
-      plainNumber = plainNumber.substring(1, number.length);
-    } else if (plainNumber.substring(0, 1) == "-") {
-      numberSign = "-";
-      plainNumber = plainNumber.substring(1, number.length);
-    }
-
-    // Remove ending decimal "0"
-    if (plainNumber.indexOf(decSeparator) != -1) {
-      while (plainNumber.substring(plainNumber.length-1, plainNumber.length) 
== "0") {
-        plainNumber = plainNumber.substring(0, plainNumber.length-1);
-      }
-    }
-
-    //Remove starting integer "0"
-    while (plainNumber.substring(0, 1) == "0" && plainNumber.substring(1, 2) 
!= decSeparator && plainNumber.length > 1) {
-      plainNumber = plainNumber.substring(1, plainNumber.length);
-    }
-
-    // Remove decimal separator if is the last character
-    if (plainNumber.substring(plainNumber.length-1, plainNumber.length) == 
decSeparator) {
+/**
+ * Returns the output format for a given format defined in Format.xml
+ * @param (String) formatName One of the defined format names in Format.xml
+ * @return The outputFormat for the formatName
+ * @type String
+*/
+function formatNameToMask(formatName) {
+  var maskNumeric = "";
+  var decSeparator = "";
+  var groupSeparator = "";
+  var F = getFrame('frameMenu').F;
+  if(typeof F === 'undefined') {
+      return maskNumeric;
+  }
+  if(formatName == null || formatName == "" || formatName == "null") {
+    formatName = "qtyEdition";
+  }
+  maskNumeric = F.getFormat(formatName);
+  if (isJavaMask()) {
+    //decSeparator = F.getDecSeparator(formatName);
+    //groupSeparator = F.getGroupSeparator(formatName);
+    decSeparator = getGlobalDecSeparator();
+    groupSeparator = getGlobalGroupSeparator();
+    maskNumeric = returnMaskChange(maskNumeric, ".", ",", decSeparator, 
groupSeparator);
+  }
+  return maskNumeric;
+}
+
+/**
+* Actions to be done when focusing a numeric input
+* @param {Object} obj The focused input
+* @param {String} maskNumeric The numeric mask of the input
+* @param {String} decSeparator The decimal separator of the input
+* @param {String} groupSeparator The group separator of the input
+* @param {String} groupInterval The group interval of the input
+*/
+function focusNumberInput(obj, maskNumeric, decSeparator, groupSeparator, 
groupInterval) {
+  if (maskNumeric == null || maskNumeric == "") maskNumeric = 
getDefaultMaskNumeric();
+  if (decSeparator == null || decSeparator == "") decSeparator = 
getGlobalDecSeparator();
+  if (groupSeparator == null || groupSeparator == "") groupSeparator = 
getGlobalGroupSeparator();
+  if (groupInterval == null || groupInterval == "") groupInterval = 
getGlobalGroupInterval();
+
+  var oldCaretPosition = getCaretPosition(obj).start;
+  var newCaretPosition = returnNewCaretPosition(obj, oldCaretPosition, 
groupSeparator);
+
+  var number = obj.value;
+  var isValid = checkNumber(number, maskNumeric, decSeparator, groupSeparator, 
groupInterval);
+  if (!isValid) {
+    return false;
+  }
+  var plainNumber = returnPlainNumber(number, decSeparator, groupSeparator);
+  obj.value = plainNumber;
+  setCaretToPos(obj, newCaretPosition);
+}
+
+/**
+* Function to calculate the new caret position when an input is focused and 
the display format is changed
+* @param {Object} obj The input
+* @param {String} oldCaretPosition The caret position before the format change
+* @param {String} groupSeparator The group separator of the input
+* @return The new caret position
+* @type Number
+*/
+function returnNewCaretPosition(obj, oldCaretPosition, groupSeparator) {
+  var newCaretPosition = oldCaretPosition;
+  for (var i=oldCaretPosition; i>0; i--) {
+    if (obj.value.substring(i-1, i) == groupSeparator) {
+      newCaretPosition = newCaretPosition - 1;
+    }
+  }
+  return newCaretPosition;
+}
+
+/**
+* Function that returns a number just with the decimal Separator
+* @param {String} number The formatted number
+* @param {String} decSeparator The decimal separator of the input
+* @param {String} groupSeparator The group separator of the input
+* @return The plain number
+* @type String
+*/
+function returnPlainNumber(number, decSeparator, groupSeparator) {
+  number = number.toString();
+  var plainNumber = number;
+
+  // Remove group separators
+  var groupRegExp = new RegExp("\\" + groupSeparator,"g");
+  plainNumber = plainNumber.replace(groupRegExp,"");
+
+  // Catch sign
+  var numberSign = "";
+  if (plainNumber.substring(0, 1) == "+") {
+    numberSign = "";
+    plainNumber = plainNumber.substring(1, number.length);
+  } else if (plainNumber.substring(0, 1) == "-") {
+    numberSign = "-";
+    plainNumber = plainNumber.substring(1, number.length);
+  }
+
+  // Remove ending decimal "0"
+  if (plainNumber.indexOf(decSeparator) != -1) {
+    while (plainNumber.substring(plainNumber.length-1, plainNumber.length) == 
"0") {
       plainNumber = plainNumber.substring(0, plainNumber.length-1);
     }
-
-    // Re-set sign
-    if (plainNumber != "0") {
-      plainNumber = numberSign + plainNumber;
-    }
-
-    //Return plain number
-    return plainNumber;
-  }
-
-  function returnFormattedToCalc(number, decSeparator, groupSeparator) {
-    var calcNumber = number;
-    calcNumber = returnPlainNumber(calcNumber, decSeparator, groupSeparator);
-    calcNumber = calcNumber.replace(decSeparator, '.');
-    return calcNumber;
-  }
-

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to