PageSourceSearch

https://tobinbrothers.com.au/wp-content/plugins/firehawkcrm-cart/public/js/fcrm-stock-grid.js?ver=1.0.17.8

js tobinbrothers.com.au collected 2026-10-02 18:25:35 UTC 45,289 bytes, 1,170 lines download raw bytes

1"use strict";
2
3function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
5function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6
7function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
9function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
11var FirehawkCRMStockGrid = /*#__PURE__*/function () {
12  function FirehawkCRMStockGrid(rootElement, element, pagination, stockCategoryElement, stockCategoryPagination, stockCategoryDivider) {
13    _classCallCheck(this, FirehawkCRMStockGrid);
14
15    _defineProperty(this, "listElement", null);
16
17    _defineProperty(this, "pagination", null);
18
19    _defineProperty(this, "loadingOverlay", null);
20
21    _defineProperty(this, "categoryLoadingOverlay", null);
22
23    _defineProperty(this, "carouselLoadingOverlay", null);
24
25    _defineProperty(this, "categoryId", null);
26
27    _defineProperty(this, "totalPages", 0);
28
29    _defineProperty(this, "totalCategories", 0);
30
31    _defineProperty(this, "totalItems", 0);
32
33    _defineProperty(this, "page", -1);
34
35    _defineProperty(this, "pageSize", 16);
36
37    _defineProperty(this, "rootElement", null);
38
39    _defineProperty(this, "stockCategoryListElement", null);
40
41    _defineProperty(this, "stockCategoryPagination", null);
42
43    _defineProperty(this, "stockCategoryTotalPages", 0);
44
45    _defineProperty(this, "stockCategoryTotalItems", 0);
46
47    _defineProperty(this, "stockCategoryPage", -1);
48
49    _defineProperty(this, "stockCategoryPageSize", 16);
50
51    _defineProperty(this, "stockCategorySearchRequest", null);
52
53    _defineProperty(this, "stockCategoryPageItems", []);
54
55    _defineProperty(this, "stockCategoryDivider", null);
56
57    _defineProperty(this, "showOnlyCartStock", false);
58
59    _defineProperty(this, "stockIds", []);
60
61    _defineProperty(this, "stockSlug", "");
62
63    _defineProperty(this, "loginSlug", "");
64
65    _defineProperty(this, "cartSlug", "");
66
67    _defineProperty(this, "searchRequest", null);
68
69    _defineProperty(this, "team", null);
70
71    _defineProperty(this, "pageItems", []);
72
73    _defineProperty(this, "defaultImageUrl", null);
74
75    _defineProperty(this, "currentLocation", null);
76
77    _defineProperty(this, "query", null);
78
79    _defineProperty(this, "dateLocale", null);
80
81    _defineProperty(this, "startDate", null);
82
83    _defineProperty(this, "endDate", null);
84
85    _defineProperty(this, "stockSorting", null);
86
87    _defineProperty(this, "categorySorting", null);
88
89    _defineProperty(this, "categoryTags", null);
90
91    _defineProperty(this, "customTerms", []);
92
93    _defineProperty(this, "hidePrices", false);
94
95    _defineProperty(this, "hideEmptyList", false);
96
97    _defineProperty(this, "catalogOnlyMode", false);
98
99    _defineProperty(this, "showLoginToSeePrices", false);
100
101    _defineProperty(this, "gridImagesCover", false);
102
103    _defineProperty(this, "parentCategoryId", null);
104
105    _defineProperty(this, "categoryId", null);
106
107    _defineProperty(this, "displayType", "grid");
108
109    _defineProperty(this, "ignoreCategories", false);
110
111    _defineProperty(this, "ignoreStockSearch", false);
112
113    _defineProperty(this, "showImageDropshadow", false);
114
115    _defineProperty(this, "addingToCart", {});
116
117    _defineProperty(this, "displayView", "grid");
118
119    _defineProperty(this, "searchDebounce", null);
120
121    _defineProperty(this, "sorted", false);
122
123    _defineProperty(this, "openDetailInModal", false);
124
125    _defineProperty(this, "containDetailDisplayImage", false);
126
127    this.listElement = element;
128    this.pagination = pagination;
129    this.stockCategoryListElement = stockCategoryElement;
130    this.stockCategoryPagination = stockCategoryPagination;
131    this.stockCategoryDivider = stockCategoryDivider;
132    this.rootElement = rootElement;
133    this.loadingOverlay = jQuery("<div class=\"loading-overlay\"><i class=\"far fa-spinner-third fa-spin\"></i></div>");
134    this.categoryLoadingOverlay = jQuery("<div class=\"loading-overlay\"><i class=\"far fa-spinner-third fa-spin\"></i></div>");
135    this.carouselLoadingOverlay = jQuery("<div class=\"loading-overlay\"><i class=\"far fa-spinner-third fa-spin\"></i></div>"); // this.listElement.addClass("loading")
136    // this.listElement.append(this.loadingOverlay)
137    // this.stockCategoryListElement.addClass("loading")
138    // this.stockCategoryListElement.append(this.categoryLoadingOverlay)
139
140    this.rootElement.find(".slider-view").addClass("loading");
141    this.rootElement.find(".slider-view").append(this.categoryLoadingOverlay);
142    this.addListeners();
143  }
144
145  _createClass(FirehawkCRMStockGrid, [{
146    key: "setupCarouselGallery",
147    value: function setupCarouselGallery(items) {
148      var sliderView = jQuery(this.rootElement).find(".slider-view");
149      var navItems = "";
150      var previewItems = "";
151
152      for (var _i2 = 0; _i2 < items.length; _i2++) {
153        var item = items[_i2];
154        navItems += "\n\t\t\t<div class=\"gallery-item\">\n\t\t\t\t<div class=\"inner\" style=\"background-image: url('".concat(item.imageBackgroun
154d, "')\">\n\t\t\t\t<img class=\"gallery-image ").concat(this.showImageDropshadow ? "dropshadow" : "", "\" src=\"").concat(item.displayImage, "\" />\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t\t");
155        var previewItem = this.buildCarouselPreviewItem(item);
156        previewItems += previewItem;
157      }
158
159      var previewSlider = sliderView.find(".slider-preview");
160      var navSlider = sliderView.find(".slider-nav");
161
162      if (previewSlider.hasClass("slick-initialized")) {
163        previewSlider.slick("unslick");
164      }
165
166      if (navSlider.hasClass("slick-initialized")) {
167        navSlider.slick("unslick");
168      }
169
170      previewSlider.html(previewItems);
171      navSlider.html(navItems);
172      this.updateSlickSettings();
173    }
174  }, {
175    key: "destroySlickGallery",
176    value: function destroySlickGallery() {
177      var sliderView = jQuery(this.rootElement).find(".slider-view");
178      var previewSlider = sliderView.find(".slider-preview");
179      var navSlider = sliderView.find(".slider-nav");
180
181      if (previewSlider.hasClass("slick-initialized")) {
182        previewSlider.slick("unslick");
183      }
184
185      if (navSlider.hasClass("slick-initialized")) {
186        navSlider.slick("unslick");
187      }
188
189      previewSlider.html("");
190      navSlider.html("");
191    }
192  }, {
193    key: "updateSlickSettings",
194    value: function updateSlickSettings() {
195      var sliderView = jQuery(this.rootElement).find(".slider-view");
196      var previewSlider = sliderView.find(".slider-preview");
197      var navSlider = sliderView.find(".slider-nav");
198
199      if (previewSlider.hasClass("slick-initialized")) {
200        previewSlider.slick("unslick");
201      }
202
203      if (navSlider.hasClass("slick-initialized")) {
204        navSlider.slick("unslick");
205      }
206
207      var rootId = jQuery(this.rootElement).attr("id");
208      previewSlider.slick({
209        slidesToShow: 1,
210        slidesToScroll: 1,
211        arrows: false,
212        fade: true,
213        adaptiveHeight: true,
214        asNavFor: "#" + rootId + ' .slider-view .slider-nav'
215      });
216      navSlider.slick({
217        slidesToShow: 5,
218        slidesToScroll: 1,
219        asNavFor: "#" + rootId + ' .slider-view .slider-preview',
220        dots: true,
221        centerMode: false,
222        focusOnSelect: true
223      });
224      setTimeout(function () {
225        window.dispatchEvent(new Event('resize'));
226      }, 800);
227    }
228  }, {
229    key: "toggleDisplayView",
230    value: function toggleDisplayView() {
231      if (this.displayView == "grid") {
232        this.displayView = "carousel";
233        this.showCarouselGallery();
234        jQuery(this.rootElement).find("#display-change-btn .fa-icon").removeClass(".fa-images").addClass("fa-th-large");
235      } else {
236        this.displayView = "grid";
237        this.showGridView();
238        this.destroySlickGallery();
239        jQuery(this.rootElement).find("#display-change-btn .fa-icon").addClass(".fa-images").removeClass("fa-th-large");
240      }
241    }
242  }, {
243    key: "showCarouselGallery",
244    value: function showCarouselGallery() {
245      jQuery(this.rootElement).find(".slider-view").show();
246      this.listElement.hide();
247      this.setupCarouselGallery(this.pageItems || []);
248    }
249  }, {
250    key: "showGridView",
251    value: function showGridView() {
252      jQuery(this.rootElement).find(".slider-view").hide();
253      this.listElement.show();
254    }
255  }, {
256    key: "buildCarouselPreviewItem",
257    value: function buildCarouselPreviewItem(item) {
258      var displayImageView = "";
259      var titleContainer = "";
260      var stockCodeContainer = "";
261      var displayImage = item.displayImage || this.defaultImageUrl;
262      var imageBackground = item.imageBackground || null;
263
264      if (displayImage && displayImage.length) {
265        if (imageBackground && imageBackground.length) {
266          displayImageView = "<div class=\"preview-image-container\" style=\"background-image: url('".concat(imageBackground, "')\"><img class=\"preview-image ").concat(this.showImageDropshadow ? "dropshadow" : "", "\" src=\"").concat(displayImage, "\"></div>");
267        } else {
268          displayImageView = "<div class=\"preview-image-container\"><img class=\"preview-image\" src=\"".concat(displayImage, "\"></div>");
269        }
270      } else {
271        displayImageView = '<div class="preview-image-container placeholder" style="background: #f1f1f1;"></div>';
272      }
273
274      titleContainer += "<h5 class=\"fh-stock-name mb-0\">".concat(item.name, "</h5>");
275      stockCodeContainer += "<div class=\"fh-stock-code\">".concat(item.stockCode, "</div>");
276      var price = item.price;
277      var addToCartButton = "<div class=\"fh-add-to-cart-wrapper\">\n      <button type=\"button\" class=\"btn btn-primary fh-add-to-cart\" data-stock=\"".concat(item.id, "\">Add to Shortlist</button>\n    </div>");
278      var hideAddToCartButton = false;
279
280      if (this.hidePrices || this.catalogOnlyMode) {
281        hideAddToCartButton = true;
282      }
283
284      if (hideAddToCartButton) {
285        addToCartButton = "";
286      }
287
288      var stockOptions = "<div class=\"fh-stock-price\">".concat(price, "</div>");
289
290      if (this.hidePrices || this.showLoginToSeePrices) {
291        stockOptions = "";
292      }
293
294      var loginToSeePrices = "";
295
296      if (this.showLoginToSeePrices) {
297        if (this.loginSlug && this.loginSlug.length) {
298          loginToSeePrices += "<div class=\"login-to-see-prices\"><a href=\"/".concat(this.loginSlug, "\">Login to see prices</a></div>");
299        } else {
300          loginToSeePrices += "<div class=\"login-to-see-prices\"><a href=\"\">Login to see prices</a></div>";
301        }
302      }
303
304      if (item._variations && item._variations.length > 1) {
305        stockOptions += "<div class=\"subtitle p-0\">".concat(item._variations.length, " Options</div>");
306      }
307
308      var stockInfo = "";
309
310      if (item.materials && item.materials.length) {
311        var materialData = "";
312        item.materials.forEach(function (material) {
313          materialData += "\n\t\t\t\t<li class=\"fh-material-type\">\n\t\t\t\t\t\t<div class=\"fh-material-type-label\">".concat(material, "</div>\n\t\t\t\t</li>\n\t\t\t\t");
314        });
315        stockInfo += "\n\t\t\t\t<div class=\"fh-stock-materials fh-stock-info-item\">\n\t\t\t\t<h5 class=\"fh-stock-info-title\">Materials</h5>\n\t\t\t\t<ul class=\"fh-stock-info-item-list\">\n\t\t\t\t\t".concat(materialData, "\n\t\t\t\t</ul>\n\t\t\t\t</div>\n\t\t\t");
316      }
317
318      if (item.dimensionsDescription || item.innerDimensionsDescription) {
319        var dimensionsDescription = "";
320
321        if (item.innerDimensionsDescription) {
322          dimensionsDescription += "\n\t\t\t\t<li class=\"fh-stock-dimensions-inner\">\n\t\t\t\t\tInside: ".concat(item.innerDimensionsDescription, "\n\t\t\t\t</li>\n\t\t\t\t");
323        }
324
325        if (item.dimensionsDescription) {
326          dimensionsDescription += "\n\t\t\t\t<li class=\"fh-stock-dimensions-inner\">\n\t\t\t\t\tOutside: ".concat(item.dimensionsDescription, "\n\t\t\t\t</li>\n\t\t\t\t");
327        }
328
329        stockInfo += "\n\t\t\t\t<div class=\"fh-stock-dimesions fh-stock-info-item\">\n\t\t\t\t<h5 class=\"fh-stock-info-title\">Dimensions</h5>\n\t\t\t\t<ul class=\"fh-stock-info-item-list\">\n\t\t\t\t".concat(dimensionsDescription, "\n\t\t\t\t</ul>\n\t\t\t</div>\n\t\t\t");
330      }
331
332      var content = "\n\t\t\t<div class=\"carousel-preview-item ".concat(hideAddToCartButton ? 'no-cart' : '', "\" id=\"grid-item-").concat(item.id, "\" data-grid-stock-id=\"").concat(item.id, "\" tabindex=\"0\" tabindex=\"0\">\n\t\t\t\t<div class=\"row\">\n\t\t\t\t\t<div class=\"col-12 col-lg-7\">\n\t\t\t\t\t\t").concat(displayImageView, "\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"col\">\n\t\t\t\t\t\t<div class=\"fh-stock-title-container\">").concat(titleContainer, "</div>\n\t\t\t\t\t\t<div class=\"fh-stock-sku-container subtitle\">").concat(stockCodeContainer, "</div>\n\t\t\t\t\t\t<div class=\"fh-stock-options\">").concat(stockOptions, "</div>\n\t\t\t\t\t\t<div class=\"fh-stock-info\">").concat(stockInfo, "</div>\n\t\t\t\t\t\t").concat(addToCartButton, "\n\t\t\t\t\t\t").concat(loginToSeePrices, "\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t");
333      return content;
334    }
335  }, {
336    key: "buildItem",
337    value: function buildItem(item) {
338      var displayImageView = "";
339      var titleContainer = "";
340      var stockCodeContainer = "";
341      var addToCartButtonText = "Add to Shortlist";
342      var allowBackorders = item.woocommerceBackordersAllowed == "Yes";
343      var displayItem = item.displayItem == true;
344      var displayImage = item.displayImage || this.defaultImageUrl;
345      var freeStockLevel = item._freeStock || 0;
346      var imageBackground = item.imageBackground || null;
347
348      if (displayImage && displayImage.length) {
349        if (imageBackground && imageBackground.length) {
350          displayImageView = "<div class=\"top-img image-basic\" style=\"background-image: url('".concat(imageBackground, "')\"><div class=\"image-display-basic ").concat(this.showImageDropshadow ? "dropshadow" : "", " ").concat(this.gridImagesCover ? "bg-image-cover" : "", "\" style=\"background-image: url('").concat(displayImage, "')\"></div></div>");
351        } else {
352          displayImageView = "<div class=\"top-img image-basic\"><div class=\"image-display-basic ".concat(this.gridImagesCover ? "bg-image-cover" : "", "\" style=\"background-image: url('").concat(displayImage, "')\"></div></div>");
353        }
354      } else {
355        displayImageView = '<div class="top-img placeholder image-basic" style="background: #f1f1f1;"></div>';
356      }
357
358      titleContainer += "<div class=\"title\">".concat(item.name, "</div>");
359      if (item.stockCode) stockCodeContainer += "<div class=\"sku\">".concat(item.stockCode, "</div>");
360      var price = item.price;
361      var addToCartButtonClass = "fh-add-to-cart";
362      var addToCartButtonDisabled = '';
363      var addToCartButton = "<div class=\"fh-add-to-cart-wrapper\">\n      <button type=\"button\" ".concat(addToCartButtonDisabled, " class=\"btn btn-primary ").concat(addToCartButtonClass, "\" data-stock=\"").concat(item.id, "\">").concat(addToCartButtonText, "</button>\n    </div>");
364      var hideAddToCartButton = false;
365
366      if (this.hidePrices || this.catalogOnlyMode) {
367        hideAddToCartButton = true;
368      }
369
370      if (hideAddToCartButton) {
371        addToCartButton = "";
372      }
373
374      var stockOptions = "<div class=\"fh-stock-price\">".concat(price, "</div>");
375
376      if (this.hidePrices || this.showLoginToSeePrices) {
377        stockOptions = "";
378      }
379
380      var loginToSeePrices = "";
381
382      if (this.showLoginToSeePrices) {
383        if (this.loginSlug && this.loginSlug.length) {
384          loginToSeePrices += "<div class=\"login-to-see-prices\"><a href=\"/".concat(this.loginSlug, "\">Login to see prices</a></div>");
385        } else {
386          loginToSeePrices += "<div class=\"login-to-see-prices\"><a href=\"\">Login to see prices</a></div>";
387        }
388      }
389
390      if (item._variations && item._variations.length > 1) {
391        stockOptions += "<div class=\"subtitle p-0\">".concat(item._variations.length, " Options</div>");
392      }
393
394      var content = "\n\t\t\t<div class=\"grid-item compact linked ".concat(hideAddToCartButton ? 'no-cart' : '', "\" id=\"grid-item-").concat(item.id, "\" data-grid-stock-id=\"").concat(item.id, "\" tabindex=\"0\" tabindex=\"0\">\n\t\t\t\t<div class=\"top-content\">\n\t\t\t\t\t\t").concat(displayImageView, "\n\t\t\t\t</div>\n        <div class=\"fh-stock-title-container\">").concat(titleContainer, "</div>\n        <div class=\"fh-stock-sku-container subtitle\">").concat(stockCodeContainer, "</div>\n        <div class=\"fh-stock-options\">").concat(stockOptions, "</div>\n        ").concat(addToCartButton, "\n        ").concat(loginToSeePrices, "\n\t\t\t</div>\n\t\t");
395      return content;
396    }
397  }, {
398    key: "buildCategoryGrid",
399    value: function buildCategoryGrid(items) {
400      var gridItems = "";
401
402      for (var _i4 = 0; _i4 < items.length; _i4++) {
403        var item = items[_i4];
404        var view = this.buildCategoryItem(item);
405        gridItems += "<div class=\"grid-col\">".concat(view, "</div>");
406      }
407
408      var content = "\n\t\t<div class=\"firehawk-crm-large-grid-view\">\n\t\t\t\t".concat(gridItems, "\n\t\t</div>\n\t\t");
409      jQuery(this.stockCategoryListElement).html(content);
410    }
411  }, {
412    key: "buildCategoryItem",
413    value: function buildCategoryItem(item) {
414      var displayImageView = "";
415      var titleContainer = "";
416      var displayImage = item.displayImage || this.defaultImageUrl;
417      var imageBackground = item.imageBackground || "https://firebasestorage.googleapis.com/v0/b/fcrm-e17b0.appspot.com/o/_storage%2Fteam%2F-N35t1rxd-QpJeuIfCZ4%2F1673584422873-wise-product-gradient.png?alt=media&token=0f2187e2-d441-41c8-84c0-a9aea14599b7";
418
419      if (displayImage && displayImage.length) {
420        if (imageBackground && imageBackground.length) {
421          displayImageView = "<div class=\"top-img image-basic\" style=\"background-image: url('".concat(imageBackground, "')\"><div class=\"image-display-basic ").concat(this.showImageDropshadow ? "dropshadow" : "", " ").concat(this.gridImagesCover ? "bg-image-cover" : "", "\" style=\"background-image: url('").concat(displayImage, "')\"></div></div>");
422        } else {
423          displayImageView = "<div class=\"top-img image-basic\"><div class=\"image-display-basic ".concat(this.gridImagesCover ? "bg-image-cover" : "", "\" style=\"background-image: url('").concat(displayImage, "')\"></div></div>");
424        }
425      } else {
426        displayImageView = '<div class="top-img placeholder image-basic" style="background: #f1f1f1;"></div>';
427      }
428
429      titleContainer += "<div class=\"title\">".concat(item.name, "</div>");
430      var content = "\n\t\t\t<div class=\"grid-item compact stock-category-grid-item linked id=\"grid-item-".concat(item.id, "\" data-grid-stock-category-id=\"").concat(item.id, "\" tabindex=\"0\" tabindex=\"0\">\n\t\t\t\t<div class=\"top-content\">\n\t\t\t\t\t\t").concat(displayImageView, "\n\t\t\t\t</div>\n        <div class=\"fh-stock-title-container\">").concat(titleContainer, "</div>\n\t\t\t</div>\n\t\t");
431      return content;
432    }
433  }, {
434    key: "buildEntityListView",
435    value: function buildEntityListView(items) {
436      var gridItems = "";
437
438      for (var _i6 = 0; _i6 < items.length; _i6++) {
439        var item = items[_i6];
440        var view = this.buildItem(item);
441        gridItems += "<div class=\"grid-col\">".concat(view, "</div>");
442      }
443
444      var content = "\n\t\t<div class=\"firehawk-crm-large-grid-view\">
444\n\t\t\t\t".concat(gridItems, "\n\t\t</div>\n\t\t");
445      jQuery(this.listElement).html(content);
446    }
447  }, {
448    key: "addListeners",
449    value: function addListeners() {
450      var _this = this;
451
452      jQuery(this.rootElement).delegate('#display-change-btn', 'click', function (event) {
453        event.preventDefault();
454
455        _this.toggleDisplayView();
456      });
457      jQuery(this.pagination).delegate('.fcrm-pagination-page', 'click', function (event) {
458        event.preventDefault();
459        var current = jQuery(event.currentTarget);
460        var pageNumber = jQuery.trim(current.attr('data-num'));
461        if (!pageNumber || current.hasClass('disabled') || current.hasClass('active')) return;
462        var newPage = pageNumber - 1;
463
464        _this.getEntities(_this.pageSize * newPage);
465      }); // Previous button click
466
467      jQuery(this.pagination).delegate('.fcrm-pagination-previous', 'click', function (event) {
468        event.preventDefault();
469        var current = jQuery(event.currentTarget);
470        var pageNumber = jQuery.trim(current.attr('data-num'));
471        if (!pageNumber || current.hasClass('disabled')) return;
472        var newPage = pageNumber - 1;
473
474        _this.getEntities(_this.pageSize * newPage);
475      }); // Next button click
476
477      jQuery(this.pagination).delegate('.fcrm-pagination-next', 'click', function (event) {
478        event.preventDefault();
479        var current = jQuery(event.currentTarget);
480        var pageNumber = jQuery.trim(current.attr('data-num'));
481        if (!pageNumber || current.hasClass('disabled')) return;
482        var newPage = pageNumber - 1;
483
484        _this.getEntities(_this.pageSize * newPage);
485      });
486      jQuery(this.listElement).delegate(".grid-item", "click", function (event) {
487        var gridId = jQuery(event.currentTarget).data("grid-stock-id");
488
489        if (gridId && gridId.length) {
490          if (_this.openDetailInModal) {
491            _this.openItemDetailModal(gridId);
492          } else {
493            _this.openStockItemDetailView(gridId);
494          }
495        }
496      });
497      jQuery(this.listElement).delegate(".grid-item", "keypress", function (event) {
498        var gridId = jQuery(event.currentTarget).data("grid-stock-id");
499
500        if (event.which == 13 && gridId && gridId.length) {
501          if (_this.openDetailInModal) {
502            _this.openItemDetailModal(gridId);
503          } else {
504            _this.openStockItemDetailView(gridId);
505          }
506        }
507      });
508      jQuery(this.listElement).delegate(".fh-add-to-cart", 'click', function (event) {
509        event.preventDefault();
510        event.stopPropagation();
511        var current = jQuery(event.currentTarget);
512        var stockId = current.data("stock");
513
514        _this.addToCart(stockId, current);
515      });
516      jQuery(this.listElement).delegate(".view-cart-button", 'click', function (event) {
517        event.stopPropagation();
518      });
519      jQuery(this.rootElement).delegate(".slider-preview .fh-add-to-cart", 'click', function (event) {
520        event.preventDefault();
521        event.stopPropagation();
522        var current = jQuery(event.currentTarget);
523        var stockId = current.data("stock");
524
525        _this.addToCart(stockId, current);
526      });
527      jQuery(this.rootElement).delegate(".slider-preview .view-cart-button", 'click', function (event) {
528        event.stopPropagation();
529      });
530      jQuery(this.stockCategoryPagination).delegate('.fcrm-pagination-page', 'click', function (event) {
531        event.preventDefault();
532        var current = jQuery(event.currentTarget);
533        var pageNumber = jQuery.trim(current.attr('data-num'));
534        if (!pageNumber || current.hasClass('disabled') || current.hasClass('active')) return;
535        var newPage = pageNumber - 1;
536
537        _this.getEntities(_this.stockCategoryPageSize * newPage);
538      }); // Previous button click
539
540      jQuery(this.stockCategoryPagination).delegate('.fcrm-pagination-previous', 'click', function (event) {
541        event.preventDefault();
542        var current = jQuery(event.currentTarget);
543        var pageNumber = jQuery.trim(current.attr('data-num'));
544        if (!pageNumber || current.hasClass('disabled')) return;
545        var newPage = pageNumber - 1;
546
547        _this.getEntities(_this.stockCategoryPageSize * newPage);
548      }); // Next button click
549
550      jQuery(this.stockCategoryPagination).delegate('.fcrm-pagination-next', 'click', function (event) {
551        event.preventDefault();
552        var current = jQuery(event.currentTarget);
553        var pageNumber = jQuery.trim(current.attr('data-num'));
554        if (!pageNumber || current.hasClass('disabled')) return;
555        var newPage = pageNumber - 1;
556
557        _this.getEntities(_this.stockCategoryPageSize * newPage);
558      });
559      jQuery(this.stockCategoryListElement).delegate(".grid-item", "click", function (event) {
560        var gridStockCategoryId = jQuery(event.currentTarget).data("grid-stock-category-id");
561        if (gridStockCategoryId && gridStockCategoryId.length) _this.openStockCategoryItemDetailVie
561w(gridStockCategoryId); // let gridItem = this.getGridItem(gridId)
562        // if (gridItem) {
563        //   this.openItemDetailModal(gridItem)
564        // }
565      });
566      jQuery(this.stockCategoryListElement).delegate(".grid-item", "keypress", function (event) {
567        var gridStockCategoryId = jQuery(event.currentTarget).data("grid-stock-category-id"); // let gridItem = this.getGridItem(gridId)
568        // if (gridItem) {
569        //   this.openItemDetailModal(gridItem)
570        // }
571
572        if (event.which == 13) {
573          if (gridStockCategoryId && gridStockCategoryId.length) _this.openStockCategoryItemDetailView(gridStockCategoryId);
574        }
575      });
576      jQuery(this.rootElement).delegate(".fh-searchbox", "keyup", function (event) {
577        _this.query = event.currentTarget.value;
578        if (_this.searchDebounce) clearTimeout(_this.searchDebounce);
579        _this.searchDebounce = setTimeout(function () {
580          _this.reloadView(0, _this.query);
581        }, 500);
582      });
583      jQuery(this.rootElement).delegate(".fa-times-circle", 'click', function (event) {
584        _this.query = null;
585        jQuery(_this.rootElement).find(".fh-searchbox").val("");
586
587        _this.reloadView(0, _this.query);
588      }); // jQuery(this.rootElement).children(".fh-searchbox").on('change, blur', function(e){
589      // 	alert($(this).parents('div:first').attr('id'));
590      // });
591    }
592  }, {
593    key: "openStockItemDetailView",
594    value: function openStockItemDetailView(gridItem) {
595      window.location.href = "/".concat(this.stockSlug, "?stock=").concat(gr
595idItem, "#firehawk-link-target");
596    }
597  }, {
598    key: "openStockCategoryItemDetailView",
599    value: function openStockCategoryItemDetailView(gridItem) {
600      window.location.href = "./?category=".concat(gridItem);
601    }
602  }, {
603    key: "openItemDetailModal",
604    value: function openItemDetailModal(gridId) {
605      var _this$stockIds,
606          _this2 = this;
607
608      var gridItem = this.getGridItem(gridId);
609      if (!gridItem) return;
610      var nextId = "";
611      var prevId = "";
612      var currentIndex = (_this$stockIds = this.stockIds) === null || _this$stockIds === void 0 ? void 0 : _this$stockIds.findIndex(function (item) {
613        return item === gridId;
614      });
615
616      if (currentIndex >= 0) {
617        nextId = this.stockIds[currentIndex + 1];
618        prevId = this.stockIds[currentIndex - 1];
619      }
620
621      var modalContainer = jQuery(this.listElement).parent(".firehawk-crm-cart");
622      var modal = new FirehawkCRMStockDetailModal(gridItem, {
623        container: modalContainer,
624        defaultImage: this.defaultImageUrl,
625        prevId: prevId,
626        nextId: nextId
627      });
628      modal.containDisplayImage = this.containDetailDisplayImage;
629      modal.allowBackorders = this.allowBackorders;
630      modal.cartSlug = this.cartSlug;
631      modal.show();
632      if (modal.nextButton) modal.nextButton.addEventListener("click", function () {
633        modal.hide();
634
635        _this2.openItemDetailModal(nextId);
636      });
637      if (modal.prevButton) modal.prevButton.addEventListener("click", function () {
638        modal.hide();
639
640        _this2.openItemDetailModal(prevId);
641      });
642    }
643  }, {
644    key: "addToCart",
645    value: function addToCart(stock, currentTarget) {
646      var _this3 = this;
647
648      if (this.addingToCart[stock] == true) return;
649      this.addingToCart[stock] = true;
650      jQuery(currentTarget).addClass("loading");
651      var params = {
652        stock: stock
653      };
654      jQuery.ajax({
655        method: 'post',
656        url: ajax_var.url,
657        data: {
658          action: 'add_to_cart',
659          params: params
660        }
661      }).done(function (response) {
662        if (jQuery(currentTarget).parent().find(".view-cart-button").length == 0) {
663          jQuery(currentTarget).after("<a class=\"btn btn-link view-cart-button\" href=\"/".concat(_this3.cartSlug, "\">View Shortlist</a>"));
664        }
665      }).fail(function () {}).always(function () {
666        jQuery(currentTarget).removeClass("loading");
667        _this3.addingToCart[stock] = null;
668      });
669    }
670  }, {
671    key: "getGridItem",
672    value: function getGridItem(itemId) {
673      if (!itemId || !itemId.length) return null;
674      return this.pageItems.filter(function (e) {
675        return e.id == itemId;
676      })[0];
677    }
678  }, {
679    key: "getEntities",
680    value: function getEntities(from) {
681      if (!this.ignoreStockSearch) {
682        this.getStockItems(from);
683      }
684
685      if (this.query && this.query.length) {
686        this.clearCurrentStockCategoryGrid();
687      } else {
688        this.getCategories(from);
689      }
690    }
691  }, {
692    key: "getCategories",
693    value: function getCategories(from) {
694      var _this4 = this;
695
696      this.stockCategoryListElement.addClass("loading");
697      this.stockCategoryListElement.append(this.categoryLoadingOverlay);
698      var params = {
699        size: this.pageSize || 16,
700        from: from || 0
701      };
702
703      if (this.categorySorting && Array.isArray(this.categorySorting)) {
704        params["sort"] = this.categorySorting;
705      }
706
707      if (this.categoryTags && Array.isArray(this.categoryTags)) {
708        params["tags"] = this.categoryTags;
709      }
710
711      if (this.categoryId && this.categoryId.length) {
712        if (this.categoryId == "all" && this.parentCategoryId && this.parentCategoryId.length) {
713          params["category"] = this.parentCategoryId;
714        } else {
715          params["category"] = this.categoryId;
716        }
717      }
718
719      if (this.query) {
720        params["query"] = this.query;
721      }
722
723      var page = (from || 0) / this.pageSize || 0;
724      this.stockCategoryPage = page;
725
726      if (this.stockCategorySearchRequest) {
727        this.stockCategorySearchRequest.abort();
728      }
729
730      this.stockCategorySearchRequest = jQuery.ajax({
731        method: 'post',
732        url: ajax_var.url,
733        data: {
734          action: 'get_stock_categories',
735          params: params
736        }
737      }).done(function (data) {
738        var results = [];
739        var total = 0;
740
741        if (data && data.results) {
742          total = data.total || 0;
743          results = data.results;
744        }
745
746        _this4.stockCategoryTotalItems = total;
747        _this4.stockCategoryTotalPages = Math.ceil(total / _this4.stockCategoryPageSize);
748        _this4.stockCategoryPageItems = results;
749
750        if (_this4.stockCategoryTotalItems == 0) {
751          _this4.stockCategoryListElement.hide();
752
753          _this4.stockCategoryPagination.hide();
754
755          _this4.stockCategoryDivider.hide();
756        } else if (_this4.stockCategoryTotalItems <= _this4.stockCategoryPageSize) {
757          _this4.stockCategoryListElement.show();
758
759          _this4.stockCategoryPagination.hide();
760
761          _this4.stockCategoryDivider.show();
762        } else {
763          _this4.stockCategoryListElement.show();
764
765          _this4.stockCategoryPagination.show();
766
767          _this4.stockCategoryDivider.show();
768        }
769
770        _this4.clearCurrentStockCategoryGrid();
771
772        _this4.updatePagination(_this4.stockCategoryPage, _this4.stockCategoryTotalPages, _this4.stockCategoryPagination);
773
774        _this4.buildCategoryGrid(results);
775
776        _this4.categoryLoadingOverlay.hide();
777
778        _this4.stockCategoryListElement.removeClass("loading");
779      }).fail(function () {
780        _this4.categoryLoadingOverlay.hide();
781
782        _this4.stockCategoryListElement.removeClass("loading");
783      });
784    }
785  }, {
786    key: "getStockItems",
787    value: function getStockItems(from) {
788      var _this5 = this;
789
790      this.listElement.addClass("loading");
791      this.listElement.append(this.loadingOverlay);
792      this.loadingOverlay.show();
793      this.rootElement.find(".slider-view").addClass("loading");
794      this.rootElement.find(".slider-view").append(this.carouselLoadingOverlay);
795      this.carouselLoadingOverlay.show();
796      var params = {
797        size: this.pageSize || 16,
798        from: from || 0,
799        customTerms: this.customTerms
800      };
801
802      if (this.query) {
803        jQuery(this.rootElement).find(".fa-times-circle").show();
804        params["query"] = this.query;
805      } else {
806        jQuery(this.rootElement).find(".fa-times-circle").hide();
807      }
808
809      if (this.categoryId && this.categoryId.length) {
810        if (this.categoryId == "all" && this.parentCategoryId && this.parentCategoryId.length) {
811          params["category"] = this.parentCategoryId;
812        } else {
813          params["category"] = this.categoryId;
814        }
815      }
816
817      if (this.showOnlyCartStock == true) {
818        params.cartOnly = true;
819      }
820
821      if (this.openDetailInModal) {
822        params.gallery = true;
823      }
824
825      if (this.stockSorting && Array.isArray(this.stockSorting)) {
826        params["sorting"] = this.stockSorting;
827      }
828
829      var page = (from || 0) / this.pageSize || 0;
830      this.page = page;
831
832      if (this.searchRequest) {
833        this.searchRequest.abort();
834      }
835
836      this.searchRequest = jQuery.ajax({
837        method: 'post',
838        url: ajax_var.url,
839        data: {
840          action: 'get_category_stock',
841          params: params
842        }
843      }).done(function (response) {
844        var results = [];
845        var total = 0;
846
847        if (response) {
848          var data = JSON.parse(response);
849
850          if (data && data.result) {
851            total = data.total || 0;
852            results = data.result;
853          }
854        }
855
856        _this5.stockIds = results.filter(function (res) {
857          return res.id;
858        }).map(function (res) {
859          return res.id;
860        });
861        _this5.totalItems = total;
862        _this5.totalPages = Math.ceil(total / _this5.pageSize);
863        _this5.pageItems = results;
864
865        if (_this5.totalItems == 0 || _this5.totalItems <= _this5.pageSize) {
866          _this5.pagination.hide();
867        } else {
868          _this5.pagination.show();
869        }
870
871        if (_this5.totalItems == 0) {
872          jQuery(_this5.rootElement).find("#display-change-btn").hide();
873        } else {
874          jQuery(_this5.rootElement).find("#display-change-btn").show();
875        }
876
877        _this5.clearCurrentGrid();
878
879        _this5.updatePagination(_this5.page, _this5.totalPages, _this5.pagination);
880
881        if (!_this5.filters) _this5.createFilters(params);
882        if (!_this5.sorted) _this5.createSort();
883
884        _this5.buildEntityListView(results);
885
886        if (!results.length) {
887          _this5.showEmptyListView();
888        }
889
890        if (_this5.displayView == "carousel") {
891          _this5.setupCarouselGallery(_this5.pageItems);
892        }
893
894        _this5.carouselLoadingOverlay.hide();
895
896        _this5.rootElement.find(".slider-view").removeClass("loading");
897      }).fail(function () {
898        _this5.loadingOverlay.hide();
899
900        _this5.carouselLoadingOverlay.hide();
901
902        _this5.listElement.removeClass("loading");
903
904        _this5.rootElement.find(".slider-view").removeClass("loading");
905      });
906    }
907  }, {
908    key: "clearCurrentStockCategoryGrid",
909    value: function clearCurrentStockCategoryGrid() {
910      this.stockCategoryListElement.html("");
911    }
912  }, {
913    key: "clearCurrentGrid",
914    value: function clearCurrentGrid() {
915      this.listElement.html("");
916    }
917  }, {
918    key: "showEmptyListView",
919    value: function showEmptyListView() {
920      if (this.hideEmptyList) {
921        jQuery(this.listElement).html();
922        this.stockCategoryDivider.hide();
923        return;
924      }
925
926      var emptyView = jQuery("<div class=\"empty-view\">No items found</div>");
927      jQuery(this.listElement).html(emptyView);
928    }
929  }, {
930    key: "getGridItemActions",
931    value: function getGridItemActions(itemId) {
932      var actions = [];
933
934      if (!this.filterMyItems && this.user && this.user.roles) {
935        var hasRole = false;
936
937        for (var i in this.user.roles) {
938          var index = +i;
939          var role = this.user.roles[index];
940
941          if (role == "supplier") {
942            hasRole = true;
943            break;
944          }
945        }
946
947        if (hasRole) {
948          actions.push({
949            action: "send-quote",
950            title: "Send Quote"
951          });
952        }
953      }
954
955      return actions;
956    }
957  }, {
958    key: "updatePagination",
959    value: function updatePagination(page, totalPages, paginationElement) {
960      if (!paginationElement) return;
961      var self = this;
962      var currentPage = page + 1;
963      var pageRange = 2;
964      var totalPage = totalPages;
965      var rangeStart = currentPage - pageRange;
966      var rangeEnd = currentPage + pageRange;
967
968      if (rangeEnd > totalPage) {
969        rangeEnd = totalPage;
970        rangeStart = totalPage - pageRange * 2;
971        rangeStart = rangeStart < 1 ? 1 : rangeStart;
972      }
973
974      if (rangeStart <= 1) {
975        rangeStart = 1;
976        rangeEnd = Math.min(pageRange * 2 + 1, totalPage);
977      }
978
979      var pageLink = '';
980      var prevText = '&laquo;';
981      var nextText = '&raquo;';
982      var ellipsisText = '...';
983      var activeClassName = 'active';
984      var disableClassName = 'disabled';
985      var showFirstOnEllipsisShow = true;
986      var showLastOnEllipsisShow = true;
987      var html = '';
988      var i; // Whether to display header
989
990      html += '<div class="fcrm-pagination-pages">';
991      html += '<ul>'; // Whether to display the Previous button
992
993      if (currentPage <= 1) {} else {
994        html += '<li class="fcrm-pagination-previous" data-num="' + (currentPage - 1) + '" title="Previous page"><a href="' + pageLink + '">' + prevText + '<\/a><\/li>';
995      } // Whether to display the pages
996
997
998      if (rangeStart <= 3) {
999        for (i = 1; i < rangeStart; i++) {
1000          if (i == currentPage) {
1001            html += '<li class="fcrm-pagination-page ' + activeClassName + '" data-num="' + i + '"><a>' + i + '<\/a><\/li>';
1002          } else {
1003            html += '<li class="fcrm-pagination-page" data-num="' + i + '"><a href="' + pageLink + '">' + i + '<\/a><\/li>';
1004          }
1005        }
1006      } else {
1007        if (showFirstOnEllipsisShow) {
1008          html += '<li class="fcrm-pagination-first fcrm-pagination-page" data-num="1"><a href="' + pageLink + '">1<\/a><\/li>';
1009        }
1010
1011        html += '<li class="fcrm-pagination-ellipsis ' + disableClassName + '"><a>' + ellipsisText + '<\/a><\/li>';
1012      }
1013
1014      for (i = rangeStart; i <= rangeEnd; i++) {
1015        if (i == currentPage) {
1016          html += '<li class="fcrm-pagination-page ' + activeClassName + '" data-num="' + i + '"><a>' + i + '<\/a><\/li>';
1017        } else {
1018          html += '<li class="fcrm-pagination-page" data-num="' + i + '"><a href="' + pageLink + '">' + i + '<\/a><\/li>';
1019        }
1020      }
1021
1022      if (rangeEnd >= totalPage - 2) {
1023        for (i = rangeEnd + 1; i <= totalPage; i++) {
1024          html += '<li class="fcrm-pagination-page" data-num="' + i + '"><a href="' + pageLink + '">' + i + '<\/a><\/li>';
1025        }
1026      } else {
1027        html += '<li class="fcrm-pagination-ellipsis ' + disableClassName + '"><a>' + ellipsisText + '<\/a><\/li>';
1028
1029        if (showLastOnEllipsisShow) {
1030          html += '<li class="fcrm-pagination-last fcrm-pagination-page" data-num="' + totalPage + '"><a href="' + pageLink + '">' + totalPage + '<\/a><\/li>';
1031        }
1032      }
1033
1034      if (currentPage >= totalPage) {} else {
1035        html += '<li class="fcrm-pagination-next" data-num="' + (currentPage + 1) + '" title="Next page"><a href="' + pageLink + '">' + nextText + '<\/a><\/li>';
1036      }
1037
1038      html += '<\/ul><\/div>';
1039
1040      if (totalPage > 1) {
1041        jQuery(paginationElement).html(html);
1042      } else {
1043        jQuery(paginationElement).html(html);
1044      }
1045    }
1046  }, {
1047    key: "reloadView",
1048    value: function reloadView(from) {
1049      var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
1050      this.query = query; // this.buildEntityListView([])
1051
1052      this.getEntities(from);
1053    }
1054  }, {
1055    key: "applyDateRange",
1056    value: function applyDateRange(startDate, endDate) {
1057      this.startDate = startDate;
1058      this.endDate = endDate;
1059      this.getEntities(0);
1060    }
1061  }, {
1062    key: "applyStockSorting",
1063    value: function applyStockSorting(sorting) {
1064      this.stockSorting = sorting;
1065      this.getEntities(this.page * this.pageSize);
1066    }
1067  }, {
1068    key: "search",
1069    value: function search(query) {
1070      this.query = query;
1071      this.getEntities(0);
1072    }
1073  }, {
1074    key: "setupView",
1075    value: function setupView(size) {
1076      this.pageSize = size ? +size : 16;
1077      this.stockCategoryPageSize = size ? +size : 16;
1078      this.reloadView(0);
1079    }
1080  }, {
1081    key: "createFilters",
1082    value: function createFilters(params) {
1083      var _this6 = this;
1084
1085      var title = document.querySelector(".fcrm-cart-grid-title");
1086      var filters = document.querySelector(".fcrm-filters-container") || document.createElement('div');
1087      filters.className = 'fcrm-filters-container';
1088      filters.innerHTML = "\n\t\t\t<select id=\"fcrm-filters-select\" class=\"dropdown\"\">\n\t\t\t\t\t<option disabled selected value=\"default\">Please select a filter</option>\n\t\t\t</select>\n\t\t\t<button id=\"fcrm-filters-clear\">x</button>\n\t\t";
1089      title.parentNode.insertBefore(filters, title.nextSibling);
1090      var dropdownMenu = document.querySelector('#fcrm-filters-select');
1091      var button = document.querySelector('#fcrm-filters-clear');
1092      button.addEventListener('click', function () {
1093        dropdownMenu.value = 'default';
1094        dropdownMenu.removeAttribute('data-dirty');
1095
1096        _this6.getStockItems(0);
1097
1098        _this6.addListeners();
1099      });
1100      dropdownMenu.addEventListener('change', function (event) {
1101        dropdownMenu.setAttribute('data-dirty', true);
1102        _this6.customTerms = event.target.value == "default" ? [] : [{
1103          field: "tags",
1104          value: event.target.value
1105        }];
1106
1107        _this6.getStockItems(0);
1108      });
1109      params.size = 1000;
1110      jQuery.ajax({
1111        method: 'post',
1112        url: ajax_var.url,
1113        data: {
1114          action: 'get_category_stock',
1115          params: params
1116        }
1117      }).done(function (response) {
1118        var results = [];
1119        var total = 0;
1120
1121        if (response) {
1122          var data = JSON.parse(response);
1123
1124          if (data && data.result) {
1125            total = data.total || 0;
1126            results = data.result;
1127            var tags = results.reduce(function (set, item) {
1128              item.tags.forEach(function (tag) {
1129                return set.add(tag);
1130              });
1131              return set;
1132            }, new Set());
1133            tags = Array.from(tags);
1134            if (!_this6.filters) _this6.filters = tags;
1135            tags.forEach(function (tag) {
1136              var option = document.createElement('option');
1137              option.innerHTML = tag.charAt(0).toUpperCase() + tag.slice(1);
1138              option.value = tag;
1139              dropdownMenu.appendChild(option);
1140            });
1141          }
1142        }
1143      }).fail(function () {});
1144    }
1145  }, {
1146    key: "createSort",
1147    value: function createSort() {
1148      var _this7 = this;
1149
1150      var title = document.querySelector(".fcrm-cart-grid-title");
1151      var sort = document.querySelector(".fcrm-sort-container") || document.createElement('div');
1152      sort.className = 'fcrm-sort-container';
1153      sort.innerHTML = "\n\t\t\t<select id=\"fcrm-sort-select\" class=\"dropdown\"\">\n\t\t\t\t\t<option value=\"name.sort_numeric:asc\">Name: A to Z</option>\n\t\t\t\t\t<option value=\"name.sort_numeric:desc\">Name: Z to A</option>\n\t\t\t\t\t<option value=\"priceRetailInclTax:desc\">Price: High to Low</option>\n\t\t\t\t\t<option value=\"priceRetailInclTax:asc\">Price: Low to High</option>\n\t\t\t</select>\n\t\t";
1154      this.sorted = true;
1155      title.parentNode.insertBefore(sort, title.nextSibling);
1156      var dropdownMenu = document.querySelector('#fcrm-sort-select');
1157      dropdownMenu.addEventListener('change', function (event) {
1158        _this7.stockSorting = [{
1159          "field": event.target.value.split(':')[0],
1160          "order": event.target.value.split(':')[1]
1161        }];
1162
1163        _this7.getStockItems(0);
1164      });
1165    }
1166  }]);
1167
1168  return FirehawkCRMStockGrid;
1169}();
1170//# sourceMappingURL=fcrm-stock-grid.js.map

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.