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

(-)a/Koha/List/Patron.pm (-1 / +9 lines)
Lines 63-69 sub GetPatronLists { Link Here
63
        return;
63
        return;
64
    }
64
    }
65
65
66
    delete( $params->{owner} ) if ( C4::Context->IsSuperLibrarian() );
66
    delete $params->{owner} if C4::Context->IsSuperLibrarian();
67
68
    if ( my $owner = $params->{owner} ) {
69
        delete $params->{owner};
70
        $params->{'-or'} = [
71
            owner => $owner,
72
            shared => 1,
73
        ];
74
    }
67
75
68
    my $schema = Koha::Database->new()->schema();
76
    my $schema = Koha::Database->new()->schema();
69
77
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/add-modify.tt (+9 lines)
Lines 50-55 Link Here
50
                        <input id="list-name" name="name" type="text" class="required" required="required" value="[% list.name %]" />
50
                        <input id="list-name" name="name" type="text" class="required" required="required" value="[% list.name %]" />
51
                    </li>
51
                    </li>
52
52
53
                    <li>
54
                        <label for="list-shared">Shared:</label>
55
                        [% IF list.shared %]
56
                            <input id="list-shared" name="shared" type="checkbox" checked="checked" />
57
                        [% ELSE %]
58
                            <input id="list-shared" name="shared" type="checkbox" />
59
                        [% END %]
60
                    </li>
61
53
                    <li>
62
                    <li>
54
                        <span class="label">Owner: </span>[% loggedinusername %]
63
                        <span class="label">Owner: </span>[% loggedinusername %]
55
                    </li>
64
                    </li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/lists.tt (-2 / +15 lines)
Lines 32-46 Link Here
32
                <tr>
32
                <tr>
33
                    <th>Name</th>
33
                    <th>Name</th>
34
                    <th>Patrons in list</th>
34
                    <th>Patrons in list</th>
35
                    <th>Shared</th>
35
                    <th class="NoSort">&nbsp;</th>
36
                    <th class="NoSort">&nbsp;</th>
36
                </tr>
37
                </tr>
37
            </thead>
38
            </thead>
38
39
39
            <tbody>
40
            <tbody>
40
                [% FOREACH l IN lists %]
41
                [% FOREACH l IN lists %]
42
                    [% SET shared_by_other = l.owner.id != logged_in_user %]
41
                    <tr>
43
                    <tr>
42
                        <td><a href="/cgi-bin/koha/patron_lists/list.pl?patron_list_id=[% l.patron_list_id %]">[% l.name |html%]</a></td>
44
                        <td><a href="/cgi-bin/koha/patron_lists/list.pl?patron_list_id=[% l.patron_list_id %]">[% l.name |html%]</a></td>
43
                        <td>[% l.patron_list_patrons_rs.count || 0 %]</td>
45
                        <td>[% l.patron_list_patrons_rs.count || 0 %]</td>
46
                        <td>
47
                            [% IF l.shared %]
48
                                [% IF shared_by_other %]
49
                                    by <a href=/cgi-bin/koha/members/moremember.pl?borrowernumber=[% l.owner.id %]">[% INCLUDE 'patron-title.inc' patron=l.owner %]</a>
50
                                [% ELSE %]
51
                                    by you
52
                                [% END %]
53
                            [% END %]
54
                        </td>
44
                        <td>
55
                        <td>
45
                            <div class="dropdown">
56
                            <div class="dropdown">
46
                                <a class="btn btn-default btn-xs dropdown-toggle" id="listactions[% l.patron_list_id %]" role="button" data-toggle="dropdown" href="#">
57
                                <a class="btn btn-default btn-xs dropdown-toggle" id="listactions[% l.patron_list_id %]" role="button" data-toggle="dropdown" href="#">
Lines 48-55 Link Here
48
                                </a>
59
                                </a>
49
                                <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="listactions[% l.patron_list_id %]">
60
                                <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="listactions[% l.patron_list_id %]">
50
                                    <li><a href="/cgi-bin/koha/patron_lists/list.pl?patron_list_id=[% l.patron_list_id %]"><i class="fa fa-user"></i> Add patrons</a></li>
61
                                    <li><a href="/cgi-bin/koha/patron_lists/list.pl?patron_list_id=[% l.patron_list_id %]"><i class="fa fa-user"></i> Add patrons</a></li>
51
                                    <li><a href="/cgi-bin/koha/patron_lists/add-modify.pl?patron_list_id=[% l.patron_list_id %]"><i class="fa fa-pencil"></i> Edit list</a></li>
62
                                    [% UNLESS shared_by_other %]
52
                                    <li><a class="delete_patron" href="/cgi-bin/koha/patron_lists/delete.pl?patron_list_id=[% l.patron_list_id %]" data-list-name="[% l.name %]"><i class="fa fa-trash"></i> Delete list</a></li>
63
                                        <li><a href="/cgi-bin/koha/patron_lists/add-modify.pl?patron_list_id=[% l.patron_list_id %]"><i class="fa fa-pencil"></i> Edit list</a></li>
64
                                        <li><a class="delete_patron" href="/cgi-bin/koha/patron_lists/delete.pl?patron_list_id=[% l.patron_list_id %]" data-list-name="[% l.name %]"><i class="fa fa-trash"></i> Delete list</a></li>
65
                                    [% END %]
53
                                    [% IF ( l.patron_list_patrons_rs.count ) %]
66
                                    [% IF ( l.patron_list_patrons_rs.count ) %]
54
                                        <li class="divider"></li>
67
                                        <li class="divider"></li>
55
                                        <li>
68
                                        <li>
(-)a/patron_lists/add-modify.pl (-2 / +3 lines)
Lines 39-44 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
39
39
40
my $id   = $cgi->param('patron_list_id');
40
my $id   = $cgi->param('patron_list_id');
41
my $name = $cgi->param('name');
41
my $name = $cgi->param('name');
42
my $shared = $cgi->param('shared') ? 1 : 0;
42
43
43
if ($id) {
44
if ($id) {
44
    my ($list) = GetPatronLists( { patron_list_id => $id } );
45
    my ($list) = GetPatronLists( { patron_list_id => $id } );
Lines 47-57 if ($id) { Link Here
47
48
48
if ($name) {
49
if ($name) {
49
    if ($id) {
50
    if ($id) {
50
        ModPatronList( { patron_list_id => $id, name => $name } );
51
        ModPatronList( { patron_list_id => $id, name => $name, shared => $shared } );
51
        print $cgi->redirect('lists.pl');
52
        print $cgi->redirect('lists.pl');
52
    }
53
    }
53
    else {
54
    else {
54
        my $list = AddPatronList( { name => $name } );
55
        my $list = AddPatronList( { name => $name, shared => $shared } );
55
        print $cgi->redirect(
56
        print $cgi->redirect(
56
            "list.pl?patron_list_id=" . $list->patron_list_id() );
57
            "list.pl?patron_list_id=" . $list->patron_list_id() );
57
    }
58
    }
(-)a/patron_lists/lists.pl (-1 / +4 lines)
Lines 39-44 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
39
39
40
my @lists = GetPatronLists();
40
my @lists = GetPatronLists();
41
41
42
$template->param( lists => \@lists );
42
$template->param(
43
    lists          => \@lists,
44
    logged_in_user => $loggedinuser,
45
);
43
46
44
output_html_with_http_headers( $cgi, $cookie, $template->output );
47
output_html_with_http_headers( $cgi, $cookie, $template->output );
(-)a/t/db_dependent/PatronLists.t (-12 / +20 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 7;
20
use Test::More tests => 9;
21
use t::lib::TestBuilder;
21
use t::lib::TestBuilder;
22
22
23
use Koha::Database;
23
use Koha::Database;
Lines 38-50 foreach (1..10) { Link Here
38
    push @borrowers, $builder->build({ source => 'Borrower' });
38
    push @borrowers, $builder->build({ source => 'Borrower' });
39
}
39
}
40
40
41
my $owner = $borrowers[0]->{borrowernumber};
41
my $owner  = $borrowers[0]->{borrowernumber};
42
my $owner2 = $borrowers[1]->{borrowernumber};
42
43
43
my @lists = GetPatronLists( { owner => $owner } );
44
my @lists = GetPatronLists( { owner => $owner } );
44
my $list_count_original = @lists;
45
my $list_count_original = @lists;
45
46
46
my $list1 = AddPatronList( { name => 'Test List 1', owner => $owner } );
47
my $list1 = AddPatronList( { name => 'Test List 1', owner => $owner } );
47
ok( $list1->name() eq 'Test List 1', 'AddPatronList works' );
48
is( $list1->name(), 'Test List 1', 'AddPatronList works' );
48
49
49
my $list2 = AddPatronList( { name => 'Test List 2', owner => $owner } );
50
my $list2 = AddPatronList( { name => 'Test List 2', owner => $owner } );
50
51
Lines 56-68 ModPatronList( Link Here
56
    }
57
    }
57
);
58
);
58
$list2->discard_changes();
59
$list2->discard_changes();
59
ok( $list2->name() eq 'Test List 3', 'ModPatronList works' );
60
is( $list2->name(), 'Test List 3', 'ModPatronList works' );
60
61
61
AddPatronsToList(
62
AddPatronsToList(
62
    { list => $list1, cardnumbers => [ map { $_->{cardnumber} } @borrowers ] }
63
    { list => $list1, cardnumbers => [ map { $_->{cardnumber} } @borrowers ] }
63
);
64
);
64
ok(
65
is(
65
    scalar @borrowers ==
66
    scalar @borrowers,
66
      $list1->patron_list_patrons()->search_related('borrowernumber')->all(),
67
      $list1->patron_list_patrons()->search_related('borrowernumber')->all(),
67
    'AddPatronsToList works for cardnumbers'
68
    'AddPatronsToList works for cardnumbers'
68
);
69
);
Lines 73-80 AddPatronsToList( Link Here
73
        borrowernumbers => [ map { $_->{borrowernumber} } @borrowers ]
74
        borrowernumbers => [ map { $_->{borrowernumber} } @borrowers ]
74
    }
75
    }
75
);
76
);
76
ok(
77
is(
77
    scalar @borrowers ==
78
    scalar @borrowers,
78
      $list2->patron_list_patrons()->search_related('borrowernumber')->all(),
79
      $list2->patron_list_patrons()->search_related('borrowernumber')->all(),
79
    'AddPatronsToList works for borrowernumbers'
80
    'AddPatronsToList works for borrowernumbers'
80
);
81
);
Lines 88-104 DelPatronsFromList( Link Here
88
    }
89
    }
89
);
90
);
90
$list1->discard_changes();
91
$list1->discard_changes();
91
ok( !$list1->patron_list_patrons()->count(), 'DelPatronsFromList works.' );
92
is( $list1->patron_list_patrons()->count(), 0, 'DelPatronsFromList works.' );
92
93
93
@lists = GetPatronLists( { owner => $owner } );
94
@lists = GetPatronLists( { owner => $owner } );
94
ok( @lists == $list_count_original + 2, 'GetPatronLists works' );
95
is( scalar @lists, $list_count_original + 2, 'GetPatronLists works' );
96
97
my $list3 = AddPatronList( { name => 'Test List 3', owner => $owner2, shared => 0 } );
98
@lists = GetPatronLists( { owner => $owner } );
99
is( scalar @lists, $list_count_original + 2, 'GetPatronLists does not return non-shared list' );
100
101
my $list4 = AddPatronList( { name => 'Test List 4', owner => $owner2, shared => 1 } );
102
@lists = GetPatronLists( { owner => $owner } );
103
is( scalar @lists, $list_count_original + 3, 'GetPatronLists does return shared list' );
95
104
96
DelPatronList( { patron_list_id => $list1->patron_list_id(), owner => $owner } );
105
DelPatronList( { patron_list_id => $list1->patron_list_id(), owner => $owner } );
97
DelPatronList( { patron_list_id => $list2->patron_list_id(), owner => $owner } );
106
DelPatronList( { patron_list_id => $list2->patron_list_id(), owner => $owner } );
98
107
99
@lists =
108
@lists =
100
  GetPatronLists( { patron_list_id => $list1->patron_list_id(), owner => $owner } );
109
  GetPatronLists( { patron_list_id => $list1->patron_list_id(), owner => $owner } );
101
ok( !@lists, 'DelPatronList works' );
110
is( scalar @lists, 0, 'DelPatronList works' );
102
111
103
$schema->storage->txn_rollback;
112
$schema->storage->txn_rollback;
104
113
105
- 

Return to bug 19524