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 | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 30 | loc.METADATA = loc.METADATA || 'Metadata'; |
| 31 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 32 | return { |
| 33 | |
| 34 | /** |
| 35 | * Create new match object |
| 36 | */ |
| 37 | create : function (match) { |
| 38 | return Object.create(this)._init(match); |
| 39 | }, |
| 40 | |
| 41 | /** |
| 42 | * Initialize object |
| 43 | */ |
| 44 | _init : function (match) { |
| 45 | this._match = match; |
| 46 | this.opened = false; |
| 47 | return this; |
| 48 | }, |
| 49 | |
| 50 | /** |
| 51 | * Get match object |
| 52 | */ |
| 53 | match : function () { |
| 54 | return this._match; |
| 55 | }, |
| 56 | |
| 57 | /** |
| 58 | * Create match reference view. |
| 59 | */ |
| 60 | element : function (metaInfo) { |
| 61 | if (this._element !== undefined) |
| 62 | return this._element; |
| 63 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 64 | var metaTable = document.createElement('div'); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 65 | metaTable.classList.add('metatable'); |
| 66 | |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 67 | /* |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 68 | var header = metaTable.appendChild( |
| 69 | document.createElement('h6') |
| 70 | ); |
| 71 | |
| 72 | header.appendChild( |
| 73 | document.createElement('div') |
| 74 | ).appendChild( |
| 75 | document.createTextNode(loc.METADATA) |
| 76 | ); |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 77 | */ |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 78 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 79 | var metaDL = metaTable.addE('dl'); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 80 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 81 | this._element = metaTable; |
| 82 | |
| 83 | // TODO: Meta fields should be separated |
| 84 | var keys = Object.keys(metaInfo); |
| 85 | for (var i in keys.sort()) { |
| 86 | var k = keys[i]; |
| 87 | if (k !== "UID" && |
| 88 | k !== "corpusID" && |
| 89 | k !== "docID" && |
| 90 | k !== "textID" && |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 91 | /* |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 92 | k !== "corpusSigle" && |
| 93 | k !== "docSigle" && |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 94 | */ |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 95 | k !== "layerInfos") { |
| 96 | |
| 97 | var metaL = document.createElement('div'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 98 | metaL.addE('dt').addT(k); |
| 99 | metaL.addE('dd').addT(metaInfo[k]); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 100 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 101 | metaDL.appendChild(metaL); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 102 | }; |
| 103 | }; |
| 104 | |
Akron | 41387d2 | 2018-02-02 18:10:06 +0100 | [diff] [blame^] | 105 | this.addButton('close', function (e) { |
| 106 | var el = this.element(); |
| 107 | el.parentNode.removeChild(el); |
| 108 | e.halt(); |
| 109 | }); |
| 110 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 111 | return this._element; |
Akron | 41387d2 | 2018-02-02 18:10:06 +0100 | [diff] [blame^] | 112 | }, |
| 113 | |
| 114 | // TODO: This should be a method by all matchinfo objects |
| 115 | addButton : function (buttonType, cb) { |
| 116 | // TODO: Unless existent |
| 117 | var actions = document.createElement('ul'); |
| 118 | actions.classList.add('action', 'image'); |
| 119 | var button = actions.addE('li'); |
| 120 | button.className = buttonType; |
| 121 | button.addE('span').addT(buttonType); |
| 122 | button.addEventListener( |
| 123 | 'click', cb.bind(this) |
| 124 | ); |
| 125 | |
| 126 | this.element().appendChild(actions); |
| 127 | return actions; |
| 128 | }, |
| 129 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 130 | }; |
Akron | 30ee514 | 2015-06-26 01:50:14 +0200 | [diff] [blame] | 131 | }); |