Akron | d4b000b | 2018-01-28 18:33:14 +0100 | [diff] [blame] | 1 | define(['util'], function () { |
| 2 | |
| 3 | /* |
Akron | 30ee514 | 2015-06-26 01:50:14 +0200 | [diff] [blame] | 4 | 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 | */ |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 27 | |
| 28 | // Localization values |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 29 | const loc = KorAP.Locale; |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame^] | 30 | loc.METADATA = loc.METADATA || 'Metadata'; |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 31 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 32 | return { |
| 33 | |
| 34 | /** |
| 35 | * Create new match object |
| 36 | */ |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame^] | 37 | create : function (match, fields) { |
| 38 | return Object.create(this)._init(match, fields); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 39 | }, |
| 40 | |
| 41 | /** |
| 42 | * Initialize object |
| 43 | */ |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame^] | 44 | _init : function (match, fields) { |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 45 | this._match = match; |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame^] | 46 | this._fields = fields; |
| 47 | // this.opened = false; |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 48 | 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 | */ |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame^] | 61 | element : function () { |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 62 | if (this._element !== undefined) |
| 63 | return this._element; |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 64 | |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame^] | 65 | if (this._fields === null) |
| 66 | return; |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 67 | |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 68 | var metaDL = document.createElement('dl'); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 69 | |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 70 | this._element = metaDL; |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 71 | |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame^] | 72 | 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 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 90 | // 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" && |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 98 | /* |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 99 | k !== "corpusSigle" && |
| 100 | k !== "docSigle" && |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 101 | */ |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 102 | k !== "layerInfos") { |
| 103 | |
| 104 | var metaL = document.createElement('div'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 105 | metaL.addE('dt').addT(k); |
| 106 | metaL.addE('dd').addT(metaInfo[k]); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 107 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 108 | metaDL.appendChild(metaL); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 109 | }; |
| 110 | }; |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 111 | return this._element; |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 112 | } |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 113 | }; |
Akron | 30ee514 | 2015-06-26 01:50:14 +0200 | [diff] [blame] | 114 | }); |