This question has been flagged
1 Reply
9587 Views

Hi Community,


There is a js file called list_view.js in  server/addons/web/static/src/js/views.
Inside of it, we have: 

ListView.List = Class.extend({

    init: function (group, opts) {     

        this.$current = $('<tbody>')

            .delegate('input[readonly=readonly]', 'click', function (e) {

                e.preventDefault();

            })

            .delegate('td.o_list_record_delete', 'click', function (e) {

                e.stopPropagation();

                var $row = $(e.target).closest('tr');

                $(self).trigger('deleted', [[self.row_id($row)]]);

                // IE Edge go crazy when we use confirm dialog and remove the focused element

                if(document.hasFocus && !document.hasFocus()) {

                    $('<input />').appendTo('body').focus().remove();

                }

            })

},

Can you tell me how can i inherit  the listView.List and  add extra code to the .delegate('td.o_list_record_delete', 'click', function (e) {..}  section ? 

Thank you.

Avatar
Discard
Best Answer

Hi Ibrahim, 

You can simply achieve this by extending the list view. First, take an instance of ListView and then you can extend the ListView.List and update the code. I'll paste the sample code below,


// taking the instance of ListView
var ListView = require('web.ListView');

// extending the ListView.List
ListView.List.include({
    init: function(group, opts){
          this._super(group, opts);
          // (add your extra code to delegate(... here.
    }
});


Thanks





Avatar
Discard
Author

Thank you for your reply.

I don't know what's the difference between self._super.apply(self, arguments); AND this._super(group, opts);

I wrote the same code but with the first _super and didn't work until i set the second _super.