X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=www%2Fjs%2Fremoteglot.js;fp=www%2Fjs%2Fremoteglot.js;h=7135953fb2298b579393d2a2668a28279fb59436;hp=870703c4edc7be33337cbc4212f63082ab5d8711;hb=b2779e155a09b1a3fcc2e132aaafbbbe4884ed49;hpb=a2249d895beb04196592e1b529bce35ed79fe210 diff --git a/www/js/remoteglot.js b/www/js/remoteglot.js index 870703c..7135953 100644 --- a/www/js/remoteglot.js +++ b/www/js/remoteglot.js @@ -2218,6 +2218,28 @@ function onDrop(source, target) { if (move === null) return 'snapback'; } +/** + * If we are in admin mode, send this move to the backend. + * + * @param {string} fen + * @param {string} move + */ +function send_chosen_move(fen, move) { + if (admin_password !== null) { + let history = current_analysis_data['position']['history']; + let url = '/manual-override.pl'; + url += '?fen=' + encodeURIComponent(fen); + url += '&history=' + encodeURIComponent(JSON.stringify(history)); + url += '&move=' + encodeURIComponent(move); + url += '&player_w=' + encodeURIComponent(current_analysis_data['position']['player_w']); + url += '&player_b=' + encodeURIComponent(current_analysis_data['position']['player_b']); + url += '&password=' + encodeURIComponent(admin_password); + + console.log(fen, history); + fetch(url); // Ignore the result. + } +} + function onSnapEnd(source, target) { if (source === target && recommended_move !== null) { source = recommended_move.from; @@ -2232,14 +2254,7 @@ function onSnapEnd(source, target) { }); if (admin_password !== null) { - let url = '/manual-override.pl'; - url += '?fen=' + encodeURIComponent(display_fen); - url += '&history=' + encodeURIComponent(JSON.stringify(current_analysis_data['position']['history'])); - url += '&move=' + encodeURIComponent(move.san); - url += '&player_w=' + encodeURIComponent(current_analysis_data['position']['player_w']); - url += '&player_b=' + encodeURIComponent(current_analysis_data['position']['player_b']); - url += '&password=' + encodeURIComponent(admin_password); - fetch(url); + send_chosen_move(display_fen, move.san); return; }