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

(-)a/Koha/Item.pm (+158 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
    my $bundle_items_rs = $self->_result->item_bundles_item;
1492
    return unless $bundle_items_rs;
1493
    return Koha::Item->_new_from_dbic($bundle_items_rs->host);
1494
}
1495
1496
=head3 in_bundle
1497
1498
  my $in_bundle = $item->in_bundle;
1499
1500
Returns whether this item is currently in a bundle
1501
1502
=cut
1503
1504
sub in_bundle {
1505
    my ($self) = @_;
1506
    return $self->bundle_host ? 1 : 0;
1507
}
1508
1509
=head3 add_to_bundle
1510
1511
  my $link = $item->add_to_bundle($bundle_item);
1512
1513
Adds the bundle_item passed to this item
1514
1515
=cut
1516
1517
sub add_to_bundle {
1518
    my ( $self, $bundle_item ) = @_;
1519
1520
    my $schema = Koha::Database->new->schema;
1521
1522
    my $BundleNotLoanValue = C4::Context->preference('BundleNotLoanValue');
1523
1524
    try {
1525
        $schema->txn_do(
1526
            sub {
1527
                $self->_result->add_to_item_bundles_hosts(
1528
                    { item => $bundle_item->itemnumber } );
1529
1530
                $bundle_item->notforloan($BundleNotLoanValue)->store();
1531
            }
1532
        );
1533
    }
1534
    catch {
1535
1536
        # 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
1537
        if ( ref($_) eq 'DBIx::Class::Exception' ) {
1538
            warn $_->{msg};
1539
            if ( $_->{msg} =~ /Cannot add or update a child row: a foreign key constraint fails/ ) {
1540
                # FK constraints
1541
                # FIXME: MySQL error, if we support more DB engines we should implement this for each
1542
                if ( $_->{msg} =~ /FOREIGN KEY \(`(?<column>.*?)`\)/ ) {
1543
                    Koha::Exceptions::Object::FKConstraint->throw(
1544
                        error     => 'Broken FK constraint',
1545
                        broken_fk => $+{column}
1546
                    );
1547
                }
1548
            }
1549
            elsif (
1550
                $_->{msg} =~ /Duplicate entry '(.*?)' for key '(?<key>.*?)'/ )
1551
            {
1552
                Koha::Exceptions::Object::DuplicateID->throw(
1553
                    error        => 'Duplicate ID',
1554
                    duplicate_id => $+{key}
1555
                );
1556
            }
1557
            elsif ( $_->{msg} =~
1558
/Incorrect (?<type>\w+) value: '(?<value>.*)' for column \W?(?<property>\S+)/
1559
              )
1560
            {    # The optional \W in the regex might be a quote or backtick
1561
                my $type     = $+{type};
1562
                my $value    = $+{value};
1563
                my $property = $+{property};
1564
                $property =~ s/['`]//g;
1565
                Koha::Exceptions::Object::BadValue->throw(
1566
                    type     => $type,
1567
                    value    => $value,
1568
                    property => $property =~ /(\w+\.\w+)$/
1569
                    ? $1
1570
                    : $property
1571
                    ,    # results in table.column without quotes or backtics
1572
                );
1573
            }
1574
1575
            # Catch-all for foreign key breakages. It will help find other use cases
1576
            $_->rethrow();
1577
        }
1578
        else {
1579
            $_;
1580
        }
1581
    };
1582
}
1583
1584
=head3 remove_from_bundle
1585
1586
Remove this item from any bundle it may have been attached to.
1587
1588
=cut
1589
1590
sub remove_from_bundle {
1591
    my ($self) = @_;
1592
1593
    my $bundle_item_rs = $self->_result->item_bundles_item;
1594
    if ( $bundle_item_rs ) {
1595
        $bundle_item_rs->delete;
1596
        $self->notforloan(0)->store();
1597
        return 1;
1598
    }
1599
    return 0;
1600
}
1601
1444
=head2 Internal methods
1602
=head2 Internal methods
1445
1603
1446
=head3 _after_item_action_hooks
1604
=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 521-526 modules: Link Here
521
            -
521
            -
522
              columnname: checkin_on
522
              columnname: checkin_on
523
523
524
      bundle_tables:
525
        columns:
526
            -
527
              columnname: title
528
              cannot_be_toggled: 1
529
            -
530
              columnname: author
531
            -
532
              columnname: collection_code
533
            -
534
              columnname: item_type
535
            -
536
              columnname: callnumber
537
            -
538
              columnname: external_id
539
            -
540
              columnname: status
541
            -
542
              columnname: bundle_actions
543
              cannot_be_toggled: 1
544
              cannot_be_modified: 1
545
524
  cataloguing:
546
  cataloguing:
525
    addbooks:
547
    addbooks:
526
      reservoir-table:
548
      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 170-175 if (@hostitems){ Link Here
170
170
171
my $dat = &GetBiblioData($biblionumber);
171
my $dat = &GetBiblioData($biblionumber);
172
172
173
#is biblio a collection and are bundles enabled
174
my $leader = $record->leader();
175
$dat->{bundlesEnabled} = ( ( substr( $leader, 7, 1 ) eq 'c' )
176
      && C4::Context->preference('BundleNotLoanValue') ) ? 1 : 0;
177
173
#coping with subscriptions
178
#coping with subscriptions
174
my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
179
my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
175
my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
180
my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
Lines 414-419 foreach my $item (@items) { Link Here
414
        }
419
        }
415
    }
420
    }
416
421
422
    if ($item_object->is_bundle) {
423
        $itemfields{bundles} = 1;
424
        $item->{is_bundle} = 1;
425
    }
426
427
    if ($item_object->in_bundle) {
428
        $item->{bundle_host} = $item_object->bundle_host;
429
    }
430
417
    if ($currentbranch and C4::Context->preference('SeparateHoldings')) {
431
    if ($currentbranch and C4::Context->preference('SeparateHoldings')) {
418
        if ($itembranchcode and $itembranchcode eq $currentbranch) {
432
        if ($itembranchcode and $itembranchcode eq $currentbranch) {
419
            push @itemloop, $item;
433
            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 356-367 Link Here
356
                [% IF ( analyze ) %]<th id="[% tab | html %]_usedin" data-colname="[% tab | html %]_usedin">Used in</th><th></th>[% END %]
356
                [% IF ( analyze ) %]<th id="[% tab | html %]_usedin" data-colname="[% tab | html %]_usedin">Used in</th><th></th>[% END %]
357
                [% IF ( ShowCourseReserves ) %]<th id="[% tab | html %]_course_reserves" data-colname="[% tab | html %]_course_reserves">Course reserves</th>[% END %]
357
                [% IF ( ShowCourseReserves ) %]<th id="[% tab | html %]_course_reserves" data-colname="[% tab | html %]_course_reserves">Course reserves</th>[% END %]
358
                [% IF ( SpineLabelShowPrintOnBibDetails ) %]<th id="[% tab | html %]_spinelabel" data-colname="[% tab | html %]_spinelabel" class="NoSort">Spine label</th>[% END %]
358
                [% IF ( SpineLabelShowPrintOnBibDetails ) %]<th id="[% tab | html %]_spinelabel" data-colname="[% tab | html %]_spinelabel" class="NoSort">Spine label</th>[% END %]
359
                [% IF ( CAN_user_editcatalogue_edit_items ) %]<th id="[% tab | html %]_actions" data-colname="[% tab | html %]_actions"class="NoSort">&nbsp;</th>[% END %]
359
                [% IF ( CAN_user_editcatalogue_edit_items ) %]<th id="[% tab | html %]_actions" data-colname="[% tab | html %]_actions"class="NoSort noExport">&nbsp;</th>[% END %]
360
            </tr>
360
            </tr>
361
        </thead>
361
        </thead>
362
        <tbody>
362
        <tbody>
363
            [% FOREACH item IN items %]
363
            [% FOREACH item IN items %]
364
                <tr>
364
                <tr id="item_[% item.itemnumber | html %]" data-itemnumber="[% item.itemnumber | html %]">
365
                [% IF (StaffDetailItemSelection) %]
365
                [% IF (StaffDetailItemSelection) %]
366
                    <td style="text-align:center;vertical-align:middle">
366
                    <td style="text-align:center;vertical-align:middle">
367
                        <input type="checkbox" value="[% item.itemnumber | html %]" name="itemnumber" />
367
                        <input type="checkbox" value="[% item.itemnumber | html %]" name="itemnumber" />
Lines 532-537 Note that permanent location is a code, and location may be an authval. Link Here
532
                        [% IF ( item.restricted ) %]
532
                        [% IF ( item.restricted ) %]
533
                            <span class="restricted">([% item.restrictedvalue | html %])</span>
533
                            <span class="restricted">([% item.restrictedvalue | html %])</span>
534
                        [% END %]
534
                        [% END %]
535
536
                        [% IF ( item.bundle_host ) %]
537
                            <span class="bundled">In bundle: [% INCLUDE 'biblio-title.inc' biblio = item.bundle_host.biblio link = 1 %]</span>
538
                        [% END %]
539
535
                    </td>
540
                    </td>
536
                    <td class="datelastseen" data-order="[% item.datelastseen | html %]">[% item.datelastseen | $KohaDates %]</td>
541
                    <td class="datelastseen" data-order="[% item.datelastseen | html %]">[% item.datelastseen | $KohaDates %]</td>
537
                    <td class="issues" data-order="[% item.issues || 0 | html %]">[% item.issues || 0 | html %]</td>
542
                    <td class="issues" data-order="[% item.issues || 0 | html %]">[% item.issues || 0 | html %]</td>
Lines 618-623 Note that permanent location is a code, and location may be an authval. Link Here
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>
623
                                <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>
619
                            [% END %]
624
                            [% END %]
620
                        [% END %]
625
                        [% END %]
626
                        [% IF bundlesEnabled %]
627
                            <button class="btn btn-default btn-xs details-control"><i class="fa fa-folder"></i> Manage bundle</button>
628
                        [% END %]
621
                    </td>
629
                    </td>
622
                [% END %]
630
                [% END %]
623
                </tr>
631
                </tr>
Lines 1059-1064 Note that permanent location is a code, and location may be an authval. Link Here
1059
1067
1060
[% END %]
1068
[% END %]
1061
1069
1070
    [% IF bundlesEnabled %]
1071
    <div class="modal" id="bundleItemsModal" tabindex="-1" role="dialog" aria-labelledby="bundleItemsLabel">
1072
        <form id="bundleItemsForm" action="">
1073
            <div class="modal-dialog" role="document">
1074
                <div class="modal-content">
1075
                    <div class="modal-header">
1076
                        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
1077
                        <h3 id="bundleItemsLabel">Add to bundle</h3>
1078
                    </div>
1079
                    <div class="modal-body">
1080
                        <div id="result"></div>
1081
                        <fieldset class="rows">
1082
                            <ol>
1083
                                <li>
1084
                                    <label class="required" for="external_id">Item barcode: </label>
1085
                                    <input type="text" id="external_id" name="external_id" required="required">
1086
                                    <span class="required">Required</span>
1087
                                </li>
1088
                            </ol>
1089
                        </fieldset>
1090
                    </div>
1091
                    <div class="modal-footer">
1092
                        <button type="submit" class="btn btn-default">Submit</button>
1093
                        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
1094
                    </div>
1095
                </div>
1096
            </div>
1097
        </form>
1098
    </div>
1099
    [% END %]
1100
1062
[% MACRO jsinclude BLOCK %]
1101
[% MACRO jsinclude BLOCK %]
1063
    [% INCLUDE 'catalog-strings.inc' %]
1102
    [% INCLUDE 'catalog-strings.inc' %]
1064
    [% Asset.js("js/catalog.js") | $raw %]
1103
    [% Asset.js("js/catalog.js") | $raw %]
Lines 1365-1370 Note that permanent location is a code, and location may be an authval. Link Here
1365
    [% INCLUDE 'datatables.inc' %]
1404
    [% INCLUDE 'datatables.inc' %]
1366
    [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
1405
    [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
1367
    [% INCLUDE 'columns_settings.inc' %]
1406
    [% INCLUDE 'columns_settings.inc' %]
1407
    [% INCLUDE 'js-date-format.inc' %]
1368
    [% Asset.js("js/browser.js") | $raw %]
1408
    [% Asset.js("js/browser.js") | $raw %]
1369
    [% Asset.js("js/table_filters.js") | $raw %]
1409
    [% Asset.js("js/table_filters.js") | $raw %]
1370
    <script>
1410
    <script>
Lines 1372-1378 Note that permanent location is a code, and location may be an authval. Link Here
1372
        browser = KOHA.browser('[% searchid | html %]', parseInt(biblionumber, 10));
1412
        browser = KOHA.browser('[% searchid | html %]', parseInt(biblionumber, 10));
1373
        browser.show();
1413
        browser.show();
1374
1414
1415
        [% IF bundlesEnabled %]
1416
        var bundle_settings = [% TablesSettings.GetTableSettings('catalogue', 'detail','bundle_tables','json') | $raw %];
1417
        [% END %]
1375
        $(document).ready(function() {
1418
        $(document).ready(function() {
1419
1420
            [% IF bundlesEnabled %] // Bundle handling
1421
            function createChild ( row, itemnumber ) {
1422
1423
                // Toolbar
1424
                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>');
1425
1426
                // This is the table we'll convert into a DataTable
1427
                var bundles_table = $('<table class="display tbundle" data-itemnumber="'+itemnumber+'" id="bundle_table_'+itemnumber+'" width="100%"/>');
1428
1429
                // Display it the child row
1430
                row.child( bundle_toolbar.add(bundles_table) ).show();
1431
1432
                // Initialise as a DataTable
1433
                var bundle_table_url = "/api/v1/items/" + itemnumber + "/bundled_items?";
1434
                var bundle_table = bundles_table.kohaTable({
1435
                    "ajax": {
1436
                        "url": bundle_table_url
1437
                    },
1438
                    "header_filter": false,
1439
                    "embed": [
1440
                        "biblio"
1441
                    ],
1442
                    "order": [[ 1, "asc" ]],
1443
                    "columnDefs": [ {
1444
                        "targets": [0,1,2,3,4,5],
1445
                        "render": function (data, type, row, meta) {
1446
                            if ( data && type == 'display' ) {
1447
                                return data.escapeHtml();
1448
                            }
1449
                            return data;
1450
                        }
1451
                    } ],
1452
                    "columns": [
1453
                        {
1454
                            "data": "biblio.title:biblio.medium",
1455
                            "title": "Title",
1456
                            "searchable": true,
1457
                            "orderable": true,
1458
                            "render": function(data, type, row, meta) {
1459
                                var title = "";
1460
                                if ( row.biblio.title ) {
1461
                                    title = title.concat('<span class="biblio-title">',row.biblio.title,'</span>');
1462
                                }
1463
                                if ( row.biblio.subtitle ) {
1464
                                    title = title.concat('<span class="biblio-subtitle">',row.biblio.subtitle,'</span>');
1465
                                }
1466
                                if ( row.biblio.medium ) {
1467
                                    title = title.concat('<span class="biblio-medium">',row.biblio.medium,'</span>');
1468
                                }
1469
                                return title;
1470
                            }
1471
                        },
1472
                        {
1473
                            "data": "biblio.author",
1474
                            "title": "Author",
1475
                            "searchable": true,
1476
                            "orderable": true,
1477
                        },
1478
                        {
1479
                            "data": "collection_code",
1480
                            "title": "Collection code",
1481
                            "searchable": true,
1482
                            "orderable": true,
1483
                        },
1484
                        {
1485
                            "data": "item_type",
1486
                            "title": "Item Type",
1487
                            "searchable": false,
1488
                            "orderable": true,
1489
                        },
1490
                        {
1491
                            "data": "callnumber",
1492
                            "title": "Callnumber",
1493
                            "searchable": true,
1494
                            "orderable": true,
1495
                        },
1496
                        {
1497
                            "data": "external_id",
1498
                            "title": "Barcode",
1499
                            "searchable": true,
1500
                            "orderable": true,
1501
                        },
1502
                        {
1503
                            "data": "lost_status:last_seen_date",
1504
                            "title": "Status",
1505
                            "searchable": false,
1506
                            "orderable": true,
1507
                            "render": function(data, type, row, meta) {
1508
                                if ( row.lost_status ) {
1509
                                    return "Lost: " + row.lost_status;
1510
                                }
1511
                                return "";
1512
                            }
1513
                        },
1514
                        {
1515
                            "data": function( row, type, val, meta ) {
1516
                                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';
1517
                                return result;
1518
                            },
1519
                            "title": "Actions",
1520
                            "searchable": false,
1521
                            "orderable": false,
1522
                            "class": "noExport"
1523
                        }
1524
                    ]
1525
                }, bundle_settings, 1);
1526
1527
                $(".tbundle").on("click", ".remove", function(){
1528
                    var bundle_table = $(this).closest('table');
1529
                    var host_itemnumber = bundle_table.data('itemnumber');
1530
                    var component_itemnumber = $(this).data('itemnumber');
1531
                    var unlink_item_url = "/api/v1/items/" + host_itemnumber + "/bundled_items/" + component_itemnumber;
1532
                    $.ajax({
1533
                        type: "DELETE",
1534
                        url: unlink_item_url,
1535
                        success: function(){
1536
                            bundle_table.DataTable({ 'retrieve': true }).draw(false);
1537
                        }
1538
                    });
1539
                });
1540
1541
                return;
1542
            }
1543
1544
            var bundle_changed;
1545
            var bundle_form_active;
1546
            $("#bundleItemsModal").on("shown.bs.modal", function(e){
1547
                var button = $(e.relatedTarget);
1548
                var item_id = button.data('item');
1549
                $("#result").replaceWith('<div id="result"></div>');
1550
                $("#bundleItemsForm").attr('action', '/api/v1/items/' + item_id + '/bundled_items');
1551
                $("#external_id").focus();
1552
                bundle_changed = 0;
1553
                bundle_form_active = item_id;
1554
            });
1555
1556
            $("#bundleItemsForm").submit(function(event) {
1557
1558
                  /* stop form from submitting normally */
1559
                  event.preventDefault();
1560
1561
                  /* get the action attribute from the <form action=""> element */
1562
                  var $form = $(this),
1563
                  url = $form.attr('action');
1564
1565
                  /* Send the data using post with external_id */
1566
                  var posting = $.post({
1567
                      url: url,
1568
                      data: JSON.stringify({ external_id: $('#external_id').val()}),
1569
                      contentType: "application/json; charset=utf-8",
1570
                      dataType: "json"
1571
                  });
1572
1573
                  /* Report the results */
1574
                  posting.done(function(data) {
1575
                      var barcode = $('#external_id').val();
1576
                      $('#result').replaceWith('<div id="result" class="alert alert-success">Success: Added '+barcode+'</div>');
1577
                      $('#external_id').val('').focus();
1578
                      bundle_changed = 1;
1579
                  });
1580
                  posting.fail(function(data) {
1581
                      var barcode = $('#external_id').val();
1582
                      if ( data.status === 409 ) {
1583
                          var response = data.responseJSON;
1584
                          if ( response.key === "PRIMARY" ) {
1585
                              $('#result').replaceWith('<div id="result" class="alert alert-warning">Warning: Item '+barcode+' already attached</div>');
1586
                          } else {
1587
                              $('#result').replaceWith('<div id="result" class="alert alert-danger">Failure: Item '+barcode+' belongs to another bundle</div>');
1588
                          }
1589
                      } else {
1590
                          $('#result').replaceWith('<div id="result" class="alert alert-danger">Failure: Check the logs for details</div>');
1591
                      }
1592
                      $('#external_id').val('').focus();
1593
                  });
1594
            });
1595
1596
            $("#bundleItemsModal").on("hidden.bs.modal", function(e){
1597
                if ( bundle_changed ) {
1598
                    $('#bundle_table_'+bundle_form_active).DataTable({ 'retrieve': true }).ajax.reload();
1599
                }
1600
                bundle_form_active = 0;
1601
                bundle_changed = 0;
1602
            });
1603
1604
            // End bundle handling
1605
            [% END %]
1606
1376
            var table_names = [ 'holdings_table', 'otherholdings_table' ];
1607
            var table_names = [ 'holdings_table', 'otherholdings_table' ];
1377
            var table_settings = [ [% TablesSettings.GetTableSettings('catalogue', 'detail','holdings_table','json') | $raw %], [% TablesSettings.GetTableSettings('catalogue', 'detail','otherholdings_table','json')  | $raw %] ];
1608
            var table_settings = [ [% TablesSettings.GetTableSettings('catalogue', 'detail','holdings_table','json') | $raw %], [% TablesSettings.GetTableSettings('catalogue', 'detail','otherholdings_table','json')  | $raw %] ];
1378
            var has_images = [ "[% itemloop_has_images | html %]", "[% otheritemloop_has_images | html %]" ];
1609
            var has_images = [ "[% itemloop_has_images | html %]", "[% otheritemloop_has_images | html %]" ];
Lines 1388-1393 Note that permanent location is a code, and location may be an authval. Link Here
1388
                    "sDom": 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
1619
                    "sDom": 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
1389
                };
1620
                };
1390
                var table = KohaTable( table_name, dt_parameters, table_settings[index], 'with_filters' );
1621
                var table = KohaTable( table_name, dt_parameters, table_settings[index], 'with_filters' );
1622
1623
                [% IF bundlesEnabled %]
1624
                // Add event listener for opening and closing bundle details
1625
                $('#' + table_name + ' tbody').on('click', 'button.details-control', function () {
1626
                    var tr = $(this).closest('tr');
1627
                    var dTable = $(this).closest('table').DataTable({ 'retrieve': true });
1628
1629
                    var itemnumber = tr.data('itemnumber');
1630
                    var row = dTable.row( tr );
1631
1632
                    if ( row.child.isShown() ) {
1633
                        // This row is already open - close it
1634
                        row.child.hide();
1635
                        tr.removeClass('shown');
1636
                    }
1637
                    else {
1638
                        // Open this row
1639
                        createChild(row, itemnumber);
1640
                        tr.addClass('shown');
1641
                    }
1642
                } );
1643
                [% END %]
1391
            });
1644
            });
1392
1645
1393
            [% IF Koha.Preference('AcquisitionDetails') %]
1646
            [% IF Koha.Preference('AcquisitionDetails') %]
Lines 1409-1414 Note that permanent location is a code, and location may be an authval. Link Here
1409
                    "sPaginationType": "full"
1662
                    "sPaginationType": "full"
1410
                }));
1663
                }));
1411
            [% END %]
1664
            [% END %]
1665
1412
        });
1666
        });
1413
1667
1414
        [% IF (found1) %]
1668
        [% IF (found1) %]
1415
- 

Return to bug 28854