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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt (-15 / +120 lines)
Lines 1064-1079 Note that permanent location is a code, and location may be an authval. Link Here
1064
[% END %]
1064
[% END %]
1065
1065
1066
    [% IF bundlesEnabled %]
1066
    [% IF bundlesEnabled %]
1067
    <div class="modal" id="bundleItemsModal" tabindex="-1" role="dialog" aria-labelledby="bundleItemsLabel">
1067
    <div class="modal" id="addToBundleModal" tabindex="-1" role="dialog" aria-labelledby="addToBundleLabel">
1068
        <form id="bundleItemsForm" action="">
1068
        <form id="addToBundleForm" action="">
1069
            <div class="modal-dialog" role="document">
1069
            <div class="modal-dialog" role="document">
1070
                <div class="modal-content">
1070
                <div class="modal-content">
1071
                    <div class="modal-header">
1071
                    <div class="modal-header">
1072
                        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
1072
                        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
1073
                        <h3 id="bundleItemsLabel">Add to bundle</h3>
1073
                        <h3 id="addToBundleLabel">Add to bundle</h3>
1074
                    </div>
1074
                    </div>
1075
                    <div class="modal-body">
1075
                    <div class="modal-body">
1076
                        <div id="result"></div>
1076
                        <div id="addResult"></div>
1077
                        <fieldset class="rows">
1077
                        <fieldset class="rows">
1078
                            <ol>
1078
                            <ol>
1079
                                <li>
1079
                                <li>
Lines 1092-1097 Note that permanent location is a code, and location may be an authval. Link Here
1092
            </div>
1092
            </div>
1093
        </form>
1093
        </form>
1094
    </div>
1094
    </div>
1095
1096
    <div class="modal" id="removeFromBundleModal" tabindex="-1" role="dialog" aria-labelledby="removeFromBundleLabel">
1097
        <form id="removeFromBundleForm" action="">
1098
            <div class="modal-dialog" role="document">
1099
                <div class="modal-content">
1100
                    <div class="modal-header">
1101
                        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
1102
                        <h3 id="removeFromBundleLabel">Remove from bundle</h3>
1103
                    </div>
1104
                    <div class="modal-body">
1105
                        <div id="removeResult"></div>
1106
                        <fieldset class="rows">
1107
                            <ol>
1108
                                <li>
1109
                                    <label class="required" for="external_id">Item barcode: </label>
1110
                                    <input type="text" id="rm_external_id" name="external_id" required="required">
1111
                                    <span class="required">Required</span>
1112
                                </li>
1113
                            </ol>
1114
                        </fieldset>
1115
                    </div>
1116
                    <div class="modal-footer">
1117
                        <button type="submit" class="btn btn-default">Submit</button>
1118
                        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
1119
                    </div>
1120
                </div>
1121
            </div>
1122
        </form>
1123
    </div>
1095
    [% END %]
1124
    [% END %]
1096
1125
1097
[% MACRO jsinclude BLOCK %]
1126
[% MACRO jsinclude BLOCK %]
Lines 1418-1424 Note that permanent location is a code, and location may be an authval. Link Here
1418
            function createChild ( row, itemnumber ) {
1447
            function createChild ( row, itemnumber ) {
1419
1448
1420
                // Toolbar
1449
                // Toolbar
1421
                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>');
1450
                var bundle_toolbar = $('<div id="toolbar" class="btn-toolbar"></div>');
1451
                bundle_toolbar.append('<a class="btn btn-default" data-toggle="modal" data-target="#addToBundleModal" data-item="' + itemnumber + '"><i class="fa fa-plus"></i> Add to bundle</a>');
1452
                bundle_toolbar.append('<a class="btn btn-default" data-toggle="modal" data-target="#removeFromBundleModal" data-item="' + itemnumber + '"><i class="fa fa-minus"></i> Remove from bundle</a>');
1422
1453
1423
                // This is the table we'll convert into a DataTable
1454
                // This is the table we'll convert into a DataTable
1424
                var bundles_table = $('<table class="display tbundle" data-itemnumber="'+itemnumber+'" id="bundle_table_'+itemnumber+'" width="100%"/>');
1455
                var bundles_table = $('<table class="display tbundle" data-itemnumber="'+itemnumber+'" id="bundle_table_'+itemnumber+'" width="100%"/>');
Lines 1547-1563 Note that permanent location is a code, and location may be an authval. Link Here
1547
1578
1548
            var bundle_changed;
1579
            var bundle_changed;
1549
            var bundle_form_active;
1580
            var bundle_form_active;
1550
            $("#bundleItemsModal").on("shown.bs.modal", function(e){
1581
            $("#addToBundleModal").on("shown.bs.modal", function(e){
1551
                var button = $(e.relatedTarget);
1582
                var button = $(e.relatedTarget);
1552
                var item_id = button.data('item');
1583
                var item_id = button.data('item');
1553
                $("#result").replaceWith('<div id="result"></div>');
1584
                $("#addResult").replaceWith('<div id="addResult"></div>');
1554
                $("#bundleItemsForm").attr('action', '/api/v1/items/' + item_id + '/bundled_items');
1585
                $("#addToBundleForm").attr('action', '/api/v1/items/' + item_id + '/bundled_items');
1555
                $("#external_id").focus();
1586
                $("#external_id").focus();
1556
                bundle_changed = 0;
1587
                bundle_changed = 0;
1557
                bundle_form_active = item_id;
1588
                bundle_form_active = item_id;
1558
            });
1589
            });
1559
1590
1560
            $("#bundleItemsForm").submit(function(event) {
1591
            $("#addToBundleForm").submit(function(event) {
1561
1592
1562
                  /* stop form from submitting normally */
1593
                  /* stop form from submitting normally */
1563
                  event.preventDefault();
1594
                  event.preventDefault();
Lines 1577-1583 Note that permanent location is a code, and location may be an authval. Link Here
1577
                  /* Report the results */
1608
                  /* Report the results */
1578
                  posting.done(function(data) {
1609
                  posting.done(function(data) {
1579
                      var barcode = $('#external_id').val();
1610
                      var barcode = $('#external_id').val();
1580
                      $('#result').replaceWith('<div id="result" class="alert alert-success">Success: Added '+barcode+'</div>');
1611
                      $('#addResult').replaceWith('<div id="addResult" class="alert alert-success">Success: Added '+barcode+'</div>');
1581
                      $('#external_id').val('').focus();
1612
                      $('#external_id').val('').focus();
1582
                      bundle_changed = 1;
1613
                      bundle_changed = 1;
1583
                  });
1614
                  });
Lines 1586-1603 Note that permanent location is a code, and location may be an authval. Link Here
1586
                      if ( data.status === 409 ) {
1617
                      if ( data.status === 409 ) {
1587
                          var response = data.responseJSON;
1618
                          var response = data.responseJSON;
1588
                          if ( response.key === "PRIMARY" ) {
1619
                          if ( response.key === "PRIMARY" ) {
1589
                              $('#result').replaceWith('<div id="result" class="alert alert-warning">Warning: Item '+barcode+' already attached</div>');
1620
                              $('#addResult').replaceWith('<div id="addResult" class="alert alert-warning">Warning: Item '+barcode+' already attached</div>');
1590
                          } else {
1621
                          } else {
1591
                              $('#result').replaceWith('<div id="result" class="alert alert-danger">Failure: Item '+barcode+' belongs to another bundle</div>');
1622
                              $('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">Failure: Item '+barcode+' belongs to another bundle</div>');
1592
                          }
1623
                          }
1593
                      } else {
1624
                      } else {
1594
                          $('#result').replaceWith('<div id="result" class="alert alert-danger">Failure: Check the logs for details</div>');
1625
                          $('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">Failure: Check the logs for details</div>');
1595
                      }
1626
                      }
1596
                      $('#external_id').val('').focus();
1627
                      $('#external_id').val('').focus();
1597
                  });
1628
                  });
1598
            });
1629
            });
1599
1630
1600
            $("#bundleItemsModal").on("hidden.bs.modal", function(e){
1631
            $("#addToBundleModal").on("hidden.bs.modal", function(e){
1601
                if ( bundle_changed ) {
1632
                if ( bundle_changed ) {
1602
                    $('#bundle_table_'+bundle_form_active).DataTable({ 'retrieve': true }).ajax.reload();
1633
                    $('#bundle_table_'+bundle_form_active).DataTable({ 'retrieve': true }).ajax.reload();
1603
                }
1634
                }
Lines 1605-1610 Note that permanent location is a code, and location may be an authval. Link Here
1605
                bundle_changed = 0;
1636
                bundle_changed = 0;
1606
            });
1637
            });
1607
1638
1639
            $("#removeFromBundleModal").on("shown.bs.modal", function(e){
1640
                var button = $(e.relatedTarget);
1641
                var item_id = button.data('item');
1642
                $("#removeResult").replaceWith('<div id="removeResult"></div>');
1643
                $("#removeFromBundleForm").attr('action', '/api/v1/items/' + item_id + '/bundled_items/');
1644
                $("#rm_external_id").focus();
1645
                bundle_changed = 0;
1646
                bundle_form_active = item_id;
1647
            });
1648
1649
            $("#removeFromBundleForm").submit(function(event) {
1650
1651
                /* stop form from submitting normally */
1652
                event.preventDefault();
1653
1654
                /* get the action attribute from the <form action=""> element */
1655
                var $form = $(this),
1656
                url = $form.attr('action');
1657
1658
                var barcode = $('#rm_external_id').val();
1659
1660
                /* Fetch itemnumber using rm_external_id */
1661
                var itemReq = $.get('/api/v1/items', { q: JSON.stringify({
1662
                    external_id: barcode
1663
                }) }, null, "json");
1664
1665
                var itemnumber;
1666
                itemReq.done(function(data) {
1667
                    if (data.length === 1) {
1668
                        itemnumber = data[0].item_id;
1669
1670
                        /* Remove link using fetch itemnumber */
1671
                        var deleteReq = $.ajax( url + itemnumber, {
1672
                            type : 'DELETE'
1673
                        });
1674
1675
                        /* Report the results */
1676
                        deleteReq.done(function(data) {
1677
                            var barcode = $('#rm_external_id').val();
1678
                            $('#removeResult').replaceWith('<div id="removeResult" class="alert alert-success">'+_("Success: Removed ")+barcode+'</div>');
1679
                            $('#rm_external_id').val('').focus();
1680
                            bundle_changed = 1;
1681
                        });
1682
                        deleteReq.fail(function(data) {
1683
                            var barcode = $('#rm_external_id').val();
1684
                            if ( data.status === 409 ) {
1685
                                var response = data.responseJSON;
1686
                                if ( response.key === "PRIMARY" ) {
1687
                                    $('#removeResult').replaceWith('<div id="removeResult" class="alert alert-warning">Warning: Item '+barcode+' already attached</div>');
1688
                                } else {
1689
                                    $('#removeResult').replaceWith('<div id="removeResult" class="alert alert-danger">Failure: Item '+barcode+' belongs to another bundle</div>');
1690
                                }
1691
                            } else {
1692
                                $('#removeResult').replaceWith('<div id="removeResult" class="alert alert-danger">Failure: Check the logs for details</div>');
1693
                            }
1694
                            $('#rm_external_id').val('').focus();
1695
                        });
1696
                    } else {
1697
                        $('#removeResult').replaceWith('<div id="removeResult" class="alert alert-danger">'+_("Failed: Barcode matched more than one item ")+barcode+'</div>');
1698
                    }
1699
                });
1700
                itemReq.fail(function(data) {
1701
                     $('#removeResult').replaceWith('<div id="removeResult" class="alert alert-danger">'+_("Failed: Item not found ")+barcode+'</div>');
1702
                    $('#rm_external_id').val('').focus();
1703
1704
                });
1705
            });
1706
1707
            $("#removeFromBundleModal").on("hidden.bs.modal", function(e){
1708
                if ( bundle_changed ) {
1709
                    $('#bundle_table_'+bundle_form_active).DataTable({ 'retrieve': true }).ajax.reload();
1710
                }
1711
                bundle_form_active = 0;
1712
                bundle_changed = 0;
1713
            });
1608
            // End bundle handling
1714
            // End bundle handling
1609
            [% END %]
1715
            [% END %]
1610
1716
1611
- 

Return to bug 28854