@aarhus-university/au-lib-react-components 10.0.2 → 10.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/umd/all.css +2 -2
- package/build/umd/all.js +1 -1
- package/build/umd/alphabox.js +1 -1
- package/build/umd/databox.js +1 -1
- package/build/umd/diagramme.js +1 -1
- package/build/umd/flowbox.js +1 -1
- package/build/umd/universe.js +1 -1
- package/package.json +6 -6
- package/src/components/AUAutoSuggestComponent.js +158 -158
- package/src/components/AUSpinnerComponent.tsx +91 -67
- package/src/components/AUToastComponent.tsx +11 -12
- package/src/components/profile/AUProfileLoginComponent.tsx +26 -26
- package/src/layout-2016/components/alphabox/AlphaBoxComponent.js +143 -143
- package/src/layout-2016/components/alphabox/AlphaBoxContentComponent.js +136 -136
- package/src/layout-2016/components/common/AUCollapsibleComponent.js +152 -152
- package/src/layout-2016/components/common/AUSpinnerComponent.js +103 -103
- package/src/layout-2016/components/databox/DataBoxAlphabetComponent.js +144 -144
- package/src/layout-2016/components/databox/DataBoxAssociationComponent.js +122 -122
- package/src/layout-2016/components/databox/DataBoxButtonComponent.js +157 -157
- package/src/layout-2016/components/databox/DataBoxComponent.js +297 -297
- package/src/layout-2016/components/databox/DataBoxGroupingComponent.js +64 -64
- package/src/layout-2016/components/databox/DataBoxSearchResultComponent.js +36 -36
- package/src/layout-2016/components/databox/DataBoxStackedAssociationComponent.js +54 -54
- package/src/layout-2016/components/databox/DataBoxSuggestionComponent.js +39 -39
- package/src/layout-2016/components/diagramme/AUDiagrammeComponent.js +309 -309
- package/src/layout-2016/components/flowbox/FlowBoxComponent.js +126 -126
- package/src/layout-2016/components/flowbox/FlowBoxPhoneComponent.js +104 -104
- package/src/layout-2016/components/profile/AUProfileAvatar2016Component.js +103 -103
- package/src/layout-2016/components/universe/StaffTopComponent.js +363 -363
- package/src/layout-2016/components/universe/StudentTopComponent.js +137 -137
- package/src/layout-2016/components/universe/UniverseContainerComponent.js +65 -65
- package/src/layout-2016/lib/all.js +3 -3
- package/src/layout-2016/lib/au-alphabox.js +100 -100
- package/src/layout-2016/lib/au-databox.js +400 -400
- package/src/layout-2016/lib/au-diagramme.js +85 -85
- package/src/layout-2016/lib/au-flowbox.js +93 -93
- package/src/layout-2016/lib/universe.js +9 -9
- package/src/lib/helpers.ts +194 -194
- package/tsconfig.json +46 -46
- package/types/common/interfaces/gui.d.ts +1 -0
- package/types/common/interfaces/model.d.ts +29 -29
- package/types/common/props.d.ts +166 -165
- package/webpack.config.js +89 -89
|
@@ -1,400 +1,400 @@
|
|
|
1
|
-
/* eslint func-names: ["error", "never"] */
|
|
2
|
-
/* eslint no-prototype-builtins: 0 */
|
|
3
|
-
/* eslint no-restricted-syntax: 0 */
|
|
4
|
-
/* eslint max-classes-per-file: 0 */
|
|
5
|
-
/* eslint no-unused-vars: 0 */
|
|
6
|
-
/* eslint-env browser */
|
|
7
|
-
import React from 'react';
|
|
8
|
-
import ReactDOM from 'react-dom';
|
|
9
|
-
import DataBoxComponent from '../components/databox/DataBoxComponent';
|
|
10
|
-
|
|
11
|
-
const defaultOptions = {
|
|
12
|
-
config: {
|
|
13
|
-
container: '.au_databox', // DOM-element
|
|
14
|
-
firstline: true, // skal søgefeltet stå på en række for sig selv?
|
|
15
|
-
alphabet: 2, // hvilken knap er alfabetet?
|
|
16
|
-
initLetter: 'a', // Startbogstavet for alfabetet
|
|
17
|
-
trigger: 0,
|
|
18
|
-
tracking: '/virtual/databox/', // GA-tracking
|
|
19
|
-
buttons: [ // Teksten på knapperne - nyt!
|
|
20
|
-
{ text: 'Dummy knap 1', link: '' },
|
|
21
|
-
{ text: 'Dummy knap 2', link: '' },
|
|
22
|
-
],
|
|
23
|
-
stacked: false,
|
|
24
|
-
rememberState: false,
|
|
25
|
-
expand: false,
|
|
26
|
-
},
|
|
27
|
-
background: {
|
|
28
|
-
color: '#003d73',
|
|
29
|
-
linkColor: '#003d73',
|
|
30
|
-
src: '',
|
|
31
|
-
height: 0,
|
|
32
|
-
text: '',
|
|
33
|
-
overlay: true,
|
|
34
|
-
},
|
|
35
|
-
search: {
|
|
36
|
-
autocomplete: true,
|
|
37
|
-
index: 1,
|
|
38
|
-
minLength: 1,
|
|
39
|
-
placeHolder: '',
|
|
40
|
-
},
|
|
41
|
-
data: {
|
|
42
|
-
mode: 'json',
|
|
43
|
-
source: '',
|
|
44
|
-
callback: null,
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
class AUDataboxParser {
|
|
49
|
-
static json(source, callback) {
|
|
50
|
-
if (source) {
|
|
51
|
-
let sourceArr = [];
|
|
52
|
-
if (!Array.isArray(source)) {
|
|
53
|
-
sourceArr.push(source);
|
|
54
|
-
} else {
|
|
55
|
-
sourceArr = source;
|
|
56
|
-
}
|
|
57
|
-
const promises = [];
|
|
58
|
-
sourceArr.forEach((s) => {
|
|
59
|
-
promises.push(new Promise((resolve) => {
|
|
60
|
-
fetch(s).then((promise) => promise.json()).then((data) => {
|
|
61
|
-
resolve(data);
|
|
62
|
-
});
|
|
63
|
-
}));
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
Promise.all(promises).then((values) => {
|
|
67
|
-
callback({
|
|
68
|
-
items: values.map((x) => x.items)[0],
|
|
69
|
-
groupings: values.map((x) => x.groupings)[0] || [],
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
static xml(source, callback) {
|
|
76
|
-
const xmlFunc = (data) => {
|
|
77
|
-
const items = [];
|
|
78
|
-
const children = [];
|
|
79
|
-
const associations = [];
|
|
80
|
-
|
|
81
|
-
let assocXML = [];
|
|
82
|
-
let count = 1;
|
|
83
|
-
|
|
84
|
-
do {
|
|
85
|
-
assocXML = $(data).find(`associations${count} > item`);
|
|
86
|
-
|
|
87
|
-
const assoc = [];
|
|
88
|
-
for (let i = 0; i < assocXML.length; i += 1) {
|
|
89
|
-
assoc.push({
|
|
90
|
-
id: $(assocXML[i]).attr('id'),
|
|
91
|
-
name: $(assocXML[i]).attr('name'),
|
|
92
|
-
items: [],
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (assoc.length > 0) {
|
|
97
|
-
associations.push(assoc);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
count += 1;
|
|
101
|
-
} while (assocXML.length > 0);
|
|
102
|
-
|
|
103
|
-
const itemsXML = $(data).find('items > item');
|
|
104
|
-
$.each(itemsXML, function () {
|
|
105
|
-
const extraXML = $(this).find('extra');
|
|
106
|
-
const extra = [];
|
|
107
|
-
$.each(extraXML.find('param'), () => {
|
|
108
|
-
extra.push({
|
|
109
|
-
param: $(this).text(),
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
const obj = {
|
|
113
|
-
id: $(this).attr('id'),
|
|
114
|
-
name: $(this).attr('name'),
|
|
115
|
-
url: $(this).attr('url'),
|
|
116
|
-
parent: $(this).attr('parent'),
|
|
117
|
-
extra,
|
|
118
|
-
children: [],
|
|
119
|
-
associations: [],
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
for (let i = 0; i < associations.length; i += 1) {
|
|
123
|
-
const objAssoc = $(this).find(`association${parseInt(i + 1, 10)}`);
|
|
124
|
-
|
|
125
|
-
obj.associations.push([]);
|
|
126
|
-
|
|
127
|
-
for (let j = 0; j < objAssoc.length; j += 1) {
|
|
128
|
-
const id = parseInt($(objAssoc[j]).attr('id'), 10) - 1;
|
|
129
|
-
obj.associations[i].push({
|
|
130
|
-
id: associations[i][id].id,
|
|
131
|
-
name: associations[i][id].name,
|
|
132
|
-
});
|
|
133
|
-
associations[i][id].items.push(obj);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
items.push(obj);
|
|
138
|
-
if (typeof obj.parent !== 'undefined' && obj.parent !== '') {
|
|
139
|
-
children.push(obj);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
for (let c = 0; c < children.length; c += 1) {
|
|
144
|
-
const pid = children[c].parent;
|
|
145
|
-
for (let p = 0; p < items.length; p += 1) {
|
|
146
|
-
if (items[p].id === pid) {
|
|
147
|
-
items[p].children.push(children[c]);
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const groupings = [];
|
|
154
|
-
for (let i = 0; i < associations.length; i += 1) {
|
|
155
|
-
groupings.push({
|
|
156
|
-
id: i,
|
|
157
|
-
associations: associations[i],
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
callback({
|
|
162
|
-
rawData: data,
|
|
163
|
-
items,
|
|
164
|
-
groupings,
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
AU.helpers.getXML(source, (data) => {
|
|
169
|
-
xmlFunc(data);
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
static table(source, callback) {
|
|
174
|
-
const table = $(`${source} > table`);
|
|
175
|
-
const list = $(`${source} > ul`);
|
|
176
|
-
|
|
177
|
-
const items = [];
|
|
178
|
-
const children = [];
|
|
179
|
-
const associations = [];
|
|
180
|
-
|
|
181
|
-
$('li', list).each(function () {
|
|
182
|
-
const assoc = [];
|
|
183
|
-
$('> ul > li', this).each(function (i) {
|
|
184
|
-
assoc.push({
|
|
185
|
-
id: i,
|
|
186
|
-
name: $(this).text(),
|
|
187
|
-
items: [],
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
if (assoc.length > 0) {
|
|
192
|
-
associations.push(assoc);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
$('tr', table).each(function (i) {
|
|
197
|
-
if (i > 0) {
|
|
198
|
-
const cells = $('td', this);
|
|
199
|
-
|
|
200
|
-
const id = parseInt(cells.eq(0).text(), 10);
|
|
201
|
-
const parent = parseInt(cells.eq(1).text(), 10);
|
|
202
|
-
let name = cells.eq(2).text();
|
|
203
|
-
name = name.trim();
|
|
204
|
-
const url = $('a', cells.eq(2)).attr('href');
|
|
205
|
-
const skip = 3; // Antallet af celler, som ikke angiver associations!
|
|
206
|
-
|
|
207
|
-
const obj = {
|
|
208
|
-
id,
|
|
209
|
-
name,
|
|
210
|
-
url,
|
|
211
|
-
parent,
|
|
212
|
-
extra: [],
|
|
213
|
-
children: [],
|
|
214
|
-
associations: [],
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
for (let j = 0; j < associations.length; j += 1) {
|
|
218
|
-
const assocCell = cells.eq(j + skip).text();
|
|
219
|
-
const assocCellSplit = assocCell.split(',');
|
|
220
|
-
|
|
221
|
-
obj.associations.push([]);
|
|
222
|
-
|
|
223
|
-
for (let k = 0; k < assocCellSplit.length; k += 1) {
|
|
224
|
-
const aid = parseInt(assocCellSplit[k], 10) - 1;
|
|
225
|
-
|
|
226
|
-
if (typeof associations[j][aid] !== 'undefined') {
|
|
227
|
-
obj.associations[j].push({
|
|
228
|
-
id: associations[j][aid].id,
|
|
229
|
-
name: associations[j][aid].name,
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
associations[j][aid].items.push(obj);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
if (obj.parent === 0 || obj.parent === '') {
|
|
238
|
-
items.push(obj);
|
|
239
|
-
} else {
|
|
240
|
-
children.push(obj);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
for (let c = 0; c < children.length; c += 1) {
|
|
246
|
-
const pid = children[c].parent;
|
|
247
|
-
for (let p = 0; p < items.length; p += 1) {
|
|
248
|
-
if (items[p].id === pid) {
|
|
249
|
-
items[p].children.push(children[c]);
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const groupings = [];
|
|
256
|
-
for (let i = 0; i < associations.length; i += 1) {
|
|
257
|
-
groupings.push({
|
|
258
|
-
id: i,
|
|
259
|
-
associations: associations[i],
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
callback({
|
|
264
|
-
items,
|
|
265
|
-
groupings,
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
static list(source, callback) {
|
|
270
|
-
const list = $(source);
|
|
271
|
-
const items = [];
|
|
272
|
-
$('li', list).each(function (i) {
|
|
273
|
-
items.push({
|
|
274
|
-
id: i,
|
|
275
|
-
label: $(this).text(),
|
|
276
|
-
value: $(this).text(),
|
|
277
|
-
name: $(this).text(),
|
|
278
|
-
url: $('a', this).attr('href'),
|
|
279
|
-
children: [],
|
|
280
|
-
associations: [],
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
callback({
|
|
285
|
-
items,
|
|
286
|
-
groupings: [],
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
class AUDatabox {
|
|
291
|
-
constructor(boxes) {
|
|
292
|
-
this.boxes = boxes;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
static mergeOptions(_box) {
|
|
296
|
-
const box = _box;
|
|
297
|
-
if (!box.hasOwnProperty('config')) {
|
|
298
|
-
box.config = {};
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
for (const conf in defaultOptions.config) {
|
|
302
|
-
if (!box.config.hasOwnProperty(conf)) {
|
|
303
|
-
box.config[conf] = defaultOptions.config[conf];
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
if (!box.hasOwnProperty('background')) {
|
|
308
|
-
box.background = {};
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
for (const bg in defaultOptions.background) {
|
|
312
|
-
if (!box.background.hasOwnProperty(bg)) {
|
|
313
|
-
box.background[bg] = defaultOptions.background[bg];
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
if (!box.hasOwnProperty('search')) {
|
|
318
|
-
box.search = {};
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
for (const sch in defaultOptions.search) {
|
|
322
|
-
if (!box.search.hasOwnProperty(sch)) {
|
|
323
|
-
box.search[sch] = defaultOptions.search[sch];
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
if (!box.hasOwnProperty('data')) {
|
|
328
|
-
box.data = {};
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
for (const data in defaultOptions.data) {
|
|
332
|
-
if (!box.data.hasOwnProperty(data)) {
|
|
333
|
-
box.data[data] = defaultOptions.data[data];
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
return box;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
static legacyCleanUp(_box) {
|
|
341
|
-
const box = _box;
|
|
342
|
-
const container = $(box.config.container);
|
|
343
|
-
if (container !== null) {
|
|
344
|
-
const containerChildren = $('> *:not(.no-header)', container); // Kan både være div og h2 elementer
|
|
345
|
-
if (containerChildren.length > 0) {
|
|
346
|
-
box.config.buttons = [];
|
|
347
|
-
containerChildren.each(function () {
|
|
348
|
-
box.config.buttons.push({
|
|
349
|
-
text: $(this).text(),
|
|
350
|
-
link: '',
|
|
351
|
-
});
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
init() {
|
|
358
|
-
const parser = {
|
|
359
|
-
json: AUDataboxParser.json,
|
|
360
|
-
xml: AUDataboxParser.xml,
|
|
361
|
-
table: AUDataboxParser.table,
|
|
362
|
-
list: AUDataboxParser.list,
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
for (let i = 0; i < this.boxes.length; i += 1) {
|
|
366
|
-
let box = this.boxes[i];
|
|
367
|
-
if (!box.loaded) {
|
|
368
|
-
box = AUDatabox.mergeOptions(box);
|
|
369
|
-
box.id = i;
|
|
370
|
-
AUDatabox.legacyCleanUp(box);
|
|
371
|
-
// I stedet for at skulle rette alle gamle søgebokse,
|
|
372
|
-
// hvor knappernes tekst er sat direkte i HTML'en,
|
|
373
|
-
// finder vi knapperne her og indsætter dem som 'buttons' i config'en
|
|
374
|
-
const mountNode = document.querySelector(box.config.container);
|
|
375
|
-
const visible = mountNode && getComputedStyle(mountNode).visibility !== 'hidden';
|
|
376
|
-
if (!box.config.stacked
|
|
377
|
-
&& AU.responsive.state
|
|
378
|
-
&& AU.responsive.state.NAME === 'PHONE') {
|
|
379
|
-
box.config.stacked = true;
|
|
380
|
-
}
|
|
381
|
-
if (visible) {
|
|
382
|
-
ReactDOM.render(<DataBoxComponent
|
|
383
|
-
box={box}
|
|
384
|
-
parse={parser[box.data.mode]}
|
|
385
|
-
/>, mountNode);
|
|
386
|
-
box.loaded = true;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
if (box.data.mode === 'table' || box.data.mode === 'list') {
|
|
390
|
-
const dataElement = document.querySelector(box.data.source);
|
|
391
|
-
if (dataElement) {
|
|
392
|
-
dataElement.parentNode.removeChild(dataElement);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
window.AUDatabox = AUDatabox;
|
|
1
|
+
/* eslint func-names: ["error", "never"] */
|
|
2
|
+
/* eslint no-prototype-builtins: 0 */
|
|
3
|
+
/* eslint no-restricted-syntax: 0 */
|
|
4
|
+
/* eslint max-classes-per-file: 0 */
|
|
5
|
+
/* eslint no-unused-vars: 0 */
|
|
6
|
+
/* eslint-env browser */
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import ReactDOM from 'react-dom';
|
|
9
|
+
import DataBoxComponent from '../components/databox/DataBoxComponent';
|
|
10
|
+
|
|
11
|
+
const defaultOptions = {
|
|
12
|
+
config: {
|
|
13
|
+
container: '.au_databox', // DOM-element
|
|
14
|
+
firstline: true, // skal søgefeltet stå på en række for sig selv?
|
|
15
|
+
alphabet: 2, // hvilken knap er alfabetet?
|
|
16
|
+
initLetter: 'a', // Startbogstavet for alfabetet
|
|
17
|
+
trigger: 0,
|
|
18
|
+
tracking: '/virtual/databox/', // GA-tracking
|
|
19
|
+
buttons: [ // Teksten på knapperne - nyt!
|
|
20
|
+
{ text: 'Dummy knap 1', link: '' },
|
|
21
|
+
{ text: 'Dummy knap 2', link: '' },
|
|
22
|
+
],
|
|
23
|
+
stacked: false,
|
|
24
|
+
rememberState: false,
|
|
25
|
+
expand: false,
|
|
26
|
+
},
|
|
27
|
+
background: {
|
|
28
|
+
color: '#003d73',
|
|
29
|
+
linkColor: '#003d73',
|
|
30
|
+
src: '',
|
|
31
|
+
height: 0,
|
|
32
|
+
text: '',
|
|
33
|
+
overlay: true,
|
|
34
|
+
},
|
|
35
|
+
search: {
|
|
36
|
+
autocomplete: true,
|
|
37
|
+
index: 1,
|
|
38
|
+
minLength: 1,
|
|
39
|
+
placeHolder: '',
|
|
40
|
+
},
|
|
41
|
+
data: {
|
|
42
|
+
mode: 'json',
|
|
43
|
+
source: '',
|
|
44
|
+
callback: null,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
class AUDataboxParser {
|
|
49
|
+
static json(source, callback) {
|
|
50
|
+
if (source) {
|
|
51
|
+
let sourceArr = [];
|
|
52
|
+
if (!Array.isArray(source)) {
|
|
53
|
+
sourceArr.push(source);
|
|
54
|
+
} else {
|
|
55
|
+
sourceArr = source;
|
|
56
|
+
}
|
|
57
|
+
const promises = [];
|
|
58
|
+
sourceArr.forEach((s) => {
|
|
59
|
+
promises.push(new Promise((resolve) => {
|
|
60
|
+
fetch(s).then((promise) => promise.json()).then((data) => {
|
|
61
|
+
resolve(data);
|
|
62
|
+
});
|
|
63
|
+
}));
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
Promise.all(promises).then((values) => {
|
|
67
|
+
callback({
|
|
68
|
+
items: values.map((x) => x.items)[0],
|
|
69
|
+
groupings: values.map((x) => x.groupings)[0] || [],
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static xml(source, callback) {
|
|
76
|
+
const xmlFunc = (data) => {
|
|
77
|
+
const items = [];
|
|
78
|
+
const children = [];
|
|
79
|
+
const associations = [];
|
|
80
|
+
|
|
81
|
+
let assocXML = [];
|
|
82
|
+
let count = 1;
|
|
83
|
+
|
|
84
|
+
do {
|
|
85
|
+
assocXML = $(data).find(`associations${count} > item`);
|
|
86
|
+
|
|
87
|
+
const assoc = [];
|
|
88
|
+
for (let i = 0; i < assocXML.length; i += 1) {
|
|
89
|
+
assoc.push({
|
|
90
|
+
id: $(assocXML[i]).attr('id'),
|
|
91
|
+
name: $(assocXML[i]).attr('name'),
|
|
92
|
+
items: [],
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (assoc.length > 0) {
|
|
97
|
+
associations.push(assoc);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
count += 1;
|
|
101
|
+
} while (assocXML.length > 0);
|
|
102
|
+
|
|
103
|
+
const itemsXML = $(data).find('items > item');
|
|
104
|
+
$.each(itemsXML, function () {
|
|
105
|
+
const extraXML = $(this).find('extra');
|
|
106
|
+
const extra = [];
|
|
107
|
+
$.each(extraXML.find('param'), () => {
|
|
108
|
+
extra.push({
|
|
109
|
+
param: $(this).text(),
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
const obj = {
|
|
113
|
+
id: $(this).attr('id'),
|
|
114
|
+
name: $(this).attr('name'),
|
|
115
|
+
url: $(this).attr('url'),
|
|
116
|
+
parent: $(this).attr('parent'),
|
|
117
|
+
extra,
|
|
118
|
+
children: [],
|
|
119
|
+
associations: [],
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
for (let i = 0; i < associations.length; i += 1) {
|
|
123
|
+
const objAssoc = $(this).find(`association${parseInt(i + 1, 10)}`);
|
|
124
|
+
|
|
125
|
+
obj.associations.push([]);
|
|
126
|
+
|
|
127
|
+
for (let j = 0; j < objAssoc.length; j += 1) {
|
|
128
|
+
const id = parseInt($(objAssoc[j]).attr('id'), 10) - 1;
|
|
129
|
+
obj.associations[i].push({
|
|
130
|
+
id: associations[i][id].id,
|
|
131
|
+
name: associations[i][id].name,
|
|
132
|
+
});
|
|
133
|
+
associations[i][id].items.push(obj);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
items.push(obj);
|
|
138
|
+
if (typeof obj.parent !== 'undefined' && obj.parent !== '') {
|
|
139
|
+
children.push(obj);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
for (let c = 0; c < children.length; c += 1) {
|
|
144
|
+
const pid = children[c].parent;
|
|
145
|
+
for (let p = 0; p < items.length; p += 1) {
|
|
146
|
+
if (items[p].id === pid) {
|
|
147
|
+
items[p].children.push(children[c]);
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const groupings = [];
|
|
154
|
+
for (let i = 0; i < associations.length; i += 1) {
|
|
155
|
+
groupings.push({
|
|
156
|
+
id: i,
|
|
157
|
+
associations: associations[i],
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
callback({
|
|
162
|
+
rawData: data,
|
|
163
|
+
items,
|
|
164
|
+
groupings,
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
AU.helpers.getXML(source, (data) => {
|
|
169
|
+
xmlFunc(data);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
static table(source, callback) {
|
|
174
|
+
const table = $(`${source} > table`);
|
|
175
|
+
const list = $(`${source} > ul`);
|
|
176
|
+
|
|
177
|
+
const items = [];
|
|
178
|
+
const children = [];
|
|
179
|
+
const associations = [];
|
|
180
|
+
|
|
181
|
+
$('li', list).each(function () {
|
|
182
|
+
const assoc = [];
|
|
183
|
+
$('> ul > li', this).each(function (i) {
|
|
184
|
+
assoc.push({
|
|
185
|
+
id: i,
|
|
186
|
+
name: $(this).text(),
|
|
187
|
+
items: [],
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
if (assoc.length > 0) {
|
|
192
|
+
associations.push(assoc);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
$('tr', table).each(function (i) {
|
|
197
|
+
if (i > 0) {
|
|
198
|
+
const cells = $('td', this);
|
|
199
|
+
|
|
200
|
+
const id = parseInt(cells.eq(0).text(), 10);
|
|
201
|
+
const parent = parseInt(cells.eq(1).text(), 10);
|
|
202
|
+
let name = cells.eq(2).text();
|
|
203
|
+
name = name.trim();
|
|
204
|
+
const url = $('a', cells.eq(2)).attr('href');
|
|
205
|
+
const skip = 3; // Antallet af celler, som ikke angiver associations!
|
|
206
|
+
|
|
207
|
+
const obj = {
|
|
208
|
+
id,
|
|
209
|
+
name,
|
|
210
|
+
url,
|
|
211
|
+
parent,
|
|
212
|
+
extra: [],
|
|
213
|
+
children: [],
|
|
214
|
+
associations: [],
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
for (let j = 0; j < associations.length; j += 1) {
|
|
218
|
+
const assocCell = cells.eq(j + skip).text();
|
|
219
|
+
const assocCellSplit = assocCell.split(',');
|
|
220
|
+
|
|
221
|
+
obj.associations.push([]);
|
|
222
|
+
|
|
223
|
+
for (let k = 0; k < assocCellSplit.length; k += 1) {
|
|
224
|
+
const aid = parseInt(assocCellSplit[k], 10) - 1;
|
|
225
|
+
|
|
226
|
+
if (typeof associations[j][aid] !== 'undefined') {
|
|
227
|
+
obj.associations[j].push({
|
|
228
|
+
id: associations[j][aid].id,
|
|
229
|
+
name: associations[j][aid].name,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
associations[j][aid].items.push(obj);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (obj.parent === 0 || obj.parent === '') {
|
|
238
|
+
items.push(obj);
|
|
239
|
+
} else {
|
|
240
|
+
children.push(obj);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
for (let c = 0; c < children.length; c += 1) {
|
|
246
|
+
const pid = children[c].parent;
|
|
247
|
+
for (let p = 0; p < items.length; p += 1) {
|
|
248
|
+
if (items[p].id === pid) {
|
|
249
|
+
items[p].children.push(children[c]);
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const groupings = [];
|
|
256
|
+
for (let i = 0; i < associations.length; i += 1) {
|
|
257
|
+
groupings.push({
|
|
258
|
+
id: i,
|
|
259
|
+
associations: associations[i],
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
callback({
|
|
264
|
+
items,
|
|
265
|
+
groupings,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
static list(source, callback) {
|
|
270
|
+
const list = $(source);
|
|
271
|
+
const items = [];
|
|
272
|
+
$('li', list).each(function (i) {
|
|
273
|
+
items.push({
|
|
274
|
+
id: i,
|
|
275
|
+
label: $(this).text(),
|
|
276
|
+
value: $(this).text(),
|
|
277
|
+
name: $(this).text(),
|
|
278
|
+
url: $('a', this).attr('href'),
|
|
279
|
+
children: [],
|
|
280
|
+
associations: [],
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
callback({
|
|
285
|
+
items,
|
|
286
|
+
groupings: [],
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
class AUDatabox {
|
|
291
|
+
constructor(boxes) {
|
|
292
|
+
this.boxes = boxes;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
static mergeOptions(_box) {
|
|
296
|
+
const box = _box;
|
|
297
|
+
if (!box.hasOwnProperty('config')) {
|
|
298
|
+
box.config = {};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
for (const conf in defaultOptions.config) {
|
|
302
|
+
if (!box.config.hasOwnProperty(conf)) {
|
|
303
|
+
box.config[conf] = defaultOptions.config[conf];
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (!box.hasOwnProperty('background')) {
|
|
308
|
+
box.background = {};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
for (const bg in defaultOptions.background) {
|
|
312
|
+
if (!box.background.hasOwnProperty(bg)) {
|
|
313
|
+
box.background[bg] = defaultOptions.background[bg];
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (!box.hasOwnProperty('search')) {
|
|
318
|
+
box.search = {};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
for (const sch in defaultOptions.search) {
|
|
322
|
+
if (!box.search.hasOwnProperty(sch)) {
|
|
323
|
+
box.search[sch] = defaultOptions.search[sch];
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (!box.hasOwnProperty('data')) {
|
|
328
|
+
box.data = {};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
for (const data in defaultOptions.data) {
|
|
332
|
+
if (!box.data.hasOwnProperty(data)) {
|
|
333
|
+
box.data[data] = defaultOptions.data[data];
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return box;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
static legacyCleanUp(_box) {
|
|
341
|
+
const box = _box;
|
|
342
|
+
const container = $(box.config.container);
|
|
343
|
+
if (container !== null) {
|
|
344
|
+
const containerChildren = $('> *:not(.no-header)', container); // Kan både være div og h2 elementer
|
|
345
|
+
if (containerChildren.length > 0) {
|
|
346
|
+
box.config.buttons = [];
|
|
347
|
+
containerChildren.each(function () {
|
|
348
|
+
box.config.buttons.push({
|
|
349
|
+
text: $(this).text(),
|
|
350
|
+
link: '',
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
init() {
|
|
358
|
+
const parser = {
|
|
359
|
+
json: AUDataboxParser.json,
|
|
360
|
+
xml: AUDataboxParser.xml,
|
|
361
|
+
table: AUDataboxParser.table,
|
|
362
|
+
list: AUDataboxParser.list,
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
for (let i = 0; i < this.boxes.length; i += 1) {
|
|
366
|
+
let box = this.boxes[i];
|
|
367
|
+
if (!box.loaded) {
|
|
368
|
+
box = AUDatabox.mergeOptions(box);
|
|
369
|
+
box.id = i;
|
|
370
|
+
AUDatabox.legacyCleanUp(box);
|
|
371
|
+
// I stedet for at skulle rette alle gamle søgebokse,
|
|
372
|
+
// hvor knappernes tekst er sat direkte i HTML'en,
|
|
373
|
+
// finder vi knapperne her og indsætter dem som 'buttons' i config'en
|
|
374
|
+
const mountNode = document.querySelector(box.config.container);
|
|
375
|
+
const visible = mountNode && getComputedStyle(mountNode).visibility !== 'hidden';
|
|
376
|
+
if (!box.config.stacked
|
|
377
|
+
&& AU.responsive.state
|
|
378
|
+
&& AU.responsive.state.NAME === 'PHONE') {
|
|
379
|
+
box.config.stacked = true;
|
|
380
|
+
}
|
|
381
|
+
if (visible) {
|
|
382
|
+
ReactDOM.render(<DataBoxComponent
|
|
383
|
+
box={box}
|
|
384
|
+
parse={parser[box.data.mode]}
|
|
385
|
+
/>, mountNode);
|
|
386
|
+
box.loaded = true;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
if (box.data.mode === 'table' || box.data.mode === 'list') {
|
|
390
|
+
const dataElement = document.querySelector(box.data.source);
|
|
391
|
+
if (dataElement) {
|
|
392
|
+
dataElement.parentNode.removeChild(dataElement);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
window.AUDatabox = AUDatabox;
|