blob: 05e1f3b04b4dd76231655ba8bc11888e077d569a [file] [log] [blame]
Akrond4b000b2018-01-28 18:33:14 +01001define(['util'], function () {
2
3 /*
Akron30ee5142015-06-26 01:50:14 +02004 author, editor title, subTitle textSigle
5 in corpusAuthor (corpusEditor), corpusTitle, corpusSubTitle, corpusSigle
6 in docAuthor (docEditor), docTitle, docSubTitle, docSigle
7 publisher
8 reference
9 creationDate
10 foundries
11 keywords
12 textClass
13 textColumn
14 textDomain
15 textType
16 textTypeArt
17 textTypeRef
18 language
19 license
20 pages
21 pubDate
22 layerInfo
23 tokenSource
24 biblEditionStatement
25 fileEditionStatement
26*/
Akronbd342982018-01-25 18:01:46 +010027
28 // Localization values
Akron0b489ad2018-02-02 16:49:32 +010029 const loc = KorAP.Locale;
Akron0ad7cd22018-02-08 18:03:06 +010030 loc.METADATA = loc.METADATA || 'Metadata';
Akronbd342982018-01-25 18:01:46 +010031
Akron24866cf2018-01-23 20:22:01 +010032 return {
33
34 /**
35 * Create new match object
36 */
Akron0ad7cd22018-02-08 18:03:06 +010037 create : function (match, fields) {
38 return Object.create(this)._init(match, fields);
Akron24866cf2018-01-23 20:22:01 +010039 },
40
41 /**
42 * Initialize object
43 */
Akron0ad7cd22018-02-08 18:03:06 +010044 _init : function (match, fields) {
Akron24866cf2018-01-23 20:22:01 +010045 this._match = match;
Akron0ad7cd22018-02-08 18:03:06 +010046 this._fields = fields;
47 // this.opened = false;
Akron24866cf2018-01-23 20:22:01 +010048 return this;
49 },
50
51 /**
52 * Get match object
53 */
54 match : function () {
55 return this._match;
56 },
57
58 /**
59 * Create match reference view.
60 */
Akron0ad7cd22018-02-08 18:03:06 +010061 element : function () {
Akron24866cf2018-01-23 20:22:01 +010062 if (this._element !== undefined)
63 return this._element;
Akronbd342982018-01-25 18:01:46 +010064
Akron0ad7cd22018-02-08 18:03:06 +010065 if (this._fields === null)
66 return;
Akronbd342982018-01-25 18:01:46 +010067
Akronaeceda72018-02-02 20:44:06 +010068 var metaDL = document.createElement('dl');
Akronbd342982018-01-25 18:01:46 +010069
Akronaeceda72018-02-02 20:44:06 +010070 this._element = metaDL;
Akron24866cf2018-01-23 20:22:01 +010071
Akron0ad7cd22018-02-08 18:03:06 +010072 var fields = this._fields;
73
74 // TODO:
75 // This should only remember array positions by index
76 // and keep all other field information intact
77 var metaInfo = {};
78 for (var i in fields) {
79 var value = fields[i].value;
80 if (value instanceof Array) {
81 metaInfo[fields[i].key] = value.join(", ");
82 }
83 else {
84 metaInfo[fields[i].key] = value;
85 };
86 };
87
88 // console.log(fields);
89
Akron24866cf2018-01-23 20:22:01 +010090 // TODO: Meta fields should be separated
91 var keys = Object.keys(metaInfo);
92 for (var i in keys.sort()) {
93 var k = keys[i];
94 if (k !== "UID" &&
95 k !== "corpusID" &&
96 k !== "docID" &&
97 k !== "textID" &&
Akron8b592d42018-01-26 18:33:06 +010098 /*
Akron24866cf2018-01-23 20:22:01 +010099 k !== "corpusSigle" &&
100 k !== "docSigle" &&
Akron8b592d42018-01-26 18:33:06 +0100101 */
Akron24866cf2018-01-23 20:22:01 +0100102 k !== "layerInfos") {
103
104 var metaL = document.createElement('div');
Akron0b489ad2018-02-02 16:49:32 +0100105 metaL.addE('dt').addT(k);
106 metaL.addE('dd').addT(metaInfo[k]);
Akron24866cf2018-01-23 20:22:01 +0100107
Akronbd342982018-01-25 18:01:46 +0100108 metaDL.appendChild(metaL);
Akron24866cf2018-01-23 20:22:01 +0100109 };
110 };
Akron24866cf2018-01-23 20:22:01 +0100111 return this._element;
Akronaeceda72018-02-02 20:44:06 +0100112 }
Akron24866cf2018-01-23 20:22:01 +0100113 };
Akron30ee5142015-06-26 01:50:14 +0200114});