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

(-)a/admin/library_groups.pl (+102 lines)
Line 0 Link Here
1
#! /usr/bin/perl
2
3
# Copyright 2016 ByWater Solutions
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
use CGI qw ( -utf8 );
22
use C4::Context;
23
use C4::Auth;
24
use C4::Output;
25
26
use Koha::Libraries;
27
use Koha::Library::Group;
28
use Koha::Library::Groups;
29
30
my $cgi = new CGI;
31
32
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
33
    {
34
        template_name   => "admin/library_groups.tt",
35
        query           => $cgi,
36
        type            => "intranet",
37
        authnotrequired => 0,
38
        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
39
        debug           => 1,
40
    }
41
);
42
43
my $action = $cgi->param('action') || q{};
44
45
if ( $action eq 'add' ) {
46
    my $parent_id   = $cgi->param('parent_id')   || undef;
47
    my $title       = $cgi->param('title')       || undef;
48
    my $description = $cgi->param('description') || undef;
49
    my $branchcode  = $cgi->param('branchcode')  || undef;
50
51
    my $group = Koha::Library::Group->new(
52
        {
53
            parent_id   => $parent_id,
54
            title       => $title,
55
            description => $description,
56
            branchcode  => $branchcode,
57
        }
58
    )->store();
59
60
    $template->param( added => $group );
61
}
62
elsif ( $action eq 'edit' ) {
63
    my $id          = $cgi->param('id')          || undef;
64
    my $title       = $cgi->param('title')       || undef;
65
    my $description = $cgi->param('description') || undef;
66
67
    if ($id) {
68
        my $group = Koha::Library::Groups->find($id);
69
70
        $group->set(
71
            {
72
                title       => $title,
73
                description => $description,
74
            }
75
        )->store();
76
77
        $template->param( edited => $group );
78
    }
79
}
80
elsif ( $action eq 'delete' ) {
81
    my $id = $cgi->param('id');
82
83
    my $group = Koha::Library::Groups->find($id);
84
85
    if ($group) {
86
        $group->delete();
87
        $template->param(
88
            deleted => {
89
                title   => $group->title(),
90
                library => $group->library()
91
                ? $group->library()->branchname
92
                : undef
93
            }
94
        );
95
    }
96
}
97
98
my $root_groups = Koha::Library::Groups->get_root_groups();
99
100
$template->param( root_groups => $root_groups, );
101
102
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc (+1 lines)
Lines 20-25 Link Here
20
<h5>Basic parameters</h5>
20
<h5>Basic parameters</h5>
21
<ul>
21
<ul>
22
    <li><a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a></li>
22
    <li><a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a></li>
23
    <li><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></li>
23
    <li><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></li>
24
    <li><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></li>
24
    <li><a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a></li>
25
    <li><a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a></li>
25
</ul>
26
</ul>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (+2 lines)
Lines 30-35 Link Here
30
                <dl>
30
                <dl>
31
                    <dt><a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a></dt>
31
                    <dt><a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a></dt>
32
                    <dd>Define libraries and groups.</dd>
32
                    <dd>Define libraries and groups.</dd>
33
                    <dt><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></dt>
34
                    <dd>Define library hierarchies.</dd>
33
                    <dt><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></dt>
35
                    <dt><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></dt>
34
                    <dd>Define item types used for circulation rules.</dd>
36
                    <dd>Define item types used for circulation rules.</dd>
35
                    <dt><a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a></dt>
37
                    <dt><a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a></dt>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt (-1 / +266 lines)
Line 0 Link Here
0
- 
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Administration &rsaquo; Library groups</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript" src="[% interface %]/lib/jquery-treegrid/js/jquery.treegrid.min.js"></script>
5
<script type="text/javascript" src="[% interface %]/lib/jquery-treegrid/js/jquery.treegrid.bootstrap2.js"></script>
6
<link rel="stylesheet" href="[% interface %]/lib/jquery-treegrid/css/jquery.treegrid.css">
7
<script type="text/javascript">
8
//<![CDATA[
9
    $(document).ready(function() {
10
        $('#library-groups').treegrid(
11
            {
12
                'saveState': true
13
            }
14
        );
15
    });
16
17
    function add_group( parent_id ) {
18
        $('#add-group-modal-parent-id').val( parent_id );
19
20
        $('#add-group-modal-description').val("");
21
        $('#add-group-modal-title').val("");
22
23
        $('#add-group-modal').on('shown', function() {
24
            $('#add-group-modal-title').focus();
25
        });
26
27
        $('#add-group-modal').modal('show');
28
    }
29
30
    function edit_group( id, title, description ) {
31
        $('#edit-group-modal-id').val( id );
32
        $('#edit-group-modal-title').val( title );
33
        $('#edit-group-modal-description').val( description );
34
35
        $('#edit-group-modal').on('shown', function() {
36
            $('#edit-group-modal-title').focus();
37
        });
38
39
        $('#edit-group-modal').modal('show');
40
    }
41
42
    function remove_library( id ) {
43
        $('#remove-library-modal-id').val( id );
44
        $('#remove-library-modal').modal('show');
45
    }
46
47
    function delete_group( id ) {
48
        $('#delete-group-modal-id').val( id );
49
        $('#delete-group-modal').modal('show');
50
    }
51
//]]>
52
</script>
53
</head>
54
<body id="admin_library_groups" class="admin">
55
[% INCLUDE 'header.inc' %]
56
[% INCLUDE 'cities-admin-search.inc' %]
57
58
<div id="breadcrumbs">
59
    <a href="/cgi-bin/koha/mainpage.pl">Home</a>
60
    &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
61
    &rsaquo; <a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a>
62
</div>
63
64
[% IF added %]
65
    <div class="dialog alert group-added">
66
        [% IF added.branchcode %]
67
            <i>[% added.library.branchname %]</i> added to group.
68
        [% ELSE %]
69
            Group <i>[% added.title %]</i> created.
70
        [% END %]
71
    </div>
72
[% ELSIF deleted %]
73
    <div class="dialog alert group-deleted">
74
        [% IF deleted.title %]
75
            Group <i>[% deleted.title %]</i> has been deleted.
76
        [% ELSE %]
77
            <i>[% deleted.library %]</i> has been removed from group.
78
        [% END %]
79
    </div>
80
[% END %]
81
82
<div id="doc3" class="yui-t2">
83
    <div id="bd">
84
        <div id="yui-main">
85
            <div class="yui-b">
86
                <div class="yui-g">
87
                    <div id="toolbar" class="btn-toolbar">
88
                        <div class="btn-group">
89
                            <a id="add-group-[% group.id %]" class="btn btn-small" href="#" onclick="add_group()">
90
                                <i class="fa fa-plus-circle"></i> Add group
91
                            </a>
92
                        </div>
93
                    </div>
94
                </div>
95
96
                [% FOREACH root_group IN root_groups %]
97
                    <table id="library-groups" class="tree">
98
                        <tr>
99
                            <th>&nbsp;</th>
100
                            <th>Description</th>
101
                            <th>&nbsp;</th>
102
                        </tr>
103
                        [% PROCESS tree group=root_group %]
104
                    </table>
105
                [% END %]
106
            </div>
107
        </div>
108
109
    <div class="yui-b">
110
        [% INCLUDE 'admin-menu.inc' %]
111
    </div>
112
113
    <div id="add-group-modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="add-group-modal-label" aria-hidden="true">
114
        <form id="add-group-form" action="/cgi-bin/koha/admin/library_groups.pl" class="form-horizontal">
115
            <div class="modal-header">
116
                <h3 id="add-group-modal-label">Add group</h3>
117
            </div>
118
            <div class="modal-body">
119
                <input type="hidden" id="add-group-modal-parent-id" name="parent_id" value="" />
120
                <input type="hidden" id="add-group-modal-action" name="action" value="add">
121
122
                <p>
123
                    <label for="title">Title: </label>
124
                    <input type="text" name="title" id="add-group-modal-title" required="required" />
125
                    <i>required</i>
126
                </p>
127
128
                <p>
129
                    <label for="description">Description: </label>
130
                    <input type="text" name="description" id="add-group-modal-description" />
131
                </p>
132
            </div>
133
            <div class="modal-footer">
134
                <button type="submit" class="btn btn-primary">Save</button>
135
                <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
136
            </div>
137
        </form>
138
    </div>
139
140
    <div id="edit-group-modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="edit-library-modal-label" aria-hidden="true">
141
        <form id="edit-group-form" action="/cgi-bin/koha/admin/library_groups.pl" class="form-horizontal">
142
            <div class="modal-header">
143
                <h3 id="edit-group-modal-label">Edit group</h3>
144
            </div>
145
            <div class="modal-body">
146
                <input type="hidden" id="edit-group-modal-id" name="id" value="" />
147
                <input type="hidden" id="edit-group-modal-action" name="action" value="edit" />
148
149
                <p>
150
                    <label for="title">Title: </label>
151
                    <input type="text" id="edit-group-modal-title" name="title" value="" required="required" />
152
                    <i>required</i>
153
                </p>
154
155
                <p>
156
                    <label for="description">Description: </label>
157
                    <input type="text" id="edit-group-modal-description" name="description" value="" />
158
                </p>
159
            </div>
160
            <div class="modal-footer">
161
                <button type="submit" class="btn btn-primary">Update</button>
162
                <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
163
            </div>
164
        </form>
165
    </div>
166
167
    <div id="delete-group-modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="delete-group-modal-label" aria-hidden="true">
168
        <form action="/cgi-bin/koha/admin/library_groups.pl" />
169
            <input id="delete-group-modal-action" type="hidden" name="action" value="delete" />
170
            <input id="delete-group-modal-id" type="hidden" name="id" value="" />
171
            <div class="modal-header">
172
                <h3 id="delete-group-modal-label">Delete group or library</h3>
173
            </div>
174
            <div class="modal-body">
175
                Are you sure you want to delete this?
176
            </div>
177
            <div class="modal-footer">
178
                <button type="submit" class="btn btn-danger"><i class="fa fa-trash"></i> Delete</button>
179
                <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
180
            </div>
181
        </form>
182
    </div>
183
184
    <div id="remove-library-modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="remove-library-modal-label" aria-hidden="true">
185
        <form action="/cgi-bin/koha/admin/library_groups.pl" />
186
            <input id="remove-library-modal-action" type="hidden" name="action" value="delete" />
187
            <input id="remove-library-modal-id" type="hidden" name="id" value="" />
188
            <div class="modal-header">
189
                <h3 id="remove-library-modal-label">Remove library from group</h3>
190
            </div>
191
            <div class="modal-body">
192
                Are you sure you want to remove this library?
193
            </div>
194
            <div class="modal-footer">
195
                <button type="submit" class="btn btn-danger"><i class="fa fa-minus-circle"></i> Remove</button>
196
                <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
197
            </div>
198
        </form>
199
    </div>
200
201
</div>
202
[% INCLUDE 'intranet-bottom.inc' %]
203
204
[% BLOCK tree %]
205
    <tr class="treegrid-[% group.id %] treegrid-parent-[% group.parent_id %]">
206
        <td>
207
            [% IF group.branchcode %]
208
                <i class="fa fa-home"></i> [% group.branchcode %]
209
            [% ELSE %]
210
                <i class="fa fa-object-group"></i> [% group.title %]
211
            [% END %]
212
        </td>
213
        <td>
214
            [% IF group.branchcode %]
215
                [% group.library.branchname %]
216
            [% ELSE %]
217
                [% group.description %]
218
            [% END %]
219
        </td>
220
        <td>
221
            [% IF group.branchcode %]
222
                <button class="btn btn-small delete-library" onclick="remove_library([% group.id %])"><i class="fa fa-minus-circle"></i> Remove from group</button>
223
            [% ELSE %]
224
                <div class="btn-group">
225
                    <button class="btn btn-small dropdown-toggle" data-toggle="dropdown"><i class="fa fa-wrench"></i> Actions <span class="caret"></span></button>
226
                    <ul class="dropdown-menu">
227
                        <li>
228
                            <a id="add-group-[% group.id %]" href="#" onclick="add_group([% group.id %])">
229
                                <i class="fa fa-plus-circle"></i> Add sub-group
230
                            </a>
231
                       </li>
232
233
                        <li>
234
                            <a class="delete-group" id="delete-group-[% group.id %]" href="#" onclick="edit_group([% group.id %], '[% group.title | replace('\'', '\\\'') | html %]', '[% group.description | replace('\'', '\\\'') | html %]')">
235
                                <i class="fa fa-edit"></i> Edit
236
                            </a>
237
                       </li>
238
239
                        <li>
240
                            <a class="delete-group" id="delete-group-[% group.id %]" href="#" onclick="delete_group([% group.id %])">
241
                                <i class="fa fa-trash"></i> Delete
242
                            </a>
243
                       </li>
244
                    </ul>
245
                </div>
246
247
                <div class="btn-group">
248
                    <button class="btn btn-small dropdown-toggle" data-toggle="dropdown"><i class="fa fa-home"></i> Add library <span class="caret"></span></button>
249
                    <ul class="dropdown-menu">
250
                        [% FOREACH library IN group.libraries_not_direct_children %]
251
                            <li>
252
                                <a class="add-library" id="add-library-[% group.id %]" href="/cgi-bin/koha/admin/library_groups.pl?action=add&parent_id=[% group.id %]&branchcode=[% library.id %]">
253
                                    [% library.branchname %]
254
                                </a>
255
                           </li>
256
                        [% END %]
257
                    </ul>
258
                </div>
259
            [% END %]
260
        </td>
261
    </tr>
262
263
    [% FOREACH g IN group.children %]
264
        [% PROCESS tree group=g %]
265
    [% END %]
266
[% END %]

Return to bug 15707