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

(-)a/Koha/Desk.pm (+45 lines)
Line 0 Link Here
1
package Koha::Desk;
2
3
# Copyright (C) 2020 BULAC
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
use Modern::Perl;
20
21
use Carp;
22
23
use Koha::Database;
24
25
use base qw(Koha::Object);
26
27
=head1 NAME
28
29
Koha::Desk - Koha Desk Object class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 _type
38
39
=cut
40
41
sub _type {
42
    return 'Desk';
43
}
44
45
1;
(-)a/Koha/Desks.pm (+56 lines)
Line 0 Link Here
1
package Koha::Desks;
2
3
# Copyright (C) 2020 BULAC
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
26
use Koha::Desk;
27
28
use base qw(Koha::Objects);
29
30
=head1 NAME
31
32
Koha::Desks - Koha Desk Object set class
33
34
=head1 API
35
36
=head2 Class Methods
37
38
=cut
39
40
=head3 _type
41
42
=cut
43
44
sub _type {
45
    return 'Desk';
46
}
47
48
=head3 object_class
49
50
=cut
51
52
sub object_class {
53
    return 'Koha::Desk';
54
}
55
56
1;
(-)a/admin/desks.pl (+114 lines)
Line 0 Link Here
1
#! /usr/bin/perl
2
3
# Copyright (C) 2020 BULAC
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
21
use Modern::Perl;
22
use CGI qw ( -utf8 );
23
use C4::Context;
24
use C4::Auth;
25
use C4::Output;
26
27
use Koha::Desks;
28
29
my $input       = new CGI;
30
my $searchfield = $input->param('desk_name') // q||;
31
my $desk_id      = $input->param('desk_id') || '';
32
my $op          = $input->param('op') || 'list';
33
my @messages;
34
35
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
    {   template_name   => "admin/desks.tt",
37
        query           => $input,
38
        type            => "intranet",
39
        authnotrequired => 0,
40
        flagsrequired   => { parameters => 'manage_desks' },
41
        debug           => 1,
42
    }
43
);
44
45
my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
46
47
if ( $op eq 'add_form' ) {
48
    my $desk;
49
    if ($desk_id) {
50
        $desk = Koha::Desks->find($desk_id);
51
    }
52
53
    $template->param( desk => $desk, );
54
} elsif ( $op eq 'add_validate' ) {
55
    my $desk_id       = $input->param('desk_id');
56
    my $desk_name    = $input->param('desk_name');
57
    my $branchcode   = $input->param('branchcode');
58
59
    if (Koha::Desks->find($desk_id)) {
60
        my $desk = Koha::Desks->find($desk_id);
61
        $desk->desk_name($desk_name);
62
        $desk->branchcode($branchcode);
63
        eval { $desk->store; };
64
        if ($@) {
65
            push @messages, { type => 'error', code => 'error_on_update' };
66
        } else {
67
            push @messages, { type => 'message', code => 'success_on_update' };
68
        }
69
    } else {
70
        my $desk = Koha::Desk->new(
71
            {
72
                desk_id       => $desk_id,
73
                desk_name    => $desk_name,
74
                branchcode   => $branchcode,
75
            }
76
        );
77
        eval { $desk->store; };
78
        if ($@) {
79
            push @messages, { type => 'error', code => 'error_on_insert' };
80
        } else {
81
            push @messages, { type => 'message', code => 'success_on_insert' };
82
        }
83
    }
84
    $searchfield = q||;
85
    $op          = 'list';
86
} elsif ( $op eq 'delete_confirm' ) {
87
    my $desk = Koha::Desks->find($desk_id);
88
    $template->param( desk => $desk, );
89
} elsif ( $op eq 'delete_confirmed' ) {
90
    my $desk = Koha::Desks->find($desk_id);
91
    my $deleted = eval { $desk->delete; };
92
93
    if ( $@ or not $deleted ) {
94
        push @messages, { type => 'error', code => 'error_on_delete' };
95
    } else {
96
        push @messages, { type => 'message', code => 'success_on_delete' };
97
    }
98
    $op = 'list';
99
}
100
101
if ( $op eq 'list' || ! $op) {
102
    my $desks = Koha::Desks->search( { desk_name => { -like => "%$searchfield%" } } );
103
    $template->param( desks => $desks, );
104
}
105
106
$template->param(
107
    desk_id      => $desk_id,
108
    searchfield => $searchfield,
109
    messages    => \@messages,
110
    op          => $op,
111
    branches    => $branches,
112
);
113
114
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc (+1 lines)
Lines 16-21 Link Here
16
            [% IF ( CAN_user_parameters_manage_libraries ) %]
16
            [% IF ( CAN_user_parameters_manage_libraries ) %]
17
                <li><a href="/cgi-bin/koha/admin/branches.pl">Libraries</a></li>
17
                <li><a href="/cgi-bin/koha/admin/branches.pl">Libraries</a></li>
18
                <li><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></li>
18
                <li><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></li>
19
                <li><a href="/cgi-bin/koha/admin/desks.pl">Desks</a></li>
19
            [% END %]
20
            [% END %]
20
            [% IF ( CAN_user_parameters_manage_itemtypes ) %]
21
            [% IF ( CAN_user_parameters_manage_itemtypes ) %]
21
                <li><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></li>
22
                <li><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/desks-admin-search.inc (+31 lines)
Line 0 Link Here
1
[% USE Koha %]
2
<div class="gradient">
3
<h1 id="logo"><a href="/cgi-bin/koha/mainpage.pl">[% LibraryName|html %]</a></h1><!-- Begin Desks Resident Search Box -->
4
<div id="header_search">
5
        <div id="desk_search" class="residentsearch">
6
    <p class="tip">Desk search:</p>
7
        <form action="[% script_name|html %]" method="post">
8
        <input class="head-searchbox" type="text" name="desk_name" value="[% searchfield|html %]" size="40" />
9
                <input type="submit" name="submit" value="OK" class="submit" />
10
        </form>
11
        </div>
12
13
    [% INCLUDE 'patron-search-box.inc' %]
14
15
        [% IF ( CAN_user_catalogue ) %]
16
    <div id="catalog_search" class="residentsearch">
17
        <p class="tip">Enter search keywords:</p>
18
                <form action="/cgi-bin/koha/catalogue/search.pl"  method="get" id="cat-search-block">
19
             [% IF ( Koha.Preference('IntranetCatalogSearchPulldown') ) %][% INCLUDE 'search_indexes.inc' %][% END %]
20
             <input type="text" name="q" id="search-form" size="40" value="" title="Enter the terms you wish to search for." class="head-searchbox form-text" />
21
                                <input type="submit" value="Submit"  class="submit" />
22
                </form>
23
        </div>[% END %]
24
                        <ul>
25
            <li><a class="keep_text" href="#desk_search">Search desks</a></li>
26
            [% IF ( CAN_user_circulate_circulate_remaining_permissions ) %]<li><a class="keep_text" href="#circ_search">Check out</a></li>[% END %]
27
            [% IF ( CAN_user_catalogue ) %]<li><a class="keep_text" href="#catalog_search">Search the catalog</a></li>[% END %]
28
                        </ul>
29
</div>
30
</div>
31
<!-- End Desks Resident Search Box -->
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (+2 lines)
Lines 63-68 Link Here
63
                        <dd>Define libraries.</dd>
63
                        <dd>Define libraries.</dd>
64
                        <dt><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></dt>
64
                        <dt><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></dt>
65
                        <dd>Define hierarchical library groups.</dd>
65
                        <dd>Define hierarchical library groups.</dd>
66
                        <dt><a href="/cgi-bin/koha/admin/desks.pl">Desks</a></dt>
67
                        <dd>Define desks.</dd>
66
                    [% END %]
68
                    [% END %]
67
                    [% IF ( CAN_user_parameters_manage_itemtypes ) %]
69
                    [% IF ( CAN_user_parameters_manage_itemtypes ) %]
68
                        <dt><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></dt>
70
                        <dt><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></dt>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/desks.tt (+190 lines)
Line 0 Link Here
1
[% USE raw %]
2
[% USE Branches %]
3
[% USE Asset %]
4
[% SET footerjs = 1 %]
5
[% INCLUDE 'doc-head-open.inc' %]
6
<title>Koha &rsaquo; Administration &rsaquo; [% IF op =='add_form' %]Desks &rsaquo; [% IF desk.desk_id %] Modify desk[% ELSE %] New desk[% END %][% ELSE %][% IF op == 'delete_confirm' %]Desks &rsaquo; Confirm deletion of desk[% ELSE %] Desks[% END %][% END %]</title>
7
[% INCLUDE 'doc-head-close.inc' %]
8
</head>
9
10
<body id="admin_desks" class="admin">
11
[% INCLUDE 'header.inc' %]
12
[% INCLUDE 'desks-admin-search.inc' %]
13
14
<div id="breadcrumbs">
15
    <a href="/cgi-bin/koha/mainpage.pl">Home</a>
16
    &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
17
    &rsaquo; <a href="/cgi-bin/koha/admin/desks.pl">Desks</a>
18
    [% IF op == 'add_form' %]
19
    &rsaquo; [% IF desk.desk_id %]Modify[% ELSE %]New[% END %] Desk
20
    [% ELSIF op == 'delete_confirm' %]
21
    &rsaquo; Confirm deletion of desk
22
    [% END %]
23
</div>
24
25
<div class="main container-fluid">
26
    <div class="row">
27
        <div class="col-sm-10 col-sm-push-2">
28
            <main>
29
30
[% FOR m IN messages %]
31
    <div class="dialog [% m.type | html %]">
32
        [% SWITCH m.code %]
33
        [% CASE 'error_on_update' %]
34
            An error occurred when updating this desk. Perhaps it already exists.
35
        [% CASE 'error_on_insert' %]
36
            An error occurred when adding this desk. The desk id might already exist.
37
        [% CASE 'error_on_delete' %]
38
            An error occurred when deleting this desk. Check the logs.
39
        [% CASE 'success_on_update' %]
40
            Desk updated successfully.
41
        [% CASE 'success_on_insert' %]
42
            Desk added successfully.
43
        [% CASE 'success_on_delete' %]
44
            Desk deleted successfully.
45
        [% CASE 'already_exists' %]
46
            This desk already exists.
47
        [% CASE %]
48
            [% m.code | html %]
49
        [% END %]
50
    </div>
51
[% END %]
52
53
[% IF op == 'add_form' %]
54
    [% IF desk %]
55
        <h1>Modify a desk</h1>
56
    [% ELSE %]
57
        <h1>New desk</h1>
58
    [% END %]
59
60
    <form action="/cgi-bin/koha/admin/desks.pl" name="Aform" method="post" class="validated">
61
        <input type="hidden" name="op" value="add_validate" />
62
        <input type="hidden" name="desk_id" value="[% desk.desk_id | html %]" />
63
64
        <fieldset class="rows">
65
            <ol>
66
                [% IF desk %]
67
                    <li><span class="label">Desk ID: </span>[% desk.desk_id | html %]</li>
68
                [% END %]
69
                <li>
70
                    <label for="desk_name" class="required">Desk: </label>
71
                    <input type="text" name="desk_name" id="desk_name" size="80" maxlength="100" value="[% desk.desk_name | html %]" required="required" class="required" /> <span class="required">Required</span>
72
                </li>
73
                <li>
74
                    <label for="branchcode" class="required">Library: </label>
75
                    <select id="branchcode" name="branchcode" required="required">
76
                      <option value=""></option>
77
                      [% FOREACH branch IN branches %]
78
                        [% IF (Branches.GetLoggedInBranchcode == branch.branchcode) %]
79
                        <option value="[% branch.branchcode|html %]" selected="selected">[% branch.branchname|html %]</option>
80
                        [% ELSE %]
81
                        <option value="[% branch.branchcode|html %]">[% branch.branchname|html %]</option>
82
                        [% END %]
83
                      [% END %]
84
                     </select>
85
                </li>
86
87
            </ol>
88
        </fieldset>
89
90
        <fieldset class="action">
91
            <input type="submit" value="Submit" />
92
            <a class="cancel" href="/cgi-bin/koha/admin/desks.pl">Cancel</a>
93
        </fieldset>
94
    </form>
95
[% END %]
96
97
[% IF op == 'delete_confirm' %]
98
    <div class="dialog alert">
99
        <h3>Delete desk "[% desk.desk_name | html %]?"</h3>
100
        <table>
101
            <tr><th>Desk id</th>
102
                <td>[% desk.desk_id | html %]</td>
103
            </tr>
104
            <tr><th>Desk</th>
105
                <td>[% desk.desk_name | html %]</td>
106
            </tr>
107
            <tr><th>Branchcode</th>
108
                <td>[% desk.branchcode | html %]</td>
109
            </tr>
110
        </table>
111
        <form action="/cgi-bin/koha/admin/desks.pl" method="post">
112
            <input type="hidden" name="op" value="delete_confirmed" />
113
            <input type="hidden" name="desk_id" value="[% desk.desk_id | html %]" />
114
            <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
115
        </form>
116
        <form action="/cgi-bin/koha/admin/desks.pl" method="get">
117
            <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
118
        </form>
119
    </div>
120
[% END %]
121
122
[% IF op == 'list' %]
123
124
    <div id="toolbar" class="btn-toolbar">
125
        <a class="btn btn-default" id="newdesk" href="/cgi-bin/koha/admin/desks.pl?op=add_form"><i class="fa fa-plus"></i> New desk</a>
126
    </div>
127
128
    <h2>Desks</h2>
129
    [% IF searchfield %]
130
        Searching: [% searchfield | html %]
131
    [% END %]
132
133
    [% IF desks.count %]
134
        <table id="table_desks">
135
            <thead>
136
                <tr>
137
                    <th>Desk ID</th>
138
                    <th>Desk</th>
139
                    <th>Library</th>
140
                    <th>Action</th>
141
                </tr>
142
            </thead>
143
            <tbody>
144
                [% FOREACH desk IN desks %]
145
                <tr>
146
                    <td>[% desk.desk_id | html %]</td>
147
                    <td>[% desk.desk_name | html %]</td>
148
                    <td>[% desk.branchcode | html %]</td>
149
                    <td class="actions">
150
                        <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/desks.pl?op=add_form&amp;desk_id=[% desk.desk_id | html %]"><i class="fa fa-pencil"></i> Edit</a>
151
                        <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/desks.pl?op=delete_confirm&amp;desk_id=[% desk.desk_id | html %]"><i class="fa fa-trash"></i> Delete</a>
152
                    </td>
153
                </tr>
154
                [% END %]
155
            </tbody>
156
        </table>
157
    [% ELSE %]
158
        <div class="dialog message">
159
            There are no desks defined. <a href="/cgi-bin/koha/admin/desks.pl?op=add_form">Create a new desk</a>.
160
        </div>
161
    [% END %]
162
[% END %]
163
164
            </main>
165
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
166
167
        <div class="col-sm-2 col-sm-pull-10">
168
            <aside>
169
                [% INCLUDE 'admin-menu.inc' %]
170
            </aside>
171
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
172
     </div> <!-- /.row -->
173
174
[% MACRO jsinclude BLOCK %]
175
    [% Asset.js("js/admin-menu.js") | $raw %]
176
    [% INCLUDE 'datatables.inc' %]
177
    <script>
178
        $(document).ready(function() {
179
            $("#table_desks").dataTable($.extend(true, {}, dataTablesDefaults, {
180
                "aoColumnDefs": [
181
                    { "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false },
182
                ],
183
                "aaSorting": [[ 1, "asc" ]],
184
                "iDisplayLength": 10,
185
                "sPaginationType": "full_numbers"
186
            }));
187
        });
188
    </script>
189
[% END %]
190
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/t/db_dependent/Koha/Desks.t (-1 / +60 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2015 Koha Development team
4
# Copyright 2020 BULAC
5
#
6
# This file is part of Koha
7
#
8
# Koha is free software; you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 3 of the License, or
11
# (at your option) any later version.
12
#
13
# Koha is distributed in the hope that it will be useful, but
14
# WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21
use Modern::Perl;
22
23
use Test::More tests => 4;
24
25
use Koha::Desk;
26
use Koha::Desks;
27
use Koha::Database;
28
use Koha::Libraries;
29
30
use t::lib::TestBuilder;
31
32
my $schema = Koha::Database->new->schema;
33
$schema->storage->txn_begin;
34
35
# Add CPL if missing.
36
if (not defined Koha::Libraries->find('CPL')) {
37
    Koha::Library->new({ branchcode => 'CPL', branchname => 'Centerville' })->store;
38
}
39
40
my $builder = t::lib::TestBuilder->new;
41
my $nb_of_desks = Koha::Desks->search->count;
42
my $new_desk_1 = Koha::Desk->new({
43
    desk_name  => 'my_desk_name_for_test_1',
44
    branchcode => 'CPL',
45
})->store;
46
my $new_desk_2 = Koha::Desk->new({
47
    desk_name  => 'my_desk_name_for_test_2',
48
    branchcode => 'CPL',
49
})->store;
50
51
like( $new_desk_1->desk_id, qr|^\d+$|, 'Adding a new desk should have set the desk_id');
52
is( Koha::Desks->search->count, $nb_of_desks + 2, 'The 2 desks should have been added' );
53
54
my $retrieved_desk_1 = Koha::Desks->find( $new_desk_1->desk_id );
55
is( $retrieved_desk_1->desk_name, $new_desk_1->desk_name, 'Find a desk by id should return the correct desk' );
56
57
$retrieved_desk_1->delete;
58
is( Koha::Desks->search->count, $nb_of_desks + 1, 'Delete should have deleted the desk' );
59
60
$schema->storage->txn_rollback;

Return to bug 13881