# HG changeset patch
# User Asier Lostalé <asier.lostale@openbravo.com>
# Date 1322131625 -3600
# Node ID 5b127af64bada09444c9ba6e4e913042452a8e10
# Parent  a281ac41f2b409df4462ff8943f5e847c66869c7
fixed bug 18561: Time reference showed incorrectly in Process Request window

Setting isc.DataSource.serializeTimeAsDatetime=true so time references are sent as complete
UTC date time rather than just truncating timezone information.

Formatting it properly in the FIC response.

diff -r a281ac41f2b4 -r 5b127af64bad modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-time.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-time.js	Wed Nov 23 18:32:11 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-time.js	Thu Nov 24 11:47:05 2011 +0100
@@ -30,16 +30,26 @@
   shortTimeFormat: 'HH:MM:SS',
   long24TimeFormat: 'HH:MM:SS',
   longTimeFormat: 'HH:MM:SS',
+ 
   
   // make sure that the undo/save buttons get enabled, needs to be done like
-  // this because changeOnKeypress is false
+  // this because changeOnKeypress is false. Activating changeOnKeypress makes the
+  // item not editable as it is reformatted on keyStroke, the same happens calling
+  // from this method form.itemChangeActions
   keyPress: function(item, form, keyName, characterValue){
+    var i, f = this.form,
+        toolBarButtons = f.view.toolBar.leftMembers;
+    
     if (characterValue || keyName === 'Backspace' || keyName === 'Delete') {
-      if (this.form.itemChangeActions) {
-        this.form.itemChangeActions();
+      f.setHasChanged(true);
+      f.view.messageBar.hide();
+      for (i = 0; i < toolBarButtons.leftMembers.length; i++) {
+        if (toolBarButtons.leftMembers[i].updateState) {
+          toolBarButtons.leftMembers[i].updateState();
+        }
       }
     }
-    return this.Super('keyPress', arguments);
+   this.Super('keyPress', arguments);
   }
 });
 
diff -r a281ac41f2b4 -r 5b127af64bad modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Wed Nov 23 18:32:11 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Thu Nov 24 11:47:05 2011 +0100
@@ -887,7 +887,8 @@
     } else if (columnValue.value || columnValue.value === 0 || columnValue.value === false) {
       isDate = field.type &&
       (isc.SimpleType.getType(field.type).inheritsFrom === 'date' ||
-      isc.SimpleType.getType(field.type).inheritsFrom === 'datetime');
+      isc.SimpleType.getType(field.type).inheritsFrom === 'datetime' ||
+      isc.SimpleType.getType(field.type).inheritsFrom === 'time');
       if (isDate) {
         this.setItemValue(field.name, isc.Date.parseSchemaDate(columnValue.value));
       } else if(columnValue.hasDateDefault){
diff -r a281ac41f2b4 -r 5b127af64bad modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/TimeUIDefinition.java
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/TimeUIDefinition.java	Wed Nov 23 18:32:11 2011 +0100
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/TimeUIDefinition.java	Thu Nov 24 11:47:05 2011 +0100
@@ -31,7 +31,7 @@
  */
 public class TimeUIDefinition extends UIDefinition {
   private SimpleDateFormat classicFormat = null;
-  private SimpleDateFormat xmlTimeFormat = JsonUtils.createTimeFormat();
+  private SimpleDateFormat xmlTimeFormat = JsonUtils.createJSTimeFormat();
 
   @Override
   public String getParentType() {
@@ -72,15 +72,9 @@
       if (value == null || value.length() == 0 || value.equals("null")) {
         return null;
       }
-      // sometimes the default value gets passed which is already in the correct
-      // format, in that case just use that.
-      if (value.indexOf(":") == 2 && value.indexOf(":", 3) == 5) {
-        if (!value.contains("+") && !value.contains("-")) {
-          return value + "+00:00";
-        }
-        return value;
-      }
+
       final java.util.Date date = getClassicFormat().parse(value);
+
       return xmlTimeFormat.format(date);
     } catch (Exception e) {
       throw new OBException("Exception when handling value " + value, e);
diff -r a281ac41f2b4 -r 5b127af64bad modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonUtils.java
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonUtils.java	Wed Nov 23 18:32:11 2011 +0100
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonUtils.java	Thu Nov 24 11:47:05 2011 +0100
@@ -70,6 +70,17 @@
   }
 
   /**
+   * @return a new instance of the {@link SimpleDateFormat} using a format of yyyy-MM-dd'T'HH:mm:ss
+   *         (see http://www.w3.org/TR/xmlschema-2/#dateTime). The date format has lenient set to
+   *         true.
+   */
+  public static SimpleDateFormat createJSTimeFormat() {
+    final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+    dateFormat.setLenient(true);
+    return dateFormat;
+  }
+
+  /**
    * Note the formatted date string must be repaired in the timezone to follow the XSD format, see:
    * {@link #convertToCorrectXSDFormat(String)}.
    * 
diff -r a281ac41f2b4 -r 5b127af64bad modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js
--- a/modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js	Wed Nov 23 18:32:11 2011 +0100
+++ b/modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js	Thu Nov 24 11:47:05 2011 +0100
@@ -31,6 +31,8 @@
 // NOTE: disabled as now timezone is send from the client to the server
 // Time.setDefaultDisplayTimezone(0);
 
+isc.DataSource.serializeTimeAsDatetime=true;
+
 isc.Canvas.addProperties({
   
   // make sure that the datasources are also destroyed
