bzr revid: nicolas.vanhoren@openerp.com-20120405162718-rbdyzsh3ssawcoe3
This commit is contained in:
niv-openerp 2012-04-05 18:27:18 +02:00
commit 236d1d2f30
17 changed files with 267 additions and 117 deletions

View File

@ -45,29 +45,20 @@ class NonLiteralEncoder(simplejson.encoder.JSONEncoder):
raise TypeError('Could not encode unknown non-literal %s' % object) raise TypeError('Could not encode unknown non-literal %s' % object)
_ALLOWED_KEYS = frozenset(['__ref', "__id", '__domains', '__debug', _ALLOWED_KEYS = frozenset(['__ref', "__id", '__domains', '__debug',
'__contexts', '__eval_context', 'own_values']) '__contexts', '__eval_context'])
def non_literal_decoder(dct): def non_literal_decoder(dct):
""" Decodes JSON dicts into :class:`Domain` and :class:`Context` based on """ Decodes JSON dicts into :class:`Domain` and :class:`Context` based on
magic attribute tags. magic attribute tags.
Also handles private context section for the domain or section via the
``own_values`` dict key.
""" """
if '__ref' in dct: if '__ref' in dct:
for x in dct: for x in dct:
if x not in _ALLOWED_KEYS: if x not in _ALLOWED_KEYS:
raise ValueError("'%s' key not allowed in non literal domain/context" % x) raise ValueError("'%s' key not allowed in non literal domain/context" % x)
if dct['__ref'] == 'domain': if dct['__ref'] == 'domain':
domain = Domain(None, key=dct['__id']) return Domain(None, key=dct['__id'])
if 'own_values' in dct:
domain.own = dct['own_values']
return domain
elif dct['__ref'] == 'context': elif dct['__ref'] == 'context':
context = Context(None, key=dct['__id']) return Context(None, key=dct['__id'])
if 'own_values' in dct:
context.own = dct['own_values']
return context
elif dct["__ref"] == "compound_domain": elif dct["__ref"] == "compound_domain":
cdomain = CompoundDomain() cdomain = CompoundDomain()
for el in dct["__domains"]: for el in dct["__domains"]:
@ -111,7 +102,6 @@ class Domain(BaseDomain):
"and a domain string") "and a domain string")
self.session = session self.session = session
self.own = {}
if domain_string: if domain_string:
self.key = binascii.hexlify( self.key = binascii.hexlify(
hashlib.sha256(domain_string).digest()[:SHORT_HASH_BYTES_SIZE]) hashlib.sha256(domain_string).digest()[:SHORT_HASH_BYTES_SIZE])
@ -131,8 +121,7 @@ class Domain(BaseDomain):
evaluated result. evaluated result.
""" """
ctx = self.session.evaluation_context(context) ctx = self.session.evaluation_context(context)
if self.own:
ctx.update(self.own)
try: try:
return eval(self.get_domain_string(), SuperDict(ctx)) return eval(self.get_domain_string(), SuperDict(ctx))
except NameError as e: except NameError as e:
@ -159,7 +148,7 @@ class Context(BaseContext):
"and a domain string") "and a domain string")
self.session = session self.session = session
self.own = {}
if context_string: if context_string:
self.key = binascii.hexlify( self.key = binascii.hexlify(
hashlib.sha256(context_string).digest()[:SHORT_HASH_BYTES_SIZE]) hashlib.sha256(context_string).digest()[:SHORT_HASH_BYTES_SIZE])
@ -179,8 +168,7 @@ class Context(BaseContext):
evaluated result. evaluated result.
""" """
ctx = self.session.evaluation_context(context) ctx = self.session.evaluation_context(context)
if self.own:
ctx.update(self.own)
try: try:
return eval(self.get_context_string(), SuperDict(ctx)) return eval(self.get_context_string(), SuperDict(ctx))
except NameError as e: except NameError as e:

View File

@ -1,5 +1,5 @@
repo: 076b192d0d8ab2b92d1dbcfa3da055382f30eaea repo: 076b192d0d8ab2b92d1dbcfa3da055382f30eaea
node: 5adb2d9c89e53a6445e3799f9c4dc9110458c149 node: 1758bfec1ec1dcff95dcc4c72269cc0e3d000afd
branch: default branch: default
latesttag: 0.5 latesttag: 0.5
latesttagdistance: 9 latesttagdistance: 11

View File

@ -384,6 +384,21 @@ var py = {};
return new py.def(val); return new py.def(val);
} }
switch(val.constructor) {
case Object:
var o = new py.object();
for (var prop in val) {
if (val.hasOwnProperty(prop)) {
o[prop] = val[prop];
}
}
return o;
case Array:
var a = new py.list();
a.values = val;
return a;
}
throw new Error("Could not convert " + val + " to a pyval"); throw new Error("Could not convert " + val + " to a pyval");
} }
// Builtins // Builtins
@ -448,7 +463,7 @@ var py = {};
__getattribute__: function (name) { __getattribute__: function (name) {
if (name in this) { if (name in this) {
var val = this[name]; var val = this[name];
if ('__get__' in val) { if (typeof val === 'object' && '__get__' in val) {
// TODO: second argument should be class // TODO: second argument should be class
return val.__get__(this); return val.__get__(this);
} }
@ -627,6 +642,9 @@ var py = {};
} }
return py.False; return py.False;
}, },
__getitem__: function (index) {
return PY_ensurepy(this.values[index.toJSON()]);
},
toJSON: function () { toJSON: function () {
var out = []; var out = [];
for (var i=0; i<this.values.length; ++i) { for (var i=0; i<this.values.length; ++i) {
@ -846,7 +864,7 @@ var py = {};
case '[': case '[':
if (expr.second) { if (expr.second) {
return py.evaluate(expr.first, context) return py.evaluate(expr.first, context)
.__getitem__(expr.evaluate(expr.second, context)); .__getitem__(py.evaluate(expr.second, context));
} }
var list_exprs = expr.first, list_values = []; var list_exprs = expr.first, list_values = [];
for (var k=0; k<list_exprs.length; ++k) { for (var k=0; k<list_exprs.length; ++k) {

View File

@ -376,4 +376,13 @@ describe('numerical protocols', function () {
}); });
}); });
}); });
}); });
describe('Type converter', function () {
it('should convert bare objects to objects', function () {
expect(py.eval('foo.bar', {foo: {bar: 3}})).to.be(3);
});
it('should convert arrays to lists', function () {
expect(py.eval('foo[3]', {foo: [9, 8, 7, 6, 5]}))
.to.be(6);
});
});

View File

@ -13,8 +13,9 @@ openerp.web.core = function(openerp) {
// a function to override the "extend()" method of JR's inheritance, allowing // a function to override the "extend()" method of JR's inheritance, allowing
// the usage of "include()" // 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' // TODO: remove usage of include everywhere, not meant to be included in novajs because we don't
oe_override_class = function(claz){ // include rotten cadavers in novajs
var oe_override_class = function(claz){
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ?
/\b_super\b/ : /.*/; /\b_super\b/ : /.*/;
@ -622,36 +623,44 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
}), true); }), true);
} }
}, },
test_eval_contexts: function (contexts) { test_eval_contexts: function (contexts, evaluation_context) {
var result_context = _.extend({}, this.user_context), evaluation_context = evaluation_context || {};
self = this; var self = this;
_(contexts).each(function (ctx) { 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) { switch(ctx.__ref) {
case 'context': case 'context':
_.extend(result_context, py.eval(ctx.__debug)); evaluated = py.eval(ctx.__debug, evaluation_context);
break; break;
case 'compound_context': case 'compound_context':
_.extend( var eval_context = self.test_eval_contexts([ctx.__eval_context]);
result_context, self.test_eval_contexts(ctx.__contexts)); evaluated = self.test_eval_contexts(
ctx.__contexts, _.extend({}, evaluation_context, eval_context));
break; break;
default:
_.extend(result_context, ctx);
} }
}); // add newly evaluated context to evaluation context for following
return result_context; // 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; var result_domain = [], self = this;
_(domains).each(function (dom) { _(domains).each(function (dom) {
switch(dom.__ref) { switch(dom.__ref) {
case 'domain': case 'domain':
result_domain.push.apply( result_domain.push.apply(
result_domain, py.eval(dom.__debug, eval_context)); result_domain, py.eval(dom.__debug, evaluation_context));
break; break;
case 'compound_domain': case 'compound_domain':
var eval_context = self.test_eval_contexts([dom.__eval_context]);
result_domain.push.apply( result_domain.push.apply(
result_domain, self.test_eval_domains( result_domain, self.test_eval_domains(
dom.__domains, eval_context)); dom.__domains, _.extend(
{}, evaluation_context, eval_context)));
break; break;
default: default:
result_domain.push.apply( result_domain.push.apply(
@ -669,7 +678,8 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
group = py.eval(ctx.__debug).group_by; group = py.eval(ctx.__debug).group_by;
break; break;
case 'compound_context': 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; break;
default: default:
group = ctx.group_by group = ctx.group_by

View File

@ -787,9 +787,8 @@ openerp.web.search.Field = openerp.web.search.Input.extend( /** @lends openerp.w
if (!(has_value && context)) { if (!(has_value && context)) {
return; return;
} }
return _.extend( return new openerp.web.CompoundContext(context)
{}, context, .set_eval_context({self: val});
{own_values: {self: val}});
}, },
/** /**
* Function creating the returned domain for the field, override this * 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, this.attrs.operator || this.default_operator,
val); val);
} }
return _.extend({}, domain, {own_values: {self: val}}); return new openerp.web.CompoundDomain(domain)
.set_eval_context({self: val});
} }
}); });
/** /**

View File

@ -13,6 +13,7 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
searchable: false, searchable: false,
template: "FormView", template: "FormView",
display_name: _lt('Form'), display_name: _lt('Form'),
view_type: "form",
/** /**
* @constructs openerp.web.FormView * @constructs openerp.web.FormView
* @extends openerp.web.View * @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.set({"force_readonly": false});
this.rendering_engine = new openerp.web.FormRenderingEngine(this); 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() { destroy: function() {
if (this.sidebar) { if (this.sidebar) {
this.sidebar.attachments.destroy(); this.sidebar.attachments.destroy();
@ -123,6 +103,7 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
}]); }]);
} }
this.has_been_loaded.resolve(); this.has_been_loaded.resolve();
return $.when();
}, },
do_load_state: function(state, warm) { do_load_state: function(state, warm) {

View File

@ -136,7 +136,6 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView#
* @returns {$.Deferred} loading promise * @returns {$.Deferred} loading promise
*/ */
start: function() { start: function() {
this._super();
this.$element.addClass('oe-listview'); this.$element.addClass('oe-listview');
return this.reload_view(null, null, true); return this.reload_view(null, null, true);
}, },

View File

@ -39,7 +39,6 @@ openerp.web.TreeView = openerp.web.View.extend(/** @lends openerp.web.TreeView#
}, },
start: function () { start: function () {
this._super();
return this.rpc("/web/treeview/load", { return this.rpc("/web/treeview/load", {
model: this.model, model: this.model,
view_id: this.view_id, view_id: this.view_id,

View File

@ -112,12 +112,13 @@ session.web.ActionManager = session.web.OldWidget.extend({
} }
var type = action.type.replace(/\./g,'_'); var type = action.type.replace(/\./g,'_');
var popup = action.target === 'new'; var popup = action.target === 'new';
var inline = action.target === 'inline';
action.flags = _.extend({ action.flags = _.extend({
views_switcher : !popup, views_switcher : !popup && !inline,
search_view : !popup, search_view : !popup && !inline,
action_buttons : !popup, action_buttons : !popup && !inline,
sidebar : !popup, sidebar : !popup && !inline,
pager : !popup, pager : !popup && !inline,
display_title : !popup display_title : !popup
}, action.flags || {}); }, action.flags || {});
if (!(type in this)) { if (!(type in this)) {
@ -1077,12 +1078,43 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{
template: "EmptyComponent", template: "EmptyComponent",
// name displayed in view switchers // name displayed in view switchers
display_name: '', 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) { init: function(parent, dataset, view_id, options) {
this._super(parent); this._super(parent);
this.dataset = dataset; this.dataset = dataset;
this.view_id = view_id; this.view_id = view_id;
this.set_default_options(options); 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) { set_default_options: function(options) {
this.options = options || {}; this.options = options || {};
_.defaults(this.options, { _.defaults(this.options, {

View File

@ -0,0 +1,135 @@
$(document).ready(function () {
var openerp;
module("eval.contexts", {
setup: function () {
openerp = window.openerp.init();
window.openerp.web.core(openerp);
}
});
test('context_sequences', function () {
// Context n should have base evaluation context + all of contexts
// 0..n-1 in its own evaluation context
var active_id = 4;
var result = openerp.connection.test_eval_contexts([
{
"__contexts": [
{
"department_id": false,
"lang": "en_US",
"project_id": false,
"section_id": false,
"tz": false,
"uid": 1
},
{ "search_default_create_uid": 1 },
{}
],
"__eval_context": null,
"__ref": "compound_context"
},
{
"active_id": active_id,
"active_ids": [ active_id ],
"active_model": "purchase.requisition"
},
{
"__debug": "{'record_id' : active_id}",
"__id": "63e8e9bff8a6",
"__ref": "context"
}
]);
deepEqual(result, {
department_id: false,
lang: 'en_US',
project_id: false,
section_id: false,
tz: false,
uid: 1,
search_default_create_uid: 1,
active_id: active_id,
active_ids: [active_id],
active_model: 'purchase.requisition',
record_id: active_id
});
});
test('non-literal_eval_contexts', function () {
var result = openerp.connection.test_eval_contexts([{
"__ref": "compound_context",
"__contexts": [
{"__ref": "context", "__debug": "{'type':parent.type}",
"__id": "462b9dbed42f"}
],
"__eval_context": {
"__ref": "compound_context",
"__contexts": [{
"__ref": "compound_context",
"__contexts": [
{"__ref": "context", "__debug": "{'type': type}",
"__id": "16a04ed5a194"}
],
"__eval_context": {
"__ref": "compound_context",
"__contexts": [
{"lang": "en_US", "tz": false, "uid": 1,
"journal_type": "sale", "section_id": false,
"default_type": "out_invoice",
"type": "out_invoice", "department_id": false},
{"id": false, "journal_id": 10,
"number": false, "type": "out_invoice",
"currency_id": 1, "partner_id": 4,
"fiscal_position": false,
"date_invoice": false, "period_id": false,
"payment_term": false, "reference_type": "none",
"reference": false, "account_id": 440,
"name": false, "invoice_line": [],
"tax_line": [], "amount_untaxed": 0,
"amount_tax": 0, "reconciled": false,
"amount_total": 0, "state": "draft",
"residual": 0, "company_id": 1,
"date_due": false, "user_id": 1,
"partner_bank_id": false, "origin": false,
"move_id": false, "comment": false,
"payment_ids": [[6, false, []]],
"active_id": false, "active_ids": [],
"active_model": "account.invoice",
"parent": {}}
], "__eval_context": null}
}, {
"id": false,
"product_id": 4,
"name": "[PC1] Basic PC",
"quantity": 1,
"uos_id": 1,
"price_unit": 100,
"account_id": 853,
"discount": 0,
"account_analytic_id": false,
"company_id": false,
"note": false,
"invoice_line_tax_id": [[6, false, [1]]],
"active_id": false,
"active_ids": [],
"active_model": "account.invoice.line",
"parent": {
"id": false, "journal_id": 10, "number": false,
"type": "out_invoice", "currency_id": 1,
"partner_id": 4, "fiscal_position": false,
"date_invoice": false, "period_id": false,
"payment_term": false, "reference_type": "none",
"reference": false, "account_id": 440, "name": false,
"tax_line": [], "amount_untaxed": 0, "amount_tax": 0,
"reconciled": false, "amount_total": 0,
"state": "draft", "residual": 0, "company_id": 1,
"date_due": false, "user_id": 1,
"partner_bank_id": false, "origin": false,
"move_id": false, "comment": false,
"payment_ids": [[6, false, []]]}
}],
"__eval_context": null
}
}]);
deepEqual(result, {type: 'out_invoice'});
});
});

View File

@ -24,7 +24,9 @@
<script src="/web/static/lib/qweb/qweb2.js"></script> <script src="/web/static/lib/qweb/qweb2.js"></script>
<script src="/web/static/lib/py.parse/lib/py.js"></script> <script src="/web/static/lib/py.js/lib/py.js"></script>
<script src="/web/static/lib/novajs/src/nova.js"></script>
<script src="/web/static/src/js/boot.js"></script> <script src="/web/static/src/js/boot.js"></script>
<script src="/web/static/src/js/core.js"></script> <script src="/web/static/src/js/core.js"></script>
@ -51,4 +53,5 @@
<script type="text/javascript" src="/web/static/test/list-utils.js"></script> <script type="text/javascript" src="/web/static/test/list-utils.js"></script>
<script type="text/javascript" src="/web/static/test/formats.js"></script> <script type="text/javascript" src="/web/static/test/formats.js"></script>
<script type="text/javascript" src="/web/static/test/onchange.js"></script> <script type="text/javascript" src="/web/static/test/onchange.js"></script>
<script type="text/javascript" src="/web/static/test/evals.js"></script>
</html> </html>

View File

@ -294,7 +294,6 @@ openerp.web_dashboard.ConfigOverview = openerp.web.View.extend({
this.dataset = new openerp.web.DataSetSearch(this, 'ir.actions.todo'); this.dataset = new openerp.web.DataSetSearch(this, 'ir.actions.todo');
}, },
start: function () { start: function () {
this._super();
var self = this; var self = this;
return this.user.read_index(['groups_id']).pipe(function(record) { return this.user.read_index(['groups_id']).pipe(function(record) {
var todos_filter = [ var todos_filter = [
@ -383,7 +382,6 @@ openerp.web_dashboard.Widget = openerp.web.View.extend(/** @lends openerp.web_da
this.widget_id = options.widget_id; this.widget_id = options.widget_id;
}, },
start: function () { start: function () {
this._super();
var ds = new openerp.web.DataSet(this, 'res.widget'); var ds = new openerp.web.DataSet(this, 'res.widget');
return ds.read_ids([this.widget_id], ['title']).then(this.on_widget_loaded); return ds.read_ids([this.widget_id], ['title']).then(this.on_widget_loaded);
}, },

View File

@ -22,7 +22,6 @@ openerp.web.DiagramView = openerp.web.View.extend({
this.ids = this.dataset.ids; this.ids = this.dataset.ids;
}, },
start: function() { start: function() {
this._super();
return this.rpc("/web_diagram/diagram/load", {"model": this.model, "view_id": this.view_id}, this.on_loaded); return this.rpc("/web_diagram/diagram/load", {"model": this.model, "view_id": this.view_id}, this.on_loaded);
}, },

View File

@ -10,20 +10,19 @@ openerp.web.views.add('gantt', 'openerp.web_gantt.GanttView');
openerp.web_gantt.GanttView = openerp.web.View.extend({ openerp.web_gantt.GanttView = openerp.web.View.extend({
display_name: _lt('Gantt'), display_name: _lt('Gantt'),
template: "GanttView", template: "GanttView",
view_type: "gantt",
init: function() { init: function() {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.has_been_loaded = $.Deferred(); this.has_been_loaded = $.Deferred();
this.chart_id = _.uniqueId(); this.chart_id = _.uniqueId();
}, },
start: function() { on_loaded: function(fields_view_get, fields_get) {
return $.when(this.rpc("/web/view/load", {"model": this.dataset.model, "view_id": this.view_id, "view_type": "gantt"}), var self = this;
this.rpc("/web/searchview/fields_get", {"model": this.dataset.model})).pipe(this.on_loaded); this.fields_view = fields_view_get;
}, return this.rpc("/web/searchview/fields_get", {"model": this.dataset.model}).pipe(function(fields_get) {
on_loaded: function(fields_view, fields_get) { self.fields = fields_get.fields;
this.fields_view = fields_view[0]; self.has_been_loaded.resolve();
this.fields = fields_get[0].fields; });
this.has_been_loaded.resolve();
}, },
do_search: function (domains, contexts, group_bys) { do_search: function (domains, contexts, group_bys) {
var self = this; var self = this;

View File

@ -17,6 +17,7 @@ var QWeb = openerp.web.qweb,
openerp.web.views.add('graph', 'openerp.web_graph.GraphView'); openerp.web.views.add('graph', 'openerp.web_graph.GraphView');
openerp.web_graph.GraphView = openerp.web.View.extend({ openerp.web_graph.GraphView = openerp.web.View.extend({
display_name: _lt('Graph'), display_name: _lt('Graph'),
view_type: "graph",
init: function(parent, dataset, view_id, options) { init: function(parent, dataset, view_id, options) {
this._super(parent); this._super(parent);
@ -39,27 +40,13 @@ openerp.web_graph.GraphView = openerp.web.View.extend({
} }
this._super(); this._super();
}, },
start: function() { on_loaded: function(fields_view_get) {
var self = this; var self = this;
this._super(); self.fields_view = fields_view_get;
var loaded; return this.dataset.call_and_eval('fields_get', [false, {}], null, 1).pipe(function(fields_result) {
if (this.embedded_view) { self.fields = fields_result;
loaded = $.when([self.embedded_view]); return self.on_loaded_2();
} else { });
loaded = this.rpc('/web/view/load', {
model: this.dataset.model,
view_id: this.view_id,
view_type: 'graph'
});
}
return $.when(
this.dataset.call_and_eval('fields_get', [false, {}], null, 1),
loaded)
.then(function (fields_result, view_result) {
self.fields = fields_result[0];
self.fields_view = view_result[0];
self.on_loaded(self.fields_view);
});
}, },
/** /**
* Returns all object fields involved in the graph view * Returns all object fields involved in the graph view
@ -72,7 +59,7 @@ openerp.web_graph.GraphView = openerp.web.View.extend({
} }
return fs; return fs;
}, },
on_loaded: function() { on_loaded_2: function() {
this.chart = this.fields_view.arch.attrs.type || 'pie'; this.chart = this.fields_view.arch.attrs.type || 'pie';
this.orientation = this.fields_view.arch.attrs.orientation || 'vertical'; this.orientation = this.fields_view.arch.attrs.orientation || 'vertical';
@ -91,6 +78,7 @@ openerp.web_graph.GraphView = openerp.web.View.extend({
}, this); }, this);
this.ordinate = this.columns[0].name; this.ordinate = this.columns[0].name;
this.is_loaded.resolve(); this.is_loaded.resolve();
return $.when();
}, },
schedule_chart: function(results) { schedule_chart: function(results) {
var self = this; var self = this;

View File

@ -9,6 +9,7 @@ openerp.web_kanban.KanbanView = openerp.web.View.extend({
template: "KanbanView", template: "KanbanView",
display_name: _lt('Kanban'), display_name: _lt('Kanban'),
default_nr_columns: 3, default_nr_columns: 3,
view_type: "kanban",
init: function (parent, dataset, view_id, options) { init: function (parent, dataset, view_id, options) {
this._super(parent); this._super(parent);
this.set_default_options(options); this.set_default_options(options);
@ -34,23 +35,14 @@ openerp.web_kanban.KanbanView = openerp.web.View.extend({
this.currently_dragging = {}; this.currently_dragging = {};
this.limit = options.limit || 80; this.limit = options.limit || 80;
}, },
start: function() { on_loaded: function(data) {
this._super();
this.$element.find('button.oe_kanban_button_new').click(this.do_add_record); this.$element.find('button.oe_kanban_button_new').click(this.do_add_record);
this.$groups = this.$element.find('.oe_kanban_groups tr'); this.$groups = this.$element.find('.oe_kanban_groups tr');
var context = new openerp.web.CompoundContext(this.dataset.get_context());
return this.rpc('/web/view/load', {
'model': this.dataset.model,
'view_id': this.view_id,
'view_type': 'kanban',
context: context
}, this.on_loaded);
},
on_loaded: function(data) {
this.fields_view = data; this.fields_view = data;
this.fields_keys = _.keys(this.fields_view.fields); this.fields_keys = _.keys(this.fields_view.fields);
this.add_qweb_template(); this.add_qweb_template();
this.has_been_loaded.resolve(); this.has_been_loaded.resolve();
return $.when();
}, },
add_qweb_template: function() { add_qweb_template: function() {
for (var i=0, ii=this.fields_view.arch.children.length; i < ii; i++) { for (var i=0, ii=this.fields_view.arch.children.length; i < ii; i++) {