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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/article-requests.tt (-66 / +92 lines)
Lines 26-65 Link Here
26
26
27
        <ul class="dropdown-menu [% pull_right | html %]" role="menu" aria-labelledby="[% aria_menu | html %]">
27
        <ul class="dropdown-menu [% pull_right | html %]" role="menu" aria-labelledby="[% aria_menu | html %]">
28
            <li>
28
            <li>
29
                <a class="ar-set-pending-request" href="#" onclick="HandleMulti( SetPending, [% id_arg | html %], $(this) ); return false;">
29
                <a class="ar-set-pending-request" href="#">
30
                    <i class="fa fa-bars"></i>
30
                    <i class="fa fa-bars"></i>
31
                    Set request as pending
31
                    Set request as pending
32
                </a>
32
                </a>
33
33
34
                <a class="ar-process-request" href="#" onclick="HandleMulti( Process, [% id_arg | html %], $(this) ); return false;">
34
                <a class="ar-process-request" data-ar-id="[% id_arg | uri %]" href="#">
35
                    <i class="fa fa-cog"></i>
35
                    <i class="fa fa-cog"></i>
36
                    Process request
36
                    Process request
37
                </a>
37
                </a>
38
38
39
                [% IF id_arg && format=='SCAN' %]
39
                [% IF id_arg && format=='SCAN' %]
40
                <a class="ar-edit-urls" href="#" onclick="HandleMulti( EditURLs, [% id_arg | html %], $(this) ); return false;">
40
                <a class="ar-edit-urls" href="#" data-ar-id="[% id_arg | uri %]" href="#">
41
                    <i class="fa-solid fa-pencil" aria-hidden="true"></i>
41
                    <i class="fa-solid fa-pencil" aria-hidden="true"></i>
42
                    Edit URLs
42
                    Edit URLs
43
                </a>
43
                </a>
44
                [% END %]
44
                [% END %]
45
45
46
                <a class="ar-complete-request" href="#" onclick="HandleMulti( Complete, [% id_arg | html %], $(this) ); return false;">
46
                <a class="ar-complete-request" href="#" data-ar-id="[% id_arg | uri %]" href="#">
47
                    <i class="fa fa-check-circle"></i>
47
                    <i class="fa fa-check-circle"></i>
48
                    Complete request
48
                    Complete request
49
                </a>
49
                </a>
50
50
51
                <a class="ar-cancel-request" href="#" onclick="Cancel( [% id_arg | html %], $(this) ); return false;">
51
                <a class="ar-cancel-request" href="#" data-ar-id="[% id_arg | uri %]" href="#">
52
                    <i class="fa fa-minus-circle"></i>
52
                    <i class="fa fa-minus-circle"></i>
53
                    Cancel request
53
                    Cancel request
54
                </a>
54
                </a>
55
55
56
                [% IF id_arg %]
56
                [% IF id_arg %]
57
                <a class="ar-print-request" href="#" onclick="HandleMulti( PrintSlip, [% id_arg | html %], $(this) ); return false;">
57
                <a class="ar-print-request" href="#" data-ar-id="[% id_arg | uri %]" href="#">
58
                    <i class="fa fa-print"></i>
58
                    <i class="fa fa-print"></i>
59
                    Print slip
59
                    Print slip
60
                </a>
60
                </a>
61
                [% ELSE %]
61
                [% ELSE %]
62
                <a class="ar-print-request" href="#" onclick="PrintMultipleSlip(); return false;">
62
                <a class="ar-print-multiple-requests" href="#">
63
                    <i class="fa fa-print"></i>
63
                    <i class="fa fa-print"></i>
64
                    Print slip
64
                    Print slip
65
                </a>
65
                </a>
Lines 577-585 Link Here
577
                var link = $('span#url_'+ id).parent().parent().find('td.ar-actions').find('div.dropdown a');
577
                var link = $('span#url_'+ id).parent().parent().find('td.ar-actions').find('div.dropdown a');
578
                if( link.length > 0 ) link[0].focus();
578
                if( link.length > 0 ) link[0].focus();
579
            });
579
            });
580
            $( '#myModal button' ).on("click", function () {
581
                SaveURLs( $('#myModal textarea').val() );
582
            });
583
580
584
            requested_datatable = $("#article-requests-requested-table").DataTable($.extend(true, {}, dataTablesDefaults, {
581
            requested_datatable = $("#article-requests-requested-table").DataTable($.extend(true, {}, dataTablesDefaults, {
585
                "columnDefs": [
582
                "columnDefs": [
Lines 630-635 Link Here
630
            var link = 'article-request-slip.pl?id='+id;
627
            var link = 'article-request-slip.pl?id='+id;
631
            window.open(link, 'popup', 'width=600,height=400,resizable=1,toolbar=0,scrollbars=1,top');
628
            window.open(link, 'popup', 'width=600,height=400,resizable=1,toolbar=0,scrollbars=1,top');
632
        }
629
        }
630
        $(".ar-print-request").on("click", function (e){
631
            e.preventDefault();
632
            HandleMulti(PrintSlip, $(this).data('ar-id'));
633
        });
633
634
634
        $('#modal-cancellation-reason').on('change', function(e) {
635
        $('#modal-cancellation-reason').on('change', function(e) {
635
            let reason = $(this).val();
636
            let reason = $(this).val();
Lines 671-678 Link Here
671
            });
672
            });
672
            var link = 'article-request-slip.pl?multi=1&id='+ids.join(',');
673
            var link = 'article-request-slip.pl?multi=1&id='+ids.join(',');
673
            window.open(link, 'popup', 'width=600,height=400,resizable=1,toolbar=0,scrollbars=1,top');
674
            window.open(link, 'popup', 'width=600,height=400,resizable=1,toolbar=0,scrollbars=1,top');
674
675
        }
675
        }
676
        $(".ar-print-multiple-requests").on("click", function (e){
677
            e.preventDefault();
678
            PrintMultipleSlip();
679
        });
676
680
677
        function Cancel( id, a ) {
681
        function Cancel( id, a ) {
678
            cancel_id = id;
682
            cancel_id = id;
Lines 680-736 Link Here
680
684
681
            $('#cancelModal').modal();
685
            $('#cancelModal').modal();
682
        }
686
        }
687
        $(".ar-cancel-request").on("click", function (e){
688
            e.preventDefault();
689
            HandleMulti(Cancel, $(this).data('ar-id'), $(this));
690
        });
683
691
684
        function SetPending( id, a ) {
692
    </script>
685
            var table_row = a.closest('tr');
693
686
            table_row.find('.ar-set-pending-request').remove();
694
    <script async type="module">
687
            table_row.find('input[type="checkbox"]').prop('checked', false);
695
        import { APIClient } from '/intranet-tmpl/prog/js/fetch/api-client.js';
688
            a.closest('td').prepend('<img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" class="spinner"/>').find('div.dropdown').hide();
689
            $.ajax({
690
                type: "POST",
691
                url: '/cgi-bin/koha/svc/article_request',
692
                data: {
693
                    action: 'pending',
694
                    id: id,
695
                },
696
                success: function( data ) {
697
                    $("img.spinner").remove();
698
                    requested_datatable.row( table_row ).remove().draw();
699
                    pending_datatable.row.add( table_row ).draw();
700
                    UpdateTabCounts();
701
                    activateBatchActions( active_tab );
702
                },
703
                dataType: 'json'
704
            });
705
        }
706
696
707
        function Process( id, a ) {
697
        async function Process( id, a ) {
708
            var table_row = a.closest('tr');
698
            var table_row = a.closest('tr');
709
            var table = a.closest('table');
699
            var table = a.closest('table');
710
            var orig_datatable = table.attr('id')==='article-requests-pending-table'?pending_datatable:requested_datatable;
700
            var orig_datatable = table.attr('id')==='article-requests-pending-table'?pending_datatable:requested_datatable;
711
            table_row.find('.ar-process-request').remove();
712
            table_row.find('input[type="checkbox"]').prop('checked', false);
713
701
714
            a.closest('td').prepend('<img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" class="spinner"/>').find('div.dropdown').hide();
702
            a.closest('td').prepend('<img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" class="spinner"/>').find('div.dropdown').hide();
715
            $.ajax({
703
716
                type: "POST",
704
            const client = APIClient.article_request;
717
                url: '/cgi-bin/koha/svc/article_request',
705
            await client.articleRequests.process(id).then(
718
                data: {
706
                success => {
719
                    action: 'process',
720
                    id: id,
721
                },
722
                success: function( data ) {
723
                    $("img.spinner").remove();
707
                    $("img.spinner").remove();
708
                    table_row.find('.ar-process-request').remove();
709
                    table_row.find('input[type="checkbox"]').prop('checked', false);
724
                    orig_datatable.row( table_row ).remove().draw();
710
                    orig_datatable.row( table_row ).remove().draw();
725
                    processing_datatable.row.add( table_row ).draw();
711
                    processing_datatable.row.add( table_row ).draw();
726
                    UpdateTabCounts();
712
                    UpdateTabCounts();
727
                    activateBatchActions( active_tab );
713
                    activateBatchActions( active_tab );
728
                },
714
                },
729
                dataType: 'json'
715
                error => {
730
            });
716
                    console.warn("Something wrong happened: %s".format(error));
717
                }
718
            );
731
        }
719
        }
720
        $(".ar-process-request").on("click", function (e){
721
            e.preventDefault();
722
            HandleMulti(Process, $(this).data('ar-id'), $(this));
723
        });
732
724
733
        function Complete( id, a ) {
725
        async function Complete( id, a ) {
734
            // if it is a scan, check if urls field is filled
726
            // if it is a scan, check if urls field is filled
735
            var urlspan = $('span#url_'+id);
727
            var urlspan = $('span#url_'+id);
736
            if( urlspan.length>0 && urlspan.text() === '' ) {
728
            if( urlspan.length>0 && urlspan.text() === '' ) {
Lines 738-758 Link Here
738
                return;
730
                return;
739
            }
731
            }
740
            a.closest('td').prepend('<img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif"/>').find('div.dropdown').hide();
732
            a.closest('td').prepend('<img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif"/>').find('div.dropdown').hide();
741
            $.ajax({
733
            const client = APIClient.article_request;
742
                type: "POST",
734
            await client.articleRequests.complete(id).then(
743
                url: '/cgi-bin/koha/svc/article_request',
735
                success => {
744
                data: {
736
                    $("img.spinner").remove();
745
                    action: 'complete',
746
                    id: id,
747
                },
748
                success: function( data ) {
749
                    active_datatable.row( a.closest('tr') ).remove().draw();
737
                    active_datatable.row( a.closest('tr') ).remove().draw();
750
                    UpdateTabCounts();
738
                    UpdateTabCounts();
751
                    activateBatchActions( active_tab );
739
                    activateBatchActions( active_tab );
752
                },
740
                },
753
                dataType: 'json'
741
                error => {
754
            });
742
                    console.warn("Something wrong happened: %s".format(error));
743
                }
744
            );
755
        }
745
        }
746
        $(".ar-complete-request").on("click", function (e){
747
            e.preventDefault();
748
            HandleMulti(Complete, $(this).data('ar-id'), $(this));
749
        });
750
751
        async function SetPending( id, a ) {
752
            var table_row = a.closest('tr');
753
            table_row.find('.ar-set-pending-request').remove();
754
            table_row.find('input[type="checkbox"]').prop('checked', false);
755
            a.closest('td').prepend('<img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" class="spinner"/>').find('div.dropdown').hide();
756
            const client = APIClient.article_request;
757
            await client.articleRequests.pending(id).then(
758
                success => {
759
                    $("img.spinner").remove();
760
                    requested_datatable.row( table_row ).remove().draw();
761
                    pending_datatable.row.add( table_row ).draw();
762
                    UpdateTabCounts();
763
                    activateBatchActions( active_tab );
764
                },
765
                error => {
766
                    console.warn("Something wrong happened: %s".format(error));
767
                }
768
            );
769
        }
770
        $(".ar-set-pending-request").on("click", function (e){
771
            e.preventDefault();
772
            HandleMulti(SetPending, $(this).data('ar-id'), $(this));
773
        });
756
774
757
        function UpdateTabCounts() {
775
        function UpdateTabCounts() {
758
            $("#ar_requested_count").html( requested_datatable.rows().count() );
776
            $("#ar_requested_count").html( requested_datatable.rows().count() );
Lines 766-773 Link Here
766
            $('#myModal textarea').attr('ar_id', id);
784
            $('#myModal textarea').attr('ar_id', id);
767
            $('#myModal').modal('show');
785
            $('#myModal').modal('show');
768
        }
786
        }
787
        $(".ar-edit-urls").on("click", function (e){
788
            e.preventDefault();
789
            HandleMulti(EditURLs, $(this).data('ar-id'));
790
        });
769
791
770
        function SaveURLs(newurl) {
792
        async function SaveURLs(newurl) {
771
            var id = $('#myModal textarea').attr('ar_id');
793
            var id = $('#myModal textarea').attr('ar_id');
772
            $('span#url_'+ id).text(newurl);
794
            $('span#url_'+ id).text(newurl);
773
            if(newurl)
795
            if(newurl)
Lines 775-789 Link Here
775
            else
797
            else
776
                $('span#url_yesno_'+id).text(_("No"));
798
                $('span#url_yesno_'+id).text(_("No"));
777
799
778
            $.ajax({
800
            const client = APIClient.article_request;
779
                type: "POST",
801
            await client.articleRequests.update_urls(id, newurl).then(
780
                url: '/cgi-bin/koha/svc/article_request',
802
                success => {
781
                data: { action: 'update_urls', id: id, urls: newurl },
803
                },
782
                dataType: 'json',
804
                error => {
783
                error: function() { alert('Error: Saving URL failed!'); },
805
                    console.warn("Something wrong happened: %s".format(error));
784
                success: function(data) { if(!data.success) alert('Saving URL failed!'); },
806
                }
785
            });
807
            );
786
        }
808
        }
809
        $( '#myModal button' ).on("click", function () {
810
            SaveURLs( $('#myModal textarea').val() );
811
        });
812
787
    </script>
813
    </script>
788
[% END %]
814
[% END %]
789
815
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt (-26 / +28 lines)
Lines 370-401 Link Here
370
370
371
            $( ".ar-update-branchcode" ).on('focus', function(){
371
            $( ".ar-update-branchcode" ).on('focus', function(){
372
                previous_branchcode = this.value;
372
                previous_branchcode = this.value;
373
            }).on('change', function(){
373
            })
374
                var branchcode = this.value;
375
                var c = confirm(_("Are you sure you want to change the pickup library from %s to %s for this request?").format( previous_branchcode, branchcode ));
376
377
                if ( c ) {
378
                    var id = this.id.split("branchcode-")[1];
379
                    $("#update-processing-" + id ).css({opacity: 0, visibility: "visible"}).animate({opacity: 1.0}, 200);
380
381
                    $.ajax({
382
                        type: "POST",
383
                        url: '/cgi-bin/koha/svc/article_request',
384
                        data: {
385
                            action: 'update_branchcode',
386
                            id: id,
387
                            branchcode: branchcode,
388
                        },
389
                        success: function( data ) {
390
                            $("#update-processing-" + id ).css({opacity: 1.0, visibility: "visible"}).animate({opacity: 0}, 200);
391
                        },
392
                        dataType: 'json'
393
                    });
394
395
                } else {
396
                    this.value = previous_branchcode;
397
                }
398
            });
399
374
400
            $('#modal-cancellation-reason').on('change', function(e) {
375
            $('#modal-cancellation-reason').on('change', function(e) {
401
                let reason = $(this).val();
376
                let reason = $(this).val();
Lines 442-447 Link Here
442
        });
417
        });
443
    </script>
418
    </script>
444
419
420
    <script async type="module">
421
        import { APIClient } from '/intranet-tmpl/prog/js/fetch/api-client.js';
422
        $(".ar-update-branchcode").on('change', async function(e){
423
            var branchcode = this.value;
424
            var c = confirm(_("Are you sure you want to change the pickup library from %s to %s for this request?").format( previous_branchcode, branchcode ));
425
426
            if ( c ) {
427
                var id = this.id.split("branchcode-")[1];
428
                $("#update-processing-" + id ).css({opacity: 0, visibility: "visible"}).animate({opacity: 1.0}, 200);
429
430
                const client = APIClient.article_request;
431
                await client.articleRequests.update_library_id(id, branchcode).then(
432
                    success => {
433
                        $("#update-processing-" + id ).css({opacity: 1.0, visibility: "visible"}).animate({opacity: 0}, 200);
434
                    },
435
                    error => {
436
                        console.warn("Something wrong happened: %s", error);
437
                    }
438
                );
439
440
441
            } else {
442
                this.value = previous_branchcode;
443
            }
444
        });
445
    </script>
446
445
    [% PROCESS patron_search_js table_id => 'table_borrowers', categories => categories, libraries => libraries, columns => columns, open_on_row_click => 1, on_click_url => '/cgi-bin/koha/circ/request-article.pl?biblionumber=' _ biblio.biblionumber, redirect_if_one_result => 1, redirect_url => '/cgi-bin/koha/circ/request-article.pl?biblionumber=' _ biblio.biblionumber %]
447
    [% PROCESS patron_search_js table_id => 'table_borrowers', categories => categories, libraries => libraries, columns => columns, open_on_row_click => 1, on_click_url => '/cgi-bin/koha/circ/request-article.pl?biblionumber=' _ biblio.biblionumber, redirect_if_one_result => 1, redirect_url => '/cgi-bin/koha/circ/request-article.pl?biblionumber=' _ biblio.biblionumber %]
446
448
447
[% END %]
449
[% END %]
(-)a/svc/article_request (-9 / +10 lines)
Lines 38-71 binmode STDOUT, ':encoding(UTF-8)'; Link Here
38
print $cgi->header( -type => 'text/plain', -charset => 'UTF-8' );
38
print $cgi->header( -type => 'text/plain', -charset => 'UTF-8' );
39
39
40
my $id = $cgi->param('id');
40
my $id = $cgi->param('id');
41
my $action = $cgi->param('action') || q{};
41
my $op = $cgi->param('op') || q{};
42
my $notes = $cgi->param('notes');
42
my $notes = $cgi->param('notes');
43
43
44
my $ar = Koha::ArticleRequests->find($id);
44
my $ar = Koha::ArticleRequests->find($id);
45
45
46
if ($ar) {
46
if ($ar) {
47
    if ( $action eq 'cancel' ) {
47
    if ( $op eq 'cud-cancel' ) {
48
        $ar = $ar->cancel({ notes => $notes });
48
        $ar = $ar->cancel({ notes => $notes });
49
    }
49
    }
50
    elsif ( $action eq 'process' ) {
50
    elsif ( $op eq 'cud-process' ) {
51
        $ar = $ar->process();
51
        $ar = $ar->process();
52
    }
52
    }
53
    elsif ( $action eq 'pending' ) {
53
    elsif ( $op eq 'cud-pending' ) {
54
        $ar = $ar->set_pending();
54
        $ar = $ar->set_pending();
55
    }
55
    }
56
    elsif ( $action eq 'complete' ) {
56
    elsif ( $op eq 'cud-complete' ) {
57
        $ar = $ar->complete();
57
        $ar = $ar->complete();
58
    }
58
    }
59
    elsif ( $action eq 'update_branchcode' ) {
59
    elsif ( $op eq 'cud-update_library_id' ) {
60
        my $branchcode = $cgi->param('branchcode');
60
        my $branchcode = $cgi->param('library_id');
61
        $ar->branchcode( $branchcode ) if $branchcode;
61
        $ar->branchcode( $branchcode ) if $branchcode;
62
        $ar = $ar->store();
62
        $ar = $ar->store();
63
    }
63
    }
64
    elsif( $action eq 'update_urls' ) {
64
    elsif( $op eq 'cud-update_urls' ) {
65
        my $urls = $cgi->param('urls') // q{};
65
        my $urls = $cgi->param('urls') // q{};
66
        $ar->urls( $urls );
66
        $ar->urls( $urls );
67
        $ar = $ar->store();
67
        $ar = $ar->store();
68
    }
68
    }
69
    else { undef $ar; }
69
}
70
}
70
71
72
# FIXME do not return 200 if not success
71
print to_json( { success => $ar ? 1 : 0 } );
73
print to_json( { success => $ar ? 1 : 0 } );
72
- 

Return to bug 36084