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/keeview_app/html/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/keeview_app/html/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") 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 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
/**
 * @extends FMExploreDelegate
 * @constructor
 */
function HRFormProjectExploreDelegate() {
    absol.form.FMExploreDelegate.call(this);
}

absol.OOP.mixClass(HRFormProjectExploreDelegate, absol.form.FMExploreDelegate);

HRFormProjectExploreDelegate.prototype.getTreeData = function () {
    var host = this.getContext('HOST');
    if (!host) return [];
    var formContent;
    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;
    if (!formContent.items) return [];
    var formList = formContent.items;
    return  formList.map(function (it) {
        formComponent[it.id] = it.content;
        it.formList = formList;
        return {
            name: it.name,
            icon: 'span.mdi.mdi-card-bulleted-outline',
            rawData: it,
            openArgs: ['form', it.id, it.name, it, it.desc]
        }
    });
};

HRFormProjectExploreDelegate.prototype.getActionContextMenuProps = function (treeData) {
    var contentArguments = treeData.rawData;
    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'
        });
    }

    return {
        items: items
    };
};

HRFormProjectExploreDelegate.prototype.onUserRenameCompleted = function (ac){
    var contentArguments = ac.rawData;
    var formList = contentArguments.formList;
    var newName = ac.newName;

    for (var i = 0; i < formList.length; i++) {
        if (formList[i].name === newName) {
            return false;
        }
    }
    var formEditor = this.getContext(absol.form.R.FORM_EDITOR);
    var host = this.getContext('HOST');
    var task = formEditor.getTaskById(contentArguments.id);

    return new Promise(function (rs) {
        form_module.renameForm(host.taskName, contentArguments.id, newName).then(function () {
           if (task) {
               task.name = newName;
           }
            contentArguments.name = newName;
            rs(true);
        }, function () {
            rs(false);
        });
    });
};

HRFormProjectExploreDelegate.prototype.onTreeAction = function (treeData, action, nodeElt) {
    var contentArguments = treeData.rawData;
    var host = this.getContext("HOST");
    var formEditor = this.getContext(absol.form.R.FORM_EDITOR);
    switch (action.cmd) {
        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 task = formEditor.getTaskById(contentArguments.id);
                    if (task) task.remove();
                    nodeElt.selfRemove();
                }, 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;
    }
};

module.PluginProjectExplore = function (context) {
    var _ = context._;
    var $ = context.$;
    context.delegate = new HRFormProjectExploreDelegate();
    var self = context.self;
    self.cmdRunner.add('new', function () {
        var host = self.getContext('HOST');
        form_module.showNewFormDialog(host).then(function (result) {
            form_module.saveForm(host, result).then(function (result) {
                self.redrawExpTree();
                self.openItem('form', result.id, result.name, result, result.desc);
            }, function (message) {
                console.log(message);
            });
        }, function (message) {
            console.log(message);
        });
    });
    var host = self.getContext('HOST');
    self.windowTitle = ({
            input: 'Input form',
            m_input: 'Input form (mobile)',
            output: 'Output form',
            m_output: 'Output form (mobile)',
        })[host.taskName] || '*';
    if (self.$window) {
        self.$window.windowTitle = self.windowTitle;
    }

};

// 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") 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);
    var typeid = formContent.items[index].typeid;
    var typeIndex = data_module.typelists.getIndex(typeid);
    var type = data_module.typelists.items[typeIndex].type;
    var type2 = data_module.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, data_module.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") 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);
    var typeid = formContent.items[index].typeid;
    var typeIndex = data_module.typelists.getIndex(typeid);
    var type = data_module.typelists.items[typeIndex].type;
    var type2 = data_module.typelists.items[typeIndex].type2;
    host.typeDict = {};
    data_module.typelists.items.forEach((item, i) => {
        host.typeDict[item.id] = item;
    });
    form_module.selectBaseForm(host, typeid).then(function (formid) {
        form_module.makeFormBasedSample(host, typeid, formContent.items[index], formid, accumulator);
    });
}

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") 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);
    var typeid = formContent.items[index].typeid;
    var typeIndex = data_module.typelists.getIndex(typeid);
    var type = data_module.typelists.items[typeIndex].type;
    var type2 = data_module.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, data_module.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 = data_module.typelists.items[typeIndex].name;

    var foo = function (data) {
        var formContent;
        if (host.taskName == "input") {
            formContent = data_module.input_forms;
            // FM_form_content = data_module.input_forms;
        }
        else if (host.taskName == "m_input") {
            formContent = data_module.input_forms;
            // FM_form_content = data_module.mobile_input_forms;
        }
        else if (host.taskName == "m_output") {
            formContent = data_module.output_forms;
            // FM_form_content = data_module.mobile_output_forms;
        }
        else {
            formContent = data_module.output_forms;
            // FM_form_content = data_module.output_forms;
        }
        ModalElement.show_loading();
        console.log(data);
        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") {
                data_module.input_forms.items = formContent.items;
                hr.input_form.loadFormConstructorToAssembler();
            }
            else if (host.taskName == "m_input") {
                data_module.mobile_input_forms.items = formContent.items;
                hr.input_form_mobile.loadFormConstructorToAssembler();
            }
            else if (host.taskName == "m_output") {
                data_module.mobile_output_forms.items = formContent.items;
                hr.output_form_mobile.loadFormConstructorToAssembler();
            }
            else {
                data_module.output_forms.items = formContent.items;
                hr.output_form.loadFormConstructorToAssembler();
            }
            ModalElement.close(-1);
        }, function (err) {
            console.log(err);
        });
    };
    foo(t_data);
}

})(absol.form);

VaKeR 2022