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

(-)a/Koha/Item.pm (-3 / +12 lines)
Lines 266-279 sub delete { Link Here
266
    my $self = shift;
266
    my $self = shift;
267
    my $params = @_ ? shift : {};
267
    my $params = @_ ? shift : {};
268
268
269
    # FIXME check the item has no current issues
270
    # i.e. raise the appropriate exception
271
272
    # Get the item group so we can delete it later if it has no items left
269
    # Get the item group so we can delete it later if it has no items left
273
    my $item_group = C4::Context->preference('EnableItemGroups') ? $self->item_group : undef;
270
    my $item_group = C4::Context->preference('EnableItemGroups') ? $self->item_group : undef;
274
271
272
    my $serial_item = $self->serial_item;
273
275
    my $result = $self->SUPER::delete;
274
    my $result = $self->SUPER::delete;
276
275
276
    # Delete the serial linked to the item if required
277
    if ( $result && $params->{delete_serial_issues} ) {
278
        if ($serial_item) {
279
            my $serial = Koha::Serials->find( $serial_item->serialid );
280
            # The serial_item is deleted by cascade when the item is deleted
281
            # so we don't need to delete it here
282
            $serial->delete;
283
        }
284
    }
285
277
    # Delete the item group if it has no items left
286
    # Delete the item group if it has no items left
278
    $item_group->delete if ( $item_group && $item_group->items->count == 0 );
287
    $item_group->delete if ( $item_group && $item_group->items->count == 0 );
279
288
(-)a/Koha/Template/Plugin/Item.pm (+43 lines)
Line 0 Link Here
1
package Koha::Template::Plugin::Item;
2
3
# Copyright PTFS EUROPE 2024
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
22
use Template::Plugin;
23
use base qw( Template::Plugin );
24
25
use Koha::Items;
26
27
=head1 METHODS
28
29
=head2 HasSerialItem
30
31
Checks whether a particular item has an associated serial item
32
33
=cut
34
35
sub HasSerialItem {
36
    my ( $self, $itemnumber ) = @_;
37
38
    my $serial_item = Koha::Items->find($itemnumber)->serial_item;
39
40
    return $serial_item ? 1 : 0;
41
}
42
43
1;
(-)a/cataloguing/additem.pl (-1 / +2 lines)
Lines 532-538 if ( $op eq "cud-additem" ) { Link Here
532
    my $item = Koha::Items->find($itemnumber);
532
    my $item = Koha::Items->find($itemnumber);
533
    my $deleted;
533
    my $deleted;
534
    if ($item) {
534
    if ($item) {
535
        $deleted = $item->safe_delete;
535
        my $delete_serial_issues = $input->param('delete-serial-issues');
536
        $deleted = $item->safe_delete( { delete_serial_issues => $delete_serial_issues } );
536
    } else {
537
    } else {
537
        $deleted = Koha::Result::Boolean->new(0)->add_message( { message => 'item_not_found' } );
538
        $deleted = Koha::Result::Boolean->new(0)->add_message( { message => 'item_not_found' } );
538
    }
539
    }
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/delete_item_confirmation.inc (+30 lines)
Line 0 Link Here
1
[% USE Item %]
2
3
<!-- delete_item_confirmation.inc -->
4
    <!-- Item deletion confirmation dialog -->
5
    <div class="modal fade" id="delete-item-modal" tabindex="-1" role="dialog" aria-labelledby="claims-returned-modal-label">
6
        <div class="modal-dialog" role="document">
7
            <div class="modal-content">
8
                <div class="modal-header">
9
                    <h4 class="modal-title" id="delete-item-modal-label">Delete item</h4>
10
                </div>
11
                <div class="modal-body">
12
                    <h5 style="margin-bottom: 15px;">Are you sure you want to delete this item?</h5>
13
14
                    <div class="form-group">
15
                        <div class="checkbox">
16
                            <label for="delete_associated_serial_issues">
17
                            <input id="delete_associated_serial_issues" type="checkbox" value="1">
18
                                Delete serial issues linked to item
19
                            </label>
20
                        </div>
21
                    </div>
22
                    <input type="hidden" id="delete-item-itemnumber" />
23
                </div>
24
                <div class="modal-footer">
25
                    <button id="delete-item-modal-btn-submit" type="button" class="btn btn-primary"><i class="fa fa-exclamation-circle"></i> Delete item</button>
26
                    <button class="btn btn-default deny cancel" href="#" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i> Cancel</button>
27
                </div>
28
            </div>
29
        </div>
30
    </div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt (-1 / +4 lines)
Lines 4-9 Link Here
4
[% USE Branches %]
4
[% USE Branches %]
5
[% USE KohaDates %]
5
[% USE KohaDates %]
6
[% USE Price %]
6
[% USE Price %]
7
[% USE Item %]
7
[% USE TablesSettings %]
8
[% USE TablesSettings %]
8
[% PROCESS 'i18n.inc' %]
9
[% PROCESS 'i18n.inc' %]
9
[% INCLUDE 'doc-head-open.inc' %]
10
[% INCLUDE 'doc-head-open.inc' %]
Lines 156-163 Link Here
156
                                            <input type="hidden" name="biblionumber" value="[% item.biblionumber | html %]" />
157
                                            <input type="hidden" name="biblionumber" value="[% item.biblionumber | html %]" />
157
                                            <input type="hidden" name="itemnumber" value="[% item.itemnumber | html %]" />
158
                                            <input type="hidden" name="itemnumber" value="[% item.itemnumber | html %]" />
158
                                            <input type="hidden" name="searchid" value="[% searchid | html %]" />
159
                                            <input type="hidden" name="searchid" value="[% searchid | html %]" />
160
                                            <input type="hidden" name="delete-serial-issues" id="[% item.itemnumber | html %]-delete-serial-issues" value="" />
159
                                        </form>
161
                                        </form>
160
                                        <a class="dropdown-item delete" data-item="[% item.itemnumber | html %]" href="#">Delete</a>
162
                                        <a class="dropdown-item delete" data-itemnumber="[% item.itemnumber | html %]" data-has-serial-item="[% Item.HasSerialItem(item.itemnumber) | html %]" href="#">Delete</a>
161
                                    </li>
163
                                    </li>
162
                                [% END %]
164
                                [% END %]
163
                            [% END %]
165
                            [% END %]
Lines 396-401 Link Here
396
    </form>
398
    </form>
397
399
398
    [% INCLUDE 'modals/cataloguing_create_av.inc' %]
400
    [% INCLUDE 'modals/cataloguing_create_av.inc' %]
401
    [% INCLUDE 'modals/delete_item_confirmation.inc' %]
399
402
400
                            </div> <!-- /#cataloguing_additem_newitem -->
403
                            </div> <!-- /#cataloguing_additem_newitem -->
401
                        </div> <!-- /.col-sm-10 -->
404
                        </div> <!-- /.col-sm-10 -->
(-)a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js (-3 / +21 lines)
Lines 135-143 $(document).ready(function(){ Link Here
135
    $(document).on('click', '.delete', function(e) {
135
    $(document).on('click', '.delete', function(e) {
136
        e.preventDefault();
136
        e.preventDefault();
137
        if (confirmDelete(MSG_CONFIRM_DELETE_ITEM)) {
137
        if (confirmDelete(MSG_CONFIRM_DELETE_ITEM)) {
138
            return $("#" + $(this).data("item") + "-delete-item-form").submit();
138
            var itemnumber = $(this).data('itemnumber');
139
            var hasSerialItem = $(this).data('has-serial-item');
140
141
            $('#delete-item-itemnumber').val(itemnumber);
142
            $('#delete_associated_serial_issues').attr('checked', false);
143
            $('#delete-item-modal-btn-submit').data("item", itemnumber);
144
            if(!hasSerialItem) {
145
                $('.form-group').hide()
146
            }
147
            $('#delete-item-modal').modal('show');
139
        }
148
        }
140
    }) ;
149
    });
150
    $(document).on('click', '#delete-item-modal-btn-submit', function(e) {
151
        e.preventDefault();
152
        var itemnumber = $('#delete-item-itemnumber').val();
153
        var deleteSerialIssues = $('#delete_associated_serial_issues').prop('checked') ? true : false;
154
        $('#delete-item-modal').modal('hide');
155
        if(deleteSerialIssues) {
156
            $('#' + itemnumber + '-delete-serial-issues').val('1');
157
        }
158
        return $("#" + $(this).data("item") + "-delete-item-form").submit();
159
    });
141
160
142
    /* On page load, check for location.hash in the page URL */
161
    /* On page load, check for location.hash in the page URL */
143
    /* If present the location hash will be used to scroll to the relevant anchor */
162
    /* If present the location hash will be used to scroll to the relevant anchor */
144
- 

Return to bug 37115