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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt (-25 / +34 lines)
Lines 1235-1240 Link Here
1235
1235
1236
[% MACRO jsinclude BLOCK %]
1236
[% MACRO jsinclude BLOCK %]
1237
    [% INCLUDE 'calendar.inc' %]
1237
    [% INCLUDE 'calendar.inc' %]
1238
    <script>
1239
        const logged_in_user_borrowernumber = "[% logged_in_user.borrowernumber | html %]";
1240
        const managedby_patron_borrowernumber = "[% managedby_patron.borrowernumber | html %]";
1241
        const op = "[% op | html %]";
1242
    </script>
1243
1238
    <script>
1244
    <script>
1239
        function select_manager(borrowernumber, borrower) {
1245
        function select_manager(borrowernumber, borrower) {
1240
            let tab = $('#suggestiontabs .active table').data('tab-name');
1246
            let tab = $('#suggestiontabs .active table').data('tab-name');
Lines 1256-1275 Link Here
1256
                managedby.val(borrowernumber);
1262
                managedby.val(borrowernumber);
1257
            }
1263
            }
1258
1264
1259
            [% IF op == "save" %]
1265
            if (op == "save"){
1260
                var notify = $('#notify');
1266
                var notify = $('#notify');
1261
                if ( notify.length ) {
1267
                if ( notify.length ) {
1262
                    [% IF managedby_patron %]
1268
                    if ((managedby_patron_borrowernumber && (borrowernumber == logged_in_user_borrowernumber || borrowernumber == managedby_patron_borrowernumber )) || (!managedby_patron_borrowernumber && borrowernumber == logged_in_user_borrowernumber )){
1263
                        if ( borrowernumber == [% logged_in_user.borrowernumber | html %] || borrowernumber == [% managedby_patron.borrowernumber | html %] ) {
1264
                    [% ELSE %]
1265
                        if ( borrowernumber == [% logged_in_user.borrowernumber | html %] ) {
1266
                    [% END %]
1267
                        $(notify).prop('checked', false).prop('disabled', true);
1269
                        $(notify).prop('checked', false).prop('disabled', true);
1268
                    } else {
1270
                    } else {
1269
                        $(notify).prop('disabled', false);
1271
                        $(notify).prop('disabled', false);
1270
                    }
1272
                    }
1271
                }
1273
                }
1272
            [% END %]
1274
            }
1273
        }
1275
        }
1274
1276
1275
        function select_suggester(borrowernumber, borrower) {
1277
        function select_suggester(borrowernumber, borrower) {
Lines 1319-1330 Link Here
1319
        </script>
1321
        </script>
1320
    [% END %]
1322
    [% END %]
1321
    [% IF op == 'else' %]
1323
    [% IF op == 'else' %]
1324
        <script>
1325
            const has_suggestions = [% suggestions.size ? 1 : 0 | html %];
1326
            let suggestionData = [% To.json(suggestions) | $raw %];
1327
            var suggestions_table_settings = [% TablesSettings.GetTableSettings( 'acqui', 'suggestions', 'suggestions', 'json' ) | $raw %]
1328
            addPermissions({
1329
                CAN_user_suggestions_suggestions_manage: [% CAN_user_suggestions_suggestions_manage ? 1 : 0 | html %],
1330
                CAN_user_suggestions_suggestions_delete: [% CAN_user_suggestions_suggestions_delete ? 1 : 0 | html %],
1331
            });
1332
        </script>
1333
1322
        [% INCLUDE 'datatables.inc' %]
1334
        [% INCLUDE 'datatables.inc' %]
1323
        <script>
1335
        <script>
1324
            $(document).ready(function() {
1336
            $(document).ready(function() {
1325
                [% IF suggestions.size %]
1337
                if (has_suggestions){
1326
                    let suggestionData = [% To.json(suggestions) | $raw %];
1327
                    var table_settings = [% TablesSettings.GetTableSettings( 'acqui', 'suggestions', 'suggestions', 'json' ) | $raw %]
1328
                    function loadDatatable(tabName) {
1338
                    function loadDatatable(tabName) {
1329
                        let tabSuggestionData = suggestionData.find(s => s.suggestiontype === `${tabName}`)
1339
                        let tabSuggestionData = suggestionData.find(s => s.suggestiontype === `${tabName}`)
1330
                        $("#table_" + tabName).kohaTable(
1340
                        $("#table_" + tabName).kohaTable(
Lines 1510-1523 Link Here
1510
                                        searchable: false,
1520
                                        searchable: false,
1511
                                        orderable: false,
1521
                                        orderable: false,
1512
                                        render: function (data, type, row, meta) {
1522
                                        render: function (data, type, row, meta) {
1513
                                            [% IF CAN_user_suggestions_suggestions_manage %]
1523
                                            if (permissions.CAN_user_suggestions_suggestions_manage){
1514
                                                let node = '<div class="btn-group dropup">'
1524
                                                let node = '<div class="btn-group dropup">'
1515
                                                node += '<a class="btn btn-default btn-xs" role="button" href="suggestion.pl?suggestionid=%s&amp;op=edit_form"><i class="fa-solid fa-pencil" aria-hidden="true"></i> %s</a>'.format(row.suggestion_id, _("Edit"))
1525
                                                node += '<a class="btn btn-default btn-xs" role="button" href="suggestion.pl?suggestionid=%s&amp;op=edit_form"><i class="fa-solid fa-pencil" aria-hidden="true"></i> %s</a>'.format(row.suggestion_id, _("Edit"))
1516
                                                node += '<a class="btn btn-default btn-xs dropdown-toggle" id="more_actions_%s" role="button" data-bs-toggle="dropdown" href="#"><b class="caret"></b></a>'.format(row.suggestion_id)
1526
                                                node += '<a class="btn btn-default btn-xs dropdown-toggle" id="more_actions_%s" role="button" data-bs-toggle="dropdown" href="#"><b class="caret"></b></a>'.format(row.suggestion_id)
1517
                                                node += '<ul class="dropdown-menu" role="menu" aria-labelledby="more_actions_%s">'.format(row.suggestion_id)
1527
                                                node += '<ul class="dropdown-menu" role="menu" aria-labelledby="more_actions_%s">'.format(row.suggestion_id)
1518
                                                [% IF CAN_user_suggestions_suggestions_delete %]
1528
                                                if (permissions.CAN_user_suggestions_suggestions_delete){
1519
                                                    node += '<li><a href="#" data-op="cud-delete" data-suggestionid="%s" class="dropdown-item trigger_action">%s</a></li>'.format(row.suggestion_id, _("Delete"))
1529
                                                    node += '<li><a href="#" data-op="cud-delete" data-suggestionid="%s" class="dropdown-item trigger_action">%s</a></li>'.format(row.suggestion_id, _("Delete"))
1520
                                                [% END %]
1530
                                                }
1521
                                                if (!row.archived){
1531
                                                if (!row.archived){
1522
                                                    node += '<li><a href="#" class="dropdown-item trigger_action" data-op="cud-archive" data-suggestionid="%s">%s</a></li>'.format(row.suggestion_id, _("Archive"))
1532
                                                    node += '<li><a href="#" class="dropdown-item trigger_action" data-op="cud-archive" data-suggestionid="%s">%s</a></li>'.format(row.suggestion_id, _("Archive"))
1523
                                                } else {
1533
                                                } else {
Lines 1525-1533 Link Here
1525
                                                }
1535
                                                }
1526
                                                node += '</ul></div>'
1536
                                                node += '</ul></div>'
1527
                                                return node
1537
                                                return node
1528
                                            [% ELSIF CAN_user_suggestions_suggestions_delete %]
1538
                                            } else if (permissions.CAN_user_suggestions_suggestions_delete){
1529
                                                return '<button data-op="cud-delete" data-suggestionid="%s" class="btn btn-xs btn-default trigger_action"><i class="fa fa-trash-can"></i> %s</button>'.format(row.suggestion_id, _("Delete"))
1539
                                                return '<button data-op="cud-delete" data-suggestionid="%s" class="btn btn-xs btn-default trigger_action"><i class="fa fa-trash-can"></i> %s</button>'.format(row.suggestion_id, _("Delete"))
1530
                                            [% END %]
1540
                                            }
1531
                                        },
1541
                                        },
1532
                                        createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
1542
                                        createdCell: function (cell, cellData, rowData, rowIndex, colIndex) {
1533
                                            $(cell).find(".trigger_action").on("click", function(e) {
1543
                                            $(cell).find(".trigger_action").on("click", function(e) {
Lines 1546-1552 Link Here
1546
                                    },
1556
                                    },
1547
                                ]
1557
                                ]
1548
                            },
1558
                            },
1549
                            table_settings
1559
                            suggestions_table_settings
1550
                        );
1560
                        );
1551
                    }
1561
                    }
1552
                    if( $("#suggestiontabs .tab-pane.active").length < 1 ){
1562
                    if( $("#suggestiontabs .tab-pane.active").length < 1 ){
Lines 1555-1573 Link Here
1555
                        $("#suggestiontabs a:first").attr("data-table_loaded", 'true')
1565
                        $("#suggestiontabs a:first").attr("data-table_loaded", 'true')
1556
                    }
1566
                    }
1557
1567
1558
                    [% FOREACH suggestion IN suggestions %]
1568
                    suggestionData.forEach(suggestion => {
1559
                        $("#suggestiontabs #[% suggestion.suggestiontype | html %]-tab").on("click", function() {
1569
                        $(`#suggestiontabs #${suggestion.suggestiontype}-tab`).on("click", function() {
1560
                            if(!$(this).data("table_loaded")) {
1570
                            if(!$(this).data("table_loaded")) {
1561
                                loadDatatable("[% suggestion.suggestiontype | html%]")
1571
                                loadDatatable(`${suggestion.suggestiontype}`);
1562
                                $(this).attr("data-table_loaded", "true")
1572
                                $(this).attr("data-table_loaded", "true");
1563
                            }
1573
                            }
1564
                        });
1574
                        });
1565
                    [% END %]
1575
                    });
1566
                [% END %]
1576
                }
1567
1577
1568
                $("#branchcode").on('change',function(){
1578
                $("#branchcode").on('change',function(){
1569
                [%# Modify the hidden input in the filters block from the library %]
1579
                    // Modify the hidden input in the filters block from the library
1570
                [%# dropdown list at the top of suggestion list %]
1580
                    // dropdown list at the top of suggestion list
1571
                    let branchcode = $(this).val();
1581
                    let branchcode = $(this).val();
1572
                    $('input[name="branchcode"]').val( branchcode );
1582
                    $('input[name="branchcode"]').val( branchcode );
1573
                    $('form[name="suggestionfilter"]').submit();
1583
                    $('form[name="suggestionfilter"]').submit();
1574
- 

Return to bug 41579