Akron | d4b000b | 2018-01-28 18:33:14 +0100 | [diff] [blame] | 1 | define(['util'], function () { |
2 | |||||
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 3 | // Localization values |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 4 | const loc = KorAP.Locale; |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 5 | loc.METADATA = loc.METADATA || 'Metadata'; |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 6 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 7 | return { |
8 | |||||
9 | /** | ||||
10 | * Create new match object | ||||
11 | */ | ||||
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 12 | create : function (match, fields) { |
13 | return Object.create(this)._init(match, fields); | ||||
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 14 | }, |
15 | |||||
16 | /** | ||||
17 | * Initialize object | ||||
18 | */ | ||||
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 19 | _init : function (match, fields) { |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 20 | this._match = match; |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 21 | this._fields = fields; |
22 | // this.opened = false; | ||||
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 23 | return this; |
24 | }, | ||||
25 | |||||
26 | /** | ||||
27 | * Get match object | ||||
28 | */ | ||||
29 | match : function () { | ||||
30 | return this._match; | ||||
31 | }, | ||||
32 | |||||
33 | /** | ||||
34 | * Create match reference view. | ||||
35 | */ | ||||
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 36 | element : function () { |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 37 | if (this._element !== undefined) |
38 | return this._element; | ||||
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 39 | |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 40 | if (this._fields === null) |
41 | return; | ||||
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 42 | |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 43 | var metaDL = document.createElement('dl'); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 44 | |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 45 | this._element = metaDL; |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 46 | |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 47 | var fields = this._fields; |
48 | |||||
49 | // TODO: | ||||
50 | // This should only remember array positions by index | ||||
51 | // and keep all other field information intact | ||||
52 | var metaInfo = {}; | ||||
53 | for (var i in fields) { | ||||
54 | var value = fields[i].value; | ||||
55 | if (value instanceof Array) { | ||||
56 | metaInfo[fields[i].key] = value.join(", "); | ||||
57 | } | ||||
58 | else { | ||||
59 | metaInfo[fields[i].key] = value; | ||||
60 | }; | ||||
61 | }; | ||||
62 | |||||
63 | // console.log(fields); | ||||
64 | |||||
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 65 | // TODO: Meta fields should be separated |
66 | var keys = Object.keys(metaInfo); | ||||
67 | for (var i in keys.sort()) { | ||||
68 | var k = keys[i]; | ||||
69 | if (k !== "UID" && | ||||
70 | k !== "corpusID" && | ||||
71 | k !== "docID" && | ||||
72 | k !== "textID" && | ||||
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 73 | /* |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 74 | k !== "corpusSigle" && |
75 | k !== "docSigle" && | ||||
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 76 | */ |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 77 | k !== "layerInfos") { |
78 | |||||
79 | var metaL = document.createElement('div'); | ||||
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 80 | metaL.addE('dt').addT(k); |
81 | metaL.addE('dd').addT(metaInfo[k]); | ||||
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 82 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 83 | metaDL.appendChild(metaL); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 84 | }; |
85 | }; | ||||
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 86 | return this._element; |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 87 | } |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 88 | }; |
Akron | 30ee514 | 2015-06-26 01:50:14 +0200 | [diff] [blame] | 89 | }); |