Skip to content
  • Categories
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse

Odoo 中文社区

  1. Home
  2. Categories
  3. Odoo 开发与实施交流
  4. 更改Editable Form里的快捷键(更新v 7.0)

更改Editable Form里的快捷键(更新v 7.0)

Scheduled Pinned Locked Moved Odoo 开发与实施交流
8 Posts 5 Posters 7.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    d_yang
    wrote on last edited by
    #1

    经常听到用户在抱怨OE的回车不好用。原来国产的很多软件里,总是把回车当成TAB用。唉。迎合用户,改。
    打开:
    \addons\web\static\src\js\view_list_editable.js

    找到(大约line169):

    <br />on_row_keyup: function (e) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var self = this;<br />......<br />
    



    动手。
    首先要支持这个:用户在一个输入框回车,跳转到本行的下一个输入框。要考虑输入框的readonly,invisible...
    思路:先数本行总共有多少个可以输入的input, 然后向后select一个。

    <br /><br />on_row_keyup: function (e) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var self = this;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch (e.which) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case KEY_RETURN:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inputs = self.edition_form.$element.find(&#039;input:visible:not(disabled):not([readonly])&#039;)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; idx = $.inArray(e.target, inputs);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(idx &lt; inputs.length-1){<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(&#039;#&#039;+inputs[idx+1].id).select();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.save_row().then(function (result) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (result.created) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.new_record();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br /><br />......<br /><br />
    




    当然,如果到了本行最后一个输入框了,那就执行系统的快捷键,保存本行,跳到下一行吧。

    打完收工。


    以下是为7.0做的改变。

    为了维持用户体验,我还是需要把v7版本的回车快捷键修改一下,使之和v 6.1中一致:

    还是那个文件,line 489,
    (BTW:这个版本支持很多的快捷键,确实提高了用户体验。)

    我们主要修改keyup_ENTER方法:

    <br /><br />keyup_ENTER: function (e) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //return this._next();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var form = this.editor.form;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //找最后一个field<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var last_field = _(form.fields_order).chain()<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .map(function (name) { return form.fields[name]; })<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .filter(function (field) { return field.$el.is(&#039;:visible&#039;); })<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .last()<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .value();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // tabbed from last field in form<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 判断是否换行<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (last_field &amp;&amp; last_field.$el.has(e.target).length) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.preventDefault();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return this._next();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //如果不需要换行,转向下一个输入框。<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var source_field = $(e.target).closest(&#039;[data-fieldname]&#039;)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .attr(&#039;data-fieldname&#039;);<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var fields_order = form.fields_order;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var field_index = _(fields_order).indexOf(source_field);<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var fields = form.fields;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var field;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; do {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (++field_index &gt;= fields_order.length) { return $.when(); }<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; field = fields[fields_order[field_index]];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } while (!field.$el.is(&#039;:visible&#039;));<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; field.focus();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return $.when();<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; },<br />
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrshelly
      wrote on last edited by
      #2

      Good , 鼠标点击事件是哪个呢?

      我发现个问题. 在 6.1 中, 如果一个 tree view 过宽的话,  点击某行的 最后某列的话. 焦点会定位到第一列.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ccdos
        wrote on last edited by
        #3

        高!
        OE 这个输入也让我头疼,我都想用原来的dephi通过xmlrpc 接口做输入了

        1 Reply Last reply
        0
        • W Offline
          W Offline
          wjfonhand
          wrote on last edited by
          #4

          这个可以提交到官方作为一个patch吧

          GoodERP -- Odoo China fork

          1 Reply Last reply
          0
          • D Offline
            D Offline
            d_yang
            wrote on last edited by
            #5

            [quote author=mrshelly link=topic=4205.msg11348#msg11348 date=1339491922]
            Good , 鼠标点击事件是哪个呢?

            我发现个问题. 在 6.1 中, 如果一个 tree view 过宽的话,  点击某行的 最后某列的话. 焦点会定位到第一列.
            [/quote]

            应该是点击什么位置,就编辑什么. 不过估计有点困难. 可以看看这个函数:  render_row_as_form.

            不过想想, 到第一列也没有什么坏处. 😉

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hungriness
              wrote on last edited by
              #6

              这个牛B

              1 Reply Last reply
              0
              • C Offline
                C Offline
                ccdos
                wrote on last edited by
                #7

                强人,再顶.

                其实 回车跳到下个字段, 还有一个 很有用的需求
                ,

                就是实现 tabstop

                1 Reply Last reply
                0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Tags
                • Popular
                • Users
                • Groups