From f357294b7a51684e704d8075fe85bc56d6b00d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9C=E6=9C=AA=E5=A4=AE?= <2996985766@qq.com> Date: Tue, 9 Sep 2025 00:05:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=8C=E6=96=87=E6=9C=AC=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=EF=BC=8Cindex=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/list/list_controller.scss | 2 +- .../static/src/js/form_controller.js | 14 +++---- .../static/src/views/form/form_controller.js | 37 ++++++----------- .../static/src/views/form/form_controller.xml | 2 +- .../static/src/field_tinymce/field_tinymce.js | 40 ++++++++++++------- 5 files changed, 48 insertions(+), 47 deletions(-) diff --git a/oo_list_manager/static/src/views/list/list_controller.scss b/oo_list_manager/static/src/views/list/list_controller.scss index 99ff343d8..11aecb43a 100644 --- a/oo_list_manager/static/src/views/list/list_controller.scss +++ b/oo_list_manager/static/src/views/list/list_controller.scss @@ -54,7 +54,7 @@ } thead { - z-index: 20 !important; + z-index: 2 !important; } thead .o_filter_box .o_column_freeze { diff --git a/sh_backmate_theme_adv_enterprise/static/src/js/form_controller.js b/sh_backmate_theme_adv_enterprise/static/src/js/form_controller.js index 0d8a0bcab..c85d20610 100644 --- a/sh_backmate_theme_adv_enterprise/static/src/js/form_controller.js +++ b/sh_backmate_theme_adv_enterprise/static/src/js/form_controller.js @@ -11,16 +11,16 @@ import { useModel } from "@web/model/model"; patch(FormController.prototype, { - async setup() { + async setup() { super.setup(); if (this.footerArchInfo) { // If dialogue box then need to give edit permission this.props.preventEdit = false } - else if (session.sh_disable_auto_edit_model){ + else if (session.sh_disable_auto_edit_model) { this.model.config.mode = 'readonly'; } - }, + }, disableEditButton() { if (session.sh_disable_auto_edit_model) { @@ -42,21 +42,21 @@ patch(FormController.prototype, { } }, async discard() { - super.discard(); + super.discard(); if (session.sh_disable_auto_edit_model) { this.hideEdit = false } - this.model.root.switchMode("readonly"); + this.model.root.switchMode("readonly"); }, async shDisplayButtons() { const dirty = await this.model.root.isDirty(); if (dirty) { - return false + return false } else { - return true + return true } }, diff --git a/sh_backmate_theme_adv_enterprise/static/src/views/form/form_controller.js b/sh_backmate_theme_adv_enterprise/static/src/views/form/form_controller.js index b09df8697..a835aaece 100644 --- a/sh_backmate_theme_adv_enterprise/static/src/views/form/form_controller.js +++ b/sh_backmate_theme_adv_enterprise/static/src/views/form/form_controller.js @@ -2,9 +2,8 @@ import { patch } from "@web/core/utils/patch"; import { session } from "@web/session"; import { FormController } from "@web/views/form/form_controller"; -import { Mutex } from "@web/core/utils/concurrency"; import { useService } from "@web/core/utils/hooks"; -import { useState, useEffect } from "@odoo/owl"; +import { useState, useEffect, onMounted } from "@odoo/owl"; const originalSetup = FormController.prototype.setup; const originalEdit = FormController.prototype.edit; const originalSaveButtonClicked = FormController.prototype.saveButtonClicked; @@ -13,16 +12,22 @@ const originalDiscard = FormController.prototype.discard; patch(FormController.prototype, { setup() { - // change this to true if you want to prevent editing for admin - // this.isAdmin = session.name === "Administrator"; this.isAdmin = session.is_admin; - // if (this.isAdmin) { - // this.props.preventEdit = this.env.inDialog ? false : true; - // } this.orm = useService("orm"); this.actionService = useService("action"); - this.props.preventEdit = this.env.inDialog ? false : true; //edit by Lucky 20250714 + const resModel = this.props.resModel; + const resmode = this.props.info.mode; + // 定义白名单模型库 + const whitelistModels = [ + "res.config.settings", + "ks_dashboard_ninja.item" // 可以继续往里加 + ]; + onMounted(async () => { + if (!whitelistModels.includes(resModel) && resmode !== "inDialog") { + await this.model.root.switchMode("readonly"); + } + }); this.buttonState = useState({ showEditButton: true, }) @@ -40,11 +45,7 @@ patch(FormController.prototype, { } if (this.model && this.model.root) { - // 添加管理员才会变只读 - // if (this.isAdmin) { await this.model.root.switchMode("edit"); - // $('.o_field_readonly').prop('readonly', false) - // } } else { console.error("Model or model root is not defined"); } @@ -57,16 +58,10 @@ patch(FormController.prototype, { const isValid = await this.model.root.checkValidity(); if (!isValid) return; if (!this.env.inDialog) { - // 添加管理员才会变只读 - // if (this.isAdmin) { await this.model.root.switchMode("readonly"); - // } } // 判断按钮状态 this.editButtonState(); - // } else { - // this.model.actionService.doAction({ type: 'ir.actions.act_window_close' }); - // } }, async discard() { @@ -75,14 +70,8 @@ patch(FormController.prototype, { } if (!this.env.inDialog) { - // 添加管理员才会变只读 - // if (this.isAdmin) { await this.model.root.switchMode("readonly"); - // } } - // else { - // this.model.actionService.doAction({ type: 'ir.actions.act_window_close' }); - // } }, // async beforeLeave() { diff --git a/sh_backmate_theme_adv_enterprise/static/src/views/form/form_controller.xml b/sh_backmate_theme_adv_enterprise/static/src/views/form/form_controller.xml index f8aa75b88..bd9450fc7 100644 --- a/sh_backmate_theme_adv_enterprise/static/src/views/form/form_controller.xml +++ b/sh_backmate_theme_adv_enterprise/static/src/views/form/form_controller.xml @@ -4,7 +4,7 @@ - + diff --git a/web_editor_tinymce/static/src/field_tinymce/field_tinymce.js b/web_editor_tinymce/static/src/field_tinymce/field_tinymce.js index 4acef7c2f..0f971810d 100644 --- a/web_editor_tinymce/static/src/field_tinymce/field_tinymce.js +++ b/web_editor_tinymce/static/src/field_tinymce/field_tinymce.js @@ -1,12 +1,12 @@ /** @odoo-module **/ -import {_t} from '@web/core/l10n/translation'; -import {Component, onWillStart, onMounted, onPatched, onWillUnmount, useEffect} from '@odoo/owl'; -import {standardFieldProps} from '@web/views/fields/standard_field_props'; -import {registry} from '@web/core/registry'; -import {TranslationButton} from '@web/views/fields/translation_button'; -import {loadJS} from '@web/core/assets'; -import {cookie} from '@web/core/browser/cookie'; +import { _t } from '@web/core/l10n/translation'; +import { Component, onWillStart, onMounted, onPatched, onWillUnmount, useEffect } from '@odoo/owl'; +import { standardFieldProps } from '@web/views/fields/standard_field_props'; +import { registry } from '@web/core/registry'; +import { TranslationButton } from '@web/views/fields/translation_button'; +import { loadJS } from '@web/core/assets'; +import { cookie } from '@web/core/browser/cookie'; export class FieldTinyMCE extends Component { static template = 'web_editor_tinymce.TinyMCE'; @@ -15,9 +15,9 @@ export class FieldTinyMCE extends Component { }; static props = { ...standardFieldProps, - placeholder: {type: String, optional: true}, - dynamicPlaceholder: {type: Boolean, optional: true}, - dynamicPlaceholderModelReferenceField: {type: String, optional: true}, + placeholder: { type: String, optional: true }, + dynamicPlaceholder: { type: Boolean, optional: true }, + dynamicPlaceholderModelReferenceField: { type: String, optional: true }, }; static defaultProps = { dynamicPlaceholder: false, @@ -32,7 +32,7 @@ export class FieldTinyMCE extends Component { plugins: 'autoresize preview importcss searchreplace autolink directionality code visualblocks visualchars fullscreen image link media codesample table charmap pagebreak nonbreaking anchor insertdatetime advlist lists wordcount help charmap quickbars emoticons accordion', editimage_cors_hosts: ['picsum.photos'], image_advtab: true, - language:"zh_CN", + language: "zh_CN", importcss_append: true, height: 'auto', image_caption: true, @@ -50,9 +50,13 @@ export class FieldTinyMCE extends Component { }); onMounted(async () => { await this.initEditor(); + this.updateReadonly(); }) useEffect(() => { this.updateEditor(); + if (this.editor) { + this.updateReadonly(); + } }) onWillUnmount(async () => { this.removeEditor() @@ -86,7 +90,7 @@ export class FieldTinyMCE extends Component { editor.on('change', e => { const value = tinymce.activeEditor.getContent(); if (value !== this.value) { - this.props.record.update({[this.props.name]: value}) + this.props.record.update({ [this.props.name]: value }) } }); } @@ -113,14 +117,22 @@ export class FieldTinyMCE extends Component { } this.editor.setContent(this.value); } - + updateReadonly() { + if (this.editor) { + if (this.props.readonly) { + this.editor.mode.set("readonly"); + } else { + this.editor.mode.set("design"); + } + } + } } export const fieldTinyMCE = { component: FieldTinyMCE, displayName: _t('TinyMCE'), supportedTypes: ['html', 'text'], - extractProps: ({attrs, options}) => ({ + extractProps: ({ attrs, options }) => ({ placeholder: attrs.placeholder, dynamicPlaceholder: options?.dynamic_placeholder || false, dynamicPlaceholderModelReferenceField: