Akron | 99713ef | 2017-06-28 18:19:28 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Information about a match. |
| 3 | */ |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 4 | define([ |
| 5 | 'match/infolayer', |
| 6 | 'match/table', |
Akron | 41387d2 | 2018-02-02 18:10:06 +0100 | [diff] [blame] | 7 | 'match/treehierarchy', |
| 8 | 'match/treearc', |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 9 | 'match/meta', |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 10 | 'util' |
| 11 | ], function (infoLayerClass, |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 12 | matchTableClass, |
Akron | 41387d2 | 2018-02-02 18:10:06 +0100 | [diff] [blame] | 13 | matchTreeHierarchyClass, |
| 14 | matchTreeArcClass, |
Akron | b6685bb | 2018-02-04 00:44:47 +0100 | [diff] [blame] | 15 | matchMetaClass) { |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 16 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 17 | // Override |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 18 | KorAP.API.getMatchInfo = KorAP.API.getMatchInfo || function () { |
| 19 | KorAP.log(0, 'KorAP.API.getMatchInfo() not implemented') |
| 20 | return {}; |
| 21 | }; |
| 22 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 23 | const loc = KorAP.Locale; |
| 24 | const d = document; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 25 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 26 | return { |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Create new match object |
| 30 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 31 | create : function (match) { |
| 32 | return Object.create(this)._init(match); |
| 33 | }, |
| 34 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 35 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 36 | /** |
| 37 | * Initialize object |
| 38 | */ |
| 39 | _init : function (match) { |
| 40 | this._match = match; |
Akron | edbf33a | 2018-02-05 19:18:03 +0100 | [diff] [blame] | 41 | this._visibleTable = false; |
| 42 | this._visibleMeta = false; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 43 | this.opened = false; |
| 44 | return this; |
| 45 | }, |
| 46 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 47 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 48 | /** |
| 49 | * Get match object |
| 50 | */ |
| 51 | match : function () { |
| 52 | return this._match; |
| 53 | }, |
| 54 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Open the information view, |
| 58 | * if closed, otherwise close. |
| 59 | */ |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 60 | /* |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 61 | toggle : function () { |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 62 | |
Akron | 08b82d6 | 2016-12-05 15:06:05 +0100 | [diff] [blame] | 63 | var elem = this._match.element(); |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 64 | |
| 65 | if (this.opened == true) { |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 66 | elem.removeChild( |
| 67 | this.element() |
| 68 | ); |
| 69 | this.opened = false; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 70 | } |
| 71 | else { |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 72 | // Append element to match |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 73 | elem.appendChild( |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 74 | this.element() |
| 75 | ); |
| 76 | this.opened = true; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | return this.opened; |
| 80 | }, |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 81 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 82 | |
| 83 | |
| 84 | /** |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 85 | * Retrieve and parse snippet for table |
| 86 | * representation |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 87 | */ |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 88 | getTableData : function (tokens, cb) { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 89 | var focus = []; |
| 90 | |
| 91 | // Get all tokens |
| 92 | if (tokens === undefined) { |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 93 | focus = this._match.getTokens(); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | // Get only some tokens |
| 97 | else { |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 98 | |
| 99 | // Push newly to focus array |
| 100 | for (var i = 0; i < tokens.length; i++) { |
| 101 | var term = tokens[i]; |
| 102 | try { |
| 103 | // Create info layer objects |
| 104 | var layer = infoLayerClass.create(term); |
| 105 | layer.type = "tokens"; |
| 106 | focus.push(layer); |
| 107 | } |
| 108 | catch (e) { |
| 109 | continue; |
| 110 | }; |
| 111 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | // No tokens chosen |
| 115 | if (focus.length == 0) |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 116 | cb(null); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 117 | |
| 118 | // Get info (may be cached) |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 119 | KorAP.API.getMatchInfo( |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 120 | this._match, |
| 121 | { 'spans' : false, 'layer' : focus }, |
| 122 | |
| 123 | // Callback for retrieval |
| 124 | function (matchResponse) { |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 125 | |
Akron | 515851a | 2017-05-02 12:53:17 +0200 | [diff] [blame] | 126 | if (matchResponse === undefined) |
| 127 | cb(null); |
| 128 | |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 129 | // Get snippet from match info |
| 130 | if (matchResponse["snippet"] !== undefined) { |
| 131 | this._table = matchTableClass.create(matchResponse["snippet"]); |
| 132 | cb(this._table); |
| 133 | }; |
| 134 | }.bind(this) |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 135 | ); |
| 136 | |
| 137 | /* |
| 138 | // Todo: Store the table as a hash of the focus |
| 139 | return null; |
| 140 | */ |
| 141 | }, |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 142 | |
| 143 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 144 | getMetaData : function (metaInfo, cb) { |
| 145 | // ... |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 146 | }, |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 147 | |
| 148 | |
| 149 | /** |
| 150 | * Retrieve and parse snippet for tree representation |
| 151 | */ |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 152 | getTreeData : function (foundry, layer, type, cb) { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 153 | var focus = []; |
| 154 | |
| 155 | // TODO: Support and cache multiple trees |
| 156 | KorAP.API.getMatchInfo( |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 157 | this._match, { |
| 158 | 'spans' : true, |
| 159 | 'foundry' : foundry, |
| 160 | 'layer' : layer |
| 161 | }, |
| 162 | function (matchResponse) { |
| 163 | // Get snippet from match info |
| 164 | if (matchResponse["snippet"] !== undefined) { |
| 165 | // Todo: This should be cached somehow |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 166 | |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 167 | if (type === "spans") { |
Akron | 41387d2 | 2018-02-02 18:10:06 +0100 | [diff] [blame] | 168 | cb(matchTreeHierarchyClass.create(matchResponse["snippet"])); |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 169 | } |
| 170 | else if (type === "rels") { |
Akron | 41387d2 | 2018-02-02 18:10:06 +0100 | [diff] [blame] | 171 | cb(matchTreeArcClass.create(matchResponse["snippet"])); |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | // Unknown tree type |
| 175 | else { |
| 176 | cb(null); |
| 177 | }; |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 178 | } |
| 179 | else { |
| 180 | cb(null); |
| 181 | }; |
| 182 | }.bind(this) |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 183 | ); |
| 184 | }, |
| 185 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 186 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 187 | /** |
| 188 | * Destroy this match information view. |
| 189 | */ |
| 190 | destroy : function () { |
| 191 | |
| 192 | // Remove circular reference |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 193 | /* |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 194 | if (this._treeMenu !== undefined) |
Akron | 99713ef | 2017-06-28 18:19:28 +0200 | [diff] [blame] | 195 | delete this._treeMenu["info"]; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 196 | |
| 197 | this._treeMenu.destroy(); |
| 198 | this._treeMenu = undefined; |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 199 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 200 | this._match = undefined; |
Akron | 99713ef | 2017-06-28 18:19:28 +0200 | [diff] [blame] | 201 | this._matchCreator = undefined; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 202 | // Element destroy |
| 203 | }, |
| 204 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 205 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 206 | /** |
| 207 | * Add a new tree view to the list |
| 208 | */ |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 209 | showTree : function (foundry, layer, type, cb) { |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 210 | var matchtree = d.createElement('div'); |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 211 | matchtree.classList.add('matchtree', 'loading'); |
| 212 | |
| 213 | this.element().appendChild(matchtree); |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 214 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 215 | // Add title line |
| 216 | var h6 = matchtree.addE('h6'); |
| 217 | h6.addE('span').addT(foundry); |
| 218 | h6.addE('span').addT(layer); |
| 219 | |
| 220 | var tree = matchtree.addE('div'); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 221 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 222 | // Add close action button |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 223 | var actions = this._addButton('close', matchtree, function (e) { |
| 224 | this.parentNode.removeChild(this); |
| 225 | e.halt(); |
| 226 | }); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 227 | |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 228 | // tree.classList.add('loading'); // alternatively |
Nils Diewald | 0ec142f | 2015-05-05 00:29:23 +0000 | [diff] [blame] | 229 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 230 | // Get tree data async |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 231 | this.getTreeData(foundry, layer, type, function (treeObj) { |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 232 | matchtree.classList.remove('loading'); |
Nils Diewald | 0ec142f | 2015-05-05 00:29:23 +0000 | [diff] [blame] | 233 | |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 234 | // Something went wrong - probably log!!! |
Nils Diewald | 0ec142f | 2015-05-05 00:29:23 +0000 | [diff] [blame] | 235 | |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 236 | if (treeObj === null) { |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 237 | tree.addT('No data available.'); |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 238 | } |
| 239 | else { |
| 240 | tree.appendChild(treeObj.element()); |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 241 | treeObj.show(); |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 242 | |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 243 | // Reposition the view to the center |
| 244 | // (This may in a future release be a reposition |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 245 | // to move the root to the actual match) |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 246 | |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 247 | // This is currently not supported by relations |
| 248 | if (type === "spans") { |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 249 | var dl = d.createElement('li'); |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 250 | dl.className = 'download'; |
| 251 | dl.addEventListener( |
| 252 | 'click', function (e) { |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 253 | var a = treeObj.downloadLink(); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 254 | d.body.appendChild(a); |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 255 | a.click(); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 256 | d.body.removeChild(a) |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 257 | e.halt(); |
| 258 | } |
| 259 | ); |
| 260 | |
| 261 | actions.appendChild(dl); |
| 262 | }; |
| 263 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 264 | treeObj.center(); |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 265 | }; |
| 266 | |
| 267 | if (cb !== undefined) |
| 268 | cb(treeObj); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 269 | }); |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 270 | matchtree.classList.remove('loading'); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 271 | }, |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 272 | |
| 273 | |
Akron | e767969 | 2018-01-26 12:06:33 +0100 | [diff] [blame] | 274 | // Add meta information to match |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 275 | showMeta : function () { |
Akron | edbf33a | 2018-02-05 19:18:03 +0100 | [diff] [blame] | 276 | |
| 277 | // Already visible |
| 278 | if (this._visibleMeta) |
| 279 | return; |
| 280 | |
| 281 | this._visibleMeta = true; |
| 282 | |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 283 | var metaTable = document.createElement('div'); |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 284 | metaTable.classList.add('metatable', 'loading'); |
| 285 | this.element().appendChild(metaTable); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 286 | |
| 287 | // TODO: This is part of the getMeta! |
| 288 | var metaInfo = this._match.element().getAttribute('data-info'); |
| 289 | |
| 290 | if (metaInfo) |
| 291 | metaInfo = JSON.parse(metaInfo); |
| 292 | |
Akron | edbf33a | 2018-02-05 19:18:03 +0100 | [diff] [blame] | 293 | var that = this; |
| 294 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 295 | // There is metainfo |
| 296 | if (metaInfo) { |
| 297 | |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 298 | // Load data |
| 299 | metaTable.classList.remove('loading'); |
| 300 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 301 | // Add metainfo to matchview |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 302 | var metaElem = matchMetaClass.create(this._match).element(metaInfo); |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 303 | metaTable.appendChild(metaElem); |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 304 | |
| 305 | // Add button |
| 306 | this._addButton('close', metaTable, function (e) { |
| 307 | this.parentNode.removeChild(this); |
Akron | edbf33a | 2018-02-05 19:18:03 +0100 | [diff] [blame] | 308 | that._visibleMeta = false; |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 309 | e.halt(); |
| 310 | }); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 311 | }; |
Akron | 41387d2 | 2018-02-02 18:10:06 +0100 | [diff] [blame] | 312 | |
| 313 | // Load data |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 314 | metaTable.classList.remove('loading'); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 315 | }, |
| 316 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 317 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 318 | // Add table |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 319 | showTable : function () { |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 320 | |
Akron | edbf33a | 2018-02-05 19:18:03 +0100 | [diff] [blame] | 321 | // Already visible |
| 322 | if (this._visibleTable) |
| 323 | return; |
| 324 | |
| 325 | this._visibleTable = true; |
| 326 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 327 | // Append default table |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 328 | var matchtable = d.createElement('div'); |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 329 | matchtable.classList.add('matchtable', 'loading'); |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 330 | var info = this.element(); |
| 331 | info.appendChild(matchtable); |
| 332 | |
Akron | edbf33a | 2018-02-05 19:18:03 +0100 | [diff] [blame] | 333 | var that = this; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 334 | |
Akron | b6685bb | 2018-02-04 00:44:47 +0100 | [diff] [blame] | 335 | // TODO: |
| 336 | // Create try-catch-exception-handling |
| 337 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 338 | // Create the table asynchronous |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 339 | this.getTableData(undefined, function (table) { |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 340 | |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 341 | // Load data |
| 342 | matchtable.classList.remove('loading'); |
| 343 | |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 344 | if (table !== null) { |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 345 | matchtable.appendChild(table.element()); |
| 346 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 347 | }); |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 348 | |
| 349 | // Add button |
| 350 | this._addButton('close', matchtable, function (e) { |
| 351 | this.parentNode.removeChild(this); |
Akron | edbf33a | 2018-02-05 19:18:03 +0100 | [diff] [blame] | 352 | that._visibleTable = false; |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 353 | e.halt(); |
| 354 | }); |
| 355 | |
| 356 | // Load data |
| 357 | matchtable.classList.remove('loading'); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 358 | }, |
| 359 | |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 360 | // Add action button |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 361 | _addButton : function (buttonType, element, cb) { |
| 362 | // TODO: Unless existent |
| 363 | var actions = document.createElement('ul'); |
| 364 | actions.classList.add('action', 'image'); |
| 365 | var b = actions.addE('li'); |
| 366 | b.className = buttonType; |
| 367 | b.addE('span').addT(buttonType); |
| 368 | b.addEventListener( |
| 369 | 'click', cb.bind(element) |
| 370 | ); |
| 371 | |
| 372 | element.appendChild(actions); |
| 373 | return actions; |
| 374 | }, |
| 375 | |
| 376 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 377 | /** |
| 378 | * Create match information view. |
| 379 | */ |
| 380 | element : function () { |
| 381 | |
| 382 | if (this._element !== undefined) |
| 383 | return this._element; |
| 384 | |
| 385 | // Create info table |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 386 | var info = d.createElement('div'); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 387 | info.classList.add('matchinfo'); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 388 | |
| 389 | this._element = info; |
| 390 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 391 | return this._element; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 392 | } |
| 393 | }; |
| 394 | }); |