var Bizgaze; (function (Bizgaze) { let Apps; (function (Apps) { let Transact; (function (Transact) { let Controls; (function (Controls) { class CartDetails extends Unibase.Platform.Core.BaseComponent { constructor() { super(...arguments); this.g_Categories = []; } init(formpropertyid, prop, callback) { var instance = this; instance.loadControlSettings(prop.ControlJsonText, prop.FormPropertyId); instance.loadPropertySettings(prop.PropertySettings, prop.FormPropertyId); } loadControl(containerid, prop) { var html = `
Add
Total Quantity : ()

` + `
` + `` + `
`; $("#" + containerid).html(html); } loadControlSettings(controlsettingjson, formpropertyid) { const instance = this; $("#totalOrderItems_link").click(function () { $("#ulOrder_Cart").toggleClass("hidden"); }); $("#cartItemsSearch").on("keyup", function () { let value = $(this).val().toString().toLowerCase(); $("#ulOrder_Cart li:not(:first-child)").filter(function () { $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1); }); }); $('#cartCategoriesSelect').select2({ placeholder: 'Select Category', data: instance.g_Categories, allowClear: true, }).on('select2:select', function () { const catId = +$(this).val(); $(this).val("").trigger("change"); $('#ulOrder_Cart .cart-item-chk').each(function (i, e) { if ($(e).is(':checked')) { const catSortableEl = $(`#catItemsSortable_${catId}`); $(e).parents('.cartitem').detach().appendTo(catSortableEl); catSortableEl.find('.cart-item-remove').removeClass('d-none').click(function () { const cartItemEl = $(this).parents('.cartitem'); cartItemEl.find('.cart-item-remove').addClass('d-none'); cartItemEl.find('.cart-item-chk').removeClass('d-none'); cartItemEl.detach().appendTo($("#ulOrder_Cart")); }); catSortableEl.find('.cart-item-chk').addClass('d-none').prop('checked', false); } }); }); $('#cartCategoryAddBtn').click(function () { $(this).addClass('d-none'); $('#categoryInputCard').removeClass('d-none'); }); $('#addCategoryBtn').click(function () { const inputVal = $('#addCategoryInput').val(); const key = +$(this).attr('data-uniqueid'); if (inputVal.trim().length) { $('#addCategoryInput').val(''); $('#addedCategoriesList').append(`
${inputVal}
`).removeClass('d-none'); $(this).attr('data-uniqueid', key + 1); const newCatObj = { id: key, text: inputVal }; instance.g_Categories.push(newCatObj); const newOption = new Option(newCatObj.text, newCatObj.id.toString(), false, false); $('#categoriesSelectWrap,#ulOrder_Cart .cart-item-chk').removeClass('d-none'); $('#cartCategoriesSelect').append(newOption); $('#cartCategoriesSelect').val(null).trigger('change'); const orderCartEl = $('#ulOrder_Cart'); orderCartEl.sortable(); orderCartEl.sortable('destroy'); orderCartEl.sortable({ connectWith: '.cartItemsSortable', receive: function () { orderCartEl.find('.drag-placeholder').remove(); }, remove: function () { if (!orderCartEl.find('.cartitem:visible').length) { orderCartEl.append('
  • Drag Items Here
  • '); } else { orderCartEl.find('.drag-placeholder').remove(); } } }).disableSelection(); $(`#catItemsSortable_${key}`).sortable({ connectWith: ".cartItemsSortable", items: '.cartitem', cancel: ".drag-placeholder", receive: function (event, ui) { $(ui.item).find('.cart-item-chk').addClass('d-none'); $(ui.item).find('.cart-item-remove').removeClass('d-none').click(function () { $(this).addClass('d-none'); $(ui.item).find('.cart-item-chk').removeClass('d-none'); $(this).parents('.cartitem').detach().appendTo(orderCartEl); }); }, remove: function (event, ui) { $(ui.item).find('.cart-item-remove').addClass('d-none'); $(ui.item).find('.cart-item-chk').removeClass('d-none'); } }).disableSelection(); $(`#catTitleEditBtn_${key}`).click(function () { $(`#catTitleEditBtn_${key},#catTitleSpan_${key}`).addClass('d-none'); $(`#catTitleInput_${key},#catTitleSaveBtn_${key}`).removeClass('d-none'); $(`#catTitleInput_${key}`).trigger('focus'); }); $(`#catTitleSaveBtn_${key}`).click(function () { const inputVal = $(`#catTitleInput_${key}`).val().toString(); $(`#catTitleInput_${key},#catTitleSaveBtn_${key}`).addClass('d-none'); $(`#catTitleEditBtn_${key},#catTitleSpan_${key}`).removeClass('d-none'); $(`#catTitleSpan_${key}`).text(inputVal); $(`#cartCategoriesSelect option[value="${key}"]`).remove(); const newCatObj = { id: key, text: inputVal }; const newOption = new Option(newCatObj.text, newCatObj.id.toString(), false, false); $('#cartCategoriesSelect').append(newOption); $('#cartCategoriesSelect').val(null).trigger('change'); }); } }); } loadPropertySettings(propertysettings, formpropertyid) { return null; } bindEditFormDetails(formpropertyid, propval, DocPropertyName) { return null; } getCategoryIndex(CategoryName) { let instance = this; let CatgryIndex = instance.g_Categories.findIndex(x => x.CategoryName == CategoryName); return CatgryIndex; } getNewRowId() { let text = ""; let possible = "0123456789"; for (let i = 0; i < 5; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return Number(text); } isCategoryExists(CategoryName) { let instance = this; let CatgryIndex = instance.getCategoryIndex(CategoryName); if (CatgryIndex == -1) { return false; } else { return true; } } pushCategoryIfNotExists(CategoryName) { let instance = this; let isCatgryExists = instance.isCategoryExists(CategoryName); if (!isCatgryExists) { let CatgryRowId = instance.getNewRowId(); let CatgryIndex = instance.getCategoryIndex(CategoryName); if (CatgryIndex != -1) { CatgryRowId = instance.getNewRowId(); } instance.g_Categories.push({ CategoryName: CategoryName, CatgryRowId: CatgryRowId }); } } getCategoryDesign(CatgryRowId, CategoryName) { let html = `
    ` + CategoryName + `
    `; return html; } bindCategoryEvents(CatgryRowId, CategoryName) { let key = CatgryRowId; $('#addCategoryInput').val(''); $('#addedCategoriesList').removeClass('d-none'); let optionLength = $("#cartCategoriesSelect option[value='" + CatgryRowId + "']").length; if (optionLength == 0) { const newOption = new Option(CategoryName, CatgryRowId.toString(), false, false); $('#cartCategoriesSelect').append(newOption); $('#cartCategoriesSelect').val(null).trigger('change'); } $('#categoriesSelectWrap,#ulOrder_Cart .cart-item-chk').removeClass('d-none'); const orderCartEl = $('#ulOrder_Cart'); orderCartEl.sortable(); orderCartEl.sortable('destroy'); orderCartEl.sortable({ connectWith: '.cartItemsSortable', receive: function () { orderCartEl.find('.drag-placeholder').remove(); }, remove: function () { if (!orderCartEl.find('.cartitem:visible').length) { orderCartEl.append('
  • Drag Items Here
  • '); } else { orderCartEl.find('.drag-placeholder').remove(); } } }).disableSelection(); $(`#catItemsSortable_` + key).sortable({ connectWith: ".cartItemsSortable", items: '.cartitem', cancel: ".drag-placeholder", receive: function (event, ui) { $(ui.item).find('.cart-item-chk').addClass('d-none'); $(ui.item).find('.cart-item-remove').removeClass('d-none').click(function () { $(this).addClass('d-none'); $(ui.item).find('.cart-item-chk').removeClass('d-none'); $(this).parents('.cartitem').detach().appendTo(orderCartEl); }); }, remove: function (event, ui) { $(ui.item).find('.cart-item-remove').addClass('d-none'); $(ui.item).find('.cart-item-chk').removeClass('d-none'); } }).disableSelection(); $(`#catTitleEditBtn_` + key).click(function () { $(`#catTitleEditBtn_` + key + `,#catTitleSpan_` + key).addClass('d-none'); $(`#catTitleInput_` + key + `,#catTitleSaveBtn_` + key).removeClass('d-none'); $(`#catTitleInput_` + key).trigger('focus'); }); $(`#catTitleSaveBtn_` + key).click(function () { const inputVal = $(`#catTitleInput_` + key).val().toString(); $(`#catTitleInput_` + key + `,#catTitleSaveBtn_` + key).addClass('d-none'); $(`#catTitleEditBtn_` + key + `,#catTitleSpan_` + key).removeClass('d-none'); $(`#catTitleSpan_` + key).text(inputVal); $(`#cartCategoriesSelect option[value="` + key + `"]`).remove(); const newCatObj = { id: key, text: inputVal }; const newOption = new Option(newCatObj.text, newCatObj.id.toString(), false, false); $('#cartCategoriesSelect').append(newOption); $('#cartCategoriesSelect').val(null).trigger('change'); }); } bindElementToCategory(html, CategoryName) { let instance = this; let CatgryRowId = 0; $('#cartCategoryAddBtn').addClass('d-none'); $('#categoryInputCard').removeClass('d-none'); let isCatgryExists = instance.isCategoryExists(CategoryName); let CatgryIndex = instance.getCategoryIndex(CategoryName); if (!isCatgryExists) { instance.pushCategoryIfNotExists(CategoryName); CatgryIndex = instance.getCategoryIndex(CategoryName); CatgryRowId = instance.g_Categories[CatgryIndex].CatgryRowId; let CatgryDesign = instance.getCategoryDesign(CatgryRowId, CategoryName); $("#addedCategoriesList").append(CatgryDesign).removeClass("d-none"); } if (CatgryIndex != -1) { CatgryRowId = instance.g_Categories[CatgryIndex].CatgryRowId; $("#catItemsSortable_" + CatgryRowId).append(html); instance.bindCategoryEvents(CatgryRowId, CategoryName); instance.hideUnUsedCategories(); } } hideUnUsedCategories() { let instance = this; $(".cartItemsSortable").each(function () { let li_length = $(this).find(".cartitem").length; if (li_length == 0) { let CatgryRowId = $(this).find("#hf_categoryrowid").val(); $("#catergoryCard_" + CatgryRowId).remove(); let CatgryIndex = instance.g_Categories.findIndex(x => x.CatgryRowId == CatgryRowId); if (CatgryIndex != -1) { instance.g_Categories.splice(CatgryIndex, 1); $("#cartCategoriesSelect option[value='" + CatgryRowId + "']").remove(); } } }); } static Instance() { if (this.instance === undefined) { this.instance = new CartDetails(); } return this.instance; } } Controls.CartDetails = CartDetails; })(Controls = Transact.Controls || (Transact.Controls = {})); })(Transact = Apps.Transact || (Apps.Transact = {})); })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {})); })(Bizgaze || (Bizgaze = {}));