diff --git a/intaro.retailcrm/export/export_setup.php b/intaro.retailcrm/export/export_setup.php
index 1baa20d6..c52c2fe2 100644
--- a/intaro.retailcrm/export/export_setup.php
+++ b/intaro.retailcrm/export/export_setup.php
@@ -592,6 +592,7 @@ if ($STEP === 1) {
+
diff --git a/intaro.retailcrm/install/export/bitrix/js/intaro/custom-props-export.js b/intaro.retailcrm/install/export/bitrix/js/intaro/custom-props-export.js
index 3b055dcc..94065dc3 100644
--- a/intaro.retailcrm/install/export/bitrix/js/intaro/custom-props-export.js
+++ b/intaro.retailcrm/install/export/bitrix/js/intaro/custom-props-export.js
@@ -1,63 +1,102 @@
-const setupFieldsListElement = $('input[name="SETUP_FIELDS_LIST"]');
-let customProperties = [
- {code: 'newProperty2', title: 'Новое свойство'},
- {code: 'newProperty3', title: 'Новое свойство 2'},
-];
+$(document).on('blur', 'input[name="custom-property-title"]', function () {
+ let inputElem = $(this);
+ let newPropertyTitle = inputElem.val();
-document.getElementById('submit-form').addEventListener('submit', function (formEvent) {
+ if (!newPropertyTitle) {
+ return;
+ }
+
+ let newPropertyCode = getUniquePropertyCode(newPropertyTitle);
+ addCustomPropCodeToSelectAttributes(newPropertyCode, inputElem);
+});
+
+$('#submit-form').submit(function (formEvent) {
+ let formElem = formEvent.currentTarget;
formEvent.preventDefault();
- // setCustomProperties();
- // addNewParametersToSetupFieldsList();
+ setCustomProperties();
+ addParamsToSetupFieldsList();
BX.ajax.runAction('intaro:retailcrm.api.customexportprops.save', {
json: {properties: customProperties},
- }).then(function(response) {
- console.log(response);
- // this.submit();
+ }).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 customPropertiesRaws = $('tr[data-type="custom-property-raw"]');
+ let customPropertiesRows = $('.custom-property-row');
+ let customPropertyCatalogId;
let customPropertyTitle = '';
let customPropertyCode = '';
let productPropertyMatch = '';
let offerPropertyMatch = '';
- customPropertiesRaws.each(function (rawElem) {
- let raw = $(rawElem);
- console.log(raw.find('input[name=custom-property-title]').val());
- customPropertyTitle = raw.find('input[name=custom-property-title]').value;
- customPropertyCode = getUniquePropertyCode(customPropertyTitle);
- productPropertyMatch = raw.find('select[name=custom-product-property-select]').value;
- offerPropertyMatch = raw.find('select[name=custom-offer-property-select]').value;
+ let catalogIds = [];
+ customPropertiesRows.each(function (index, propertyRow) {
+ let propertyRowObj = $(propertyRow);
+ customPropertyCatalogId = propertyRowObj.closest('.iblockExportTable').data('type');
- customProperties.push({
+ 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) {
+ customProperties[customPropertyCatalogId] = [values];
+ } else {
+ customProperties[customPropertyCatalogId].push(values);
+ }
+ catalogIds.push(customPropertyCatalogId);
});
}
function getUniquePropertyCode(customPropertyTitle)
{
- const setupFieldsListValues = setupFieldsListElement.val().split(',');
- let uniqueValue = customPropertyTitle;
- console.log(uniqueValue);
+ let uniqueValue = transliterate(customPropertyTitle).replace(/ /g, '_');
let counter = 0;
+ const setupFieldsListValues = setupFieldsListElement.val().split(',');
while (setupFieldsListValues.includes(uniqueValue)) {
uniqueValue = `${customPropertyTitle}${++counter}`;
}
- console.log(uniqueValue);
return uniqueValue;
}
-function addNewParametersToSetupFieldsList()
+function addParamsToSetupFieldsList()
{
let newParams = '';
let parametersToFill = [
@@ -73,22 +112,97 @@ function addNewParametersToSetupFieldsList()
'highloadblock_producteshop_brand_reference_'
];
- customProperties.forEach(function (property) {
- parametersToFill.forEach(function (param) {
- newParams += param + property.code;
+ for (let propertiesByCatalogId of Object.values(customProperties)) {
+ propertiesByCatalogId.forEach(function (values) {
+ parametersToFill.forEach(function (param) {
+ newParams += ',' + param + values.code;
+ });
});
- });
+ }
- setupFieldsListElement.value = setupFieldsListElement.value + ',' + newParams;
+ let newValue = setupFieldsListElement.val() + newParams;
+ setupFieldsListElement.val(newValue);
}
-function createNewCustomPropertyTableRaw()
+function createCustomPropsRaw(addRowButton)
{
- let elementsToCopy = document.querySelectorAll('[data-type="custom-property-raw"]');
+ let templateRow = $($('#custom-property-template-row').html());
+ let templateSelectElements = templateRow.find('select');
- if (elementsToCopy.length > 0) {
- const lastElement = elementsToCopy[elementsToCopy.length - 1];
- const copyElement = lastElement.cloneNode(true);
- lastElement.after(copyElement);
+ 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();
+
+ $('