blob: 8667953074d0ef2057375d1912e392257acc7962 [file] [log] [blame]
Akrond4b000b2018-01-28 18:33:14 +01001define(['util'], function () {
2
Akronbd342982018-01-25 18:01:46 +01003 // Localization values
Akron0b489ad2018-02-02 16:49:32 +01004 const loc = KorAP.Locale;
Akron0ad7cd22018-02-08 18:03:06 +01005 loc.METADATA = loc.METADATA || 'Metadata';
Akronbd342982018-01-25 18:01:46 +01006
Akron24866cf2018-01-23 20:22:01 +01007 return {
8
9 /**
10 * Create new match object
11 */
Akron0ad7cd22018-02-08 18:03:06 +010012 create : function (match, fields) {
13 return Object.create(this)._init(match, fields);
Akron24866cf2018-01-23 20:22:01 +010014 },
15
16 /**
17 * Initialize object
18 */
Akron0ad7cd22018-02-08 18:03:06 +010019 _init : function (match, fields) {
Akron24866cf2018-01-23 20:22:01 +010020 this._match = match;
Akron0ad7cd22018-02-08 18:03:06 +010021 this._fields = fields;
22 // this.opened = false;
Akron24866cf2018-01-23 20:22:01 +010023 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 */
Akron0ad7cd22018-02-08 18:03:06 +010036 element : function () {
Akron24866cf2018-01-23 20:22:01 +010037 if (this._element !== undefined)
38 return this._element;
Akronbd342982018-01-25 18:01:46 +010039
Akron0ad7cd22018-02-08 18:03:06 +010040 if (this._fields === null)
41 return;
Akronbd342982018-01-25 18:01:46 +010042
Akronaeceda72018-02-02 20:44:06 +010043 var metaDL = document.createElement('dl');
Akron2f979122018-07-25 17:00:23 +020044 metaDL.classList.add("flex");
Akronbd342982018-01-25 18:01:46 +010045
Akronaeceda72018-02-02 20:44:06 +010046 this._element = metaDL;
Akron24866cf2018-01-23 20:22:01 +010047
Akron0ad7cd22018-02-08 18:03:06 +010048 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) {
hebasta24fbc9e2018-04-12 13:47:50 +020055 var value = fields[i].value;
56 metaInfo[fields[i].key] = value;
Akron0ad7cd22018-02-08 18:03:06 +010057 };
hebasta24fbc9e2018-04-12 13:47:50 +020058
59 // console.log(fields);
60
Akron24866cf2018-01-23 20:22:01 +010061 // TODO: Meta fields should be separated
hebasta24fbc9e2018-04-12 13:47:50 +020062 var keys = Object.keys(metaInfo);
63
Akron24866cf2018-01-23 20:22:01 +010064 for (var i in keys.sort()) {
65 var k = keys[i];
66 if (k !== "UID" &&
67 k !== "corpusID" &&
68 k !== "docID" &&
69 k !== "textID" &&
Akron8b592d42018-01-26 18:33:06 +010070 /*
Akron24866cf2018-01-23 20:22:01 +010071 k !== "corpusSigle" &&
72 k !== "docSigle" &&
Akron8b592d42018-01-26 18:33:06 +010073 */
Akron24866cf2018-01-23 20:22:01 +010074 k !== "layerInfos") {
75
76 var metaL = document.createElement('div');
hebasta24fbc9e2018-04-12 13:47:50 +020077
Akronc4568382018-03-06 20:16:12 +010078 var dt = metaL.addE('dt');
79 dt.addT(k);
80 dt.setAttribute("title", k);
hebasta24fbc9e2018-04-12 13:47:50 +020081
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
Akronbd342982018-01-25 18:01:46 +010095 metaDL.appendChild(metaL);
Akron24866cf2018-01-23 20:22:01 +010096 };
97 };
Akron24866cf2018-01-23 20:22:01 +010098 return this._element;
Akronaeceda72018-02-02 20:44:06 +010099 }
Akron24866cf2018-01-23 20:22:01 +0100100 };
Akron30ee5142015-06-26 01:50:14 +0200101});