0

The default behaviour of the discuss module in Odoo 9 is:

  • Last message at the bottom
  • Scrollbar at the bottom

I need to change this behaviour to:

  • Last message on top
  • Scrollbar on top

I think all this can be changed in odoo/addons/mail/static/src/js/thread.js The order of messages is changed with:

init: function (parent, options) {
    this._super.apply(this, arguments);
    this.options = _.defaults(options || {}, {
        //display_order: ORDER.ASC,
        display_order: ORDER.DESC,
        display_needactions: true,
        display_stars: true,
        display_document_link: true,
        display_avatar: true,
        shorten_messages: true,
        squash_close_messages: true,
        display_reply_icon: false,
    });
    this.expanded_msg_ids = [];
    this.selected_id = null;
},

But then the user always has to scroll up so I also need to modify the behaviour of the scrollbar.

In this thread: Set scroll position I found it could be done with:

window.scrollTo(0, 0); // values are x,y-offset

or

var el = document.getElementById("myel"); // Or whatever method to get the element

// To set the scroll
el.scrollTop = 0;
el.scrollLeft = 0;

This is some code I found in odoo/addons/mail/static/src/js/thread.js:

    /**
     * Scrolls the thread to a given message or offset if any, to bottom otherwise
     * @param {int} [options.id] optional: the id of the message to scroll to
     * @param {int} [options.offset] optional: the number of pixels to scroll
     */
    scroll_to: function (options) {
    window.alert("In function scroll_to");
        options = options || {};
        if (options.id !== undefined) {
            var $target = this.$('.o_thread_message[data-message-id=' + options.id + ']');
            if (options.only_if_necessary) {
                var delta = $target.parent().height() - $target.height();
                var offset = delta < 0 ? 0 : delta - ($target.offset().top - $target.offsetParent().offset().top);
                offset = - Math.min(offset, 0);
                this.$el.scrollTo("+=" + offset + "px", options);
            } else if ($target.length) {
                this.$el.scrollTo($target);
            }
        } else if (options.offset !== undefined) {
            this.$el.scrollTop(options.offset);
        } else {
        window.alert("55555555555");
        window.alert("55555555555" + this.el.scrollHeight);
            //this.$el.scrollTop(this.el.scrollHeight);
            this.$el.scrollTop(20);
        }
    },
    get_scrolltop: function () {
        return this.$el.scrollTop();
    },
    is_at_bottom: function () {
    window.alert("777777777777777");
        return this.el.scrollHeight - this.$el.scrollTop() - this.$el.outerHeight() < 5;
    },
    unselect: function () {
        this.$('.o_thread_message').removeClass('o_thread_selected_message');
        this.selected_id = null;
    },
});

I've put some alertboxes to see what happens when the page is loaded. It seems it goes straight to the part with "5555555". I've tried some changes there to adjust the scrollbar but nothing happens.

Does anyone have an idea on how to get the scrollbar on top as default?

RobbeM
  • 727
  • 7
  • 16
  • 36

2 Answers2

0

Hi: Last message on top you can see this page:

Change message order in discuss odoo 9

I have test it at Odoo10 And it run well:

display_order set as DESC

init: function (parent, options) {
    this._super.apply(this, arguments);
    this.options = _.defaults(options || {}, {
        display_order: ORDER.DESC,

},
zhanghao
  • 1
  • 2
0

through an friend's Help,Now I'm OK share the code :

scroll_to: function (options) {
    options = options || {};
    if (options.id !== undefined) {
        var $target = this.$('.o_thread_message[data-message-id="' + options.id + '"]');
        if (options.only_if_necessary) {
            var delta = $target.parent().height() - $target.height();
            var offset = delta < 0 ? 0 : delta - ($target.offset().top - $target.offsetParent().offset().top);
            offset = - Math.min(offset, 0);
            this.$el.scrollTo("+=" + offset + "px", options);
        } else if ($target.length) {
            this.$el.scrollTo($target);
        }
    } else if (options.offset !== undefined) {
        this.$el.scrollTop(options.offset);
    } else {
        // this.$el.scrollTop(this.el.scrollHeight);
        this.$el.scrollTop();
        console.log("flag 4");
    }
},
zhanghao
  • 1
  • 2