Advertisement
Guest User

kur

a guest
Jun 16th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function updateOdds(id, home, away, draw) {
  2.     console.log(JSON.stringify({
  3.         home: home,
  4.         away: away,
  5.         draw: draw
  6.     }));
  7.  
  8.     $.ajax({
  9.         url: `/Events/UpdateOdds/${id}`,
  10.         type: 'put',
  11.         contentType: 'application/json',
  12.         data: JSON.stringify({
  13.             home: home,
  14.             away: away,
  15.             draw: draw
  16.         }),
  17.         success: function (data) {
  18.             console.log(data);
  19.             console.log("updated.");
  20.             location.reload();
  21.         },
  22.         error: function (err) {
  23.             console.log(err);
  24.         }
  25.     });
  26. }
  27.  
  28. $(document).ready(function () {
  29.     $("#changeFormat").unbind("click");
  30.     $("#changeFormat").bind("click", function () {
  31.         let current = getCookie("format");
  32.         if (current == "american") {
  33.             document.cookie = "format=decimal";
  34.         } else {
  35.             document.cookie = "format=american";
  36.         }
  37.         updateOddsFormat();
  38.     });
  39.  
  40.     let current = getCookie("format");
  41.  
  42.     if (current == "american") {
  43.         let away = Number($("#awayOdds").text());
  44.         let home = Number($("#homeOdds").text());
  45.         let draw = Number($("#drawOdds").text());
  46.  
  47.         $("#awayOdds").text(((away - 1) * 100).toFixed(2));
  48.         $("#homeOdds").text(((home - 1) * 100).toFixed(2));
  49.         $("#drawOdds").text(((draw - 1) * 100).toFixed(2));
  50.     }
  51. });
  52.  
  53. function updateOddsFormat() {
  54.     let current = getCookie("format");
  55.     let away = Number($("#awayOdds").text());
  56.     let home = Number($("#homeOdds").text());
  57.     let draw = Number($("#drawOdds").text());
  58.  
  59.     console.log(draw);
  60.  
  61.     if (current == "american") {
  62.         $("#awayOdds").text(((away - 1) * 100).toFixed(2));
  63.         $("#homeOdds").text(((home - 1) * 100).toFixed(2));
  64.         $("#drawOdds").text(((draw - 1) * 100).toFixed(2));
  65.     } else {                                  
  66.         $("#awayOdds").text(((away / 100) + 1).toFixed(2));
  67.         $("#homeOdds").text(((home / 100) + 1).toFixed(2));
  68.         $("#drawOdds").text(((draw / 100) + 1).toFixed(2));
  69.     }
  70. }
  71.  
  72. $("#drawOdds").bind("click", () => formify("drawOdds"));
  73. $("#awayOdds").bind("click", () => formify("awayOdds"));
  74. $("#homeOdds").bind("click", () => formify("homeOdds"));
  75.  
  76. function formify(id) {
  77.     let element = $(`#${id}`);
  78.     element.unbind("click");
  79.  
  80.     let text = element.text();
  81.  
  82.     element.text("");
  83.     element.append($('<div class="input-field">').append($("<input id='odds' class='validate min='0.1'>").attr("type", "number").css("width", "100px").css("display", "inherit")).on("keyup", function(event) {
  84.         if (event.key === "Enter") {
  85.             let val = $(`#${id} input`).val();
  86.             console.log(val);
  87.  
  88.             let away = Number($("#awayOdds").text());
  89.             let home = Number($("#homeOdds").text());
  90.             let draw = Number($("#drawOdds").text());
  91.  
  92.             if (Number.isNaN(away) || away == 0) {
  93.                 away = val;
  94.             }
  95.             if (Number.isNaN(home) || home == 0) {
  96.                 home = val;
  97.             }
  98.             if (Number.isNaN(draw) || draw == 0) {
  99.                 draw = val;
  100.             }
  101.  
  102.             console.log(away);
  103.             console.log(home);
  104.             console.log(draw);
  105.  
  106.             updateOdds($("#eventId").text(), home, away, draw);
  107.         }
  108.     }).append($('<label for="odds">Odds</label>'))
  109.         .append($('<span class="helper-text" data-error="Invalid value">Helper text</span>')));
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement