@@ -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,24 +219,48 @@ 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 } ,
225226
226227 validateAll : function ( ) {
228+ if ( this . fireEvent ( 'beforevalidation' , this ) === false )
229+ return ;
227230 this . serverStores . each ( function ( serverStore ) {
228231 serverStore . validateRecords ( serverStore . getRange ( ) , true ) ;
229232 } , this ) ;
230233 } ,
231234
232235 validateRecords : function ( recordMap ) {
236+ if ( this . fireEvent ( 'beforevalidation' , this ) === false )
237+ return ;
233238 for ( var serverStoreId in recordMap ) {
234239 var serverStore = this . serverStores . get ( serverStoreId ) ;
235240 serverStore . validateRecords ( Ext4 . Object . getValues ( recordMap [ serverStoreId ] ) , true ) ;
236241 }
237242 } ,
238243
244+ onValidationRequestStart : function ( ) {
245+ this . validationRequestsInFlight ++ ;
246+
247+ if ( this . validationRequestsInFlight === 1 ) {
248+ this . fireEvent ( 'validationstart' , this ) ;
249+ }
250+ } ,
251+
252+ onValidationRequestComplete : function ( ) {
253+ if ( ! this . validationRequestsInFlight ) {
254+ return ;
255+ }
256+
257+ this . validationRequestsInFlight -- ;
258+
259+ if ( this . validationRequestsInFlight === 0 ) {
260+ this . fireEvent ( 'validationcomplete' , this ) ;
261+ }
262+ } ,
263+
239264 serverToClientDataMap : null ,
240265
241266 getServerToClientDataMap : function ( ) {
@@ -472,11 +497,31 @@ Ext4.define('EHR.data.StoreCollection', {
472497 if ( EHR . debug )
473498 console . log ( commands ) ;
474499
500+ var success = this . getOnCommitSuccess ( recordsArr , validateOnly , retainErrors ) ;
501+ var failure = this . getOnCommitFailure ( recordsArr , validateOnly ) ;
475502 var cfg = {
476503 url : LABKEY . ActionURL . buildURL ( 'query' , 'saveRows' , this . containerPath ) ,
477504 method : 'POST' ,
478- success : this . getOnCommitSuccess ( recordsArr , validateOnly , retainErrors ) ,
479- failure : this . getOnCommitFailure ( recordsArr , validateOnly ) ,
505+ success : function ( response , options ) {
506+ try {
507+ success . call ( this , response , options ) ;
508+ }
509+ finally {
510+ if ( validateOnly ) {
511+ this . onValidationRequestComplete ( ) ;
512+ }
513+ }
514+ } ,
515+ failure : function ( response , options ) {
516+ try {
517+ failure . call ( this , response , options ) ;
518+ }
519+ finally {
520+ if ( validateOnly ) {
521+ this . onValidationRequestComplete ( ) ;
522+ }
523+ }
524+ } ,
480525 scope : this ,
481526 timeout : 5000000 , //a little extreme?
482527 transacted : true ,
@@ -498,9 +543,20 @@ Ext4.define('EHR.data.StoreCollection', {
498543 if ( validateOnly ) {
499544 cfg . jsonData . validateOnly = true ;
500545 cfg . jsonData . extraContext . isValidateOnly = true ;
546+ this . onValidationRequestStart ( ) ;
547+ }
548+
549+ var request ;
550+ try {
551+ request = LABKEY . Ajax . request ( cfg ) ;
501552 }
553+ catch ( e ) {
554+ if ( validateOnly ) {
555+ this . onValidationRequestComplete ( ) ;
556+ }
502557
503- var request = LABKEY . Ajax . request ( cfg ) ;
558+ throw e ;
559+ }
504560
505561 Ext4 . Array . forEach ( recordsArr , function ( command ) {
506562 Ext4 . Array . forEach ( command , function ( rec ) {
@@ -893,4 +949,4 @@ Ext4.define('EHR.data.StoreCollection', {
893949 s . checkForServerErrorChanges ( ) ;
894950 } , this ) ;
895951 }
896- } ) ;
952+ } ) ;
0 commit comments