View | Details | Raw Unified | Return to bug 17387
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-menu.inc (-1 / +6 lines)
Lines 43-49 Link Here
43
        </ul>
43
        </ul>
44
    [% END %]
44
    [% END %]
45
45
46
    [% IF ( CAN_user_tools_items_batchmod || CAN_user_tools_items_batchdel || CAN_user_tools_records_batchmod || CAN_user_tools_records_batchdel || CAN_user_tools_marc_modification_templates ) %]
46
    [% IF ( CAN_user_tools_items_batchmod || CAN_user_tools_items_batchdel || CAN_user_tools_records_batchmod || CAN_user_tools_records_batchdel || CAN_user_tools_marc_modification_templates || CAN_user_editcatalogue_edit_catalogue ) %]
47
        <h5>Batch editing</h5>
47
        <h5>Batch editing</h5>
48
        <ul>
48
        <ul>
49
            [% IF ( CAN_user_tools_items_batchmod ) %]
49
            [% IF ( CAN_user_tools_items_batchmod ) %]
Lines 66-71 Link Here
66
                    <a href="/cgi-bin/koha/tools/batch_delete_records.pl">Batch record deletion</a>
66
                    <a href="/cgi-bin/koha/tools/batch_delete_records.pl">Batch record deletion</a>
67
                </li>
67
                </li>
68
            [% END %]
68
            [% END %]
69
            [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]
70
                <li>
71
                    <a href="/cgi-bin/koha/tools/restore-records.pl">Restore deleted records</a>
72
                </li>
73
            [% END %]
69
            [% IF ( CAN_user_tools_marc_modification_templates ) %]
74
            [% IF ( CAN_user_tools_marc_modification_templates ) %]
70
                <li>
75
                <li>
71
                    <a href="/cgi-bin/koha/tools/marc_modification_templates.pl">MARC modification templates</a>
76
                    <a href="/cgi-bin/koha/tools/marc_modification_templates.pl">MARC modification templates</a>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/restore-records.tt (+322 lines)
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
        &rsaquo; [% t("Tools") | html %] &rsaquo; [% 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">&times;</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">&times;</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' %]
(-)a/tools/restore-records.pl (-1 / +36 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <https://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use CGI qw ( -utf8 );
21
22
use C4::Auth   qw( get_template_and_user );
23
use C4::Output qw( output_html_with_http_headers );
24
25
my $input = CGI->new;
26
27
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
28
    {
29
        template_name => "tools/restore-records.tt",
30
        query         => $input,
31
        type          => "intranet",
32
        flagsrequired => { editcatalogue => 'edit_catalogue' },
33
    }
34
);
35
36
output_html_with_http_headers $input, $cookie, $template->output;

Return to bug 17387