Advertisement
Guest User

Untitled

a guest
Jan 28th, 2017
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. var app = app || {};
  2.  
  3. (function() {
  4. var book = new recipeBook;
  5.  
  6. function getRecipe(){
  7. let name = $('#name').val();
  8. let rating = $('#rating').val();
  9. let image = $('#image').val();
  10. let category = $('select#category').val();
  11. let recipe = new Recipe(name, rating, image, category);
  12. return recipe;
  13. }
  14.  
  15. $('#add_book').click(function(ev) {
  16. book.addRecipe(getRecipe());
  17. console.log('add new recipe to book');
  18. loadData();
  19. });
  20.  
  21. $("#clear_book").click(function(ev) {
  22. $(".uk-form").reset();
  23. console.log('clears recipe form');
  24. });
  25.  
  26. $(document).on('click','.remove',function(ev){
  27. //TODO: remove target recipe by Id
  28. console.log('remove target recipe by Id');
  29. loadData();
  30. });
  31.  
  32. loadData();
  33.  
  34. function loadData() {
  35.  
  36. var meat = book.getRecipes().filter(function(r) {
  37. return r._category == "meat";
  38. });
  39.  
  40. var vegan = book.getRecipes().filter(function(r) {
  41. return r._category == "vegan";
  42. });
  43.  
  44. var dessert = book.getRecipes().filter(function(r) {
  45. return r._category == "dessert";
  46. });
  47.  
  48. var source = $("#recipe-trmplate").html();
  49.  
  50. var template = Handlebars.compile(source);
  51. var contextMeat = {meat:meat};
  52. var contextvegan = {meat:vegan};
  53. var contextdessert = {meat:dessert};
  54. var html = template(contextMeat);
  55. var html2 = template(contextvegan);
  56. var html3 = template(contextdessert);
  57.  
  58. $('#meat_recipes').html(html);
  59. $('#vegan_recipes').html(html2);
  60. $('#dessert_recipes').html(html3);
  61. }
  62. }(app));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement