1/**/ 2var driveList = []; 3var bayList = []; 4var sortType = []; 5var sortCounted = []; 6var rowNum = 1; 7var curRow = ""; 8var driveType = ""; 9var bizType = ""; 10var maxBays = []; 11var maxBay = 0; 12var maxBig = 0; 13var maxSmall = 0; 14var bigDD = 0; 15var smallDD = 0; 16var warning = false; 17var pageMatch = false; 18var select = { 19 bigDrive: 'null', 20 bigCount: 0, 21 smallDrive: 'null', 22 smallCount: 0 23} 24 25function precisionRound(number) { 26 var factor = Math.pow(10, 0); 27 return Math.round(number * factor) / factor; 28} 29 30function createRow(info, final) { 31 var row = $("<div>"); 32 row.addClass("row row" + rowNum); 33 $("#prodList").append(row); 34 curRow = ".row" + rowNum; 35 36 var desc2 = info.desc.split(' ')[0] !== "QNAP" ? 'QNAP ' + info.desc.replace(/&lt;/g, '<') : info.desc.replace(/&lt;/g, '<'); 37 var priceDesc = '">Our'; 38 var extraBtn = ''; 39 var SKU = info.sku; 40 var pageLink = pageMatch ? '' : '<br><p style="padding-top: 5px;"><span class="btn btn-xs btn-link"><a href="https://www.qnapworks.com' + info.href + '" target="_blank"><i class="fa fa-info-circle"></i> Visit Product Page</a></span></p>'; 41 var gray = false; 42 43 if (final) { 44 desc2 = info.desc2; 45 priceDesc = ' redText">Bundle'; 46 extraBtn = info.extraBtn; 47 SKU = info.minSKU 48 gray = info.oops === "" ? false : true; 49 } 50 51 var smallDesc = info.small !== '0' ? '<br><small>' + info.small + '</small>' : ''; 52 var price = precisionRound(info.price).toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$&,"); 53 54 var descInfo = '<div class="col-sm-7"><strong><span class="text-primary">' + info.sku + '</span> - ' + info.desc + '</strong>' + smallDesc + '</div>'; 55 //var skuInfo = '<div class="col-sm-3">#' + SKU + '<br><span class="price' + priceDesc + ' Price: $' + price + '</span>' + pageLink + '</div>'; 56 var skuInfo = '<div class="col-sm-3">#' + SKU + '<br><span class="price">Contact Us for Pricing</span>' + pageLink + '</div>';
57 //var btnInfo = '<div class="col-sm-2 text-center"><form action="/portal/cart/addtocart" method="get"><input type="hidden" name="item" value="' + SKU + ' - ' + desc2 + '"><input type="hidden" name="price" value="$' + price + '"><input type="hidden" name="quantity" value="1"><button type="submit" class="btn btn-warning center-block"' + info.oops + '><i class="fa fa-shopping-cart"></i> Add to Cart</button></form>' + extraBtn + '</div>'; 58 var btnInfo = '<div class="col-sm-2 text-center">' + extraBtn + '</div>'; 59 row.append(descInfo).append(skuInfo).append(btnInfo); 60 $(curRow).append(row); 61 if (gray) { 62 $(curRow).attr("class", "row alert-danger"); 63 } else { 64 $(curRow).attr("class", "row"); 65 } 66} 67 68function createDriveRow(bay, select, bigCheck, smallCheck, good) { 69 if (!bigCheck && !smallCheck) { 70 return createRow(bay, false); 71 } 72 73 var driveB = driveList[select.bigDrive]; 74 var driveS = driveList[select.smallDrive]; 75 76 var driveDesc = ''; 77 var SKU = bay.minSKU; 78 var price = bay.price; 79 var oops = ''; 80 81 switch (driveType) { 82 case "SAS": 83 oops = select.bigCount > bay.bigSAS || (select.smallCount > bay.smallSAS && bay.smallSAS !== 0) ? ' disabled' : ''; 84 warning = oops === '' ? warning : true; 85 break; 86 case "SATA": 87 oops = select.bigCount > bay.bigSATA || (select.smallCount > bay.smallSATA && bay.smallSATA !== 0) ? ' disabled' : ''; 88 warning = oops === '' ? warning : true; 89 break; 90 } 91 92 oops = !good ? ' disabled' : oops; 93 94 if (bigCheck && smallCheck) { 95 driveDesc = driveB.desc + ' (' + driveB.bytes + ' x ' + select.bigCount + ') & ' + driveS.desc + ' (' + driveS.bytes + ' x ' + select.smallCount + ')'; 96 SKU += "-" + select.bigCount + "-" + driveB.sku + "-" + select.smallCount + "-" + driveS.sku; 97 price = price + (driveB.price * select.bigCount) + (driveS.price * select.smallCount); 98 } else if (bigCheck && !smallCheck) { 99 driveDesc = driveB.desc + ' (' + driveB.bytes + ' x ' + select.bigCount + ')'; 100 SKU += "-" + select.bigCount + "-" + driveB.sku; 101 price = price + (driveB.price * select.bigCount); 102 } else if (!bigCheck && smallCheck) { 103 driveDesc = driveS.desc + ' (' + driveS.bytes + ' x ' + select.smallCount + ')'; 104 SKU += "-" + select.smallCount + "-" + driveS.sku; 105 price = price + (driveS.price * select.smallCount); 106 } 107 108 var desc2 = 'QNAP ' + bay.sku + ' with ' + driveDesc; 109 110 var obj = { 111 desc: bay.desc + ' <span class="text-primary">with ' + driveDesc + '</span>', 112 desc2: desc2, 113 sku: bay.sku, 114 minSKU: SKU, 115 small: bay.small, 116 price: price, 117 oops: oops, 118 //extraBtn: '<p style="padding-top: 5px;"><span class="btn btn-primary"' + oops + '><a href="https://www.qnapworks.com/quoterequest.asp?product=' + desc2.replace(/ /g, '+').replace(/&/g, "%26") + '+Bundle+for+%24' + precisionRound(price).toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$&,") + '" target="_blank" style="color: #fff;"><i class="fa fa-envelope-o"></i> Get Better Pricing</a></span></p>', 119 extraBtn: '<span class="btn btn-primary"' + oops + '><a href="https://www.qnapworks.com/quoterequest.asp?product=' + desc2.replace(/ /g, '+').replace(/&/g, "%26") + '+Bundle" target="_blank" style="color: #fff;"><i class="fa fa-envelope-o"></i> Get A Quote</a></span>', 120 href: bay.href 121 } 122 createRow(obj, true); 123} 124 125function getBays() { 126 sortType = []; 127 maxBays = []; 128 129 for (var i = 0; i < bayList.length - 1; i++) { 130 switch (driveType) { 131 case '': 132 sortType = bayList; 133 break; 134 case 'SATA': 135 if (bayList[i].bigSATA > 0 || bayList[i].smallSATA > 0) { 136 if (bayList[i].compType === bizType) { 137 sortType.push(bayList[i]); 138 addUnique(bayList[i].baySize, maxBays); 139 } else if (bizType === "") { 140 sortType.push(bayList[i]); 141 addUnique(bayList[i].baySize, maxBays); 142 } 143 } 144 break; 145 case 'SAS': 146 if (bayList[i].bigSAS > 0 || bayList[i].smallSAS > 0) { 147 sortType.push(bayList[i]); 148 addUnique(bayList[i].baySize, maxBays); 149 } 150 break; 151 } 152 } 153 $("#prodList").empty(); 154 for (var z = 0; z < sortType.length; z++) { 155 createRow(sortType[z], false); 156 rowNum++; 157 } 158} 159 160function updateBays(num) { 161 sortType = pageMatch ? sortCounted : sortType; 162 sortCounted = []; 163 maxBig = 0; 164 maxSmall = 0; 165 166 if (num === 0) { 167 sortCounted = sortType; 168 } else { 169 for (var i = 0; i < sortType.length; i++) { 170 if (sortType[i].baySize === num) { 171 sortCounted.push(sortType[i]); 172 switch (driveType) { 173 case "SAS":
174 setMax(sortType[i].bigSAS, sortType[i].smallSAS); 175 break; 176 case "SATA": 177 setMax(sortType[i].bigSATA, sortType[i].smallSATA); 178 break; 179 } 180 } 181 } 182 } 183 184 $("#prodList").empty(); 185 for (var z = 0; z < sortCounted.length; z++) { 186 createRow(sortCounted[z], false); 187 rowNum++; 188 } 189} 190 191function startDriveList() { 192 bigDD = 0; 193 smallDD = 0; 194 select = { 195 bigDrive: 'null', 196 bigCount: 0, 197 smallDrive: 'null', 198 smallCount: 0 199 } 200 201 $("#driveBrandBig").empty(); 202 $("#driveCountBig").empty(); 203 $("#driveBrandSmall").empty(); 204 $("#driveCountSmall").empty(); 205 206 $("#driveBrandBig").removeAttr("disabled"); 207 $("#driveCountBig").attr("disabled", "true"); 208 $("#driveBrandSmall").removeAttr("disabled"); 209 $("#driveCountSmall").attr("disabled", "true"); 210 211 $("#driveBrandBig").append('<option value="null">None</option>'); 212 $("#driveCountBig").append('<option value="0">None</option>'); 213 $("#driveBrandSmall").append('<option value="null">None</option>'); 214 $("#driveCountSmall").append('<option value="0">None</option>'); 215 216 if (maxSmall === 0 || maxBay === maxBig) { 217 for (var i = 1; i <= maxBig; i++) { 218 $("#driveCountBig").append('<option value="' + i + '">' + i + '</option>'); 219 $("#driveCountSmall").append('<option value="' + i + '">' + i + '</option>'); 220 bigDD++; 221 smallDD++; 222 } 223 } else { 224 for (var j = 1; j <= maxBig; j++) { 225 $("#driveCountBig").append('<option value="' + j + '">' + j + '</option>'); 226 bigDD++; 227 } 228 for (var k = 1; k <= maxSmall; k++) { 229 $("#driveCountSmall").append('<option value="' + k + '">' + k + '</option>'); 230 smallDD++; 231 } 232 } 233} 234 235function pickDrives() { 236 startDriveList(); 237 var bigDrives = false; 238 var smallDrives = false; 239 240 for (var i = 0; i < driveList.length; i++) { 241 if (driveList[i].driveType === driveType && (driveList[i].compType === bizType || driveList[i].bytes.indexOf("PRO") > -1)) { 242 switch (driveList[i].size) { 243 case "3.5": 244 $("#driveBrandBig").append('<option value="' + i + '">' + driveList[i].desc + ' (' + driveList[i].bytes + ')</option>'); 245 bigDrives = true; 246 break; 247 case "2.5": 248 $("#driveBrandSmall").append('<option value="' + i + '">' + driveList[i].desc + ' (' + driveList[i].bytes + ')</option>'); 249 smallDrives = true; 250 break; 251 } 252 } 253 } 254 if (!bigDrives || bigDD === 0) $("#driveBrandBig").attr("disabled", "true"); 255 if (!smallDrives || smallDD === 0) $("#driveBrandSmall").attr("disabled", "true"); 256} 257 258function addDrives() { 259 var bigCheck = select.bigCount !== 0 && select.bigDrive !== "null" ? true : false; 260 var smallCheck = select.smallCount !== 0 && select.smallDrive !== "null" ? true : false; 261 var good = true; 262 warning = false; 263 264 if (((select.bigCount + select.smallCount) > maxBay) && (bigCheck && smallCheck)) { 265 $(".woops").slideDown(); 266 good = false; 267 } else { 268 $(".woops").slideUp(); 269 good = true; 270 } 271 272 $("#prodList").empty(); 273 for (var z = 0; z < sortCounted.length; z++) { 274 createDriveRow(sortCounted[z], select, bigCheck, smallCheck, good); 275 rowNum++; 276 } 277 if (warning && good) { 278 $(".warning").slideDown(); 279 } else { 280 $(".warning").slideUp(); 281 } 282 if (pageMatch && !bigCheck && !smallCheck) { 283 $("#bundleList").slideUp(); 284 } else if (pageMatch) { 285 $("#bundleList").slideDown(); 286 } 287} 288 289function setMax(big, small) { 290 maxBig = maxBig > big ? maxBig : big; 291 maxSmall = maxSmall > small ? maxSmall : small; 292} 293 294function addUnique(max, array) { 295 if (array.indexOf(max) < 0) { 296 array.push(max); 297 } 298} 299 300function updateDriveList() { 301 $("#driveType").empty(); 302 if (bizType === "SOHO") { 303 $("#driveType").append('<option value="SATA">SATA Drives</option>'); 304 } else { 305 $("#driveType").append('<option value="null">Select a drive type...</option>'); 306 $("#driveType").append('<option value="SAS">SAS Drives</option>'); 307 $("#driveType").append('<option value="SATA">SATA Drives</option>'); 308 } 309} 310 311function updateBayList() { 312 $("#bayCount").empty(); 313 $("#bayCount").append('<option value="0">Select amount of bays...</option>'); 314 maxBays.sort(numSort); 315 for (var i = 0; i < maxBays.length; i++) { 316 var text = maxBays[i] === 1 ? maxBays[i] + ' bay' : maxBays[i] + ' bays'; 317 $("#bayCount").append('<option value="' + maxBays[i] + '">
317' + text + '</option>'); 318 } 319} 320 321function numSort(a, b) { 322 return a > b ? 1 : b > a ? -1 : 0; 323} 324 325$.ajax({ 326 url: '/bundle-creator/drives.csv?v=10', 327 dataType: 'text', 328}).done(function (data) { 329 var res = data.split("\r\n"); 330 331 for (var i = 1; i < res.length - 1; i++) { 332 var skuD = res[i].split(",")[0]; 333 var descD = res[i].split(",")[1]; 334 var bytes = res[i].split(",")[2]; 335 var priceD = res[i].split(",")[3]; 336 var driveType = res[i].split(",")[4]; 337 var size = res[i].split(",")[5]; 338 var compTypeD = res[i].split(",")[6]; 339 340 var obj = { 341 sku: skuD, 342 desc: descD, 343 bytes: bytes, 344 price: parseFloat(priceD), 345 driveType: driveType, 346 size: size, 347 compType: compTypeD 348 }; 349 driveList.push(obj); 350 } 351}); 352 353$.ajax({ 354 url: '/bundle-creator/bays.csv?v=10', 355 dataType: 'text', 356}).done(function (data) { 357 var res = data.split("\r\n"); 358 var hasSAS = false; 359 var hasSATA = false; 360 361 for (var j = 1; j < res.length - 1; j++) { 362 var skuB = res[j].split(",")[0];//.replace(/-US/g, ''); 363 var descB = res[j].split(",")[1].replace(/-_-/g, ',').replace(/</g, '<').replace(/&/g, '&').replace(/``/g, 'in').replace(/�/g, ''); 364 var smallB = res[j].split(",")[2].replace(/-_-/g, ',').replace(/</g, '<').replace(/&/g, '&').replace(/``/g, 'in').replace(/�/g, ''); 365 var priceB = res[j].split(",")[3]; 366 var baySize = res[j].split(",")[4]; 367 var bigSATA = res[j].split(",")[5]; 368 var smallSATA = res[j].split(",")[6]; 369 var bigSAS = res[j].split(",")[7]; 370 var smallSAS = res[j].split(",")[8]; 371 var minSKU = res[j].split(",")[9]; 372 var compTypeB = res[j].split(",")[10]; 373 var href = res[j].split(",")[11]; 374 375 var obj = { 376 sku: skuB, 377 desc: descB, 378 small: smallB, 379 price: parseFloat(priceB), 380 baySize: parseFloat(baySize), 381 bigSATA: parseFloat(bigSATA), 382 smallSATA: parseFloat(smallSATA), 383 bigSAS: parseFloat(bigSAS), 384 smallSAS: parseFloat(smallSAS), 385 minSKU: minSKU, 386 compType: compTypeB, 387 href: href 388 }; 389 390 if (window.location.href.indexOf(href) > -1) { 391 maxBay = parseFloat(baySize); 392 bizType = compTypeB; 393 pageMatch = true; 394 hasSAS = obj.bigSAS > 0 || obj.smallSAS > 0 ? true : hasSAS; 395 hasSATA = obj.bigSATA > 0 || obj.smallSATA > 0 ? true : hasSATA; 396 sortCounted.push(obj); 397 } 398 399 bayList.push(obj); 400 } 401 402 if (pageMatch) { 403 if (!hasSAS) { 404 $("option[value='SAS']").attr("disabled", "disabled"); 405 } 406 if (!hasSATA) { 407 $("option[value='SATA']").attr("disabled", "disabled"); 408 } 409 } 410 411 for (var k = 0; k < bayList.length; k++) { 412 createRow(bayList[k], false); 413 rowNum++; 414 } 415}); 416 417$("#bizType option[value='null']").attr("selected", "selected");
418$("#driveType option[value='null']").attr("selected", "selected"); 419$("#bayCount option[value='0']").attr("selected", "selected"); 420 421$(".form-control").on("change", function () { 422 switch ($(this).attr("id")) { 423 case "bizType": 424 var bT = $(this).val(); 425 $(this).children("option[value='null']").hide(); 426 switch (bT) { 427 case "SMB": 428 bizType = bT; 429 driveType = ""; 430 $("#driveType").removeAttr("disabled"); 431 $("#bayCount").attr("disabled", "true"); 432 break; 433 case "SOHO": 434 bizType = bT; 435 driveType = "SATA" 436 $("#driveType").attr("disabled", "true"); 437 $("#bayCount").removeAttr("disabled"); 438 break; 439 } 440 $(".drive-form").slideUp(); 441 $("#bundleList").slideUp(); 442 getBays(); 443 updateDriveList(); 444 updateBayList(); 445 break; 446 case "driveType": 447 var dT = $(this).val(); 448 $(this).children("option[value='null']").hide(); 449 if (pageMatch){ 450 $(".woops").slideUp(); 451 $(".warning").slideUp(); 452 driveType = dT; 453 $(".drive-form").slideDown(); 454 $("#bundleList").slideUp(); 455 updateBays(maxBay); 456 pickDrives(); 457 } else { 458 driveType = dT; 459 $("#bayCount").removeAttr("disabled"); 460 $(".drive-form").slideUp(); 461 $("#bundleList").slideUp(); 462 getBays(); 463 updateBayList(); 464 } 465 break; 466 case "bayCount": 467 maxBay = parseFloat($(this).val()); 468 $(this).children("option[value='0']").hide(); 469 $(".woops").slideUp(); 470 $(".warning").slideUp(); 471 $(".drive-form").slideDown(); 472 updateBays(maxBay); 473 pickDrives(); 474 $("#bundleList").slideDown(); 475 break; 476 case "driveBrandBig": 477 var dBB = $(this).val(); 478 select.bigDrive = dBB; 479 $("#driveCountBig").removeAttr("disabled"); 480 if (dBB === "null") { 481 $("#driveCountBig").attr("disabled", "true"); 482 } 483 addDrives(); 484 break; 485 case "driveBrandSmall": 486 var dBS = $(this).val(); 487 select.smallDrive = dBS; 488 $("#driveCountSmall").removeAttr("disabled"); 489 if (dBS === "null") { 490 $("#driveCountSmall").attr("disabled", "true"); 491 } 492 addDrives(); 493 break; 494 case "driveCountBig": 495 var dCB = parseFloat($(this).val()); 496 select.bigCount = dCB; 497 addDrives(); 498 break; 499 case "driveCountSmall": 500 var dCS = parseFloat($(this).val()); 501 select.smallCount = dCS; 502 addDrives(); 503 break; 504 } 505}); 506 507$("#toggleBtn").on("click", function() { 508 $("#prodList").slideToggle(); 509})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.