From c88da0805f5090e2c0a9c6957a3edf29d05a34b4 Mon Sep 17 00:00:00 2001 From: unknown <13521043@std.stei.itb.ac.id> Date: Thu, 16 Nov 2023 22:02:53 +0700 Subject: [PATCH] feat: ajax for acc and reject trainer --- src/admin/gym/index.php | 4 +- src/public/javascript/gym/application.js | 94 ++++++++++++------------ 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/admin/gym/index.php b/src/admin/gym/index.php index f1bad41..0572d0a 100644 --- a/src/admin/gym/index.php +++ b/src/admin/gym/index.php @@ -121,8 +121,8 @@ AuthMiddleware::getInstance()->secureRoute(true); <script src="/public/javascript/gym/trainer.js"></script> <script> // getGymTrainers(<?php echo $gym_id ?>); - // getGymApplication(<?php echo $gym_id ?>); - getTrainersByGymId(<?php echo $gym_id ?>); + getGymApplication(<?php echo $gym_id ?>); + // getTrainersByGymId(<?php echo $gym_id ?>); </script> </body> diff --git a/src/public/javascript/gym/application.js b/src/public/javascript/gym/application.js index 71b51be..c930a01 100644 --- a/src/public/javascript/gym/application.js +++ b/src/public/javascript/gym/application.js @@ -4,23 +4,6 @@ function hidePopupRej() { document.querySelector(`#pop-up-reject`).style.display function showPopupRej() { document.querySelector(`#pop-up-reject`).style.display = "flex";} // dummy data -// let trainer = { -// username: "johndoe", -// gym_id: 43, -// acceptance: 0, -// trainer_name: "John Doe", -// trainer_description: "Aku ingin bekerja", -// application_description: "Aku ingin bekerja di sebuah gym, aku memiliki semangat di gym 43 ini semoga bisa keterima. Sekian dan terima kasih atas perhatian dan kesan dan pesannya", -// } -// let trainer2 = { -// username: "johndoedfdf", -// gym_id: 43, -// acceptance: 0, -// trainer_name: "John Doe", -// trainer_description: "Aku ingin bekerja", -// application_description: "Aku ingin bekerja", -// } -// let data = [trainer, trainer2]; const response = `<?xml version="1.0"?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> @@ -98,43 +81,62 @@ function getApplication(username, gymId) { xhr.send(soapBody); } -function acceptApplication(username, gymId) { - alert("ajax : accept with username: " + username + " and gym id: " + gymId); +function acceptApplication(gymId, username) { + hidePopupAcc() const xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { - if (this.readyState === 4) { - if (this.status === 200) { - alert("accept with username: " + username + " and gym id: " + gymId); - - } else { - const json = JSON.parse(this.responseText); - alert(json["error"]); - } + if (this.readyState === 4) { + if (this.status === 200) { + alert("accept with username: " + username + " and gym id: " + gymId + "\n" + "Email has been sent to the trainer"); + } else { + const xml = this.responseXML; + console.log("error status : " + this.status + " error text : " + xml); + } } - }; - - // xhr.open("GET", `/api/gym/rating?gym_id=${gymId}`, true); - // xhr.setRequestHeader("X-API-KEY", apikey); - xhr.send(); + }; + + const soapBody = `<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> + <Body> + <accept xmlns="http://service.gymtracker.com/"> + <username xmlns="">${username}</username> + <gym_id xmlns="">${gymId}</gym_id> + </accept> + </Body> + </Envelope>`; + + xhr.open("POST", soapurl, true); + xhr.setRequestHeader("Content-Type", "text/xml"); + xhr.setRequestHeader("Authorization", soapkey); + xhr.send(soapBody); } -function rejectApplication(username, gymId) { - alert("ajax : reject with username: " + username + " and gym id: " + gymId); +function rejectApplication(gymId, username) { + hidePopupRej() const xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { - if (this.readyState === 4) { - if (this.status === 200) { - alert("reject with username: " + username + " and gym id: " + gymId); - - } else { - const json = JSON.parse(this.responseText); - alert(json["error"]); - } + if (this.readyState === 4) { + if (this.status === 200) { + alert("reject with username: " + username + " and gym id: " + gymId + "\n" + "Email has been sent to the trainer"); + } else { + const xml = this.responseXML; + console.log("error status : " + this.status + " error text : " + xml); + } } - }; - // xhr.open("GET", `/api/gym/rating?gym_id=${gymId}`, true); - // xhr.setRequestHeader("X-API-KEY", apikey); - xhr.send(); + }; + + const soapBody = `<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> + <Body> + <reject xmlns="http://service.gymtracker.com/"> + <username xmlns="">${username}</username> + <gym_id xmlns="">${gymId}</gym_id> + </reject> + </Body> + </Envelope>`; + + xhr.open("POST", soapurl, true); + xhr.setRequestHeader("Content-Type", "text/xml"); + xhr.setRequestHeader("Authorization", soapkey); + xhr.send(soapBody); } function modifyGymApplicationList(data) { -- GitLab