Skip to content

Commit 1e2cc84

Browse files
committed
46577: Failed test: Delete news
1 parent e4dbb70 commit 1e2cc84

File tree

1 file changed

+98
-100
lines changed

1 file changed

+98
-100
lines changed
Lines changed: 98 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
"use strict";
21
/* global il, $ */
32

43
il = il || {};
54
il.repository = il.repository || {};
65

7-
il.repository.ui = (function(il, $) {
6+
il.repository.ui = (function (il, $) {
87
// All functions now have direct access to each other
98

109
const sendAsync = function (form, replace = null) {
@@ -19,39 +18,37 @@ il.repository.ui = (function(il, $) {
1918
credentials: 'same-origin',
2019
redirect: 'follow',
2120
referrerPolicy: 'same-origin',
22-
body: data
23-
}).then(response => {
24-
response.text().then(text => {
25-
if (replace) {
26-
// this keeps the dialog open (full replacement would close)
27-
const marker = "component";
28-
var $new_content = $("<div>" + text + "</div>");
29-
var $marked_new_content = $new_content.find("[data-replace-marker='" + marker + "']").first();
30-
if ($marked_new_content.length == 0) {
31-
// if marker does not come with the new content, we put the new content into the existing element
32-
$(replace).html(text);
33-
} else {
34-
35-
// get new id of the root and set it
36-
const tpl = document.createElement('template');
37-
tpl.innerHTML = text.trim();
38-
const id = tpl.content.firstElementChild?.id ?? null;
39-
if (id) {
40-
replace.id = id;
41-
}
42-
43-
// if marker is in new content, we replace the complete old node with the marker
44-
// with the new marked node
45-
$(replace).find("[data-replace-marker='" + marker + "']").first()
21+
body: data,
22+
}).then((response) => {
23+
response.text().then((text) => {
24+
if (replace) {
25+
// this keeps the dialog open (full replacement would close)
26+
const marker = 'component';
27+
const $new_content = $(`<div>${text}</div>`);
28+
const $marked_new_content = $new_content.find(`[data-replace-marker='${marker}']`).first();
29+
if ($marked_new_content.length == 0) {
30+
// if marker does not come with the new content, we put the new content into the existing element
31+
$(replace).html(text);
32+
} else {
33+
// get new id of the root and set it
34+
const tpl = document.createElement('template');
35+
tpl.innerHTML = text.trim();
36+
const id = tpl.content.firstElementChild?.id ?? null;
37+
if (id) {
38+
replace.id = id;
39+
}
40+
41+
// if marker is in new content, we replace the complete old node with the marker
42+
// with the new marked node
43+
$(replace).find(`[data-replace-marker='${marker}']`).first()
4644
.replaceWith($marked_new_content);
4745

48-
// append included script (which will not be part of the marked node
49-
$(replace).find("[data-replace-marker='" + marker + "']").first()
46+
// append included script (which will not be part of the marked node
47+
$(replace).find(`[data-replace-marker='${marker}']`).first()
5048
.after($new_content.find("[data-replace-marker='script']"));
51-
}
5249
}
5350
}
54-
);
51+
});
5552
});
5653
};
5754

@@ -61,20 +58,26 @@ il.repository.ui = (function(il, $) {
6158
const initModal = function (id) {
6259
const modal = document.getElementById(id);
6360
const buttons = modal.querySelectorAll('.modal-footer button');
64-
if (buttons.length >= 2) {
61+
62+
// remove "save" button that has been added by the ks modal component
63+
// since inputs have been added to the modal in getModalWithContent.
64+
// this standard button is missing features like sending async requests
65+
// and replacing the modal (which the adapter save button does)
66+
const form = modal.querySelector('form');
67+
if (form && buttons.length > 2) {
6568
const penultimate = buttons[buttons.length - 2];
6669
penultimate.remove();
6770
}
6871
modal.dataset.modalInitialised = '1';
6972
};
7073

71-
const init = function() {
74+
const init = function () {
7275
initForms();
7376
};
7477

75-
const submitModalForm = function(event, sentAsync) {
76-
const f = event.target.closest(".c-modal").querySelector(".modal-body").querySelector("form");
77-
const modal = f.closest(".c-modal");
78+
const submitModalForm = function (event, sentAsync) {
79+
const f = event.target.closest('.c-modal').querySelector('.modal-body').querySelector('form');
80+
const modal = f.closest('.c-modal');
7881
if (sentAsync) {
7982
sendAsync(f, modal);
8083
} else {
@@ -83,56 +86,56 @@ il.repository.ui = (function(il, $) {
8386
};
8487

8588
return {
86-
init: init,
87-
submitModalForm: submitModalForm,
88-
initModal: initModal,
89+
init,
90+
submitModalForm,
91+
initModal,
8992
};
9093
}(il, $));
9194

92-
il.repository.core = (function() {
95+
il.repository.core = (function () {
9396
let httpPath = '';
9497

95-
const init = function(path) {
98+
const init = function (path) {
9699
httpPath = path;
97100
};
98101

99102
// set inner html and execute script tags
100103
function setInnerHTML(el, html) {
101104
el.innerHTML = html;
102105

103-
Array.from(el.querySelectorAll("script"))
104-
.forEach( oldScriptEl => {
105-
const newScriptEl = document.createElement("script");
106+
Array.from(el.querySelectorAll('script'))
107+
.forEach((oldScriptEl) => {
108+
const newScriptEl = document.createElement('script');
106109

107-
Array.from(oldScriptEl.attributes).forEach( attr => {
108-
newScriptEl.setAttribute(attr.name, attr.value)
109-
});
110+
Array.from(oldScriptEl.attributes).forEach((attr) => {
111+
newScriptEl.setAttribute(attr.name, attr.value);
112+
});
110113

111-
const scriptText = document.createTextNode(oldScriptEl.innerHTML);
112-
newScriptEl.appendChild(scriptText);
114+
const scriptText = document.createTextNode(oldScriptEl.innerHTML);
115+
newScriptEl.appendChild(scriptText);
113116

114-
oldScriptEl.parentNode.replaceChild(newScriptEl, oldScriptEl);
115-
});
117+
oldScriptEl.parentNode.replaceChild(newScriptEl, oldScriptEl);
118+
});
116119
}
117120

118121
function setOuterHTML(el_id, html) {
119122
let el = document.getElementById(el_id);
120123
el.outerHTML = html;
121124
el = document.getElementById(el_id);
122125

123-
Array.from(el.querySelectorAll("script"))
124-
.forEach( oldScriptEl => {
125-
const newScriptEl = document.createElement("script");
126+
Array.from(el.querySelectorAll('script'))
127+
.forEach((oldScriptEl) => {
128+
const newScriptEl = document.createElement('script');
126129

127-
Array.from(oldScriptEl.attributes).forEach( attr => {
128-
newScriptEl.setAttribute(attr.name, attr.value)
129-
});
130+
Array.from(oldScriptEl.attributes).forEach((attr) => {
131+
newScriptEl.setAttribute(attr.name, attr.value);
132+
});
130133

131-
const scriptText = document.createTextNode(oldScriptEl.innerHTML);
132-
newScriptEl.appendChild(scriptText);
134+
const scriptText = document.createTextNode(oldScriptEl.innerHTML);
135+
newScriptEl.appendChild(scriptText);
133136

134-
oldScriptEl.parentNode.replaceChild(newScriptEl, oldScriptEl);
135-
});
137+
oldScriptEl.parentNode.replaceChild(newScriptEl, oldScriptEl);
138+
});
136139
}
137140

138141
function trigger(name, el = null, details = null) {
@@ -149,11 +152,10 @@ il.repository.core = (function() {
149152
}
150153

151154
function fetchJson(url = '', params = {}) {
152-
153-
let fetch_url = getFetchUrl(url);
154-
let url_params = new URLSearchParams(fetch_url.search.slice(1));
155+
const fetch_url = getFetchUrl(url);
156+
const url_params = new URLSearchParams(fetch_url.search.slice(1));
155157
for (const [key, value] of Object.entries(params)) {
156-
url_params.append(key, value)
158+
url_params.append(key, value);
157159
}
158160
fetch_url.search = url_params;
159161

@@ -163,10 +165,10 @@ il.repository.core = (function() {
163165
cache: 'no-cache',
164166
credentials: 'same-origin',
165167
headers: {
166-
'Content-Type': 'application/json'
168+
'Content-Type': 'application/json',
167169
},
168170
redirect: 'follow',
169-
referrerPolicy: 'same-origin'
171+
referrerPolicy: 'same-origin',
170172
});
171173
}
172174

@@ -180,15 +182,15 @@ il.repository.core = (function() {
180182
fetch_url = new URL(url);
181183
} catch (error) {
182184
// relative paths
183-
fetch_url = new URL(httpPath + "/" + url);
185+
fetch_url = new URL(`${httpPath}/${url}`);
184186
}
185187
return fetch_url;
186188
}
187189

188190
function fetchHtml(url = '', params = {}, post = false) {
189-
let fetch_url = getFetchUrl(url);
191+
const fetch_url = getFetchUrl(url);
190192
let formData;
191-
let url_params = new URLSearchParams(fetch_url.search.slice(1));
193+
const url_params = new URLSearchParams(fetch_url.search.slice(1));
192194
if (!post) {
193195
for (const [key, value] of Object.entries(params)) {
194196
url_params.append(key, value);
@@ -201,25 +203,23 @@ il.repository.core = (function() {
201203
}
202204
fetch_url.search = url_params;
203205

204-
const method = (post) ? "POST" : "GET" ;
205-
let config = {
206-
method: method,
206+
const method = (post) ? 'POST' : 'GET';
207+
const config = {
208+
method,
207209
mode: 'same-origin',
208210
cache: 'no-cache',
209211
credentials: 'same-origin',
210212
redirect: 'follow',
211-
referrerPolicy: 'same-origin'
213+
referrerPolicy: 'same-origin',
212214
};
213215
if (post) {
214216
config.body = formData;
215217
}
216218
return new Promise((resolve, reject) => {
217-
fetch(fetch_url.href, config).then(response => {
219+
fetch(fetch_url.href, config).then((response) => {
218220
if (response.ok) {
219-
//const statusText = response.statusText;
220-
response.text().then(text =>
221-
resolve(text)
222-
).catch();
221+
// const statusText = response.statusText;
222+
response.text().then((text) => resolve(text)).catch();
223223
}
224224
}).catch();
225225
});
@@ -237,51 +237,49 @@ il.repository.core = (function() {
237237

238238
function fetchReplace(el_id, url = '', params = {}) {
239239
fetchHtml(url, params)
240-
.then(html => {
241-
setOuterHTML(el_id, html)
242-
}).catch();
240+
.then((html) => {
241+
setOuterHTML(el_id, html);
242+
}).catch();
243243
}
244244

245245
function fetchUrl(url = '', params = {}, args = {}, success_cb = null) {
246-
let fetch_url = getFetchUrl(url);
247-
let url_params = new URLSearchParams(fetch_url.search.slice(1));
246+
const fetch_url = getFetchUrl(url);
247+
const url_params = new URLSearchParams(fetch_url.search.slice(1));
248248
for (const [key, value] of Object.entries(params)) {
249249
url_params.append(key, value);
250250
}
251251
fetch_url.search = url_params;
252-
let config = {
252+
const config = {
253253
method: 'GET',
254254
mode: 'same-origin',
255255
cache: 'no-cache',
256256
credentials: 'same-origin',
257257
redirect: 'follow',
258258
referrerPolicy: 'same-origin',
259259
};
260-
fetch(fetch_url.href, config).then(response => {
260+
fetch(fetch_url.href, config).then((response) => {
261261
if (response.ok) {
262-
//const statusText = response.statusText;
263-
response.text().then(text => {
262+
// const statusText = response.statusText;
263+
response.text().then((text) => {
264264
if (success_cb) {
265265
success_cb({
266-
text: text,
267-
args: args,
266+
text,
267+
args,
268268
});
269269
}
270-
},
271-
).catch();
270+
}).catch();
272271
}
273272
}).catch();
274273
}
275274

276275
return {
277-
setInnerHTML: setInnerHTML,
278-
setOuterHTML: setOuterHTML,
279-
fetchHtml: fetchHtml,
280-
fetchUrl: fetchUrl,
281-
fetchReplace: fetchReplace,
282-
fetchReplaceInner: fetchReplaceInner,
283-
trigger: trigger,
284-
init: init
276+
setInnerHTML,
277+
setOuterHTML,
278+
fetchHtml,
279+
fetchUrl,
280+
fetchReplace,
281+
fetchReplaceInner,
282+
trigger,
283+
init,
285284
};
286-
287285
}());

0 commit comments

Comments
 (0)