Test major Koha Wiki changes or bug fixes here without fear of breaking the production wiki.
For the current Koha Wiki, visit https://wiki.koha-community.org .Update parts of the staff interface to use AJAX RFC
AJAX in the Staff Interface
NOTE: relevant patches are available at http://arwen.metavore.com/~jpw/ajaxcirc/.
Currently, in the svc/ directory and tagging tools, there are some cautious forays into using AJAX. However, many more areas of the staff (and possibly patron) interface could be improved using AJAX and well-structured web services.
Towards this end, LibLime has implemented an AJAX-enabled circulation screen and added click-to-edit for cells of existing values on the smart-rules page, for possible inclusion in 3.2.
Both of these use new web services.
AJAX Circulation uses /svc/checkouts:
- POST /svc/checkouts/ (with data, creates a new checkout)
- POST /svc/checkouts/<issueid> (renews or returns checkouts, based on POSTed data (POST returned=1 > /svc/checkouts/<issueid> returns a checkout, for example)
issueid is a new column on the issues and old_issues table that is a simple auto_increment integer. One feature of this webservice is that renewals and checkins can happen on multiple items at once, by doing, for example, POST /svc/checkouts/64|90|32 (where 64, 90 and 32 are the issues in question). This is perhaps not the REST-approved way to do it, but it was the least complex way of implementing required functionality.
The improved smart-rules page is somewhat simpler; POST key=<column from `issuingrules`>&value=<new value> > /svc/admin/issuingrules/<branch>;<categorycode>;<itemtype> updates a part of an issuing rule.
Both of these services are based on two new modules, C4::Output::JSONStream and C4::Service.
C4::Output::JSONStream implements a simple, HTML::Template-ish way of creating JSON objects:
my $response = new C4::Output::JSONStream;
$response->param( foo => 'blah' );
$response->output() == "{'foo':'blah'}";
C4::Service bundles this and some utility functions, to make creation of JSON-based webservices simple:
my ( $query, $response ) = C4::Service->init( circulation => 1 ) # Required permissions
my ( $borrowernumber ) = C4::Service->require_params( 'borrowernumber' ) # Returns 'borrowernumber' from the query if present, returns 400 Bad Request and an error message if not
C4::Service->return_error( 'impossible', 'too_many', blah => 'boo!' ); # Returns 400 Bad Request, and { 'type': 'impossible', 'error': 'too_many', 'blah': 'boo!' }
C4::Service->return_success( $response );
It also has a simple regex-based dispatch mechanism, and support for multiple responses (207 Multi-status).