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 | |
Akron | 4f79144 | 2018-02-12 13:25:47 +0100 | [diff] [blame] | 118 | try { |
| 119 | // Get info (may be cached) |
| 120 | KorAP.API.getMatchInfo( |
| 121 | this._match, |
| 122 | { 'spans' : false, 'layer' : focus }, |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 123 | |
Akron | 4f79144 | 2018-02-12 13:25:47 +0100 | [diff] [blame] | 124 | // Callback for retrieval |
| 125 | function (matchResponse) { |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 126 | |
Akron | 4f79144 | 2018-02-12 13:25:47 +0100 | [diff] [blame] | 127 | if (matchResponse === undefined) |
| 128 | cb(null); |
Akron | 515851a | 2017-05-02 12:53:17 +0200 | [diff] [blame] | 129 | |
Akron | 4f79144 | 2018-02-12 13:25:47 +0100 | [diff] [blame] | 130 | // Get snippet from match info |
| 131 | if (matchResponse["snippet"] !== undefined) { |
| 132 | this._table = matchTableClass.create(matchResponse["snippet"]); |
| 133 | cb(this._table); |
| 134 | }; |
| 135 | }.bind(this) |
| 136 | ); |
| 137 | } |
| 138 | catch (e) { |
| 139 | KorAP.log(0, e); |
| 140 | cb(null); |
| 141 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 142 | |
| 143 | /* |
| 144 | // Todo: Store the table as a hash of the focus |
| 145 | return null; |
| 146 | */ |
| 147 | }, |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 148 | |
| 149 | |
Akron | 4f79144 | 2018-02-12 13:25:47 +0100 | [diff] [blame] | 150 | /** |
| 151 | * Receive meta data from server. |
| 152 | */ |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 153 | getMetaData : function (cb) { |
Akron | 4f79144 | 2018-02-12 13:25:47 +0100 | [diff] [blame] | 154 | try { |
| 155 | KorAP.API.getTextInfo( |
| 156 | this._match, {}, function (textResponse) { |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 157 | |
Akron | 4f79144 | 2018-02-12 13:25:47 +0100 | [diff] [blame] | 158 | if (textResponse === undefined) { |
| 159 | cb(null); |
| 160 | return; |
| 161 | }; |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 162 | |
Akron | 4f79144 | 2018-02-12 13:25:47 +0100 | [diff] [blame] | 163 | var doc = textResponse["document"]; |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 164 | |
Akron | 4f79144 | 2018-02-12 13:25:47 +0100 | [diff] [blame] | 165 | if (doc === undefined) { |
| 166 | cb(null); |
| 167 | return; |
| 168 | }; |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 169 | |
Akron | 4f79144 | 2018-02-12 13:25:47 +0100 | [diff] [blame] | 170 | var fields = doc["fields"]; |
| 171 | if (fields === undefined) { |
| 172 | cb(null); |
| 173 | return; |
| 174 | }; |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 175 | |
Akron | 4f79144 | 2018-02-12 13:25:47 +0100 | [diff] [blame] | 176 | // Add metainfo to matchview |
| 177 | cb(matchMetaClass.create( |
| 178 | this._match, fields |
| 179 | )); |
| 180 | } |
| 181 | ); |
| 182 | } |
| 183 | catch (e) { |
| 184 | KorAP.log(0, e); |
| 185 | cb(null); |
| 186 | }; |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 187 | }, |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 188 | |
| 189 | |
| 190 | /** |
| 191 | * Retrieve and parse snippet for tree representation |
| 192 | */ |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 193 | getTreeData : function (foundry, layer, type, cb) { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 194 | var focus = []; |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 195 | |
Akron | 4f79144 | 2018-02-12 13:25:47 +0100 | [diff] [blame] | 196 | try { |
| 197 | // TODO: Support and cache multiple trees |
| 198 | KorAP.API.getMatchInfo( |
| 199 | this._match, { |
| 200 | 'spans' : true, |
| 201 | 'foundry' : foundry, |
| 202 | 'layer' : layer |
| 203 | }, |
| 204 | function (matchResponse) { |
| 205 | if (matchResponse === undefined) { |
| 206 | cb(null); |
| 207 | return; |
| 208 | }; |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 209 | |
Akron | 4f79144 | 2018-02-12 13:25:47 +0100 | [diff] [blame] | 210 | // Get snippet from match info |
| 211 | if (matchResponse["snippet"] !== undefined) { |
| 212 | // Todo: This should be cached somehow |
| 213 | |
| 214 | if (type === "spans") { |
| 215 | cb(matchTreeHierarchyClass.create(matchResponse["snippet"])); |
| 216 | } |
| 217 | else if (type === "rels") { |
| 218 | cb(matchTreeArcClass.create(matchResponse["snippet"])); |
| 219 | } |
| 220 | |
| 221 | // Unknown tree type |
| 222 | else { |
| 223 | cb(null); |
| 224 | }; |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 225 | } |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 226 | else { |
| 227 | cb(null); |
| 228 | }; |
Akron | 4f79144 | 2018-02-12 13:25:47 +0100 | [diff] [blame] | 229 | }.bind(this) |
| 230 | ); |
| 231 | } |
| 232 | catch (e) { |
| 233 | KorAP.log(0, e); |
| 234 | cb(null); |
| 235 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 236 | }, |
| 237 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 238 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 239 | /** |
| 240 | * Destroy this match information view. |
| 241 | */ |
| 242 | destroy : function () { |
| 243 | |
| 244 | // Remove circular reference |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 245 | /* |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 246 | if (this._treeMenu !== undefined) |
Akron | 99713ef | 2017-06-28 18:19:28 +0200 | [diff] [blame] | 247 | delete this._treeMenu["info"]; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 248 | |
| 249 | this._treeMenu.destroy(); |
| 250 | this._treeMenu = undefined; |
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 251 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 252 | this._match = undefined; |
Akron | 99713ef | 2017-06-28 18:19:28 +0200 | [diff] [blame] | 253 | this._matchCreator = undefined; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 254 | // Element destroy |
| 255 | }, |
| 256 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 257 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 258 | /** |
| 259 | * Add a new tree view to the list |
| 260 | */ |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 261 | showTree : function (foundry, layer, type, cb) { |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 262 | var matchtree = d.createElement('div'); |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 263 | matchtree.classList.add('matchtree', 'loading'); |
| 264 | |
| 265 | this.element().appendChild(matchtree); |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 266 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 267 | // Add title line |
| 268 | var h6 = matchtree.addE('h6'); |
| 269 | h6.addE('span').addT(foundry); |
| 270 | h6.addE('span').addT(layer); |
| 271 | |
| 272 | var tree = matchtree.addE('div'); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 273 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 274 | // Add close action button |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 275 | var actions = this._addButton('close', matchtree, function (e) { |
| 276 | this.parentNode.removeChild(this); |
| 277 | e.halt(); |
| 278 | }); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 279 | |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 280 | // tree.classList.add('loading'); // alternatively |
Nils Diewald | 0ec142f | 2015-05-05 00:29:23 +0000 | [diff] [blame] | 281 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 282 | // Get tree data async |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 283 | this.getTreeData(foundry, layer, type, function (treeObj) { |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 284 | matchtree.classList.remove('loading'); |
Nils Diewald | 0ec142f | 2015-05-05 00:29:23 +0000 | [diff] [blame] | 285 | |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 286 | // Something went wrong - probably log!!! |
Nils Diewald | 0ec142f | 2015-05-05 00:29:23 +0000 | [diff] [blame] | 287 | |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 288 | if (treeObj === null) { |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 289 | tree.addT('No data available.'); |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 290 | } |
| 291 | else { |
| 292 | tree.appendChild(treeObj.element()); |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 293 | treeObj.show(); |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 294 | |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 295 | // Reposition the view to the center |
| 296 | // (This may in a future release be a reposition |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 297 | // to move the root to the actual match) |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 298 | |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 299 | // This is currently not supported by relations |
| 300 | if (type === "spans") { |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 301 | var dl = d.createElement('li'); |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 302 | dl.className = 'download'; |
| 303 | dl.addEventListener( |
| 304 | 'click', function (e) { |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 305 | var a = treeObj.downloadLink(); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 306 | d.body.appendChild(a); |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 307 | a.click(); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 308 | d.body.removeChild(a) |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 309 | e.halt(); |
| 310 | } |
| 311 | ); |
| 312 | |
| 313 | actions.appendChild(dl); |
| 314 | }; |
| 315 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 316 | treeObj.center(); |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 317 | }; |
| 318 | |
| 319 | if (cb !== undefined) |
| 320 | cb(treeObj); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 321 | }); |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 322 | matchtree.classList.remove('loading'); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 323 | }, |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 324 | |
| 325 | |
Akron | e767969 | 2018-01-26 12:06:33 +0100 | [diff] [blame] | 326 | // Add meta information to match |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 327 | showMeta : function () { |
Akron | edbf33a | 2018-02-05 19:18:03 +0100 | [diff] [blame] | 328 | |
| 329 | // Already visible |
| 330 | if (this._visibleMeta) |
| 331 | return; |
| 332 | |
| 333 | this._visibleMeta = true; |
| 334 | |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 335 | var metaTable = document.createElement('div'); |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 336 | metaTable.classList.add('metatable', 'loading'); |
| 337 | this.element().appendChild(metaTable); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 338 | |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 339 | /* |
| 340 | * This was temporary |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 341 | var metaInfo = this._match.element().getAttribute('data-info'); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 342 | if (metaInfo) |
| 343 | metaInfo = JSON.parse(metaInfo); |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 344 | */ |
Akron | edbf33a | 2018-02-05 19:18:03 +0100 | [diff] [blame] | 345 | var that = this; |
| 346 | |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 347 | this.getMetaData(function (meta) { |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 348 | // Load data |
| 349 | metaTable.classList.remove('loading'); |
| 350 | |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 351 | metaTable.appendChild(meta.element()); |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 352 | |
| 353 | // Add button |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 354 | that._addButton('close', metaTable, function (e) { |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 355 | this.parentNode.removeChild(this); |
Akron | edbf33a | 2018-02-05 19:18:03 +0100 | [diff] [blame] | 356 | that._visibleMeta = false; |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 357 | e.halt(); |
| 358 | }); |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 359 | }); |
Akron | 41387d2 | 2018-02-02 18:10:06 +0100 | [diff] [blame] | 360 | |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 361 | // Do not load any longer |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 362 | metaTable.classList.remove('loading'); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 363 | }, |
| 364 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 365 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 366 | // Add table |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 367 | showTable : function () { |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 368 | |
Akron | edbf33a | 2018-02-05 19:18:03 +0100 | [diff] [blame] | 369 | // Already visible |
| 370 | if (this._visibleTable) |
| 371 | return; |
| 372 | |
| 373 | this._visibleTable = true; |
| 374 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 375 | // Append default table |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 376 | var matchtable = d.createElement('div'); |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 377 | matchtable.classList.add('matchtable', 'loading'); |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 378 | var info = this.element(); |
| 379 | info.appendChild(matchtable); |
| 380 | |
Akron | edbf33a | 2018-02-05 19:18:03 +0100 | [diff] [blame] | 381 | var that = this; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 382 | |
Akron | b6685bb | 2018-02-04 00:44:47 +0100 | [diff] [blame] | 383 | // TODO: |
| 384 | // Create try-catch-exception-handling |
| 385 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 386 | // Create the table asynchronous |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 387 | this.getTableData(undefined, function (table) { |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 388 | |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 389 | // Load data |
| 390 | matchtable.classList.remove('loading'); |
| 391 | |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 392 | if (table !== null) { |
Akron | 3bb91bc | 2016-12-02 16:43:17 +0100 | [diff] [blame] | 393 | matchtable.appendChild(table.element()); |
| 394 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 395 | }); |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 396 | |
| 397 | // Add button |
| 398 | this._addButton('close', matchtable, function (e) { |
| 399 | this.parentNode.removeChild(this); |
Akron | edbf33a | 2018-02-05 19:18:03 +0100 | [diff] [blame] | 400 | that._visibleTable = false; |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 401 | e.halt(); |
| 402 | }); |
| 403 | |
| 404 | // Load data |
| 405 | matchtable.classList.remove('loading'); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 406 | }, |
| 407 | |
Akron | c8eb4a1 | 2018-02-03 00:39:58 +0100 | [diff] [blame] | 408 | // Add action button |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 409 | _addButton : function (buttonType, element, cb) { |
| 410 | // TODO: Unless existent |
| 411 | var actions = document.createElement('ul'); |
| 412 | actions.classList.add('action', 'image'); |
| 413 | var b = actions.addE('li'); |
| 414 | b.className = buttonType; |
| 415 | b.addE('span').addT(buttonType); |
| 416 | b.addEventListener( |
| 417 | 'click', cb.bind(element) |
| 418 | ); |
| 419 | |
| 420 | element.appendChild(actions); |
| 421 | return actions; |
| 422 | }, |
| 423 | |
| 424 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 425 | /** |
| 426 | * Create match information view. |
| 427 | */ |
| 428 | element : function () { |
| 429 | |
| 430 | if (this._element !== undefined) |
| 431 | return this._element; |
| 432 | |
| 433 | // Create info table |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 434 | var info = d.createElement('div'); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 435 | info.classList.add('matchinfo'); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 436 | |
| 437 | this._element = info; |
| 438 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 439 | return this._element; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 440 | } |
| 441 | }; |
| 442 | }); |