Advertisement
Prohause

Problem04

Jul 15th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. function onlineShop(selector) {
  2.  
  3. 2
  4.  
  5. let form = `<div id="header">Online Shop Inventory</div>
  6.  
  7. 3
  8.  
  9. <div class="block">
  10.  
  11. 4
  12.  
  13. <label class="field">Product details:</label>
  14.  
  15. 5
  16.  
  17. <br>
  18.  
  19. 6
  20.  
  21. <input placeholder="Enter product" class="custom-select">
  22.  
  23. 7
  24.  
  25. <input class="input1" id="price" type="number" min="1" max="999999" value="1"><label class="text">BGN</label>
  26.  
  27. 8
  28.  
  29. <input class="input1" id="quantity" type="number" min="1" value="1"><label class="text">Qty.</label>
  30.  
  31. 9
  32.  
  33. <button id="submit" class="button" disabled>Submit</button>
  34.  
  35. 10
  36.  
  37. <br><br>
  38.  
  39. 11
  40.  
  41. <label class="field">Inventory:</label>
  42.  
  43. 12
  44.  
  45. <br>
  46.  
  47. 13
  48.  
  49. <ul class="display">
  50.  
  51. 14
  52.  
  53. </ul>
  54.  
  55. 15
  56.  
  57. <br>
  58.  
  59. 16
  60.  
  61. <label class="field">Capacity:</label><input id="capacity" readonly>
  62.  
  63. 17
  64.  
  65. <label class="field">(maximum capacity is 150 items.)</label>
  66.  
  67. 18
  68.  
  69. <br>
  70.  
  71. 19
  72.  
  73. <label class="field">Price:</label><input id="sum" readonly>
  74.  
  75. 20
  76.  
  77. <label class="field">BGN</label>
  78.  
  79. 21
  80.  
  81. </div>`;
  82.  
  83. 22
  84.  
  85. $(selector).html(form);
  86.  
  87. 23
  88.  
  89. let product = $('.custom-select');
  90.  
  91. 24
  92.  
  93. let price = $('#price');
  94.  
  95. 25
  96.  
  97. let quantity = $('#quantity');
  98.  
  99. 26
  100.  
  101. let button = $('#submit');
  102.  
  103. 27
  104.  
  105. let capacity = $('#capacity');
  106.  
  107. 28
  108.  
  109.  
  110. 29
  111.  
  112. function capacityCheck() {
  113.  
  114. 30
  115.  
  116. if (Number(capacity.val()) >= 150) {
  117.  
  118. 31
  119.  
  120. button.attr('disabled', true);
  121.  
  122. 32
  123.  
  124. product.attr('disabled', true);
  125.  
  126. 33
  127.  
  128. price.attr('disabled', true);
  129.  
  130. 34
  131.  
  132. quantity.attr('disabled', true);
  133.  
  134. 35
  135.  
  136. capacity.val('full');
  137.  
  138. 36
  139.  
  140. capacity.addClass('fullCapacity');
  141.  
  142. 37
  143.  
  144.  
  145. 38
  146.  
  147.  
  148. 39
  149.  
  150. }
  151.  
  152. 40
  153.  
  154. }
  155.  
  156. 41
  157.  
  158.  
  159. 42
  160.  
  161. capacityCheck();
  162.  
  163. 43
  164.  
  165. product.on('input', function () {
  166.  
  167. 44
  168.  
  169.  
  170. 45
  171.  
  172. button.attr('disabled', false);
  173.  
  174. 46
  175.  
  176. if (product.val() === '') {
  177.  
  178. 47
  179.  
  180. button.attr('disabled', true);
  181.  
  182. 48
  183.  
  184. }
  185.  
  186. 49
  187.  
  188.  
  189. 50
  190.  
  191. });
  192.  
  193. 51
  194.  
  195. button.on('click', function () {
  196.  
  197. 52
  198.  
  199. let body = $('.display');
  200.  
  201. 53
  202.  
  203. let li = $(`<li>Product: ${product.val()} Price: ${price.val()} Quantity: ${quantity.val()}</li>`)
  204.  
  205. 54
  206.  
  207. product.val('');
  208.  
  209. 55
  210.  
  211. body.append(li);
  212.  
  213. 56
  214.  
  215. button.attr('disabled', true);
  216.  
  217. 57
  218.  
  219. let sum = $('#sum');
  220.  
  221. 58
  222.  
  223. let adition = Number(sum.val());
  224.  
  225. 59
  226.  
  227. adition += Number(price.val()) * Number(quantity.val());
  228.  
  229. 60
  230.  
  231. sum.val(adition);
  232.  
  233. 61
  234.  
  235. capacity.val(Number(capacity.val()) + Number(quantity.val()));
  236.  
  237. 62
  238.  
  239. price.val(1);
  240.  
  241. 63
  242.  
  243. quantity.val(1);
  244.  
  245. 64
  246.  
  247. capacityCheck();
  248.  
  249. 65
  250.  
  251. })
  252.  
  253. 66
  254.  
  255. }
  256.  
  257. 67
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement