Prohause

Problem04

Jul 15th, 2018
230
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.  
  111. 29
  112.  
  113. function capacityCheck() {
  114.  
  115. 30
  116.  
  117. if (Number(capacity.val()) >= 150) {
  118.  
  119. 31
  120.  
  121. button.attr('disabled', true);
  122.  
  123. 32
  124.  
  125. product.attr('disabled', true);
  126.  
  127. 33
  128.  
  129. price.attr('disabled', true);
  130.  
  131. 34
  132.  
  133. quantity.attr('disabled', true);
  134.  
  135. 35
  136.  
  137. capacity.val('full');
  138.  
  139. 36
  140.  
  141. capacity.addClass('fullCapacity');
  142.  
  143. 37
  144.  
  145. ​
  146.  
  147. 38
  148.  
  149. ​
  150.  
  151. 39
  152.  
  153. }
  154.  
  155. 40
  156.  
  157. }
  158.  
  159. 41
  160.  
  161. ​
  162.  
  163. 42
  164.  
  165. capacityCheck();
  166.  
  167. 43
  168.  
  169. product.on('input', function () {
  170.  
  171. 44
  172.  
  173. ​
  174.  
  175. 45
  176.  
  177. button.attr('disabled', false);
  178.  
  179. 46
  180.  
  181. if (product.val() === '') {
  182.  
  183. 47
  184.  
  185. button.attr('disabled', true);
  186.  
  187. 48
  188.  
  189. }
  190.  
  191. 49
  192.  
  193. ​
  194.  
  195. 50
  196.  
  197. });
  198.  
  199. 51
  200.  
  201. button.on('click', function () {
  202.  
  203. 52
  204.  
  205. let body = $('.display');
  206.  
  207. 53
  208.  
  209. let li = $(`<li>Product: ${product.val()} Price: ${price.val()} Quantity: ${quantity.val()}</li>`)
  210.  
  211. 54
  212.  
  213. product.val('');
  214.  
  215. 55
  216.  
  217. body.append(li);
  218.  
  219. 56
  220.  
  221. button.attr('disabled', true);
  222.  
  223. 57
  224.  
  225. let sum = $('#sum');
  226.  
  227. 58
  228.  
  229. let adition = Number(sum.val());
  230.  
  231. 59
  232.  
  233. adition += Number(price.val()) * Number(quantity.val());
  234.  
  235. 60
  236.  
  237. sum.val(adition);
  238.  
  239. 61
  240.  
  241. capacity.val(Number(capacity.val()) + Number(quantity.val()));
  242.  
  243. 62
  244.  
  245. price.val(1);
  246.  
  247. 63
  248.  
  249. quantity.val(1);
  250.  
  251. 64
  252.  
  253. capacityCheck();
  254.  
  255. 65
  256.  
  257. })
  258.  
  259. 66
  260.  
  261. }
  262.  
  263. 67
Advertisement
Add Comment
Please, Sign In to add comment