Example #1
0
 search: function(domains, contexts, groupbys) {
     var self = this;
     var controller = this.active_view.controller; // the correct view must be loaded here
     var action_context = this.action.context || {};
     var view_context = controller.get_context();
     pyeval.eval_domains_and_contexts({
         domains: [this.action.domain || []].concat(domains || []),
         contexts: [action_context, view_context].concat(contexts || []),
         group_by_seq: groupbys || []
     }).done(function (results) {
         if (results.error) {
             self.active_search.resolve();
             throw new Error(
                     _.str.sprintf(_t("Failed to evaluate search criterions")+": \n%s",
                                   JSON.stringify(results.error)));
         }
         self.dataset._model = new Model(
             self.dataset.model, results.context, results.domain);
         var groupby = results.group_by.length ?
                       results.group_by :
                       action_context.group_by;
         if (_.isString(groupby)) {
             groupby = [groupby];
         }
         if (!controller.grouped && !_.isEmpty(groupby)){
             self.dataset.set_sort([]);
         }
         $.when(controller.do_search(results.domain, results.context, groupby || [])).then(function() {
             self.active_search.resolve();
         });
     });
 },
Example #2
0
    open: function () {
        if (this.options.initial_view !== "search") {
            return this.create_edit_record();
        }
        var self = this;
        var user_context = this.getSession().user_context;

        var _super = this._super.bind(this);
        var context = pyeval.eval_domains_and_contexts({
            domains: [],
            contexts: [user_context, this.context]
        }).context;
        var search_defaults = {};
        _.each(context, function (value_, key) {
            var match = /^search_default_(.*)$/.exec(key);
            if (match) {
                search_defaults[match[1]] = value_;
            }
        });
        this.loadViews(this.dataset.model, this.dataset.get_context().eval(), [[false, 'list'], [false, 'search']], {})
            .then(this.setup.bind(this, search_defaults))
            .then(function (fragment) {
                self.opened().then(function () {
                    dom.append(self.$el, fragment, {
                        callbacks: [{widget: self.list_controller}],
                        in_DOM: true,
                    });
                    self.set_buttons(self.__buttons);
                });
                _super();
            });
        return this;
    },
Example #3
0
 _process_search_data: function(domains, contexts, groupbys) {
     // var controller = this.active_view.controller; // the correct view must be loaded here
     var action_context = this.action.context || {};
     var view_context = {}; //controller.get_context();
     var results = pyeval.eval_domains_and_contexts({
         domains: [this.action.domain || []].concat(domains || []),
         contexts: [action_context, view_context].concat(contexts || []),
         group_by_seq: groupbys || [],
         eval_context: this.getSession().user_context,
     });
     if (results.error) {
         throw new Error(_.str.sprintf(_t("Failed to evaluate search criterions")+": \n%s",
                         JSON.stringify(results.error)));
     }
     // this.dataset._model = new Model(this.dataset.model, results.context, results.domain);
     // var groupby = results.group_by.length ? results.group_by : action_context.group_by;
     // if (_.isString(groupby)) {
     //     groupby = [groupby];
     // }
     // if (!controller.grouped && !_.isEmpty(groupby)){
     //     this.dataset.set_sort([]);
     // }
     return {
         context: results.context,
         domain: results.domain,
         groupBy: results.group_by,
     };
 },
Example #4
0
 save_favorite: function () {
     var self = this,
         filter_name = this.$inputs[0].value,
         default_filter = this.$inputs[1].checked,
         shared_filter = this.$inputs[2].checked;
     if (!filter_name.length){
         this.do_warn(_t("Error"), _t("Filter name is required."));
         this.$inputs.first().focus();
         return;
     }
     if (_.chain(this.filters)
             .pluck('name')
             .contains(filter_name).value()) {
         this.do_warn(_t("Error"), _t("Filter with same name already exists."));
         this.$inputs.first().focus();
         return;
     }
     var user_context = this.getSession().user_context;
     var search = this.searchview.build_search_data();
     var view_manager = this.findAncestor(function (a) {
             // HORRIBLE HACK. PLEASE SAVE ME FROM MYSELF (BUT IN A PAINLESS WAY IF POSSIBLE)
             return 'active_view' in a;
         });
     var view_context = view_manager ? view_manager.active_view.controller.get_context() : {};
     var results = pyeval.eval_domains_and_contexts({
             domains: search.domains,
             contexts: [user_context].concat(search.contexts.concat(view_context || [])),
             group_by_seq: search.groupbys || [],
         });
     if (!_.isEmpty(results.group_by)) {
         results.context.group_by = results.group_by;
     }
     // Don't save user_context keys in the custom filter, otherwise end
     // up with e.g. wrong uid or lang stored *and used in subsequent
     // reqs*
     var ctx = results.context;
     _(_.keys(session.user_context)).each(function (key) {
         delete ctx[key];
     });
     var filter = {
         name: filter_name,
         user_id: shared_filter ? false : session.uid,
         model_id: this.target_model,
         context: results.context,
         domain: results.domain,
         is_default: default_filter,
         action_id: this.action_id,
     };
     return data_manager.create_filter(filter).done(function (id) {
         filter.id = id;
         self.toggle_save_menu(false);
         self.$save_name.find('input').val('').prop('checked', false);
         self.add_filter(filter);
         self.append_filter(filter);
         self.toggle_filter(filter, true);
     });
 },
Example #5
0
    _onSearch: function (search_event) {
        var session = this.getSession();
        // group by are disabled, so we don't take care of them
        var result = pyeval.eval_domains_and_contexts({
            domains: search_event.data.domains,
            contexts: [session.user_context].concat(search_event.data.contexts)
        });

        this._fetchPlan(result.domain);
    },
Example #6
0
 _process_search_data: function (domains, contexts, groupbys) {
     var results = pyeval.eval_domains_and_contexts({
         domains: [this.domain].concat(domains),
         contexts: [this.context].concat(contexts),
         group_by_seq: groupbys || []
     });
     return {
         context: results.context,
         domain: results.domain,
         groupBy: results.group_by,
     };
 },
Example #7
0
 _process_search_data: function (domains, contexts, groupbys) {
     var results = pyeval.eval_domains_and_contexts({
         domains: [this.domain].concat(domains),
         contexts: [this.context].concat(contexts),
         group_by_seq: groupbys || [],
         eval_context: this.getSession().user_context,
     });
     var context = _.omit(results.context, function (value, key) { return key.indexOf('search_default_') === 0; });
     return {
         context: context,
         domain: results.domain,
         groupBy: results.group_by,
     };
 },
Example #8
0
 on_search: function(domains, contexts, groupbys){
     var self = this;
     return pyeval.eval_domains_and_contexts({
         domains: [[]].concat(domains || []),
         contexts: [this.context].concat(contexts || []),
         group_by_seq: groupbys || []
     }).done(function(results){
         if (results.error) {
             throw new Error(_.str.sprintf(_t("Failed to evaluate search criterions")+": \n%s", JSON.stringify(results.error)));
         }
         // modify the search domain and do search
         self.search_domain = results.domain;
         return self.message_load_new();
     });
 },
Example #9
0
 _onSearch: function (event) {
     event.stopPropagation();
     var session = this.getSession();
     var result = pyeval.eval_domains_and_contexts({
         domains: event.data.domains,
         contexts: [session.user_context],
     });
     this.domain = result.domain;
     if (this.channel) {
         // initially (when _onSearch is called manually), there is no
         // channel set yet, so don't try to fetch and render the thread as
         // this will be done as soon as the default channel is set
         this._fetchAndRenderThread();
     }
 },
Example #10
0
 getActiveDomain: function () {
     // TODO: this method should be synchronous...
     var self = this;
     if (this.$('thead .o_list_record_selector input').prop('checked')) {
         var searchView = this.getParent().searchview; // fixme
         var searchData = searchView.build_search_data();
         var userContext = this.getSession().user_context;
         var results = pyeval.eval_domains_and_contexts({
             domains: searchData.domains,
             contexts: [userContext].concat(searchData.contexts),
             group_by_seq: searchData.groupbys || []
         });
         return $.when(self.dataset.domain.concat(results.domain || []));
     } else {
         return $.Deferred().resolve();
     }
 },