<commit_before>/**
 * 
 * @author User
 */
define('NewService', ['orm', 'forms', 'ui', 'rpc', 'invoke'], function (Orm, Forms, Ui, Rpc, invoke, ModuleName) {
    function module_constructor() {
        var self = this
                , model = Orm.loadModel(ModuleName)
                , form = Forms.loadForm(ModuleName, model);

        var BillFunc = new Rpc.Proxy('BillApiFunctions');
        //var ListOfTypes;

        self.show = function (aPanel) {
            var cont = aPanel ? (typeof (aPanel) === 'object' ? aPanel
                    : document.getElementById(aPanel))
                    : self.container;
            if (cont) {
                if (cont.add)
                    cont.add(form.view, {left: 0, top: 0, right: 0, bottom: 0});
                else
                    form.view.showOn(cont);
                if (form.onWindowOpened)
                    form.onWindowOpened();
            } else
                form.show();
        };

        self.showModal = function (callback) {
            form.showModal(callback);
        };

        form.mcbPeriod.value = true;
        form.mcbCounter.value = false;
        form.mcbPrepayment.value = false;
        form.mcbOnce.value = false;

        //Открытие для редактирования
        self.setParamsOpen = function (aListOfTypes) {
            form.btnCreate.visible = false;
            form.btnDel.visible = true;
            form.cbUnsubscribe.visible = true;
            form.btnSave.visible = true;

            checkListOfTypes(aListOfTypes, function (types) {
                SetData_mcType(types);
            });
        };

        //Открытия для создания
        self.setParamsNew = function (aListOfTypes) {
            checkListOfTypes(aListOfTypes, function (types) {
                SetData_mcType(types);
            });
        };

        //заполнение mcType
        function SetData_mcType(aListOfTypes) {
            form.mcType.displayList = aListOfTypes;
            form.mcType.displayField = 'type_name';
            form.mcType.value = form.mcType.displayList[0];
        }
        ;

        //Если есть список типов, присваиваем, если нет, запрашиваем с сервера
        function checkListOfTypes(aListOfTypes, callback) {
            if (aListOfTypes)
                callback(aListOfTypes);
            else {
                GetListOfTypes(function (types) {
                    callback(types);
                });
            }
        }

        //Запрос списка типов
        function GetListOfTypes(CallBack) {
            BillFunc.request("services/get_types", {}, function (success_getTypes) {
                console.log(success_getTypes);
//                    Request();
                CallBack(success_getTypes);
            }, function (error_getTypes) {
                console.log(error_getTypes);
                CallBack(null);
                md.alert("Ошибка получения типов!");
            });
        }
        ;

        //Кнопка подверждения создания
        form.btnCreate.onActionPerformed = function () {

        };

        //Кнопка сохранения
        form.btnSave.onActionPerformed = function () {

        };

        //Изменение значения типа в списке типов
        function ChangeType(TypeId) {
            form.mcType.value = form.mcType.displayList.filter(function (aItems) {
                return aItems.bill_services_types_id.indexOf(TypeId) !== -1;
            })[0];
        }

        //Нажали галочку на периоде
        form.mcbPeriod.onActionPerformed = function (evt) {
            if (form.mcbPeriod.value) {
                form.mcbCounter.value = true;
                if (form.mcbOnce.value) {
                    //ChangeType('OneTime');
                } else {
                    ChangeType('CounterServiceModule');
                }
            } else {
                if (form.mcbOnce.value) {
                    form.mcbCounter.value = false;
                    //ChangeType('OneTime');
                } else {
                    if (form.mcbCounter.value)
                        ChangeType('PeriodCounterServiceModule');
                    else
                        ChangeType('PeriodServiceModule');
                }
            }

            //form.mcbCounter.enabled = form.mcbPeriod.value;
        };

        //Кликнули галочку на счетчике
        form.mcbCounter.onActionPerformed = function () {
            if (form.mcbCounter.value) {
                form.mcbPeriod.value = true;
                if (form.mcbOnce.value) {
                    //ChangeType('OneTime');
                } else {
                    ChangeType('PeriodServiceModule');
                }
            } else {
                if (form.mcbOnce.value) {
                    form.mcbPeriod.value = false;
                    //ChangeType('OneTime');
                } else {
                    if (form.mcbPeriod.value)
                        ChangeType('PeriodCounterServiceModule');
                    else
                        ChangeType('CounterServiceModule');
                }
            }
            //form.mcbPeriod.enabled = form.mcbCounter.value;
        };

        //Нажатие на галочку "Единоразово"
        form.mcbOnce.onActionPerformed = function () {
            if (!form.mcbOnce.value)
                ChangeType('OneTime');
            
            else if (!form.mcbCounter.value)
                ChangeType('PeriodServiceModule');
            else if (!form.mcbPeriod.value)
                ChangeType('CounterServiceModule');
            else
                ChangeType('PeriodCounterServiceModule');



        };


        //Смена значения списка типов
        form.mcType.onValueChange = function (evt) {
            if (!form.mcType.value) {
                form.mcType.value = form.mcType.displayList[0];
            } else
                switch (form.mcType.value.bill_services_types_id) {
                    case 'PeriodServiceModule':
                        form.mcbPeriod.value = true;
                        form.mcbCounter.value = false;
                        form.mcbOnce.value = false;
                        break;
                    case 'CounterServiceModule':
                        form.mcbPeriod.value = false;
                        form.mcbCounter.value = true;
                        form.mcbOnce.value = false;
                        break;<commit_msg>little fix<commit_after>/**
 * 
 * @author User
 */
define('NewService', ['orm', 'forms', 'ui', 'rpc', 'invoke'], function (Orm, Forms, Ui, Rpc, invoke, ModuleName) {
    function module_constructor() {
        var self = this
                , model = Orm.loadModel(ModuleName)
                , form = Forms.loadForm(ModuleName, model);

        var BillFunc = new Rpc.Proxy('BillApiFunctions');
        //var ListOfTypes;

        self.show = function (aPanel) {
            var cont = aPanel ? (typeof (aPanel) === 'object' ? aPanel
                    : document.getElementById(aPanel))
                    : self.container;
            if (cont) {
                if (cont.add)
                    cont.add(form.view, {left: 0, top: 0, right: 0, bottom: 0});
                else
                    form.view.showOn(cont);
                if (form.onWindowOpened)
                    form.onWindowOpened();
            } else
                form.show();
        };

        self.showModal = function (callback) {
            form.showModal(callback);
        };

        form.mcbPeriod.value = true;
        form.mcbCounter.value = false;
        form.mcbPrepayment.value = false;
        form.mcbOnce.value = false;

        //Открытие для редактирования
        self.setParamsOpen = function (aListOfTypes) {
            form.btnCreate.visible = false;
            form.btnDel.visible = true;
            form.cbUnsubscribe.visible = true;
            form.btnSave.visible = true;

            checkListOfTypes(aListOfTypes, function (types) {
                SetData_mcType(types);
            });
        };

        //Открытия для создания
        self.setParamsNew = function (aListOfTypes) {
            checkListOfTypes(aListOfTypes, function (types) {
                SetData_mcType(types);
            });
        };

        //заполнение mcType
        function SetData_mcType(aListOfTypes) {
            form.mcType.displayList = aListOfTypes;
            form.mcType.displayField = 'type_name';
            form.mcType.value = form.mcType.displayList[0];
        }
        ;

        //Если есть список типов, присваиваем, если нет, запрашиваем с сервера
        function checkListOfTypes(aListOfTypes, callback) {
            if (aListOfTypes)
                callback(aListOfTypes);
            else {
                GetListOfTypes(function (types) {
                    callback(types);
                });
            }
        }

        //Запрос списка типов
        function GetListOfTypes(CallBack) {
            BillFunc.request("services/get_types", {}, function (success_getTypes) {
                console.log(success_getTypes);
//                    Request();
                CallBack(success_getTypes);
            }, function (error_getTypes) {
                console.log(error_getTypes);
                CallBack(null);
                md.alert("Ошибка получения типов!");
            });
        }
        ;

        //Кнопка подверждения создания
        form.btnCreate.onActionPerformed = function () {

        };

        //Кнопка сохранения
        form.btnSave.onActionPerformed = function () {

        };

        //Изменение значения типа в списке типов
        function ChangeType(TypeId) {
            form.mcType.value = form.mcType.displayList.filter(function (aItems) {
                return aItems.bill_services_types_id.indexOf(TypeId) !== -1;
            })[0];
        }

        //Нажали галочку на периоде
        form.mcbPeriod.onActionPerformed = function (evt) {
            if (form.mcbPeriod.value) {
                form.mcbCounter.value = true;
                if (form.mcbOnce.value) {
                    //ChangeType('OneTime');
                } else {
                    ChangeType('CounterServiceModule');
                }
            } else {
                if (form.mcbOnce.value) {
                    form.mcbCounter.value = false;
                    //ChangeType('OneTime');
                } else {
                    if (form.mcbCounter.value)
                        ChangeType('PeriodCounterServiceModule');
                    else
                        ChangeType('PeriodServiceModule');
                }
            }

            //form.mcbCounter.enabled = form.mcbPeriod.value;
        };

        //Кликнули галочку на счетчике
        form.mcbCounter.onActionPerformed = function () {
//            if (form.mcbCounter.value) {
//                form.mcbPeriod.value = true;
//                if (form.mcbOnce.value) {
//                    //ChangeType('OneTime');
//                } else {
//                    ChangeType('PeriodServiceModule');
//                }
//            } else {
//                if (form.mcbOnce.value) {
//                    form.mcbPeriod.value = false;
//                    //ChangeType('OneTime');
//                } else {
//                    if (form.mcbPeriod.value)
//                        ChangeType('PeriodCounterServiceModule');
//                    else
//                        ChangeType('CounterServiceModule');
//                }
//            }
//            //form.mcbPeriod.enabled = form.mcbCounter.value;

            if (form.mcbCounter.value)
                if (!form.mcbOnce.value)
                    ChangeType('PeriodServiceModule');
                else
                    form.mcbPeriod.value = true;
            else if (!form.mcbPeriod.value)
                ChangeType('CounterServiceModule');
            else if (!form.mcbOnce.value)
                ChangeType('PeriodCounterServiceModule');
            else
                form.mcbPeriod.value = false;
        };

        //Нажатие на галочку "Единоразово"
        form.mcbOnce.onActionPerformed = function () {
            if (!form.mcbOnce.value)
                ChangeType('OneTime');

            else if (!form.mcbCounter.value)
                ChangeType('PeriodServiceModule');
            else if (!form.mcbPeriod.value)
                ChangeType('CounterServiceModule');
            //else
            //ChangeType('PeriodCounterServiceModule');
        };


        //Смена значения списка типов
        form.mcType.onValueChange = function (evt) {
            if (!form.mcType.value) {
                form.mcType.value = form.mcType.displayList[0];
            } else
                switch (form.mcType.value.bill_services_types_id) {
                    case 'PeriodServiceModule':
                        form.mcbPeriod.value = true;
                        form.mcbCounter.value = false;
                        form.mcbOnce.value = false;
                        break;
                    case 'CounterServiceModule':
                        form.mcbPeriod.value = false;
                        form.mcbCounter.value = true;
                        form.mcbOnce.value = false;
                        break;
{'fraction_non_alphanumeric': 0.10339354546141637, 'fraction_numerical': 0.0012092812334668582, 'mean_word_length': 1.3064319330660623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2936366', 'n_tokens_mistral': 3641, 'n_tokens_neox': 3523, 'n_words': 591}