details: https://code.openbravo.com/erp/devel/pi/rev/138134afe781 changeset: 25310:138134afe781 user: Augusto Mauch <augusto.mauch <at> openbravo.com> date: Mon Nov 24 13:05:08 2014 +0100 summary: Related with issue 28188: Handle better the records with validation errors
When a record is saved and it has a validation errors, its _hasValidationErrors flag is set to true. At no point this flag was set to false when the validation errors were solved (either by cancelling the changes or by saving the record again after fixing the data). Now the handling of the validation errores is done using the addRecordToValidationErrorList and removeRecordFromValidationErrorList functions. This functions not only set to true or false the _hasValidatio nErrors flag, but also keep a list of the ids of the records that have validation errors. This allows to know at any point what records have validation errors without having to iterate the whole grid local data. Also a function has been added to check if the grid has any validation errors. details: https://code.openbravo.com/erp/devel/pi/rev/bc62931cf7f8 changeset: 25311:bc62931cf7f8 user: Augusto Mauch <augusto.mauch <at> openbravo.com> date: Mon Nov 24 13:13:22 2014 +0100 summary: Related with issue 28188: Disable refresh button if grid has validation errors If any record of the grid has validation errors, disable the refresh toolbar button. If the user were to refresh the record while it had validation errors, the unsaved data would be lost. details: https://code.openbravo.com/erp/devel/pi/rev/b1d40e3d4f77 changeset: 25312:b1d40e3d4f77 user: Augusto Mauch <augusto.mauch <at> openbravo.com> date: Mon Nov 24 15:44:51 2014 +0100 summary: Related with bug 28188:Enable the Cancel button if selected record has errors The Cancel Changes toolbar button should be enabled if the selected record has validation errors, even if the record is not being currently edited. In this case, if the button is pushed then the local chan ges of that record should be canceled. details: https://code.openbravo.com/erp/devel/pi/rev/5275962066ba changeset: 25313:5275962066ba user: Augusto Mauch <augusto.mauch <at> openbravo.com> date: Mon Nov 24 15:49:17 2014 +0100 summary: Fixes issue 28188: Backs out original fix, another approach is used When the grid has data that has not been saved due to having validation errors, instead of allowing the user to refresh the record and get rid of the local changes, now the refresh button is disabled. The cancel button can be used to restore the data to the state it had before the validation errors, and once there are no more invalid records the refresh button will be enabled again. diffstat: modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js | 50 +++++++++- modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-toolbar.js | 10 +- 2 files changed, 56 insertions(+), 4 deletions(-) diffs (127 lines): diff -r 31a1f49e05a8 -r 5275962066ba 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 Mon Nov 24 11:09:01 2014 +0100 +++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js Mon Nov 24 15:49:17 2014 +0100 @@ -1733,7 +1733,6 @@ } this.actionAfterDataArrived = callback; this.invalidateCache(); - this.discardAllEdits(); var context = { showPrompt: false @@ -2895,7 +2894,7 @@ // set the default error message, // is possibly overridden in the next call if (record) { - record._hasValidationErrors = true; + this.addRecordToValidationErrorList(record); if (!record[isc.OBViewGrid.ERROR_MESSAGE_PROP]) { this.setRecordErrorMessage(rowNum, OB.I18N.getLabel('OBUIAPP_ErrorInFields')); // do not automatically remove this message @@ -2927,6 +2926,45 @@ } }, + addRecordToValidationErrorList: function (record) { + if (!record) { + return; + } + record._hasValidationErrors = true; + this.recordIdsWithValidationError = this.recordIdsWithValidationError || []; + if (!this.recordIdsWithValidationError.contains(record[OB.Constants.ID])) { + this.recordIdsWithValidationError.push(record[OB.Constants.ID]); + } + }, + + removeRecordFromValidationErrorList: function (record) { + if (!record) { + return; + } + delete record._hasValidationErrors; + this.recordIdsWithValidationError = this.recordIdsWithValidationError || []; + this.recordIdsWithValidationError.remove(record[OB.Constants.ID]); + }, + + selectedRecordHasValidationErrors: function () { + var record; + // if the number of selected records is not 1, return false + if (this.getSelectedRecords().length !== 1 || !isc.isA.Array(this.recordIdsWithValidationError)) { + return false; + } + record = this.getSelectedRecord(); + return this.recordIdsWithValidationError.contains(record[OB.Constants.ID]); + }, + + gridHasValidationErrors: function () { + if (!isc.isA.Array(this.recordIdsWithValidationError)) { + return false; + } else { + // return true if the list of record ids with validation errors is not empty + return !this.recordIdsWithValidationError.isEmpty(); + } + }, + recordHasChanges: function (rowNum, colNum, checkEditor) { var record = this.getRecord(rowNum); // If a record has validation errors but had all the mandatory fields set, @@ -2984,6 +3022,9 @@ return; } + // the record has been sucessfully saved so it does not have validation errors + this.removeRecordFromValidationErrorList(record); + // a new id has been computed use that now if (record && record._newId) { record.id = record._newId; @@ -3061,6 +3102,7 @@ for (i = 0; i < length; i++) { var rowNum = this.getRecordIndex(selectedRecords[i]); var record = selectedRecords[i]; + this.removeRecordFromValidationErrorList(record); this.Super('discardEdits', [rowNum, false, false, isc.ListGrid.PROGRAMMATIC]); // remove the record if new if (record._new) { @@ -3103,6 +3145,10 @@ totalRows, me = this, record = this.getRecord(rowNum); + if (record) { + this.removeRecordFromValidationErrorList(record); + } + if (!preventConfirm && ((editForm && editForm.hasChanged) || this.rowHasErrors(rowNum))) { me.Super('discardEdits', localArguments); diff -r 31a1f49e05a8 -r 5275962066ba modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-toolbar.js --- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-toolbar.js Mon Nov 24 11:09:01 2014 +0100 +++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-toolbar.js Mon Nov 24 15:49:17 2014 +0100 @@ -218,7 +218,12 @@ sortPosition: 70, prompt: OB.I18N.getLabel('OBUIAPP_RefreshData'), updateState: function () { - this.setDisabled(this.view.isRefreshing || !this.view.hasNotChanged()); + var gridVisibleAndWithValidationErrors = false; + if (!this.view.isShowingForm && this.view.viewGrid.gridHasValidationErrors()) { + // do not allow refreshing the grid if it has validation errors + gridVisibleAndWithValidationErrors = true; + } + this.setDisabled(gridVisibleAndWithValidationErrors || this.view.isRefreshing || !this.view.hasNotChanged()); }, keyboardShortcutId: 'ToolBar_Refresh' }, @@ -235,12 +240,13 @@ sortPosition: 50, prompt: OB.I18N.getLabel('OBUIAPP_CancelEdit'), updateState: function () { + var recordWithValidationErrorsSelected = false; if (this.view.isShowingForm) { this.setDisabled(false); } else { // Only enabled when the grid is being edited or when // the selected records have errors - this.setDisabled(!this.view.isEditingGrid && this.view.hasNotChanged()); + this.setDisabled(!this.view.isEditingGrid && this.view.hasNotChanged() && !this.view.viewGrid.selectedRecordHasValidationErrors()); } }, keyboardShortcutId: 'ToolBar_Undo' ------------------------------------------------------------------------------ Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits