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

(-)a/admin/problem-reports.pl (+73 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2020 Aleisha Amohia <aleisha@catalyst.net.nz>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use CGI qw ( -utf8 );
23
use C4::Context;
24
use C4::Output;
25
use C4::Auth;
26
use Koha::ProblemReports;
27
28
my $query = new CGI;
29
30
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
31
    {
32
        template_name   => "admin/problem-reports.tt",
33
        query           => $query,
34
        type            => "intranet",
35
        authnotrequired => 0,
36
        flagsrequired   => { problem_reports => 1 },
37
    }
38
);
39
40
my $action;
41
foreach (qw( viewed closed new )) {
42
    $action = $_ if ( $query->param("mark_selected-$_") );
43
}
44
$action ||= 'none';
45
46
my @report_ids = $query->multi_param('report_ids');
47
48
if ( $action eq 'viewed' ) {
49
    foreach my $report_id ( @report_ids ) {
50
        my $report = Koha::ProblemReports->find($report_id);
51
        $report->set({ status => 'V' })->store;
52
                                }
53
} elsif ( $action eq 'closed' ) {
54
    foreach my $report_id ( @report_ids ) {
55
        my $report = Koha::ProblemReports->find($report_id);
56
        $report->set({ status => 'C' })->store;
57
    }
58
59
} elsif ( $action eq 'new' ) {
60
    foreach my $report_id ( @report_ids ) {
61
        my $report = Koha::ProblemReports->find($report_id);
62
        $report->set({ status => 'N' })->store;
63
    }
64
}
65
66
my $problem_reports = Koha::ProblemReports->search();
67
$template->param(
68
    selected_count  => scalar(@report_ids),
69
    action          => $action,
70
    problem_reports => $problem_reports,
71
);
72
73
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/problem-reports.tt (+235 lines)
Line 0 Link Here
1
[% USE raw %]
2
[% USE Asset %]
3
[% USE Koha %]
4
[% USE KohaDates %]
5
[% SET footerjs = 1 %]
6
[% INCLUDE 'doc-head-open.inc' %]
7
<title>Koha &rsaquo; Administration &rsaquo; OPAC problem reports</title>
8
[% INCLUDE 'doc-head-close.inc' %]
9
</head>
10
11
<body id="admin_problem-reports" class="admin">
12
13
[% INCLUDE 'header.inc' %]
14
[% INCLUDE 'prefs-admin-search.inc' %]
15
<div id="breadcrumbs">
16
    <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
17
    <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo;
18
    OPAC problem reports
19
</div>
20
21
<div class="main container-fluid">
22
    <div class="row">
23
        <div class="col-sm-10 col-sm-push-2">
24
            <main>
25
26
            <h1>OPAC problem reports</h1>
27
28
            <div class="dialog alert" id="error" style="display:none;"></div>
29
30
            [% IF ( selected_count ) %]
31
                <div class="dialog message">
32
                    [% IF ( action == 'viewed' ) %]
33
                        <span>[% selected_count | html %] problem report(s) marked as viewed.</span>
34
                    [% ELSIF ( action == 'closed' ) %]
35
                        <span>[% selected_count | html %] problem report(s) marked as closed.</span>
36
                    [% ELSIF ( action == 'new' ) %]
37
                        <span>[% selected_count | html %] problem report(s) marked as new.</span>
38
                    [% ELSE %]
39
                        <span>Failed to change the status of [% selected_count | html %] problem report(s).</span>
40
                    [% END %]
41
                </div>
42
            [% END %]
43
44
            [% IF ( problem_reports.count ) %]
45
                <form id="mark_selected" method="post" action="/cgi-bin/koha/admin/problem-reports.pl">
46
                    <div id="toolbar" class="btn-toolbar">
47
                        <button type="submit" class="btn btn-default markviewed" name="mark_selected-viewed" value="viewed" disabled="disabled"><i class="fa fa-eye"></i> Mark viewed</button>
48
                        <button type="submit" class="btn btn-default markclosed" name="mark_selected-closed" value="closed" disabled="disabled"><i class="fa fa-times-circle"></i> Mark closed</button>
49
                        <button type="submit" class="btn btn-default marknew" name="mark_selected-new" value="new" disabled="disabled"><i class="fa fa-star"></i> Mark new</button>
50
                    </div>
51
52
                    <fieldset class="action" style="cursor:pointer;">
53
                        <a class="SelectAll"><i class="fa fa-check"></i> Select all</a>
54
                        | <a class="ClearAll"><i class="fa fa-remove"></i> Clear all</a>
55
                        | <a class="HideViewed"><i class="fa fa-minus-square"></i> Hide viewed</a>
56
                        | <a class="HideClosed"><i class="fa fa-minus-square"></i> Hide closed</a>
57
                        | <a class="HideNew"><i class="fa fa-minus-square"></i> Hide new</a>
58
                        | <a class="ShowAll"><i class="fa fa-bars"></i> Show all</a>
59
                    </fieldset>
60
61
                    <table id="problemreportstable">
62
                        <thead>
63
                            <tr>
64
                                <th class="NoSort">&nbsp;</th>
65
                                <th class="anti-the">Message</th>
66
                                <th>Problem page</th>
67
                                <th class="title-string">Created on</th>
68
                                <th>Set by</th>
69
                                <th>Status</th>
70
                                <th class="NoSort">Actions</th>
71
                            </tr>
72
                        </thead>
73
                        <tbody>
74
                            [% FOREACH report IN problem_reports %]
75
                                <tr>
76
                                    <td><input type="checkbox" name="report_ids" value="[% report.reportid | html %]"></td>
77
                                    <td>
78
                                        <b>[% report.title | html %]</b><br>
79
                                        [% report.content | html %]
80
                                    </td>
81
                                    <td><a href="[% report.problempage | uri %]">[% report.problempage | html %]</a></td>
82
                                    <td><span title="[% report.created_on | html %]">[% report.created_on | $KohaDates with_hours => 1 %]</span></td>
83
                                    <td>[% INCLUDE 'patron-title.inc' patron => report.patron hide_patron_infos_if_needed=1 %]</td>
84
                                    <td class="status[% report.status | html %]" name="status">
85
                                        [% IF ( report.status == 'V' ) %]
86
                                            <span id="status_[% report.reportid | html %]">Viewed</span>
87
                                        [% ELSIF ( report.status == 'C' ) %]
88
                                            <span id="status_[% report.reportid | html %]">Closed</span>
89
                                        [% ELSE %]
90
                                            <span id="status_[% report.reportid | html %]">New</span>
91
                                        [% END %]
92
                                    </td>
93
                                    <td class="actions">
94
                                        [% IF ( report.status == 'N' ) %]
95
                                            <button name="viewed" data-report_id="[% report.reportid | html %]" class="viewed btn btn-default btn-xs"><i class="fa fa-eye"></i> Mark viewed</button> <button name="closed" data-report_id="[% report.reportid | html %]" class="closed btn btn-default btn-xs"><i class="fa fa-times-circle"></i> Mark closed</button> <button name="new" disabled="disabled" data-report_id="[% report.reportid | html %]" class="new btn btn-default btn-xs"><i class="fa fa-star"></i> Mark new</button>
96
                                        [% ELSIF ( report.status == 'V' ) %]
97
                                            <button name="viewed" disabled="disabled" data-report_id="[% report.reportid | html %]" class="viewed btn btn-default btn-xs"><i class="fa fa-eye"></i> Mark viewed</button> <button name="closed" data-report_id="[% report.reportid | html %]" class="closed btn btn-default btn-xs"><i class="fa fa-times-circle"></i> Mark closed</button> <button name="new" data-report_id="[% report.reportid | html %]" class="new btn btn-default btn-xs"><i class="fa fa-star"></i> Mark new</button>
98
                                        [% ELSE %]
99
                                            <button name="viewed" data-report_id="[% report.reportid | html %]" class="viewed btn btn-default btn-xs"><i class="fa fa-eye"></i> Mark viewed</button> <button name="closed" disabled="disabled" data-report_id="[% report.reportid | html %]" class="closed btn btn-default btn-xs"><i class="fa fa-times-circle"></i> Mark closed</button> <button name="new" data-report_id="[% report.reportid | html %]" class="new btn btn-default btn-xs"><i class="fa fa-star"></i> Mark new</button>
100
                                        [% END %]
101
                                    </td>
102
                                </tr>
103
                            [% END %]
104
                        </tbody>
105
                    </table>
106
107
                </form>
108
109
            [% ELSE %]
110
                <div class="dialog message">There are currently no problem reports.</div>
111
            [% END %] <!-- problem reports -->
112
113
            </main>
114
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
115
116
        <div class="col-sm-2 col-sm-pull-10">
117
            <aside>
118
                [% INCLUDE 'admin-menu.inc' %]
119
            </aside>
120
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
121
122
    </div> <!-- /.row -->
123
124
[% MACRO jsinclude BLOCK %]
125
    [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
126
    [% INCLUDE 'calendar.inc' %]
127
    [% INCLUDE 'datatables.inc' %]
128
    <script>
129
        $(document).ready(function(){
130
            $("#problemreportstable").dataTable($.extend(true, {}, dataTablesDefaults, {
131
                "order": [[ 1, "asc" ]],
132
                "aoColumnDefs": [
133
                    { "orderable": false, "searchable": false, 'targets': [ 'NoSort' ] },
134
                    { "type": "title-string", "targets" : [ "title-string" ] },
135
                    { "type": "anti-the", "targets": [ "anti-the" ] }
136
                ],
137
                "pagingType": "full"
138
            }));
139
140
            $(".SelectAll").on("click", function(){
141
                $("input[name='report_ids'][type='checkbox']").prop("checked", true);
142
                $(".markviewed").prop("disabled", false);
143
                $(".markclosed").prop("disabled", false);
144
                $(".marknew").prop("disabled", false);
145
            });
146
147
            $(".ClearAll").on("click", function(){
148
                $("input[name='report_ids'][type='checkbox']").prop("checked", false);
149
                $(".markviewed").prop("disabled", true);
150
                $(".markclosed").prop("disabled", true);
151
                $(".marknew").prop("disabled", true);
152
            });
153
154
            $(".HideViewed").on("click", function(){
155
                $(".statusV").parent().hide();
156
            });
157
158
            $(".HideClosed").on("click", function(){
159
                $(".statusC").parent().hide();
160
            });
161
162
            $(".HideNew").on("click", function(){
163
                $(".statusN").parent().hide();
164
            });
165
166
            $(".ShowAll").on("click", function(){
167
                $("tr").show();
168
            });
169
170
            $("#error").hide();
171
172
            $("#problemreportstable").on("change", "input[type='checkbox']", function(){
173
                if ( $("input[type='checkbox']").is(":checked") ) {
174
                    $(".markviewed").prop("disabled", false);
175
                    $(".markclosed").prop("disabled", false);
176
                    $(".marknew").prop("disabled", false);
177
                } else {
178
                    $(".markviewed").prop("disabled", true);
179
                    $(".markclosed").prop("disabled", true);
180
                    $(".marknew").prop("disabled", true);
181
                }
182
            });
183
184
            $("#problemreportstable").on("click", "button.viewed, button.closed, button.new", function(event){
185
                event.preventDefault(); // prevent form submission
186
                var $action = $(this).attr("name");
187
                var $report_id = $(this).data('report_id');
188
                var ajaxData = {
189
                    'action': $action,
190
                    'report_id': $report_id,
191
                };
192
193
                $.ajax({
194
                    url: '/cgi-bin/koha/svc/problem_reports/',
195
                    type: 'POST',
196
                    dataType: 'json',
197
                    data: ajaxData,
198
                })
199
200
                .done(function(data){
201
                    if (data.status == 'success'){
202
                        if ( $action == 'viewed' ){
203
                            $("#status_" + $report_id).text(_("Viewed"));
204
                            $(event.target).parent().siblings("status").removeClass().addClass("statusV");
205
                            $(event.target).siblings(".closed").prop("disabled", false);
206
                            $(event.target).siblings(".new").prop("disabled", false);
207
                            $(event.target).prop("disabled", true);
208
                        } else if ( $action == 'new' ){
209
                            $("#status_" + $report_id).text(_("New"));
210
                            $(event.target).parent().siblings("status").removeClass().addClass("statusN");
211
                            $(event.target).siblings(".closed").prop("disabled", false);
212
                            $(event.target).siblings(".viewed").prop("disabled", false);
213
                            $(event.target).prop("disabled", true);
214
                        } else {
215
                            $("#status_" + $report_id).text(_("Closed"));
216
                            $(event.target).parent().siblings("status").removeClass().addClass("statusC");
217
                            $(event.target).siblings(".viewed").prop("disabled", false);
218
                            $(event.target).siblings(".new").prop("disabled", false);
219
                            $(event.target).prop("disabled", true);
220
                        }
221
                    } else {
222
                        $("#error").text(_("Unable to change status of problem report."));
223
                        $("#error").show();
224
                    }
225
                })
226
                .error(function(data){
227
                    $("#error").text(_("Unable to change status of problem report."));
228
                    $("#error").show();
229
                });
230
            });
231
        });
232
    </script>
233
[% END %]
234
235
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/svc/problem_reports (-1 / +68 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2020 Aleisha Amohia <aleisha@catalyst.net.nz>
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use JSON qw( to_json );
23
use CGI;
24
use C4::Service;
25
use C4::Auth qw /check_cookie_auth/;
26
use C4::Output qw(:DEFAULT :ajax);
27
use Koha::ProblemReports;
28
29
=head1 NAME
30
31
svc/problem_reports - Web service for managing OPAC problem reports
32
33
=head1 DESCRIPTION
34
35
=cut
36
37
# AJAX requests
38
my $is_ajax = is_ajax();
39
my $query = new CGI;
40
my ( $auth_status, $sessionID ) = check_cookie_auth( $query->cookie('CGISESSID'), { problem_reports => 1 } );
41
if ( $auth_status ne "ok" ) {
42
    exit 0;
43
}
44
if ($is_ajax) {
45
    my $report_id = $query->param('report_id');
46
    my $report = Koha::ProblemReports->find($report_id);
47
    my $action = $query->param('action');
48
    my $status = 'success';
49
    if ( $action eq 'viewed' ) {
50
        $report->set({ status => 'V' })->store;
51
        if ( $report->status ne 'V' ) {
52
            $status = 'failure';
53
        }
54
    } elsif ( $action eq 'closed' ) {
55
        $report->set({ status => 'C' })->store;
56
        if ( $report->status ne 'C' ) {
57
            $status = 'failure';
58
        }
59
    } elsif ( $action eq 'new' ) {
60
        $report->set({ status => 'N' })->store;
61
        if ( $report->status ne 'N' ) {
62
            $status = 'failure';
63
        }
64
    }
65
    my $json = to_json ( { status => $status } );
66
    output_with_http_headers $query, undef, $json, 'js';
67
    exit;
68
}

Return to bug 4461