[英]How to add WYSIWYG on portal website odoo13
I want to add WYSIWYG HTML to the Odoo 13 website portal by using the following this tutorial , but the WYSIWYG display that I have tried only displays a loading screen so that it cannot be inputted with text.我想通过使用以下本教程将所见即所得 HTML 添加到 Odoo 13 网站门户,但我尝试过的所见即所得显示器仅显示加载屏幕,因此无法输入文本。 is there anything missing?
有什么遗漏吗?
XML code: XML 代码:
<template id="portal_my_details_sl_elrn" inherit_id="portal.portal_my_details">
<xpath expr="//form/div/div/div/div[3]" position="before">
<div t-attf-class="form-group #{error.get('about_me') and 'o_has_error' or ''} col-xs-12">
<!-- <label class="col-form-label" for="about_me">About Me</label> -->
<label class="col-form-label" for="about_me">About Me</label>
<textarea name="about_me" id="about_me" class="form-control o_wysiwyg_loader">
<!-- <t t-esc="about_me"/> -->
<input name="about_me" t-attf-class="form-control #{error.get('about_me') and 'is-invalid' or ''}"
t-att-value="about_me or partner.about_me"/>
</textarea>
</div>
</xpath>
</template>
In addition to the code you posted, you can add website_profile
to your module depends
and add o_wprofile_editor_form
class to the form
.除了您发布的代码之外,您还可以将
website_profile
添加到您的模块depends
中,并将o_wprofile_editor_form
class 添加到form
中。
<xpath expr="//form" position="attributes">
<attribute name="class">o_wprofile_editor_form</attribute>
</xpath>
Or you can add the javascript website profile editor code to website.assets_frontend
instead of installing website_profile
.或者您可以将 javascript 网站配置文件编辑器代码添加到
website.assets_frontend
而不是安装website_profile
。
<template id="assets_frontend" inherit_id="website.assets_frontend">
<xpath expr="script[last()]" position="after">
<script type="text/javascript" src="/module_name/static/src/js/custom_editor.js"></script>
</xpath>
</template>
The following code can be found in website_profile static folder.以下代码可在website_profile static 文件夹中找到。
var publicWidget = require('web.public.widget');
var wysiwygLoader = require('web_editor.loader');
publicWidget.registry.websiteProfileEditor = publicWidget.Widget.extend({
selector: '.o_wprofile_editor_form',
read_events: {
'click .o_forum_profile_pic_edit': '_onEditProfilePicClick',
'change .o_forum_file_upload': '_onFileUploadChange',
'click .o_forum_profile_pic_clear': '_onProfilePicClearClick',
'click .o_wprofile_submit_btn': '_onSubmitClick',
},
/**
* @override
*/
start: function () {
var def = this._super.apply(this, arguments);
if (this.editableMode) {
return def;
}
var $textarea = this.$('textarea.o_wysiwyg_loader');
var loadProm = wysiwygLoader.load(this, $textarea[0], {
recordInfo: {
context: this._getContext(),
res_model: 'res.users',
res_id: parseInt(this.$('input[name=user_id]').val()),
},
}).then(wysiwyg => {
this._wysiwyg = wysiwyg;
});
return Promise.all([def, loadProm]);
},
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
/**
* @private
* @param {Event} ev
*/
_onEditProfilePicClick: function (ev) {
ev.preventDefault();
$(ev.currentTarget).closest('form').find('.o_forum_file_upload').trigger('click');
},
/**
* @private
* @param {Event} ev
*/
_onFileUploadChange: function (ev) {
if (!ev.currentTarget.files.length) {
return;
}
var $form = $(ev.currentTarget).closest('form');
var reader = new window.FileReader();
reader.readAsDataURL(ev.currentTarget.files[0]);
reader.onload = function (ev) {
$form.find('.o_forum_avatar_img').attr('src', ev.target.result);
};
$form.find('#forum_clear_image').remove();
},
/**
* @private
* @param {Event} ev
*/
_onProfilePicClearClick: function (ev) {
var $form = $(ev.currentTarget).closest('form');
$form.find('.o_forum_avatar_img').attr('src', '/web/static/src/img/placeholder.png');
$form.append($('<input/>', {
name: 'clear_image',
id: 'forum_clear_image',
type: 'hidden',
}));
},
/**
* @private
*/
_onSubmitClick: function () {
if (this._wysiwyg) {
this._wysiwyg.save();
}
},
});
Edit:编辑:
We need to call _onSubmitClick
on form submit, add o_wprofile_submit_btn
class to the submit button:我们需要在表单提交上调用
_onSubmitClick
,在提交按钮上添加o_wprofile_submit_btn
class:
<xpath expr="//button[@type='submit']" position="attributes">
<attribute name="class">btn btn-primary o_wprofile_submit_btn</attribute>
</xpath>
Edit: unknown field 'files'编辑:未知字段“文件”
The widget adds an input names files
which is passed to the controller and when you click on Confirm
button, details_form_validate
method is called to check if keys present in data
(post) are also in MANDATORY_BILLING_FIELDS
or in OPTIONAL_BILLING_FIELDS
.该小部件添加了一个输入名称
files
,该文件传递给 controller 并且当您单击Confirm
按钮时,会调用details_form_validate
方法来检查data
(帖子)中存在的键是否也在MANDATORY_BILLING_FIELDS
或OPTIONAL_BILLING_FIELDS
中。
I suppose you are not using files
field ( it is not declared in BILLING_FIELDS
), to avoid the warning try to bypass verification:我想您没有使用
files
字段(未在BILLING_FIELDS
中声明),以避免警告尝试绕过验证:
from odoo.addons.portal.controllers.portal import CustomerPortal
class CustomerPortalNew(CustomerPortal):
def details_form_validate(self, data):
files = data.pop('files', None)
res = super(CustomerPortalNew, self).details_form_validate(data)
data['files'] = files
return res
Fix Code:修复代码:
res_partner.py res_partner.py
from odoo import api, models, fields, _
class ResPartner(models.Model):
_inherit = 'res.partner'
about_me = fields.Html('About Me')
portal.py门户.py
from odoo.http import Controller
from odoo.addons.portal.controllers.portal import CustomerPortal
CustomerPortal.OPTIONAL_BILLING_FIELDS.append('about_me')
class CustomerPortalNew(CustomerPortal):
def details_form_validate(self, data):
files = data.pop('files', None)
res = super(CustomerPortalNew, self).details_form_validate(data)
data['files'] = files
return res
portal_templates.xml门户模板.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_frontend" inherit_id="website.assets_frontend">
<xpath expr="script[last()]" position="after">
<script type="text/javascript" src="/sl_elrn/static/src/js/website_profile.js"></script>
</xpath>
</template>
<template id="portal_my_details_sl_elrn" inherit_id="portal.portal_my_details">
<xpath expr="//form" position="attributes">
<attribute name="class">o_wprofile_editor_form</attribute>
</xpath>
<xpath expr="//form/div/div/div/div[3]" position="before">
<div t-attf-class="form-group #{error.get('about_me') and 'o_has_error' or ''} col-xl-12">
<label class="col-form-label" for="about_me">About Me</label>
<textarea name="about_me" id="about_me" style="min-height: 120px" class="form-control o_wysiwyg_loader">
<t t-esc="about_me or partner.about_me"/>
</textarea>
</div>
</xpath>
<xpath expr="//button[@type='submit']" position="attributes">
<attribute name="class">btn btn-primary o_wprofile_submit_btn</attribute>
</xpath>
</template>
</odoo>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.