(59) 解决在列表视图复制导致打开详细内容

Posted toby2chen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了(59) 解决在列表视图复制导致打开详细内容相关的知识,希望对你有一定的参考价值。

现象:
在列表视图中,当你要复制一个内容,就触发click事件,就打开form视图了
为了区分click mousedown mousemove muuseup 事件,从而放弃click事件
用后面那几个事件组合来解决是要打开,还是复制内容事件

改动代码如下:
\addons\web\static\src\js\view_list.js

var hasMove =false;
        this.$current = $(‘<tbody>‘)
            .delegate(‘input[readonly=readonly]‘, ‘click‘, function (e) {
                /*
                    Against all logic and sense, as of right now @readonly
                    apparently does nothing on checkbox and radio inputs, so
                    the trick of using @readonly to have, well, readonly
                    checkboxes (which still let clicks go through) does not
                    work out of the box. We *still* need to preventDefault()
                    on the event, otherwise the checkbox‘s state *will* toggle
                    on click
                 */
                e.preventDefault();
            })
            .delegate(‘th.oe_list_record_selector‘, ‘click‘, function (e) {
                e.stopPropagation();
                var selection = self.get_selection();
                var checked = $(e.currentTarget).find(‘input‘).prop(‘checked‘);
                $(self).trigger(
                        ‘selected‘, [selection.ids, selection.records, ! checked]);
            })
            .delegate(‘td.oe_list_record_delete button‘, ‘click‘, function (e) {
                e.stopPropagation();
                var $row = $(e.target).closest(‘tr‘);
                $(self).trigger(‘deleted‘, [[self.row_id($row)]]);
            })
            .delegate(‘td.oe_list_field_cell button‘, ‘click‘, function (e) {
                e.stopPropagation();
                var $target = $(e.currentTarget),
                      field = $target.closest(‘td‘).data(‘field‘),
                       $row = $target.closest(‘tr‘),
                  record_id = self.row_id($row);
               
                if ($target.attr(‘disabled‘)) {
                    return;
                }
                $target.attr(‘disabled‘, ‘disabled‘);

                // note: $.data converts data to number if it‘s composed only
                // of digits, nice when storing actual numbers, not nice when
                // storing strings composed only of digits. Force the action
                // name to be a string
                $(self).trigger(‘action‘, [field.toString(), record_id, function (id) {
                    $target.removeAttr(‘disabled‘);
                    return self.reload_record(self.records.get(id));
                }]);
            })
            .delegate(‘a‘, ‘click‘, function (e) {
                e.stopPropagation();
            })
            .delegate(‘tr‘, ‘mousedown‘, function (e) {

                hasMove=false;
            })

            .delegate(‘tr‘, ‘mousemove‘, function (e) {

                hasMove=true;
            })

            .delegate(‘tr‘, ‘mouseup‘, function (e) {
                if (hasMove){

                }else{
                var row_id = self.row_id(e.currentTarget);
                if (row_id) {
                    e.stopPropagation();
                    if (!self.dataset.select_id(row_id)) {
                        throw new Error(_t("Could not find id in dataset"));
                    }
                    self.row_clicked(e);
                }
                }
                hasMove =false;
            });

以上是关于(59) 解决在列表视图复制导致打开详细内容的主要内容,如果未能解决你的问题,请参考以下文章

Odoo12: 列表视图禁止打开表单内容

Django 视图打开不同的内容

列表视图适配器实现

Segue导致黑屏

表视图单元格 - UITableView - 无法在详细视图中显示多行

用于两级详细视图的表视图中的表视图的替代方案