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