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/sale/checkout/model/src/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/sale/checkout/model/src/consent.js
import {VuexBuilderModel} from 'ui.vue.vuex';
import {Type} from 'main.core';
import {Consent as Const} from 'sale.checkout.const';

export class Consent extends VuexBuilderModel
{
    getName()
    {
        return 'consent';
    }

    getState()
    {
        return {
            status: Const.status.init,
            consent: Consent.getBaseItem(),
            errors: []
        }
    }

    static getBaseItem()
    {
        return {
            id: 0,
            title: '',
            isLoaded: '',
            autoSave: '',
            isChecked: '',
            submitEventName: '',
            params: []
        };
    }

    validate(fields)
    {
        const result = {};

        if (Type.isString(fields.status))
        {
            result.status = fields.status.toString()
        }

        if (Type.isObject(fields.consent))
        {
            result.consent = this.validateConsent(fields.consent);
        }

        return result;
    }

    validateConsent(fields)
    {
        const result = {};

        if (Type.isNumber(fields.id) || Type.isString(fields.id))
        {
            result.id = parseInt(fields.id);
        }

        if (Type.isString(fields.title))
        {
            result.title = fields.title.toString();
        }

        if (Type.isString(fields.isLoaded))
        {
            result.isLoaded = fields.isLoaded.toString();
        }

        if (Type.isString(fields.autoSave))
        {
            result.autoSave = fields.autoSave.toString();
        }

        if (Type.isString(fields.isChecked))
        {
            result.isChecked = fields.isChecked.toString();
        }

        if (Type.isString(fields.submitEventName))
        {
            result.submitEventName = fields.submitEventName.toString();
        }

        if (Type.isArrayFilled(fields.params))
        {
            result.params = this.validateParams(fields.params);
        }

        return result;
    }

    validateParams(fields)
    {
        const result = [];
        try
        {
            for (let key in fields)
            {
                if (!fields.hasOwnProperty(key))
                {
                    continue;
                }

                if (Type.isNumber(fields[key]) || Type.isString(fields[key]))
                {
                    result[key] = fields[key];
                }
            }
        }
        catch (e) {}

        return result;
    }

    getActions()
    {
        return {
            setStatus: ({ commit }, payload) =>
            {
                payload = this.validate({status: payload});

                const status = Object.values(Const.status);

                payload.status = status.includes(payload.status) ? payload.status : Const.status.init;

                commit('setStatus', payload);
            },

            set: ({ commit }, payload) =>
            {
                payload = this.validate({consent: payload});
                commit('set', payload);
            }
        }
    }

    getGetters()
    {
        return {
            getStatus: state =>
            {
                return state.status;
            },
            get: state =>
            {
                return state.consent;
            },
        }
    }

    getMutations()
    {
        return {
            setStatus: (state, payload) =>
            {
                state.status = payload.status;
            },

            set: (state, payload) =>
            {
                let item = Consent.getBaseItem();

                state.consent = Object.assign(item, payload.consent);
            },
            setErrors: (state, payload) =>
            {
                state.errors = payload;
            },
            clearErrors: (state) =>
            {
                state.errors = [];
            }
        }
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit