Fixed issue 25936: Added 'javaTimeformat.java=MM-dd-yyyy hh:mm:ss a' capability
authorDavid Baz Fayos <david.baz@openbravo.com>
Thu, 15 May 2014 23:49:40 +0200
changeset 23074 43e598987eb7
parent 23073 f401b711161b
child 23075 5f805d20cad7
Fixed issue 25936: Added 'javaTimeformat.java=MM-dd-yyyy hh:mm:ss a' capability
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-datetime.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-time.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/Default/org.openbravo.client.application/ob-form-styles.css
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/AbsoluteTimeUIDefinition.java
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateUIDefinition.java
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/TimeUIDefinition.java
src/index.jsp
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-datetime.js	Tue May 20 12:22:06 2014 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-datetime.js	Thu May 15 23:49:40 2014 +0200
@@ -137,13 +137,22 @@
     } else {
       this.showPickerTimeItem = false;
     }
+    if (OB.Format.dateTime.toUpperCase().endsWith(' A')) {
+      this.use24HourTime = false;
+    } else {
+      this.use24HourTime = true;
+    }
     return this.Super('doInit', arguments);
   },
 
   parseValue: function () {
     var parseVal = this.Super('parseValue', arguments);
     if (this.showTime && parseVal.indexOf(' ') === -1) {
-      parseVal = parseVal + ' ' + '00:00:00';
+      if (this.use24HourTime) {
+        parseVal = parseVal + ' ' + '00:00:00';
+      } else {
+        parseVal = parseVal + ' ' + '12:00:00 AM';
+      }
     }
     return parseVal;
   },
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-time.js	Tue May 20 12:22:06 2014 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-time.js	Thu May 15 23:49:40 2014 +0200
@@ -30,12 +30,7 @@
   operator: 'equals',
   validateOnExit: true,
   showHint: false,
-  timeFormatter: 'to24HourTime',
-  displayFormat: 'to24HourTime',
-  short24TimeFormat: 'HH:MM:SS',
-  shortTimeFormat: 'HH:MM:SS',
-  long24TimeFormat: 'HH:MM:SS',
-  longTimeFormat: 'HH:MM:SS',
+  timeFormatter: isc.Time.displayFormat,
 
   mapValueToDisplay: function (value) {
     var newValue = value;
@@ -146,7 +141,6 @@
   init: function () {
     var oldShowHint, hint, formatDefinition = OB.Utilities.getTimeFormatDefinition();
 
-    this.timeFormatter = formatDefinition.timeFormatter;
     this.timeFormat = formatDefinition.timeFormat;
 
     this.Super('init', arguments);
@@ -573,7 +567,7 @@
       this.precission = 'hour';
     }
 
-    if (this.timeFormat.toUpperCase().indexOf('AM') !== -1 || this.timeFormat.toUpperCase().indexOf('PM') !== -1) {
+    if (this.timeFormat.toUpperCase().indexOf(isc.Time.AMIndicator) !== -1 || this.timeFormat.toUpperCase().indexOf(isc.Time.PMIndicator) !== -1) {
       this.is24hTime = false;
     }
 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js	Tue May 20 12:22:06 2014 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js	Thu May 15 23:49:40 2014 +0200
@@ -62,6 +62,9 @@
   } else if (displayFormat.indexOf(' HH.MI') !== -1) {
     newFormat += ' %H.%M';
   }
+  if (displayFormat.indexOf(' a') !== -1) {
+    newFormat += ' A';
+  }
   return newFormat;
 };
 
@@ -110,15 +113,25 @@
   }
 
   // if already a date then return true
-  var isADate = Object.prototype.toString.call(OBDate) === '[object Date]';
+  var isADate = Object.prototype.toString.call(OBDate) === '[object Date]',
+      is24h = true,
+      isPM = false;
   if (isADate) {
     return OBDate;
   }
 
   dateFormat = OB.Utilities.Date.normalizeDisplayFormat(dateFormat);
+  dateFormat = dateFormat.replace(' A', '');
   var dateSeparator = dateFormat.substring(2, 3);
   var timeSeparator = dateFormat.substring(11, 12);
   var isFullYear = (dateFormat.indexOf('%Y') !== -1);
+  if (OBDate.indexOf(isc.Time.PMIndicator) !== 1 || OBDate.indexOf(isc.Time.AMIndicator) !== 1) {
+    is24h = false;
+  }
+  if (!is24h && OBDate.indexOf(isc.Time.PMIndicator) !== -1) {
+    isPM = true;
+  }
+  OBDate = OBDate.replace(isc.Time.AMIndicator, '').replace(isc.Time.PMIndicator, '');
 
   if ((isFullYear ? OBDate.length - 2 : OBDate.length) !== dateFormat.length) {
     return null;
@@ -157,6 +170,15 @@
   minutes = parseInt(minutes, 10);
   seconds = parseInt(seconds, 10);
 
+  if (!is24h) {
+    if (!isPM && hours === 12) {
+      hours = 0;
+    }
+    if (isPM && hours !== 12) {
+      hours = hours + 12;
+    }
+  }
+
   if (day < 1 || day > 31 || month < 1 || month > 12 || year > 99 || fullYear > 9999) {
     return null;
   }
@@ -210,10 +232,15 @@
 OB.Utilities.Date.JSToOB = function (JSDate, dateFormat) {
   dateFormat = OB.Utilities.Date.normalizeDisplayFormat(dateFormat);
 
-  var isADate = Object.prototype.toString.call(JSDate) === '[object Date]';
+  var isADate = Object.prototype.toString.call(JSDate) === '[object Date]',
+      is24h = true,
+      isPM = false;
   if (!isADate) {
     return null;
   }
+  if (dateFormat.toUpperCase().endsWith(' A')) {
+    is24h = false;
+  }
 
   var year = JSDate.getYear().toString();
   var fullYear = JSDate.getFullYear().toString();
@@ -235,6 +262,20 @@
     }
   }
 
+  if (!is24h) {
+    hours = parseInt(hours, 10);
+    if (hours >= 12) {
+      isPM = true;
+    }
+    if (hours > 12) {
+      hours = hours - 12;
+    }
+    if (hours === 0) {
+      hours = 12;
+    }
+    hours = hours.toString();
+  }
+
   while (year.length < 2) {
     year = '0' + year;
   }
@@ -265,6 +306,14 @@
   OBDate = OBDate.replace('%M', minutes);
   OBDate = OBDate.replace('%S', seconds);
 
+  if (!is24h) {
+    if (isPM) {
+      OBDate = OBDate.replace(' A', isc.Time.PMIndicator);
+    } else {
+      OBDate = OBDate.replace(' A', isc.Time.AMIndicator);
+    }
+  }
+
   return OBDate;
 };
 
--- a/modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/Default/org.openbravo.client.application/ob-form-styles.css	Tue May 20 12:22:06 2014 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/Default/org.openbravo.client.application/ob-form-styles.css	Thu May 15 23:49:40 2014 +0200
@@ -156,6 +156,62 @@
   width: 100%;
 }
 
+.OBFormField .OBFormFieldDateInputRequired,
+.OBFormField .OBFormFieldDateInputRequiredFocused,
+.OBFormField .OBFormFieldDateInputRequiredDisabled,
+.OBFormField .OBFormFieldDateInputRequiredError,
+.OBFormField .OBFormFieldDateInputRequiredHint,
+
+.OBFormField .OBFormFieldDateInput,
+.OBFormField .OBFormFieldDateInputDisabled,
+.OBFormField .OBFormFieldDateInputFocused,
+.OBFormField .OBFormFieldDateInputError,
+.OBFormField .OBFormFieldDateInputHint,
+
+.OBFormFieldError .OBFormFieldDateInputRequired,
+.OBFormFieldError .OBFormFieldDateInputRequiredFocused,
+.OBFormFieldError .OBFormFieldDateInputRequiredDisabled,
+.OBFormFieldError .OBFormFieldDateInputRequiredError,
+.OBFormFieldError .OBFormFieldDateInputRequiredHint,
+
+.OBFormFieldError .OBFormFieldDateInput,
+.OBFormFieldError .OBFormFieldDateInputDisabled,
+.OBFormFieldError .OBFormFieldDateInputFocused,
+.OBFormFieldError .OBFormFieldDateInputError,
+.OBFormFieldError .OBFormFieldDateInputHint {
+  /* The date input should have a maximum width to ensure that the datepicker button is not
+     too far from the input */
+  max-width: 137px;
+}
+
+html[data-useragent*='MSIE 7.0'] .OBFormField .OBFormFieldDateInputRequired,
+html[data-useragent*='MSIE 7.0'] .OBFormField .OBFormFieldDateInputRequiredFocused,
+html[data-useragent*='MSIE 7.0'] .OBFormField .OBFormFieldDateInputRequiredDisabled,
+html[data-useragent*='MSIE 7.0'] .OBFormField .OBFormFieldDateInputRequiredError,
+html[data-useragent*='MSIE 7.0'] .OBFormField .OBFormFieldDateInputRequiredHint,
+
+html[data-useragent*='MSIE 7.0'] .OBFormField .OBFormFieldDateInput,
+html[data-useragent*='MSIE 7.0'] .OBFormField .OBFormFieldDateInputDisabled,
+html[data-useragent*='MSIE 7.0'] .OBFormField .OBFormFieldDateInputFocused,
+html[data-useragent*='MSIE 7.0'] .OBFormField .OBFormFieldDateInputError,
+html[data-useragent*='MSIE 7.0'] .OBFormField .OBFormFieldDateInputHint,
+
+html[data-useragent*='MSIE 7.0'] .OBFormFieldError .OBFormFieldDateInputRequired,
+html[data-useragent*='MSIE 7.0'] .OBFormFieldError .OBFormFieldDateInputRequiredFocused,
+html[data-useragent*='MSIE 7.0'] .OBFormFieldError .OBFormFieldDateInputRequiredDisabled,
+html[data-useragent*='MSIE 7.0'] .OBFormFieldError .OBFormFieldDateInputRequiredError,
+html[data-useragent*='MSIE 7.0'] .OBFormFieldError .OBFormFieldDateInputRequiredHint,
+
+html[data-useragent*='MSIE 7.0'] .OBFormFieldError .OBFormFieldDateInput,
+html[data-useragent*='MSIE 7.0'] .OBFormFieldError .OBFormFieldDateInputDisabled,
+html[data-useragent*='MSIE 7.0'] .OBFormFieldError .OBFormFieldDateInputFocused,
+html[data-useragent*='MSIE 7.0'] .OBFormFieldError .OBFormFieldDateInputError,
+html[data-useragent*='MSIE 7.0'] .OBFormFieldError .OBFormFieldDateInputHint {
+  /* The previous improvement is not working ok in IE7 or in IE>7 with compatibility mode enabled
+     because the datepicker button is rendered in the corner, as if the input be width: 100% */
+  max-width: none;
+}
+
 .OBFormFieldNumberInput,
 .OBFormFieldNumberInputDisabled,
 .OBFormFieldNumberInputFocused,
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/AbsoluteTimeUIDefinition.java	Tue May 20 12:22:06 2014 +0200
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/AbsoluteTimeUIDefinition.java	Thu May 15 23:49:40 2014 +0200
@@ -29,6 +29,7 @@
 import org.codehaus.jettison.json.JSONObject;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.session.OBPropertiesProvider;
+import org.openbravo.client.kernel.KernelConstants;
 import org.openbravo.client.kernel.RequestContext;
 import org.openbravo.data.Sqlc;
 import org.openbravo.model.ad.ui.Field;
@@ -71,7 +72,14 @@
   private SimpleDateFormat getClassicFormat() {
     if (classicFormat == null) {
       String dateTimeFormat = (String) OBPropertiesProvider.getInstance().getOpenbravoProperties()
-          .get("dateTimeFormat.java");
+          .get(KernelConstants.DATETIME_FORMAT_PROPERTY);
+      if (dateTimeFormat.indexOf(" a") != -1) {
+        // The value of this reference always go to/from the client in the 24h notation, so in case
+        // the dateTimeFormat.java be defined to use the 'AM/PM' notation, it should be modified to
+        // work with this reference
+        dateTimeFormat = dateTimeFormat.replace(" a", "");
+        dateTimeFormat = dateTimeFormat.replace("hh", "HH");
+      }
       if (dateTimeFormat.contains(" ")) {
         dateTimeFormat = dateTimeFormat.substring(dateTimeFormat.indexOf(" ") + 1);
       } else {
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateUIDefinition.java	Tue May 20 12:22:06 2014 +0200
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateUIDefinition.java	Thu May 15 23:49:40 2014 +0200
@@ -25,7 +25,9 @@
 
 import org.codehaus.jettison.json.JSONObject;
 import org.openbravo.base.exception.OBException;
+import org.openbravo.base.session.OBPropertiesProvider;
 import org.openbravo.client.application.Parameter;
+import org.openbravo.client.kernel.KernelConstants;
 import org.openbravo.client.kernel.RequestContext;
 import org.openbravo.model.ad.ui.Field;
 
@@ -77,10 +79,17 @@
     try {
       JSONObject o = new JSONObject(
           fieldProperties != null && fieldProperties.length() > 0 ? fieldProperties : "{}");
-      o.put("width", "50%");
       if (field != null && field.getColumn() != null) {
-        final Long length = field.getColumn().getLength();
+        Long length = field.getColumn().getLength();
         if (length != null) {
+          final String dateTimeFormat = (String) OBPropertiesProvider.getInstance()
+              .getOpenbravoProperties().get(KernelConstants.DATETIME_FORMAT_PROPERTY);
+          if (length.equals(19L) && dateTimeFormat.endsWith(" a")) {
+            // If it is a DateTime (typical length of 19) and there is also the need to show the
+            // " AM" or " PM" text, three characters more need to be added, so the length should be
+            // increased by 3
+            length += 3L;
+          }
           o.put("length", length);
         }
       }
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/TimeUIDefinition.java	Tue May 20 12:22:06 2014 +0200
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/TimeUIDefinition.java	Thu May 15 23:49:40 2014 +0200
@@ -29,6 +29,7 @@
 import org.codehaus.jettison.json.JSONObject;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.session.OBPropertiesProvider;
+import org.openbravo.client.kernel.KernelConstants;
 import org.openbravo.client.kernel.RequestContext;
 import org.openbravo.data.Sqlc;
 import org.openbravo.model.ad.ui.Field;
@@ -76,7 +77,14 @@
   private SimpleDateFormat getClassicFormat() {
     if (classicFormat == null) {
       String dateTimeFormat = (String) OBPropertiesProvider.getInstance().getOpenbravoProperties()
-          .get("dateTimeFormat.java");
+          .get(KernelConstants.DATETIME_FORMAT_PROPERTY);
+      if (dateTimeFormat.endsWith(" a")) {
+        // The value of this reference always go to/from the client in the 24h notation, so in case
+        // the dateTimeFormat.java be defined to use the 'AM/PM' notation, it should be modified to
+        // work with this reference
+        dateTimeFormat = dateTimeFormat.replace(" a", "");
+        dateTimeFormat = dateTimeFormat.replace("hh", "HH");
+      }
       if (dateTimeFormat.contains(" ")) {
         dateTimeFormat = dateTimeFormat.substring(dateTimeFormat.indexOf(" ") + 1);
       } else {
--- a/src/index.jsp	Tue May 20 12:22:06 2014 +0200
+++ b/src/index.jsp	Thu May 15 23:49:40 2014 +0200
@@ -99,6 +99,15 @@
 <script src="./web/org.openbravo.client.kernel/js/LAB.min.js"></script>
 <script src="./web/org.openbravo.client.kernel/js/BigDecimal-all-1.0.1.min.js"></script>
 
+<script>
+  (function () {
+    var b = document.documentElement;
+    b.setAttribute('data-useragent',  navigator.userAgent);
+    b.setAttribute('data-platform', navigator.platform );
+    b.className += ((!!('ontouchstart' in window) || !!('onmsgesturechange' in window))?' touch':'');
+  }());
+</script>
+
 <!-- styles used during loading -->
 <style>
   html, body {