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

(-)a/Koha/Desk.pm (+44 lines)
Line 0 Link Here
1
package Koha::Desk;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::Desk - Koha Desk Object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 type
37
38
=cut
39
40
sub _type {
41
    return 'Desk';
42
}
43
44
1;
(-)a/Koha/Desks.pm (+50 lines)
Line 0 Link Here
1
package Koha::Desks;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use Koha::Desk;
25
26
use base qw(Koha::Objects);
27
28
=head1 NAME
29
30
Koha::Desks - Koha Desk Object set class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 type
39
40
=cut
41
42
sub _type {
43
    return 'Desk';
44
}
45
46
sub object_class {
47
    return 'Koha::Desk';
48
}
49
50
1;
(-)a/admin/desks.pl (+116 lines)
Line 0 Link Here
1
#! /usr/bin/perl
2
3
# Copyright 2006 SAN OUEST-PROVENCE et Paul POULAIN
4
# Copyright 2015 Koha Development Team
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
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
use Data::Dumper;
107
108
$template->param(
109
    desk_id      => $desk_id,
110
    searchfield => $searchfield,
111
    messages    => \@messages,
112
    op          => $op,
113
    branches    => $branches,
114
);
115
116
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/modules/admin/admin-home.tt (+2 lines)
Lines 54-59 Link Here
54
                        <dd>Define libraries.</dd>
54
                        <dd>Define libraries.</dd>
55
                        <dt><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></dt>
55
                        <dt><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></dt>
56
                        <dd>Define hierarchical library groups.</dd>
56
                        <dd>Define hierarchical library groups.</dd>
57
                        <dt><a href="/cgi-bin/koha/admin/desks.pl">Desks</a></dt>
58
                        <dd>Define desks.</dd>
57
                    [% END %]
59
                    [% END %]
58
                    [% IF ( CAN_user_parameters_manage_itemtypes ) %]
60
                    [% IF ( CAN_user_parameters_manage_itemtypes ) %]
59
                        <dt><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></dt>
61
                        <dt><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></dt>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/desks.tt (-1 / +195 lines)
Line 0 Link Here
0
- 
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
        [% IF desk_id %]
63
        <input type="hidden" name="desk_id" value="[% desk.desk_id | html %]" />
64
        [% END %]
65
        <fieldset class="rows">
66
            <ol>
67
                [% IF desk_id %]
68
                    <li><span class="label">Desk ID: </span>[% desk.desk_id | html %]</li>
69
                [% ELSE %]
70
                    <li>
71
                      <label for="desk_name" class="required">Desk ID:</label>
72
                      <input type="text" name="desk_id" id="deskdi" size="11" maxlength="11" value="[% desk.desk_id | html %]" required="required" class="required" /> <span class="required">Required</span>
73
                [% END %]
74
                <li>
75
                    <label for="desk_name" class="required">Desk: </label>
76
                    <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>
77
                </li>
78
                <li>
79
	    <label for="branchcode" class="required">Library: </label>
80
            <select id="branchcode" name="branchcode" required="required">
81
              <option value=""></option>
82
              [% FOREACH branch IN branches %]
83
                [% IF (Branches.GetLoggedInBranchcode == branch.branchcode) %]
84
                <option value="[% branch.branchcode %]" selected="selected">[% branch.branchname %]</option>
85
                [% ELSE %]
86
                <option value="[% branch.branchcode %]">[% branch.branchname %]</option>
87
            [% END %]
88
              [% END %]
89
            </select>
90
          </li>
91
92
            </ol>
93
        </fieldset>
94
95
        <fieldset class="action">
96
            <input type="submit" value="Submit" />
97
            <a class="cancel" href="/cgi-bin/koha/admin/desks.pl">Cancel</a>
98
        </fieldset>
99
    </form>
100
[% END %]
101
102
[% IF op == 'delete_confirm' %]
103
    <div class="dialog alert">
104
        <h3>Delete desk "[% desk.desk_name | html %]?"</h3>
105
        <table>
106
            <tr><th>Desk id</th>
107
                <td>[% desk.desk_id | html %]</td>
108
            </tr>
109
            <tr><th>Desk</th>
110
                <td>[% desk.desk_name | html %]</td>
111
            </tr>
112
            <tr><th>Library</th>
113
                <td>[% desk.branchcode | html %]</td>
114
            </tr>
115
        </table>
116
        <form action="/cgi-bin/koha/admin/desks.pl" method="post">
117
            <input type="hidden" name="op" value="delete_confirmed" />
118
            <input type="hidden" name="desk_id" value="[% desk.desk_id | html %]" />
119
            <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
120
        </form>
121
        <form action="/cgi-bin/koha/admin/desks.pl" method="get">
122
            <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
123
        </form>
124
    </div>
125
[% END %]
126
127
[% IF op == 'list' %]
128
129
    <div id="toolbar" class="btn-toolbar">
130
        <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>
131
    </div>
132
133
    <h2>Desks</h2>
134
    [% IF searchfield %]
135
        Searching: [% searchfield | html %]
136
    [% END %]
137
138
    [% IF desks.count %]
139
        <table id="table_desks">
140
            <thead>
141
                <tr>
142
                    <th>Desk ID</th>
143
                    <th>Desk</th>
144
                    <th>Library</th>
145
                    <th>Action</th>
146
                </tr>
147
            </thead>
148
            <tbody>
149
                [% FOREACH desk IN desks %]
150
                <tr>
151
                    <td>[% desk.desk_id | html %]</td>
152
                    <td>[% desk.desk_name | html %]</td>
153
                    <td>[% desk.branchcode | html %]</td>
154
                    <td class="actions">
155
                        <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>
156
                        <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>
157
                    </td>
158
                </tr>
159
                [% END %]
160
            </tbody>
161
        </table>
162
    [% ELSE %]
163
        <div class="dialog message">
164
            There are no desks defined. <a href="/cgi-bin/koha/admin/desks.pl?op=add_form">Create a new desk</a>.
165
        </div>
166
    [% END %]
167
[% END %]
168
169
            </main>
170
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
171
172
        <div class="col-sm-2 col-sm-pull-10">
173
            <aside>
174
                [% INCLUDE 'admin-menu.inc' %]
175
            </aside>
176
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
177
     </div> <!-- /.row -->
178
179
[% MACRO jsinclude BLOCK %]
180
    [% Asset.js("js/admin-menu.js") | $raw %]
181
    [% INCLUDE 'datatables.inc' %]
182
    <script>
183
        $(document).ready(function() {
184
            $("#table_desks").dataTable($.extend(true, {}, dataTablesDefaults, {
185
                "aoColumnDefs": [
186
                    { "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable": false },
187
                ],
188
                "aaSorting": [[ 1, "asc" ]],
189
                "iDisplayLength": 10,
190
                "sPaginationType": "full_numbers"
191
            }));
192
        });
193
    </script>
194
[% END %]
195
[% INCLUDE 'intranet-bottom.inc' %]

Return to bug 13881