summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorniv-openerp <nicolas.vanhoren@openerp.com>2012-04-05 18:27:18 +0200
committerniv-openerp <nicolas.vanhoren@openerp.com>2012-04-05 18:27:18 +0200
commit236d1d2f30d7233376b0f6603fdcb28f95b692d2 (patch)
tree4320c805c1a17eb7662e5b8879e8c7a18e739f07 /addons/web/static/src/js
parent468a2094087161a048edc2c46e7319a70a7f0197 (diff)
parentca05331377a4c6d84e2b20c0a5b39a48321a3786 (diff)
[merge]
bzr revid: nicolas.vanhoren@openerp.com-20120405162718-rbdyzsh3ssawcoe3
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/core.js44
-rw-r--r--addons/web/static/src/js/search.js8
-rw-r--r--addons/web/static/src/js/view_form.js23
-rw-r--r--addons/web/static/src/js/view_list.js1
-rw-r--r--addons/web/static/src/js/view_tree.js1
-rw-r--r--addons/web/static/src/js/views.js42
6 files changed, 70 insertions, 49 deletions
diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js
index 094c81ffa54..6bddb993a85 100644
--- a/addons/web/static/src/js/core.js
+++ b/addons/web/static/src/js/core.js
@@ -13,8 +13,9 @@ openerp.web.core = function(openerp) {
// a function to override the "extend()" method of JR's inheritance, allowing
// the usage of "include()"
-// al: Either move it into novajs or make sure we dont use include, i dont want 2 diff implementations of 'extend'
-oe_override_class = function(claz){
+// TODO: remove usage of include everywhere, not meant to be included in novajs because we don't
+// include rotten cadavers in novajs
+var oe_override_class = function(claz){
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ?
/\b_super\b/ : /.*/;
@@ -622,36 +623,44 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
}), true);
}
},
- test_eval_contexts: function (contexts) {
- var result_context = _.extend({}, this.user_context),
- self = this;
- _(contexts).each(function (ctx) {
+ test_eval_contexts: function (contexts, evaluation_context) {
+ evaluation_context = evaluation_context || {};
+ var self = this;
+ return _(contexts).reduce(function (result_context, ctx) {
+ // __eval_context evaluations can lead to some of `contexts`'s
+ // values being null, skip them as well as empty contexts
+ if (_.isEmpty(ctx)) { return result_context; }
+ var evaluated = ctx;
switch(ctx.__ref) {
case 'context':
- _.extend(result_context, py.eval(ctx.__debug));
+ evaluated = py.eval(ctx.__debug, evaluation_context);
break;
case 'compound_context':
- _.extend(
- result_context, self.test_eval_contexts(ctx.__contexts));
+ var eval_context = self.test_eval_contexts([ctx.__eval_context]);
+ evaluated = self.test_eval_contexts(
+ ctx.__contexts, _.extend({}, evaluation_context, eval_context));
break;
- default:
- _.extend(result_context, ctx);
}
- });
- return result_context;
+ // add newly evaluated context to evaluation context for following
+ // siblings
+ _.extend(evaluation_context, evaluated);
+ return _.extend(result_context, evaluated);
+ }, _.extend({}, this.user_context));
},
- test_eval_domains: function (domains, eval_context) {
+ test_eval_domains: function (domains, evaluation_context) {
var result_domain = [], self = this;
_(domains).each(function (dom) {
switch(dom.__ref) {
case 'domain':
result_domain.push.apply(
- result_domain, py.eval(dom.__debug, eval_context));
+ result_domain, py.eval(dom.__debug, evaluation_context));
break;
case 'compound_domain':
+ var eval_context = self.test_eval_contexts([dom.__eval_context]);
result_domain.push.apply(
result_domain, self.test_eval_domains(
- dom.__domains, eval_context));
+ dom.__domains, _.extend(
+ {}, evaluation_context, eval_context)));
break;
default:
result_domain.push.apply(
@@ -669,7 +678,8 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
group = py.eval(ctx.__debug).group_by;
break;
case 'compound_context':
- group = self.test_eval_contexts(ctx.__contexts).group_by;
+ group = self.test_eval_contexts(
+ ctx.__contexts, ctx.__eval_context).group_by;
break;
default:
group = ctx.group_by
diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js
index 8e89595585b..0136d41ada0 100644
--- a/addons/web/static/src/js/search.js
+++ b/addons/web/static/src/js/search.js
@@ -787,9 +787,8 @@ openerp.web.search.Field = openerp.web.search.Input.extend( /** @lends openerp.w
if (!(has_value && context)) {
return;
}
- return _.extend(
- {}, context,
- {own_values: {self: val}});
+ return new openerp.web.CompoundContext(context)
+ .set_eval_context({self: val});
},
/**
* Function creating the returned domain for the field, override this
@@ -818,7 +817,8 @@ openerp.web.search.Field = openerp.web.search.Input.extend( /** @lends openerp.w
this.attrs.operator || this.default_operator,
val);
}
- return _.extend({}, domain, {own_values: {self: val}});
+ return new openerp.web.CompoundDomain(domain)
+ .set_eval_context({self: val});
}
});
/**
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index 1a09c3a7903..663ea0246e9 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -13,6 +13,7 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
searchable: false,
template: "FormView",
display_name: _lt('Form'),
+ view_type: "form",
/**
* @constructs openerp.web.FormView
* @extends openerp.web.View
@@ -52,27 +53,6 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
this.set({"force_readonly": false});
this.rendering_engine = new openerp.web.FormRenderingEngine(this);
},
- start: function() {
- this._super();
- return this.init_view();
- },
- init_view: function() {
- if (this.embedded_view) {
- var def = $.Deferred().then(this.on_loaded);
- var self = this;
- $.async_when().then(function() {def.resolve(self.embedded_view);});
- return def.promise();
- } else {
- var context = new openerp.web.CompoundContext(this.dataset.get_context());
- return this.rpc("/web/view/load", {
- "model": this.model,
- "view_id": this.view_id,
- "view_type": "form",
- toolbar: this.options.sidebar,
- context: context
- }, this.on_loaded);
- }
- },
destroy: function() {
if (this.sidebar) {
this.sidebar.attachments.destroy();
@@ -123,6 +103,7 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
}]);
}
this.has_been_loaded.resolve();
+ return $.when();
},
do_load_state: function(state, warm) {
diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js
index b93aeb72e25..b4902e1286d 100644
--- a/addons/web/static/src/js/view_list.js
+++ b/addons/web/static/src/js/view_list.js
@@ -136,7 +136,6 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
* @returns {$.Deferred} loading promise
*/
start: function() {
- this._super();
this.$element.addClass('oe-listview');
return this.reload_view(null, null, true);
},
diff --git a/addons/web/static/src/js/view_tree.js b/addons/web/static/src/js/view_tree.js
index 6039e4a0822..72a643b3d51 100644
--- a/addons/web/static/src/js/view_tree.js
+++ b/addons/web/static/src/js/view_tree.js
@@ -39,7 +39,6 @@ openerp.web.TreeView = openerp.web.View.extend(/** @lends openerp.web.TreeView#
},
start: function () {
- this._super();
return this.rpc("/web/treeview/load", {
model: this.model,
view_id: this.view_id,
diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js
index 96e5632b976..70a2c88f6cf 100644
--- a/addons/web/static/src/js/views.js
+++ b/addons/web/static/src/js/views.js
@@ -112,12 +112,13 @@ session.web.ActionManager = session.web.OldWidget.extend({
}
var type = action.type.replace(/\./g,'_');
var popup = action.target === 'new';
+ var inline = action.target === 'inline';
action.flags = _.extend({
- views_switcher : !popup,
- search_view : !popup,
- action_buttons : !popup,
- sidebar : !popup,
- pager : !popup,
+ views_switcher : !popup && !inline,
+ search_view : !popup && !inline,
+ action_buttons : !popup && !inline,
+ sidebar : !popup && !inline,
+ pager : !popup && !inline,
display_title : !popup
}, action.flags || {});
if (!(type in this)) {
@@ -1077,12 +1078,43 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{
template: "EmptyComponent",
// name displayed in view switchers
display_name: '',
+ /**
+ * Define a view type for each view to allow automatic call to fields_view_get.
+ */
+ view_type: undefined,
init: function(parent, dataset, view_id, options) {
this._super(parent);
this.dataset = dataset;
this.view_id = view_id;
this.set_default_options(options);
},
+ start: function() {
+ return this.load_view();
+ },
+ load_view: function() {
+ if (this.embedded_view) {
+ var def = $.Deferred().pipe(this.on_loaded);
+ var self = this;
+ $.async_when().then(function() {def.resolve(self.embedded_view);});
+ return def.promise();
+ } else {
+ var context = new session.web.CompoundContext(this.dataset.get_context());
+ if (! this.view_type)
+ console.warn("view_type is not defined", this);
+ return this.rpc("/web/view/load", {
+ "model": this.dataset.model,
+ "view_id": this.view_id,
+ "view_type": this.view_type,
+ toolbar: this.options.sidebar,
+ context: context
+ }).pipe(this.on_loaded);
+ }
+ },
+ /**
+ * Called after a successful call to fields_view_get.
+ * Must return a promise.
+ */
+ on_loaded: function(fields_view_get) {},
set_default_options: function(options) {
this.options = options || {};
_.defaults(this.options, {