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

(-)a/Koha/Item.pm (+165 lines)
Lines 20-25 package Koha::Item; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use List::MoreUtils qw( any );
22
use List::MoreUtils qw( any );
23
use Try::Tiny qw( catch try );
23
24
24
use Koha::Database;
25
use Koha::Database;
25
use Koha::DateUtils qw( dt_from_string output_pref );
26
use Koha::DateUtils qw( dt_from_string output_pref );
Lines 1441-1446 sub move_to_biblio { Link Here
1441
    return $to_biblionumber;
1442
    return $to_biblionumber;
1442
}
1443
}
1443
1444
1445
=head3 bundle_items
1446
1447
  my $bundle_items = $item->bundle_items;
1448
1449
Returns the items associated with this bundle
1450
1451
=cut
1452
1453
sub bundle_items {
1454
    my ($self) = @_;
1455
1456
    if ( !$self->{_bundle_items_cached} ) {
1457
        my $bundle_items = Koha::Items->search(
1458
            { 'item_bundles_item.host' => $self->itemnumber },
1459
            { join                     => 'item_bundles_item' } );
1460
        $self->{_bundle_items}        = $bundle_items;
1461
        $self->{_bundle_items_cached} = 1;
1462
    }
1463
1464
    return $self->{_bundle_items};
1465
}
1466
1467
=head3 is_bundle
1468
1469
  my $is_bundle = $item->is_bundle;
1470
1471
Returns whether the item is a bundle or not
1472
1473
=cut
1474
1475
sub is_bundle {
1476
    my ($self) = @_;
1477
    return $self->bundle_items->count ? 1 : 0;
1478
}
1479
1480
=head3 bundle_host
1481
1482
  my $bundle = $item->bundle_host;
1483
1484
Returns the bundle item this item is attached to
1485
1486
=cut
1487
1488
sub bundle_host {
1489
    my ($self) = @_;
1490
1491
    if ( !$self->{_bundle_host_cached} ) {
1492
        my $bundle_item_rs = $self->_result->item_bundles_item;
1493
        $self->{_bundle_host} =
1494
          $bundle_item_rs
1495
          ? Koha::Item->_new_from_dbic($bundle_item_rs->host)
1496
          : undef;
1497
        $self->{_bundle_host_cached} = 1;
1498
    }
1499
1500
    return $self->{_bundle_host};
1501
}
1502
1503
=head3 in_bundle
1504
1505
  my $in_bundle = $item->in_bundle;
1506
1507
Returns whether this item is currently in a bundle
1508
1509
=cut
1510
1511
sub in_bundle {
1512
    my ($self) = @_;
1513
    return $self->bundle_host ? 1 : 0;
1514
}
1515
1516
=head3 add_to_bundle
1517
1518
  my $link = $item->add_to_bundle($bundle_item);
1519
1520
Adds the bundle_item passed to this item
1521
1522
=cut
1523
1524
sub add_to_bundle {
1525
    my ( $self, $bundle_item ) = @_;
1526
1527
    my $schema = Koha::Database->new->schema;
1528
1529
    my $BundleNotLoanValue = C4::Context->preference('BundleNotLoanValue');
1530
1531
    try {
1532
        $schema->txn_do(
1533
            sub {
1534
                $self->_result->add_to_item_bundles_hosts(
1535
                    { item => $bundle_item->itemnumber } );
1536
1537
                $bundle_item->notforloan($BundleNotLoanValue)->store();
1538
            }
1539
        );
1540
    }
1541
    catch {
1542
1543
        # FIXME: See if we can move the below copy/paste from Koha::Object::store into it's own class and catch at a lower level in the Schema instantiation.. take inspiration fro DBIx::Error
1544
        if ( ref($_) eq 'DBIx::Class::Exception' ) {
1545
            warn $_->{msg};
1546
            if ( $_->{msg} =~ /Cannot add or update a child row: a foreign key constraint fails/ ) {
1547
                # FK constraints
1548
                # FIXME: MySQL error, if we support more DB engines we should implement this for each
1549
                if ( $_->{msg} =~ /FOREIGN KEY \(`(?<column>.*?)`\)/ ) {
1550
                    Koha::Exceptions::Object::FKConstraint->throw(
1551
                        error     => 'Broken FK constraint',
1552
                        broken_fk => $+{column}
1553
                    );
1554
                }
1555
            }
1556
            elsif (
1557
                $_->{msg} =~ /Duplicate entry '(.*?)' for key '(?<key>.*?)'/ )
1558
            {
1559
                Koha::Exceptions::Object::DuplicateID->throw(
1560
                    error        => 'Duplicate ID',
1561
                    duplicate_id => $+{key}
1562
                );
1563
            }
1564
            elsif ( $_->{msg} =~
1565
/Incorrect (?<type>\w+) value: '(?<value>.*)' for column \W?(?<property>\S+)/
1566
              )
1567
            {    # The optional \W in the regex might be a quote or backtick
1568
                my $type     = $+{type};
1569
                my $value    = $+{value};
1570
                my $property = $+{property};
1571
                $property =~ s/['`]//g;
1572
                Koha::Exceptions::Object::BadValue->throw(
1573
                    type     => $type,
1574
                    value    => $value,
1575
                    property => $property =~ /(\w+\.\w+)$/
1576
                    ? $1
1577
                    : $property
1578
                    ,    # results in table.column without quotes or backtics
1579
                );
1580
            }
1581
1582
            # Catch-all for foreign key breakages. It will help find other use cases
1583
            $_->rethrow();
1584
        }
1585
        else {
1586
            $_;
1587
        }
1588
    };
1589
}
1590
1591
=head3 remove_from_bundle
1592
1593
Remove this item from any bundle it may have been attached to.
1594
1595
=cut
1596
1597
sub remove_from_bundle {
1598
    my ($self) = @_;
1599
1600
    my $bundle_item_rs = $self->_result->item_bundles_item;
1601
    if ( $bundle_item_rs ) {
1602
        $bundle_item_rs->delete;
1603
        $self->notforloan(0)->store();
1604
        return 1;
1605
    }
1606
    return 0;
1607
}
1608
1444
=head2 Internal methods
1609
=head2 Internal methods
1445
1610
1446
=head3 _after_item_action_hooks
1611
=head3 _after_item_action_hooks
(-)a/Koha/REST/V1/Items.pm (+121 lines)
Lines 148-151 sub pickup_locations { Link Here
148
    };
148
    };
149
}
149
}
150
150
151
=head3 bundled_items
152
153
Controller function that handles bundled_items Koha::Item objects
154
155
=cut
156
157
sub bundled_items {
158
    my $c = shift->openapi->valid_input or return;
159
160
    my $item_id = $c->validation->param('item_id');
161
    my $item = Koha::Items->find( $item_id );
162
163
    unless ($item) {
164
        return $c->render(
165
            status  => 404,
166
            openapi => { error => "Item not found" }
167
        );
168
    }
169
170
    return try {
171
        my $items_set = $item->bundle_items;
172
        my $items     = $c->objects->search( $items_set );
173
        return $c->render(
174
            status  => 200,
175
            openapi => $items
176
        );
177
    }
178
    catch {
179
        $c->unhandled_exception($_);
180
    };
181
}
182
183
=head3 add_to_bundle
184
185
Controller function that handles adding items to this bundle
186
187
=cut
188
189
sub add_to_bundle {
190
    my $c = shift->openapi->valid_input or return;
191
192
    my $item_id = $c->validation->param('item_id');
193
    my $item = Koha::Items->find( $item_id );
194
195
    unless ($item) {
196
        return $c->render(
197
            status  => 404,
198
            openapi => { error => "Item not found" }
199
        );
200
    }
201
202
203
    my $bundle_item_id = $c->validation->param('body')->{'external_id'};
204
    my $bundle_item = Koha::Items->find( { barcode => $bundle_item_id } );
205
206
    unless ($bundle_item) {
207
        return $c->render(
208
            status  => 404,
209
            openapi => { error => "Bundle item not found" }
210
        );
211
    }
212
213
    return try {
214
        my $link = $item->add_to_bundle($bundle_item);
215
        return $c->render(
216
            status  => 201,
217
            openapi => $bundle_item
218
        );
219
    }
220
    catch {
221
        if ( ref($_) eq 'Koha::Exceptions::Object::DuplicateID' ) {
222
            return $c->render(
223
                status  => 409,
224
                openapi => {
225
                    error => 'Item is already bundled',
226
                    key   => $_->duplicate_id
227
                }
228
            );
229
        }
230
        else {
231
            $c->unhandled_exception($_);
232
        }
233
    };
234
}
235
236
=head3 remove_from_bundle
237
238
Controller function that handles removing items from this bundle
239
240
=cut
241
242
sub remove_from_bundle {
243
    my $c = shift->openapi->valid_input or return;
244
245
    my $item_id = $c->validation->param('item_id');
246
    my $item = Koha::Items->find( $item_id );
247
248
    unless ($item) {
249
        return $c->render(
250
            status  => 404,
251
            openapi => { error => "Item not found" }
252
        );
253
    }
254
255
    my $bundle_item_id = $c->validation->param('bundled_item_id');
256
    my $bundle_item = Koha::Items->find( { itemnumber => $bundle_item_id } );
257
258
    unless ($bundle_item) {
259
        return $c->render(
260
            status  => 404,
261
            openapi => { error => "Bundle item not found" }
262
        );
263
    }
264
265
    $bundle_item->remove_from_bundle;
266
    return $c->render(
267
        status  => 204,
268
        openapi => q{}
269
    );
270
}
271
151
1;
272
1;
(-)a/admin/columns_settings.yml (+22 lines)
Lines 509-514 modules: Link Here
509
            -
509
            -
510
              columnname: checkin_on
510
              columnname: checkin_on
511
511
512
      bundle_tables:
513
        columns:
514
            -
515
              columnname: title
516
              cannot_be_toggled: 1
517
            -
518
              columnname: author
519
            -
520
              columnname: collection_code
521
            -
522
              columnname: item_type
523
            -
524
              columnname: callnumber
525
            -
526
              columnname: external_id
527
            -
528
              columnname: status
529
            -
530
              columnname: bundle_actions
531
              cannot_be_toggled: 1
532
              cannot_be_modified: 1
533
512
  cataloguing:
534
  cataloguing:
513
    addbooks:
535
    addbooks:
514
      reservoir-table:
536
      reservoir-table:
(-)a/api/v1/swagger/definitions/bundle_link.yaml (+14 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  item_id:
5
    type:
6
      - integer
7
      - "null"
8
    description: Internal item identifier
9
  external_id:
10
    type:
11
      - string
12
      - "null"
13
    description: Item barcode
14
additionalProperties: false
(-)a/api/v1/swagger/definitions/item.yaml (+1 lines)
Lines 7-12 properties: Link Here
7
  biblio_id:
7
  biblio_id:
8
    type: integer
8
    type: integer
9
    description: Internal identifier for the parent bibliographic record
9
    description: Internal identifier for the parent bibliographic record
10
  biblio: {}
10
  external_id:
11
  external_id:
11
    type:
12
    type:
12
      - string
13
      - string
(-)a/api/v1/swagger/paths/items.yaml (+157 lines)
Lines 93-98 Link Here
93
    x-koha-authorization:
93
    x-koha-authorization:
94
      permissions:
94
      permissions:
95
        catalogue: "1"
95
        catalogue: "1"
96
"/items/{item_id}/bundled_items":
97
  post:
98
    x-mojo-to: Items#add_to_bundle
99
    operationId: addToBundle
100
    tags:
101
      - items
102
    summary: Add item to bundle
103
    parameters:
104
      - $ref: "../swagger.yaml#/parameters/item_id_pp"
105
      - name: body
106
        in: body
107
        description: A JSON object containing information about the new bundle link
108
        required: true
109
        schema:
110
          $ref: "../swagger.yaml#/definitions/bundle_link"
111
    consumes:
112
      - application/json
113
    produces:
114
      - application/json
115
    responses:
116
      "201":
117
        description: A successfully created bundle link
118
        schema:
119
          items:
120
            $ref: "../swagger.yaml#/definitions/item"
121
      "400":
122
        description: Bad parameter
123
        schema:
124
          $ref: "../swagger.yaml#/definitions/error"
125
      "401":
126
        description: Authentication required
127
        schema:
128
          $ref: "../swagger.yaml#/definitions/error"
129
      "403":
130
        description: Access forbidden
131
        schema:
132
          $ref: "../swagger.yaml#/definitions/error"
133
      "404":
134
        description: Resource not found
135
        schema:
136
          $ref: "../swagger.yaml#/definitions/error"
137
      "409":
138
        description: Conflict in creating resource
139
        schema:
140
          $ref: "../swagger.yaml#/definitions/error"
141
      "500":
142
        description: Internal server error
143
        schema:
144
          $ref: "../swagger.yaml#/definitions/error"
145
      "503":
146
        description: Under maintenance
147
        schema:
148
          $ref: "../swagger.yaml#/definitions/error"
149
    x-koha-authorization:
150
      permissions:
151
        catalogue: 1
152
  get:
153
    x-mojo-to: Items#bundled_items
154
    operationId: bundledItems
155
    tags:
156
      - items
157
    summary: List bundled items
158
    parameters:
159
      - $ref: "../swagger.yaml#/parameters/item_id_pp"
160
      - name: external_id
161
        in: query
162
        description: Search on the item's barcode
163
        required: false
164
        type: string
165
      - $ref: "../swagger.yaml#/parameters/match"
166
      - $ref: "../swagger.yaml#/parameters/order_by"
167
      - $ref: "../swagger.yaml#/parameters/page"
168
      - $ref: "../swagger.yaml#/parameters/per_page"
169
      - $ref: "../swagger.yaml#/parameters/q_param"
170
      - $ref: "../swagger.yaml#/parameters/q_body"
171
      - $ref: "../swagger.yaml#/parameters/q_header"
172
    consumes:
173
      - application/json
174
    produces:
175
      - application/json
176
    responses:
177
      "200":
178
        description: A list of item
179
        schema:
180
          type: array
181
          items:
182
            $ref: "../swagger.yaml#/definitions/item"
183
      "401":
184
        description: Authentication required
185
        schema:
186
          $ref: "../swagger.yaml#/definitions/error"
187
      "403":
188
        description: Access forbidden
189
        schema:
190
          $ref: "../swagger.yaml#/definitions/error"
191
      "500":
192
        description: Internal server error
193
        schema:
194
          $ref: "../swagger.yaml#/definitions/error"
195
      "503":
196
        description: Under maintenance
197
        schema:
198
          $ref: "../swagger.yaml#/definitions/error"
199
    x-koha-authorization:
200
      permissions:
201
        catalogue: "1"
202
    x-koha-embed:
203
      - biblio
204
      - checkout
205
"/items/{item_id}/bundled_items/{bundled_item_id}":
206
  delete:
207
    x-mojo-to: Items#remove_from_bundle
208
    operationId: removeFromBundle
209
    tags:
210
      - items
211
    summary: Remove item from bundle
212
    parameters:
213
      - $ref: "../swagger.yaml#/parameters/item_id_pp"
214
      - name: bundled_item_id
215
        in: path
216
        description: Internal identifier for the bundled item
217
        required: true
218
        type: string
219
    consumes:
220
      - application/json
221
    produces:
222
      - application/json
223
    responses:
224
      "204":
225
        description: Bundle link deleted
226
      "400":
227
        description: Bad parameter
228
        schema:
229
          $ref: "../swagger.yaml#/definitions/error"
230
      "401":
231
        description: Authentication required
232
        schema:
233
          $ref: "../swagger.yaml#/definitions/error"
234
      "403":
235
        description: Access forbidden
236
        schema:
237
          $ref: "../swagger.yaml#/definitions/error"
238
      "404":
239
        description: Resource not found
240
        schema:
241
          $ref: "../swagger.yaml#/definitions/error"
242
      "500":
243
        description: Internal server error
244
        schema:
245
          $ref: "../swagger.yaml#/definitions/error"
246
      "503":
247
        description: Under maintenance
248
        schema:
249
          $ref: "../swagger.yaml#/definitions/error"
250
    x-koha-authorization:
251
      permissions:
252
        catalogue: 1
96
"/items/{item_id}/pickup_locations":
253
"/items/{item_id}/pickup_locations":
97
  get:
254
  get:
98
    x-mojo-to: Items#pickup_locations
255
    x-mojo-to: Items#pickup_locations
(-)a/api/v1/swagger/swagger.yaml (+6 lines)
Lines 10-15 definitions: Link Here
10
    $ref: ./definitions/allows_renewal.yaml
10
    $ref: ./definitions/allows_renewal.yaml
11
  basket:
11
  basket:
12
    $ref: ./definitions/basket.yaml
12
    $ref: ./definitions/basket.yaml
13
  bundle_link:
14
    $ref: ./definitions/bundle_link.yaml
13
  cashup:
15
  cashup:
14
    $ref: ./definitions/cashup.yaml
16
    $ref: ./definitions/cashup.yaml
15
  checkout:
17
  checkout:
Lines 153-158 paths: Link Here
153
    $ref: ./paths/items.yaml#/~1items
155
    $ref: ./paths/items.yaml#/~1items
154
  "/items/{item_id}":
156
  "/items/{item_id}":
155
    $ref: "./paths/items.yaml#/~1items~1{item_id}"
157
    $ref: "./paths/items.yaml#/~1items~1{item_id}"
158
  "/items/{item_id}/bundled_items":
159
    $ref: ./paths/items.yaml#/~1items~1{item_id}~1bundled_items
160
  "/items/{item_id}/bundled_items/{bundled_item_id}":
161
    $ref: ./paths/items.yaml#/~1items~1{item_id}~1bundled_items~1{bundled_item_id}
156
  "/items/{item_id}/pickup_locations":
162
  "/items/{item_id}/pickup_locations":
157
    $ref: "./paths/items.yaml#/~1items~1{item_id}~1pickup_locations"
163
    $ref: "./paths/items.yaml#/~1items~1{item_id}~1pickup_locations"
158
  /libraries:
164
  /libraries:
(-)a/catalogue/detail.pl (+14 lines)
Lines 173-178 if (@hostitems){ Link Here
173
173
174
my $dat = &GetBiblioData($biblionumber);
174
my $dat = &GetBiblioData($biblionumber);
175
175
176
#is biblio a collection and are bundles enabled
177
my $leader = $record->leader();
178
$dat->{bundlesEnabled} = ( ( substr( $leader, 7, 1 ) eq 'c' )
179
      && C4::Context->preference('BundleNotLoanValue') ) ? 1 : 0;
180
176
#coping with subscriptions
181
#coping with subscriptions
177
my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
182
my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
178
my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
183
my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
Lines 415-420 foreach my $item (@items) { Link Here
415
        }
420
        }
416
    }
421
    }
417
422
423
    if ($item_object->is_bundle) {
424
        $itemfields{bundles} = 1;
425
        $item->{is_bundle} = 1;
426
    }
427
428
    if ($item_object->in_bundle) {
429
        $item->{bundle_host} = $item_object->bundle_host;
430
    }
431
418
    if ($currentbranch and C4::Context->preference('SeparateHoldings')) {
432
    if ($currentbranch and C4::Context->preference('SeparateHoldings')) {
419
        if ($itembranchcode and $itembranchcode eq $currentbranch) {
433
        if ($itembranchcode and $itembranchcode eq $currentbranch) {
420
            push @itemloop, $item;
434
            push @itemloop, $item;
(-)a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss (+4 lines)
Lines 2355-2360 td { Link Here
2355
    display: block;
2355
    display: block;
2356
}
2356
}
2357
2357
2358
.bundled {
2359
    display: block;
2360
}
2361
2358
.datedue {
2362
.datedue {
2359
    color: #999;
2363
    color: #999;
2360
    display: block;
2364
    display: block;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (+4 lines)
Lines 165-170 Cataloging: Link Here
165
            - and record's last modifier name in MARC subfield
165
            - and record's last modifier name in MARC subfield
166
            - pref: MarcFieldForModifierName
166
            - pref: MarcFieldForModifierName
167
            - ". <br/><strong>NOTE:</strong> Use a dollar sign between field and subfield like 123$a."
167
            - ". <br/><strong>NOTE:</strong> Use a dollar sign between field and subfield like 123$a."
168
        -
169
            - Use the NOT_LOAN authorised value
170
            - pref: BundleNotLoanValue
171
            - to represent 'added to bundle' when an item is attached to bundle.
168
    Display:
172
    Display:
169
        -
173
        -
170
            - 'Separate main entry and subdivisions with '
174
            - 'Separate main entry and subdivisions with '
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt (-3 / +256 lines)
Lines 354-365 Link Here
354
                [% IF ( analyze ) %]<th id="[% tab | html %]_usedin" data-colname="[% tab | html %]_usedin">Used in</th><th></th>[% END %]
354
                [% IF ( analyze ) %]<th id="[% tab | html %]_usedin" data-colname="[% tab | html %]_usedin">Used in</th><th></th>[% END %]
355
                [% IF ( ShowCourseReserves ) %]<th id="[% tab | html %]_course_reserves" data-colname="[% tab | html %]_course_reserves">Course reserves</th>[% END %]
355
                [% IF ( ShowCourseReserves ) %]<th id="[% tab | html %]_course_reserves" data-colname="[% tab | html %]_course_reserves">Course reserves</th>[% END %]
356
                [% IF ( SpineLabelShowPrintOnBibDetails ) %]<th id="[% tab | html %]_spinelabel" data-colname="[% tab | html %]_spinelabel" class="NoSort">Spine label</th>[% END %]
356
                [% IF ( SpineLabelShowPrintOnBibDetails ) %]<th id="[% tab | html %]_spinelabel" data-colname="[% tab | html %]_spinelabel" class="NoSort">Spine label</th>[% END %]
357
                [% IF ( CAN_user_editcatalogue_edit_items ) %]<th id="[% tab | html %]_actions" data-colname="[% tab | html %]_actions"class="NoSort">&nbsp;</th>[% END %]
357
                [% IF ( CAN_user_editcatalogue_edit_items ) %]<th id="[% tab | html %]_actions" data-colname="[% tab | html %]_actions"class="NoSort noExport">&nbsp;</th>[% END %]
358
            </tr>
358
            </tr>
359
        </thead>
359
        </thead>
360
        <tbody>
360
        <tbody>
361
            [% FOREACH item IN items %]
361
            [% FOREACH item IN items %]
362
                <tr>
362
                <tr id="item_[% item.itemnumber | html %]" data-itemnumber="[% item.itemnumber | html %]">
363
                [% IF (StaffDetailItemSelection) %]
363
                [% IF (StaffDetailItemSelection) %]
364
                    <td style="text-align:center;vertical-align:middle">
364
                    <td style="text-align:center;vertical-align:middle">
365
                        <input type="checkbox" value="[% item.itemnumber | html %]" name="itemnumber" />
365
                        <input type="checkbox" value="[% item.itemnumber | html %]" name="itemnumber" />
Lines 529-534 Note that permanent location is a code, and location may be an authval. Link Here
529
                        [% IF ( item.restricted ) %]
529
                        [% IF ( item.restricted ) %]
530
                            <span class="restricted">([% item.restrictedvalue | html %])</span>
530
                            <span class="restricted">([% item.restrictedvalue | html %])</span>
531
                        [% END %]
531
                        [% END %]
532
533
                        [% IF ( item.bundle_host ) %]
534
                            <span class="bundled">In bundle: [% INCLUDE 'biblio-title.inc' biblio = item.bundle_host.biblio link = 1 %]</span>
535
                        [% END %]
536
532
                    </td>
537
                    </td>
533
                    <td class="datelastseen" data-order="[% item.datelastseen | html %]">[% item.datelastseen | $KohaDates %]</td>
538
                    <td class="datelastseen" data-order="[% item.datelastseen | html %]">[% item.datelastseen | $KohaDates %]</td>
534
                    <td class="dateaccessioned" data-order="[% item.dateaccessioned | html %]">[% item.dateaccessioned | $KohaDates %]</td>
539
                    <td class="dateaccessioned" data-order="[% item.dateaccessioned | html %]">[% item.dateaccessioned | $KohaDates %]</td>
Lines 613-618 Note that permanent location is a code, and location may be an authval. Link Here
613
                                <a class="btn btn-default btn-xs" href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber=[% item.biblionumber | html %]&itemnumber=[% item.itemnumber | html %]#edititem"><i class="fa fa-pencil"></i> Edit</a>
618
                                <a class="btn btn-default btn-xs" href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber=[% item.biblionumber | html %]&itemnumber=[% item.itemnumber | html %]#edititem"><i class="fa fa-pencil"></i> Edit</a>
614
                            [% END %]
619
                            [% END %]
615
                        [% END %]
620
                        [% END %]
621
                        [% IF bundlesEnabled %]
622
                            <button class="btn btn-default btn-xs details-control"><i class="fa fa-folder"></i> Manage bundle</button>
623
                        [% END %]
616
                    </td>
624
                    </td>
617
                [% END %]
625
                [% END %]
618
                </tr>
626
                </tr>
Lines 1054-1059 Note that permanent location is a code, and location may be an authval. Link Here
1054
1062
1055
[% END %]
1063
[% END %]
1056
1064
1065
    [% IF bundlesEnabled %]
1066
    <div class="modal" id="bundleItemsModal" tabindex="-1" role="dialog" aria-labelledby="bundleItemsLabel">
1067
        <form id="bundleItemsForm" action="">
1068
            <div class="modal-dialog" role="document">
1069
                <div class="modal-content">
1070
                    <div class="modal-header">
1071
                        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
1072
                        <h3 id="bundleItemsLabel">Add to bundle</h3>
1073
                    </div>
1074
                    <div class="modal-body">
1075
                        <div id="result"></div>
1076
                        <fieldset class="rows">
1077
                            <ol>
1078
                                <li>
1079
                                    <label class="required" for="external_id">Item barcode: </label>
1080
                                    <input type="text" id="external_id" name="external_id" required="required">
1081
                                    <span class="required">Required</span>
1082
                                </li>
1083
                            </ol>
1084
                        </fieldset>
1085
                    </div>
1086
                    <div class="modal-footer">
1087
                        <button type="submit" class="btn btn-default">Submit</button>
1088
                        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
1089
                    </div>
1090
                </div>
1091
            </div>
1092
        </form>
1093
    </div>
1094
    [% END %]
1095
1057
[% MACRO jsinclude BLOCK %]
1096
[% MACRO jsinclude BLOCK %]
1058
    [% INCLUDE 'catalog-strings.inc' %]
1097
    [% INCLUDE 'catalog-strings.inc' %]
1059
    [% Asset.js("js/catalog.js") | $raw %]
1098
    [% Asset.js("js/catalog.js") | $raw %]
Lines 1359-1364 Note that permanent location is a code, and location may be an authval. Link Here
1359
    [% INCLUDE 'datatables.inc' %]
1398
    [% INCLUDE 'datatables.inc' %]
1360
    [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
1399
    [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
1361
    [% INCLUDE 'columns_settings.inc' %]
1400
    [% INCLUDE 'columns_settings.inc' %]
1401
    [% INCLUDE 'js-date-format.inc' %]
1362
    [% Asset.js("js/browser.js") | $raw %]
1402
    [% Asset.js("js/browser.js") | $raw %]
1363
    [% Asset.js("js/table_filters.js") | $raw %]
1403
    [% Asset.js("js/table_filters.js") | $raw %]
1364
    <script>
1404
    <script>
Lines 1366-1372 Note that permanent location is a code, and location may be an authval. Link Here
1366
        browser = KOHA.browser('[% searchid | html %]', parseInt(biblionumber, 10));
1406
        browser = KOHA.browser('[% searchid | html %]', parseInt(biblionumber, 10));
1367
        browser.show();
1407
        browser.show();
1368
1408
1409
        [% IF bundlesEnabled %]
1410
        var bundle_settings = [% TablesSettings.GetTableSettings('catalogue', 'detail','bundle_tables','json') | $raw %];
1411
        [% END %]
1369
        $(document).ready(function() {
1412
        $(document).ready(function() {
1413
1414
            [% IF bundlesEnabled %] // Bundle handling
1415
            function createChild ( row, itemnumber ) {
1416
1417
                // Toolbar
1418
                var bundle_toolbar = $('<div id="toolbar" class="btn-toolbar"><a class="btn btn-default" data-toggle="modal" data-target="#bundleItemsModal" data-item="' + itemnumber + '"><i class="fa fa-plus"></i> Add to bundle</a></div>');
1419
1420
                // This is the table we'll convert into a DataTable
1421
                var bundles_table = $('<table class="display tbundle" data-itemnumber="'+itemnumber+'" id="bundle_table_'+itemnumber+'" width="100%"/>');
1422
1423
                // Display it the child row
1424
                row.child( bundle_toolbar.add(bundles_table) ).show();
1425
1426
                // Initialise as a DataTable
1427
                var bundle_table_url = "/api/v1/items/" + itemnumber + "/bundled_items?";
1428
                var bundle_table = bundles_table.kohaTable({
1429
                    "ajax": {
1430
                        "url": bundle_table_url
1431
                    },
1432
                    "header_filter": false,
1433
                    "embed": [
1434
                        "biblio"
1435
                    ],
1436
                    "order": [[ 1, "asc" ]],
1437
                    "columnDefs": [ {
1438
                        "targets": [0,1,2,3,4,5],
1439
                        "render": function (data, type, row, meta) {
1440
                            if ( data && type == 'display' ) {
1441
                                return data.escapeHtml();
1442
                            }
1443
                            return data;
1444
                        }
1445
                    } ],
1446
                    "columns": [
1447
                        {
1448
                            "data": "biblio.title:biblio.medium",
1449
                            "title": "Title",
1450
                            "searchable": true,
1451
                            "orderable": true,
1452
                            "render": function(data, type, row, meta) {
1453
                                var title = "";
1454
                                if ( row.biblio.title ) {
1455
                                    title = title.concat('<span class="biblio-title">',row.biblio.title,'</span>');
1456
                                }
1457
                                if ( row.biblio.subtitle ) {
1458
                                    title = title.concat('<span class="biblio-subtitle">',row.biblio.subtitle,'</span>');
1459
                                }
1460
                                if ( row.biblio.medium ) {
1461
                                    title = title.concat('<span class="biblio-medium">',row.biblio.medium,'</span>');
1462
                                }
1463
                                return title;
1464
                            }
1465
                        },
1466
                        {
1467
                            "data": "biblio.author",
1468
                            "title": "Author",
1469
                            "searchable": true,
1470
                            "orderable": true,
1471
                        },
1472
                        {
1473
                            "data": "collection_code",
1474
                            "title": "Collection code",
1475
                            "searchable": true,
1476
                            "orderable": true,
1477
                        },
1478
                        {
1479
                            "data": "item_type",
1480
                            "title": "Item Type",
1481
                            "searchable": false,
1482
                            "orderable": true,
1483
                        },
1484
                        {
1485
                            "data": "callnumber",
1486
                            "title": "Callnumber",
1487
                            "searchable": true,
1488
                            "orderable": true,
1489
                        },
1490
                        {
1491
                            "data": "external_id",
1492
                            "title": "Barcode",
1493
                            "searchable": true,
1494
                            "orderable": true,
1495
                        },
1496
                        {
1497
                            "data": "lost_status:last_seen_date",
1498
                            "title": "Status",
1499
                            "searchable": false,
1500
                            "orderable": true,
1501
                            "render": function(data, type, row, meta) {
1502
                                if ( row.lost_status ) {
1503
                                    return "Lost: " + row.lost_status;
1504
                                }
1505
                                return "";
1506
                            }
1507
                        },
1508
                        {
1509
                            "data": function( row, type, val, meta ) {
1510
                                var result = '<button class="btn btn-default btn-xs remove" role="button" data-itemnumber="'+row.item_id+'"><i class="fa fa-minus" aria-hidden="true"></i> '+_("Remove")+'</button>\n';
1511
                                return result;
1512
                            },
1513
                            "title": "Actions",
1514
                            "searchable": false,
1515
                            "orderable": false,
1516
                            "class": "noExport"
1517
                        }
1518
                    ]
1519
                }, bundle_settings, 1);
1520
1521
                $(".tbundle").on("click", ".remove", function(){
1522
                    var bundle_table = $(this).closest('table');
1523
                    var host_itemnumber = bundle_table.data('itemnumber');
1524
                    var component_itemnumber = $(this).data('itemnumber');
1525
                    var unlink_item_url = "/api/v1/items/" + host_itemnumber + "/bundled_items/" + component_itemnumber;
1526
                    $.ajax({
1527
                        type: "DELETE",
1528
                        url: unlink_item_url,
1529
                        success: function(){
1530
                            bundle_table.DataTable({ 'retrieve': true }).draw(false);
1531
                        }
1532
                    });
1533
                });
1534
1535
                return;
1536
            }
1537
1538
            var bundle_changed;
1539
            var bundle_form_active;
1540
            $("#bundleItemsModal").on("shown.bs.modal", function(e){
1541
                var button = $(e.relatedTarget);
1542
                var item_id = button.data('item');
1543
                $("#result").replaceWith('<div id="result"></div>');
1544
                $("#bundleItemsForm").attr('action', '/api/v1/items/' + item_id + '/bundled_items');
1545
                $("#external_id").focus();
1546
                bundle_changed = 0;
1547
                bundle_form_active = item_id;
1548
            });
1549
1550
            $("#bundleItemsForm").submit(function(event) {
1551
1552
                  /* stop form from submitting normally */
1553
                  event.preventDefault();
1554
1555
                  /* get the action attribute from the <form action=""> element */
1556
                  var $form = $(this),
1557
                  url = $form.attr('action');
1558
1559
                  /* Send the data using post with external_id */
1560
                  var posting = $.post({
1561
                      url: url,
1562
                      data: JSON.stringify({ external_id: $('#external_id').val()}),
1563
                      contentType: "application/json; charset=utf-8",
1564
                      dataType: "json"
1565
                  });
1566
1567
                  /* Report the results */
1568
                  posting.done(function(data) {
1569
                      var barcode = $('#external_id').val();
1570
                      $('#result').replaceWith('<div id="result" class="alert alert-success">Success: Added '+barcode+'</div>');
1571
                      $('#external_id').val('').focus();
1572
                      bundle_changed = 1;
1573
                  });
1574
                  posting.fail(function(data) {
1575
                      var barcode = $('#external_id').val();
1576
                      if ( data.status === 409 ) {
1577
                          var response = data.responseJSON;
1578
                          if ( response.key === "PRIMARY" ) {
1579
                              $('#result').replaceWith('<div id="result" class="alert alert-warning">Warning: Item '+barcode+' already attached</div>');
1580
                          } else {
1581
                              $('#result').replaceWith('<div id="result" class="alert alert-danger">Failure: Item '+barcode+' belongs to another bundle</div>');
1582
                          }
1583
                      } else {
1584
                          $('#result').replaceWith('<div id="result" class="alert alert-danger">Failure: Check the logs for details</div>');
1585
                      }
1586
                      $('#external_id').val('').focus();
1587
                  });
1588
            });
1589
1590
            $("#bundleItemsModal").on("hidden.bs.modal", function(e){
1591
                if ( bundle_changed ) {
1592
                    $('#bundle_table_'+bundle_form_active).DataTable({ 'retrieve': true }).ajax.reload();
1593
                }
1594
                bundle_form_active = 0;
1595
                bundle_changed = 0;
1596
            });
1597
1598
            // End bundle handling
1599
            [% END %]
1600
1370
            var table_names = [ 'holdings_table', 'otherholdings_table' ];
1601
            var table_names = [ 'holdings_table', 'otherholdings_table' ];
1371
            var table_settings = [ [% TablesSettings.GetTableSettings('catalogue', 'detail','holdings_table','json') | $raw %], [% TablesSettings.GetTableSettings('catalogue', 'detail','otherholdings_table','json')  | $raw %] ];
1602
            var table_settings = [ [% TablesSettings.GetTableSettings('catalogue', 'detail','holdings_table','json') | $raw %], [% TablesSettings.GetTableSettings('catalogue', 'detail','otherholdings_table','json')  | $raw %] ];
1372
            var has_images = [ "[% itemloop_has_images | html %]", "[% otheritemloop_has_images | html %]" ];
1603
            var has_images = [ "[% itemloop_has_images | html %]", "[% otheritemloop_has_images | html %]" ];
Lines 1382-1387 Note that permanent location is a code, and location may be an authval. Link Here
1382
                    "sDom": 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
1613
                    "sDom": 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
1383
                };
1614
                };
1384
                var table = KohaTable( table_name, dt_parameters, table_settings[index], 'with_filters' );
1615
                var table = KohaTable( table_name, dt_parameters, table_settings[index], 'with_filters' );
1616
1617
                [% IF bundlesEnabled %]
1618
                // Add event listener for opening and closing bundle details
1619
                $('#' + id + ' tbody').on('click', 'button.details-control', function () {
1620
                    var tr = $(this).closest('tr');
1621
                    var dTable = $(this).closest('table').DataTable({ 'retrieve': true });
1622
1623
                    var itemnumber = tr.data('itemnumber');
1624
                    var row = dTable.row( tr );
1625
1626
                    if ( row.child.isShown() ) {
1627
                        // This row is already open - close it
1628
                        row.child.hide();
1629
                        tr.removeClass('shown');
1630
                    }
1631
                    else {
1632
                        // Open this row
1633
                        createChild(row, itemnumber);
1634
                        tr.addClass('shown');
1635
                    }
1636
                } );
1637
                [% END %]
1385
            });
1638
            });
1386
1639
1387
            [% IF Koha.Preference('AcquisitionDetails') %]
1640
            [% IF Koha.Preference('AcquisitionDetails') %]
Lines 1403-1408 Note that permanent location is a code, and location may be an authval. Link Here
1403
                    "sPaginationType": "full"
1656
                    "sPaginationType": "full"
1404
                }));
1657
                }));
1405
            [% END %]
1658
            [% END %]
1659
1406
        });
1660
        });
1407
1661
1408
        [% IF (found1) %]
1662
        [% IF (found1) %]
1409
- 

Return to bug 28854