diff --git a/html/templates/ship/ship_modal.html b/html/templates/ship/ship_modal.html index 0c8b464..447f60c 100644 --- a/html/templates/ship/ship_modal.html +++ b/html/templates/ship/ship_modal.html @@ -1,5 +1,19 @@ -
-

Bienvenue sur SkamCraft

-

Application client pour l'API Space Tarders.

-
+
+ +

+

+

+

+

+

+

+

+

+

+

+

+
+ +
+
\ No newline at end of file diff --git a/js/controllers/ships.js b/js/controllers/ships.js index 9fd3da7..954653c 100644 --- a/js/controllers/ships.js +++ b/js/controllers/ships.js @@ -9,27 +9,44 @@ export default (temp_engine) => { menu_mod(temp_engine); modal.load("templates/ship/ship_modal.html"); - Ship.list((ship) => { - ship.data.forEach(data => { - console.log(data) - $(".ships").html( + Ship.list((ships) => { + ships.forEach(ship => { + $(".ships").append( `
-
${data.symbol}
-

fuel capacity: ${data.fuel.capacity}

-
` ) + temp_engine.add_event("#FT", "click", (e) => { + const id_ship = $(e.target).attr("data-symbol"); + if(ship.symbol=id_ship) + { + $(".Ship-id").text("ID : " + ship.symbol); + $(".Ship-registration").text("Registration : " + ship.registration); + $(".Ship-nav").text("Nav : " + ship.nav); + $(".Ship-crew").text("Crew : " + ship.crew); + $(".Ship-frame").text("Frame : " + ship.frame ); + $(".Ship-reactor").text("Reactor : " + ship.reactor ); + $(".Ship-engine").text("Engine : " + ship.engine); + $(".Ship-cooldown").text("Cooldown : " + ship.cooldown); + $(".Ship-modules").text("Modules : " + ship.modules ); + $(".Ship-mounts").text("Mounts : " + ship.mounts ); + $(".Ship-cargo").text("Cargo : " + ship.cargo); + $(".Ship-fuel").text("Fuel : " + ship.fuel); + } + modal.show(); + }); }); + }); - temp_engine.add_event("#btn-close", "click", () => { + temp_engine.add_event(".btn-close", "click", () => { modal.close(); }); - temp_engine.add_event("#FT", "click", () => { - modal.show(); - }); + }); diff --git a/js/skama_code/api/ship.js b/js/skama_code/api/ship.js index fcdfbaf..ce44eb2 100644 --- a/js/skama_code/api/ship.js +++ b/js/skama_code/api/ship.js @@ -5,11 +5,17 @@ import { My } from "./agent.js"; export class Ship { constructor(data) { - this.name = data.symbol; - this.AgentName = data.registration; - this.Nav = data.nav; + this.symbol = data.symbol; + this.registration = data.registration; + this.nav = data.nav; this.crew = data.crew; + this.frame = data.frame; + this.reactor = data.reactor; this.engine = data.engine; + this.cooldown = data.cooldown; + this.modules = data.modules; + this.mounts = data.mounts; + this.cargo = data.cargo; this.fuel = data.fuel; } @@ -23,27 +29,32 @@ export class Ship { Authorization: `Bearer ${My.agent.token}`, }, success: (response) => { - callback(response); + let listShips = []; + response.data.forEach(ship => { + listShips.push(new Ship(ship)) + + }); + callback(listShips); }, error: (err) => { error_handler(["Token invalide."]); }, }); } - static get(callback) { - const url = `${SpaceTraders.host}/my/ships/${this.name}`; + static get(shipSymbol, callback, error_handler) { + const url = `${SpaceTraders.host}/my/ships/${shipSymbol}`; $.ajax({ url: url, method: "GET", headers: { Accept: "application/json", - Authorization: `Bearer ${token}`, + Authorization: `Bearer ${My.agent.token}`, }, success: (response) => { - callback(response); + callback(new Ship(response.data)); }, error: (err) => { - error_handler(["Token invalide."]); + error_handler(err); }, }); }