Bug 15707: Add library groups editor
authorKyle M Hall <kyle@bywatersolutions.com>
Sun, 31 Jan 2016 11:22:51 +0000 (11:22 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 9 Feb 2018 18:05:53 +0000 (15:05 -0300)
Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
admin/library_groups.pl [new file with mode: 0755]
koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc
koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt [new file with mode: 0644]

diff --git a/admin/library_groups.pl b/admin/library_groups.pl
new file mode 100755 (executable)
index 0000000..e506d48
--- /dev/null
@@ -0,0 +1,102 @@
+#! /usr/bin/perl
+
+# Copyright 2016 ByWater Solutions
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+use CGI qw ( -utf8 );
+use C4::Context;
+use C4::Auth;
+use C4::Output;
+
+use Koha::Libraries;
+use Koha::Library::Group;
+use Koha::Library::Groups;
+
+my $cgi = new CGI;
+
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+    {
+        template_name   => "admin/library_groups.tt",
+        query           => $cgi,
+        type            => "intranet",
+        authnotrequired => 0,
+        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
+        debug           => 1,
+    }
+);
+
+my $action = $cgi->param('action') || q{};
+
+if ( $action eq 'add' ) {
+    my $parent_id   = $cgi->param('parent_id')   || undef;
+    my $title       = $cgi->param('title')       || undef;
+    my $description = $cgi->param('description') || undef;
+    my $branchcode  = $cgi->param('branchcode')  || undef;
+
+    my $group = Koha::Library::Group->new(
+        {
+            parent_id   => $parent_id,
+            title       => $title,
+            description => $description,
+            branchcode  => $branchcode,
+        }
+    )->store();
+
+    $template->param( added => $group );
+}
+elsif ( $action eq 'edit' ) {
+    my $id          = $cgi->param('id')          || undef;
+    my $title       = $cgi->param('title')       || undef;
+    my $description = $cgi->param('description') || undef;
+
+    if ($id) {
+        my $group = Koha::Library::Groups->find($id);
+
+        $group->set(
+            {
+                title       => $title,
+                description => $description,
+            }
+        )->store();
+
+        $template->param( edited => $group );
+    }
+}
+elsif ( $action eq 'delete' ) {
+    my $id = $cgi->param('id');
+
+    my $group = Koha::Library::Groups->find($id);
+
+    if ($group) {
+        $group->delete();
+        $template->param(
+            deleted => {
+                title   => $group->title(),
+                library => $group->library()
+                ? $group->library()->branchname
+                : undef
+            }
+        );
+    }
+}
+
+my $root_groups = Koha::Library::Groups->get_root_groups();
+
+$template->param( root_groups => $root_groups, );
+
+output_html_with_http_headers $cgi, $cookie, $template->output;
index 5a08564..b2a330c 100644 (file)
@@ -10,6 +10,7 @@
 <h5>Basic parameters</h5>
 <ul>
     <li><a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a></li>
+    <li><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></li>
     <li><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></li>
     <li><a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a></li>
 </ul>
index dd29587..652c796 100644 (file)
@@ -32,6 +32,8 @@
                 <dl>
                     <dt><a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a></dt>
                     <dd>Define libraries and groups.</dd>
+                    <dt><a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a></dt>
+                    <dd>Define library hierarchies.</dd>
                     <dt><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></dt>
                     <dd>Define item types used for circulation rules.</dd>
                     <dt><a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a></dt>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt
new file mode 100644 (file)
index 0000000..4e25a54
--- /dev/null
@@ -0,0 +1,266 @@
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Koha &rsaquo; Administration &rsaquo; Library groups</title>
+[% INCLUDE 'doc-head-close.inc' %]
+<script type="text/javascript" src="[% interface %]/lib/jquery-treegrid/js/jquery.treegrid.min.js"></script>
+<script type="text/javascript" src="[% interface %]/lib/jquery-treegrid/js/jquery.treegrid.bootstrap2.js"></script>
+<link rel="stylesheet" href="[% interface %]/lib/jquery-treegrid/css/jquery.treegrid.css">
+<script type="text/javascript">
+//<![CDATA[
+    $(document).ready(function() {
+        $('#library-groups').treegrid(
+            {
+                'saveState': true
+            }
+        );
+    });
+
+    function add_group( parent_id ) {
+        $('#add-group-modal-parent-id').val( parent_id );
+
+        $('#add-group-modal-description').val("");
+        $('#add-group-modal-title').val("");
+
+        $('#add-group-modal').on('shown', function() {
+            $('#add-group-modal-title').focus();
+        });
+
+        $('#add-group-modal').modal('show');
+    }
+
+    function edit_group( id, title, description ) {
+        $('#edit-group-modal-id').val( id );
+        $('#edit-group-modal-title').val( title );
+        $('#edit-group-modal-description').val( description );
+
+        $('#edit-group-modal').on('shown', function() {
+            $('#edit-group-modal-title').focus();
+        });
+
+        $('#edit-group-modal').modal('show');
+    }
+
+    function remove_library( id ) {
+        $('#remove-library-modal-id').val( id );
+        $('#remove-library-modal').modal('show');
+    }
+
+    function delete_group( id ) {
+        $('#delete-group-modal-id').val( id );
+        $('#delete-group-modal').modal('show');
+    }
+//]]>
+</script>
+</head>
+<body id="admin_library_groups" class="admin">
+[% INCLUDE 'header.inc' %]
+[% INCLUDE 'cities-admin-search.inc' %]
+
+<div id="breadcrumbs">
+    <a href="/cgi-bin/koha/mainpage.pl">Home</a>
+    &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
+    &rsaquo; <a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a>
+</div>
+
+[% IF added %]
+    <div class="dialog alert group-added">
+        [% IF added.branchcode %]
+            <i>[% added.library.branchname %]</i> added to group.
+        [% ELSE %]
+            Group <i>[% added.title %]</i> created.
+        [% END %]
+    </div>
+[% ELSIF deleted %]
+    <div class="dialog alert group-deleted">
+        [% IF deleted.title %]
+            Group <i>[% deleted.title %]</i> has been deleted.
+        [% ELSE %]
+            <i>[% deleted.library %]</i> has been removed from group.
+        [% END %]
+    </div>
+[% END %]
+
+<div id="doc3" class="yui-t2">
+    <div id="bd">
+        <div id="yui-main">
+            <div class="yui-b">
+                <div class="yui-g">
+                    <div id="toolbar" class="btn-toolbar">
+                        <div class="btn-group">
+                            <a id="add-group-[% group.id %]" class="btn btn-small" href="#" onclick="add_group()">
+                                <i class="fa fa-plus-circle"></i> Add group
+                            </a>
+                        </div>
+                    </div>
+                </div>
+
+                [% FOREACH root_group IN root_groups %]
+                    <table id="library-groups" class="tree">
+                        <tr>
+                            <th>&nbsp;</th>
+                            <th>Description</th>
+                            <th>&nbsp;</th>
+                        </tr>
+                        [% PROCESS tree group=root_group %]
+                    </table>
+                [% END %]
+            </div>
+        </div>
+
+    <div class="yui-b">
+        [% INCLUDE 'admin-menu.inc' %]
+    </div>
+
+    <div id="add-group-modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="add-group-modal-label" aria-hidden="true">
+        <form id="add-group-form" action="/cgi-bin/koha/admin/library_groups.pl" class="form-horizontal">
+            <div class="modal-header">
+                <h3 id="add-group-modal-label">Add group</h3>
+            </div>
+            <div class="modal-body">
+                <input type="hidden" id="add-group-modal-parent-id" name="parent_id" value="" />
+                <input type="hidden" id="add-group-modal-action" name="action" value="add">
+
+                <p>
+                    <label for="title">Title: </label>
+                    <input type="text" name="title" id="add-group-modal-title" required="required" />
+                    <i>required</i>
+                </p>
+
+                <p>
+                    <label for="description">Description: </label>
+                    <input type="text" name="description" id="add-group-modal-description" />
+                </p>
+            </div>
+            <div class="modal-footer">
+                <button type="submit" class="btn btn-primary">Save</button>
+                <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
+            </div>
+        </form>
+    </div>
+
+    <div id="edit-group-modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="edit-library-modal-label" aria-hidden="true">
+        <form id="edit-group-form" action="/cgi-bin/koha/admin/library_groups.pl" class="form-horizontal">
+            <div class="modal-header">
+                <h3 id="edit-group-modal-label">Edit group</h3>
+            </div>
+            <div class="modal-body">
+                <input type="hidden" id="edit-group-modal-id" name="id" value="" />
+                <input type="hidden" id="edit-group-modal-action" name="action" value="edit" />
+
+                <p>
+                    <label for="title">Title: </label>
+                    <input type="text" id="edit-group-modal-title" name="title" value="" required="required" />
+                    <i>required</i>
+                </p>
+
+                <p>
+                    <label for="description">Description: </label>
+                    <input type="text" id="edit-group-modal-description" name="description" value="" />
+                </p>
+            </div>
+            <div class="modal-footer">
+                <button type="submit" class="btn btn-primary">Update</button>
+                <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
+            </div>
+        </form>
+    </div>
+
+    <div id="delete-group-modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="delete-group-modal-label" aria-hidden="true">
+        <form action="/cgi-bin/koha/admin/library_groups.pl" />
+            <input id="delete-group-modal-action" type="hidden" name="action" value="delete" />
+            <input id="delete-group-modal-id" type="hidden" name="id" value="" />
+            <div class="modal-header">
+                <h3 id="delete-group-modal-label">Delete group or library</h3>
+            </div>
+            <div class="modal-body">
+                Are you sure you want to delete this?
+            </div>
+            <div class="modal-footer">
+                <button type="submit" class="btn btn-danger"><i class="fa fa-trash"></i> Delete</button>
+                <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
+            </div>
+        </form>
+    </div>
+
+    <div id="remove-library-modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="remove-library-modal-label" aria-hidden="true">
+        <form action="/cgi-bin/koha/admin/library_groups.pl" />
+            <input id="remove-library-modal-action" type="hidden" name="action" value="delete" />
+            <input id="remove-library-modal-id" type="hidden" name="id" value="" />
+            <div class="modal-header">
+                <h3 id="remove-library-modal-label">Remove library from group</h3>
+            </div>
+            <div class="modal-body">
+                Are you sure you want to remove this library?
+            </div>
+            <div class="modal-footer">
+                <button type="submit" class="btn btn-danger"><i class="fa fa-minus-circle"></i> Remove</button>
+                <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
+            </div>
+        </form>
+    </div>
+
+</div>
+[% INCLUDE 'intranet-bottom.inc' %]
+
+[% BLOCK tree %]
+    <tr class="treegrid-[% group.id %] treegrid-parent-[% group.parent_id %]">
+        <td>
+            [% IF group.branchcode %]
+                <i class="fa fa-home"></i> [% group.branchcode %]
+            [% ELSE %]
+                <i class="fa fa-object-group"></i> [% group.title %]
+            [% END %]
+        </td>
+        <td>
+            [% IF group.branchcode %]
+                [% group.library.branchname %]
+            [% ELSE %]
+                [% group.description %]
+            [% END %]
+        </td>
+        <td>
+            [% IF group.branchcode %]
+                <button class="btn btn-small delete-library" onclick="remove_library([% group.id %])"><i class="fa fa-minus-circle"></i> Remove from group</button>
+            [% ELSE %]
+                <div class="btn-group">
+                    <button class="btn btn-small dropdown-toggle" data-toggle="dropdown"><i class="fa fa-wrench"></i> Actions <span class="caret"></span></button>
+                    <ul class="dropdown-menu">
+                        <li>
+                            <a id="add-group-[% group.id %]" href="#" onclick="add_group([% group.id %])">
+                                <i class="fa fa-plus-circle"></i> Add sub-group
+                            </a>
+                       </li>
+
+                        <li>
+                            <a class="delete-group" id="delete-group-[% group.id %]" href="#" onclick="edit_group([% group.id %], '[% group.title | replace('\'', '\\\'') | html %]', '[% group.description | replace('\'', '\\\'') | html %]')">
+                                <i class="fa fa-edit"></i> Edit
+                            </a>
+                       </li>
+
+                        <li>
+                            <a class="delete-group" id="delete-group-[% group.id %]" href="#" onclick="delete_group([% group.id %])">
+                                <i class="fa fa-trash"></i> Delete
+                            </a>
+                       </li>
+                    </ul>
+                </div>
+
+                <div class="btn-group">
+                    <button class="btn btn-small dropdown-toggle" data-toggle="dropdown"><i class="fa fa-home"></i> Add library <span class="caret"></span></button>
+                    <ul class="dropdown-menu">
+                        [% FOREACH library IN group.libraries_not_direct_children %]
+                            <li>
+                                <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 %]">
+                                    [% library.branchname %]
+                                </a>
+                           </li>
+                        [% END %]
+                    </ul>
+                </div>
+            [% END %]
+        </td>
+    </tr>
+
+    [% FOREACH g IN group.children %]
+        [% PROCESS tree group=g %]
+    [% END %]
+[% END %]