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 | 2f97912 | 2018-07-25 17:00:23 +0200 | [diff] [blame] | 44 | metaDL.classList.add("flex"); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 45 | |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 46 | this._element = metaDL; |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 47 | |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 48 | var fields = this._fields; |
49 | |||||
50 | // TODO: | ||||
51 | // This should only remember array positions by index | ||||
52 | // and keep all other field information intact | ||||
53 | var metaInfo = {}; | ||||
54 | for (var i in fields) { | ||||
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 55 | var value = fields[i].value; |
56 | metaInfo[fields[i].key] = value; | ||||
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 57 | }; |
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 58 | |
59 | // console.log(fields); | ||||
60 | |||||
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 61 | // TODO: Meta fields should be separated |
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 62 | var keys = Object.keys(metaInfo); |
63 | |||||
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 64 | for (var i in keys.sort()) { |
65 | var k = keys[i]; | ||||
66 | if (k !== "UID" && | ||||
67 | k !== "corpusID" && | ||||
68 | k !== "docID" && | ||||
69 | k !== "textID" && | ||||
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 70 | /* |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 71 | k !== "corpusSigle" && |
72 | k !== "docSigle" && | ||||
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 !== "layerInfos") { |
75 | |||||
76 | var metaL = document.createElement('div'); | ||||
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 77 | |
Akron | c456838 | 2018-03-06 20:16:12 +0100 | [diff] [blame] | 78 | var dt = metaL.addE('dt'); |
79 | dt.addT(k); | ||||
80 | dt.setAttribute("title", k); | ||||
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 81 | |
82 | var metaDescr = metaInfo[k]; | ||||
83 | metaDD = metaL.addE('dd'); | ||||
84 | |||||
85 | if(metaDescr instanceof Array){ | ||||
86 | metaDD.classList.add("metakeyvalues"); | ||||
87 | for(i = 0; i < metaDescr.length; i++){ | ||||
88 | metaDD.addE('div').addT(metaDescr[i]); | ||||
89 | } | ||||
90 | } | ||||
91 | else{ | ||||
92 | metaDD.addT(metaInfo[k]); | ||||
93 | } | ||||
94 | |||||
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 95 | metaDL.appendChild(metaL); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 96 | }; |
97 | }; | ||||
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 98 | return this._element; |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 99 | } |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 100 | }; |
Akron | 30ee514 | 2015-06-26 01:50:14 +0200 | [diff] [blame] | 101 | }); |