Skip to content

Commit d943a26

Browse files
authored
Confirmation alert pops up when the user presses delete branch button (#40)
* Confirmation alert pops up when the user presses delete branch button * Added icon to alert Co-authored-by: Sarmishta Velury <[email protected]>
1 parent 69b70da commit d943a26

File tree

3 files changed

+120
-14
lines changed

3 files changed

+120
-14
lines changed

git-webui/release/share/git-webui/webui/css/git-webui.css

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,28 @@ body {
3131
margin: 0;
3232
font: 10pt sans-serif;
3333
}
34+
35+
#confirm-branch-delete p{
36+
font-size:105%;
37+
}
38+
39+
#confirm-delete, #cancel-delete {
40+
margin-left: 1rem;
41+
margin-top: 0.5rem;
42+
}
43+
44+
.modal-title pre{
45+
display:inline;
46+
}
3447
#error-modal .modal-body {
3548
margin-bottom: 0;
3649
}
3750
.modal-header .close {
38-
padding: 1rem 1rem;
39-
margin: -0.51rem -0.5rem -1rem auto;
51+
padding: 1.25rem 1.5rem;
52+
margin: -1rem -1rem -1rem auto;
53+
}
54+
.alert-dismissible .close {
55+
padding: .3rem 1.25rem;
4056
}
4157
#help-modal img {
4258
display: block;

git-webui/release/share/git-webui/webui/js/git-webui.js

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,16 @@ webui.SideBarView = function(mainView) {
205205
'</svg>'+
206206
'</button>' +
207207
'</div>' +
208-
'<div class="modal-body"><div class="list-group"></div></div>' +
208+
'<div class="modal-body"></div>' +
209209
'</div>' +
210210
'</div>' +
211211
'</div>')[0];
212212
self.element.appendChild(popup);
213-
var popupContent = $(".list-group", popup)[0];
213+
var popupContent = $(".modal-body", popup)[0];
214214
$(self.buildAccordion(section, refs, id, undefined, "popup")).appendTo(popupContent);
215215
$(popupContent).find(".btn-delete-branch, .btn-checkout-local-branch, .btn-checkout-remote-branch").click(function() {
216216
$(popup).modal('hide');
217-
})
217+
});
218218
return popup;
219219
};
220220

@@ -1819,13 +1819,58 @@ $(function () {
18191819

18201820
$(document).on('click', '.btn-delete-branch', function(e) {
18211821
e.preventDefault();
1822+
$("#confirm-branch-delete").remove(); //removes any remaining modals. If there are more than one modals, the ids are duplicated and event listeners won't work.
18221823
var refName = $(this).parent().parent().parent().siblings(
18231824
".card-header").children("button").html();
18241825

1825-
webui.git("branch -d " + refName, function() {
1826-
webui.showWarning("Local branch " + refName + " deleted.");
1827-
updateSideBar();
1826+
console.log($(this).parent().parent().parent()[0]);
1827+
1828+
var popup = $( '<div class="modal fade" id="confirm-branch-delete" role="dialog">' +
1829+
'<div class="modal-dialog modal-md">' +
1830+
'<div class="modal-content">' +
1831+
'<div class="modal-header">' +
1832+
'<h5 class="modal-title">Confirm <pre>'+refName+' </pre>Deletion</h5>' +
1833+
'<button type="button" class="btn btn-default close" data-dismiss="modal">'+
1834+
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-x-lg" viewBox="0 0 16 16">'+
1835+
'<path fill-rule="evenodd" clip-rule="evenodd" d="M13.854 2.146a.5.5 0 0 1 0 .708l-11 11a.5.5 0 0 1-.708-.708l11-11a.5.5 0 0 1 .708 0Z" fill="#000"/>'+
1836+
'<path fill-rule="evenodd" clip-rule="evenodd" d="M2.146 2.146a.5.5 0 0 0 0 .708l11 11a.5.5 0 0 0 .708-.708l-11-11a.5.5 0 0 0-.708 0Z" fill="#000"/>'+
1837+
'</svg>'+
1838+
'</button>' +
1839+
'</div>' +
1840+
'<div class="modal-body"></div>' +
1841+
'</div>' +
1842+
'</div>' +
1843+
'</div>')[0];
1844+
1845+
$("body").append(popup);
1846+
var popupContent = $(".modal-body", popup)[0];
1847+
1848+
$('<div class="row"><div class="col-sm-1">'+
1849+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="#dc3545" class="bi bi-exclamation-circle-fill" viewBox="0 0 16 16">'+
1850+
'<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8 4a.905.905 0 0 0-.9.995l.35 3.507a.552.552 0 0 0 1.1 0l.35-3.507A.905.905 0 0 0 8 4zm.002 6a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"></path>'+
1851+
'</svg></div>'+
1852+
'<div class="col-sm-11">By deleting this branch, you might lose uncommitted work. <br/> Do you want to proceed?</div></div>'+
1853+
'<button class="btn btn-sm btn-danger float-right" id="confirm-delete">Delete Branch</button>'+
1854+
'<button class="btn btn-sm btn-secondary float-right" id="cancel-delete">Cancel</button>').appendTo(popupContent);
1855+
$(popup).modal('show');
1856+
1857+
$("#confirm-branch-delete").on('click', '#confirm-delete', function(e){
1858+
$(popup).children( ".modal-fade").modal('hide');
1859+
$(".modal-backdrop").remove();
1860+
$("#confirm-branch-delete").remove();
1861+
webui.git("branch -d " + refName, function() {
1862+
webui.showWarning("Local branch " + refName + " deleted.");
1863+
updateSideBar();
1864+
});
1865+
1866+
});
1867+
1868+
$("#confirm-branch-delete").find("#cancel-delete, .close").click(function() {
1869+
$(popup).children( ".modal-fade").modal('hide');
1870+
$(".modal-backdrop").remove();
1871+
$("#confirm-branch-delete").remove();
18281872
});
1873+
18291874
});
18301875

18311876
$(document).on('click', '.btn-checkout-remote-branch', function(e) {

git-webui/src/share/git-webui/webui/js/git-webui.js

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,16 @@ webui.SideBarView = function(mainView) {
205205
'</svg>'+
206206
'</button>' +
207207
'</div>' +
208-
'<div class="modal-body"><div class="list-group"></div></div>' +
208+
'<div class="modal-body"></div>' +
209209
'</div>' +
210210
'</div>' +
211211
'</div>')[0];
212212
self.element.appendChild(popup);
213-
var popupContent = $(".list-group", popup)[0];
213+
var popupContent = $(".modal-body", popup)[0];
214214
$(self.buildAccordion(section, refs, id, undefined, "popup")).appendTo(popupContent);
215215
$(popupContent).find(".btn-delete-branch, .btn-checkout-local-branch, .btn-checkout-remote-branch").click(function() {
216216
$(popup).modal('hide');
217-
})
217+
});
218218
return popup;
219219
};
220220

@@ -1819,13 +1819,58 @@ $(function () {
18191819

18201820
$(document).on('click', '.btn-delete-branch', function(e) {
18211821
e.preventDefault();
1822+
$("#confirm-branch-delete").remove(); //removes any remaining modals. If there are more than one modals, the ids are duplicated and event listeners won't work.
18221823
var refName = $(this).parent().parent().parent().siblings(
18231824
".card-header").children("button").html();
18241825

1825-
webui.git("branch -d " + refName, function() {
1826-
webui.showWarning("Local branch " + refName + " deleted.");
1827-
updateSideBar();
1826+
console.log($(this).parent().parent().parent()[0]);
1827+
1828+
var popup = $( '<div class="modal fade" id="confirm-branch-delete" role="dialog">' +
1829+
'<div class="modal-dialog modal-md">' +
1830+
'<div class="modal-content">' +
1831+
'<div class="modal-header">' +
1832+
'<h5 class="modal-title">Confirm <pre>'+refName+' </pre>Deletion</h5>' +
1833+
'<button type="button" class="btn btn-default close" data-dismiss="modal">'+
1834+
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-x-lg" viewBox="0 0 16 16">'+
1835+
'<path fill-rule="evenodd" clip-rule="evenodd" d="M13.854 2.146a.5.5 0 0 1 0 .708l-11 11a.5.5 0 0 1-.708-.708l11-11a.5.5 0 0 1 .708 0Z" fill="#000"/>'+
1836+
'<path fill-rule="evenodd" clip-rule="evenodd" d="M2.146 2.146a.5.5 0 0 0 0 .708l11 11a.5.5 0 0 0 .708-.708l-11-11a.5.5 0 0 0-.708 0Z" fill="#000"/>'+
1837+
'</svg>'+
1838+
'</button>' +
1839+
'</div>' +
1840+
'<div class="modal-body"></div>' +
1841+
'</div>' +
1842+
'</div>' +
1843+
'</div>')[0];
1844+
1845+
$("body").append(popup);
1846+
var popupContent = $(".modal-body", popup)[0];
1847+
1848+
$('<div class="row"><div class="col-sm-1">'+
1849+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="#dc3545" class="bi bi-exclamation-circle-fill" viewBox="0 0 16 16">'+
1850+
'<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8 4a.905.905 0 0 0-.9.995l.35 3.507a.552.552 0 0 0 1.1 0l.35-3.507A.905.905 0 0 0 8 4zm.002 6a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"></path>'+
1851+
'</svg></div>'+
1852+
'<div class="col-sm-11">By deleting this branch, you might lose uncommitted work. <br/> Do you want to proceed?</div></div>'+
1853+
'<button class="btn btn-sm btn-danger float-right" id="confirm-delete">Delete Branch</button>'+
1854+
'<button class="btn btn-sm btn-secondary float-right" id="cancel-delete">Cancel</button>').appendTo(popupContent);
1855+
$(popup).modal('show');
1856+
1857+
$("#confirm-branch-delete").on('click', '#confirm-delete', function(e){
1858+
$(popup).children( ".modal-fade").modal('hide');
1859+
$(".modal-backdrop").remove();
1860+
$("#confirm-branch-delete").remove();
1861+
webui.git("branch -d " + refName, function() {
1862+
webui.showWarning("Local branch " + refName + " deleted.");
1863+
updateSideBar();
1864+
});
1865+
1866+
});
1867+
1868+
$("#confirm-branch-delete").find("#cancel-delete, .close").click(function() {
1869+
$(popup).children( ".modal-fade").modal('hide');
1870+
$(".modal-backdrop").remove();
1871+
$("#confirm-branch-delete").remove();
18281872
});
1873+
18291874
});
18301875

18311876
$(document).on('click', '.btn-checkout-remote-branch', function(e) {

0 commit comments

Comments
 (0)