|  |  |  | 
|---|
|  |  |  | function ResultsTable(id, container) { | 
|---|
|  |  |  | function ResultsTable(id, container, editPlayerCallback, editResultCallback) { | 
|---|
|  |  |  | this.id = id; | 
|---|
|  |  |  | this.players = []; | 
|---|
|  |  |  | this.results = []; | 
|---|
|  |  |  | this.store = window.sessionStorage; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(!editPlayerCallback) { | 
|---|
|  |  |  | editPlayerCallback = this._editPlayerCallback; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.editPlayerCallback = editPlayerCallback; | 
|---|
|  |  |  | if(!editResultCallback) { | 
|---|
|  |  |  | editResultCallback = this._editResultCallback; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.editResultCallback = editResultCallback; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | container.appendChild(this._createTable()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | th.innerText = name; | 
|---|
|  |  |  | th.onclick = function(self) { return function() { | 
|---|
|  |  |  | var originalName = th.innerText; | 
|---|
|  |  |  | var result = prompt('Podaj nowe inicjały gracza. Wyczyść pole, by go usunąć.', name); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | self.editPlayerCallback( | 
|---|
|  |  |  | originalName, | 
|---|
|  |  |  | function (result) { | 
|---|
|  |  |  | if(result == null) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var index = self.players.indexOf(originalName); | 
|---|
|  |  |  | self.players = self.players.splice(index, 1); | 
|---|
|  |  |  | self.results = self.results.splice(index, 1); | 
|---|
|  |  |  | self.players.splice(index, 1); | 
|---|
|  |  |  | self.results.splice(index, 1); | 
|---|
|  |  |  | self.refresh(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } }(this); | 
|---|
|  |  |  | return th; | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | 
|---|
|  |  |  | this.results[i].push(result[i]); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.refresh(); | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | ResultsTable.prototype._editPlayerCallback = function(name, callback) { | 
|---|
|  |  |  | var result = prompt('Podaj nowe inicjały gracza. Wyczyść pole, by go usunąć.', name); | 
|---|
|  |  |  | if(result) { | 
|---|
|  |  |  | callback(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | ResultsTable.prototype._editResultCallback = function(value, callback) { | 
|---|
|  |  |  | var result = prompt('Podaj nową wartość:', value); | 
|---|
|  |  |  | if(result) { | 
|---|
|  |  |  | callback(result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | ResultsTable.prototype.refresh = function() { | 
|---|
|  |  |  | this.save(); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for(var i = 0; i < this.results.length; i++) { | 
|---|
|  |  |  | var td = document.createElement('th'); | 
|---|
|  |  |  | td.innerText = this.results[i].reduce(function(a, b) { return (parseInt(a, 10) || 0)+(parseInt(b, 10) || 0); }, 0); | 
|---|
|  |  |  | td.innerText = this.results[i].reduce( | 
|---|
|  |  |  | function(a, b) { return (parseInt(a, 10) || 0)+(parseInt(b, 10) || 0); }, 0 | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | this.tresults.appendChild(td); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | var td = document.createElement('td'); | 
|---|
|  |  |  | td.innerText = this.results[j][i]; | 
|---|
|  |  |  | td.onclick = function(j, i, self) { return function() { | 
|---|
|  |  |  | var result = prompt('Podaj nową wartość:', self.results[j][i]); | 
|---|
|  |  |  | if(result != null) { | 
|---|
|  |  |  | self.results[j][i] = result; | 
|---|
|  |  |  | self.editResultCallback( | 
|---|
|  |  |  | self.results[j][i], | 
|---|
|  |  |  | function (value) { | 
|---|
|  |  |  | self.results[j][i] = value; | 
|---|
|  |  |  | self.refresh(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } }(j, i, this); | 
|---|
|  |  |  | tr.appendChild(td); | 
|---|
|  |  |  | } | 
|---|