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