0
votes

I want to modify this line self.drawer.toggle(e === 'graph') by self.drawer.toggle(e !== 'form') of the method "start" of this class:

instance.web.SearchView = instance.web.Widget.extend({
    template: "SearchView",
    start: function() {
        var self = this;
        var p = this._super();
        this.$view_manager_header = this.$el.parents(".oe_view_manager_header").first();
        this.setup_global_completion();
        this.query = new my.SearchQuery()
                .on('add change reset remove', this.proxy('do_search'))
                .on('change', this.proxy('renderChangedFacets'))
                .on('add reset remove', this.proxy('renderFacets'));
        if (this.options.hidden) {
            this.$el.hide();
        }
        if (this.headless) {
            this.ready.resolve();
        } else {
            var load_view = instance.web.fields_view_get({
                model: this.dataset._model,
                view_id: this.view_id,
                view_type: 'search',
                context: this.dataset.get_context(),
            });

            this.alive($.when(load_view)).then(function (r) {
                self.fields_view_get.resolve(r);
                return self.search_view_loaded(r);
            }).fail(function () {
                self.ready.reject.apply(null, arguments);
            });
        }
        var view_manager = this.getParent();
        while (!(view_manager instanceof instance.web.ViewManager) &&
                view_manager && view_manager.getParent) {
            view_manager = view_manager.getParent();
        }
        if (view_manager) {
            this.view_manager = view_manager;
            view_manager.on('switch_mode', this, function (e) {
                self.drawer.toggle(e === 'graph');
            });
        }
        return $.when(p, this.ready);
    },

Have I to overwrite all lines in my new class or is there another way?

1

1 Answers

0
votes

I would suggest that the best idea would be to allow your class's constructor to that name as an argument.

I'm not familiar with the library you're using, but in terms of classical inheritance your class would look like this.

class SearchView extends Widget {
  constructor(name='graph') {
    this.name = name;

    view_manager.on('switch_mode', this, function (e) {
      self.drawer.toggle(e === this.name);
    });
  }
}

By default this would create instances that used 'graph', if you wanted an instance that used 'form' instead, then you would do the following:

var searchView = new SearchView('form');

You wouldn't need to subclass it.