Bugzilla – Attachment 183353 Details for
Bug 40172
Remove jQuery from js/fetch/http-client.js
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40172: Replace jQuery with vanilla JS in js/fetch/http-client.js
Bug-40172-Replace-jQuery-with-vanilla-JS-in-jsfetc.patch (text/plain), 2.73 KB, created by
Jonathan Druart
on 2025-06-18 20:54:19 UTC
(
hide
)
Description:
Bug 40172: Replace jQuery with vanilla JS in js/fetch/http-client.js
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-06-18 20:54:19 UTC
Size:
2.73 KB
patch
obsolete
>From 2b646fd21e06abad038909d12e65179c8071050a Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 16 Jun 2025 09:39:38 +0200 >Subject: [PATCH] Bug 40172: Replace jQuery with vanilla JS in > js/fetch/http-client.js > >So that we can reuse it from somewhere else. >The current need is to be able to reuse it from Cypress tests. > >Test plan: >Try to hit several places where APIClient is used: > * Syspref edition > * Translation of item type description (be aware of bug 40161) > * Delete of cover images > * checkin, renew from the checkout list > * etc. > >Note that this does not affect Vue components. >--- > .../prog/js/fetch/http-client.js | 40 +++++++++++++++---- > 1 file changed, 33 insertions(+), 7 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/fetch/http-client.js b/koha-tmpl/intranet-tmpl/prog/js/fetch/http-client.js >index 50dc09f6ca7..93194a164b5 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/fetch/http-client.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/fetch/http-client.js >@@ -1,16 +1,31 @@ >+function _ifDocumentAvailable(callback) { >+ if (typeof document !== "undefined" && document.getElementById) { >+ callback(); >+ } >+} >+ > class Dialog { > constructor(options = {}) {} > >+ _appendMessage(type, message) { >+ _ifDocumentAvailable(() => { >+ const messagesContainer = document.getElementById("messages"); >+ if (!messagesContainer) { >+ return; >+ } >+ >+ const htmlString = >+ `<div class="alert alert-${type}">%s</div>`.format(message); >+ messagesContainer.insertAdjacentHTML("beforeend", htmlString); >+ }); >+ } >+ > setMessage(message) { >- $("#messages").append( >- '<div class="alert alert-info">%s</div>'.format(message) >- ); >+ this._appendMessage("info", message); > } > > setError(error) { >- $("#messages").append( >- '<div class="alert alert-warning">%s</div>'.format(error) >- ); >+ this._appendMessage("warning", error); > } > } > >@@ -22,7 +37,18 @@ class HttpClient { > "Content-Type": "application/json;charset=utf-8", > "X-Requested-With": "XMLHttpRequest", > }; >- this.csrf_token = $('meta[name="csrf-token"]').attr("content"); >+ this.csrf_token = this._getCsrfToken(options); >+ } >+ >+ _getCsrfToken(options) { >+ let token = null; >+ _ifDocumentAvailable(() => { >+ const metaTag = document.querySelector('meta[name="csrf-token"]'); >+ if (metaTag) { >+ token = metaTag.getAttribute("content"); >+ } >+ }); >+ return token !== null ? token : options.csrfToken || null; > } > > async _fetchJSON( >-- >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 40172
:
183353
|
183361