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 1411-1416 sub move_to_biblio { Link Here
1411
    return $to_biblionumber;
1412
    return $to_biblionumber;
1412
}
1413
}
1413
1414
1415
=head3 bundle_items
1416
1417
  my $bundle_items = $item->bundle_items;
1418
1419
Returns the items associated with this bundle
1420
1421
=cut
1422
1423
sub bundle_items {
1424
    my ($self) = @_;
1425
1426
    if ( !$self->{_bundle_items_cached} ) {
1427
        my $bundle_items = Koha::Items->search(
1428
            { 'item_bundles_item.host' => $self->itemnumber },
1429
            { join                     => 'item_bundles_item' } );
1430
        $self->{_bundle_items}        = $bundle_items;
1431
        $self->{_bundle_items_cached} = 1;
1432
    }
1433
1434
    return $self->{_bundle_items};
1435
}
1436
1437
=head3 is_bundle
1438
1439
  my $is_bundle = $item->is_bundle;
1440
1441
Returns whether the item is a bundle or not
1442
1443
=cut
1444
1445
sub is_bundle {
1446
    my ($self) = @_;
1447
    return $self->bundle_items->count ? 1 : 0;
1448
}
1449
1450
=head3 bundle_host
1451
1452
  my $bundle = $item->bundle_host;
1453
1454
Returns the bundle item this item is attached to
1455
1456
=cut
1457
1458
sub bundle_host {
1459
    my ($self) = @_;
1460
1461
    if ( !$self->{_bundle_host_cached} ) {
1462
        my $bundle_item_rs = $self->_result->item_bundles_item;
1463
        $self->{_bundle_host} =
1464
          $bundle_item_rs
1465
          ? Koha::Item->_new_from_dbic($bundle_item_rs->host)
1466
          : undef;
1467
        $self->{_bundle_host_cached} = 1;
1468
    }
1469
1470
    return $self->{_bundle_host};
1471
}
1472
1473
=head3 in_bundle
1474
1475
  my $in_bundle = $item->in_bundle;
1476
1477
Returns whether this item is currently in a bundle
1478
1479
=cut
1480
1481
sub in_bundle {
1482
    my ($self) = @_;
1483
    return $self->bundle_host ? 1 : 0;
1484
}
1485
1486
=head3 add_to_bundle
1487
1488
  my $link = $item->add_to_bundle($bundle_item);
1489
1490
Adds the bundle_item passed to this item
1491
1492
=cut
1493
1494
sub add_to_bundle {
1495
    my ( $self, $bundle_item ) = @_;
1496
1497
    my $schema = Koha::Database->new->schema;
1498
1499
    my $BundleNotLoanValue = C4::Context->preference('BundleNotLoanValue');
1500
1501
    try {
1502
        $schema->txn_do(
1503
            sub {
1504
                $self->_result->add_to_item_bundles_hosts(
1505
                    { item => $bundle_item->itemnumber } );
1506
1507
                $bundle_item->notforloan($BundleNotLoanValue)->store();
1508
            }
1509
        );
1510
    }
1511
    catch {
1512
1513
        # 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
1514
        if ( ref($_) eq 'DBIx::Class::Exception' ) {
1515
            warn $_->{msg};
1516
            if ( $_->{msg} =~ /Cannot add or update a child row: a foreign key constraint fails/ ) {
1517
                # FK constraints
1518
                # FIXME: MySQL error, if we support more DB engines we should implement this for each
1519
                if ( $_->{msg} =~ /FOREIGN KEY \(`(?<column>.*?)`\)/ ) {
1520
                    Koha::Exceptions::Object::FKConstraint->throw(
1521
                        error     => 'Broken FK constraint',
1522
                        broken_fk => $+{column}
1523
                    );
1524
                }
1525
            }
1526
            elsif (
1527
                $_->{msg} =~ /Duplicate entry '(.*?)' for key '(?<key>.*?)'/ )
1528
            {
1529
                Koha::Exceptions::Object::DuplicateID->throw(
1530
                    error        => 'Duplicate ID',
1531
                    duplicate_id => $+{key}
1532
                );
1533
            }
1534
            elsif ( $_->{msg} =~
1535
/Incorrect (?<type>\w+) value: '(?<value>.*)' for column \W?(?<property>\S+)/
1536
              )
1537
            {    # The optional \W in the regex might be a quote or backtick
1538
                my $type     = $+{type};
1539
                my $value    = $+{value};
1540
                my $property = $+{property};
1541
                $property =~ s/['`]//g;
1542
                Koha::Exceptions::Object::BadValue->throw(
1543
                    type     => $type,
1544
                    value    => $value,
1545
                    property => $property =~ /(\w+\.\w+)$/
1546
                    ? $1
1547
                    : $property
1548
                    ,    # results in table.column without quotes or backtics
1549
                );
1550
            }
1551
1552
            # Catch-all for foreign key breakages. It will help find other use cases
1553
            $_->rethrow();
1554
        }
1555
        else {
1556
            $_;
1557
        }
1558
    };
1559
}
1560
1561
=head3 remove_from_bundle
1562
1563
Remove this item from any bundle it may have been attached to.
1564
1565
=cut
1566
1567
sub remove_from_bundle {
1568
    my ($self) = @_;
1569
1570
    my $bundle_item_rs = $self->_result->item_bundles_item;
1571
    if ( $bundle_item_rs ) {
1572
        $bundle_item_rs->delete;
1573
        $self->notforloan(0)->store();
1574
        return 1;
1575
    }
1576
    return 0;
1577
}
1578
1414
=head2 Internal methods
1579
=head2 Internal methods
1415
1580
1416
=head3 _after_item_action_hooks
1581
=head3 _after_item_action_hooks
(-)a/Koha/REST/V1/Items.pm (+121 lines)
Lines 152-155 sub pickup_locations { Link Here
152
    };
152
    };
153
}
153
}
154
154
155
=head3 bundled_items
156
157
Controller function that handles bundled_items Koha::Item objects
158
159
=cut
160
161
sub bundled_items {
162
    my $c = shift->openapi->valid_input or return;
163
164
    my $item_id = $c->validation->param('item_id');
165
    my $item = Koha::Items->find( $item_id );
166
167
    unless ($item) {
168
        return $c->render(
169
            status  => 404,
170
            openapi => { error => "Item not found" }
171
        );
172
    }
173
174
    return try {
175
        my $items_set = $item->bundle_items;
176
        my $items     = $c->objects->search( $items_set );
177
        return $c->render(
178
            status  => 200,
179
            openapi => $items
180
        );
181
    }
182
    catch {
183
        $c->unhandled_exception($_);
184
    };
185
}
186
187
=head3 add_to_bundle
188
189
Controller function that handles adding items to this bundle
190
191
=cut
192
193
sub add_to_bundle {
194
    my $c = shift->openapi->valid_input or return;
195
196
    my $item_id = $c->validation->param('item_id');
197
    my $item = Koha::Items->find( $item_id );
198
199
    unless ($item) {
200
        return $c->render(
201
            status  => 404,
202
            openapi => { error => "Item not found" }
203
        );
204
    }
205
206
207
    my $bundle_item_id = $c->validation->param('body')->{'external_id'};
208
    my $bundle_item = Koha::Items->find( { barcode => $bundle_item_id } );
209
210
    unless ($bundle_item) {
211
        return $c->render(
212
            status  => 404,
213
            openapi => { error => "Bundle item not found" }
214
        );
215
    }
216
217
    return try {
218
        my $link = $item->add_to_bundle($bundle_item);
219
        return $c->render(
220
            status  => 201,
221
            openapi => $bundle_item
222
        );
223
    }
224
    catch {
225
        if ( ref($_) eq 'Koha::Exceptions::Object::DuplicateID' ) {
226
            return $c->render(
227
                status  => 409,
228
                openapi => {
229
                    error => 'Item is already bundled',
230
                    key   => $_->duplicate_id
231
                }
232
            );
233
        }
234
        else {
235
            $c->unhandled_exception($_);
236
        }
237
    };
238
}
239
240
=head3 remove_from_bundle
241
242
Controller function that handles removing items from this bundle
243
244
=cut
245
246
sub remove_from_bundle {
247
    my $c = shift->openapi->valid_input or return;
248
249
    my $item_id = $c->validation->param('item_id');
250
    my $item = Koha::Items->find( $item_id );
251
252
    unless ($item) {
253
        return $c->render(
254
            status  => 404,
255
            openapi => { error => "Item not found" }
256
        );
257
    }
258
259
    my $bundle_item_id = $c->validation->param('bundled_item_id');
260
    my $bundle_item = Koha::Items->find( { itemnumber => $bundle_item_id } );
261
262
    unless ($bundle_item) {
263
        return $c->render(
264
            status  => 404,
265
            openapi => { error => "Bundle item not found" }
266
        );
267
    }
268
269
    $bundle_item->remove_from_bundle;
270
    return $c->render(
271
        status  => 204,
272
        openapi => q{}
273
    );
274
}
275
155
1;
276
1;
(-)a/admin/columns_settings.yml (+22 lines)
Lines 464-469 modules: Link Here
464
            -
464
            -
465
              columnname: checkin_on
465
              columnname: checkin_on
466
466
467
      bundle_tables:
468
        columns:
469
            -
470
              columnname: title
471
              cannot_be_toggled: 1
472
            -
473
              columnname: author
474
            -
475
              columnname: collection_code
476
            -
477
              columnname: item_type
478
            -
479
              columnname: callnumber
480
            -
481
              columnname: external_id
482
            -
483
              columnname: status
484
            -
485
              columnname: bundle_actions
486
              cannot_be_toggled: 1
487
              cannot_be_modified: 1
488
467
  cataloguing:
489
  cataloguing:
468
    addbooks:
490
    addbooks:
469
      reservoir-table:
491
      reservoir-table:
(-)a/api/v1/swagger/definitions.yaml (+2 lines)
Lines 7-12 allows_renewal: Link Here
7
  $ref: definitions/allows_renewal.yaml
7
  $ref: definitions/allows_renewal.yaml
8
basket:
8
basket:
9
  $ref: definitions/basket.yaml
9
  $ref: definitions/basket.yaml
10
bundle_link:
11
  $ref: definitions/bundle_link.yaml
10
cashup:
12
cashup:
11
  $ref: definitions/cashup.yaml
13
  $ref: definitions/cashup.yaml
12
checkout:
14
checkout:
(-)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.yaml (+4 lines)
Lines 59-64 Link Here
59
  $ref: paths/items.yaml#/~1items
59
  $ref: paths/items.yaml#/~1items
60
"/items/{item_id}":
60
"/items/{item_id}":
61
  $ref: paths/items.yaml#/~1items~1{item_id}
61
  $ref: paths/items.yaml#/~1items~1{item_id}
62
"/items/{item_id}/bundled_items":
63
  $ref: paths/items.yaml#/~1items~1{item_id}~1bundled_items
64
"/items/{item_id}/bundled_items/{bundled_item_id}":
65
  $ref: paths/items.yaml#/~1items~1{item_id}~1bundled_items~1{bundled_item_id}
62
"/items/{item_id}/pickup_locations":
66
"/items/{item_id}/pickup_locations":
63
  $ref: paths/items.yaml#/~1items~1{item_id}~1pickup_locations
67
  $ref: paths/items.yaml#/~1items~1{item_id}~1pickup_locations
64
/libraries:
68
/libraries:
(-)a/api/v1/swagger/paths/items.yaml (+157 lines)
Lines 92-97 Link Here
92
    x-koha-authorization:
92
    x-koha-authorization:
93
      permissions:
93
      permissions:
94
        catalogue: "1"
94
        catalogue: "1"
95
/items/{item_id}/bundled_items:
96
  post:
97
    x-mojo-to: Items#add_to_bundle
98
    operationId: addToBundle
99
    tags:
100
      - items
101
    summary: Add item to bundle
102
    parameters:
103
      - $ref: ../parameters.json#/item_id_pp
104
      - name: body
105
        in: body
106
        description: A JSON object containing information about the new bundle link
107
        required: true
108
        schema:
109
          $ref: ../definitions.json#/bundle_link
110
    consumes:
111
      - application/json
112
    produces:
113
      - application/json
114
    responses:
115
      "201":
116
        description: A successfully created bundle link
117
        schema:
118
          items:
119
            $ref: ../definitions.json#/item
120
      "400":
121
        description: Bad parameter
122
        schema:
123
          $ref: ../definitions.json#/error
124
      "401":
125
        description: Authentication required
126
        schema:
127
          $ref: ../definitions.json#/error
128
      "403":
129
        description: Access forbidden
130
        schema:
131
          $ref: ../definitions.json#/error
132
      "404":
133
        description: Resource not found
134
        schema:
135
          $ref: ../definitions.json#/error
136
      "409":
137
        description: Conflict in creating resource
138
        schema:
139
          $ref: ../definitions.json#/error
140
      "500":
141
        description: Internal server error
142
        schema:
143
          $ref: ../definitions.json#/error
144
      "503":
145
        description: Under maintenance
146
        schema:
147
          $ref: ../definitions.json#/error
148
    x-koha-authorization:
149
      permissions:
150
        catalogue: 1
151
  get:
152
    x-mojo-to: Items#bundled_items
153
    operationId: bundledItems
154
    tags:
155
      - items
156
    summary: List bundled items
157
    parameters:
158
      - $ref: ../parameters.json#/item_id_pp
159
      - name: external_id
160
        in: query
161
        description: Search on the item's barcode
162
        required: false
163
        type: string
164
      - $ref: ../parameters.json#/match
165
      - $ref: ../parameters.json#/order_by
166
      - $ref: ../parameters.json#/page
167
      - $ref: ../parameters.json#/per_page
168
      - $ref: ../parameters.json#/q_param
169
      - $ref: ../parameters.json#/q_body
170
      - $ref: ../parameters.json#/q_header
171
    consumes:
172
      - application/json
173
    produces:
174
      - application/json
175
    responses:
176
      "200":
177
        description: A list of item
178
        schema:
179
          type: array
180
          items:
181
            $ref: ../definitions.json#/item
182
      "401":
183
        description: Authentication required
184
        schema:
185
          $ref: ../definitions.json#/error
186
      "403":
187
        description: Access forbidden
188
        schema:
189
          $ref: ../definitions.json#/error
190
      "500":
191
        description: Internal server error
192
        schema:
193
          $ref: ../definitions.json#/error
194
      "503":
195
        description: Under maintenance
196
        schema:
197
          $ref: ../definitions.json#/error
198
    x-koha-authorization:
199
      permissions:
200
        catalogue: "1"
201
    x-koha-embed:
202
      - biblio
203
      - checkout
204
/items/{item_id}/bundled_items/{bundled_item_id}:
205
  delete:
206
    x-mojo-to: Items#remove_from_bundle
207
    operationId: removeFromBundle
208
    tags:
209
      - items
210
    summary: Remove item from bundle
211
    parameters:
212
      - $ref: ../parameters.json#/item_id_pp
213
      - name: bundled_item_id
214
        in: path
215
        description: Internal identifier for the bundled item
216
        required: true
217
        type: string
218
    consumes:
219
      - application/json
220
    produces:
221
      - application/json
222
    responses:
223
      "204":
224
        description: Bundle link deleted
225
      "400":
226
        description: Bad parameter
227
        schema:
228
          $ref: ../definitions.json#/error
229
      "401":
230
        description: Authentication required
231
        schema:
232
          $ref: ../definitions.json#/error
233
      "403":
234
        description: Access forbidden
235
        schema:
236
          $ref: ../definitions.json#/error
237
      "404":
238
        description: Resource not found
239
        schema:
240
          $ref: ../definitions.json#/error
241
      "500":
242
        description: Internal server error
243
        schema:
244
          $ref: ../definitions.json#/error
245
      "503":
246
        description: Under maintenance
247
        schema:
248
          $ref: ../definitions.json#/error
249
    x-koha-authorization:
250
      permissions:
251
        catalogue: 1
95
"/items/{item_id}/pickup_locations":
252
"/items/{item_id}/pickup_locations":
96
  get:
253
  get:
97
    x-mojo-to: Items#pickup_locations
254
    x-mojo-to: Items#pickup_locations
(-)a/catalogue/detail.pl (+14 lines)
Lines 167-172 if (@hostitems){ Link Here
167
167
168
my $dat = &GetBiblioData($biblionumber);
168
my $dat = &GetBiblioData($biblionumber);
169
169
170
#is biblio a collection and are bundles enabled
171
my $leader = $record->leader();
172
$dat->{bundlesEnabled} = ( ( substr( $leader, 7, 1 ) eq 'c' )
173
      && C4::Context->preference('BundleNotLoanValue') ) ? 1 : 0;
174
170
#coping with subscriptions
175
#coping with subscriptions
171
my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
176
my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
172
my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
177
my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
Lines 401-406 foreach my $item (@items) { Link Here
401
        $item->{cover_images} = $item_object->cover_images;
406
        $item->{cover_images} = $item_object->cover_images;
402
    }
407
    }
403
408
409
    if ($item_object->is_bundle) {
410
        $itemfields{bundles} = 1;
411
        $item->{is_bundle} = 1;
412
    }
413
414
    if ($item_object->in_bundle) {
415
        $item->{bundle_host} = $item_object->bundle_host;
416
    }
417
404
    if ($currentbranch and C4::Context->preference('SeparateHoldings')) {
418
    if ($currentbranch and C4::Context->preference('SeparateHoldings')) {
405
        if ($itembranchcode and $itembranchcode eq $currentbranch) {
419
        if ($itembranchcode and $itembranchcode eq $currentbranch) {
406
            push @itemloop, $item;
420
            push @itemloop, $item;
(-)a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss (+4 lines)
Lines 2346-2351 td { Link Here
2346
    display: block;
2346
    display: block;
2347
}
2347
}
2348
2348
2349
.bundled {
2350
    display: block;
2351
}
2352
2349
.datedue {
2353
.datedue {
2350
    color: #999;
2354
    color: #999;
2351
    display: block;
2355
    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 / +249 lines)
Lines 338-349 Link Here
338
                [% IF ( analyze ) %]<th id="[% tab | html %]_usedin" data-colname="[% tab | html %]_usedin">Used in</th><th></th>[% END %]
338
                [% IF ( analyze ) %]<th id="[% tab | html %]_usedin" data-colname="[% tab | html %]_usedin">Used in</th><th></th>[% END %]
339
                [% IF ( ShowCourseReserves ) %]<th id="[% tab | html %]_course_reserves" data-colname="[% tab | html %]_course_reserves">Course reserves</th>[% END %]
339
                [% IF ( ShowCourseReserves ) %]<th id="[% tab | html %]_course_reserves" data-colname="[% tab | html %]_course_reserves">Course reserves</th>[% END %]
340
                [% IF ( SpineLabelShowPrintOnBibDetails ) %]<th id="[% tab | html %]_spinelabel" data-colname="[% tab | html %]_spinelabel" class="NoSort">Spine label</th>[% END %]
340
                [% IF ( SpineLabelShowPrintOnBibDetails ) %]<th id="[% tab | html %]_spinelabel" data-colname="[% tab | html %]_spinelabel" class="NoSort">Spine label</th>[% END %]
341
                [% IF ( CAN_user_editcatalogue_edit_items ) %]<th id="[% tab | html %]_actions" data-colname="[% tab | html %]_actions"class="NoSort">&nbsp;</th>[% END %]
341
                [% IF ( CAN_user_editcatalogue_edit_items ) %]<th id="[% tab | html %]_actions" data-colname="[% tab | html %]_actions"class="NoSort noExport">&nbsp;</th>[% END %]
342
            </tr>
342
            </tr>
343
        </thead>
343
        </thead>
344
        <tbody>
344
        <tbody>
345
            [% FOREACH item IN items %]
345
            [% FOREACH item IN items %]
346
                <tr>
346
                <tr id="item_[% item.itemnumber | html %]" data-itemnumber="[% item.itemnumber | html %]">
347
                [% IF (StaffDetailItemSelection) %]
347
                [% IF (StaffDetailItemSelection) %]
348
                    <td style="text-align:center;vertical-align:middle">
348
                    <td style="text-align:center;vertical-align:middle">
349
                        <input type="checkbox" value="[% item.itemnumber | html %]" name="itemnumber" />
349
                        <input type="checkbox" value="[% item.itemnumber | html %]" name="itemnumber" />
Lines 505-510 Note that permanent location is a code, and location may be an authval. Link Here
505
                            <span class="restricted">([% item.restrictedvalue | html %])</span>
505
                            <span class="restricted">([% item.restrictedvalue | html %])</span>
506
                        [% END %]
506
                        [% END %]
507
507
508
                        [% IF ( item.bundle_host ) %]
509
                            <span class="bundled">In bundle: [% INCLUDE 'biblio-title.inc' biblio = item.bundle_host.biblio link = 1 %]</span>
510
                        [% END %]
511
508
                    </td>
512
                    </td>
509
                    <td class="datelastseen" data-order="[% item.datelastseen | html %]">[% item.datelastseen | $KohaDates %]</td>
513
                    <td class="datelastseen" data-order="[% item.datelastseen | html %]">[% item.datelastseen | $KohaDates %]</td>
510
                    <td class="dateaccessioned" data-order="[% item.dateaccessioned | html %]">[% item.dateaccessioned | $KohaDates %]</td>
514
                    <td class="dateaccessioned" data-order="[% item.dateaccessioned | html %]">[% item.dateaccessioned | $KohaDates %]</td>
Lines 589-594 Note that permanent location is a code, and location may be an authval. Link Here
589
                                <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>
593
                                <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>
590
                            [% END %]
594
                            [% END %]
591
                        [% END %]
595
                        [% END %]
596
                        [% IF bundlesEnabled %]
597
                            <button class="btn btn-default btn-xs details-control"><i class="fa fa-folder"></i> Manage bundle</button>
598
                        [% END %]
592
                    </td>
599
                    </td>
593
                [% END %]
600
                [% END %]
594
                </tr>
601
                </tr>
Lines 1029-1034 Note that permanent location is a code, and location may be an authval. Link Here
1029
1036
1030
[% END %]
1037
[% END %]
1031
1038
1039
    [% IF bundlesEnabled %]
1040
    <div class="modal" id="bundleItemsModal" tabindex="-1" role="dialog" aria-labelledby="bundleItemsLabel">
1041
        <form id="bundleItemsForm" action="">
1042
            <div class="modal-dialog" role="document">
1043
                <div class="modal-content">
1044
                    <div class="modal-header">
1045
                        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
1046
                        <h3 id="bundleItemsLabel">Add to bundle</h3>
1047
                    </div>
1048
                    <div class="modal-body">
1049
                        <div id="result"></div>
1050
                        <fieldset class="rows">
1051
                            <ol>
1052
                                <li>
1053
                                    <label class="required" for="external_id">Item barcode: </label>
1054
                                    <input type="text" id="external_id" name="external_id" required="required">
1055
                                    <span class="required">Required</span>
1056
                                </li>
1057
                            </ol>
1058
                        </fieldset>
1059
                    </div>
1060
                    <div class="modal-footer">
1061
                        <button type="submit" class="btn btn-default">Submit</button>
1062
                        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
1063
                    </div>
1064
                </div>
1065
            </div>
1066
        </form>
1067
    </div>
1068
    [% END %]
1069
1032
[% MACRO jsinclude BLOCK %]
1070
[% MACRO jsinclude BLOCK %]
1033
    [% INCLUDE 'catalog-strings.inc' %]
1071
    [% INCLUDE 'catalog-strings.inc' %]
1034
    [% Asset.js("js/catalog.js") | $raw %]
1072
    [% Asset.js("js/catalog.js") | $raw %]
Lines 1327-1332 Note that permanent location is a code, and location may be an authval. Link Here
1327
    [% INCLUDE 'datatables.inc' %]
1365
    [% INCLUDE 'datatables.inc' %]
1328
    [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
1366
    [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
1329
    [% INCLUDE 'columns_settings.inc' %]
1367
    [% INCLUDE 'columns_settings.inc' %]
1368
    [% INCLUDE 'js-date-format.inc' %]
1330
    [% Asset.js("js/browser.js") | $raw %]
1369
    [% Asset.js("js/browser.js") | $raw %]
1331
    [% Asset.js("js/table_filters.js") | $raw %]
1370
    [% Asset.js("js/table_filters.js") | $raw %]
1332
    <script>
1371
    <script>
Lines 1334-1340 Note that permanent location is a code, and location may be an authval. Link Here
1334
        browser = KOHA.browser('[% searchid | html %]', parseInt(biblionumber, 10));
1373
        browser = KOHA.browser('[% searchid | html %]', parseInt(biblionumber, 10));
1335
        browser.show();
1374
        browser.show();
1336
1375
1376
        [% IF bundlesEnabled %]
1377
        var bundle_columns = [% TablesSettings.GetColumns('catalogue', 'detail','bundle_tables','json') | $raw %];
1378
        [% END %]
1337
        $(document).ready(function() {
1379
        $(document).ready(function() {
1380
1381
            [% IF bundlesEnabled %] // Bundle handling
1382
            function createChild ( row, itemnumber ) {
1383
1384
                // Toolbar
1385
                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>');
1386
1387
                // This is the table we'll convert into a DataTable
1388
                var bundles_table = $('<table class="display tbundle" data-itemnumber="'+itemnumber+'" id="bundle_table_'+itemnumber+'" width="100%"/>');
1389
1390
                // Display it the child row
1391
                row.child( bundle_toolbar.add(bundles_table) ).show();
1392
1393
                // Initialise as a DataTable
1394
                var bundle_table_url = "/api/v1/items/" + itemnumber + "/bundled_items?";
1395
                var bundle_table = bundles_table.kohaTable({
1396
                    "ajax": {
1397
                        "url": bundle_table_url
1398
                    },
1399
                    "header_filter": false,
1400
                    "embed": [
1401
                        "biblio"
1402
                    ],
1403
                    "order": [[ 1, "asc" ]],
1404
                    "columnDefs": [ {
1405
                        "targets": [0,1,2,3,4,5],
1406
                        "render": function (data, type, row, meta) {
1407
                            if ( data && type == 'display' ) {
1408
                                return data.escapeHtml();
1409
                            }
1410
                            return data;
1411
                        }
1412
                    } ],
1413
                    "columns": [
1414
                        {
1415
                            "data": "biblio.title:biblio.medium",
1416
                            "title": "Title",
1417
                            "searchable": true,
1418
                            "orderable": true,
1419
                            "render": function(data, type, row, meta) {
1420
                                var title = "";
1421
                                if ( row.biblio.title ) {
1422
                                    title = title.concat('<span class="biblio-title">',row.biblio.title,'</span>');
1423
                                }
1424
                                if ( row.biblio.medium ) {
1425
                                    title = title.concat('<span class="biblio-medium">',row.biblio.medium,'</span>');
1426
                                }
1427
                                return title;
1428
                            }
1429
                        },
1430
                        {
1431
                            "data": "biblio.author",
1432
                            "title": "Author",
1433
                            "searchable": true,
1434
                            "orderable": true,
1435
                        },
1436
                        {
1437
                            "data": "collection_code",
1438
                            "title": "Collection code",
1439
                            "searchable": true,
1440
                            "orderable": true,
1441
                        },
1442
                        {
1443
                            "data": "item_type",
1444
                            "title": "Item Type",
1445
                            "searchable": false,
1446
                            "orderable": true,
1447
                        },
1448
                        {
1449
                            "data": "callnumber",
1450
                            "title": "Callnumber",
1451
                            "searchable": true,
1452
                            "orderable": true,
1453
                        },
1454
                        {
1455
                            "data": "external_id",
1456
                            "title": "Barcode",
1457
                            "searchable": true,
1458
                            "orderable": true,
1459
                        },
1460
                        {
1461
                            "data": "lost_status:last_seen_date",
1462
                            "title": "Status",
1463
                            "searchable": false,
1464
                            "orderable": true,
1465
                            "render": function(data, type, row, meta) {
1466
                                if ( row.lost_status ) {
1467
                                    return "Lost: " + row.lost_status;
1468
                                }
1469
                                return "";
1470
                            }
1471
                        },
1472
                        {
1473
                            "data": function( row, type, val, meta ) {
1474
                                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';
1475
                                return result;
1476
                            },
1477
                            "title": "Actions",
1478
                            "searchable": false,
1479
                            "orderable": false,
1480
                            "class": "noExport"
1481
                        }
1482
                    ]
1483
                }, bundle_columns, 1);
1484
1485
                $(".tbundle").on("click", ".remove", function(){
1486
                    var bundle_table = $(this).closest('table');
1487
                    var host_itemnumber = bundle_table.data('itemnumber');
1488
                    var component_itemnumber = $(this).data('itemnumber');
1489
                    var unlink_item_url = "/api/v1/items/" + host_itemnumber + "/bundled_items/" + component_itemnumber;
1490
                    $.ajax({
1491
                        type: "DELETE",
1492
                        url: unlink_item_url,
1493
                        success: function(){
1494
                            bundle_table.DataTable({ 'retrieve': true }).draw(false);
1495
                        }
1496
                    });
1497
                });
1498
1499
                return;
1500
            }
1501
1502
            var bundle_changed;
1503
            var bundle_form_active;
1504
            $("#bundleItemsModal").on("shown.bs.modal", function(e){
1505
                var button = $(e.relatedTarget);
1506
                var item_id = button.data('item');
1507
                $("#result").replaceWith('<div id="result"></div>');
1508
                $("#bundleItemsForm").attr('action', '/api/v1/items/' + item_id + '/bundled_items');
1509
                $("#external_id").focus();
1510
                bundle_changed = 0;
1511
                bundle_form_active = item_id;
1512
            });
1513
1514
            $("#bundleItemsForm").submit(function(event) {
1515
1516
                  /* stop form from submitting normally */
1517
                  event.preventDefault();
1518
1519
                  /* get the action attribute from the <form action=""> element */
1520
                  var $form = $(this),
1521
                  url = $form.attr('action');
1522
1523
                  /* Send the data using post with external_id */
1524
                  var posting = $.post(url, JSON.stringify({
1525
                      external_id: $('#external_id').val()
1526
                  }), null, "json");
1527
1528
                  /* Report the results */
1529
                  posting.done(function(data) {
1530
                      var barcode = $('#external_id').val();
1531
                      $('#result').replaceWith('<div id="result" class="alert alert-success">Success: Added '+barcode+'</div>');
1532
                      $('#external_id').val('').focus();
1533
                      bundle_changed = 1;
1534
                  });
1535
                  posting.fail(function(data) {
1536
                      var barcode = $('#external_id').val();
1537
                      if ( data.status === 409 ) {
1538
                          var response = data.responseJSON;
1539
                          if ( response.key === "PRIMARY" ) {
1540
                              $('#result').replaceWith('<div id="result" class="alert alert-warning">Warning: Item '+barcode+' already attached</div>');
1541
                          } else {
1542
                              $('#result').replaceWith('<div id="result" class="alert alert-danger">Failure: Item '+barcode+' belongs to another bundle</div>');
1543
                          }
1544
                      } else {
1545
                          $('#result').replaceWith('<div id="result" class="alert alert-danger">Failure: Check the logs for details</div>');
1546
                      }
1547
                      $('#external_id').val('').focus();
1548
                  });
1549
            });
1550
1551
            $("#bundleItemsModal").on("hidden.bs.modal", function(e){
1552
                if ( bundle_changed ) {
1553
                    $('#bundle_table_'+bundle_form_active).DataTable({ 'retrieve': true }).ajax.reload();
1554
                }
1555
                bundle_form_active = 0;
1556
                bundle_changed = 0;
1557
            });
1558
1559
            // End bundle handling
1560
            [% END %]
1561
1338
            var ids = ['holdings_table', 'otherholdings_table'];
1562
            var ids = ['holdings_table', 'otherholdings_table'];
1339
            var columns_settings = [ [% TablesSettings.GetColumns('catalogue', 'detail','holdings_table','json') | $raw %], [% TablesSettings.GetColumns('catalogue', 'detail','otherholdings_table','json')  | $raw %] ];
1563
            var columns_settings = [ [% TablesSettings.GetColumns('catalogue', 'detail','holdings_table','json') | $raw %], [% TablesSettings.GetColumns('catalogue', 'detail','otherholdings_table','json')  | $raw %] ];
1340
            var has_images = ["[% itemloop_has_images | html %]", "[% otheritemloop_has_images | html %]"];
1564
            var has_images = ["[% itemloop_has_images | html %]", "[% otheritemloop_has_images | html %]"];
Lines 1351-1356 Note that permanent location is a code, and location may be an authval. Link Here
1351
                    "sDom": 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
1575
                    "sDom": 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
1352
                };
1576
                };
1353
                var table = KohaTable(id, dt_parameters, columns_settings[i], 'with_filters');
1577
                var table = KohaTable(id, dt_parameters, columns_settings[i], 'with_filters');
1578
1579
                [% IF bundlesEnabled %]
1580
                // Add event listener for opening and closing bundle details
1581
                $('#' + id + ' tbody').on('click', 'button.details-control', function () {
1582
                    var tr = $(this).closest('tr');
1583
                    var dTable = $(this).closest('table').DataTable({ 'retrieve': true });
1584
1585
                    var itemnumber = tr.data('itemnumber');
1586
                    var row = dTable.row( tr );
1587
1588
                    if ( row.child.isShown() ) {
1589
                        // This row is already open - close it
1590
                        row.child.hide();
1591
                        tr.removeClass('shown');
1592
                    }
1593
                    else {
1594
                        // Open this row
1595
                        createChild(row, itemnumber);
1596
                        tr.addClass('shown');
1597
                    }
1598
                } );
1599
                [% END %]
1354
            }
1600
            }
1355
1601
1356
            [% IF Koha.Preference('AcquisitionDetails') %]
1602
            [% IF Koha.Preference('AcquisitionDetails') %]
Lines 1372-1377 Note that permanent location is a code, and location may be an authval. Link Here
1372
                    "sPaginationType": "full"
1618
                    "sPaginationType": "full"
1373
                }));
1619
                }));
1374
            [% END %]
1620
            [% END %]
1621
1375
        });
1622
        });
1376
1623
1377
        $(document).ready(function() {
1624
        $(document).ready(function() {
1378
- 

Return to bug 28854