跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • 浅色
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • 深色
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 开发与实施交流
  4. [分享]buke 分享的一个关于自定义 widget 的例子.

[分享]buke 分享的一个关于自定义 widget 的例子.

已定时 已固定 已锁定 已移动 Odoo 开发与实施交流
8 帖子 7 发布者 11.5k 浏览 1 关注中
  • 从旧到新
  • 从新到旧
  • 最多赞同
回复
  • 在新帖中回复
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • M 离线
    M 离线
    mrshelly
    发表于 最后由 编辑
    #1

    先看看最终效果:
    Page 页效果:
    [attachimg=1]
    编辑页效果:
    [attachimg=2]

    相关 view xml:

    <br />....<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;website&quot; position=&quot;after&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;qq&quot; widget=&quot;qq&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/field&gt;<br />....<br />
    



    模块核心文件结构:
    openerp.py
    static/src/js/web_qq_widget.js
    static/src/xml/web_qq_widget.xml

    openerp.py 文件:

    <br />....<br />{<br />&nbsp; &nbsp; &#039;name&#039;: &#039;rundex&#039;,<br />&nbsp; &nbsp; &#039;version&#039;: &#039;0.1&#039;,<br />&nbsp; &nbsp; &#039;category&#039;: &#039;Sales Management&#039;,<br />&nbsp; &nbsp; &#039;description&#039;: &quot;&quot;&quot;<br />....<br />&nbsp; &nbsp; &#039;js&#039;: [<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;static/src/js/*.js&#039;,<br />&nbsp; &nbsp; ],<br />&nbsp; &nbsp; &#039;css&#039;: [<br />&nbsp; &nbsp; ],<br />&nbsp; &nbsp; &#039;qweb&#039;: [<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;static/src/xml/*.xml&#039;,<br />&nbsp; &nbsp; ],<br />....<br />
    



    web_qq_widget.xml 文件:

    <br />....<br />&lt;template&gt;<br />&nbsp; &nbsp; &lt;t t-name=&quot;QqWidget&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;span class=&quot;oe_form_field oe_form_field_url&quot; t-att-style=&quot;widget.node.attrs.style&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;span class=&quot;oe_form_qq&quot; t-if=&quot;widget.get(&#039;effective_readonly&#039;)&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;a href=&quot;#&quot; class=&quot;oe_form_uri&quot; target=&quot;_blank&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;span class=&quot;qq_number&quot;&gt;&lt;/span&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/span&gt;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;t t-if=&quot;!widget.get(&#039;effective_readonly&#039;)&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;text&quot; t-att-id=&quot;widget.id_for_label&quot; t-att-tabindex=&quot;widget.node.attrs.tabindex&quot; t-att-autofocus=&quot;widget.node.attrs.autofocus&quot; t-att-placeholder=&quot;widget.node.attrs.placeholder&quot; t-att-maxlength=&quot;widget.field.size&quot; /&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/t&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/span&gt;<br />&nbsp; &nbsp; &lt;/t&gt;<br />&lt;/template&gt;<br />....<br />
    



    web_qq_widget.js 文件:

    <br />....<br />openerp.rundex = function(instance){<br />&nbsp; &nbsp; var _t = instance.web._t, _lt = instance.web._lt;<br />&nbsp; &nbsp; var QWeb = instance.web.qweb;<br />&nbsp; &nbsp; instance.web.form.widgets.add(&#039;qq&#039;, &#039;instance.rundex.QqWidget&#039;);<br />&nbsp; &nbsp; instance.rundex.QqWidget = instance.web.form.FieldChar.extend({<br />&nbsp; &nbsp; &nbsp; &nbsp; display_name : _lt(&#039;QqWidget&#039;),<br />&nbsp; &nbsp; &nbsp; &nbsp; template: &quot;QqWidget&quot;,<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; render_value: function(){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!this.get(&quot;effective_readonly&quot;)){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this._super();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (this.get(&#039;value&#039;)){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.$el.find(&#039;a&#039;).attrs(&#039;href&#039;, &#039;http://wpa.qq.com/msgrd?v=3&amp;uid=&#039; + this.get(&#039;value&#039;) + &#039;&amp;site=qq&amp;menu=yes&#039;).html(&#039;&lt;img border=&quot;0&quot; src=&quot;http://pub.idqqimg.com/wpa/images/counseling_style_52.png&quot; alt=&quot;&#039; + this.get(&#039;value&#039;) + &#039;&quot; title=&quot;&#039; +this.get(&#039;value&#039;) + &#039;&quot;/&gt;&#039;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.$el.find(&quot;.qq_number&quot;).text(this.get(&#039;value&#039;));<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.$el.find(&#039;a&#039;).attr(&#039;href&#039;, &#039;#&#039;).html(&#039;&#039;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.$el.find(&quot;.qq_number&quot;).text();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; },<br />&nbsp; &nbsp; });<br />};<br />....<br />
    




    注: rundex 为模块名
    模板文件中注意:  t-if="widget.get('effective_readonly')"  effective_readonly = true 表示编辑状态

    特此感谢 buke(广州-步科) 同学的分享.. 大家鼓掌...

    1 条回复 最后回复
    0
    • JoshuaJ 离线
      JoshuaJ 离线
      Joshua
      管理员
      发表于 最后由 编辑
      #2

      鼓掌,谢谢buke,谢谢shelly

      【上海先安科技】(joshua AT openerp.cn),欢迎关注公众号:openerp_cn

      1 条回复 最后回复
      0
      • B 离线
        B 离线
        baialaps
        发表于 最后由 编辑
        #3

        哈哈,感觉buke && 感谢总监

        1 条回复 最后回复
        0
        • C 离线
          C 离线
          ccdos
          发表于 最后由 编辑
          #4

          鼓掌

          1 条回复 最后回复
          0
          • O 离线
            O 离线
            oldrev
            发表于 最后由 编辑
            #5

            赞一个,确实不错呢

            1 条回复 最后回复
            0
            • W 离线
              W 离线
              wangbuke
              发表于 最后由 编辑
              #6

              总监辛苦了,多谢各位捧场 ~

              代码整理了下,做成了2个小模块,请大家笑纳

              https://github.com/buke/openerp-custom-widget-qq

              1 条回复 最后回复
              0
              • D 离线
                D 离线
                digitalsatori
                管理员
                发表于 最后由 编辑
                #7

                谢谢 步科, 谢谢总监

                【上海先安科技】(tony AT openerp.cn)

                1 条回复 最后回复
                0

                你好!看起来您对这段对话很感兴趣,但您还没有一个账号。

                厌倦了每次访问都刷到同样的帖子?您注册账号后,您每次返回时都能精准定位到您上次浏览的位置,并可选择接收新回复通知(通过邮件或推送通知)。您还能收藏书签、为帖子顶,向社区成员表达您的欣赏。

                有了你的建议,这篇帖子会更精彩哦 💗

                注册 登录
                回复
                • 在新帖中回复
                登录后回复
                • 从旧到新
                • 从新到旧
                • 最多赞同


                • 登录

                • 没有帐号? 注册

                • 登录或注册以进行搜索。
                • 第一个帖子
                  最后一个帖子
                0
                • 版块
                • 标签
                • 热门
                • 用户
                • 群组