SHARE
TWEET

Untitled

a guest Oct 21st, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  $.ajax({
  2.         type: "GET",
  3.         url: targetUrl,
  4.         success: getBeers,
  5.         error: "error get beers"
  6.     });
  7.  
  8.     // Function to get all beers via BeerRestController , create a div for each
  9.     // and append it to div container in allBeersOld.html
  10.     function getBeers(beers) {
  11.         $("#container").empty();
  12.         let allBeers = Object.values(beers);
  13.         console.log(allBeers);
  14.         let beerArrSize = beers.length;
  15.  
  16.         for (var i = 0; i < allBeers.length; i++) {
  17.             let beer = allBeers[i];
  18.             let beerPic = beer.beerPicture;
  19.  
  20.             if (beerPic === null || beerPic === "") {
  21.                 beerPic = beerDefaultImage;
  22.             }
  23.  
  24.  
  25.             let beerObj = ` <div class="col-lg-4 col-md-4 mb-4" id="beer-card">
  26.             <div onclick="location.href'#';" class="card h-100" style="cursor: pointer">
  27.             <img class="card-img-top" src="data:image/jpeg;charset=utf-8;base64,` + beerPic + `"  height="350px"  value="${allBeers[i].beerId}" />
  28.                          
  29.               <div class="card-header text-center">
  30.               <button value="${allBeers[i].beerId}" id="btn-del-beer" type="button" class="btn btn-danger" style="padding-inline: 60px">DELETE</button>
  31.               </div>
  32.            
  33.            
  34.               <div class="card-body" style="background: rgba(255,252,85,0.21)">
  35.                 <h4 class="card-title">${beer.beerName}</h4>
  36.                 <label for ="style">Style: </label>
  37.                 <span id="style"><b>${beer.style.name}</b></span>
  38.                 <br>
  39.                 <label for ="style">Brewery: </label>
  40.                 <span id="brewery"><b>${beer.brewery.name}</b></span>
  41.                 <br>
  42.                 <label for ="abv">Alcohol by volume: </label>
  43.                 <span id="abv"><b>${beer.abv}</b></span>
  44.                 <br>
  45.                  <label for ="avgRate">Average rating: </label>
  46.                 <span id="avgRate"><b>${beer.averageRating}</b></span>
  47.                 <br>
  48.                  <label for ="card-text">Description: </label>
  49.                  <p class="card-text">${beer.description}</p>
  50.               </div>
  51.               <div id = "footer" class="card-footer">
  52.            
  53.             <button id="wishBtn" type="button" class="btn btn-outline-danger"
  54.               title="Add to wishlist" value="${beer.beerId}">
  55.               <i class="fas fa-heart" aria-hidden="true"></i>    
  56.             </button>
  57.             <button id="drankBtn" type="button" class="btn btn-outline-warning"
  58.               title="Mark as drank" value="${beer.beerId}">
  59.               <i class="fa fa-beer" aria-hidden="true"></i>
  60.             </button>
  61.              </div>        
  62.             </div>            
  63.           </div>`;
  64.  
  65.  
  66.             $("#container").append(beerObj);
  67.         }
  68.  
  69.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top