|
Line 0
Link Here
|
|
|
1 |
[% USE raw %] |
| 2 |
[% USE Asset %] |
| 3 |
[% USE KohaDates %] |
| 4 |
[% USE Koha %] |
| 5 |
[% PROCESS 'i18n.inc' %] |
| 6 |
[% SET footerjs = 1 %] |
| 7 |
[% INCLUDE 'doc-head-open.inc' %] |
| 8 |
<title> |
| 9 |
[% FILTER collapse %] |
| 10 |
[% t("Restore deleted records") | html %] |
| 11 |
› [% t("Tools") | html %] › [% t("Koha") | html %] |
| 12 |
[% END %] |
| 13 |
</title> |
| 14 |
[% INCLUDE 'doc-head-close.inc' %] |
| 15 |
</head> |
| 16 |
|
| 17 |
<body id="tools_restore-records" class="tools"> |
| 18 |
[% WRAPPER 'header.inc' %] |
| 19 |
[% INCLUDE 'cat-search.inc' %] |
| 20 |
[% END %] |
| 21 |
|
| 22 |
[% WRAPPER 'sub-header.inc' %] |
| 23 |
[% WRAPPER breadcrumbs %] |
| 24 |
[% WRAPPER breadcrumb_item %] |
| 25 |
<a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> |
| 26 |
[% END %] |
| 27 |
[% WRAPPER breadcrumb_item bc_active= 1 %] |
| 28 |
<span>Restore deleted records</span> |
| 29 |
[% END %] |
| 30 |
[% END #/ WRAPPER breadcrumbs %] |
| 31 |
[% END #/ WRAPPER sub-header.inc %] |
| 32 |
|
| 33 |
[% SET asides = [] %] |
| 34 |
[% asides.push('cat-menu') %] |
| 35 |
|
| 36 |
[% WRAPPER 'main-container.inc' %] |
| 37 |
<div class="row"> |
| 38 |
<div class="col-md-10 col-md-push-2"> |
| 39 |
<main> |
| 40 |
<h1>Restore deleted records</h1> |
| 41 |
|
| 42 |
<div id="messages"></div> |
| 43 |
|
| 44 |
<h2>Deleted bibliographic records</h2> |
| 45 |
<div class="page-section"> |
| 46 |
<table id="deleted_biblios_table" class="table table-bordered table-striped"> |
| 47 |
<thead> |
| 48 |
<tr> |
| 49 |
<th>Biblio ID</th> |
| 50 |
<th>Title</th> |
| 51 |
<th>Author</th> |
| 52 |
<th>Deleted on</th> |
| 53 |
<th class="NoSort">Actions</th> |
| 54 |
</tr> |
| 55 |
</thead> |
| 56 |
</table> |
| 57 |
</div> |
| 58 |
|
| 59 |
<h2>Deleted items</h2> |
| 60 |
<div class="page-section"> |
| 61 |
<table id="deleted_items_table" class="table table-bordered table-striped"> |
| 62 |
<thead> |
| 63 |
<tr> |
| 64 |
<th>Item ID</th> |
| 65 |
<th>Biblio ID</th> |
| 66 |
<th>Barcode</th> |
| 67 |
<th>Call number</th> |
| 68 |
<th>Home library</th> |
| 69 |
<th>Deleted on</th> |
| 70 |
<th class="NoSort">Actions</th> |
| 71 |
</tr> |
| 72 |
</thead> |
| 73 |
</table> |
| 74 |
</div> |
| 75 |
</main> |
| 76 |
</div> |
| 77 |
</div> |
| 78 |
[% END #/ WRAPPER main-container.inc %] |
| 79 |
|
| 80 |
[% MACRO jsinclude BLOCK %] |
| 81 |
[% Asset.js("js/tools-menu.js") | $raw %] |
| 82 |
[% INCLUDE 'datatables.inc' %] |
| 83 |
<script> |
| 84 |
function showMessage(message, type) { |
| 85 |
var alert = $('<div class="alert alert-' + type + '">' + message + "</div>"); |
| 86 |
$("#messages").append(alert); |
| 87 |
|
| 88 |
setTimeout(function () { |
| 89 |
alert.fadeOut(400, function () { |
| 90 |
$(this).remove(); |
| 91 |
}); |
| 92 |
}, 5000); |
| 93 |
} |
| 94 |
|
| 95 |
$(document).ready(function () { |
| 96 |
// Deleted biblios DataTable |
| 97 |
var biblios_table = $("#deleted_biblios_table").kohaTable({ |
| 98 |
ajax: { |
| 99 |
url: "/api/v1/deleted/biblios", |
| 100 |
}, |
| 101 |
order: [[3, "desc"]], |
| 102 |
columns: [ |
| 103 |
{ |
| 104 |
data: "biblio_id", |
| 105 |
searchable: true, |
| 106 |
orderable: true, |
| 107 |
}, |
| 108 |
{ |
| 109 |
data: "title", |
| 110 |
searchable: true, |
| 111 |
orderable: true, |
| 112 |
render: function (data, type, row) { |
| 113 |
if (type === "display") { |
| 114 |
return $("<div/>").text(data).html(); |
| 115 |
} |
| 116 |
return data; |
| 117 |
}, |
| 118 |
}, |
| 119 |
{ |
| 120 |
data: "author", |
| 121 |
searchable: true, |
| 122 |
orderable: true, |
| 123 |
render: function (data, type, row) { |
| 124 |
if (type === "display") { |
| 125 |
return data ? $("<div/>").text(data).html() : ""; |
| 126 |
} |
| 127 |
return data || ""; |
| 128 |
}, |
| 129 |
}, |
| 130 |
{ |
| 131 |
data: "deleted_on", |
| 132 |
searchable: false, |
| 133 |
orderable: true, |
| 134 |
render: function (data, type, row) { |
| 135 |
if (type === "display" && data) { |
| 136 |
return $date(data); |
| 137 |
} |
| 138 |
return data; |
| 139 |
}, |
| 140 |
}, |
| 141 |
{ |
| 142 |
data: function (row, type) { |
| 143 |
if (type === "display") { |
| 144 |
return ( |
| 145 |
'<button class="btn btn-sm btn-default restore-biblio" data-biblio-id="' + |
| 146 |
row.biblio_id + |
| 147 |
'" data-title="' + |
| 148 |
$("<div/>").text(row.title).html() + |
| 149 |
'"><i class="fa fa-undo" aria-hidden="true"></i> ' + |
| 150 |
_("Restore") + |
| 151 |
"</button>" |
| 152 |
); |
| 153 |
} |
| 154 |
return ""; |
| 155 |
}, |
| 156 |
searchable: false, |
| 157 |
orderable: false, |
| 158 |
}, |
| 159 |
], |
| 160 |
}); |
| 161 |
var biblios_table_api = biblios_table.DataTable(); |
| 162 |
|
| 163 |
// Deleted items DataTable |
| 164 |
var items_table = $("#deleted_items_table").kohaTable({ |
| 165 |
ajax: { |
| 166 |
url: "/api/v1/deleted/items", |
| 167 |
}, |
| 168 |
order: [[5, "desc"]], |
| 169 |
columns: [ |
| 170 |
{ |
| 171 |
data: "item_id", |
| 172 |
searchable: true, |
| 173 |
orderable: true, |
| 174 |
}, |
| 175 |
{ |
| 176 |
data: "biblio_id", |
| 177 |
searchable: true, |
| 178 |
orderable: true, |
| 179 |
}, |
| 180 |
{ |
| 181 |
data: "external_id", |
| 182 |
searchable: true, |
| 183 |
orderable: true, |
| 184 |
render: function (data, type, row) { |
| 185 |
if (type === "display") { |
| 186 |
return data ? $("<div/>").text(data).html() : ""; |
| 187 |
} |
| 188 |
return data || ""; |
| 189 |
}, |
| 190 |
}, |
| 191 |
{ |
| 192 |
data: "callnumber", |
| 193 |
searchable: true, |
| 194 |
orderable: true, |
| 195 |
render: function (data, type, row) { |
| 196 |
if (type === "display") { |
| 197 |
return data ? $("<div/>").text(data).html() : ""; |
| 198 |
} |
| 199 |
return data || ""; |
| 200 |
}, |
| 201 |
}, |
| 202 |
{ |
| 203 |
data: "home_library_id", |
| 204 |
searchable: true, |
| 205 |
orderable: true, |
| 206 |
render: function (data, type, row) { |
| 207 |
if (type === "display") { |
| 208 |
return data ? $("<div/>").text(data).html() : ""; |
| 209 |
} |
| 210 |
return data || ""; |
| 211 |
}, |
| 212 |
}, |
| 213 |
{ |
| 214 |
data: "deleted_on", |
| 215 |
searchable: false, |
| 216 |
orderable: true, |
| 217 |
render: function (data, type, row) { |
| 218 |
if (type === "display" && data) { |
| 219 |
return $date(data); |
| 220 |
} |
| 221 |
return data || ""; |
| 222 |
}, |
| 223 |
}, |
| 224 |
{ |
| 225 |
data: function (row, type) { |
| 226 |
if (type === "display") { |
| 227 |
return ( |
| 228 |
'<button class="btn btn-sm btn-default restore-item" data-item-id="' + |
| 229 |
row.item_id + |
| 230 |
'" data-barcode="' + |
| 231 |
$("<div/>") |
| 232 |
.text(row.external_id || row.item_id) |
| 233 |
.html() + |
| 234 |
'"><i class="fa fa-undo" aria-hidden="true"></i> ' + |
| 235 |
_("Restore") + |
| 236 |
"</button>" |
| 237 |
); |
| 238 |
} |
| 239 |
return ""; |
| 240 |
}, |
| 241 |
searchable: false, |
| 242 |
orderable: false, |
| 243 |
}, |
| 244 |
], |
| 245 |
}); |
| 246 |
var items_table_api = items_table.DataTable(); |
| 247 |
|
| 248 |
// Restore biblio handler |
| 249 |
$("#deleted_biblios_table").on("click", ".restore-biblio", function (e) { |
| 250 |
e.preventDefault(); |
| 251 |
var button = $(this); |
| 252 |
var biblio_id = button.data("biblio-id"); |
| 253 |
var title = button.data("title"); |
| 254 |
|
| 255 |
if (!confirm(_("Are you sure you want to restore bibliographic record %s '%s'?").format(biblio_id, title))) { |
| 256 |
return; |
| 257 |
} |
| 258 |
|
| 259 |
button.prop("disabled", true); |
| 260 |
|
| 261 |
$.ajax({ |
| 262 |
url: "/api/v1/deleted/biblios/" + biblio_id, |
| 263 |
type: "POST", |
| 264 |
headers: { |
| 265 |
"x-koha-request-id": Math.random(), |
| 266 |
}, |
| 267 |
success: function (data) { |
| 268 |
$("#messages").append( |
| 269 |
'<div class="alert alert-success">' + '<button type="button" class="close" data-dismiss="alert">×</button>' + _("Bibliographic record %s restored successfully").format(biblio_id) + "</div>" |
| 270 |
); |
| 271 |
biblios_table_api.ajax.reload(); |
| 272 |
items_table_api.ajax.reload(); |
| 273 |
}, |
| 274 |
error: function (xhr) { |
| 275 |
var error_msg = _("Error restoring bibliographic record %s").format(biblio_id); |
| 276 |
if (xhr.responseJSON && xhr.responseJSON.error) { |
| 277 |
error_msg += ": " + xhr.responseJSON.error; |
| 278 |
} |
| 279 |
$("#messages").append('<div class="alert alert-danger">' + '<button type="button" class="close" data-dismiss="alert">×</button>' + error_msg + "</div>"); |
| 280 |
button.prop("disabled", false); |
| 281 |
}, |
| 282 |
}); |
| 283 |
}); |
| 284 |
|
| 285 |
// Restore item handler |
| 286 |
$("#deleted_items_table").on("click", ".restore-item", function (e) { |
| 287 |
e.preventDefault(); |
| 288 |
var button = $(this); |
| 289 |
var item_id = button.data("item-id"); |
| 290 |
var barcode = button.data("barcode"); |
| 291 |
|
| 292 |
if (!confirm(_("Are you sure you want to restore item %s (%s)?").format(item_id, barcode))) { |
| 293 |
return; |
| 294 |
} |
| 295 |
|
| 296 |
button.prop("disabled", true); |
| 297 |
|
| 298 |
$.ajax({ |
| 299 |
url: "/api/v1/deleted/items/" + item_id, |
| 300 |
type: "PUT", |
| 301 |
headers: { |
| 302 |
"x-koha-request-id": Math.random(), |
| 303 |
}, |
| 304 |
success: function (data) { |
| 305 |
showMessage(_("Item %s restored successfully").format(item_id), "success"); |
| 306 |
items_table_api.ajax.reload(); |
| 307 |
}, |
| 308 |
error: function (xhr) { |
| 309 |
var error_msg = _("Error restoring item %s").format(item_id); |
| 310 |
if (xhr.responseJSON && xhr.responseJSON.error) { |
| 311 |
error_msg += ": " + xhr.responseJSON.error; |
| 312 |
} |
| 313 |
showMessage(error_msg, "danger"); |
| 314 |
button.prop("disabled", false); |
| 315 |
}, |
| 316 |
}); |
| 317 |
}); |
| 318 |
}); |
| 319 |
</script> |
| 320 |
[% END %] |
| 321 |
|
| 322 |
[% INCLUDE 'intranet-bottom.inc' %] |