@@ -12,6 +12,7 @@ Ext4.define('EHR.data.StoreCollection', {
1212 serverStores : null ,
1313 hasLoaded : false , //will be set true after initial load
1414 clientDataChangeBuffer : 150 ,
15+ validationRequestsInFlight : 0 ,
1516 ignoredClientEvents : { } ,
1617
1718 constructor : function ( ) {
@@ -20,7 +21,7 @@ Ext4.define('EHR.data.StoreCollection', {
2021 this . serverStores = Ext4 . create ( 'Ext.util.MixedCollection' , false , this . getKey ) ;
2122
2223 this . callParent ( arguments ) ;
23- this . addEvents ( 'commitcomplete' , 'commitexception' , 'validation' , 'initialload' , 'load' , 'clientdatachanged' , 'serverdatachanged' ) ;
24+ this . addEvents ( 'commitcomplete' , 'commitexception' , 'beforevalidation' , 'validationstart' , ' validation' , 'validationcomplete ', 'initialload' , 'load' , 'clientdatachanged' , 'serverdatachanged' ) ;
2425
2526 this . on ( 'clientdatachanged' , this . onClientDataChanged , this , { buffer : this . clientDataChangeBuffer } ) ;
2627 } ,
@@ -218,7 +219,7 @@ Ext4.define('EHR.data.StoreCollection', {
218219 }
219220 else
220221 {
221- //this really isnt the right event to fire, but it will force a recalulation of buttons on the panel
222+ //this really isn't the right event to fire, but it will force a recalculation of buttons on the panel
222223 this . fireEvent ( 'validation' , this ) ;
223224 }
224225 } ,
@@ -230,12 +231,34 @@ Ext4.define('EHR.data.StoreCollection', {
230231 } ,
231232
232233 validateRecords : function ( recordMap ) {
234+ if ( this . fireEvent ( 'beforevalidation' , this ) === false )
235+ return ;
233236 for ( var serverStoreId in recordMap ) {
234237 var serverStore = this . serverStores . get ( serverStoreId ) ;
235238 serverStore . validateRecords ( Ext4 . Object . getValues ( recordMap [ serverStoreId ] ) , true ) ;
236239 }
237240 } ,
238241
242+ onValidationRequestStart : function ( ) {
243+ this . validationRequestsInFlight ++ ;
244+
245+ if ( this . validationRequestsInFlight === 1 ) {
246+ this . fireEvent ( 'validationstart' , this ) ;
247+ }
248+ } ,
249+
250+ onValidationRequestComplete : function ( ) {
251+ if ( ! this . validationRequestsInFlight ) {
252+ return ;
253+ }
254+
255+ this . validationRequestsInFlight -- ;
256+
257+ if ( this . validationRequestsInFlight === 0 ) {
258+ this . fireEvent ( 'validationcomplete' , this ) ;
259+ }
260+ } ,
261+
239262 serverToClientDataMap : null ,
240263
241264 getServerToClientDataMap : function ( ) {
@@ -472,11 +495,31 @@ Ext4.define('EHR.data.StoreCollection', {
472495 if ( EHR . debug )
473496 console . log ( commands ) ;
474497
498+ var success = this . getOnCommitSuccess ( recordsArr , validateOnly , retainErrors ) ;
499+ var failure = this . getOnCommitFailure ( recordsArr , validateOnly ) ;
475500 var cfg = {
476501 url : LABKEY . ActionURL . buildURL ( 'query' , 'saveRows' , this . containerPath ) ,
477502 method : 'POST' ,
478- success : this . getOnCommitSuccess ( recordsArr , validateOnly , retainErrors ) ,
479- failure : this . getOnCommitFailure ( recordsArr , validateOnly ) ,
503+ success : function ( response , options ) {
504+ try {
505+ success . call ( this , response , options ) ;
506+ }
507+ finally {
508+ if ( validateOnly ) {
509+ this . onValidationRequestComplete ( ) ;
510+ }
511+ }
512+ } ,
513+ failure : function ( response , options ) {
514+ try {
515+ failure . call ( this , response , options ) ;
516+ }
517+ finally {
518+ if ( validateOnly ) {
519+ this . onValidationRequestComplete ( ) ;
520+ }
521+ }
522+ } ,
480523 scope : this ,
481524 timeout : 5000000 , //a little extreme?
482525 transacted : true ,
@@ -498,9 +541,20 @@ Ext4.define('EHR.data.StoreCollection', {
498541 if ( validateOnly ) {
499542 cfg . jsonData . validateOnly = true ;
500543 cfg . jsonData . extraContext . isValidateOnly = true ;
544+ this . onValidationRequestStart ( ) ;
545+ }
546+
547+ var request ;
548+ try {
549+ request = LABKEY . Ajax . request ( cfg ) ;
501550 }
551+ catch ( e ) {
552+ if ( validateOnly ) {
553+ this . onValidationRequestComplete ( ) ;
554+ }
502555
503- var request = LABKEY . Ajax . request ( cfg ) ;
556+ throw e ;
557+ }
504558
505559 Ext4 . Array . forEach ( recordsArr , function ( command ) {
506560 Ext4 . Array . forEach ( command , function ( rec ) {
@@ -893,4 +947,4 @@ Ext4.define('EHR.data.StoreCollection', {
893947 s . checkForServerErrorChanges ( ) ;
894948 } , this ) ;
895949 }
896- } ) ;
950+ } ) ;
0 commit comments