Odoo Website 替換 Summernote 為第三方富文本編輯器


隨着用odoo的人越來越多,奇葩的需求也是越來越多。。。。

這不,有同學就想替換掉website forum里邊的summernote控件,花了點時間研究了一下,先說結論:替換是可行的。

 

先上替換之后的圖,這里替換的是kindeditor:

 

 

要替換成別的,也是可以的,只不過需要使用odoo的前端開發規則,本模塊計划做成一個demo供參考。

替換步驟:

1. 首先將kindeditor的源文件引入到新模塊中

2. 將原來的summernote空間隱藏掉,並用kindeditor替代:

$('textarea.load_editor').each(function () {
        var $textarea = $(this);
        var $form = $textarea.closest('form');

        $('.note-editor').hide();
        KindEditor.ready(function(K){            
            window.editor=K.create($textarea,{
                themeType:'default',
                uploadJson : '/filemanager',
                fileManagerJson : '/filemanager',
                allowFileManager : true,
            })
        });

        $form.on('click', 'button, .a-submit', function () {
            window.editor.sync();
            window.editor.html($textarea.val());
        });
    });

3. 你會發現雖然引用了新的控件,但是樣式在提交后都消失不見了。。。。

解決方法:設置content字段的strip_style屬性為false

4. 最后我們來解決圖片上傳的問題:

@http.route('/filemanager',type='http',auth="public",website=True,csrf=False)
    def _store_file(self,*args,**kwargs):
        img = kwargs['imgFile']
        path = os.path.abspath(os.path.realpath(__file__)).split('controller')[0]+'static/files'
        #os.path.abspath(join(os.getcwd(),'/web_kindeditor/static/files'))
        filepath = path+'/'+img.filename
        img.save(filepath)
        url = request.env['ir.config_parameter'].get_param('web.base.url')+"/web_kindeditor/static/files/"+img.filename
        return json.dumps({'error':0,'url':url})

5. 9.0 以后web url訪問會有csrf驗證的問題,這就是另外一回事兒了,有空再說。

Over。

模塊共享地址依舊見群公告。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM