Bug 36084: svc - authorised_values - APIClient now global
APIClient is not a global variable, which will make the next changes much easier! Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
8b1871f5cf
commit
40cfd29b83
6 changed files with 42 additions and 20 deletions
|
@ -29,6 +29,10 @@
|
|||
[% Asset.css("css/print.css", { media = "print" }) | $raw %]
|
||||
[% INCLUDE intranetstylesheet.inc %]
|
||||
[% IF ( bidi ) %][% Asset.css("css/right-to-left.css") | $raw %][% END %]
|
||||
<script type="module">
|
||||
import { APIClient } from '/intranet-tmpl/prog/js/fetch/api-client.js';
|
||||
window.APIClient = APIClient;
|
||||
</script>
|
||||
|
||||
<script>
|
||||
var Koha = {};
|
||||
|
|
|
@ -689,11 +689,6 @@
|
|||
HandleMulti(Cancel, $(this).data('ar-id'), $(this));
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<script async type="module">
|
||||
import { APIClient } from '/intranet-tmpl/prog/js/fetch/api-client.js';
|
||||
|
||||
async function Process( id, a ) {
|
||||
var table_row = a.closest('tr');
|
||||
var table = a.closest('table');
|
||||
|
|
|
@ -415,10 +415,7 @@
|
|||
$('#format option[value="'+first_format+'"]').attr('selected', true);
|
||||
}
|
||||
});
|
||||
</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 ));
|
||||
|
|
|
@ -625,24 +625,18 @@ $(document).ready(function() {
|
|||
var description = form.description.value;
|
||||
var opac_description = form.opac_description.value;
|
||||
|
||||
var data = "category="+encodeURIComponent(category)
|
||||
+"&value="+encodeURIComponent(value)
|
||||
+"&description="+encodeURIComponent(description)
|
||||
+"&opac_description="+encodeURIComponent(opac_description);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/cgi-bin/koha/svc/authorised_values",
|
||||
data: data,
|
||||
success: function(response) {
|
||||
const client = APIClient.authorised_value;
|
||||
client.values.create({category, value, description, opac_description}).then(
|
||||
success => {
|
||||
$('#avCreate').modal('hide');
|
||||
|
||||
$(current_select2).append('<option selected value="'+response.value+'">'+response.description+'</option>');
|
||||
$(current_select2).append('<option selected value="'+success.value+'">'+success.description+'</option>');
|
||||
$("#avCreate").modal("hide");
|
||||
},
|
||||
error: function() {
|
||||
error => {
|
||||
$(".avCreate_error").html(__("Something went wrong. Maybe the value already exists?")).show();
|
||||
}
|
||||
});
|
||||
);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import ArticleRequestAPIClient from "./article-request-api-client.js";
|
||||
import AVAPIClient from "./authorised-value-api-client.js";
|
||||
|
||||
export const APIClient = {
|
||||
article_request: new ArticleRequestAPIClient(),
|
||||
authorised_value: new AVAPIClient(),
|
||||
};
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
import HttpClient from "./http-client.js";
|
||||
|
||||
export class AVAPIClient extends HttpClient {
|
||||
constructor() {
|
||||
super({
|
||||
baseURL: "/cgi-bin/koha/svc/authorised_values",
|
||||
headers: {
|
||||
"Content-Type":
|
||||
"application/x-www-form-urlencoded;charset=utf-8",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
get values() {
|
||||
return {
|
||||
create: value =>
|
||||
this.post({
|
||||
endpoint: "",
|
||||
body: "category=%s&value=%s&description=%s&opac_description=%s".format(
|
||||
encodeURIComponent(value.category),
|
||||
encodeURIComponent(value.value),
|
||||
encodeURIComponent(value.description),
|
||||
encodeURIComponent(value.opac_description),
|
||||
),
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default AVAPIClient;
|
Loading…
Reference in a new issue