-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathtopjava.common.js
More file actions
80 lines (69 loc) · 1.7 KB
/
topjava.common.js
File metadata and controls
80 lines (69 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
let form;
function makeEditable(datatableApi) {
ctx.datatableApi = datatableApi;
form = $('#detailsForm');
$(".delete").click(function () {
if (confirm('Are you sure?')) {
deleteRow($(this).closest('tr').attr("id"));
}
});
$(document).ajaxError(function (event, jqXHR, options, jsExc) {
failNoty(jqXHR);
});
// solve problem with cache in IE: https://stackoverflow.com/a/4303862/548473
$.ajaxSetup({cache: false});
}
function add() {
form.find(":input").val("");
$("#editRow").modal();
}
function deleteRow(id) {
$.ajax({
url: ctx.ajaxUrl + id,
type: "DELETE"
}).done(function () {
updateTable();
successNoty("Deleted");
});
}
function updateTable() {
$.get(ctx.ajaxUrl, function (data) {
ctx.datatableApi.clear().rows.add(data).draw();
});
}
function save() {
$.ajax({
type: "POST",
url: ctx.ajaxUrl,
data: form.serialize()
}).done(function () {
$("#editRow").modal("hide");
updateTable();
successNoty("Saved");
});
}
let failedNote;
function closeNoty() {
if (failedNote) {
failedNote.close();
failedNote = undefined;
}
}
function successNoty(text) {
closeNoty();
new Noty({
text: "<span class='fa fa-lg fa-check'></span> " + text,
type: 'success',
layout: "bottomRight",
timeout: 1000
}).show();
}
function failNoty(jqXHR) {
closeNoty();
failedNote = new Noty({
text: "<span class='fa fa-lg fa-exclamation-circle'></span> Error status: " + jqXHR.status,
type: "error",
layout: "bottomRight"
});
failedNote.show()
}