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

(-)a/Koha/RestrictionType.pm (+22 lines)
Lines 63-68 sub delete { Link Here
63
    return 0;
63
    return 0;
64
}
64
}
65
65
66
=head3 make_default
67
68
Set the current restriction type as the default for manual restrictions
69
70
=cut
71
72
sub make_default {
73
    my ( $self ) = @_;
74
75
    $self->_result->result_source->schema->txn_do(
76
        sub {
77
            my $types =
78
              Koha::RestrictionTypes->search( { code => { '!=' => $self->code } } );
79
            $types->update( { is_default => 0 } );
80
            $self->set( { is_default => 1 } );
81
            $self->SUPER::store;
82
        }
83
    );
84
85
    return $self;
86
}
87
66
=head2 Internal methods
88
=head2 Internal methods
67
89
68
=head3 type
90
=head3 type
(-)a/admin/restrictions.pl (-6 / +5 lines)
Lines 53-59 if ( $op eq 'add_form') { Link Here
53
} elsif ( $op eq 'add_validate' ) {
53
} elsif ( $op eq 'add_validate' ) {
54
54
55
    my $display_text = $input->param('display_text');
55
    my $display_text = $input->param('display_text');
56
    my $can_be_added_manually = $input->param('can_be_added_manually') || 0;
57
    my $is_a_modif = $input->param("is_a_modif");
56
    my $is_a_modif = $input->param("is_a_modif");
58
57
59
    if ($is_a_modif) {
58
    if ($is_a_modif) {
Lines 68-76 if ( $op eq 'add_form') { Link Here
68
        } else {
67
        } else {
69
            my $restriction = Koha::RestrictionTypes->find($code);
68
            my $restriction = Koha::RestrictionTypes->find($code);
70
            $restriction->display_text($display_text);
69
            $restriction->display_text($display_text);
71
            unless ($restriction->is_system) {
72
                $restriction->can_be_added_manually($can_be_added_manually);
73
            }
74
            $restriction->store;
70
            $restriction->store;
75
        }
71
        }
76
    } else {
72
    } else {
Lines 83-95 if ( $op eq 'add_form') { Link Here
83
        } else {
79
        } else {
84
            my $restriction = Koha::RestrictionType->new({
80
            my $restriction = Koha::RestrictionType->new({
85
                code => $code,
81
                code => $code,
86
                display_text => $display_text,
82
                display_text => $display_text
87
                can_be_added_manually => $can_be_added_manually
88
            });
83
            });
89
            $restriction->store;
84
            $restriction->store;
90
        }
85
        }
91
    }
86
    }
92
    $op = 'list';
87
    $op = 'list';
88
} elsif ( $op eq 'make_default' ) {
89
    my $restriction = Koha::RestrictionTypes->find($code);
90
    $restriction->make_default;
91
    $op = 'list';
93
} elsif ( $op eq 'delete_confirm' ) {
92
} elsif ( $op eq 'delete_confirm' ) {
94
    $template->param(
93
    $template->param(
95
        restriction => scalar Koha::RestrictionTypes->find($code)
94
        restriction => scalar Koha::RestrictionTypes->find($code)
(-)a/installer/data/mysql/atomicupdate/bug_23681.pl (-7 / +6 lines)
Lines 12-29 return { Link Here
12
                code varchar(50) NOT NULL PRIMARY KEY,
12
                code varchar(50) NOT NULL PRIMARY KEY,
13
                display_text text NOT NULL,
13
                display_text text NOT NULL,
14
                is_system tinyint(1) NOT NULL DEFAULT 0,
14
                is_system tinyint(1) NOT NULL DEFAULT 0,
15
                default_value tinyint(1) NOT NULL DEFAULT 0,
15
                is_default tinyint(1) NOT NULL DEFAULT 0
16
                can_be_added_manually tinyint(1) NOT NULL DEFAULT 0
17
            ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
16
            ) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
18
        });
17
        });
19
        say $out "Added debarment_types table";
18
        say $out "Added debarment_types table";
20
19
21
        $dbh->do(q{
20
        $dbh->do(q{
22
            INSERT IGNORE INTO debarment_types (code, display_text, is_system, default_value, can_be_added_manually) VALUES
21
            INSERT IGNORE INTO debarment_types (code, display_text, is_system, is_default) VALUES
23
            ('MANUAL', 'Manual', 1, 1, 0),
22
            ('MANUAL', 'Manual', 0, 1),
24
            ('OVERDUES', 'Overdues', 1, 0, 0),
23
            ('OVERDUES', 'Overdues', 1, 0),
25
            ('SUSPENSION', 'Suspension', 1, 0, 0),
24
            ('SUSPENSION', 'Suspension', 1, 0),
26
            ('DISCHARGE', 'Discharge', 1, 0, 0);
25
            ('DISCHARGE', 'Discharge', 1, 0);
27
        });
26
        });
28
        say $out "Added system debarment_types";
27
        say $out "Added system debarment_types";
29
28
(-)a/installer/data/mysql/kohastructure.sql (-2 / +1 lines)
Lines 2026-2033 CREATE TABLE debarment_types ( Link Here
2026
    code varchar(50) NOT NULL PRIMARY KEY,
2026
    code varchar(50) NOT NULL PRIMARY KEY,
2027
    display_text text NOT NULL,
2027
    display_text text NOT NULL,
2028
    is_system tinyint(1) NOT NULL DEFAULT 0,
2028
    is_system tinyint(1) NOT NULL DEFAULT 0,
2029
    default_value tinyint(1) NOT NULL DEFAULT 0,
2029
    is_default tinyint(1) NOT NULL DEFAULT 0
2030
    can_be_added_manually tinyint(1) NOT NULL DEFAULT 0
2031
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2030
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2032
2031
2033
--
2032
--
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc (-2 / +6 lines)
Lines 58-65 Link Here
58
                        <label for="debarred_type">Type:</label>
58
                        <label for="debarred_type">Type:</label>
59
                        <select name="debarred_type">
59
                        <select name="debarred_type">
60
                            [% FOREACH code IN restriction_types.keys %]
60
                            [% FOREACH code IN restriction_types.keys %]
61
                                [% IF restriction_types.$code.can_be_added_manually %]
61
                                [% IF !restriction_types.$code.is_system %]
62
                                    <option value="[% code | html %]">[% PROCESS restriction_type_description restriction=restriction_types.$code %]</option>
62
                                   [% IF restriction_types.$code.is_default %]
63
                                   <option value="[% code | html %]" selected>[% PROCESS restriction_type_description restriction=restriction_types.$code %]</option>
64
                                   [% ELSE %]
65
                                   <option value="[% code | html %]">[% PROCESS restriction_type_description restriction=restriction_types.$code %]</option>
66
                                   [% END %]
63
                                [% END %]
67
                                [% END %]
64
                            [% END %]
68
                            [% END %]
65
                        </select>
69
                        </select>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/restrictions.tt (-27 / +5 lines)
Lines 103-118 Link Here
103
                        <input type="text" value="[% restriction.display_text | html %]" name="display_text" id="display_text" size="50" maxlength="50" class="required" required="required" />
103
                        <input type="text" value="[% restriction.display_text | html %]" name="display_text" id="display_text" size="50" maxlength="50" class="required" required="required" />
104
                        <span class="required">Required</span>
104
                        <span class="required">Required</span>
105
                    </li>
105
                    </li>
106
                    <li>
107
                        <label for="can_be_added_manually">Can be manually added?</label>
108
                        [% IF restriction && restriction.is_system %]
109
                            [% IF restriction.can_be_added_manually %]Yes[% ELSE %]No[% END %]
110
                        [% ELSIF restriction.can_be_added_manually %]
111
                            <input type="checkbox" name="can_be_added_manually" id="can_be_added_manually" checked="checked" value="1" />
112
                        [% ELSE %]
113
                            <input type="checkbox" name="can_be_added_manually" id="can_be_added_manually" value="1" />
114
                        [% END %]
115
                    </li>
116
                [% ELSE %]
106
                [% ELSE %]
117
                    <li>
107
                    <li>
118
                        <label for="code" class="required">Code: </label>
108
                        <label for="code" class="required">Code: </label>
Lines 124-139 Link Here
124
                        <input type="text" name="display_text" id="display_text" size="50" maxlength="50" class="required" required="required" />
114
                        <input type="text" name="display_text" id="display_text" size="50" maxlength="50" class="required" required="required" />
125
                        <span class="required">Required</span>
115
                        <span class="required">Required</span>
126
                    </li>
116
                    </li>
127
                    <li>
128
                        <label for="can_be_added_manually">Can be manually added?</label>
129
                        [% IF restriction && restriction.is_system %]
130
                            [% IF restriction.can_be_added_manually %]Yes[% ELSE %]No[% END %]
131
                        [% ELSIF restriction.can_be_added_manually %]
132
                            <input type="checkbox" name="can_be_added_manually" id="can_be_added_manually" checked="checked" value="1" />
133
                        [% ELSE %]
134
                            <input type="checkbox" name="can_be_added_manually" id="can_be_added_manually" value="1" />
135
                        [% END %]
136
                    </li>
137
                [% END %]
117
                [% END %]
138
            </ol>
118
            </ol>
139
        </fieldset>
119
        </fieldset>
Lines 180-186 Link Here
180
                <tr>
160
                <tr>
181
                    <th scope="col">Code</th>
161
                    <th scope="col">Code</th>
182
                    <th scope="col">Label</th>
162
                    <th scope="col">Label</th>
183
                    <th scope="col">Manual</th>
184
                    <th scope="col">Default</th>
163
                    <th scope="col">Default</th>
185
                    <th scope="col">Actions</th>
164
                    <th scope="col">Actions</th>
186
                </tr>
165
                </tr>
Lines 195-210 Link Here
195
                            [% PROCESS restriction_type_description %]
174
                            [% PROCESS restriction_type_description %]
196
                        </td>
175
                        </td>
197
                        <td>
176
                        <td>
198
                            [% IF restriction.can_be_added_manually %]Yes[% END %]
177
                            [% IF restriction.is_default %]Yes[% END %]
199
                        </td>
200
                        <td>
201
                            [% IF restriction.default_value %]Yes[% END %]
202
                        </td>
178
                        </td>
203
                        <td class="actions">
179
                        <td class="actions">
204
                            <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/restrictions.pl?op=add_form&amp;code=[% restriction.code | uri %]"><i class="fa fa-pencil"></i> Edit</a>
180
                            <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/restrictions.pl?op=add_form&amp;code=[% restriction.code | uri %]"><i class="fa fa-pencil"></i> Edit</a>
205
                            [% IF !restriction.is_system %]
181
                            [% IF !restriction.is_system && !restriction.is_default %]
206
                                <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/restrictions.pl?op=delete_confirm&amp;code=[% restriction.code | uri %]"><i class="fa fa-trash"></i> Delete</a>
182
                                <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/restrictions.pl?op=delete_confirm&amp;code=[% restriction.code | uri %]"><i class="fa fa-trash"></i> Delete</a>
207
                            [% END %]
183
                            [% END %]
184
                            [% IF !restriction.is_system && !restriction.is_default %]
185
                                <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/restrictions.pl?op=make_default&amp;code=[% restriction.code | uri %]"><i class="fa fa-archive"></i> Make default</a>
186
                            [% END %]
208
                        </td>
187
                        </td>
209
                    </tr>
188
                    </tr>
210
                [% END %]
189
                [% END %]
211
- 

Return to bug 23681