Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda

im inheriting the Field fiel js from "@web/views/fields/field"; and it contain a function that i want to inherit


Field.parseFieldNode = function (node, models, modelName, viewType, jsClass) {
    const name = node.getAttribute("name");
    const widget = node.getAttribute("widget");
    const fields = models[modelName];
    if (!fields[name]) {
        throw new Error(`"${modelName}"."${name}" field is undefined.`);
    }
    const field = getFieldFromRegistry(fields[name].type, widget, viewType, jsClass);
    const fieldInfo = {
        name,
        type: fields[name].type,
        viewType,
        widget,
        field,
        context: "{}",
        string: fields[name].string,
        help: undefined,
        onChange: false,
        forceSave: false,
        options: {},
        decorations: {},
        attrs: {},
        domain: undefined,
    };

    for (const attr of ["invisible", "column_invisible", "readonly", "required"]) {
        fieldInfo[attr] = node.getAttribute(attr);
        if (fieldInfo[attr] === "True") {
            if (attr === "column_invisible") {
                fieldInfo.invisible = "True";
            }
        } else if (fieldInfo[attr] === null && fields[name][attr]) {
            fieldInfo[attr] = "True";
        }
    }

    for (const { name, value } of node.attributes) {
        if (["name", "widget"].includes(name)) {
            // avoid adding name and widget to attrs
            continue;
        }
        if (["context", "string", "help", "domain"].includes(name)) {
            fieldInfo[name] = value;
        } else if (name === "on_change") {
            fieldInfo.onChange = archParseBoolean(value);
        } else if (name === "options") {
            fieldInfo.options = evaluateExpr(value);
        } else if (name === "force_save") {
            fieldInfo.forceSave = archParseBoolean(value);
        } else if (name.startsWith("decoration-")) {
            // prepare field decorations
            fieldInfo.decorations[name.replace("decoration-", "")] = value;
        } else if (!name.startsWith("t-att")) {
            // all other (non dynamic) attributes
            fieldInfo.attrs[name] = value;
        }
    }
    if (name === "id") {
        fieldInfo.readonly = "True";
    }

    if (widget === "handle") {
        fieldInfo.isHandle = true;
    }

    if (X2M_TYPES.includes(fields[name].type)) {
        const views = {};
        let relatedFields = fieldInfo.field.relatedFields;
        if (relatedFields) {
            if (relatedFields instanceof Function) {
                relatedFields = relatedFields(fieldInfo);
            }
            for (const relatedField of relatedFields) {
                if (!("readonly" in relatedField)) {
                    relatedField.readonly = true;
                }
            }
            relatedFields = Object.fromEntries(relatedFields.map((f) => [f.name, f]));
            views.default = { fieldNodes: relatedFields, fields: relatedFields };
            if (!fieldInfo.field.useSubView) {
                fieldInfo.viewMode = "default";
            }
        }
        for (const child of node.children) {
            const viewType = child.tagName === "tree" ? "list" : child.tagName;
            const { ArchParser } = viewRegistry.get(viewType);
            // We copy and hence isolate the subview from the main view's tree
            // This way, the subview's tree is autonomous and CSS selectors will work normally
            const childCopy = child.cloneNode(true);
            const archInfo = new ArchParser().parse(childCopy, models, fields[name].relation);
            views[viewType] = {
                ...archInfo,
                limit: archInfo.limit || 40,
                fields: models[fields[name].relation],
            };
        }

        let viewMode = node.getAttribute("mode");
        if (viewMode) {
            if (viewMode.split(",").length !== 1) {
                viewMode = isSmall() ? "kanban" : "list";
            } else {
                viewMode = viewMode === "tree" ? "list" : viewMode;
            }
        } else {
            if (views.list && !views.kanban) {
                viewMode = "list";
            } else if (!views.list && views.kanban) {
                viewMode = "kanban";
            } else if (views.list && views.kanban) {
                viewMode = isSmall() ? "kanban" : "list";
            }
        }
        if (viewMode) {
            fieldInfo.viewMode = viewMode;
        }
        if (Object.keys(views).length) {
            fieldInfo.relatedFields = models[fields[name].relation];
            fieldInfo.views = views;
        }
    }

    return fieldInfo;
};


is there a way to inherit it without crashing something in it?

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
0
Nov 24
521
0
Okt 24
851
2
Okt 23
3623
1
Okt 23
2966
1
Apr 23
17316