diff --git a/intaro.retailcrm/install/export/bitrix/js/intaro/export/custom-props-export.js b/intaro.retailcrm/install/export/bitrix/js/intaro/export/custom-props-export.js index e312f11e..e3761113 100644 --- a/intaro.retailcrm/install/export/bitrix/js/intaro/export/custom-props-export.js +++ b/intaro.retailcrm/install/export/bitrix/js/intaro/export/custom-props-export.js @@ -64,7 +64,6 @@ function setCustomProperties() 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) { @@ -87,6 +86,7 @@ function setCustomProperties() } else { customProps[customPropertyCatalogId].push(values); } + catalogIds.push(customPropertyCatalogId); }); } @@ -95,8 +95,8 @@ function getUniquePropertyCode(customPropertyTitle) { let uniqueValue = transliterate(customPropertyTitle).replace(/ /g, '_'); let counter = 0; - const setupFieldsListValues = setupFieldsListElement.val().split(','); + while (setupFieldsListValues.includes(uniqueValue)) { uniqueValue = `${customPropertyTitle}${++counter}`; } @@ -167,6 +167,7 @@ function createCustomPropsRaw(addRowButton) function fillTemplateSelect(sourceSelectElement, templateSelectElement) { let selectOptions = sourceSelectElement.find('option'); + selectOptions.each(function (index, element) { let optionElem = $(element); let value = $(optionElem).val(); @@ -225,212 +226,3 @@ function transliterate(titleToTransliterate) } return translitedText; } -/* -$(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) { - let formElem = formEvent.currentTarget; - formEvent.preventDefault(); - setCustomProperties(); - addParamsToSetupFieldsList(); - - BX.ajax.runAction('intaro:retailcrm.api.customexportprops.save', { - json: {properties: customProps}, - }).then(function() { - formElem.submit(); - }); -}); - -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) { - console.log('был') - selectElem.trigger('change', [self]); - } -} - -function setCustomProperties() -{ - let customPropertiesRows = $('.custom-property-row'); - 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(); - 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 = ''; - let parametersToFill = [ - '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_' - ]; - - for (let propertiesByCatalogId of Object.values(customProps)) { - propertiesByCatalogId.forEach(function (values) { - parametersToFill.forEach(function (param) { - newParams += ',' + param + values.code; - }); - }); - } - - let newValue = setupFieldsListElement.val() + newParams; - setupFieldsListElement.val(newValue); -} - -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 deleteCustomPropsRaw(buttonEvent) -{ - buttonEvent.closest('tr').remove(); -} - -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(); - - $('