[core] passcode contents are displayed correctly

Includes some other small fixes regarding passcodes.

Fixes #883
This commit is contained in:
fkloft 2014-10-05 22:24:15 +02:00
parent 2ec481b673
commit c4117b3c29
2 changed files with 37 additions and 25 deletions

View File

@ -389,6 +389,9 @@ window.setupPlayerStat = function() {
var level = PLAYER.verified_level; var level = PLAYER.verified_level;
PLAYER.level = level; //for historical reasons IITC expects PLAYER.level to contain the current player level PLAYER.level = level; //for historical reasons IITC expects PLAYER.level to contain the current player level
var n = window.PLAYER.nickname;
PLAYER.nickMatcher = new RegExp('\\b('+n+')\\b', 'ig');
var ap = parseInt(PLAYER.ap); var ap = parseInt(PLAYER.ap);
var thisLvlAp = parseInt(PLAYER.min_ap_for_current_level); var thisLvlAp = parseInt(PLAYER.min_ap_for_current_level);
var nextLvlAp = parseInt(PLAYER.min_ap_for_next_level); var nextLvlAp = parseInt(PLAYER.min_ap_for_next_level);
@ -601,10 +604,6 @@ function boot() {
} }
urlPortal = getURLParam('pguid'); urlPortal = getURLParam('pguid');
// load only once
var n = window.PLAYER['nickname'];
window.PLAYER['nickMatcher'] = new RegExp('\\b('+n+')\\b', 'ig');
$('#sidebar').show(); $('#sidebar').show();
if(window.bootPlugins) { if(window.bootPlugins) {
@ -654,7 +653,7 @@ function boot() {
window.runOnSmartphonesAfterBoot(); window.runOnSmartphonesAfterBoot();
// workaround for #129. Not sure why this is required. // workaround for #129. Not sure why this is required.
// setTimeout('window.map.invalidateSize(false);', 500); // setTimeout('window.map.invalidateSize(false);', 500);
window.iitcLoaded = true; window.iitcLoaded = true;
window.runHooks('iitcLoaded'); window.runHooks('iitcLoaded');

View File

@ -1,8 +1,6 @@
// REDEEMING /////////////////////////////////////////////////////// // REDEEMING ///////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// TODO remove lots of unused code from the old redeeming method
window.REDEEM_SHORT_NAMES = { window.REDEEM_SHORT_NAMES = {
'portal shield':'S', 'portal shield':'S',
'force amp':'FA', 'force amp':'FA',
@ -27,15 +25,29 @@ window.REDEEM_STATUSES = {
}; };
window.handleRedeemResponse = function(data, textStatus, jqXHR) { window.handleRedeemResponse = function(data, textStatus, jqXHR) {
var passcode = this.passcode; var passcode = jqXHR.passcode;
if(data.error) { if(data.error) {
console.error('Error redeeming passcode "'+passcode+'": ' + data.error)
dialog({ dialog({
title: 'Error: ' + passcode, title: 'Error: ' + passcode,
html: '<strong>' + data.error + '</strong>' html: '<strong>' + data.error + '</strong>'
}); });
return; return;
} }
if(!data.rewards) {
console.error('Error redeeming passcode "'+passcode+'": ', data)
dialog({
title: 'Error: ' + passcode,
html: '<strong>An unexpected error occured</strong>'
});
return;
}
if(data.playerData) {
window.PLAYER = data.playerData;
window.setupPlayerStat();
}
var format = "long"; var format = "long";
try { try {
@ -49,9 +61,8 @@ window.handleRedeemResponse = function(data, textStatus, jqXHR) {
if(!formatHandlers[format]) if(!formatHandlers[format])
format = "long"; format = "long";
var html = formatHandlers[format](data); var html = formatHandlers[format](data.rewards);
var that = this;
var buttons = {}; var buttons = {};
Object.keys(formatHandlers).forEach(function(label) { Object.keys(formatHandlers).forEach(function(label) {
if(label == format) return; if(label == format) return;
@ -59,7 +70,7 @@ window.handleRedeemResponse = function(data, textStatus, jqXHR) {
buttons[label.toUpperCase()] = function() { buttons[label.toUpperCase()] = function() {
$(this).dialog("close"); $(this).dialog("close");
localStorage["iitc-passcode-format"] = label; localStorage["iitc-passcode-format"] = label;
handleRedeemResponse.call(that, data, textStatus, jqXHR); handleRedeemResponse(data, textStatus, jqXHR);
} }
}); });
@ -154,21 +165,23 @@ window.formatPasscodeShort = function(data) {
window.setupRedeem = function() { window.setupRedeem = function() {
$("#redeem").keypress(function(e) { $("#redeem").keypress(function(e) {
if((e.keyCode ? e.keyCode : e.which) !== 13 || !$(this).val()) return; if((e.keyCode ? e.keyCode : e.which) !== 13) return;
var data = {passcode: $(this).val()};
window.postAjax('redeemReward', data, window.handleRedeemResponse, var passcode = $(this).val();
function(response) { if(!passcode) return;
var extra = '';
if(response.status) { var jqXHR = window.postAjax('redeemReward', {passcode:passcode}, window.handleRedeemResponse, function(response) {
extra = (window.REDEEM_STATUSES[response.status] || 'The server indicated an error.') + ' (HTTP ' + response.status + ')'; var extra = '';
} else { if(response.status) {
extra = 'No status code was returned.'; extra = (window.REDEEM_STATUSES[response.status] || 'The server indicated an error.') + ' (HTTP ' + response.status + ')';
} } else {
dialog({ extra = 'No status code was returned.';
title: 'Request failed: ' + data.passcode, }
html: '<strong>The HTTP request failed.</strong> ' + extra dialog({
}); title: 'Request failed: ' + data.passcode,
html: '<strong>The HTTP request failed.</strong> ' + extra
}); });
});
jqXHR.passcode = passcode;
}); });
}; };