}
});
- 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') {
++ 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) {