blob: a9bf2dbe1eda15416c05e278bc85085200172fa3 [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');
Akronbd342982018-01-25 18:01:46 +010044
Akronaeceda72018-02-02 20:44:06 +010045 this._element = metaDL;
Akron24866cf2018-01-23 20:22:01 +010046
Akron0ad7cd22018-02-08 18:03:06 +010047 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) {
hebasta24fbc9e2018-04-12 13:47:50 +020054 var value = fields[i].value;
55 metaInfo[fields[i].key] = value;
Akron0ad7cd22018-02-08 18:03:06 +010056 };
hebasta24fbc9e2018-04-12 13:47:50 +020057
58 // console.log(fields);
59
Akron24866cf2018-01-23 20:22:01 +010060 // TODO: Meta fields should be separated
hebasta24fbc9e2018-04-12 13:47:50 +020061 var keys = Object.keys(metaInfo);
62
Akron24866cf2018-01-23 20:22:01 +010063 for (var i in keys.sort()) {
64 var k = keys[i];
65 if (k !== "UID" &&
66 k !== "corpusID" &&
67 k !== "docID" &&
68 k !== "textID" &&
Akron8b592d42018-01-26 18:33:06 +010069 /*
Akron24866cf2018-01-23 20:22:01 +010070 k !== "corpusSigle" &&
71 k !== "docSigle" &&
Akron8b592d42018-01-26 18:33:06 +010072 */
Akron24866cf2018-01-23 20:22:01 +010073 k !== "layerInfos") {
74
75 var metaL = document.createElement('div');
hebasta24fbc9e2018-04-12 13:47:50 +020076
Akronc4568382018-03-06 20:16:12 +010077 var dt = metaL.addE('dt');
78 dt.addT(k);
79 dt.setAttribute("title", k);
hebasta24fbc9e2018-04-12 13:47:50 +020080
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
Akronbd342982018-01-25 18:01:46 +010094 metaDL.appendChild(metaL);
Akron24866cf2018-01-23 20:22:01 +010095 };
96 };
Akron24866cf2018-01-23 20:22:01 +010097 return this._element;
Akronaeceda72018-02-02 20:44:06 +010098 }
Akron24866cf2018-01-23 20:22:01 +010099 };
Akron30ee5142015-06-26 01:50:14 +0200100});