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