details:   https://code.openbravo.com/erp/devel/pi/rev/f5556ad1abb1
changeset: 18154:f5556ad1abb1
user:      David Baz Fayos <david.baz <at> openbravo.com>
date:      Mon Oct 08 13:43:19 2012 +0200
summary:   Fixed issue 16300: Now filter date fields have the same behavior
than regular date fields

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-minidaterange.js
                                      |  62 ++++++++-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js
                                                  |   6 +
 
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/Default/org.openbravo.client.application/ob-form-styles.css
 |   8 +-
 
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/Default/org.openbravo.client.application/ob-form-styles.js
  |   2 +
 4 files changed, 68 insertions(+), 10 deletions(-)

diffs (162 lines):

diff -r 5ccb51bce128 -r f5556ad1abb1 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-minidaterange.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-minidaterange.js
       Thu Oct 04 10:21:53 2012 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-minidaterange.js
       Mon Oct 08 13:43:19 2012 +0200
@@ -76,17 +76,49 @@
     }
   },
 
+  validateOnExit: true,
+  showErrorIcon: false,
+
+  validateRelativeDateItem: function (value) {
+    var isADate = Object.prototype.toString.call(value) === '[object Date]';
+    if (value === null || isADate) {
+      this.editor.items[0].textBoxStyle = 
this.editor.items[0].textBoxStyleNormal;
+      this.editor.items[0].redraw();
+      return true;
+    } else {
+      this.editor.items[0].textBoxStyle = 
this.editor.items[0].textBoxStyleError;
+      this.editor.items[0].redraw();
+      return false;
+    }
+  },
+
+  validators: [{
+    type: 'custom',
+    condition: function (item, validator, value) {
+      return item.validateRelativeDateItem(value);
+    }
+  }],
+
   blur: function () {
     var blurValue = this.blurValue(),
+        newBlurValue = '',
         digitRegExp = new RegExp('^\\d+$', 'gm'),
-        areOnlyDigits = digitRegExp.test(blurValue),
-        newValue;
+        newValue, i;
 
-    if (areOnlyDigits) {
-      if (!this.areDateItemPropertiesSet) {
-        this.addDateItemProperties();
-        this.areDateItemPropertiesSet = true;
+    if (!this.areDateItemPropertiesSet) {
+      this.addDateItemProperties();
+      this.areDateItemPropertiesSet = true;
+    }
+
+    // Remove all kind of separators of the input value
+    for (i = 0; i < blurValue.length; i++) {
+      if (!this.isSeparator(blurValue, i)) {
+        newBlurValue += blurValue[i];
       }
+    }
+
+    // If are only digits/numbers
+    if (digitRegExp.test(newBlurValue)) {
       newValue = this.parseValue();
       if (newValue) {
         this.setValue(OB.Utilities.Date.OBToJS(newValue, this.dateFormat));
@@ -152,13 +184,25 @@
   initWidget: function () {
     this.Super('initWidget', arguments);
     this.rangeForm.setFocusItem(this.rangeItem);
+
+    var fromField = this.rangeForm.items[0].fromField,
+        toField = this.rangeForm.items[0].toField;
+    this.clearButton.click = function () {
+      this.creator.clearValues();
+      fromField.validate();
+      toField.validate();
+    };
   },
 
   show: function () {
     this.Super('show', arguments);
-    this.rangeForm.items[0].fromField.calculatedDateField.canFocus = false;
-    this.rangeForm.items[0].toField.calculatedDateField.canFocus = false;
-    this.rangeForm.items[0].fromField.valueField.focusInItem();
+    var fromField = this.rangeForm.items[0].fromField,
+        toField = this.rangeForm.items[0].toField;
+    fromField.calculatedDateField.canFocus = false;
+    fromField.validate();
+    toField.calculatedDateField.canFocus = false;
+    toField.validate();
+    fromField.valueField.focusInItem();
     this.rangeForm.focus();
   },
 
diff -r 5ccb51bce128 -r f5556ad1abb1 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js
   Thu Oct 04 10:21:53 2012 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js
   Mon Oct 08 13:43:19 2012 +0200
@@ -115,6 +115,12 @@
   var minutes = dateFormat.indexOf('%M') !== -1 ? 
OBDate.substring(dateFormat.indexOf('%M'), dateFormat.indexOf('%M') + 2) : 0;
   var seconds = dateFormat.indexOf('%S') !== -1 ? 
OBDate.substring(dateFormat.indexOf('%S'), dateFormat.indexOf('%S') + 2) : 0;
 
+  // Check that really all date parts (if they are present) are numbers
+  var digitRegExp = ['^\\d+$', 'gm'];
+  if ((year && !(new RegExp(digitRegExp[0], digitRegExp[1]).test(year))) || 
(fullYear && !(new RegExp(digitRegExp[0], digitRegExp[1]).test(fullYear))) || 
(month && !(new RegExp(digitRegExp[0], digitRegExp[1]).test(month))) || (day && 
!(new RegExp(digitRegExp[0], digitRegExp[1]).test(day))) || (hours && !(new 
RegExp(digitRegExp[0], digitRegExp[1]).test(hours))) || (minutes && !(new 
RegExp(digitRegExp[0], digitRegExp[1]).test(minutes))) || (seconds && !(new 
RegExp(digitRegExp[0], digitRegExp[1]).test(seconds)))) {
+    return null;
+  }
+
   month = parseInt(month, 10);
   day = parseInt(day, 10);
   hours = parseInt(hours, 10);
diff -r 5ccb51bce128 -r f5556ad1abb1 
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/Default/org.openbravo.client.application/ob-form-styles.css
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/Default/org.openbravo.client.application/ob-form-styles.css
  Thu Oct 04 10:21:53 2012 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/Default/org.openbravo.client.application/ob-form-styles.css
  Mon Oct 08 13:43:19 2012 +0200
@@ -107,6 +107,7 @@
 .OBFormFieldSelectInputDisabled,
 .OBFormFieldSelectInputFocused,
 .OBFormFieldSelectInputError,
+.OBFormFieldSelectInputErrorFocused,
 .OBFormFieldSelectInputHint,
 
 .OBFormFieldSelectInputPending,
@@ -194,6 +195,7 @@
 
 .OBFormFieldSelectInput,
 .OBFormFieldSelectInputError,
+.OBFormFieldSelectInputErrorFocused,
 .OBFormFieldSelectInputFocused,
 .OBFormFieldSelectInputHint,
 
@@ -268,6 +270,7 @@
 .OBFormFieldNumberInputRequiredError,
 .OBFormFieldInputError,
 .OBFormFieldSelectInputError,
+.OBFormFieldSelectInputErrorFocused,
 .OBFormFieldDateInputError,
 .OBFormFieldLabelError { 
   color: red; /*#204268;*/
@@ -317,7 +320,9 @@
 .OBFormFieldDateInputSelectedFocused
 .OBFormFieldNumberInput:focus,
 .OBFormFieldNumberInputFocused,
-.OBFormFieldNumberInputSelectedFocused {
+.OBFormFieldNumberInputSelectedFocused,
+.OBFormFieldSelectInputError:focus,
+.OBFormFieldSelectInputErrorFocused {
   -moz-outline-offset: -1;
   outline-offset: -1;
   outline: none;
@@ -326,6 +331,7 @@
 
 .OBFormFieldSelectInput,
 .OBFormFieldSelectInputError,
+.OBFormFieldSelectInputErrorFocused,
 .OBFormFieldSelectInputSelectedFocused,
 .OBFormFieldSelectInputFocused,
 .OBFormFieldSelectInputDisabled,
diff -r 5ccb51bce128 -r f5556ad1abb1 
modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/Default/org.openbravo.client.application/ob-form-styles.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/Default/org.openbravo.client.application/ob-form-styles.js
   Thu Oct 04 10:21:53 2012 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.userinterface.smartclient/openbravo/skins/Default/org.openbravo.client.application/ob-form-styles.js
   Mon Oct 08 13:43:19 2012 +0200
@@ -428,6 +428,8 @@
   cellStyle: 'OBFormField',
   titleStyle: 'OBFormFieldLabel',
   textBoxStyle: 'OBFormFieldSelectInput',
+  textBoxStyleNormal: 'OBFormFieldSelectInput',
+  textBoxStyleError: 'OBFormFieldSelectInputError',
   controlStyle: 'OBFormFieldSelectControl',
   pickerIconSrc: OB.Styles.skinsPath + 
'Default/org.openbravo.client.application/images/form/comboBoxPicker.png',
   pickerIconWidth: 21,

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to