From 285233c3b8dccb5bb424511ccfad5f48271710d2 Mon Sep 17 00:00:00 2001
From: "Benjamin.sitbon" <benjamin.sitbon@etu.hesge.ch>
Date: Sun, 9 May 2021 16:05:31 +0200
Subject: [PATCH] =?UTF-8?q?impl=C3=A9mentation=20du=20sac=20termin=C3=A9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 frontend/cart.css      | 13 +++++++++++++
 frontend/js/bag.js     | 42 +++++++++++++++++++++++++++++++++++-------
 frontend/js/product.js |  9 ++++++---
 3 files changed, 54 insertions(+), 10 deletions(-)

diff --git a/frontend/cart.css b/frontend/cart.css
index 8de31bf..5df317a 100644
--- a/frontend/cart.css
+++ b/frontend/cart.css
@@ -99,4 +99,17 @@ main{
     transform: translateX(-50%);
     margin-bottom: 5vh;
     margin-top: 5vh;
+}
+
+
+.price {
+    
+    display: flex;
+    flex-direction: column;
+    justify-content: center;
+    font-size: 1.5vw;
+    margin-left: 1vw;
+    margin-right: 1vw;
+
+
 }
\ No newline at end of file
diff --git a/frontend/js/bag.js b/frontend/js/bag.js
index 1461139..546ae8d 100644
--- a/frontend/js/bag.js
+++ b/frontend/js/bag.js
@@ -27,6 +27,24 @@ function typeBox(src1,src2){
 }
 
 
+function toDeleteArticle(poke,name){
+    let x = document.createElement("img");
+    x.className = "x";
+    x.src ="img/x.png";
+    x.style.cursor = "pointer";
+
+    x.onclick = function(){
+
+        poke.remove()
+        localStorage.removeItem(name);
+        document.getElementById("number").innerHTML = localStorage.length-1;
+
+    }
+
+    return x;
+}
+
+
 function createArticle(name,number,type1,type2,attacks,talent,shiny){
 
     let container = document.getElementById("container");
@@ -35,7 +53,19 @@ function createArticle(name,number,type1,type2,attacks,talent,shiny){
     pokemon.className = "pokemon";
 
     let img = document.createElement("img");
-    img.src = "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/" + number + ".png";
+
+    let price = document.createElement("p");
+    price.className = "price";
+
+    if(shiny == 1){
+        img.src = "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/shiny/" + number + ".png";
+        price.innerHTML = "4.00 CHF";
+    }
+    else{
+        img.src = "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/" + number + ".png";
+        price.innerHTML = "2.00 CHF";
+    }
+
     img.style.width = "8vw";
     img.style.height ="8vw";
 
@@ -56,11 +86,7 @@ function createArticle(name,number,type1,type2,attacks,talent,shiny){
     talentName.className = "text";
     talentName.innerHTML = talent;
     
-    let x = document.createElement("img");
-    x.className = "x";
-    x.src ="img/x.png";
-
-
+    let x = toDeleteArticle(pokemon,name);
 
     typeAndName.appendChild(pokname);
     typeAndName.appendChild(typebox);
@@ -81,6 +107,7 @@ function createArticle(name,number,type1,type2,attacks,talent,shiny){
     }
 
     pokemon.appendChild(talentName)
+    pokemon.appendChild(price);
     
 
     container.appendChild(pokemon);
@@ -106,8 +133,9 @@ for(let i = 0; i<localStorage.length; i++){
     else{
 
         let data = getItem(i).split(',');
+        console.log(data[9]);
         let attacks = [data[4],data[5],data[6],data[7]];
-        createArticle(data[0],data[1],data[2],data[3],attacks,data[8],0)
+        createArticle(data[0],data[1],data[2],data[3],attacks,data[8],data[9])
 
     }
 
diff --git a/frontend/js/product.js b/frontend/js/product.js
index 6c1efe5..d0c800e 100644
--- a/frontend/js/product.js
+++ b/frontend/js/product.js
@@ -67,8 +67,13 @@
                     let attack2 = choice.children[1].children[2].innerHTML;
                     let attack3 = choice.children[2].children[2].innerHTML;
                     let attack4 = choice.children[3].children[2].innerHTML;
+                    let shiny = 0;
+
+                    if(document.getElementsByClassName("btn-2")[0] != undefined){
+                        shiny = 1;
+                    }
         
-                    newData = [pokemon,number,data[1],data[2],attack1,attack2,attack3,attack4,talent];
+                    newData = [pokemon,number,data[1],data[2],attack1,attack2,attack3,attack4,talent,shiny];
         
                     localStorage.setItem(pokemon,newData);
                     window.location.href = "shop.html";
@@ -89,8 +94,6 @@
             if(choice.childNodes.length < 1){
                 choice.style.display = "none";
             }
-
-
             let button = document.getElementsByClassName("addcart")[0];
             if(button != undefined){
                 button.remove();
-- 
GitLab