VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/www/html/tech_preview/hr/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/tech_preview/hr/FunctionEditor.js
!(function (module){
var Context = absol.Context;
var EventEmitter  =  absol.EventEmitter;
var QuickMenu = absol.QuickMenu;
var  contenteditableTextOnly = absol.AComp.contenteditableTextOnly;
var PropertyEditor = absol.form.PropertyEditor;

var _ = absol._;
var $ = absol.$;
var formComponent = {};

module.emittor = new absol.EventEmitter();

// Hàm tạo component từ form có sẵn

module.PluginFormComponent = function(context){
    var allNode = $('exptree', context.self.$view, function (node) {
        return node.name == "all";
    });
    var self = context.self;
    var host = self.getContext("HOST");

    var formContent;
    if (host.taskName == "input" || host.taskName == "m_input") formContent = host.database.input_forms;
    else formContent = host.database.output_forms;

    var formNode = _({
        tag: 'exptree',
        props: {
            name: 'form',
            status: 'close'
        },
        on: {
            press: context.toggleGroup
        }
    });
    formContent.items.forEach(function(elt){
        var name = elt.name;
        var st = _({
            tag: 'exptree',
            props: {
                name: name,
                icon: 'span.mdi.mdi-terraform',
                /** class này đã tạo lúc thêm vào AssemblerInstance*/
                componentConstructor: elt.FragmentClass
            }
        });
        st.addTo(formNode);
    });

    allNode.addChild(formNode);
};


//Hàm tạo form navigation

module.PluginProjectExplore = function(context) {
    var _ = context._;
    var $ = context.$;

    /**
     * @type {import('../fragment/ProjectExplorer').default}
     */
    var self = context.self;
    var host = self.getContext("HOST");

    var formContent;
    if (host.taskName == "input" || host.taskName == "m_input") formContent = host.database.input_forms;
    else formContent = host.database.output_forms;

    var view = self.getView();
    var droppanel = self.$droppanel;
    var newButton = _({
        tag:'button',
        child:'span.mdi.mdi-file-plus-outline',
        on: {
            click: function(){
                form_module.showNewFormDialog(host).then(function(result){
                    form_module.saveForm(host, result).then(function(result){
                        self.loadExpTree();
                        self.openItem('form', result.id, result.name, result, result.desc);
                    }, function(message){
                        console.log(message);
                    });
                }, function(message){
                    console.log(message);
                });
            }
        }
    }).addTo(self.$cmdCtn);

    function contextMenuEventHandler(contentArguments, event) {
        var items = [
            {
                text: 'Open',
                icon: 'span.mdi.mdi-menu-open',
                cmd: 'open'
            }
        ];
        if (contentArguments.id > 0){
            items.push({
                text: 'Rename',
                icon: 'span.mdi.mdi-rename-box',
                cmd: 'rename'
            });
            items.push({
                text: 'Delete',
                icon: 'span.mdi.mdi-delete',
                cmd: 'delete'
            });
        }
        // if (contentArguments.id < 0){
        //     items.push({
        //         text: 'Upload Default',
        //         icon: 'span.mdi.mdi-rename-box',
        //         cmd: 'save'
        //     });
        // }

        event.showContextMenu({
            items: items,
            extendStyle: {
                fontSize: '12px'
            }
        }, function (event) {
            switch (event.menuItem.cmd) {
                case 'open':
                    self.openItem('form', contentArguments.id, contentArguments.name, contentArguments, contentArguments.desc)
                    break;
                case 'rename':
                    this.getNode().rename(function(newName){
                        for (var i = 0; i < contentArguments.formList.length; i++){
                            if (contentArguments.formList[i].name == newName) {
                                return false;
                            }
                        }
                        var formEditor =  context.self.getContext(absol.form.R.FORM_EDITOR);
                        return new Promise(function(rs){
                            form_module.renameForm(host.taskName, contentArguments.id, newName).then(function(){
                                var editorHolders = formEditor.editorHolders;
                                if (editorHolders[contentArguments.id] !== undefined){
                                    var tabElt = editorHolders[contentArguments.id].tabframe;
                                    tabElt.name = newName;
                                    editorHolders[contentArguments.id].name = newName;
                                }
                                contentArguments.name = newName;
                                self.loadExpTree();
                                rs(true);
                            }, function(){
                                rs(false);
                            });
                        });
                    }.bind(this));
                    break;
                case 'delete':
                    var title = "Xóa form";
                    var str = "Bạn muốn xóa form " + contentArguments.name + "?";
                    theme.deleteConfirm(title, str).then(function(){
                        form_module.deleteForm(host, contentArguments.id).then(function(){
                            var formEditor =  context.self.getContext(absol.form.R.FORM_EDITOR);
                            var editorHolders = formEditor.editorHolders;
                            if (editorHolders[contentArguments.id] !== undefined){
                                var tabElt = editorHolders[contentArguments.id].tabframe;
                                tabElt.$parent.removeTab(tabElt.id);
                            }
                            self.loadExpTree();
                        }, function(message){
                            if (message == "inForm") message = "Form này đang được sử dụng bởi form khác, không được xóa.";
                            if (message == "inUse") message = "Form này đang được sử dụng, không được xóa.";
                            else if (message == "notExist") message = "Form này không tồn tại";
                            ModalElement.alert({message: message});
                        });
                    }, function(){});
                    break;
            }
        }.bind(this));
    }

    var drawFormList = function (formList) {
        var droppanel = self.$droppanel;
        droppanel.clearChild();
        formList.forEach(function (it) {
            // if(it.id < 0) return;
            formComponent[it.id] = it.content;
            var res;
            res = _({
                tag: 'exptree',
                props: {
                    name: it.name,
                    icon: 'span.mdi.mdi-card-bulleted-outline'
                }
            });
            it.formList = formList;
            res.getNode().defineEvent('contextmenu')
                            .on('contextmenu', contextMenuEventHandler.bind(res, it))
                            .on('dblclick', function (event) {
                                self.openItem('form', it.id, it.name, it, it.desc);
                            });
            res.addTo(droppanel);
        });
        droppanel.show = true;
    };

    context.loadExpTree = function(){
        drawFormList(formContent.items);
    };

    self.loadExpTree();
};

// Hàm load nội dung form để xem và chỉnh sửa

module.PluginLoadContentData =  function (accumulator) {
    var sync;
    var host = accumulator.formEditor.getContext("HOST");
    if (accumulator.contentArguments.id > 0) {
        sync = host.funcs.loadFormContent(host, accumulator.contentArguments.id).then(function(data){
            try {
                accumulator.editor.setData(data);
            } catch (e) {
                console.log("error", data);
                console.error(e);
            }
        }).catch(function(err){
            ModalElement.alert({message: err.message});
            console.error(err);
        });
        accumulator.waitFor(sync);
    }
    else {
        if (host.taskName == "input") formContent = data_module.input_forms;
        else if (host.taskName == "m_input") formContent = data_module.mobile_input_forms;
        else if (host.taskName == "m_output") formContent = data_module.mobile_output_forms;
        else formContent = data_module.output_forms;
        var index = formContent.getIndex(accumulator.contentArguments.id);
        console.log(accumulator.contentArguments.id);
        console.log(formContent);
        console.log(index);
        accumulator.editor.setData(formContent.items[index].content);
        // accumulator.editor.setData(accumulator.contentArguments.content);
    }
}

// Hàm lấy dữ liệu để lưu form và hậu xử lý

module.PluginSaveContentData = function(accumulator) {
    if (accumulator.contentArguments.id < 0) {
        module.PluginSaveAsSystemContentData(accumulator);
        return;
    }
    var host = accumulator.formEditor.getContext("HOST");
    var content = accumulator.editor.getData();
    var data = accumulator.contentArguments;
    var formContent;
    if (host.taskName == "input" || host.taskName == "m_input") formContent = host.database.input_forms;
    else formContent = host.database.output_forms;
    var index = formContent.getIndex(accumulator.contentArguments.id);
    var typeid = formContent.items[index].typeid;
    var typeIndex = host.database.typelists.getIndex(typeid);
    var type = host.database.typelists.items[typeIndex].type;
    var type2 = host.database.typelists.items[typeIndex].type2;
    if (type == "structure" || type == "extends_structure" || type2 == "structure"){
        if (content.children){
            var childrenid = "";
            var getChildrenIdList = function(cur){
                if (cur.class && !isNaN(parseInt(cur.class))){
                    childrenid += "_" + parseInt(cur.class);
                }
                else if (cur.children && cur.children.length > 0){
                    cur.children.forEach(function(elt){
                        getChildrenIdList(elt);
                    })
                }
            }
            content.children.forEach(function(elt){
                getChildrenIdList(elt);
            });
            if (childrenid != "") childrenid += "_";
            data.childrenid = childrenid;
        }
    }
    else {
        data.childrenid = formContent.items[index].childrenid;
    }
    data.typedescendantid = "";
    contentModule.getDescendantsId(host, host.database.typelists.items[typeIndex]).forEach(function(elt){
        if (elt > 0) data.typedescendantid += "_" + elt;
    });
    if (data.typedescendantid != "") data.typedescendantid += "_";
    var blockDict = {};
    if (formContent.items[index].content.circuit.blocks)
    formContent.items[index].content.circuit.blocks.forEach(function(elt){
        if (elt.attributes.ident) blockDict[elt.name] = elt;
    });
    var lineDict = {};
    if (formContent.items[index].content.circuit.lines)
    formContent.items[index].content.circuit.lines.forEach(function(elt){
        if (elt.attributes && elt.attributes.ident) lineDict[elt.attributes.ident] = elt;
    });
    content.circuit.blocks.forEach(function(elt){
        if (elt.attributes.ident){
            if (EncodingClass.string.compare(elt, blockDict[elt.name]) == -1){
                elt.attributes.isModified = true;
            }
        }
    });
    content.circuit.lines.forEach(function(elt){
        if (elt.attributes && elt.attributes.ident){
            if (EncodingClass.string.compare(elt, blockDict[elt.name]) == -1){
                elt.attributes.isModified = true;
            }
        }
    });
    data.content = EncodingClass.string.fromVariable(content);
    var foo = function(data){
        form_module.formSaveContent(data).then(function(result){
            formContent.items[index] = result;
            accumulator.contentArguments = result;
        }, function(message){
            if (message.substr(0, 3) == "ver"){
                var result = EncodingClass.string.toVariable(message.substr(3));
                form_module.confirmVersionQuestion().then(function(message){
                    if (message == "overwrite"){
                        accumulator.contentArguments = result;
                        data.ver = result.ver;
                        foo(data);
                    }
                    else {
                        accumulator.contentArguments = result;
                        accumulator.editor.setData(EncodingClass.string.toVariable(result.content));
                    }
                });
            }
            else ModalElement.alert({message: message});
        });
    };
    foo(data);
}

module.PluginSaveAsContentData = function(accumulator) {
    var host = accumulator.formEditor.getContext("HOST");
    var content = accumulator.editor.getData();
    var data = accumulator.contentArguments;
    var formContent;
    if (host.taskName == "input" || host.taskName == "m_input") formContent = host.database.input_forms;
    else formContent = host.database.output_forms;
    var index = formContent.getIndex(accumulator.contentArguments.id);
    var typeid = formContent.items[index].typeid;
    var typeIndex = host.database.typelists.getIndex(typeid);
    var type = host.database.typelists.items[typeIndex].type;
    var type2 = host.database.typelists.items[typeIndex].type2;
    if (type == "structure" || type == "extends_structure" || type2 == "structure"){
        if (content.children){
            var childrenid = "";
            var getChildrenIdList = function(cur){
                if (cur.class && !isNaN(parseInt(cur.class))){
                    childrenid += "_" + parseInt(cur.class);
                }
                else if (cur.children && cur.children.length > 0){
                    cur.children.forEach(function(elt){
                        getChildrenIdList(elt);
                    })
                }
            }
            content.children.forEach(function(elt){
                getChildrenIdList(elt);
            });
            if (childrenid != "") childrenid += "_";
            data.childrenid = childrenid;
        }
    }
    else {
        data.childrenid = formContent.items[index].childrenid;
    }
    data.typedescendantid = "";
    contentModule.getDescendantsId(host, host.database.typelists.items[typeIndex]).forEach(function(elt){
        if (elt > 0) data.typedescendantid += "_" + elt;
    });
    if (data.typedescendantid != "") data.typedescendantid += "_";
    var blockDict = {};
    formContent.items[index].content.circuit.blocks.forEach(function(elt){
        if (elt.attributes.ident) blockDict[elt.name] = elt;
    });
    var lineDict = {};
    formContent.items[index].content.circuit.lines.forEach(function(elt){
        if (elt.attributes && elt.attributes.ident) lineDict[elt.attributes.ident] = elt;
    });
    content.circuit.blocks.forEach(function(elt){
        if (elt.attributes.ident){
            if (EncodingClass.string.compare(elt, blockDict[elt.name]) == -1){
                elt.attributes.isModified = true;
            }
        }
    });
    content.circuit.lines.forEach(function(elt){
        if (elt.attributes && elt.attributes.ident){
            if (EncodingClass.string.compare(elt, blockDict[elt.name]) == -1){
                elt.attributes.isModified = true;
            }
        }
    });
    var t_data = Object.assign({}, data);
    delete(t_data.formList);
    t_data.content = content;
    t_data = EncodingClass.string.duplicate(t_data);
    t_data.id = 0;
    t_data.name += " (copy)";
    var foo = function(data){
        form_module.saveForm(host, data).then(function(result){
            accumulator.formEditor.getContext(absol.form.R.PROJECT_EXPLORER).loadExpTree();
            accumulator.formEditor.getContext(absol.form.R.PROJECT_EXPLORER).openItem('form', result.id, result.name, result, result.desc);
        }, function(message){
            console.log(message);
        });
    };
    foo(t_data);
}

module.PluginSaveAsSystemContentData = function(accumulator) {
    var host = accumulator.formEditor.getContext("HOST");
    var content = accumulator.editor.getData();
    var data = accumulator.contentArguments;
    var formContent;
    if (host.taskName == "input" || host.taskName == "m_input") formContent = host.database.input_forms;
    else formContent = host.database.output_forms;
    var index = formContent.getIndex(accumulator.contentArguments.id);
    var typeid = formContent.items[index].typeid;
    var typeIndex = host.database.typelists.getIndex(typeid);
    var type = host.database.typelists.items[typeIndex].type;
    var type2 = host.database.typelists.items[typeIndex].type2;
    if (type == "structure" || type == "extends_structure" || type2 == "structure"){
        if (content.children){
            var childrenid = "";
            var getChildrenIdList = function(cur){
                if (cur.class && !isNaN(parseInt(cur.class))){
                    childrenid += "_" + parseInt(cur.class);
                }
                else if (cur.children && cur.children.length > 0){
                    cur.children.forEach(function(elt){
                        getChildrenIdList(elt);
                    })
                }
            }
            content.children.forEach(function(elt){
                getChildrenIdList(elt);
            });
            if (childrenid != "") childrenid += "_";
            data.childrenid = childrenid;
        }
    }
    else {
        data.childrenid = formContent.items[index].childrenid;
    }
    data.typedescendantid = "";
    contentModule.getDescendantsId(host, host.database.typelists.items[typeIndex]).forEach(function(elt){
        if (elt > 0) data.typedescendantid += "_" + elt;
    });
    if (data.typedescendantid != "") data.typedescendantid += "_";
    var blockDict = {};
    if (formContent.items[index].content.circuit.blocks){
        formContent.items[index].content.circuit.blocks.forEach(function(elt){
            if (elt.attributes.ident) blockDict[elt.name] = elt;
        });
    }
    var lineDict = {};
    if (formContent.items[index].content.circuit.lines){
        formContent.items[index].content.circuit.lines.forEach(function(elt){
            if (elt.attributes && elt.attributes.ident) lineDict[elt.attributes.ident] = elt;
        });
    }
    content.circuit.blocks.forEach(function(elt){
        if (elt.attributes.ident){
            if (EncodingClass.string.compare(elt, blockDict[elt.name]) == -1){
                elt.attributes.isModified = true;
            }
        }
    });
    content.circuit.lines.forEach(function(elt){
        if (elt.attributes && elt.attributes.ident){
            if (EncodingClass.string.compare(elt, blockDict[elt.name]) == -1){
                elt.attributes.isModified = true;
            }
        }
    });
    var t_data = Object.assign({}, data);
    delete(t_data.formList);
    t_data.content = content;
    t_data = EncodingClass.string.duplicate(t_data);
    t_data.id = (host.taskName == "input" || host.taskName == "m_input") ? t_data.typeid : -1000 + t_data.typeid;
    t_data.name = host.database.typelists.items[typeIndex].name;

    var foo = function(data){
        var formContent, FM_form_content;
        if (host.taskName == "input") {
            formContent = host.database.input_forms;
            FM_form_content = data_module.input_forms;
        }
        else if (host.taskName == "m_input") {
            formContent = host.database.input_forms;
            FM_form_content = data_module.mobile_input_forms;
        }
        else if (host.taskName == "m_output") {
            formContent = host.database.output_forms;
            FM_form_content = data_module.mobile_output_forms;
        }
        else {
            formContent = host.database.output_forms;
            FM_form_content = data_module.output_forms;
        }
        ModalElement.show_loading();
        uploadFormSystem.upload(data).then(function(rt){
            rt.content = EncodingClass.string.toVariable(rt.content);
            if (host.isMobile) rt.id = "m_" + rt.formid;
            else rt.id = rt.formid;
            if (rt.isInsert == 1){
                formContent.items.push(rt);
                FM_form_content.items.push(rt);
                console.log("insert");
            }
            else {
                var index = formContent.getIndex(rt.id);
                formContent.items[index] = rt;
                console.log(rt);
                var index = FM_form_content.getIndex(rt.id);
                FM_form_content.items[index] = rt;
                console.log("update_" + index);
            }
            if (host.taskName == "input") hr.input_form.loadFormConstructorToAssembler(formContent.items, host.database.typelists.items, 1);
            else if (host.taskName == "m_input") hr.input_form_mobile.loadFormConstructorToAssembler(formContent.items, host.database.typelists.items, 1);
            else if (host.taskName == "m_output") hr.output_form_mobile.loadFormConstructorToAssembler(formContent.items, host.database.typelists.items, 1);
            else hr.output_form.loadFormConstructorToAssembler(formContent.items, host.database.typelists.items, 1);
            ModalElement.close(-1);
        }, function(err){
            console.log(err);
        });
    };
    foo(t_data);
}

})(absol.form);

VaKeR 2022