From 20ba4844df3cd75cd675cf2356abd58cd3283c0b Mon Sep 17 00:00:00 2001 From: Ivan Chaplygin Date: Mon, 2 Dec 2024 17:55:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=B8=20=D1=81=D0=BE?= =?UTF-8?q?=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B8=20=D1=8D=D0=BA=D1=81=D0=BF?= =?UTF-8?q?=D0=BE=D1=80=D1=82=D0=B0=20=D0=9F=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20js=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=BF=D1=80=D0=B8=20=D1=83=D1=81=D1=82=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B5=20=D0=B8=20=D0=B8=20=D0=BE=D0=B1=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D1=83=D0=BB=D1=8F=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B7=D0=B0=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D1=8C=20=D0=BC=D0=B0=D1=81=D1=81=D0=B8=D0=B2=D0=B0?= =?UTF-8?q?=20=D0=BA=D0=B0=D1=82=D0=B0=D0=BB=D0=BE=D0=B3=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B2=20=D0=BF=D1=80=D0=BE=D1=84=D0=B8=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- intaro.retailcrm/export/export_setup.php | 311 +----------------- .../bitrix/js/intaro/custom-props-export.js | 310 ++++++++++++++++- .../lang/ru/icml_export_setup.php | 1 + .../lib/component/advanced/installertrait.php | 10 + .../lib/controller/customexportprops.php | 13 +- intaro.retailcrm/lib/icml/settingsservice.php | 59 +++- intaro.retailcrm/updater.php | 39 +-- 7 files changed, 388 insertions(+), 355 deletions(-) diff --git a/intaro.retailcrm/export/export_setup.php b/intaro.retailcrm/export/export_setup.php index 05a06418..b4161b35 100644 --- a/intaro.retailcrm/export/export_setup.php +++ b/intaro.retailcrm/export/export_setup.php @@ -562,7 +562,7 @@ if ($STEP === 1) { ?> - +

@@ -764,7 +764,6 @@ if ($STEP === 1) { function propertyChange(obj) { let selectedOption = $(obj).find('option')[obj.selectedIndex]; - console.log(selectedOption); if (selectedOption.className === 'not-highloadblock') { let objId = '#' + obj.id; @@ -873,314 +872,6 @@ if ($STEP === 1) { return select; } - - const setupFieldsListElement = $('input[name="SETUP_FIELDS_LIST"]'); - let customProps = {}; - let customPropsToDelete = {}; - const setupFieldsParamsToFill = [ - 'iblockPropertySku_', - 'iblockPropertyUnitSku_', - 'iblockPropertyProduct_', - 'iblockPropertyUnitProduct_', - 'highloadblockb_hlsys_marking_code_group_', - 'highloadblock_productb_hlsys_marking_code_group_', - 'highloadblockeshop_color_reference_', - 'highloadblock_producteshop_color_reference_', - 'highloadblockeshop_brand_reference_', - 'highloadblock_producteshop_brand_reference_' - ]; - - $('.add-custom-row').click(function () { - createCustomPropsRaw($(this)); - }); - - $(document).on('click', '#delete-new-custom-row', function () { - deleteCustomPropRow($(this)); - }); - - $(document).on('click', '#delete-custom-row', function () { - let buttonElem = $(this); - addCustomPropToDelete(buttonElem); - deleteCustomPropRow(buttonElem); - }); - - $(document).on('blur', 'input[name="custom-property-title"]', function () { - let inputElem = $(this); - let newPropertyTitle = inputElem.val(); - - if (!newPropertyTitle) { - return; - } - - let newPropertyCode = getUniquePropertyCode(newPropertyTitle); - addCustomPropCodeToSelectAttributes(newPropertyCode, inputElem); - }); - - $('#submit-form').submit(function (formEvent) { - formEvent.preventDefault(); - let savePromise = null; - let deletePromise = null; - let formElem = formEvent.currentTarget; - let profileId = $($('input[name="PROFILE_ID"]')).val(); - - setCustomProperties(); - - if (Object.keys(customProps).length > 0) { - savePromise = BX.ajax.runAction('intaro:retailcrm.api.customexportprops.save', { - json: { - properties: customProps, - profileId: profileId - }, - }).then(addParamsToSetupFieldsList()); - } - - if (Object.keys(customPropsToDelete).length > 0) { - deletePromise = BX.ajax.runAction('intaro:retailcrm.api.customexportprops.delete', { - json: { - properties: customPropsToDelete, - profileId: profileId - }, - }).then(deleteParamsFromSetupFieldsList()); - } - - const promises = [savePromise, deletePromise].filter(Boolean); - - if (promises.length > 0) { - Promise.all(promises) - .finally(() => { - formElem.submit(); - }); - } else { - formElem.submit(); - } - }); - - function deleteCustomPropRow(deleteButton) - { - deleteButton.closest('tr').remove(); - } - - function addCustomPropToDelete(deleteButton) - { - let deletedPropTitle = deleteButton.closest('td').siblings().filter('.custom-property-title').text().trim(); - let deletedPropCode = deleteButton.siblings().filter('select').first().data('type'); - let customPropCatalogId = deleteButton.closest('.iblockExportTable').data('type'); - - let values = { - 'code': deletedPropCode, - 'title': deletedPropTitle, - }; - - if (customPropsToDelete.hasOwnProperty(customPropCatalogId)) { - customPropsToDelete[customPropCatalogId].push(values); - } else { - customPropsToDelete[customPropCatalogId] = [values]; - } - } - - function addCustomPropCodeToSelectAttributes(customPropCode, customPropTitleElem) - { - let selectElements = customPropTitleElem.closest('.custom-property-row').find('td select'); - let catalogId = customPropTitleElem.closest('.iblockExportTable').data('type'); - - selectElements.each(function (index, element) { - let selectElem = $(element); - let newSelectIdValue = selectElem.attr('id').match(/^[^_]*_/)[0] + customPropCode + catalogId; - let newSelectNameValue = selectElem.attr('name').match(/^[^_]*_/)[0] + customPropCode + `[${catalogId}]`; - - selectElem.attr('id', newSelectIdValue); - selectElem.attr('name', newSelectNameValue); - selectElem.data('type', customPropCode); - triggerSelectChange(selectElem); - }); - } - - function triggerSelectChange(selectElem) - { - if (selectElem.val().length > 0) { - selectElem.trigger('change', [self]); - } - } - - function setCustomProperties() - { - let customPropertiesRows = $('.custom-property-row'); - - if (customPropertiesRows.length === 0) { - return; - } - - let customPropertyCatalogId; - let customPropertyTitle = ''; - let customPropertyCode = ''; - let productPropertyMatch = ''; - let offerPropertyMatch = ''; - - let catalogIds = []; - customPropertiesRows.each(function (index, propertyRow) { - let propertyRowObj = $(propertyRow); - customPropertyCatalogId = propertyRowObj.closest('.iblockExportTable').data('type'); - - customPropertyTitle = propertyRowObj.find('input[name="custom-property-title"]').val(); - - if (!customPropertyTitle) { - return true; - } - - customPropertyCode = getUniquePropertyCode(customPropertyTitle); - productPropertyMatch = propertyRowObj.find('select[name=custom-product-property-select]').val(); - offerPropertyMatch = propertyRowObj.find('select[name=custom-offer-property-select]').val(); - - let values = { - 'title': customPropertyTitle, - 'code': customPropertyCode, - 'productProperty': productPropertyMatch, - 'offerProperty': offerPropertyMatch - }; - - if (catalogIds.indexOf(customPropertyCatalogId) === -1) { - customProps[customPropertyCatalogId] = [values]; - } else { - customProps[customPropertyCatalogId].push(values); - } - catalogIds.push(customPropertyCatalogId); - }); - } - - function getUniquePropertyCode(customPropertyTitle) - { - let uniqueValue = transliterate(customPropertyTitle).replace(/ /g, '_'); - let counter = 0; - - const setupFieldsListValues = setupFieldsListElement.val().split(','); - while (setupFieldsListValues.includes(uniqueValue)) { - uniqueValue = `${customPropertyTitle}${++counter}`; - } - - return uniqueValue; - } - - function addParamsToSetupFieldsList() - { - let newParams = ''; - - if (Object.keys(customProps).length === 0) { - return; - } - - for (let propertiesByCatalogId of Object.values(customProps)) { - propertiesByCatalogId.forEach(function (values) { - setupFieldsParamsToFill.forEach(function (param) { - newParams += ',' + param + values.code; - }); - }); - } - - let newValue = setupFieldsListElement.val() + newParams; - setupFieldsListElement.val(newValue); - - return true; - } - - function deleteParamsFromSetupFieldsList() - { - let setupFields = setupFieldsListElement.val(); - - if (Object.keys(customPropsToDelete).length === 0) { - return; - } - - for (let propsByCatalogId of Object.values(customPropsToDelete)) { - propsByCatalogId.forEach(function (propValues) { - setupFieldsParamsToFill.forEach(function (param) { - let paramToDelete = ',' + param + propValues.code; - setupFields = setupFields.replace(paramToDelete, ''); - }); - }); - } - - setupFieldsListElement.val(setupFields); - - return true; - } - - function createCustomPropsRaw(addRowButton) - { - let templateRow = $($('#custom-property-template-row').html()); - let templateSelectElements = templateRow.find('select'); - - let prevTableRow = $(addRowButton).prev('table').find('tbody tr:last-child'); - let lastRawSelectElements = prevTableRow.find('td select'); - - lastRawSelectElements.each(function (index, element) { - let selectElement = $(element); - let templateSelectElement = templateSelectElements[index]; - fillTemplateSelect(selectElement, templateSelectElement); - prevTableRow.after(templateRow); - }); - } - - function fillTemplateSelect(sourceSelectElement, templateSelectElement) - { - let selectOptions = sourceSelectElement.find('option'); - selectOptions.each(function (index, element) { - let optionElem = $(element); - let value = $(optionElem).val(); - let text = $(optionElem).text(); - - $('