summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views.js
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@openerp.com>2012-12-07 09:10:26 +0100
committerChristophe Matthieu <chm@openerp.com>2012-12-07 09:10:26 +0100
commit94c9801ac707086732cbe1a7913ef139d1cc785b (patch)
tree4f06a75730ae688b2afe07fa9350e601d97030e8 /addons/web/static/src/js/views.js
parent98e87a51aef5c7457c444334f3f5270cbb947ba3 (diff)
parentc09b9cb5f9a2a7825571cf803ec760f9e3983b6c (diff)
[MERGE] from trunk
bzr revid: chm@openerp.com-20121207081026-3edlt0698csc6gk8
Diffstat (limited to 'addons/web/static/src/js/views.js')
-rw-r--r--addons/web/static/src/js/views.js87
1 files changed, 51 insertions, 36 deletions
diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js
index 5d152db1f60..94ce854876e 100644
--- a/addons/web/static/src/js/views.js
+++ b/addons/web/static/src/js/views.js
@@ -275,7 +275,7 @@ instance.web.ActionManager = instance.web.Widget.extend({
}
if (action.domain) {
action.domain = instance.web.pyeval.eval(
- 'domain', action.domain);
+ 'domain', action.domain, action.context || {});
}
if (!action.type) {
@@ -758,12 +758,6 @@ instance.web.ViewManagerAction = instance.web.ViewManager.extend({
dataset.index = 0;
}
this.dataset = dataset;
-
- // setup storage for session-wise menu hiding
- if (this.session.hidden_menutips) {
- return;
- }
- this.session.hidden_menutips = {};
},
/**
* Initializes the ViewManagerAction: sets up the searchview (if the
@@ -1209,13 +1203,11 @@ instance.web.View = instance.web.Widget.extend({
} else {
if (! this.view_type)
console.warn("view_type is not defined", this);
- view_loaded = this.rpc("/web/view/load", {
- "model": this.dataset.model,
+ view_loaded = instance.web.fields_view_get({
+ "model": this.dataset._model,
"view_id": this.view_id,
"view_type": this.view_type,
- toolbar: !!this.options.$sidebar,
- context: instance.web.pyeval.eval(
- 'context', this.dataset.get_context(context))
+ "toolbar": !!this.options.$sidebar,
});
}
return view_loaded.then(function(r) {
@@ -1390,12 +1382,53 @@ instance.web.View = instance.web.Widget.extend({
}
});
-instance.web.xml_to_json = function(node) {
+/**
+ * Performs a fields_view_get and apply postprocessing.
+ * return a {$.Deferred} resolved with the fvg
+ *
+ * @param {Object} [args]
+ * @param {String|Object} args.model instance.web.Model instance or string repr of the model
+ * @param {null|Object} args.context context if args.model is a string
+ * @param {null|Number} args.view_id id of the view to be loaded, default view if null
+ * @param {null|String} args.view_type type of view to be loaded if view_id is null
+ * @param {Boolean} [args.toolbar=false] get the toolbar definition
+ */
+instance.web.fields_view_get = function(args) {
+ function postprocess(fvg) {
+ var doc = $.parseXML(fvg.arch).documentElement;
+ fvg.arch = instance.web.xml_to_json(doc, (doc.nodeName.toLowerCase() !== 'kanban'));
+ if ('id' in fvg.fields) {
+ // Special case for id's
+ var id_field = fvg.fields['id'];
+ id_field.original_type = id_field.type;
+ id_field.type = 'id';
+ }
+ _.each(fvg.fields, function(field) {
+ _.each(field.views || {}, function(view) {
+ postprocess(view);
+ });
+ });
+ return fvg;
+ }
+ args = _.defaults(args, {
+ toolbar: false,
+ });
+ var model = args.model;
+ if (typeof model === 'string') {
+ model = new instance.web.Model(args.model, args.context);
+ }
+ return args.model.call('fields_view_get', [args.view_id, args.view_type, model.context(), args.toolbar]).then(function(fvg) {
+ return postprocess(fvg);
+ });
+};
+
+instance.web.xml_to_json = function(node, strip_whitespace) {
switch (node.nodeType) {
+ case 9:
+ return instance.web.xml_to_json(node.documentElement, strip_whitespace);
case 3:
case 4:
- return node.data;
- break;
+ return (strip_whitespace && node.data.trim() === '') ? undefined : node.data;
case 1:
var attrs = $(node).getAttributes();
_.each(['domain', 'filter_domain', 'context', 'default_get'], function(key) {
@@ -1408,7 +1441,9 @@ instance.web.xml_to_json = function(node) {
return {
tag: node.tagName.toLowerCase(),
attrs: attrs,
- children: _.map(node.childNodes, instance.web.xml_to_json)
+ children: _.compact(_.map(node.childNodes, function(node) {
+ return instance.web.xml_to_json(node, strip_whitespace);
+ })),
}
}
}
@@ -1460,26 +1495,6 @@ instance.web.xml_to_str = function(node) {
throw new Error(_t("Could not serialize XML"));
}
};
-instance.web.str_to_xml = function(s) {
- if (window.DOMParser) {
- var dp = new DOMParser();
- var r = dp.parseFromString(s, "text/xml");
- if (r.body && r.body.firstChild && r.body.firstChild.nodeName == 'parsererror') {
- throw new Error(_t("Could not parse string to xml"));
- }
- return r;
- }
- var xDoc;
- try {
- xDoc = new ActiveXObject("MSXML2.DOMDocument");
- } catch (e) {
- throw new Error(_.str.sprintf( _t("Could not find a DOM Parser: %s"), e.message));
- }
- xDoc.async = false;
- xDoc.preserveWhiteSpace = true;
- xDoc.loadXML(s);
- return xDoc;
-}
/**
* Registry for all the main views