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