blob: a806e2ebaa95cebf9021600e63b0b4100f48856b [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) {
54 var value = fields[i].value;
55 if (value instanceof Array) {
56 metaInfo[fields[i].key] = value.join(", ");
57 }
58 else {
59 metaInfo[fields[i].key] = value;
60 };
61 };
62
63 // console.log(fields);
64
Akron24866cf2018-01-23 20:22:01 +010065 // TODO: Meta fields should be separated
66 var keys = Object.keys(metaInfo);
67 for (var i in keys.sort()) {
68 var k = keys[i];
69 if (k !== "UID" &&
70 k !== "corpusID" &&
71 k !== "docID" &&
72 k !== "textID" &&
Akron8b592d42018-01-26 18:33:06 +010073 /*
Akron24866cf2018-01-23 20:22:01 +010074 k !== "corpusSigle" &&
75 k !== "docSigle" &&
Akron8b592d42018-01-26 18:33:06 +010076 */
Akron24866cf2018-01-23 20:22:01 +010077 k !== "layerInfos") {
78
79 var metaL = document.createElement('div');
Akronc4568382018-03-06 20:16:12 +010080 var dt = metaL.addE('dt');
81 dt.addT(k);
82 dt.setAttribute("title", k);
Akron0b489ad2018-02-02 16:49:32 +010083 metaL.addE('dd').addT(metaInfo[k]);
Akron24866cf2018-01-23 20:22:01 +010084
Akronbd342982018-01-25 18:01:46 +010085 metaDL.appendChild(metaL);
Akron24866cf2018-01-23 20:22:01 +010086 };
87 };
Akron24866cf2018-01-23 20:22:01 +010088 return this._element;
Akronaeceda72018-02-02 20:44:06 +010089 }
Akron24866cf2018-01-23 20:22:01 +010090 };
Akron30ee5142015-06-26 01:50:14 +020091});