403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/boxberry.delivery/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/boxberry.delivery/widget.js
const bbParams = {
    widgetKey: null,
    customCity: null,
    targetStart: null,
    ordersum: null,
    weight: null,
    paysum: null,
    height: null,
    width: null,
    depth: null,
    addressPropId: null,
    address: '',
    pvzId: null,
    pvzProfileIds: null,
    addToDescription: null,
    addAfterDescription: null,
    addToCustomId: null,
    customId: null,
    currentId: null,
    consoleLogEnabled: false,
    addressPvzReadOnly: false,
    ajaxUrl: '/bitrix/services/main/ajax.php?sessid=' + BX.bitrix_sessid() + '&action=boxberry:delivery.api.widget.',
    apiUrl: 'https://api.boxberry.ru/json.php',
    initialRequestMade: false,
    isAddressOneProp: false,
    cityName: null,
    street: null,
    house: null,
    flat: null,
    streetPropId: null,
    housePropId: null,
    flatPropId: null,
};

const bbDelivery = {
    callback: function (result) {
        bbDelivery.showConsoleLog(BX.message('WIDGET_SELECTED_PVZ_DATA'), result)

        if (result.id && result.address && result.address.length > 0) {
            bbDelivery.setPickupPoint(result);
        }
    },
    setAddress: function () {
        if (bbParams.isAddressOneProp) {
            const addressFields = document.getElementsByName('ORDER_PROP_' + bbParams.addressPropId);

            if (bbParams.address && addressFields) {
                addressFields.forEach((addressField) => {
                    addressField.value = bbParams.address;
                });

                bbDelivery.showConsoleLog(BX.message('WIDGET_ADDRESS_FIELDS'), addressFields)
            } else {
                bbDelivery.showConsoleLog(BX.message('WIDGET_ADDRESS_FIELDS_NOT_FOUND'))
            }
        } else {
            const streetFields = document.getElementsByName('ORDER_PROP_' + bbParams.streetPropId);
            const houseFields = document.getElementsByName('ORDER_PROP_' + bbParams.housePropId);
            const flatFields = document.getElementsByName('ORDER_PROP_' + bbParams.flatPropId);

            if (bbParams.street && bbParams.cityName && streetFields) {
                streetFields.forEach((streetField) => {
                    streetField.value = bbParams.street;
                });

                bbDelivery.showConsoleLog(BX.message('WIDGET_STREET_FIELDS'), streetFields)
            } else {
                bbDelivery.showConsoleLog(BX.message('WIDGET_STREET_FIELDS_NOT_FOUND'))
            }

            if (bbParams.house && houseFields) {
                houseFields.forEach((houseField) => {
                    houseField.value = bbParams.house;
                });

                bbDelivery.showConsoleLog(BX.message('WIDGET_HOUSE_FIELDS'), houseFields)
            } else {
                bbDelivery.showConsoleLog(BX.message('WIDGET_HOUSE_FIELDS_NOT_FOUND'))
            }

            if (bbParams.flat && flatFields) {
                flatFields.forEach((flatField) => {
                    flatField.value = bbParams.flat;
                });

                bbDelivery.showConsoleLog(BX.message('WIDGET_FLAT_FIELDS'), flatFields)
            } else {
                bbDelivery.showConsoleLog(BX.message('WIDGET_FLAT_FIELDS_NOT_FOUND'))
            }
        }
    },
    isSelected: function () {
        return bbParams.pvzProfileIds.includes(bbParams.currentId);
    },
    markAddressFieldReadOnly: function () {
        if (bbDelivery.isSelected() && bbParams.addressPvzReadOnly && bbParams.pvzId) {
            if (bbParams.isAddressOneProp) {
                const addressFields = document.getElementsByName('ORDER_PROP_' + bbParams.addressPropId);
                if (addressFields) {
                    addressFields.forEach((addressField) => {
                        addressField.value = bbParams.address;
                        addressField.readOnly = true;
                    });

                    bbDelivery.showConsoleLog(BX.message('WIDGET_ADDRESS_FIELDS_MARKED_AS_READONLY'), addressFields);
                }
            } else {
                const streetFields = document.getElementsByName('ORDER_PROP_' + bbParams.streetPropId);
                const houseFields = document.getElementsByName('ORDER_PROP_' + bbParams.housePropId);
                const flatFields = document.getElementsByName('ORDER_PROP_' + bbParams.flatPropId);

                if (streetFields) {
                    streetFields.forEach((streetField) => {
                        streetField.value = bbParams.street;
                        streetField.readOnly = true;
                    });

                    bbDelivery.showConsoleLog(BX.message('WIDGET_STREET_FIELDS_MARKED_AS_READONLY'), streetFields);

                }

                if (houseFields) {
                    houseFields.forEach((houseField) => {
                        houseField.value = bbParams.house;
                        houseField.readOnly = true;
                    });

                    bbDelivery.showConsoleLog(BX.message('WIDGET_HOUSE_FIELDS_MARKED_AS_READONLY'), houseFields);
                }

                if (flatFields) {
                    flatFields.forEach((flatField) => {
                        flatField.value = bbParams.flat;
                        flatField.readOnly = true;
                    });

                    bbDelivery.showConsoleLog(BX.message('WIDGET_FLAT_FIELDS_MARKED_AS_READONLY'), flatFields);
                }
            }
        }
    },
    showConsoleLog: function (...logs) {
        if (bbParams.consoleLogEnabled) {
            console.log(...logs);
        }
    },
    getParams: function () {
        const url = bbParams.ajaxUrl + 'get';
        fetch(url)
            .then(response => response.json())
            .then(data => {
                if (data.status === 'success') {
                    Object.assign(bbParams, data.data);
                    bbDelivery.updateElements();
                }

                bbDelivery.markAddressFieldReadOnly();

                bbDelivery.showConsoleLog(BX.message('WIDGET_PARAMS'), data)
            })
            .catch(error => {
                bbDelivery.showConsoleLog(BX.message('WIDGET_PARAMS_REQUEST_FAILED'), error)
            });
    },
    setPickupPoint: function (result) {
        Object.assign(bbParams, result);
        bbParams.pvzId = result.id;

        const url = bbParams.ajaxUrl + 'setPickupPoint';
        const urlParams = new URLSearchParams({
            sessid: BX.bitrix_sessid(),
            id: bbParams.pvzId,
            address: bbParams.address
        });

        fetch(url, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            body: urlParams
        })
            .then(response => response.json())
            .then(data => {
                bbDelivery.showConsoleLog(BX.message('WIDGET_PICKUP_POINT_DATA_SET'), data)
                if (data.status === 'success') {
                    Object.assign(bbParams, data.data);
                    bbDelivery.setAddress();
                    bbDelivery.updateElements();
                    bbDelivery.markAddressFieldReadOnly();
                    return true;
                } else {
                    if (data.errors[0].customData !== null && data.errors[0].customData.checkLocation === false) {
                        bbDelivery.showConsoleLog(data)
                        alert(data.errors[0].message);
                        return false;
                    }
                }
            })
            .catch(error => {
                bbDelivery.showConsoleLog(BX.message('WIDGET_PICKUP_POINT_DATA_NOT_SET'), error)
            });
    },
    open: function (e) {
        e.preventDefault();
        bbWidget.versionAPI(bbParams.apiUrl);
        bbWidget.open(
            bbDelivery.callback,
            bbParams.widgetKey,
            bbParams.customCity !== null ? bbParams.customCity.replace(BX.message('YO'), BX.message('YE')) : null,
            bbParams.targetStart,
            bbParams.ordersum,
            bbParams.weight,
            bbParams.paysum,
            bbParams.height,
            bbParams.width,
            bbParams.depth
        );
    },
    makeInitialRequest: function () {
        if (!bbParams.initialRequestMade) {
            bbParams.initialRequestMade = true;

            bbDelivery.getParams();

            if (typeof BX !== 'undefined' && BX.addCustomEvent) {
                BX.addCustomEvent('onAjaxSuccess', function (data, ajaxData) {
                    bbDelivery.showConsoleLog(BX.message('WIDGET_ON_AJAX_SUCCESS_ARGUMENT_1_DATA'), data, BX.message('WIDGET_ON_AJAX_SUCCESS_ARGUMENT_2_DATA'), ajaxData)
                    bbDelivery.getParams();
                });
            }
        }
    },
    updateElements: function () {
        if (!Array.isArray(bbParams.pvzProfileIds) || bbParams.pvzProfileIds.length === 0) {
            bbDelivery.showConsoleLog(BX.message('WIDGET_PVZ_PROFILES_NOT_FOUND'));
            return;
        }

        if (bbParams.addToCustomId) {
            bbDelivery.handleAddToCustomId();
            return;
        }

        if (bbParams.addAfterDescription) {
            bbDelivery.showConsoleLog(BX.message('WIDGET_ADD_AFTER_DESCRIPTION'), bbParams.addAfterDescription)
            bbDelivery.handleAddAfterDescription();
            return;
        }

        bbParams.pvzProfileIds.forEach(function (id) {
            if (id === null) {
                return;
            }

            let bbDivId = 'boxberry_widget_' + id;
            let bbDiv = document.getElementById(bbDivId);

            if (bbDiv) {
                bbDelivery.updateElement(bbDivId);
            } else {
                const intervalId = setInterval(() => {
                    bbDiv = document.getElementById(bbDivId);
                    if (bbDiv) {
                        bbDelivery.updateElement(bbDivId);
                        clearInterval(intervalId);
                    }
                }, 1000);
            }
        });
    },
    handleAddToCustomId: function () {
        const customIdElement = document.getElementById(bbParams.customId);
        if (!customIdElement) {
            setTimeout(bbDelivery.handleAddToCustomId, 1000);
            return;
        }

        bbDelivery.updateElement(bbParams.customId);
    },
    handleAddAfterDescription: function () {
        const descriptionElements = document.querySelectorAll('#bx-soa-delivery .bx-soa-pp-company-desc');
        if (descriptionElements.length === 0) {
            setTimeout(bbDelivery.handleAddAfterDescription, 1000);
            return;
        }

        descriptionElements.forEach((descriptionElement) => {

            if (!bbDelivery.isSelected()) {
                return;
            }
            const nextElement = descriptionElement.nextElementSibling;
            if (bbParams.addAfterDescription && (!nextElement || nextElement.id !== 'boxberry_widget_' + bbParams.currentId || !nextElement.querySelector('.boxberry_widget'))) {
                descriptionElement.insertAdjacentHTML('afterend', bbParams.addAfterDescription);
                bbDelivery.updateElement(descriptionElement.nextElementSibling.id);
                return;
            }

            if (nextElement && nextElement.id === 'boxberry_widget_' + bbParams.currentId) {
                bbDelivery.updateElement(nextElement.id);
            }
        });
    },
    updateElement: function (bbDiv) {
        const targetDiv = document.getElementById(bbDiv);

        if (!targetDiv) {
            bbDelivery.showConsoleLog(BX.message('WIDGET_TARGET_DIV_NOT_FOUND'), bbDiv)
            return;
        } else {
            bbDelivery.showConsoleLog(BX.message('WIDGET_TARGET_DIV'), targetDiv);
        }

        if (bbParams.addToCustomId) {
            targetDiv.innerHTML = bbParams.addToCustomId;
            bbDelivery.showConsoleLog(BX.message('WIDGET_ADD_TO_CUSTOM_ID'), bbParams.addToCustomId)
        }

        if (bbParams.addToDescription) {
            targetDiv.innerHTML = bbParams.addToDescription;

            bbDelivery.showConsoleLog(BX.message('WIDGET_ADD_AFTER_DESCRIPTION'), bbParams.addToDescription)
        }

        if (bbDelivery.isSelected()) {
            bbDelivery.showConsoleLog(BX.message('WIDGET_SELECTED_PROFILE_ID'), bbParams.currentId)
            targetDiv.style.display = 'block';
        } else {
            targetDiv.style.display = 'none';
            return;
        }

        const buttonElement = targetDiv.querySelector('button');

        if (!buttonElement) {
            bbDelivery.showConsoleLog(BX.message('WIDGET_BUTTON_ELEMENT_NOT_FOUND'))
            return;
        } else {
            bbDelivery.showConsoleLog(BX.message('WIDGET_BUTTON_ELEMENT'), buttonElement)
        }

        buttonElement.textContent = !bbParams.address ? BX.message('WIDGET_SELECT_PVZ_TEXT') : BX.message('WIDGET_SELECT_ANOTHER_PVZ_TEXT');
        buttonElement.addEventListener('click', bbDelivery.open);

        const p = targetDiv.querySelector('p');
        if (p) {
            if (bbParams.address) {
                p.textContent = BX.message('WIDGET_SELECTED_PVZ_TEXT') + bbParams.address;
                p.style.display = 'block';

                bbDelivery.showConsoleLog(BX.message('WIDGET_P_TAG_FOUND'), p, 'p textContent:', p.textContent, 'p style:', p.style.display)
            }

            if (!bbParams.address) {
                p.textContent = '';
                p.style.display = 'none';

                bbDelivery.showConsoleLog(BX.message('WIDGET_P_TAG_FOUND'), p, 'p textContent:', p.textContent, 'p style:', p.style.display)
            }
        } else {
            bbDelivery.showConsoleLog(BX.message('WIDGET_P_TAG_NOT_FOUND'))
        }

        bbDelivery.setAddress();
    }
};

document.addEventListener('DOMContentLoaded', () => {
    bbDelivery.makeInitialRequest();
});

Youez - 2016 - github.com/yon3zu
LinuXploit