MAPG-133 replace XHRs to MapGuesser.httpRequest
This commit is contained in:
		
							parent
							
								
									25262fb5fe
								
							
						
					
					
						commit
						e4c7aadc64
					
				| @ -25,9 +25,7 @@ | |||||||
|             }); |             }); | ||||||
|             Game.map.fitBounds(mapBounds); |             Game.map.fitBounds(mapBounds); | ||||||
| 
 | 
 | ||||||
|             var xhr = new XMLHttpRequest(); |             MapGuesser.httpRequest('GET', '/game/' + mapId + '/newPlace.json', function () { | ||||||
|             xhr.responseType = 'json'; |  | ||||||
|             xhr.onload = function () { |  | ||||||
|                 document.getElementById('loading').style.visibility = 'hidden'; |                 document.getElementById('loading').style.visibility = 'hidden'; | ||||||
|                 document.getElementById('cover').style.visibility = 'hidden'; |                 document.getElementById('cover').style.visibility = 'hidden'; | ||||||
| 
 | 
 | ||||||
| @ -51,10 +49,7 @@ | |||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 Game.startNewRound(); |                 Game.startNewRound(); | ||||||
|             }; |             }); | ||||||
| 
 |  | ||||||
|             xhr.open('GET', '/game/' + mapId + '/newPlace.json', true); |  | ||||||
|             xhr.send(); |  | ||||||
|         }, |         }, | ||||||
| 
 | 
 | ||||||
|         reset: function () { |         reset: function () { | ||||||
| @ -127,16 +122,11 @@ | |||||||
|         handleErrorResponse: function (error) { |         handleErrorResponse: function (error) { | ||||||
|             // for the time being we only handle the "no_session_found" error and reset the game
 |             // for the time being we only handle the "no_session_found" error and reset the game
 | ||||||
| 
 | 
 | ||||||
|             var xhr = new XMLHttpRequest(); |             MapGuesser.httpRequest('GET', '/game/' + mapId + '/json', function () { | ||||||
|             xhr.responseType = 'json'; |  | ||||||
|             xhr.onload = function () { |  | ||||||
|                 mapBounds = this.response.bounds; |                 mapBounds = this.response.bounds; | ||||||
| 
 | 
 | ||||||
|                 Game.reset(); |                 Game.reset(); | ||||||
|             }; |             }); | ||||||
| 
 |  | ||||||
|             xhr.open('GET', '/game/' + mapId + '/json', true); |  | ||||||
|             xhr.send(); |  | ||||||
|         }, |         }, | ||||||
| 
 | 
 | ||||||
|         loadPano: function (panoId) { |         loadPano: function (panoId) { | ||||||
| @ -168,9 +158,7 @@ | |||||||
|             data.append('lat', String(guessPosition.lat)); |             data.append('lat', String(guessPosition.lat)); | ||||||
|             data.append('lng', String(guessPosition.lng)); |             data.append('lng', String(guessPosition.lng)); | ||||||
| 
 | 
 | ||||||
|             var xhr = new XMLHttpRequest(); |             MapGuesser.httpRequest('POST', '/game/' + mapId + '/guess.json', function () { | ||||||
|             xhr.responseType = 'json'; |  | ||||||
|             xhr.onload = function () { |  | ||||||
|                 if (this.response.error) { |                 if (this.response.error) { | ||||||
|                     Game.handleErrorResponse(this.response.error); |                     Game.handleErrorResponse(this.response.error); | ||||||
|                     return; |                     return; | ||||||
| @ -211,10 +199,7 @@ | |||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 Game.panoId = this.response.panoId; |                 Game.panoId = this.response.panoId; | ||||||
|             }; |             }, data); | ||||||
| 
 |  | ||||||
|             xhr.open('POST', '/game/' + mapId + '/guess.json', true); |  | ||||||
|             xhr.send(data); |  | ||||||
|         }, |         }, | ||||||
| 
 | 
 | ||||||
|         addRealGuessPair: function (position, guessPosition, hidden) { |         addRealGuessPair: function (position, guessPosition, hidden) { | ||||||
|  | |||||||
| @ -8,9 +8,7 @@ | |||||||
| 
 | 
 | ||||||
|         var formData = new FormData(form); |         var formData = new FormData(form); | ||||||
| 
 | 
 | ||||||
|         var xhr = new XMLHttpRequest(); |         MapGuesser.httpRequest('POST', form.action, function () { | ||||||
|         xhr.responseType = 'json'; |  | ||||||
|         xhr.onload = function () { |  | ||||||
|             if (this.response.error) { |             if (this.response.error) { | ||||||
|                 var errorText; |                 var errorText; | ||||||
|                 switch (this.response.error) { |                 switch (this.response.error) { | ||||||
| @ -34,9 +32,6 @@ | |||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             window.location.replace('/'); |             window.location.replace('/'); | ||||||
|         }; |         }, formData); | ||||||
| 
 |  | ||||||
|         xhr.open('POST', form.action, true); |  | ||||||
|         xhr.send(formData); |  | ||||||
|     }; |     }; | ||||||
| })(); | })(); | ||||||
|  | |||||||
| @ -28,9 +28,7 @@ | |||||||
|         }, |         }, | ||||||
| 
 | 
 | ||||||
|         getPlace: function (placeId, marker) { |         getPlace: function (placeId, marker) { | ||||||
|             var xhr = new XMLHttpRequest(); |             MapGuesser.httpRequest('GET', '/admin/place.json/' + placeId, function () { | ||||||
|             xhr.responseType = 'json'; |  | ||||||
|             xhr.onload = function () { |  | ||||||
|                 document.getElementById('loading').style.visibility = 'hidden'; |                 document.getElementById('loading').style.visibility = 'hidden'; | ||||||
| 
 | 
 | ||||||
|                 if (!this.response.panoId) { |                 if (!this.response.panoId) { | ||||||
| @ -46,10 +44,7 @@ | |||||||
|                 places[marker.placeId].noPano = false; |                 places[marker.placeId].noPano = false; | ||||||
| 
 | 
 | ||||||
|                 MapEditor.loadPano(this.response.panoId, places[marker.placeId].pov); |                 MapEditor.loadPano(this.response.panoId, places[marker.placeId].pov); | ||||||
|             }; |             }); | ||||||
| 
 |  | ||||||
|             xhr.open('GET', '/admin/place.json/' + placeId, true); |  | ||||||
|             xhr.send(); |  | ||||||
|         }, |         }, | ||||||
| 
 | 
 | ||||||
|         loadPano: function (panoId, pov) { |         loadPano: function (panoId, pov) { | ||||||
| @ -284,9 +279,7 @@ | |||||||
|                 data.append('deleted[]', JSON.stringify(MapEditor.deleted[placeId])); |                 data.append('deleted[]', JSON.stringify(MapEditor.deleted[placeId])); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             var xhr = new XMLHttpRequest(); |             MapGuesser.httpRequest('POST', '/admin/saveMap/' + mapId + '/json', function () { | ||||||
|             xhr.responseType = 'json'; |  | ||||||
|             xhr.onload = function () { |  | ||||||
|                 document.getElementById('loading').style.visibility = 'hidden'; |                 document.getElementById('loading').style.visibility = 'hidden'; | ||||||
| 
 | 
 | ||||||
|                 if (this.response.error) { |                 if (this.response.error) { | ||||||
| @ -310,10 +303,7 @@ | |||||||
|                 document.getElementById('deleted').innerHTML = '0'; |                 document.getElementById('deleted').innerHTML = '0'; | ||||||
| 
 | 
 | ||||||
|                 document.getElementById('saveButton').disabled = true; |                 document.getElementById('saveButton').disabled = true; | ||||||
|             }; |             }, data); | ||||||
| 
 |  | ||||||
|             xhr.open('POST', '/admin/saveMap/' + mapId + '/json', true); |  | ||||||
|             xhr.send(data); |  | ||||||
|         }, |         }, | ||||||
| 
 | 
 | ||||||
|         replacePlaceIdsToReal: function (addedPlaces) { |         replacePlaceIdsToReal: function (addedPlaces) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user