}
instance.web.form.DashBoard = instance.web.form.FormWidget.extend({
+ events: {
+ 'click .oe_dashboard_link_reset': 'on_reset',
+ 'click .oe_dashboard_link_change_layout': 'on_change_layout',
+ 'click h2.oe_header span.oe_header_txt': function (ev) {
+ if(ev.target === ev.currentTarget)
+ self.on_header_string($(ev.target).parent());
+ },
+ 'click .oe_dashboard_column .oe_fold': 'on_fold_action',
+ 'click .oe_dashboard_column .oe_close': 'on_close_action',
+ },
init: function(view, node) {
this._super(view, node);
this.form_template = 'DashBoard';
var old_title = this.__parentedParent.get('title');
this.__parentedParent.on('load_record', self, function(){
self.__parentedParent.set({ 'title': old_title});
- })
- // Events
- this.$('.oe_dashboard_link_reset').click(this.on_reset);
- this.$('.oe_dashboard_link_change_layout').click(this.on_change_layout);
- this.$('h2.oe_header span.oe_header_txt').click(function(ev){
- if(ev.target === ev.currentTarget)
- self.on_header_string($(ev.target).parent());
});
- this.$el.delegate('.oe_dashboard_column .oe_fold', 'click', this.on_fold_action);
- this.$el.delegate('.oe_dashboard_column .oe_close', 'click', this.on_close_action);
// Init actions
_.each(this.node.children, function(column, column_index) {
var self = this;
this._super(filters);
this.$('.favorites-menu').append(QWeb.render('SearchView.addtodashboard'));
- this.$add_to_dashboard = this.$('.add-to-dashboard');
- this.$add_dashboard_btn = this.$add_to_dashboard.eq(2).find('button');
- this.$add_dashboard_input = this.$add_to_dashboard.eq(1).find('input');
- this.$add_dashboard_link = this.$add_to_dashboard.first().find('a');
+ var $add_to_dashboard = this.$('.add-to-dashboard');
+ this.$add_dashboard_btn = $add_to_dashboard.eq(2).find('button');
+ this.$add_dashboard_input = $add_to_dashboard.eq(1).find('input');
+ this.$add_dashboard_link = $add_to_dashboard.first().find('a');
var title = this.searchview.getParent().title;
this.$add_dashboard_input.val(title);
this.$add_dashboard_link.click(function () {
this.$add_dashboard_btn.click(this.proxy('add_dashboard'));
},
toggle_dashboard_menu: function (is_open) {
- this.$add_to_dashboard.first()
+ this.$add_dashboard_link
.toggleClass('closed-menu', !is_open)
.toggleClass('open-menu', is_open);
this.$add_dashboard_btn.toggle(is_open);
this.$add_dashboard_input.toggle(is_open);
- if (this.$add_to_dashboard.first().hasClass('open-menu')) {
+ if (this.$add_dashboard_link.hasClass('open-menu')) {
this.$add_dashboard_input.focus();
}
},
this._super();
},
add_dashboard: function () {
- var self = this;
- var view_manager = this.getParent();
- while (!(view_manager instanceof instance.web.ViewManager) &&
- view_manager && view_manager.getParent) {
- view_manager = view_manager.getParent();
- }
+ var self = this,
+ view_manager = this.findAncestor(function (a) {
+ return a instanceof instance.web.ViewManager
+ });
if (!view_manager.action) {
this.do_warn(_t("Can't find dashboard action"));
return;
name: name,
});
}).then(function (r) {
- if (r === false) {
- self.do_warn(_t("Could not add filter to dashboard"));
+ if (r) {
+ self.do_notify(_.str.sprintf(_t("'%s' added to dashboard"), name), '');
} else {
- self.do_notify(_t("'"+name + "' added to dashboard"), '');
+ self.do_warn(_t("Could not add filter to dashboard"));
}
});
},
openerp.google_spreadsheet = function(instance) {
var _t = instance.web._t,
- QWeb = instance.web.qweb;
+ QWeb = instance.web.qweb;
instance.web.FormView.include({
- on_processed_onchange: function(result, processed) {
- var self = this;
- var fields = self.fields;
- _(result.selection).each(function (selection, fieldname) {
- var field = fields[fieldname];
- if (!field) { return; }
- field.field.selection = selection;
- field.values = selection;
- field.renderElement();
- });
- return this._super(result, processed);
- },
+ on_processed_onchange: function(result, processed) {
+ var self = this;
+ var fields = self.fields;
+ _(result.selection).each(function (selection, fieldname) {
+ var field = fields[fieldname];
+ if (!field) { return; }
+ field.field.selection = selection;
+ field.values = selection;
+ field.renderElement();
+ });
+ return this._super(result, processed);
+ },
});
instance.web.search.FavoriteMenu.include({
- prepare_dropdown_menu: function (filters) {
- this._super(filters);
- this.$('.favorites-menu').append(QWeb.render('SearchView.addtogooglespreadsheet'));
- this.$('.add-to-spreadsheet').click(this.add_to_spreadsheet.bind(this));
- },
- add_to_spreadsheet: function () {
- var data = this.searchview.build_search_data(),
- model = this.searchview.dataset.model,
- view_manager = this.searchview.getParent(),
- list_view = view_manager.views.list,
- list_view_id = list_view ? list_view.view_id : false,
- context = this.searchview.dataset.get_context() || [],
- domain = this.searchview.dataset.get_domain() || [],
- compound_context = new instance.web.CompoundContext(context),
- compound_domain = new instance.web.CompoundDomain(context),
- groupbys = instance.web.pyeval.eval('groupbys', data.groupbys).join(" "),
- ds = new instance.web.DataSet(this, 'google.drive.config');
+ prepare_dropdown_menu: function (filters) {
+ this._super(filters);
+ this.$('.favorites-menu').append(QWeb.render('SearchView.addtogooglespreadsheet'));
+ this.$('.add-to-spreadsheet').click(this.add_to_spreadsheet.bind(this));
+ },
+ add_to_spreadsheet: function () {
+ var data = this.searchview.build_search_data(),
+ model = this.searchview.dataset.model,
+ view_manager = this.searchview.getParent(),
+ list_view = view_manager.views.list,
+ list_view_id = list_view ? list_view.view_id : false,
+ context = this.searchview.dataset.get_context() || [],
+ domain = this.searchview.dataset.get_domain() || [],
+ compound_context = new instance.web.CompoundContext(context),
+ compound_domain = new instance.web.CompoundDomain(context),
+ groupbys = instance.web.pyeval.eval('groupbys', data.groupbys).join(" "),
+ ds = new instance.web.DataSet(this, 'google.drive.config');
- _.each(data.contexts, compound_context.add, compound_context);
- _.each(data.domains, compound_domain.add, compound_domain);
+ _.each(data.contexts, compound_context.add, compound_context);
+ _.each(data.domains, compound_domain.add, compound_domain);
- compound_domain = JSON.stringify(compound_domain.eval());
- console.log('add_to_spreadsheet');
+ compound_domain = JSON.stringify(compound_domain.eval());
ds.call('set_spreadsheet', [model, compound_domain, groupbys, list_view_id])
- .done(function (res) {
- if (res['url']){
- window.open(res['url'], '_blank');
- }
- });
- },
+ .done(function (res) {
+ if (res['url']){
+ window.open(res['url'], '_blank');
+ }
+ });
+ },
});
};
\ No newline at end of file
* @param {Object} defaults ??
*/
load_searchview: function (defaults) {
- var self = this;
- var ds_msg = new session.web.DataSetSearch(this, 'mail.message');
- var options = {
- $buttons: this.$('.oe-search-options')
- };
+ var self = this,
+ ds_msg = new session.web.DataSetSearch(this, 'mail.message'),
+ options = { $buttons: this.$('.oe-search-options') };
this.searchview = new session.web.SearchView(this, ds_msg, false, defaults || {}, options);
this.searchview.on('search_data', this, this.do_searchview_search);
this.searchview.appendTo(this.$('.oe-view-manager-search-view')).then(function () {
});
this.setParent(undefined);
this.__parentedDestroyed = true;
- }
+ },
+ /**
+ * Find the closest ancestor matching predicate
+ */
+ findAncestor: function (predicate) {
+ var ancestor = this;
+ while (!(predicate(ancestor)) && ancestor && ancestor.getParent) {
+ ancestor = ancestor.getParent();
+ }
+ return ancestor;
+ },
};
/**
},
'click .oe_searchview_unfold_drawer': function (e) {
e.stopImmediatePropagation();
- $(e.target).toggleClass('fa-caret-down')
- .toggleClass('fa-caret-up');
- localStorage.visible_search_menu = !(localStorage.visible_search_menu === 'true');
+ $(e.target).toggleClass('fa-caret-down fa-caret-up');
+ localStorage.visible_search_menu = (localStorage.visible_search_menu !== 'true');
this.toggle_buttons();
},
'keydown .oe_searchview_input, .oe_searchview_facet': function (e) {
this.search_fields = [];
this.filters = [];
this.groupbys = [];
- this.visible_filters = !!(localStorage.visible_search_menu === 'true');
+ this.visible_filters = (localStorage.visible_search_menu === 'true');
this.input_subviews = []; // for user input in searchbar
this.defaults = defaults || {};
this.headless = this.options.hidden && _.isEmpty(this.defaults);
this.$('.oe_searchview_unfold_drawer')
.toggleClass('fa-caret-down', !this.visible_filters)
.toggleClass('fa-caret-up', this.visible_filters);
- return $.when(this._super(), this.alive($.when(load_view))
- .then(this.view_loaded.bind(this)));
+ return this.alive($.when(this._super(), load_view.then(this.view_loaded.bind(this))));
},
view_loaded: function (r) {
var self = this;
}
return $.when(custom_filters_ready).then(this.proxy('set_default_filters'));
},
- set_default_filters: function (a, b) {
+ set_default_filters: function () {
var self = this,
default_custom_filter = this.$buttons && this.favorite_menu.get_default_filter();
if (default_custom_filter) {
source: this.proxy('complete_global_search'),
select: this.proxy('select_completion'),
delay: 0,
- get_search_string: function () {
- return self.$('div.oe_searchview_input').text();
+ get_search_string: function () {
+ return self.$('div.oe_searchview_input').text();
},
});
this.autocomplete.appendTo(this.$el);
this.$el.addClass('active');
},
childBlurred: function () {
- var val = this.$el.val();
- this.$el.val('');
- this.$el.removeClass('active')
- .trigger('blur');
+ this.$el.val('').removeClass('active').trigger('blur');
this.autocomplete.close();
},
/**
*/
visible: function () {
return !this.attrs.modifiers.invisible;
-
- // var parent = this;
- // while ((parent = parent.getParent()) &&
- // ( (parent instanceof instance.web.search.Group)
- // || (parent instanceof instance.web.search.Input))) {
- // if (!parent.visible()) {
- // return false;
- // }
- // }
- // return true;
},
});
instance.web.search.FilterGroup = instance.web.search.Input.extend(/** @lends instance.web.search.FilterGroup# */{
_.each(this.filters, function (group) {
if (group.is_visible()) {
group.insertBefore(self.$add_filter);
- $('<li>').addClass('divider').insertBefore(self.$add_filter);
+ $('<li class="divider">').insertBefore(self.$add_filter);
}
});
this.append_proposition().then(function (prop) {
});
},
remove_proposition: function (prop) {
- this.propositions = _.reject(this.propositions, function (p) { return p === prop});
+ this.propositions = _.without(this.propositions, prop);
if (!this.propositions.length) {
this.$apply_filter.prop('disabled', true);
}
prop.destroy();
},
commit_search: function () {
- var self = this,
- filters = _.invoke(this.propositions, 'get_filter'),
+ var filters = _.invoke(this.propositions, 'get_filter'),
filters_widgets = _.map(filters, function (filter) {
- return new my.Filter(filter, self);
- });
- var filter_group = new my.FilterGroup(filters_widgets, this.searchview);
+ return new my.Filter(filter, this);
+ }),
+ filter_group = new my.FilterGroup(filters_widgets, this.searchview),
+ facets = filters_widgets.map(function (filter) {
+ return filter_group.make_facet([filter_group.make_value(filter)]);
+ });
filter_group.insertBefore(this.$add_filter);
- $('<li>').addClass('divider').insertBefore(self.$add_filter);
-
- filters_widgets.forEach(function (filter) {
- self.searchview.query.add(filter_group.make_facet([filter_group.make_value(filter)]), {silent: true});
- });
+ $('<li class="divider">').insertBefore(this.$add_filter);
+ this.searchview.query.add(facets, {silent: true});
this.searchview.query.trigger('reset');
_.invoke(this.propositions, 'destroy');
this.$inputs = this.$save_name.find('input');
this.$divider = this.$('.divider');
- var $shared_filter = $(this.$inputs[1]),
- $default_filter = $(this.$inputs[2]);
+ var $shared_filter = this.$inputs.eq(1),
+ $default_filter = this.$inputs.eq(2);
$shared_filter.click(function () {$default_filter.prop('checked', false)});
$default_filter.click(function () {$shared_filter.prop('checked', false)});
'use strict';
var instance = openerp,
- _lt = instance.web._lt,
- _t = instance.web._t,
- QWeb = instance.web.qweb;
+ _lt = instance.web._lt,
+ _t = instance.web._t,
+ QWeb = instance.web.qweb;
instance.web.views.add('pivot', 'instance.web.PivotView');
instance.web.PivotView = instance.web.View.extend({
- template: 'PivotView',
+ template: 'PivotView',
display_name: _lt('Pivot'),
view_type: 'pivot',
init: function(parent, dataset, view_id, options) {
- this._super(parent, dataset, view_id, options);
+ this._super(parent, dataset, view_id, options);
this.model = new instance.web.Model(dataset.model, {group_by_no_leaf: true});
- this.action_manager = parent.action_manager;
+ this.action_manager = parent.action_manager;
- this.$buttons = options.$buttons;
- this.fields = {};
- this.measures = {};
- this.groupable_fields = {};
+ this.$buttons = options.$buttons;
+ this.fields = {};
+ this.measures = {};
+ this.groupable_fields = {};
- this.row_groupbys = [];
- this.col_groupbys = [];
- this.active_measures = [];
- },
- start: function () {
- var self = this,
- load_fields = this.model.call('fields_get', [])
- .then(this.prepare_fields.bind(this));
+ this.row_groupbys = [];
+ this.col_groupbys = [];
+ this.active_measures = [];
+ },
+ start: function () {
+ var self = this,
+ load_fields = this.model.call('fields_get', [])
+ .then(this.prepare_fields.bind(this));
- return $.when(this._super(), load_fields).then(function () {
- var context = {measures: _.pairs(self.measures)};
- self.$buttons.html(QWeb.render('PivotView.buttons', self), context);
- });
- },
- view_loading: function (fvg) {
- var self = this;
- this.do_push_state({});
- fvg.arch.children.forEach(function (field) {
- var name = field.attrs.name + (field.attrs.interval || '');
+ return $.when(this._super(), load_fields).then(function () {
+ var context = {measures: _.pairs(self.measures)};
+ self.$buttons.html(QWeb.render('PivotView.buttons', self), context);
+ });
+ },
+ view_loading: function (fvg) {
+ var self = this;
+ this.do_push_state({});
+ fvg.arch.children.forEach(function (field) {
+ var name = field.attrs.name + (field.attrs.interval || '');
//noinspection FallThroughInSwitchStatementJS
switch (field.attrs.type) {
case 'measure':
case 'row':
self.row_groupbys.push(name);
}
- });
- },
+ });
+ },
prepare_fields: function (fields) {
- var self = this,
+ var self = this,
groupable_types = ['many2one', 'char', 'boolean',
- 'selection', 'date', 'datetime'];
- this.fields = fields;
- _.each(fields, function (field, name) {
- if ((name !== 'id') && (field.store === true)) {
- if (field.type === 'integer' || field.type === 'float') {
- self.measures[name] = field;
- }
- if (_.contains(groupable_types, field.type)) {
- self.groupable_fields[name] = field;
- }
- }
- });
+ 'selection', 'date', 'datetime'];
+ this.fields = fields;
+ _.each(fields, function (field, name) {
+ if ((name !== 'id') && (field.store === true)) {
+ if (field.type === 'integer' || field.type === 'float') {
+ self.measures[name] = field;
+ }
+ if (_.contains(groupable_types, field.type)) {
+ self.groupable_fields[name] = field;
+ }
+ }
+ });
},
do_search: function (domain, context, group_by) {
- console.log('do_search', domain, context, group_by);
- debugger;
- context.measure = "lol";
},
});
this.inner_widget = null;
}
},
- add_breadcrumb_url: function (url, label) {
- // Add a pseudo breadcrumb that will redirect to an url
- // this.push_breadcrumb({
- // show: function() {
- // instance.web.redirect(url);
- // },
- // hide: function() {},
- // destroy: function() {},
- // get_title: function() {
- // return label;
- // }
- // });
- },
do_push_state: function(state) {
if (!this.webclient || !this.webclient.do_push_state || this.dialog) {
return;
do_load_state: function(state, warm) {
var self = this,
action_loaded;
- if (!warm && 'return_label' in state) {
- var return_url = state.return_url || document.referrer;
- if (return_url) {
- this.add_breadcrumb_url(return_url, state.return_label);
- }
- }
if (state.action) {
if (_.isString(state.action) && instance.web.client_actions.contains(state.action)) {
var action_client = {
var self = this;
this._super(parent);
- this.flags = flags;
+ this.flags = flags || {};
this.dataset = dataset;
this.view_order = [];
this.url_states = {};
},
do_load_state: function(state, warm) {
var self = this,
- defs = [];
+ def = this.active_view.created;
if (state.view_type && state.view_type !== this.active_view.type) {
- defs.push(
- this.active_view.created.then(function() {
- return self.switch_mode(state.view_type, true);
- })
- );
- }
-
- $.when(this.active_view ? this.active_view.created : null, defs).done(function() {
+ def = def.then(function() {
+ return self.switch_mode(state.view_type, true);
+ });
+ }
+ def.done(function() {
self.active_view.controller.do_load_state(state, warm);
});
},
// this method gets the fields that appear in the search view, under the
// 'Groupby' heading
get_search_fields: function () {
- return [];
+ // this method is disabled for now. This requires extensive changes because the
+ // search view works quite differently: But the graph view is going to be split
+ // soon in pivot view and graph view. The pivot view will then properly handle
+ // groupbys.
+ return [];
var self = this;
var groupbygroups = _(this.search_view.drawer.inputs).select(function (g) {
var QWeb = instance.web.qweb;
instance.web.ViewManagerAction.include({
on_debug_changed:function(evt){
- var val = $(evt.target).data().action,
+ var val = $(evt.target).data('action'),
current_view = this.active_view.controller;
if(val === "manage_views"){
if (current_view.fields_view && current_view.fields_view.arch) {