Koha/koha-tmpl/intranet-tmpl/prog/js/fetch/system-preferences-api-client.js
Jonathan Druart 37a16e69c7
Bug 36374: Keep tidy files from 'fetch' directory
And tidy them

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
2024-04-29 15:19:33 +02:00

54 lines
1.8 KiB
JavaScript

/* keep tidy */
import HttpClient from "./http-client.js";
export class SysprefAPIClient extends HttpClient {
constructor() {
super({
baseURL: "/cgi-bin/koha/svc/config/systempreferences",
});
}
get sysprefs() {
return {
get: variable =>
this.get({
endpoint: "/?pref=" + variable,
}),
update: (variable, value) =>
this.post({
endpoint: "",
body: "pref_%s=%s".format(
encodeURIComponent(variable),
encodeURIComponent(value)
),
headers: {
"Content-Type":
"application/x-www-form-urlencoded;charset=utf-8",
},
}),
update_all: sysprefs =>
this.post({
endpoint: "",
body: Object.keys(sysprefs)
.map(variable =>
sysprefs[variable].length
? sysprefs[variable].map(value =>
"%s=%s".format(
variable,
encodeURIComponent(value)
)
)
: "%s=".format(variable)
)
.flat(Infinity)
.join("&"),
headers: {
"Content-Type":
"application/x-www-form-urlencoded;charset=utf-8",
},
}),
};
}
}
export default SysprefAPIClient;