summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorFabien Meghazi <fme@openerp.com>2012-12-04 17:39:48 +0100
committerFabien Meghazi <fme@openerp.com>2012-12-04 17:39:48 +0100
commit58b44d50824d082aec6ef05742823a8da7a65e14 (patch)
tree70d7919063cb94bfb2e03c69296b6c57f39e2cbd /addons/web/static/src/js
parentae53b85d90fe3e1644d0f44d49bae75f38e95709 (diff)
[IMP] Removed fields_view_get from controllers. Add a helper client side.
bzr revid: fme@openerp.com-20121204163948-pctxvy55w34e1pg9
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/search.js6
-rw-r--r--addons/web/static/src/js/view_tree.js14
-rw-r--r--addons/web/static/src/js/views.js71
3 files changed, 51 insertions, 40 deletions
diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js
index 3917f342391..eea8bba726d 100644
--- a/addons/web/static/src/js/search.js
+++ b/addons/web/static/src/js/search.js
@@ -341,12 +341,10 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
if (this.headless) {
this.ready.resolve();
} else {
- var load_view = this.rpc("/web/view/load", {
- model: this.model,
+ var load_view = instance.web.fields_view_get({
+ model: this.dataset._model,
view_id: this.view_id,
view_type: 'search',
- context: instance.web.pyeval.eval(
- 'context', this.dataset.get_context())
});
$.when(load_view).then(function (r) {
diff --git a/addons/web/static/src/js/view_tree.js b/addons/web/static/src/js/view_tree.js
index 4d08da385fd..a68b92bc33a 100644
--- a/addons/web/static/src/js/view_tree.js
+++ b/addons/web/static/src/js/view_tree.js
@@ -9,6 +9,7 @@ var QWeb = instance.web.qweb,
instance.web.views.add('tree', 'instance.web.TreeView');
instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeView# */{
display_name: _lt('Tree'),
+ view_type: 'tree',
/**
* Indicates that this view is not searchable, and thus that no search
* view should be displayed (if there is one active).
@@ -36,18 +37,9 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie
this.options = _.extend({}, this.defaults, options || {});
_.bindAll(this, 'color_for');
+ this.on('view_loaded', self, self.load_tree);
},
- start: function () {
- return this.rpc("/web/treeview/load", {
- model: this.model,
- view_id: this.view_id,
- view_type: "tree",
- toolbar: this.view_manager ? !!this.view_manager.sidebar : false,
- context: instance.web.pyeval.eval(
- 'context', this.dataset.get_context())
- }).done(this.on_loaded);
- },
/**
* Returns the list of fields needed to correctly read objects.
*
@@ -64,7 +56,7 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie
}
return fields;
},
- on_loaded: function (fields_view) {
+ load_tree: function (fields_view) {
var self = this;
var has_toolbar = !!fields_view.arch.attrs.toolbar;
// field name in OpenERP is kinda stupid: this is the name of the field
diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js
index 939c98015bc..607e8fc7ed8 100644
--- a/addons/web/static/src/js/views.js
+++ b/addons/web/static/src/js/views.js
@@ -1204,13 +1204,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) {
@@ -1385,8 +1383,51 @@ instance.web.View = instance.web.Widget.extend({
}
});
+/**
+ * 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) {
+ fvg.arch_string = fvg.arch;
+ fvg.arch_doc = $.parseXML(fvg.arch);
+ fvg.arch = instance.web.xml_to_json(fvg.arch_doc);
+ 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) {
switch (node.nodeType) {
+ case 9:
+ return instance.web.xml_to_json(node.documentElement);
case 3:
case 4:
return node.data;
@@ -1455,26 +1496,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