c67821502978738825847b59ab440d653568276c
[odoo/odoo.git] / addons / base / static / src / js / views.js
1 /*---------------------------------------------------------
2  * OpenERP base library
3  *---------------------------------------------------------*/
4
5 openerp.base.views = function(openerp) {
6
7 var _t = openerp.base._t;
8
9 /**
10  * Registry for all the client actions key: tag value: widget
11  */
12 openerp.base.client_actions = new openerp.base.Registry();
13
14 openerp.base.ActionManager = openerp.base.Widget.extend({
15     identifier_prefix: "actionmanager",
16     init: function(parent) {
17         this._super(parent);
18         this.inner_viewmanager = null;
19         this.dialog = null;
20         this.dialog_viewmanager = null;
21         this.client_widget = null;
22         this.url = {}
23     },
24     render: function() {
25         return "<div id='"+this.element_id+"'></div>";
26     },
27     dialog_stop: function () {
28         if (this.dialog) {
29             this.dialog_viewmanager.stop();
30             this.dialog_viewmanager = null;
31             this.dialog.stop();
32             this.dialog = null;
33         }
34     },
35     content_stop: function () {
36         if (this.inner_viewmanager) {
37             this.inner_viewmanager.stop();
38             this.inner_viewmanager = null;
39         }
40         if (this.client_widget) {
41             this.client_widget.stop();
42             this.client_widget = null;
43         }
44     },
45     url_update: function(action) {
46         // this.url = {
47         //     "model": action.model,
48         //     "domain": action.domain,
49         // };
50         // action.res_model
51         // action.domain
52         // action.context
53         // after
54         // action.views
55         // action.res_id
56         // mode
57         // menu
58     },
59     url_stringify: function(action) {
60     },
61     url_parse: function(action) {
62     },
63     on_url_update: function(url) {
64     },
65     do_url_action: function(url) {
66     },
67     do_action: function(action, on_close) {
68         var type = action.type.replace(/\./g,'_');
69         var popup = action.target === 'new';
70         action.flags = _.extend({
71             views_switcher : !popup,
72             search_view : !popup,
73             action_buttons : !popup,
74             sidebar : !popup,
75             pager : !popup
76         }, action.flags || {});
77         if (!(type in this)) {
78             this.log("Action manager can't handle action of type " + action.type, action);
79             return;
80         }
81         this[type](action, on_close);
82     },
83     ir_actions_act_window: function (action, on_close) {
84         if (action.target === 'new') {
85             if (this.dialog == null) {
86                 this.dialog = new openerp.base.Dialog(this, { title: action.name, width: '80%' });
87                 if(on_close)
88                     this.dialog.on_close.add(on_close);
89                 this.dialog.start();
90             } else {
91                 this.dialog_viewmanager.stop();
92             }
93             this.dialog_viewmanager = new openerp.base.ViewManagerAction(this, action);
94             this.dialog_viewmanager.appendTo(this.dialog.$element);
95             this.dialog.open();
96         } else  {
97             this.dialog_stop();
98             this.content_stop();
99             this.inner_viewmanager = new openerp.base.ViewManagerAction(this, action);
100             this.inner_viewmanager.appendTo(this.$element);
101             this.url_update(action);
102         }
103         /* new window code
104             this.rpc("/base/session/save_session_action", { the_action : action}, function(key) {
105                 var url = window.location.protocol + "//" + window.location.host + window.location.pathname + "?" + jQuery.param({ s_action : "" + key });
106                 window.open(url,'_blank');
107             });
108         */
109     },
110     ir_actions_act_window_close: function (action, on_closed) {
111         this.dialog_stop();
112     },
113     ir_actions_server: function (action, on_closed) {
114         var self = this;
115         this.rpc('/base/action/run', {
116             action_id: action.id,
117             context: {active_id: 66, active_ids: [66], active_model: 'ir.ui.menu'}
118         }).then(function (action) {
119             self.do_action(action, on_closed)
120         });
121     },
122     ir_actions_client: function (action) {
123         this.content_stop();
124         var ClientWidget = openerp.base.client_actions.get_object(action.tag);
125         (this.client_widget = new ClientWidget(this, action.params)).appendTo(this);
126     }
127 });
128
129 openerp.base.ViewManager =  openerp.base.Widget.extend({
130     identifier_prefix: "viewmanager",
131     init: function(parent, dataset, views) {
132         this._super(parent);
133         this.model = dataset.model;
134         this.dataset = dataset;
135         this.searchview = null;
136         this.active_view = null;
137         this.views_src = _.map(views, function(x) {return x instanceof Array? {view_id: x[0], view_type: x[1]} : x;});
138         this.views = {};
139         this.flags = this.flags || {};
140         this.registry = openerp.base.views;
141     },
142     render: function() {
143         return QWeb.render("ViewManager", {"prefix": this.element_id, views: this.views_src})
144     },
145     /**
146      * @returns {jQuery.Deferred} initial view loading promise
147      */
148     start: function() {
149         this._super();
150         var self = this;
151         this.dataset.start();
152         this.$element.find('.oe_vm_switch button').click(function() {
153             self.on_mode_switch($(this).data('view-type'));
154         });
155         var views_ids = {};
156         _.each(this.views_src, function(view) {
157             self.views[view.view_type] = $.extend({}, view, {
158                 controller : null,
159                 options : _.extend({
160                     sidebar_id : self.element_id + '_sidebar_' + view.view_type,
161                     action : self.action,
162                     action_views_ids : views_ids
163                 }, self.flags, view.options || {})
164             });
165             views_ids[view.view_type] = view.view_id;
166         });
167         if (this.flags.views_switcher === false) {
168             this.$element.find('.oe_vm_switch').hide();
169         }
170         // switch to the first one in sequence
171         return this.on_mode_switch(this.views_src[0].view_type);
172     },
173     /**
174      * Asks the view manager to switch visualization mode.
175      *
176      * @param {String} view_type type of view to display
177      * @returns {jQuery.Deferred} new view loading promise
178      */
179     on_mode_switch: function(view_type) {
180         var self = this,
181             view_promise;
182         this.active_view = view_type;
183         var view = this.views[view_type];
184         if (!view.controller) {
185             // Lazy loading of views
186             var controllerclass = this.registry.get_object(view_type);
187             var controller = new controllerclass(this, this.element_id + '_view_' + view_type,
188                 this.dataset, view.view_id, view.options);
189             if (view.embedded_view) {
190                 controller.set_embedded_view(view.embedded_view);
191             }
192             controller.do_switch_view.add_last(this.on_mode_switch);
193             if (view_type === 'list' && this.flags.search_view === false && this.action && this.action['auto_search']) {
194                 // In case the search view is not instantiated: manually call ListView#search
195                 var domains = !_(self.action.domain).isEmpty()
196                                 ? [self.action.domain] : [],
197                    contexts = !_(self.action.context).isEmpty()
198                                 ? [self.action.context] : [];
199                 controller.on_loaded.add({
200                     callback: function () {
201                         controller.do_search(domains, contexts, []);
202                     },
203                     position: 'last',
204                     unique: true
205                 });
206             }
207             view_promise = controller.start();
208             $.when(view_promise).then(function() {
209                 self.on_controller_inited(view_type, controller);
210             });
211             this.views[view_type].controller = controller;
212         }
213
214
215         if (this.searchview) {
216             if (view.controller.searchable === false) {
217                 this.searchview.hide();
218             } else {
219                 this.searchview.show();
220             }
221         }
222
223         this.$element
224             .find('.views-switchers button').removeAttr('disabled')
225             .filter('[data-view-type="' + view_type + '"]')
226             .attr('disabled', true);
227
228         for (var view_name in this.views) {
229             if (!this.views.hasOwnProperty(view_name)) { continue; }
230             if (this.views[view_name].controller) {
231                 if (view_name === view_type) {
232                     $.when(view_promise).then(this.views[view_name].controller.do_show);
233                 } else {
234                     this.views[view_name].controller.do_hide();
235                 }
236             }
237         }
238         return view_promise;
239     },
240     /**
241      * Event launched when a controller has been inited.
242      * 
243      * @param {String} view_type type of view
244      * @param {String} view the inited controller
245      */
246     on_controller_inited: function(view_type, view) {
247     },
248     /**
249      * Sets up the current viewmanager's search view.
250      *
251      * @param view_id the view to use or false for a default one
252      * @returns {jQuery.Deferred} search view startup deferred
253      */
254     setup_search_view: function(view_id, search_defaults) {
255         var self = this;
256         if (this.searchview) {
257             this.searchview.stop();
258         }
259         this.searchview = new openerp.base.SearchView(this, this.element_id + "_search", this.dataset, view_id, search_defaults);
260         if (this.flags.search_view === false) {
261             this.searchview.hide();
262         }
263         this.searchview.on_search.add(function(domains, contexts, groupbys) {
264             var controller = self.views[self.active_view].controller;
265             controller.do_search.call(controller, domains, contexts, groupbys);
266         });
267         return this.searchview.start();
268     },
269     /**
270      * Called when one of the view want to execute an action
271      */
272     on_action: function(action) {
273     },
274     on_create: function() {
275     },
276     on_remove: function() {
277     },
278     on_edit: function() {
279     }
280 });
281
282 openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({
283     init: function(parent, action) {
284         this.session = parent.session;
285         this.action = action;
286         var dataset;
287         if (!action.res_id) {
288             dataset = new openerp.base.DataSetSearch(this, action.res_model, action.context, action.domain);
289         } else {
290             this.action.flags.search_view = false;
291             dataset = new openerp.base.DataSetStatic(this, action.res_model, action.context, [action.res_id]);
292             dataset.index = 0;
293         }
294         this._super(parent, dataset, action.views);
295         this.action = action;
296         this.flags = this.action.flags || {};
297         if (action.res_model == 'board.board' && action.views.length == 1 && action.views) {
298             // Not elegant but allows to avoid flickering of SearchView#do_hide
299             this.flags.search_view = this.flags.pager = this.flags.sidebar = this.flags.action_buttons = false;
300         }
301     },
302     start: function() {
303         var inital_view_loaded = this._super();
304
305         var search_defaults = {};
306         _.each(this.action.context, function (value, key) {
307             var match = /^search_default_(.*)$/.exec(key);
308             if (match) {
309                 search_defaults[match[1]] = value;
310             }
311         });
312
313         if (this.flags.search_view !== false) {
314             // init search view
315             var searchview_id = this.action.search_view_id && this.action.search_view_id[0];
316
317             var searchview_loaded = this.setup_search_view(
318                     searchview_id || false, search_defaults);
319             
320             // schedule auto_search
321             if (searchview_loaded != null && this.action['auto_search']) {
322                 $.when(searchview_loaded, inital_view_loaded)
323                     .then(this.searchview.do_search);
324             }
325         }
326     },
327     on_mode_switch: function (view_type) {
328         this._super(view_type);
329         this.shortcut_check(this.views[view_type]);
330     },
331     shortcut_check : function(view) {
332         var self = this;
333         var grandparent = this.widget_parent && this.widget_parent.widget_parent;
334         // display shortcuts if on the first view for the action
335         var $shortcut_toggle = this.$element.find('.oe-shortcut-toggle');
336         if (!(grandparent instanceof openerp.base.WebClient) ||
337             !(view.view_type === this.views_src[0].view_type
338                 && view.view_id === this.views_src[0].view_id)) {
339             $shortcut_toggle.hide();
340             return;
341         }
342         $shortcut_toggle.removeClass('oe-shortcut-remove').show();
343         if (_(this.session.shortcuts).detect(function (shortcut) {
344                     return shortcut.res_id === self.session.active_id; })) {
345             $shortcut_toggle.addClass("oe-shortcut-remove");
346         }
347         this.shortcut_add_remove();
348     },
349     shortcut_add_remove: function() {
350         var self = this;
351         var $shortcut_toggle = this.$element.find('.oe-shortcut-toggle');
352         $shortcut_toggle.click(function() {
353             if ($shortcut_toggle.hasClass("oe-shortcut-remove")) {
354                 $(self.session.shortcuts.binding).trigger('remove-current');
355                 $shortcut_toggle.removeClass("oe-shortcut-remove");
356             } else {
357                 $(self.session.shortcuts.binding).trigger('add', {
358                     'user_id': self.session.uid,
359                     'res_id': self.session.active_id,
360                     'resource': 'ir.ui.menu',
361                     'name': self.action.name
362                 });
363                 $shortcut_toggle.addClass("oe-shortcut-remove");
364             }
365         });
366     }
367 });
368
369 openerp.base.Sidebar = openerp.base.Widget.extend({
370     init: function(parent, element_id) {
371         this._super(parent, element_id);
372         this.items = {};
373         this.sections = {};
374     },
375     start: function() {
376         var self = this;
377         this._super(this, arguments);
378         this.$element.html(QWeb.render('Sidebar'));
379         this.$element.find(".toggle-sidebar").click(function(e) {
380             self.do_toggle();
381         });
382     },
383     add_toolbar: function(toolbar) {
384         var self = this;
385         _.each([['print', "Reports"], ['action', "Actions"], ['relate', "Links"]], function(type) {
386             var items = toolbar[type[0]];
387             if (items.length) {
388                 for (var i = 0; i < items.length; i++) {
389                     items[i] = {
390                         label: items[i]['name'],
391                         action: items[i],
392                         classname: 'oe_sidebar_' + type[0]
393                     }
394                 }
395                 self.add_section(type[0], type[1], items);
396             }
397         });
398     },
399     add_section: function(code, name, items) {
400         // For each section, we pass a name/label and optionally an array of items.
401         // If no items are passed, then the section will be created as a custom section
402         // returning back an element_id to be used by a custom controller.
403         // Else, the section is a standard section with items displayed as links.
404         // An item is a dictonary : {
405         //    label: label to be displayed for the link,
406         //    action: action to be launch when the link is clicked,
407         //    callback: a function to be executed when the link is clicked,
408         //    classname: optional dom class name for the line,
409         //    title: optional title for the link
410         // }
411         // Note: The item should have one action or/and a callback
412         var self = this,
413             section_id = _.uniqueId(this.element_id + '_section_' + code + '_');
414         if (items) {
415             for (var i = 0; i < items.length; i++) {
416                 items[i].element_id = _.uniqueId(section_id + '_item_');
417                 this.items[items[i].element_id] = items[i];
418             }
419         }
420         var $section = $(QWeb.render("Sidebar.section", {
421             section_id: section_id,
422             name: name,
423             classname: 'oe_sidebar_' + code,
424             items: items
425         }));
426         if (items) {
427             $section.find('a.oe_sidebar_action_a').click(function() {
428                 var item = self.items[$(this).attr('id')];
429                 if (item.callback) {
430                     item.callback();
431                 }
432                 if (item.action) {
433                     item.action.flags = item.action.flags || {};
434                     item.action.flags.new_window = true;
435                     self.do_action(item.action);
436                 }
437                 return false;
438             });
439         }
440         $section.appendTo(this.$element.find('div.sidebar-actions'));
441         this.sections[code] = $section;
442         return section_id;
443     },
444     do_fold: function() {
445         this.$element.addClass('closed-sidebar').removeClass('open-sidebar');
446     },
447     do_unfold: function() {
448         this.$element.addClass('open-sidebar').removeClass('closed-sidebar');
449     },
450     do_toggle: function() {
451         this.$element.toggleClass('open-sidebar closed-sidebar');
452     }
453 });
454
455 openerp.base.TranslateDialog = openerp.base.Dialog.extend({
456     dialog_title: _t("Translations"),
457     init: function(view) {
458         this['on_button' + _t("Save")] = this.on_button_Save;
459         this['on_button' + _t("Close")] = this.on_button_Close;
460         this._super(view, {
461             width: '80%',
462             height: '80%'
463         });
464         this.view = view;
465         this.view_type = view.fields_view.type || '';
466         this.$fields_form = null;
467         this.$view_form = null;
468         this.$sidebar_form = null;
469         this.translatable_fields_keys = _.map(this.view.translatable_fields || [], function(i) { return i.name });
470         this.languages = null;
471         this.languages_loaded = $.Deferred();
472         (new openerp.base.DataSetSearch(this, 'res.lang', this.view.dataset.get_context(),
473             [['translatable', '=', '1']])).read_slice(['code', 'name'], { sort: 'id' }, this.on_languages_loaded);
474     },
475     start: function() {
476         var self = this;
477         this._super();
478         $.when(this.languages_loaded).then(function() {
479             self.$element.html(QWeb.render('TranslateDialog', { widget: self }));
480             self.$element.tabs();
481             if (!(self.view.translatable_fields && self.view.translatable_fields.length)) {
482                 self.hide_tabs('fields');
483                 self.select_tab('view');
484             }
485             self.$fields_form = self.$element.find('.oe_translation_form');
486         });
487         return this;
488     },
489     on_languages_loaded: function(langs) {
490         this.languages = langs;
491         this.languages_loaded.resolve();
492     },
493     do_load_fields_values: function(callback) {
494         var self = this,
495             deffered = [];
496         this.$fields_form.find('.oe_trad_field').val('').removeClass('touched');
497         _.each(self.languages, function(lg) {
498             var deff = $.Deferred();
499             deffered.push(deff);
500             self.rpc('/base/dataset/get', {
501                 model: self.view.dataset.model,
502                 ids: [self.view.datarecord.id],
503                 fields: self.translatable_fields_keys,
504                 context: self.view.dataset.get_context({
505                     'lang': lg.code
506                 })
507             }, function(values) {
508                 _.each(self.translatable_fields_keys, function(f) {
509                     self.$fields_form.find('.oe_trad_field[name="' + lg.code + '-' + f + '"]').val(values[0][f] || '');
510                 });
511                 deff.resolve();
512             });
513         });
514         $.when.apply(null, deffered).then(callback);
515     },
516     show_tabs: function() {
517         for (var i = 0; i < arguments.length; i++) {
518             this.$element.find('ul.oe_translate_tabs li a[href$="' + arguments[i] + '"]').parent().show();
519         }
520     },
521     hide_tabs: function() {
522         for (var i = 0; i < arguments.length; i++) {
523             this.$element.find('ul.oe_translate_tabs li a[href$="' + arguments[i] + '"]').parent().hide();
524         }
525     },
526     select_tab: function(name) {
527         this.show_tabs(name);
528         var index = this.$element.find('ul.oe_translate_tabs li a[href$="' + arguments[i] + '"]').parent().index() - 1;
529         this.$element.tabs('select', index);
530     },
531     open: function(field) {
532         var self = this,
533             super = this._super;
534         $.when(this.languages_loaded).then(function() {
535             if (self.view.translatable_fields && self.view.translatable_fields.length) {
536                 self.do_load_fields_values(function() {
537                     super.call(self);
538                     if (field) {
539                         // TODO: focus and scroll to field
540                     }
541                 });
542             } else {
543                 super.call(self);
544             }
545         });
546     },
547     on_button_Save: function() {
548         this.close();
549     },
550     on_button_Close: function() {
551         this.close();
552     }
553 });
554
555 openerp.base.View = openerp.base.Widget.extend({
556     set_default_options: function(options) {
557         this.options = options || {};
558         _.defaults(this.options, {
559             // All possible views options should be defaulted here
560             sidebar_id: null,
561             sidebar: true,
562             action: null,
563             action_views_ids: {}
564         });
565     },
566     open_translate_dialog: function(field) {
567         if (!this.translate_dialog) {
568             this.translate_dialog = new openerp.base.TranslateDialog(this).start();
569         }
570         this.translate_dialog.open(field);
571     },
572     /**
573      * Fetches and executes the action identified by ``action_data``.
574      *
575      * @param {Object} action_data the action descriptor data
576      * @param {String} action_data.name the action name, used to uniquely identify the action to find and execute it
577      * @param {String} [action_data.special=null] special action handlers (currently: only ``'cancel'``)
578      * @param {String} [action_data.type='workflow'] the action type, if present, one of ``'object'``, ``'action'`` or ``'workflow'``
579      * @param {Object} [action_data.context=null] additional action context, to add to the current context
580      * @param {openerp.base.DataSet} dataset a dataset object used to communicate with the server
581      * @param {Object} [record_id] the identifier of the object on which the action is to be applied
582      * @param {Function} on_closed callback to execute when dialog is closed or when the action does not generate any result (no new action)
583      */
584     execute_action: function (action_data, dataset, record_id, on_closed) {
585         var self = this;
586         var handler = function (r) {
587             var action = r.result;
588             if (action && action.constructor == Object) {
589                 action.context = action.context || {};
590                 _.extend(action.context, {
591                     active_id: record_id || false,
592                     active_ids: [record_id || false],
593                     active_model: dataset.model
594                 });
595                 self.do_action(action, on_closed);
596             } else if (on_closed) {
597                 on_closed(action);
598             }
599         };
600
601         var context = new openerp.base.CompoundContext(dataset.get_context(), action_data.context || {});
602
603         if (action_data.special) {
604             handler({result: {"type":"ir.actions.act_window_close"}});
605         } else if (action_data.type=="object") {
606             return dataset.call_button(action_data.name, [[record_id], context], handler);
607         } else if (action_data.type=="action") {
608             return this.rpc('/base/action/load', { action_id: parseInt(action_data.name, 10), context: context }, handler);
609         } else  {
610             return dataset.exec_workflow(record_id, action_data.name, handler);
611         } 
612     },
613     /**
614      * Directly set a view to use instead of calling fields_view_get. This method must
615      * be called before start(). When an embedded view is set, underlying implementations
616      * of openerp.base.View must use the provided view instead of any other one.
617      * 
618      * @param embedded_view A view.
619      */
620     set_embedded_view: function(embedded_view) {
621         this.embedded_view = embedded_view;
622         this.options.sidebar = false;
623     },
624     do_switch_view: function(view) {
625     },
626     set_common_sidebar_sections: function(sidebar) {
627         sidebar.add_section('customize', "Customize", [
628             {
629                 label: "Manage Views",
630                 callback: this.on_sidebar_manage_view,
631                 title: "Manage views of the current object"
632             }, {
633                 label: "Edit Workflow",
634                 callback: this.on_sidebar_edit_workflow,
635                 title: "Manage views of the current object",
636                 classname: 'oe_hide oe_sidebar_edit_workflow'
637             }, {
638                 label: "Customize Object",
639                 callback: this.on_sidebar_customize_object,
640                 title: "Manage views of the current object"
641             }
642         ]);
643         sidebar.add_section('other', "Other Options", [
644             {
645                 label: "Import",
646                 callback: this.on_sidebar_import
647             }, {
648                 label: "Export",
649                 callback: this.on_sidebar_export
650             }, {
651                 label: "Translate",
652                 callback: this.on_sidebar_translate,
653                 classname: 'oe_sidebar_translate'
654             }, {
655                 label: "View Log",
656                 callback: this.on_sidebar_view_log,
657                 classname: 'oe_hide oe_sidebar_view_log'
658             }
659         ]);
660     },
661     on_sidebar_manage_view: function() {
662         if (this.fields_view && this.fields_view.arch) {
663             $('<xmp>' + openerp.base.json_node_to_xml(this.fields_view.arch, true) + '</xmp>').dialog({ width: '95%', height: 600});
664         } else {
665             this.notification.warn("Manage Views", "Could not find current view declaration");
666         }
667     },
668     on_sidebar_edit_workflow: function() {
669         this.log('Todo');
670     },
671     on_sidebar_customize_object: function() {
672         this.log('Todo');
673     },
674     on_sidebar_import: function() {
675     },
676     on_sidebar_export: function() {
677         var export_view = new openerp.base.DataExport(this, this.dataset);
678         export_view.start();
679     },
680     on_sidebar_translate: function() {
681         this.open_translate_dialog();
682     },
683     on_sidebar_view_log: function() {
684     }
685 });
686
687 /**
688  * Registry for all the main views
689  */
690 openerp.base.views = new openerp.base.Registry();
691
692 openerp.base.json_node_to_xml = function(node, single_quote, indent) {
693     // For debugging purpose, this function will convert a json node back to xml
694     // Maybe usefull for xml view editor
695     if (typeof(node.tag) !== 'string' || !node.children instanceof Array || !node.attrs instanceof Object) {
696         throw("Node a json node");
697     }
698     indent = indent || 0;
699     var sindent = new Array(indent + 1).join('\t'),
700         r = sindent + '<' + node.tag;
701     for (var attr in node.attrs) {
702         var vattr = node.attrs[attr];
703         if (typeof(vattr) !== 'string') {
704             // domains, ...
705             vattr = JSON.stringify(vattr);
706         }
707         vattr = vattr.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
708         if (single_quote) {
709             vattr = vattr.replace(/&quot;/g, "'");
710         }
711         r += ' ' + attr + '="' + vattr + '"';
712     }
713     if (node.children.length) {
714         r += '>\n';
715         var childs = [];
716         for (var i = 0, ii = node.children.length; i < ii; i++) {
717             childs.push(openerp.base.json_node_to_xml(node.children[i], single_quote, indent + 1));
718         }
719         r += childs.join('\n');
720         r += '\n' + sindent + '</' + node.tag + '>';
721         return r;
722     } else {
723         return r + '/>';
724     }
725 }
726
727 };
728
729 // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: