富文本修复,index问题修复

This commit is contained in:
夜未央
2025-09-09 00:05:13 +08:00
parent c021d0eb82
commit f357294b7a
5 changed files with 48 additions and 47 deletions
@@ -54,7 +54,7 @@
}
thead {
z-index: 20 !important;
z-index: 2 !important;
}
thead .o_filter_box .o_column_freeze {
@@ -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
}
},
@@ -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() {
@@ -4,7 +4,7 @@
<xpath expr="//Layout/t[@t-set-slot='control-panel-create-button'][2]" position="inside">
<!-- edit by Lucky 20250714:增加buttonState.showEditButton -->
<t t-if="!canEdit and !model.root.isInEdition and buttonState.showEditButton">
<t t-if="!model.root.isInEdition and buttonState.showEditButton">
<button type="button" class="btn btn-outline-primary o_form_button_edit" t-on-click="edit" data-hotkey="a">编辑</button>
</t>
<t t-if="model.root.isInEdition">
@@ -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: