Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. $(function () {
  2. // configuration js
  3. const configCatgories = [
  4. {
  5. id: 1,
  6. title: "barebone",
  7. maxQty: 1,
  8. },
  9. {
  10. id: 2,
  11. title: "processor",
  12. maxQty: 3,
  13. },
  14. {
  15. id: 3,
  16. title: "memory",
  17. maxQty: 1,
  18. },
  19. {
  20. id: 4,
  21. title: "m.2 drive",
  22. maxQty: 4,
  23. },
  24. ];
  25. const bareboneProducts = [
  26. {
  27. id: 1,
  28. title: `Anwi C252 Chipset - 1U - 2x SATA - 1x M.2 - Dual Anwi 1-Gigabit
  29. Ethernet (RJ45) - 350W Power Supply`,
  30. qty: 3,
  31. price: 99,
  32. },
  33. ];
  34. const processorProducts = [
  35. {
  36. productcatid: 1,
  37. productcattitle: `Intel<sup>®</sup> Xeon<sup>®</sup> E-2300 Processor Series`,
  38. products: [
  39. {
  40. id: 1,
  41. title: `Quad-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2314 Processor 2.8GHz 8MB
  42. Cache (65W)`,
  43. qty: 3,
  44. price: 99,
  45. },
  46. {
  47. id: 2,
  48. title: `Quad-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2334 Processor 3.4GHz 8MB Cache (65W)`,
  49. qty: 3,
  50. price: 99,
  51. },
  52. {
  53. id: 3,
  54. title: `Eight-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2378 Processor 2.6GHz 16MB Cache (65W)`,
  55. qty: 3,
  56. price: 99,
  57. },
  58. ],
  59. },
  60. {
  61. productcatid: 2,
  62. productcattitle: `Intel<sup>®</sup> Xeon<sup>®</sup> E-2300 Processor Series with Anwi UHD P750 Graphics`,
  63. products: [
  64. {
  65. id: 1,
  66. title: `Quad-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2324G Processor 3.1GHz
  67. 8MB Cache (65W)`,
  68. qty: 1,
  69. price: 99,
  70. },
  71. {
  72. id: 2,
  73. title: `Quad-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2374G Processor 3.7GHz 8MB Cache (80W)`,
  74. qty: 1,
  75. price: 99,
  76. },
  77. {
  78. id: 3,
  79. title: `Six-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2356G Processor 3.2GHz 12MB Cache (80W)`,
  80. qty: 1,
  81. price: 99,
  82. },
  83. {
  84. id: 4,
  85. title: `Six-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2386G Processor 3.5GHz 12MB Cache (95W)`,
  86. qty: 1,
  87. price: 99,
  88. },
  89. ],
  90. },
  91. ];
  92. const memoryProducts = [
  93. {
  94. id: 1,
  95. title: `16GB PC4-25600 3200MHz DDR4 ECC UDIMM`,
  96. qty: 2,
  97. price: 99,
  98. },
  99. {
  100. id: 2,
  101. title: `32GB PC4-25600 3200MHz DDR4 ECC UDIMM`,
  102. qty: 2,
  103. price: 220,
  104. },
  105. ];
  106. const m2driveProducts = [
  107. {
  108. productcatid: 1,
  109. productcattitle: `Kioxia XG6 M.2 PCIe 3.1 x4 NVMe Solid State Drives`,
  110. products: [
  111. {
  112. id: 1,
  113. title: `Quad-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2314 Processor 2.8GHz 8MB
  114. Cache (65W)`,
  115. qty: 3,
  116. price: 99,
  117. },
  118. {
  119. id: 2,
  120. title: `Quad-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2334 Processor 3.4GHz 8MB Cache (65W)`,
  121. qty: 2,
  122. price: 149,
  123. },
  124. {
  125. id: 3,
  126. title: `Eight-Core Intel<sup>®</sup> Xeon<sup>®</sup> E-2378 Processor 2.6GHz 16MB Cache (65W)`,
  127. qty: 2,
  128. price: 269,
  129. },
  130. ],
  131. },
  132. {
  133. productcatid: 2,
  134. productcattitle: `Anwi DC P4801X M.2 PCIe 3.0 x4 NVMe Solid State Drives`,
  135. products: [
  136. {
  137. id: 1,
  138. title: `100GB Intel<sup>®</sup> Optane™ SSD DC P4801X Series M.2 PCIe 3.0 x4 NVMe
  139. Solid State Drive`,
  140. qty: 1,
  141. price: 99,
  142. },
  143. {
  144. id: 2,
  145. title: `200GB Intel<sup>®</sup> Optane™ SSD DC P4801X Series M.2 PCIe
  146. 3.0 x4 NVMe Solid State Drive`,
  147. qty: 1,
  148. price: 149,
  149. },
  150. {
  151. id: 3,
  152. title: `1.0TB Kioxia XG6 M.2 PCIe 3.1 x4 NVMe Solid State Drive`,
  153. qty: 1,
  154. price: 269,
  155. },
  156. ],
  157. },
  158. {
  159. productcatid: 3,
  160. productcattitle: `Micron 7400 PRO M.2 PCIe 4.0 x4 NVMe Solid State Drives`,
  161. products: [
  162. {
  163. id: 1,
  164. title: `480GB Micron 7400 PRO Series M.2 22x80 PCIe 4.0 x4 NVMe Solid
  165. State Drive`,
  166. qty: 1,
  167. price: 99,
  168. },
  169. {
  170. id: 2,
  171. title: `960GB Micron 7400 PRO Series M.2 22x80 PCIe 4.0 x4
  172. NVMe Solid State Drive`,
  173. qty: 1,
  174. price: 149,
  175. },
  176. {
  177. id: 3,
  178. title: `1.92TB Micron 7400 PRO Series M.2 22x110 PCIe 4.0 x4 NVMe Solid
  179. State Drive`,
  180. qty: 1,
  181. price: 269,
  182. },
  183. ],
  184. },
  185. ];
  186. //Bind Config Categories
  187. bindConfigurations();
  188. function bindConfigurations() {
  189. let configCatHtml = "";
  190. $.each(configCatgories, function (i, cat) {
  191. const id = cat.id;
  192. let title = cat.title;
  193. let qty = cat.maxQty;
  194. let maxQtyHtml = "";
  195. if (title == "m.2 drive") {
  196. title = "m2-drive";
  197. }
  198. if (title == "m2-drive" || title == "processor") {
  199. let quantityHtml = "";
  200. if (title == "m2-drive") {
  201. let qtyProgressBarHtml = "";
  202. for (let i = 0; i < qty; i++) {
  203. qtyProgressBarHtml += `<span class="progress-bar progress-bar-${i}"></span>`;
  204. }
  205. quantityHtml = `<span>Quantity:</span><div class="max-qty-wrap ml-15"><div class="d-flex justify-content-between align-items-center"><div class="d-flex flex-column"><div class="qty-progress-bars d-flex align-items-center">${qtyProgressBarHtml}</div><div class="d-flex justify-content-between align-items-center mt-1"><span>Max Quantity: ${qty}</span><div><span class="selected-qty">0</span>/<span class="max-qty-span">${qty}</span></div></div></div></div></div>`;
  206. }
  207. maxQtyHtml = `<div class="text-white p-3 border-radius-custom float-lg-end d-flex align-items-center config-max-quantity">${quantityHtml}</div>`;
  208. }
  209. configCatHtml += `<div class="product-config-selector mb-20" id="config-${title}" data-maxqty='${qty}'>
  210. <div class="config-heading d-flex justify-content-between align-items-center">
  211. <h5 class="text-white p-3 border-radius-custom text-uppercase">${title}
  212. </h5>
  213. ${maxQtyHtml}
  214. </div>
  215. <div class="config-content p-0"></div>
  216. </div>`;
  217. });
  218. $("#block-content-main").html(configCatHtml);
  219. bindAllConfigProducts();
  220. }
  221. function bindAllConfigProducts() {
  222. bindBareboneAndMemoryProducts("barebone");
  223. bindBareboneAndMemoryProducts("memory");
  224. bindProcessorAndM2DriveProducts("processor");
  225. bindProcessorAndM2DriveProducts("m2-drive");
  226. bindEventListeners();
  227. }
  228. function bindBareboneAndMemoryProducts(cat) {
  229. let productHtml = "";
  230. let productsArr = bareboneProducts;
  231. if (cat == "memory") {
  232. productsArr = memoryProducts;
  233. }
  234. $.each(productsArr, function (i, product) {
  235. productHtml += `<p class="provide-content product-item">
  236. <div
  237. class="name-of-config card-body row justify-content-between py-1 align-items-center config-product-item" data-id='${product.id}' data-cat='${cat}' data-price='${product.price}'>
  238. <div class="form-check mt-2 col-lg-7" id="form-check">
  239. <input class="form-check-input product-radio-btn" type="radio" name="radio-btns"
  240. value="${product.title}" for="Radio-btn-${i}" >
  241. <b>${product.title}</b>
  242. </label>
  243. </div>
  244. <div class="btn-group config-quantity-btn text-black col-lg-2">
  245. <select class="form-select fw-bold qty-selector">`;
  246. for (let i = 1; i <= product.qty; i++) {
  247. productHtml += `<option value="${i}">Qty: ${i}</option>`;
  248. }
  249. productHtml += `</select>
  250. </div>
  251. <div class="config-pricing col-lg-2">
  252. <span class="config-price-span p-2 border-radius-custom"><span class="total-price-amount">${product.price}</span></span>
  253. </div>
  254. </div>
  255. </p>`;
  256. });
  257. $(`#config-${cat} .config-content`).html(productHtml);
  258. }
  259. function bindProcessorAndM2DriveProducts(cat) {
  260. let productCatHtml = "";
  261. let productsArr = processorProducts;
  262. let accordion = "processorProductAccordion";
  263. let collapse = "processorProductcollapse";
  264. if (cat == "m2-drive") {
  265. productsArr = m2driveProducts;
  266. accordion = "m2DriveProductAccordion";
  267. collapse = "m2DriveProductcollapse";
  268. }
  269. $.each(productsArr, function (i, productcat) {
  270. const productcatid = productcat.productcatid;
  271. const productcattitle = productcat.productcattitle;
  272. productCatHtml += `<div class="accordion mt-4 border-radius-custom" id="${accordion}-${productcatid}">
  273. <div class="accordion-item">
  274. <h2 class="accordion-header">
  275. <button class="accordion-button" style="color:#4e4c7d; background-color: #e7e9f4;"
  276. type="button" data-bs-toggle="collapse" data-bs-target="#${collapse}-${productcatid}"
  277. aria-expanded="true" aria-controls="${collapse}-${productcatid}">
  278. <strong>${productcattitle}</strong>
  279. </button>
  280. </h2>
  281. <div id="${collapse}-${productcatid}" class="accordion-collapse collapse show" data-bs-parent="#${accordion}-${productcatid}">
  282. <div class="accordion-body">`;
  283. let productHtml = "";
  284. $.each(productcat.products, function (i, product) {
  285. productHtml += `
  286. <div class="name-of-config row justify-content-between py-1 align-items-center config-product-item" data-id='${
  287. product.id
  288. }' data-cat='${cat}' data-price='${
  289. product.price
  290. }' data-productcatid='${productcatid}'>
  291. <div class="form-check mt-2 col-lg-7" id="form-check">
  292. ${appendProcessorAndM2DriveInput(cat, i, product.title)}
  293. </div>
  294. <div class="btn-group config-quantity-btn text-black col-lg-2">
  295. <select class="form-select fw-bold qty-selector">`;
  296. for (let i = 1; i <= product.qty; i++) {
  297. productHtml += `<option value="${i}">Qty: ${i}</option>`;
  298. }
  299. productHtml += `</select>
  300. </div>
  301. <div class="config-pricing col-lg-2">
  302. <span class="config-price-span p-2 border-radius-custom"><span class="processor-total-price total-price-amount"> ${product.price} </span> </span>
  303. </div>
  304. </div>`;
  305. });
  306. productCatHtml += productHtml;
  307. productCatHtml += `</div>
  308. </div>
  309. </div>
  310. </div>`;
  311. });
  312. $(`#config-${cat} .config-content`).html(productCatHtml);
  313. }
  314. function appendProcessorAndM2DriveInput(cat, id, title) {
  315. if (cat == "m2-drive") {
  316. return `<input class="form-check-input product-check-btn" type="checkbox" name="m2Drive-check-btns"
  317. id="Check-btn-${id}" value="${title}" >
  318. <label class="form-check-label" for="Check-btn-${id}">
  319. <strong>${title}</strong>
  320. </label>`;
  321. } else {
  322. return `<input class="form-check-input product-radio-btn" type="radio" name="processor-radio-btns"
  323. id="Radio-btn${id}" value="${title}" >
  324. <label class="form-check-label" for="Radio-btn${id}">
  325. <strong>${title}</strong>
  326. </label>`;
  327. }
  328. }
  329. function bindEventListeners() {
  330. $(".product-radio-btn").click(function (e) {
  331. const radioEl = $(this);
  332. const parentEl = radioEl.parents(".config-product-item");
  333. const val = radioEl.val();
  334. const productCatId = parentEl.data("productcatid");
  335. const price = parentEl.data("price");
  336. const cat = parentEl.data("cat");
  337. const qty = parentEl.find(".qty-selector").val();
  338. const id = parentEl.data("id");
  339. const maxQty = $(`#config-${cat}`).data("maxqty");
  340. $(`#config-${cat}`).find(".config-price-span").removeClass("active");
  341. parentEl.find(".config-price-span").addClass("active");
  342. bindSelectedProduct(cat, val, qty, price, id, maxQty, productCatId);
  343. updateItemsCount();
  344. updateTotalCartPrice();
  345. });
  346. $(".qty-selector").change(function () {
  347. const selectEl = $(this);
  348. const parentEl = selectEl.parents(".config-product-item");
  349. const val = selectEl.val();
  350. const price = parentEl.data("price");
  351. const cat = parentEl.data("cat");
  352. const id = parentEl.data("id");
  353. if (!parentEl.find("input").is(":checked")) {
  354. parentEl.find("input").trigger("click");
  355. parentEl.find(".config-price-span").addClass("active");
  356. }
  357. const selecedSummaryProduct = $(`.${cat}-cart-product-${id}`);
  358. selecedSummaryProduct.find(".summary-total-qty .qty-span").text(val);
  359. selecedSummaryProduct.find(".price-span").text(price * val);
  360. updateTotalCartPrice();
  361. });
  362. $(".product-check-btn").click(function () {
  363. const checkEl = $(this);
  364. const parentEl = checkEl.parents(".config-product-item");
  365. const val = checkEl.val();
  366. const productCatId = parentEl.data("productcatid");
  367. const price = parentEl.data("price");
  368. const cat = parentEl.data("cat");
  369. const qty = parentEl.find(".qty-selector").val();
  370. const id = parentEl.data("id");
  371. const maxQty = $(`#config-${cat}`).data("maxqty");
  372. if ($(".product-check-btn:checked").length > maxQty) {
  373. alert("Max limit reached");
  374. return false;
  375. } else {
  376. parentEl.find(".config-price-span").toggleClass("active");
  377. bindSelectedProduct(cat, val, qty, price, id, maxQty, productCatId);
  378. updateItemsCount();
  379. updateTotalCartPrice();
  380. }
  381. });
  382. }
  383. function bindSelectedProduct(
  384. cat,
  385. val,
  386. qty,
  387. price,
  388. id,
  389. maxQty,
  390. productCatId = ""
  391. ) {
  392. const summaryProductHtml = `<li class="w-100 my-1 d-flex align-items-center cart-product-item ${cat}-cart-product-${id}" data-productcatid='${productCatId}'><span class="summary-total-qty"><span class="qty-span">${qty}</span><i class="fa fa-times"></i></span>
  393. <div class="flex-grow-1 d-flex align-items-center"><span class="summary-product-val mr-2">${val}</span>
  394. <span class="order-price price-span ml-auto">${price}</span></div>
  395. </li>`;
  396. if (cat == "m2-drive") {
  397. let checkedCount = $(".product-check-btn:checked").length;
  398. if (
  399. $(`.m2-drive-cart-product-${id}[data-productcatid = "${productCatId}"]`)
  400. .length
  401. ) {
  402. $(
  403. `.m2-drive-cart-product-${id}[data-productcatid = "${productCatId}"]`
  404. ).remove();
  405. $("#config-m2-drive .qty-progress-bars")
  406. .find(".progress-bar.active")
  407. .last()
  408. .removeClass("active");
  409. $("#config-m2-drive .max-qty-wrap")
  410. .find(".selected-qty")
  411. .text(checkedCount);
  412. } else {
  413. $("#config-m2-drive .qty-progress-bars")
  414. .find(".progress-bar")
  415. .not(".active")
  416. .first()
  417. .addClass("active");
  418. $("#config-m2-drive .max-qty-wrap")
  419. .find(".selected-qty")
  420. .text(checkedCount);
  421. $(`#${cat}-summary .summary-list`).append(summaryProductHtml);
  422. }
  423. } else {
  424. $(`#${cat}-summary .summary-list`).html(summaryProductHtml);
  425. }
  426. if ($(`#${cat}-summary .summary-list li`).length) {
  427. $(`#${cat}-summary`).removeClass("d-none");
  428. } else {
  429. $(`#${cat}-summary`).addClass("d-none");
  430. }
  431. }
  432. function updateItemsCount() {
  433. const cartProductCount = $(
  434. "#productOrderSummary .cart-product-item"
  435. ).length;
  436. $(".summery-head #items-count").text(cartProductCount);
  437. }
  438. function updateTotalCartPrice() {
  439. let totalPrice = 0;
  440. $("#productOrderSummary .cart-product-item")
  441. .find(".price-span")
  442. .each(function (i, e) {
  443. totalPrice += Number($(e).text().trim());
  444. });
  445. $("#productOrderSummary #total-amount").text(totalPrice);
  446. }
  447. });