summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2014-10-14 14:48:31 +0200
committerGéry Debongnie <ged@odoo.com>2014-10-21 09:33:52 +0200
commitd82ca918cd0f131959615150bba1930cb9c83fe5 (patch)
tree238dd5b8ec00bf6e1fe520c0cdfca35e93ae6f91 /addons/web/static/src
parentef636ed520852357241862b9e6ece7bb32c9e676 (diff)
[IMP] various code improvements
mostly styling, and related micro-changes
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/openerpframework.js12
-rw-r--r--addons/web/static/src/js/search.js58
-rw-r--r--addons/web/static/src/js/view_pivot.js89
-rw-r--r--addons/web/static/src/js/views.js36
4 files changed, 82 insertions, 113 deletions
diff --git a/addons/web/static/src/js/openerpframework.js b/addons/web/static/src/js/openerpframework.js
index fd13bea49cb..b112783793f 100644
--- a/addons/web/static/src/js/openerpframework.js
+++ b/addons/web/static/src/js/openerpframework.js
@@ -287,7 +287,17 @@ openerp.ParentedMixin = {
});
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;
+ },
};
/**
diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js
index f55f9b4fe93..de839036d06 100644
--- a/addons/web/static/src/js/search.js
+++ b/addons/web/static/src/js/search.js
@@ -333,9 +333,8 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
},
'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) {
@@ -380,7 +379,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
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);
@@ -410,8 +409,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
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;
@@ -433,7 +431,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
}
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) {
@@ -523,8 +521,8 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
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);
@@ -632,10 +630,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
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();
},
/**
@@ -789,16 +784,6 @@ instance.web.search.Input = instance.web.Widget.extend( /** @lends instance.web.
*/
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# */{
@@ -1449,7 +1434,7 @@ instance.web.search.FilterMenu = instance.web.Widget.extend({
_.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) {
@@ -1477,25 +1462,24 @@ instance.web.search.FilterMenu = instance.web.Widget.extend({
});
},
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');
@@ -1608,8 +1592,8 @@ instance.web.search.FavoriteMenu = instance.web.Widget.extend({
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)});
diff --git a/addons/web/static/src/js/view_pivot.js b/addons/web/static/src/js/view_pivot.js
index 48237393a54..9aa294ead55 100644
--- a/addons/web/static/src/js/view_pivot.js
+++ b/addons/web/static/src/js/view_pivot.js
@@ -6,46 +6,46 @@
'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':
@@ -62,28 +62,25 @@ instance.web.PivotView = instance.web.View.extend({
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";
},
});
diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js
index ef71f19729a..4fe276a8b5b 100644
--- a/addons/web/static/src/js/views.js
+++ b/addons/web/static/src/js/views.js
@@ -119,19 +119,6 @@ instance.web.ActionManager = instance.web.Widget.extend({
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;
@@ -179,12 +166,6 @@ instance.web.ActionManager = instance.web.Widget.extend({
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 = {
@@ -517,7 +498,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
var self = this;
this._super(parent);
- this.flags = flags;
+ this.flags = flags || {};
this.dataset = dataset;
this.view_order = [];
this.url_states = {};
@@ -785,16 +766,13 @@ instance.web.ViewManager = instance.web.Widget.extend({
},
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);
});
},