Bugzilla – Attachment 162109 Details for
Bug 36084
Pass CSRF token to SVC scripts (1/2)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36084: svc - article_request - POC
Bug-36084-svc---articlerequest---POC.patch (text/plain), 17.01 KB, created by
Jonathan Druart
on 2024-02-13 14:25:07 UTC
(
hide
)
Description:
Bug 36084: svc - article_request - POC
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2024-02-13 14:25:07 UTC
Size:
17.01 KB
patch
obsolete
>From 946176376a2dce973693ca9e71dd8435aca4f3c8 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 12 Feb 2024 16:32:40 +0100 >Subject: [PATCH] Bug 36084: svc - article_request - POC > >This is a proof of concept >--- > .../prog/en/modules/circ/article-requests.tt | 158 ++++++++++-------- > .../prog/en/modules/circ/request-article.tt | 54 +++--- > svc/article_request | 18 +- > 3 files changed, 130 insertions(+), 100 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/article-requests.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/article-requests.tt >index 9b30551f97e..5b66241152e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/article-requests.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/article-requests.tt >@@ -26,40 +26,40 @@ > > <ul class="dropdown-menu [% pull_right | html %]" role="menu" aria-labelledby="[% aria_menu | html %]"> > <li> >- <a class="ar-set-pending-request" href="#" onclick="HandleMulti( SetPending, [% id_arg | html %], $(this) ); return false;"> >+ <a class="ar-set-pending-request" href="#"> > <i class="fa fa-bars"></i> > Set request as pending > </a> > >- <a class="ar-process-request" href="#" onclick="HandleMulti( Process, [% id_arg | html %], $(this) ); return false;"> >+ <a class="ar-process-request" data-ar-id="[% id_arg | uri %]" href="#"> > <i class="fa fa-cog"></i> > Process request > </a> > > [% IF id_arg && format=='SCAN' %] >- <a class="ar-edit-urls" href="#" onclick="HandleMulti( EditURLs, [% id_arg | html %], $(this) ); return false;"> >+ <a class="ar-edit-urls" href="#" data-ar-id="[% id_arg | uri %]" href="#"> > <i class="fa-solid fa-pencil" aria-hidden="true"></i> > Edit URLs > </a> > [% END %] > >- <a class="ar-complete-request" href="#" onclick="HandleMulti( Complete, [% id_arg | html %], $(this) ); return false;"> >+ <a class="ar-complete-request" href="#" data-ar-id="[% id_arg | uri %]" href="#"> > <i class="fa fa-check-circle"></i> > Complete request > </a> > >- <a class="ar-cancel-request" href="#" onclick="Cancel( [% id_arg | html %], $(this) ); return false;"> >+ <a class="ar-cancel-request" href="#" data-ar-id="[% id_arg | uri %]" href="#"> > <i class="fa fa-minus-circle"></i> > Cancel request > </a> > > [% IF id_arg %] >- <a class="ar-print-request" href="#" onclick="HandleMulti( PrintSlip, [% id_arg | html %], $(this) ); return false;"> >+ <a class="ar-print-request" href="#" data-ar-id="[% id_arg | uri %]" href="#"> > <i class="fa fa-print"></i> > Print slip > </a> > [% ELSE %] >- <a class="ar-print-request" href="#" onclick="PrintMultipleSlip(); return false;"> >+ <a class="ar-print-multiple-requests" href="#"> > <i class="fa fa-print"></i> > Print slip > </a> >@@ -577,9 +577,6 @@ > var link = $('span#url_'+ id).parent().parent().find('td.ar-actions').find('div.dropdown a'); > if( link.length > 0 ) link[0].focus(); > }); >- $( '#myModal button' ).on("click", function () { >- SaveURLs( $('#myModal textarea').val() ); >- }); > > requested_datatable = $("#article-requests-requested-table").DataTable($.extend(true, {}, dataTablesDefaults, { > "columnDefs": [ >@@ -630,6 +627,10 @@ > var link = 'article-request-slip.pl?id='+id; > window.open(link, 'popup', 'width=600,height=400,resizable=1,toolbar=0,scrollbars=1,top'); > } >+ $(".ar-print-request").on("click", function (e){ >+ e.preventDefault(); >+ HandleMulti(PrintSlip, $(this).data('ar-id')); >+ }); > > $('#modal-cancellation-reason').on('change', function(e) { > let reason = $(this).val(); >@@ -671,8 +672,11 @@ > }); > var link = 'article-request-slip.pl?multi=1&id='+ids.join(','); > window.open(link, 'popup', 'width=600,height=400,resizable=1,toolbar=0,scrollbars=1,top'); >- > } >+ $(".ar-print-multiple-requests").on("click", function (e){ >+ e.preventDefault(); >+ PrintMultipleSlip(); >+ }); > > function Cancel( id, a ) { > cancel_id = id; >@@ -680,57 +684,45 @@ > > $('#cancelModal').modal(); > } >+ $(".ar-cancel-request").on("click", function (e){ >+ e.preventDefault(); >+ HandleMulti(Cancel, $(this).data('ar-id'), $(this)); >+ }); > >- function SetPending( id, a ) { >- var table_row = a.closest('tr'); >- table_row.find('.ar-set-pending-request').remove(); >- table_row.find('input[type="checkbox"]').prop('checked', false); >- a.closest('td').prepend('<img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" class="spinner"/>').find('div.dropdown').hide(); >- $.ajax({ >- type: "POST", >- url: '/cgi-bin/koha/svc/article_request', >- data: { >- action: 'pending', >- id: id, >- }, >- success: function( data ) { >- $("img.spinner").remove(); >- requested_datatable.row( table_row ).remove().draw(); >- pending_datatable.row.add( table_row ).draw(); >- UpdateTabCounts(); >- activateBatchActions( active_tab ); >- }, >- dataType: 'json' >- }); >- } >+ </script> >+ >+ <script async type="module"> >+ import { APIClient } from '/intranet-tmpl/prog/js/fetch/api-client.js'; > >- function Process( id, a ) { >+ async function Process( id, a ) { > var table_row = a.closest('tr'); > var table = a.closest('table'); > var orig_datatable = table.attr('id')==='article-requests-pending-table'?pending_datatable:requested_datatable; >- table_row.find('.ar-process-request').remove(); >- table_row.find('input[type="checkbox"]').prop('checked', false); > > a.closest('td').prepend('<img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" class="spinner"/>').find('div.dropdown').hide(); >- $.ajax({ >- type: "POST", >- url: '/cgi-bin/koha/svc/article_request', >- data: { >- action: 'process', >- id: id, >- }, >- success: function( data ) { >+ >+ const client = APIClient.article_request; >+ await client.articleRequests.process(id).then( >+ success => { > $("img.spinner").remove(); >+ table_row.find('.ar-process-request').remove(); >+ table_row.find('input[type="checkbox"]').prop('checked', false); > orig_datatable.row( table_row ).remove().draw(); > processing_datatable.row.add( table_row ).draw(); > UpdateTabCounts(); > activateBatchActions( active_tab ); > }, >- dataType: 'json' >- }); >+ error => { >+ console.warn("Something wrong happened: %s".format(error)); >+ } >+ ); > } >+ $(".ar-process-request").on("click", function (e){ >+ e.preventDefault(); >+ HandleMulti(Process, $(this).data('ar-id'), $(this)); >+ }); > >- function Complete( id, a ) { >+ async function Complete( id, a ) { > // if it is a scan, check if urls field is filled > var urlspan = $('span#url_'+id); > if( urlspan.length>0 && urlspan.text() === '' ) { >@@ -738,21 +730,47 @@ > return; > } > a.closest('td').prepend('<img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif"/>').find('div.dropdown').hide(); >- $.ajax({ >- type: "POST", >- url: '/cgi-bin/koha/svc/article_request', >- data: { >- action: 'complete', >- id: id, >- }, >- success: function( data ) { >+ const client = APIClient.article_request; >+ await client.articleRequests.complete(id).then( >+ success => { >+ $("img.spinner").remove(); > active_datatable.row( a.closest('tr') ).remove().draw(); > UpdateTabCounts(); > activateBatchActions( active_tab ); > }, >- dataType: 'json' >- }); >+ error => { >+ console.warn("Something wrong happened: %s".format(error)); >+ } >+ ); > } >+ $(".ar-complete-request").on("click", function (e){ >+ e.preventDefault(); >+ HandleMulti(Complete, $(this).data('ar-id'), $(this)); >+ }); >+ >+ async function SetPending( id, a ) { >+ var table_row = a.closest('tr'); >+ table_row.find('.ar-set-pending-request').remove(); >+ table_row.find('input[type="checkbox"]').prop('checked', false); >+ a.closest('td').prepend('<img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" class="spinner"/>').find('div.dropdown').hide(); >+ const client = APIClient.article_request; >+ await client.articleRequests.pending(id).then( >+ success => { >+ $("img.spinner").remove(); >+ requested_datatable.row( table_row ).remove().draw(); >+ pending_datatable.row.add( table_row ).draw(); >+ UpdateTabCounts(); >+ activateBatchActions( active_tab ); >+ }, >+ error => { >+ console.warn("Something wrong happened: %s".format(error)); >+ } >+ ); >+ } >+ $(".ar-set-pending-request").on("click", function (e){ >+ e.preventDefault(); >+ HandleMulti(SetPending, $(this).data('ar-id'), $(this)); >+ }); > > function UpdateTabCounts() { > $("#ar_requested_count").html( requested_datatable.rows().count() ); >@@ -766,8 +784,12 @@ > $('#myModal textarea').attr('ar_id', id); > $('#myModal').modal('show'); > } >+ $(".ar-edit-urls").on("click", function (e){ >+ e.preventDefault(); >+ HandleMulti(EditURLs, $(this).data('ar-id')); >+ }); > >- function SaveURLs(newurl) { >+ async function SaveURLs(newurl) { > var id = $('#myModal textarea').attr('ar_id'); > $('span#url_'+ id).text(newurl); > if(newurl) >@@ -775,15 +797,19 @@ > else > $('span#url_yesno_'+id).text(_("No")); > >- $.ajax({ >- type: "POST", >- url: '/cgi-bin/koha/svc/article_request', >- data: { action: 'update_urls', id: id, urls: newurl }, >- dataType: 'json', >- error: function() { alert('Error: Saving URL failed!'); }, >- success: function(data) { if(!data.success) alert('Saving URL failed!'); }, >- }); >+ const client = APIClient.article_request; >+ await client.articleRequests.update_urls(id, newurl).then( >+ success => { >+ }, >+ error => { >+ console.warn("Something wrong happened: %s".format(error)); >+ } >+ ); > } >+ $( '#myModal button' ).on("click", function () { >+ SaveURLs( $('#myModal textarea').val() ); >+ }); >+ > </script> > [% END %] > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt >index f92d2ad0359..4295e07a7d6 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt >@@ -370,32 +370,7 @@ > > $( ".ar-update-branchcode" ).on('focus', function(){ > previous_branchcode = this.value; >- }).on('change', function(){ >- var branchcode = this.value; >- var c = confirm(_("Are you sure you want to change the pickup library from %s to %s for this request?").format( previous_branchcode, branchcode )); >- >- if ( c ) { >- var id = this.id.split("branchcode-")[1]; >- $("#update-processing-" + id ).css({opacity: 0, visibility: "visible"}).animate({opacity: 1.0}, 200); >- >- $.ajax({ >- type: "POST", >- url: '/cgi-bin/koha/svc/article_request', >- data: { >- action: 'update_branchcode', >- id: id, >- branchcode: branchcode, >- }, >- success: function( data ) { >- $("#update-processing-" + id ).css({opacity: 1.0, visibility: "visible"}).animate({opacity: 0}, 200); >- }, >- dataType: 'json' >- }); >- >- } else { >- this.value = previous_branchcode; >- } >- }); >+ }) > > $('#modal-cancellation-reason').on('change', function(e) { > let reason = $(this).val(); >@@ -442,6 +417,33 @@ > }); > </script> > >+ <script async type="module"> >+ import { APIClient } from '/intranet-tmpl/prog/js/fetch/api-client.js'; >+ $(".ar-update-branchcode").on('change', async function(e){ >+ var branchcode = this.value; >+ var c = confirm(_("Are you sure you want to change the pickup library from %s to %s for this request?").format( previous_branchcode, branchcode )); >+ >+ if ( c ) { >+ var id = this.id.split("branchcode-")[1]; >+ $("#update-processing-" + id ).css({opacity: 0, visibility: "visible"}).animate({opacity: 1.0}, 200); >+ >+ const client = APIClient.article_request; >+ await client.articleRequests.update_library_id(id, branchcode).then( >+ success => { >+ $("#update-processing-" + id ).css({opacity: 1.0, visibility: "visible"}).animate({opacity: 0}, 200); >+ }, >+ error => { >+ console.warn("Something wrong happened: %s", error); >+ } >+ ); >+ >+ >+ } else { >+ this.value = previous_branchcode; >+ } >+ }); >+ </script> >+ > [% 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 %] > > [% END %] >diff --git a/svc/article_request b/svc/article_request >index 28db40d42db..3760ae074df 100755 >--- a/svc/article_request >+++ b/svc/article_request >@@ -38,34 +38,36 @@ binmode STDOUT, ':encoding(UTF-8)'; > print $cgi->header( -type => 'text/plain', -charset => 'UTF-8' ); > > my $id = $cgi->param('id'); >-my $action = $cgi->param('action') || q{}; >+my $op = $cgi->param('op') || q{}; > my $notes = $cgi->param('notes'); > > my $ar = Koha::ArticleRequests->find($id); > > if ($ar) { >- if ( $action eq 'cancel' ) { >+ if ( $op eq 'cud-cancel' ) { > $ar = $ar->cancel({ notes => $notes }); > } >- elsif ( $action eq 'process' ) { >+ elsif ( $op eq 'cud-process' ) { > $ar = $ar->process(); > } >- elsif ( $action eq 'pending' ) { >+ elsif ( $op eq 'cud-pending' ) { > $ar = $ar->set_pending(); > } >- elsif ( $action eq 'complete' ) { >+ elsif ( $op eq 'cud-complete' ) { > $ar = $ar->complete(); > } >- elsif ( $action eq 'update_branchcode' ) { >- my $branchcode = $cgi->param('branchcode'); >+ elsif ( $op eq 'cud-update_library_id' ) { >+ my $branchcode = $cgi->param('library_id'); > $ar->branchcode( $branchcode ) if $branchcode; > $ar = $ar->store(); > } >- elsif( $action eq 'update_urls' ) { >+ elsif( $op eq 'cud-update_urls' ) { > my $urls = $cgi->param('urls') // q{}; > $ar->urls( $urls ); > $ar = $ar->store(); > } >+ else { undef $ar; } > } > >+# FIXME do not return 200 if not success > print to_json( { success => $ar ? 1 : 0 } ); >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36084
:
162108
|
162109
|
162110
|
162111
|
162112
|
162133
|
162147
|
162150
|
162712