@@ -744,6 +744,14 @@ module fng.services {
744
744
processLookupHandlers ( $scope . record , { } ) ;
745
745
}
746
746
747
+ function processDirtyFlag ( resp :{ dirty ?: boolean , dirtyMessage ?: string } ) {
748
+ if ( resp ?. dirty === true ) {
749
+ $scope . cancel ( ) ;
750
+ setTimeout ( ( ) => {
751
+ $scope . showError ( resp . dirtyMessage , "Record Locked" ) ;
752
+ } )
753
+ }
754
+ }
747
755
if ( listOnly ) {
748
756
ctrlState . allowLocationChange = true ;
749
757
} else {
@@ -761,7 +769,18 @@ module fng.services {
761
769
$scope . $watch (
762
770
"record" ,
763
771
function ( newValue , oldValue ) {
764
- if ( newValue !== oldValue ) {
772
+ if ( $scope . phase === "ready" && ! $scope . dirtyChecked && Object . keys ( oldValue ) . length > 0 && $scope . topLevelFormName && $scope [ $scope . topLevelFormName ] . $dirty && typeof $scope . dataEventFunctions ?. checkDirty === "function" ) {
773
+ $scope . dirtyChecked = true ;
774
+ // An opportunity to ask whether we can edit this document or not - pessimistic locking can be implemented by using this
775
+ const checkDirty = $scope . dataEventFunctions . checkDirty ( newValue , oldValue ) ;
776
+ if ( typeof checkDirty ?. then === "function" ) {
777
+ checkDirty . then ( ( resp ) => {
778
+ processDirtyFlag ( resp ) ;
779
+ } )
780
+ } else {
781
+ processDirtyFlag ( checkDirty ) ;
782
+ }
783
+ }
765
784
if (
766
785
Object . keys ( oldValue ) . length > 0 &&
767
786
$scope . dropConversionWatcher
@@ -814,7 +833,6 @@ module fng.services {
814
833
title = title . trimEnd ( ) + ( formsAngular . title . suffix || "" ) ;
815
834
$window . document . title = title . replace ( / < \/ ? [ ^ > ] + ( > | $ ) / g, "" ) ;
816
835
}
817
- }
818
836
} ,
819
837
true
820
838
) ;
@@ -1441,7 +1459,7 @@ module fng.services {
1441
1459
// we already have an error showing, so clear timeout and don't overwrite it
1442
1460
$scope . clearTimeout ( ) ;
1443
1461
}
1444
- if ( $scope . errorMessage ) {
1462
+ if ( $scope . errorMessage && $scope . errorMessage . indexOf ( error ) === - 1 ) {
1445
1463
$scope . errorMessage += "<br /><br />" ;
1446
1464
} else {
1447
1465
$scope . errorMessage = "" ;
0 commit comments