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