@@ -2512,6 +2512,7 @@ webui.NewChangedFilesView = function(workspaceView) {
2512
2512
self . update = function ( ) {
2513
2513
$ ( fileList ) . empty ( ) ;
2514
2514
selectedItems = [ ] ;
2515
+ selectedItemsFromOtherUser = [ ] ;
2515
2516
$ ( '#stashBtn' ) . prop ( "disabled" , true ) ;
2516
2517
$ ( '#discardBtn' ) . prop ( "disabled" , true ) ;
2517
2518
$ ( '#commitBtn' ) . prop ( "disabled" , true ) ;
@@ -2523,15 +2524,35 @@ webui.NewChangedFilesView = function(workspaceView) {
2523
2524
$ . get ( "api/uncommitted" , function ( uncommitted ) {
2524
2525
var uncommittedItems = JSON . parse ( uncommitted ) [ "current user's changes" ] ;
2525
2526
self . filesCount = 0 ;
2526
- function addItemToFileList ( fileList , workingTreeStatus , model ) {
2527
- var formCheck = $ ( '<div class="form-check changes-check"></div>' ) ;
2527
+ function addItemToFileList ( fileList , workingTreeStatus , model , isOtherUserChange ) {
2528
+
2529
+ var formCheck ;
2530
+ if ( isOtherUserChange ) {
2531
+ formCheck = $ ( '<div class="form-check changes-check other-user"></div>' ) ;
2532
+ } else {
2533
+ formCheck = $ ( '<div class="form-check changes-check"></div>' ) ;
2534
+ }
2535
+
2528
2536
formCheck . attr ( "data-filename" , model ) ;
2529
2537
2530
- var checkboxInput = $ ( '<input class="form-check-input changes-checkbox" type="checkbox" value="">' ) ;
2538
+ var checkboxInput ;
2539
+
2540
+ if ( isOtherUserChange ) {
2541
+ checkboxInput = $ ( '<input class="form-check-input changes-checkbox other-user" type="checkbox" value="">' ) ;
2542
+ } else {
2543
+ checkboxInput = $ ( '<input class="form-check-input changes-checkbox" type="checkbox" value="">' ) ;
2544
+ }
2545
+
2531
2546
checkboxInput . attr ( 'id' , model ) ;
2532
2547
formCheck . append ( checkboxInput ) ;
2533
2548
2534
- var checkboxLabel = $ ( '<label class="form-check-label file-item-label"></label>' ) . text ( model ) ;
2549
+ var checkboxLabel ;
2550
+ if ( isOtherUserChange ) {
2551
+ checkboxLabel = $ ( '<label class="form-check-label file-item-label other-user-label"></label>' ) . text ( model ) ;
2552
+ } else {
2553
+ checkboxLabel = $ ( '<label class="form-check-label file-item-label"></label>' ) . text ( model ) ;
2554
+ }
2555
+
2535
2556
checkboxLabel . addClass ( workingTreeStatus ) ;
2536
2557
checkboxLabel . attr ( 'for' , model ) ;
2537
2558
formCheck . append ( checkboxLabel ) ;
@@ -2542,6 +2563,7 @@ webui.NewChangedFilesView = function(workspaceView) {
2542
2563
// $(item).click(self.select);
2543
2564
2544
2565
}
2566
+
2545
2567
webui . splitLines ( data ) . forEach ( function ( line ) {
2546
2568
var indexStatus = line [ 0 ] ;
2547
2569
var workingTreeStatus = line [ 1 ] ;
@@ -2564,7 +2586,9 @@ webui.NewChangedFilesView = function(workspaceView) {
2564
2586
}
2565
2587
2566
2588
if ( isForCurrentUser ) {
2567
- addItemToFileList ( fileList , workingTreeStatus , model ) ;
2589
+ addItemToFileList ( fileList , workingTreeStatus , model , false ) ;
2590
+ } else {
2591
+ addItemToFileList ( fileList , workingTreeStatus , model , true )
2568
2592
}
2569
2593
2570
2594
} ) ;
@@ -2610,13 +2634,78 @@ webui.NewChangedFilesView = function(workspaceView) {
2610
2634
} ) ;
2611
2635
}
2612
2636
2637
+ self . confirmActionOnOtherUsersChanges = function ( action ) {
2638
+ function removeWarningModal ( popup ) {
2639
+ $ ( popup ) . children ( ".modal-fade" ) . modal ( "hide" ) ;
2640
+ $ ( ".modal-backdrop" ) . remove ( ) ;
2641
+ $ ( "#confirmAction" ) . remove ( ) ;
2642
+ modalOpen = false ;
2643
+ }
2644
+
2645
+ var popup = $ ( '<div class="modal fade" id="confirmAction" role="dialog" data-backdrop="static">' +
2646
+ '<div class="modal-dialog modal-md">' +
2647
+ '<div class="modal-content>' +
2648
+ '<div class="modal-header">' +
2649
+ '<h5 class="modal-title">Confirm ' + action + '</h5>' +
2650
+ '<button type="button" class="btn btn-default close" data-dismiss="modal">' +
2651
+ webui . largeXIcon +
2652
+ '</button>' +
2653
+ '</div>' +
2654
+ '<div class="modal-body"></div>' +
2655
+ '</div>' +
2656
+ '</div>' +
2657
+
2658
+ '</div>' ) [ 0 ] ;
2659
+ $ ( "body" ) . append ( popup ) ;
2660
+ var popupContent = $ ( ".modal-body" , popup ) [ 0 ] ;
2661
+ webui . detachChildren ( popupContent ) ;
2662
+ $ ( '<div class="row"><div class="col-sm-1">' +
2663
+ webui . warningIcon +
2664
+ '</div>' +
2665
+ '<div class="col-sm-11">The following files were changed by other users. Are you sure you want to ' + action + ' them?</div></div><ul>' ) . appendTo ( popupContent ) ;
2666
+
2667
+ selectedItemsFromOtherUser . forEach ( function ( file , index ) {
2668
+ $ ( '<li>' + file + '</li>' ) . appendTo ( popupContent ) ;
2669
+ } ) ;
2670
+
2671
+ $ ( '</ul>' ) . appendTo ( popupContent ) ;
2672
+
2673
+ $ ( '<button class="btn btn-sm btn-warning float-right" id="confirmActionBtn">' + action . charAt ( 0 ) . toUpperCase ( ) + action . substring ( 1 ) + '</button>' +
2674
+ '<button class="btn btn-sm btn-secondary float-right" id="cancelActionBtn">Cancel</button>' ) . appendTo ( popupContent ) ;
2675
+
2676
+ $ ( popup ) . modal ( 'show' ) ;
2677
+ var modalOpen = true ;
2678
+
2679
+ var actionConfirmed = false ;
2680
+
2681
+ $ ( '#confirmAction' ) . on ( 'click' , '#confirmActionBtn' , function ( ) {
2682
+ actionConfirmed = true ;
2683
+ removeWarningModal ( popup ) ;
2684
+ } ) ;
2685
+
2686
+ $ ( '#confirmAction' ) . find ( '#cancelAction, .close' ) . click ( function ( ) {
2687
+ removeWarningModal ( popup ) ;
2688
+ } )
2689
+
2690
+ while ( modalOpen ) {
2691
+ // spin
2692
+ }
2693
+
2694
+ return actionConfirmed ;
2695
+ }
2696
+
2613
2697
self . afterFileChecked = function ( element ) {
2614
2698
var fileName = element . id ;
2615
2699
var fileIndex = selectedItems . indexOf ( fileName ) ;
2616
2700
if ( element . checked ) {
2617
2701
if ( fileIndex == - 1 ) {
2618
2702
selectedItems . push ( fileName ) ;
2619
2703
}
2704
+
2705
+ if ( element . hasClass ( "other-user" ) && ( selectedItems . indexOf ( fileName ) == - 1 ) ) {
2706
+ selectedItemsFromOtherUser . push ( fileName ) ;
2707
+ }
2708
+
2620
2709
if ( selectedItems . length == Array . from ( fileList . children ) . length ) {
2621
2710
$ ( '#selectAllFiles' ) . prop ( 'checked' , true ) ;
2622
2711
}
@@ -2625,6 +2714,10 @@ webui.NewChangedFilesView = function(workspaceView) {
2625
2714
if ( fileIndex > - 1 ) {
2626
2715
selectedItems . splice ( fileIndex , 1 ) ;
2627
2716
}
2717
+
2718
+ if ( element . hasClass ( "other-user" ) && ( selectedItems . indexOf ( fileName ) > - 1 ) ) {
2719
+ selectedItemsFromOtherUser . splice ( selectedItems . indexOf ( fileName ) , 1 ) ;
2720
+ }
2628
2721
}
2629
2722
self . updateButtons ( ) ;
2630
2723
}
@@ -2689,6 +2782,11 @@ webui.NewChangedFilesView = function(workspaceView) {
2689
2782
2690
2783
self . stash = function ( ) {
2691
2784
var selectedFilesAsString = selectedItems . join ( " " ) ;
2785
+ if ( selectedItemsFromOtherUser . length > 0 ) {
2786
+ if ( ! this . confirmActionOnOtherUsersChanges ( "stash" ) ) {
2787
+ return
2788
+ }
2789
+ }
2692
2790
webui . git ( "stash push -- " + selectedFilesAsString , function ( output ) {
2693
2791
webui . showSuccess ( output ) ;
2694
2792
workspaceView . update ( ) ;
@@ -2697,13 +2795,24 @@ webui.NewChangedFilesView = function(workspaceView) {
2697
2795
2698
2796
self . discard = function ( ) {
2699
2797
var selectedFilesAsString = selectedItems . join ( " " ) ;
2798
+ if ( selectedItemsFromOtherUser . length > 0 ) {
2799
+ if ( ! this . confirmActionOnOtherUsersChanges ( "discard" ) ) {
2800
+ return
2801
+ }
2802
+ }
2700
2803
webui . git ( "restore -- " + selectedFilesAsString , function ( output ) {
2701
2804
workspaceView . update ( ) ;
2702
2805
} ) ;
2703
2806
}
2704
2807
2705
2808
self . commit = function ( message ) {
2706
2809
var selectedFilesAsString = selectedItems . join ( " " ) ;
2810
+
2811
+ if ( selectedItemsFromOtherUser . length > 0 ) {
2812
+ if ( ! this . confirmActionOnOtherUsersChanges ( "commit" ) ) {
2813
+ return
2814
+ }
2815
+ }
2707
2816
webui . git ( "add " + selectedFilesAsString ) ;
2708
2817
webui . git ( 'commit -m "' + message + '" -- ' + selectedFilesAsString , function ( output ) {
2709
2818
webui . showSuccess ( output ) ;
@@ -2740,6 +2849,7 @@ webui.NewChangedFilesView = function(workspaceView) {
2740
2849
var fileListContainer = $ ( ".file-area" , self . element ) [ 0 ] ;
2741
2850
var fileList = $ ( ".changed-files-list" , fileListContainer ) [ 0 ] ;
2742
2851
var selectedItems = [ ] ;
2852
+ var selectedItemsFromOtherUser = [ ] ;
2743
2853
var fileToDiff ;
2744
2854
2745
2855
}
0 commit comments