Skip to content

Commit b852018

Browse files
committed
8_11_notification
1 parent 2bf7ecf commit b852018

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

src/main/webapp/WEB-INF/jsp/fragments/headTag.jsp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
<link rel="stylesheet" href="webjars/bootstrap/4.6.2/css/bootstrap.min.css">
1212
<link rel="stylesheet" href="webjars/noty/3.1.4/demo/font-awesome/css/font-awesome.min.css">
1313
<link rel="stylesheet" href="webjars/datatables/1.13.5/css/dataTables.bootstrap4.min.css">
14+
<link rel="stylesheet" href="webjars/noty/3.1.4/lib/noty.css"/>
1415
<link rel="shortcut icon" href="resources/images/icon-meal.png">
1516

1617
<%--http://stackoverflow.com/a/24070373/548473--%>
1718
<script src="webjars/jquery/3.7.1/jquery.min.js" defer></script>
1819
<script src="webjars/bootstrap/4.6.2/js/bootstrap.min.js" defer></script>
1920
<script src="webjars/datatables/1.13.5/js/jquery.dataTables.min.js" defer></script>
2021
<script src="webjars/datatables/1.13.5/js/dataTables.bootstrap4.min.js" defer></script>
22+
<script src="webjars/noty/3.1.4/lib/noty.min.js" defer></script>
2123
</head>

src/main/webapp/WEB-INF/jsp/users.jsp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<div class="modal-content">
5151
<div class="modal-header">
5252
<h4 class="modal-title"><spring:message code="user.add"/></h4>
53-
<button type="button" class="close" data-dismiss="modal">&times;</button>
53+
<button type="button" class="close" data-dismiss="modal" onclick="closeNoty()">&times;</button>
5454
</div>
5555
<div class="modal-body">
5656
<form id="detailsForm">
@@ -76,7 +76,7 @@
7676
</form>
7777
</div>
7878
<div class="modal-footer">
79-
<button type="button" class="btn btn-secondary" data-dismiss="modal">
79+
<button type="button" class="btn btn-secondary" data-dismiss="modal" onclick="closeNoty()">
8080
<span class="fa fa-close"></span>
8181
<spring:message code="common.cancel"/>
8282
</button>

src/main/webapp/resources/js/topjava.common.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ function makeEditable(datatableApi) {
88
deleteRow($(this).closest('tr').attr("id"));
99
}
1010
});
11+
12+
$(document).ajaxError(function (event, jqXHR, options, jsExc) {
13+
failNoty(jqXHR);
14+
});
15+
16+
// solve problem with cache in IE: https://stackoverflow.com/a/4303862/548473
17+
$.ajaxSetup({cache: false});
1118
}
1219

1320
function add() {
@@ -21,6 +28,7 @@ function deleteRow(id) {
2128
type: "DELETE"
2229
}).done(function () {
2330
updateTable();
31+
successNoty("Deleted");
2432
});
2533
}
2634

@@ -38,5 +46,35 @@ function save() {
3846
}).done(function () {
3947
$("#editRow").modal("hide");
4048
updateTable();
49+
successNoty("Saved");
50+
});
51+
}
52+
53+
let failedNote;
54+
55+
function closeNoty() {
56+
if (failedNote) {
57+
failedNote.close();
58+
failedNote = undefined;
59+
}
60+
}
61+
62+
function successNoty(text) {
63+
closeNoty();
64+
new Noty({
65+
text: "<span class='fa fa-lg fa-check'></span> &nbsp;" + text,
66+
type: 'success',
67+
layout: "bottomRight",
68+
timeout: 1000
69+
}).show();
70+
}
71+
72+
function failNoty(jqXHR) {
73+
closeNoty();
74+
failedNote = new Noty({
75+
text: "<span class='fa fa-lg fa-exclamation-circle'></span> &nbsp;Error status: " + jqXHR.status,
76+
type: "error",
77+
layout: "bottomRight"
4178
});
79+
failedNote.show()
4280
}

0 commit comments

Comments
 (0)