details: https://code.openbravo.com/erp/devel/main/rev/55e501dad3b7 changeset: 15711:55e501dad3b7 user: Augusto Mauch <augusto.mauch <at> openbravo.com> date: Wed Mar 21 18:21:23 2012 +0100 summary: Fixes issue 20071: Now autosave will work when focus is in a date field
The ob-formitem-date.js now overwrites the blur method in order to make sure that its value is updated when the autosave is done. details: https://code.openbravo.com/erp/devel/main/rev/0a30d7aaaed2 changeset: 15712:0a30d7aaaed2 user: Augusto Mauch <augusto.mauch <at> openbravo.com> date: Thu Mar 22 18:18:00 2012 +0100 summary: Fixes issue 20071: Autosave with date field focus works both in grid and form view The previous fix only achieved to fix the issue when the change of tab was done while the date field was focus in the form view. Now it also works if it is focused in grid view. This solution works for date fields that have callouts and for date fields that do not. Additional changes have been made to allow to save a date multiple times in a row. diffstat: modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-date.js | 58 +++++++-- modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js | 4 + 2 files changed, 48 insertions(+), 14 deletions(-) diffs (117 lines): diff -r f5fe379ed93a -r 0a30d7aaaed2 modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-date.js --- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-date.js Wed Mar 21 11:40:03 2012 +0100 +++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-date.js Thu Mar 22 18:18:00 2012 +0100 @@ -79,6 +79,24 @@ this.Super('init', arguments); + if (this.textField) { + this.textField.changed = function () { + // when the textfield of the date is updated, the date + // field should be flagged as changed + // see issue 20071 (https://issues.openbravo.com/view.php?id=20071) + this._textChanged = true; + this.parentItem._hasChanged = true; + // There is a mechanism to prevent infinite looping in number fields + // (see issue https://issues.openbravo.com/view.php?id=17290) that + // interferes with the correct behaviour of the date fields + // The infinite looping described in the issue does not apply to date fields, + // so it is safe to delete the saveFocusItemChanged flag when a date is modified + if (this.parentItem.form && this.parentItem.form.view && this.parentItem.form.view.viewForm) { + delete this.parentItem.form.view.viewForm.saveFocusItemChanged; + } + }; + } + if (this.showDisabled === false) { this.textField.showDisabled = false; } @@ -91,15 +109,14 @@ parseValue: function () { var i, str = this.blurValue(), - length = str.length, - parts = ['', '', ''], + length, parts = ['', '', ''], partIndex = 0, result; if (!str || isc.isA.Date(str) || str.replace(/0/g, '') === '') { return str; } - + length = str.length; for (i = 0; i < length; i++) { if (this.isNumber(str, i)) { if (this.reachedLength(parts[partIndex], partIndex)) { @@ -177,8 +194,10 @@ pickerDataChanged: function (picker) { this.Super('pickerDataChanged', arguments); + // update the date field after picking a new date + this.textField._textChanged = true; + this.updateValue(); if (this.form.focusInNextItem) { - if (this.form.handleItemChange) { this._hasChanged = true; this.form.handleItemChange(this); @@ -207,22 +226,33 @@ }, // update the value in update value as this is called from cellEditEnd in the - // grid, or after losing the focus on the form + // grid, after losing the focus on the form and when autosaving updateValue: function () { - if (this.grid && this.grid._preventDateParsing) { + if (this.grid && this.grid._preventDateParsing && !this.grid._autoSaving) { return; } - this.expandValue(); - this.Super('updateValue', arguments); - // when the date field has a callout and all the mandatory fields have been entered, - // the grid does not save the value before making the FIC call, so the value has to - // be saved explicitly - // See issue 19694 (https://issues.openbravo.com/view.php?id=19694) - if (this.grid) { - this.grid.getEditValues(this.grid.getEditRow())[this.name] = this.getValue(); + if (this.textField._textChanged) { + this.expandValue(); + this.Super('updateValue', arguments); + // when the date field has a callout and all the mandatory fields have been entered, + // the grid does not save the value before making the FIC call, so the value has to + // be saved explicitly + // See issue 19694 (https://issues.openbravo.com/view.php?id=19694) + if (this.grid && this.grid.getEditRow()) { + this.grid.getEditValues(this.grid.getEditRow())[this.name] = this.getValue(); + } + this.textField._textChanged = false; } }, + blur: function () { + // force the update of the date when its field loses the focus + // it has to be done before the call to the super because the + // date should be updated before calling handleItemChange, + // which is called in the super blur + this.updateValue(); + this.Super('blur', arguments); + }, blurValue: function () { return this.dateTextField.getElementValue(); diff -r f5fe379ed93a -r 0a30d7aaaed2 modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js --- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js Wed Mar 21 11:40:03 2012 +0100 +++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js Thu Mar 22 18:18:00 2012 +0100 @@ -2164,7 +2164,11 @@ }, autoSave: function () { + // flag to force the parsing of date fields when autosaving + // see issue 20071 (https://issues.openbravo.com/view.php?id=20071) + this._autoSaving = true; this.storeUpdatedEditorValue(); + delete this._autoSaving; this.endEditing(); }, ------------------------------------------------------------------------------ This SF email is sponsosred by: Try Windows Azure free for 90 days Click Here http://p.sf.net/sfu/sfd2d-msazure _______________________________________________ Openbravo-commits mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openbravo-commits
