1"use strict"; 2 3function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } 4 5function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } 6 7function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } 8 9function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } 10 11function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } 12 13function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } 14 15function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } 16 17function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } 18 19function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 20 21function _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); } } 22 23function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } 24 25function _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; } 26 27var Shuffle = window.Shuffle; 28 29var FirehawkCRMServiceTributeTrees = /*#__PURE__*/function () { 30 function FirehawkCRMServiceTributeTrees(element, pagination, client) { 31 _classCallCheck(this, FirehawkCRMServiceTributeTrees); 32 33 _defineProperty(this, "listElement", null); 34 35 _defineProperty(this, "pagination", null); 36 37 _defineProperty(this, "purchaseTreeModal", null); 38 39 _defineProperty(this, "loadingOverlay", null); 40 41 _defineProperty(this, "entityType", null); 42 43 _defineProperty(this, "category", null); 44 45 _defineProperty(this, "randomSorting", null); 46 47 _defineProperty(this, "randomSortKey", null); 48 49 _defineProperty(this, "totalPages", 0); 50 51 _defineProperty(this, "totalItems", 0); 52 53 _defineProperty(this, "page", -1); 54 55 _defineProperty(this, "pageSize", 12); 56 57 _defineProperty(this, "nextPageButton", null); 58 59 _defineProperty(this, "searchRequest", null); 60 61 _defineProperty(this, "filterMyItems", false); 62 63 _defineProperty(this, "actionModal", null); 64 65 _defineProperty(this, "actionModalElement", null); 66 67 _defineProperty(this, "client", null); 68 69 _defineProperty(this, "clientName", null); 70 71 _defineProperty(this, "pageItems", []); 72 73 _defineProperty(this, "verifyCode", null); 74 75 _defineProperty(this, "verifyId", null); 76 77 _defineProperty(this, "formSubmitData", {}); 78 79 _defineProperty(this, "verifyInput", null); 80 81 _defineProperty(this, "shuffle", null); 82 83 _defineProperty(this, "itemsWaiting", {}); 84 85 _defineProperty(this, "dateLocale", null); 86 87 _defineProperty(this, "cartId", null); 88 89 _defineProperty(this, "treeStock", null); 90 91 _defineProperty(this, "country", null); 92 93 this.listElement = element; 94 this.pagination = pagination; 95 this.client = client; 96 this.loadingOverlay = jQuery("<div class=\"loading-overlay\"><i class=\"far fa-spinner-third fa-spin\"></i></div>"); 97 this.listElement.addClass("loading"); 98 this.listElement.append(this.loadingOverlay); 99 this.addListeners(); 100 this.shuffle = new Shuffle(element, { 101 itemSelector: '.grid-item', 102 sizer: '.my-sizer-element' 103 }); 104 } 105 106 _createClass(FirehawkCRMServiceTributeTrees, [{ 107 key: "buildItem", 108 value: function buildItem(item) { 109 var name = ""; 110 var numberOfTrees = 1; 111 112 if (item.numberOfTrees) { 113 numberOfTrees = +item.numberOfTrees; 114 } 115 116 var treeCount = numberOfTrees > 1 ? "".concat(numberOfTrees, " trees") : "a tree"; 117 118 if (item.anonymous == "Yes" || item.anonymous == true) { 119 name = "Anonymous"; 120 } else { 121 if (item.displayName && item.displayName.length) { 122 name = item.displayName; 123 } else if (item.firstName) { 124 name = item.firstName; 125 if (item.lastName) name += " " + item.lastName; 126 } 127 } 128 129 var title = "<div class=\"item-title\"><div class=\"title\"><h5>".concat(name, "</h5>"); 130 131 if (item.timestamp) { 132 var dateTime = ""; 133 134 if (this.dateLocale && this.dateLocale == "en-US") { 135 dateTime = moment(item.timestamp).format("MM/DD/YYYY"); 136 } else { 137 dateTime = moment(item.timestamp).format("DD/MM/YYYY"); 138 } 139
140 title += "<small class=\"item-date text-muted\">Planted ".concat(treeCount, " on ").concat(dateTime, "</small>"); 141 } 142 143 title += "</div>"; 144 title += "<div class=\"actions\"></div>"; 145 title += "</div>"; 146 var isLiked = false; 147 var likesCount = item.likes > 0 ? item.likes : 0; 148 149 if (this.getCookie("tribute-".concat(item.id, "-liked"))) { 150 isLiked = true; 151 } 152 153 var extraClasses = ""; 154 var itemMessage = (item.message || "").replace(/(?:\r\n|\r|\n)/g, '<br>'); 155 var message = ""; 156 157 if (itemMessage.length > 0) { 158 message = "<div class=\"item-message\">".concat(itemMessage, "</div>"); 159 } else { 160 extraClasses = "no-message"; 161 } 162 163 var footer = "<div class=\"item-footer\"><div class=\"likes\"><a class=\"like-btn ".concat(isLiked ? "liked" : "", "\"><i class=\"far fa-heart\"></i></a><span class=\"counter\">").concat(likesCount, "</span></div>"); 164 footer += "</div>"; 165 var content = "\n\t\t\t<div class=\"item-view tribute-item tribute-tree ".concat(extraClasses, "\" id=\"tribute-tree-").concat(item.id, "\" data-tree-id=\"").concat(item.id, "\">\n\t\t\t\t<div class=\"tree-background normal\" aria-hidden=\"true\"></div>\n\t\t\t\t<div class=\"row\">\n\t\t\t\t\t<div class=\"col\">\n\t\t\t\t\t\t<div class=\"item-content\">\n\t\t\t\t\t\t\t").concat(title, "\n\t\t\t\t\t\t\t").concat(message, "\n\t\t\t\t\t\t\t").concat(footer, "\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"); 166 return content; 167 } 168 }, { 169 key: "insertNewItem", 170 value: function insertNewItem(item) { 171 var _this = this; 172 173 var gridItems = []; 174 var view = this.buildItem(item); 175 gridItems.push(jQuery("<div class=\"grid-item col-12 col-md-6 col-lg-4\">".concat(view, "</div>")).get(0)); 176 gridItems.forEach(function (element) { 177 jQuery(_this.listElement).prepend(element); 178 }); 179 this.shuffle.add(gridItems); 180 this.shuffle.update(); 181 } 182 }, { 183 key: "updateItemMessage", 184 value: function updateItemMessage(id, message) { 185 for (var _i2 = 0, _this$pageItems2 = this.pageItems; _i2 < _this$pageItems2.length; _i2++) { 186 var item = _this$pageItems2[_i2]; 187 188 if (item.id == id) { 189 item.message = message; 190 break; 191 } 192 } 193 } 194 }, { 195 key: "clearCurrentList", 196 value: function clearCurrentList() { 197 var items = _toConsumableArray(this.shuffle.items); 198 199 items.shift(); 200 this.shuffle.remove(items.map(function (e) { 201 return e.element; 202 })); 203 } 204 }, { 205 key: "buildEntityListView", 206 value: function buildEntityListView(items) { 207 var _this2 = this; 208 209 var gridItems = []; 210 211 for (var _i4 = 0; _i4 < items.length; _i4++) { 212 var item = items[_i4]; 213 var view = this.buildItem(item); 214 gridItems.push(jQuery("<div class=\"grid-item col-12 col-sm-6 col-lg-4\">".concat(view, "</div>")).get(0)); 215 } 216 217 gridItems.forEach(function (element) { 218 jQuery(_this2.listElement).append(element); 219 }); 220 this.shuffle.add(gridItems); 221 this.shuffle.update(); 222 } 223 }, { 224 key: "addListeners", 225 value: function addListeners() { 226 var _this3 = this; 227 228 jQuery(this.pagination).delegate('.fcrm-pagination-page', 'click', function (event) { 229 event.preventDefault(); 230 var current = jQuery(event.currentTarget); 231 var pageNumber = jQuery.trim(current.attr('data-num')); 232 if (!pageNumber || current.hasClass('disabled') || current.hasClass('active')) return; 233 var newPage = pageNumber - 1; 234 235 _this3.getEntities(_this3.pageSize * newPage); 236 }); // Previous button click 237 238 jQuery(this.pagination).delegate('.fcrm-pagination-previous', 'click', function (event) { 239 event.preventDefault(); 240 var current = jQuery(event.currentTarget); 241 var pageNumber = jQuery.trim(current.attr('data-num')); 242 if (!pageNumber || current.hasClass('disabled')) return; 243 var newPage = pageNumber - 1; 244 245 _this3.getEntities(_this3.pageSize * newPage); 246 }); // Next button click 247 248 jQuery(this.pagination).delegate('.fcrm-pagination-next', 'click', function (event) { 249 event.preventDefault(); 250 var current = jQuery(event.currentTarget); 251 var pageNumber = jQuery.trim(current.attr('data-num')); 252 if (!pageNumber || current.hasClass('disabled')) return; 253 var newPage = pageNumber - 1; 254 255 _this3.getEntities(_this3.pageSize * newPage); 256 }); 257 jQuery(this.listElement).delegate(".tribute-item .like-btn", "click", function (event) { 258 var item = jQuery(event.currentTarget); 259 var treeId = item.parents(".tribute-item").data("tree-id"); 260 if (_this3.itemsWaiting[treeId]) return; 261 262 if (item.hasClass("liked")) { 263 item.removeClass("liked"); 264 265 _this3.setCookie("tribute-".concat(treeId, "-liked"), "false", -1); 266 267 _this3.unlikeTributeTree(treeId); 268 } else { 269 item.addClass("liked"); // 24 hours x 30 = 30 days 270 271 var cookieExpiry = 24 * 30; 272 273 _this3.setCookie("tribute-".concat(treeId, "-liked"), "true", cookieExpiry); 274 275 _this3.likeTributeTree(treeId); 276 } 277 }); 278 } 279 }, { 280 key: "getTreeStock", 281 value: function getTreeStock() { 282 var _this4 = this; 283 284 jQuery.ajax({ 285 method: 'post', 286 url: ajax_var.url, 287 data: { 288 action: 'get_tree_stock' 289 } 290 }).done(function (response) { 291 if (response && response.result && response.result.stock) { 292 _this4.treeStock = response.result.stock; 293 294 if (_this4.treeStock.pricing && _this4.treeStock.pricing[0] && _this4.treeStock.pricing[0].priceValues) { 295 var price = _this4.treeStock.pricing[0].priceValues.priceInclTax; 296 297 _this4.actionModalElement.find("#page-1 .tree-price-info").show(); 298 299 _this4.actionModalElement.find("#page-1 .tree-price-info .tree-price").html("$".concat(price)); 300 } else { 301 _this4.actionModalElement.find("#page-1 .tree-price-info").hide(); 302 } 303 } else { 304 _this4.treeStock = null; 305 306 _this4.actionModalElement.find("#page-1 .tree-price-info").hide(); 307 } 308 }).fail(function (xhr, status, error) { 309 var errorMessage = "Something went wrong, please try again."; 310 311 if (error.responseJSON) { 312 errorMessage = error.responseJSON.error || error.responseJSON.message || ""; 313 } 314 }); 315 } 316 }, { 317 key: "getEntities", 318 value: function getEntities(from) { 319 var _this5 = this; 320 321 if (!this.client) { 322 this.listElement.removeClass("loading"); 323 this.loadingOverlay.remove(); 324 return; 325 } 326 327 this.listElement.addClass("loading"); 328 this.listElement.append(this.loadingOverlay); 329 var params = { 330 size: this.pageSize || 16, 331 from: from || 0, 332 client: this.client || null 333 }; 334 var page = (from || 0) / this.pageSize || 0; 335 this.page = page; 336 337 if (this.searchRequest) { 338 this.searchRequest.abort(); 339 } 340 341 this.searchRequest = jQuery.ajax({ 342 method: 'post', 343 url: ajax_var.url, 344 data: { 345 action: 'get_tribute_trees', 346 params: params 347 } 348 }).done(function (response) { 349 var results = []; 350 var total = 0; 351 352 if (response) { 353 var data = JSON.parse(response); 354 355 if (data && data.results) { 356 total = data.total || 0; 357 results = data.results; 358 } 359 } 360 361 _this5.totalItems = total; 362 _this5.totalPages = Math.ceil(total / _this5.pageSize); 363 _this5.pageItems = results; 364 365 _this5.clearCurrentList(); 366 367 _this5.updatePagination(); 368 369 _this5.buildEntityListView(results); 370 371 if (!results.length) { 372 _this5.showEmptyListView(); 373 } 374 375 _this5.loadingOverlay.remove(); 376 377 _this5.listElement.removeClass("loading"); 378 }).fail(function (xhr, status, error) { 379 _this5.listElement.removeClass("loading"); 380 }); 381 } 382 }, { 383 key: "showEmptyListView", 384 value: function showEmptyListView() { 385 var emptyView = jQuery("<div class=\"empty-view\">No results found</div>"); 386 jQuery(this.listElement).html(emptyView); 387 } 388 }, { 389 key: "updatePagination", 390 value: function updatePagination() { 391 if (!this.pagination) return; 392 var self = this; 393 var currentPage = self.page + 1; 394 var pageRange = 2; 395 var totalPage = self.totalPages; 396 var rangeStart = currentPage - pageRange; 397 var rangeEnd = currentPage + pageRange; 398 399 if (rangeEnd > totalPage) { 400 rangeEnd = totalPage; 401 rangeStart = totalPage - pageRange * 2; 402 rangeStart = rangeStart < 1 ? 1 : rangeStart; 403 } 404 405 if (rangeStart <= 1) { 406 rangeStart = 1; 407 rangeEnd = Math.min(pageRange * 2 + 1, totalPage); 408 } 409 410 var pageLink = ''; 411 var prevText = '«'; 412 var nextText = '»'; 413 var ellipsisText = '...'; 414 var activeClassName = 'active'; 415 var disableClassName = 'disabled'; 416 var showFirstOnEllipsisShow = true; 417 var showLastOnEllipsisShow = true; 418 var html = ''; 419 var i; // Whether to display header 420 421 html += '<div class="fcrm-pagination-pages">'; 422 html += '<ul>'; // Whether to display the Previous button 423 424 if (currentPage <= 1) {} else { 425 html += '<li class="fcrm-pagination-previous" data-num="' + (currentPage - 1) + '" title="Previous page"><a href="' + pageLink + '">' + prevText + '<\/a><\/li>'; 426 } // Whether to display the pages 427 428 429 if (rangeStart <= 3) { 430 for (i = 1; i < rangeStart; i++) { 431 if (i == currentPage) { 432 html += '<li class="fcrm-pagination-page ' + activeClassName + '" data-num="' + i + '"><a>' + i + '<\/a><\/li>'; 433 } else { 434 html += '<li class="fcrm-pagination-page" data-num="' + i + '"><a href="' + pageLink + '">' + i + '<\/a><\/li>'; 435 } 436 } 437 } else { 438 if (showFirstOnEllipsisShow) { 439 html += '<li class="fcrm-pagination-first fcrm-pagination-page" data-num="1"><a href="' + pageLink + '">1<\/a><\/li>'; 440 } 441 442 html += '<li class="fcrm-pagination-ellipsis ' + disableClassName + '"><a>' + ellipsisText + '<\/a><\/li>'; 443 } 444 445 for (i = rangeStart; i <= rangeEnd; i++) { 446 if (i == currentPage) { 447 html += '<li class="fcrm-pagination-page ' + activeClassName + '" data-num="' + i + '"><a>' + i + '<\/a><\/li>'; 448 } else { 449 html += '<li class="fcrm-pagination-page" data-num="' + i + '"><a href="' + pageLink + '">' + i + '<\/a><\/li>'; 450 } 451 } 452 453 if (rangeEnd >= totalPage - 2) { 454 for (i = rangeEnd + 1; i <= totalPage; i++) { 455 html += '<li class="fcrm-pagination-page" data-num="' + i + '"><a href="' + pageLink + '">' + i + '<\/a><\/li>'; 456 } 457 } else { 458 html += '<li class="fcrm-pagination-ellipsis ' + disableClassName + '"><a>' + ellipsisText + '<\/a><\/li>'; 459 460 if (showLastOnEllipsisShow) { 461 html += '<li class="fcrm-pagination-last fcrm-pagination-page" data-num="' + totalPage + '"><a href="' + pageLink + '">' + totalPage + '<\/a><\/li>'; 462 } 463 } 464 465 if (currentPage >= totalPage) {} else { 466 html += '<li class="fcrm-pagination-next" data-num="' + (currentPage + 1) + '" title="Next page"><a href="' + pageLink + '">' + nextText + '<\/a><\/li>'; 467 } 468 469 html += '<\/ul><\/div>'; 470 471 if (totalPage > 1) { 472 jQuery(this.pagination).html(html); 473 } else { 474 jQuery(this.pagination).html(); 475 } 476 } 477 }, { 478 key: "reloadView", 479 value: function reloadView(from) { 480 this.buildEntityListView([]); 481 this.getEntities(from); 482 } 483 }, { 484 key: "setupView", 485 value: function setupView(category, size) { 486 this.pageSize = size ? +size : 16; 487 this.category = category; 488 this.reloadView(0); 489 } 490 }, { 491 key: "resetTreePurchaseModal", 492 value: function resetTreePurchaseModal() { 493 if (!this.actionModalElement) return; 494 this.actionModalElement.undelegate();
495 this.actionModalElement.find("form .modal-footer .submit-btn").prop("disabled", false).html("Submit"); 496 this.actionModalElement.find("#page-1").show(); 497 this.actionModalElement.find("#page-1 form").trigger("reset"); 498 this.actionModalElement.find("#page-2").hide(); 499 this.actionModalElement.find("#page-2 form").trigger("reset"); 500 this.formSubmitData = {}; 501 this.verifyCode = null; 502 var copyOfModal = this.actionModalElement; 503 setTimeout(function () { 504 if (copyOfModal) { 505 copyOfModal.remove(); 506 } 507 }, 600); 508 } 509 }, { 510 key: "closeActionModal", 511 value: function closeActionModal() { 512 var destroy = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; 513 514 if (this.actionModal) { 515 this.actionModal.hide(); 516 } 517 518 this.actionModal = null; 519 this.resetTreePurchaseModal(); 520 } 521 }, { 522 key: "buildCreateTreeModal", 523 value: function buildCreateTreeModal() { 524 var modalContainer = jQuery("<div class=\"bs-modal modal fade fcrm-purchase-tree-modal\" id=\"fcrm-create-tree\" tabindex=\"-1\" style=\"display: none;\" aria-hidden=\"true\"></div>"); 525 var modal = jQuery('<div class="modal-dialog modal-lg modal-dialog-centered"></div>'); 526 var modalContent = jQuery('<div class="modal-content">'); 527 var modalTitle = "Plant trees"; 528 529 if (this.clientName && this.clientName.length) { 530 modalTitle = "Plant trees in memory of ".concat(this.clientName); 531 } 532 533 modalContent.append("<div class=\"modal-header px-4\"><h5 class=\"modal-title\">".concat(modalTitle, " <i class=\"fas fa-xs fa-seedling mb-1 ms-1\" aria-hidden=\"true\"></i></h5><button type=\"button\" class=\"btn-close close-modal-btn\" data-bs-dismiss=\"modal\" aria-label=\"Close\" style=\"font-size: 12px;\"></button></div>")); // Setup: Modal body 534 535 var modalBody = jQuery('<div class="modal-body px-4"></div>'); // Setup: Page 1 536 537 var page1 = jQuery('<div class="form-page" id="page-1"></div>'); 538 var page1Form = jQuery('<form></form>'); 539 var numberOfTreeOptions = [1, 2, 3, 4, 5, 10, 20, 30, 50]; 540 var treeNumberOptions = numberOfTreeOptions.map(function (option, index) { 541 return "\n\t\t\t<input type=\"radio\" class=\"btn-check\" name=\"numberOfTrees\" id=\"numberOfTrees".concat(index, "\" value=\"").concat(option, "\" autocomplete=\"off\">\n\t\t\t<label class=\"btn btn-outline-dark\" for=\"numberOfTrees").concat(index, "\">").concat(option, "</label>\n\t\t\t"); 542 }); // Page 1 form: Number of trees 543 544 page1Form.append("\n\t\t\t<div class=\"row mb-3\">\n\t\t\t\t<div class=\"col\">\n\t\t\t\t\t<label class=\"form-label\" for=\"numberOfTrees\">How many trees would you like to plant?</label><br/>\n\t\t\t\t\t<div class=\"btn-group\" role=\"group\">\n\t\t\t\t\t\t".concat(treeNumberOptions.join(""), "\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t")); 545 page1Form.append("\n\t\t\t<div class=\"bd-callout bd-callout-info tree-price-info\">\n\t\t\t\t<div class=\"tree-info\">Each tree planted costs <strong class=\"tree-price\"><i class=\"fcrms-spinner primary sm\"></i></strong></div>\n\t\t\t\t<div class=\"tree-price-totals\" style=\"display: none;\">\n\t\t\t\t\t<strong><span class=\"tree-quantity\"></span> x <span class=\"tree-price\"><i class=\"fcrms-spinner primary sm\"></i></span></strong>\n\t\t\t\t\t<div>\n\t\t\t\t\t\tTotal: <strong class=\"tree-total\"></strong>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"); // Page 1 form: Forest location 546 547 page1Form.append("\n\t\t\t<div class=\"row mb-3\">\n\t\t\t\t<div class=\"col\">\n\t\t\t\t\t<label class=\"form-label\" for=\"forest\">Where would you like to plant them?</label>\n\t\t\t\t\t<select class=\"forest-picker form-select\" id=\"forest\" name=\"forest\" required></select>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"); // Page 1 form: First & Last name 548 549 page1Form.append("\n\t\t\t<div class=\"row mb-3\">\n\t\t\t\t<div class=\"col\">\n\t\t\t\t\t<label class=\"form-label\" for=\"firstName\">First name</label>\n\t\t\t\t\t<input type=\"text\" class=\"form-control\" id=\"firstName\" name=\"firstName\" required>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"col\">\n\t\t\t\t\t<label class=\"form-label\" for=\"lastName\">Last name</label>\n\t\t\t\t\t<input type=\"text\" class=\"form-control\" id=\"lastName\" name=\"lastName\" required>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"); // Page 1 form: Email & Postcode 550 551 page1Form.append("\n\t\t\t<div class=\"row mb-3\">\n\t\t\t\t<div class=\"col\">\n\t\t\t\t\t<label class=\"form-label\" for=\"email\">Email</label>\n\t\t\t\t\t<input type=\"text\" class=\"form-control\" id=\"email\" name=\"email\" required>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"col\">\n\t\t\t\t\t<label class=\"form-label\" for=\"postcode\">Postcode</label>\n\t\t\t\t\t<input type=\"text\" class=\"form-control\" id=\"postcode\" name=\"postcode\" required>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"); 552 page1Form.append("<div class=\"bd-callout bd-callout-danger error-callout\" style=\"display: none;\"></div>"); 553 page1Form.append("\n\t\t\t<div class=\"modal-footer justify-content-between border-0 pt-3 px-0 pb-0\">\n\t\t\t\t<button type=\"button\" class=\"btn btn-secondary close-modal-btn\" data-bs-dismiss=\"modal\">Cancel</button>\n\t\t\t\t<button type=\"submit\" class=\"btn btn-primary submit-btn\">Next</button>\n\t\t\t</div>\n\t\t"); 554 page1.append(page1Form); 555 modalBody.append(page1); // Setup: Page 2 556 557 var page2 = jQuery('<div class="form-page" id="page-2" style="display: none;"></div>'); 558 var page2Form = jQuery('<form></form>'); // Page 2 form: Anonymous 559 560 page2Form.append("\n\t\t\t<div class=\"row mb-3\">\n\t\t\t\t<div class=\"col\">\n\t\t\t\t\t<label class=\"form-label\" for=\"anonymous\">
560Anonymous (Your name will be hidden to the public)</label><br>\n\t\t\t\t\t<div class=\"btn-group\" role=\"group\">\n\t\t\t\t\t <input type=\"radio\" class=\"btn-check\" name=\"anonymous\" id=\"anonymous1\" value=\"No\" autocomplete=\"off\" checked>\n\t\t\t\t\t <label class=\"btn btn-outline-dark\" for=\"anonymous1\">No</label>\n\n\t\t\t\t\t <input type=\"radio\" class=\"btn-check\" name=\"anonymous\" id=\"anonymous2\" value=\"Yes\" autocomplete=\"off\">\n\t\t\t\t\t <label class=\"btn btn-outline-dark\" for=\"anonymous2\">Yes</label>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"); // Page 2 form: Private 561 562 page2Form.append("\n\t\t\t<div class=\"row mb-3\">\n\t\t\t\t<div class=\"col\">\n\t\t\t\t\t<label class=\"form-label\" for=\"private\">Private (Your tree will be hidden to the public)</label><br>\n\t\t\t\t\t<div class=\"btn-group\" role=\"group\">\n\t\t\t\t\t\t<input type=\"radio\" class=\"btn-check\" name=\"private\" id=\"private1\" value=\"No\" autocomplete=\"off\" checked>\n\t\t\t\t\t\t<label class=\"btn btn-outline-dark\" for=\"private1\">No</label>\n\n\t\t\t\t\t\t<input type=\"radio\" class=\"btn-check\" name=\"private\" id=\"private2\" value=\"Yes\" autocomplete=\"off\">\n\t\t\t\t\t\t<label class=\"btn btn-outline-dark\" for=\"private2\">Yes</label>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"); // Page 2 form: Display Name 563 564 page2Form.append("\n\t\t\t<div class=\"row mb-3\">\n\t\t\t\t<div class=\"col\">\n\t\t\t\t\t<label class=\"form-label\" for=\"displayName\">Display name (Leave blank if you want to use your full name)</label>\n\t\t\t\t\t<input type=\"text\" class=\"form-control\" id=\"displayName\" name=\"displayName\">\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t"); 565 var messageLabel = "Write a message of dedication<br/>(This will be emailed to the family and visible on their tribute page)"; 566 567 if (this.clientName && this.clientName.length) { 568 messageLabel = "Write a message of dedication<br/>(This will be emailed to the family of ".concat(this.clientName, " and visible on their tribute page)"); 569 } // Page 2 form: Display Name 570 571 572 page2Form.append("\n\t\t\t<div class=\"row mb-3\">\n\t\t\t\t<div class=\"col\">\n\t\t\t\t\t<label class=\"form-label\" for=\"message\">".concat(messageLabel, "</label>\n\t\t\t\t\t<div class=\"grow-wrap\">\n\t\t\t\t <textarea class=\"form-control\" name=\"message\" id=\"message\" onInput=\"this.parentNode.dataset.replicatedValue = this.value\" maxlength=\"300\"></textarea>\n\t\t\t\t </div>\n\t\t\t\t\t<div class=\"character-count\">0/300</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t")); 573 page2Form.append("<div class=\"bd-callout bd-callout-danger error-callout\" style=\"display: none;\"></div>"); 574 page2Form.append("<button type=\"button\" class=\"d-none checkout-button\">Checkout</button>"); 575 page2Form.append("\n\t\t\t<div class=\"modal-footer justify-content-between border-0 pt-3 px-0 pb-0\">\n\t\t\t\t<button type=\"button\" class=\"btn btn-secondary back-btn\">Back</button>\n\t\t\t\t<button type=\"submit\" class=\"btn btn-primary submit-btn\">Checkout</button>\n\t\t\t</div>\n\t\t"); 576 page2.append(page2Form); 577 modalBody.append(page2); 578 modalContent.append(modalBody); 579 modal.append(modalContent); 580 modalContainer.append(modal); 581 return modalContainer; 582 } 583 }, { 584 key: "showTreePurchaseModal", 585 value: function showTreePurchaseModal() { 586 var _this6 = this; 587 588 this.closeActionModal(true); 589 var modalElement = jQuery(this.buildCreateTreeModal()); 590 jQuery(this.listElement).parents(".firehawk-crm-tributes").append(modalElement); 591 this.getTreeStock(); 592 this.actionModalElement = modalElement; 593 this.actionModal = new bootstrap.Modal(modalElement.get(0), { 594 backdrop: "static" 595 }); 596 this.actionModal.show(); 597 this.actionModalElement.delegate(".action-modal .close-modal-btn", "click", function (event) { 598 _this6.closeActionModal(); 599 600 _this6.resetTreePurchaseModal(); 601 }); 602 this.actionModalElement.on('hidden.bs.modal', function (event) { 603 _this6.resetTreePurchaseModal(); 604 }); 605 this.actionModalElement.delegate("#page-2 .back-btn", "click", function (event) { 606 _this6.actionModalElement.find("#page-2").hide(); 607 608 _this6.actionModalElement.find("#page-1").show(); 609 }); 610 var country = this.country; 611 this.actionModalElement.find('.forest-picker').select2({ 612 theme: "bootstrap4", 613 allowClear: false, 614 placeholder: "Select forest", 615 dropdownCssClass: "forst-picker-select2", 616 ajax: { 617 url: "https://api.firehawkcrm.com/v2/wp/tributes/forests", 618 dataType: 'json', 619 data: function data(params) { 620 return { 621 country: country && country.length ? country : null, 622 q: params.term, 623 page: params.page 624 }; 625 }, 626 processResults: function processResults(data) { 627 var results = data.results.map(function (option) { 628 return { 629 "id": option.id || null, 630 "text": option.name, 631 "source": option 632 }; 633 }); 634 return { 635 results: results 636 }; 637 } 638 } 639 }); 640 this.actionModalElement.delegate("#page-1 form :radio[name='numberOfTrees']", "change", function (event) { 641 var field = jQuery(event.target); 642 var quantity = +(field.val() || 0); 643 console.log(field.val()); 644 645 if (_this6.treeStock && _this6.treeStock.pricing && _this6.treeStock.pricing[0] && _this6.treeStock.pricing[0].priceValues) { 646 var price = _this6.treeStock.pricing[0].priceValues.priceInclTax; 647 var totalPrice = quantity * price; 648 649 _this6.actionModalElement.find("#page-1 .tree-price-info").show(); 650 651 _this6.actionModalElement.find("#page-1 .tree-price-info .tree-price").html("$".concat(price)); 652 653 _this6.actionModalElement.find("#page-1 .tree-price-info .tree-quantity").html("".concat(quantity)); 654 655 _this6.actionModalElement.find("#page-1 .tree-price-info .tree-total").html("$".concat(totalPrice)); 656 657 if (quantity > 0) { 658 _this6.actionModalElement.find("#page-1 .tree-price-info .tree-price-totals").show(); 659 } else { 660 _this6.actionModalElement.find("#page-1 .tree-price-info .tree-price-totals").hide(); 661 } 662 } else { 663 _this6.actionModalElement.find("#page-1 .tree-price-info").hide(); 664 } 665 }); 666 this.actionModalElement.delegate("#page-1 form", "submit", function (event) { 667 event.preventDefault(); 668 var form = jQuery(event.target); 669 form.find(".error-callout").hide().html(""); 670 var formData = new FormData(event.target); 671 672 var mappedData = _this6.formDataToJSON(formData); 673 674 if (!mappedData.numberOfTrees) { 675 form.find(".error-callout").show().html("Please select the number of trees you would like to plant."); 676 return; 677 } 678 679 _this6.formSubmitData = _objectSpread({}, _this6.formSubmitData, {}, mappedData); 680 form.parent().hide(); 681 form.parent().siblings("#page-2").show(); 682 }); 683 this.actionModalElement.delegate("#page-2 form", "submit", function (event) { 684 event.preventDefault(); 685 var form = jQuery(event.target); 686 form.find(".error-callout").hide().html("");
687 var submitButton = form.find(".modal-footer .submit-btn"); 688 submitButton.prop("disabled", true); 689 submitButton.html("<span class=\"spinner-border spinner-border-sm\" role=\"status\" aria-hidden=\"true\">"); 690 var formData = new FormData(event.target); 691 formData.append("client", _this6.client); 692 693 var mappedData = _this6.formDataToJSON(formData); 694 695 _this6.formSubmitData = _objectSpread({}, _this6.formSubmitData, {}, mappedData); 696 697 _this6.createTributeTree(); 698 }); 699 this.actionModalElement.delegate("#page-2 form #message", "keyup", function (event) { 700 var textarea = jQuery(event.target); 701 var characterCount = textarea.val().length; 702 textarea.parent().siblings(".character-count").text("".concat(characterCount, " / 300")); 703 }); 704 } 705 }, { 706 key: "createTributeTree", 707 value: function createTributeTree() { 708 var _this7 = this; 709 710 var formData = new FormData(); 711 712 for (var key in this.formSubmitData) { 713 var value = this.formSubmitData[key]; 714 715 if (value != null) { 716 formData.append(key, value); 717 } 718 } 719 720 formData.append("action", "create_tribute_tree"); 721 var quantity = +(this.formSubmitData["numberOfTrees"] || 1); 722 723 var tributeAction = function tributeAction(cartId, errorMessage) { 724 _this7.cartId = cartId; 725 726 if (errorMessage) { 727 _this7.actionModalElement.find("#page-2 .error-callout").show().html(errorMessage); 728 729 var submitButton = _this7.actionModalElement.find("#page-2 form .modal
729-footer .submit-btn"); 730 731 submitButton.prop("disabled", false); 732 submitButton.html("Submit"); 733 return; 734 } 735 736 formData.append("checkoutCart", cartId); 737 jQuery.ajax({ 738 type: "POST", 739 url: ajax_var.url, 740 data: formData, 741 contentType: false, 742 cache: false, 743 processData: false 744 }).done(function (response) { 745 if (!response) { 746 _this7.actionModalElement.find("#page-2 .error-callout").show().html("Error: Unknown error"); 747 } else { 748 var data = JSON.parse(response); 749 750 if (data && data.error) { 751 var _errorMessage = data.error || "Unknown error"; 752 753 _this7.actionModalElement.find("#page-2 .error-callout").show().html("Error: " + _errorMessage); 754 755 var _submitButton = _this7.actionModalElement.find("#page-2 .modal-footer .submit-btn"); 756 757 _submitButton.prop("disabled", false); 758 759 _submitButton.html("Submit"); 760 } else { 761 //Handle successful transaction 762 window.location = "".concat(_this7.checkoutCartUrl || '/checkout', "?cart=").concat(_this7.cartId); 763 } 764 } 765 }).fail(function (xhr, status, error) { 766 if (error.responseJSON) { 767 var _errorMessage2 = error.responseJSON.error || error.responseJSON.message || ""; 768 769 _this7.actionModalElement.find("#page-2 .error-callout").show().html("Error: " + _errorMessage2); 770 } else { 771 _this7.actionModalElement.find("#page-2 .error-callout").show().html("Something went wrong, please try again."); 772 } 773 774 var submitButton = _this7.actionModalElement.find("#page-2 .modal-footer .submit-btn"); 775 776 submitButton.prop("disabled", false); 777 submitButton.html("Submit"); 778 }); 779 }; 780 781 if (this.cartId) { 782 tributeAction(this.cartId, null); 783 } else { 784 this.addTreeToCart(quantity, tributeAction); 785 } 786 } 787 }, { 788 key: "addTreeToCart", 789 value: function addTreeToCart(quantity, callback) { 790 var contact = { 791 firstName: this.formSubmitData.firstName, 792 lastName: this.formSubmitData.lastName, 793 email: this.formSubmitData.email, 794 postcode: this.formSubmitData.postcode 795 }; 796 jQuery.ajax({ 797 type: "POST", 798 url: ajax_var.url, 799 data: { 800 action: "add_tree_to_cart", 801 quantity: quantity, 802 contact: contact 803 } 804 }).done(function (response) { 805 if (!response) { 806 callback(null, "Something went wrong, please try again."); 807 } else { 808 if (response && response.error) { 809 callback(null, "Error: " + (response.error || "Unknown error")); 810 } else if (response && response.result && response.result.cart) { 811 callback(response.result.cart, null); 812 } else { 813 callback(null, "Error: Unable to process transaction"); 814 } 815 } 816 }).fail(function (xhr, status, error) { 817 if (error.responseJSON) { 818 var errorMessage = error.responseJSON.error || error.responseJSON.message || ""; 819 callback(null, "Error: " + errorMessage); 820 } else { 821 callback(null, "Something went wrong, please try again."); 822 } 823 }); 824 } 825 }, { 826 key: "showVerificationModal", 827 value: function showVerificationModal() { 828 if (!this.actionModalElement) return; 829 this.actionModalElement.find("#page-2").hide(); 830 this.actionModalElement.find("#page-1").show(); 831 } 832 }, { 833 key: "requestVerificationCode", 834 value: function requestVerificationCode(email) { 835 var _this8 = this; 836 837 jQuery.ajax({ 838 method: 'post', 839 url: ajax_var.url, 840 data: { 841 action: 'verify_tribute_email', 842 params: { 843 client: this.client, 844 email: email 845 } 846 } 847 }).done(function (response) { 848 if (response) { 849 var data = JSON.parse(response); 850 851 if (data && data.code) { 852 _this8.verifyCode = data.code;
853 854 _this8.showVerificationModal(); 855 } else {} 856 857 console.log(data); 858 } 859 }).fail(function (xhr, status, error) {}).always(function () { 860 var submitButton = _this8.actionModalElement.find("#tribute-form .modal-footer .submit-btn"); 861 862 submitButton.prop("disabled", false); 863 submitButton.html("Submit"); 864 }); 865 } 866 }, { 867 key: "formDataToJSON", 868 value: function formDataToJSON(formData) { 869 var convertedJSON = {}; 870 formData.forEach(function (value, key) { 871 if (typeof value == "string" && value.length == 0) { 872 convertedJSON[key] = null; 873 } else { 874 convertedJSON[key] = value; 875 } 876 }); 877 return convertedJSON; 878 } // Likes 879 880 }, { 881 key: "likeTributeTree", 882 value: function likeTributeTree(id) { 883 var _this9 = this; 884 885 if (this.itemsWaiting[id]) return; 886 this.itemsWaiting[id] = true; 887 jQuery.ajax({ 888 method: 'post', 889 url: ajax_var.url, 890 data: { 891 action: 'like_tribute_tree', 892 params: { 893 id: id 894 } 895 } 896 }).done(function (response) { 897 var newLikesCount = null; 898 899 if (response) { 900 var data = JSON.parse(response); 901 902 if (data && data.success && data.likes != null) { 903 newLikesCount = data.likes; 904 jQuery("#tribute-tree-".concat(id, " .likes .counter")).html("".concat(newLikesCount)); 905 } 906 } 907 908 _this9.itemsWaiting[id] = null; 909 }).fail(function (xhr, status, error) { 910 _this9.itemsWaiting[id] = null; 911 }); 912 } 913 }, { 914 key: "unlikeTributeTree", 915 value: function unlikeTributeTree(id) { 916 var _this10 = this; 917 918 if (this.itemsWaiting[id]) return; 919 this.itemsWaiting[id] = true; 920 jQuery.ajax({ 921 method: 'post', 922 url: ajax_var.url, 923 data: { 924 action: 'unlike_tribute_tree', 925 params: { 926 id: id 927 } 928 } 929 }).done(function (response) { 930 var newLikesCount = null; 931 932 if (response) { 933 var data = JSON.parse(response); 934 935 if (data && data.success && data.likes != null) { 936 newLikesCount = data.likes; 937 jQuery("#tribute-tree-".concat(id, " .likes .counter")).html("".concat(newLikesCount)); 938 } 939 } 940 941 _this10.itemsWaiting[id] = null; 942 }).fail(function (xhr, status, error) { 943 _this10.itemsWaiting[id] = null; 944 }); 945 } 946 }, { 947 key: "setCookie", 948 value: function setCookie(cname, cvalue, hours) { 949 var d = new Date(); 950 d.setTime(d.getTime() + hours * 60 * 60 * 1000); 951 var expires = "expires=" + d.toUTCString(); 952 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; 953 } 954 }, { 955 key: "getCookie", 956 value: function getCookie(cname) { 957 var name = cname + "="; 958 var decodedCookie = decodeURIComponent(document.cookie); 959 var ca = decodedCookie.split(';'); 960 961 for (var i = 0; i < ca.length; i++) { 962 var c = ca[i]; 963 964 while (c.charAt(0) == ' ') { 965 c = c.substring(1); 966 } 967 968 if (c.indexOf(name) == 0) { 969 return c.substring(name.length, c.length); 970 } 971 } 972 973 return ""; 974 } 975 }]); 976 977 return FirehawkCRMServiceTributeTrees; 978}();
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.