ee5529262f78895da2ca393eb8a7285c9f203904
[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         return $.when(
329             this._super(view_type),
330             this.shortcut_check(this.views[view_type]));
331     },
332     shortcut_check : function(view) {
333         var self = this;
334         var grandparent = this.widget_parent && this.widget_parent.widget_parent;
335         // display shortcuts if on the first view for the action
336         var $shortcut_toggle = this.$element.find('.oe-shortcut-toggle');
337         if (!(grandparent instanceof openerp.base.WebClient) ||
338             !(view.view_type === this.views_src[0].view_type
339                 && view.view_id === this.views_src[0].view_id)) {
340             $shortcut_toggle.hide();
341             return;
342         }
343         $shortcut_toggle.removeClass('oe-shortcut-remove').show();
344         if (_(this.session.shortcuts).detect(function (shortcut) {
345                     return shortcut.res_id === self.session.active_id; })) {
346             $shortcut_toggle.addClass("oe-shortcut-remove");
347         }
348         this.shortcut_add_remove();
349     },
350     shortcut_add_remove: function() {
351         var self = this;
352         var $shortcut_toggle = this.$element.find('.oe-shortcut-toggle');
353         $shortcut_toggle
354             .unbind("click")
355             .click(function() {
356                 if ($shortcut_toggle.hasClass("oe-shortcut-remove")) {
357                     $(self.session.shortcuts.binding).trigger('remove-current');
358                     $shortcut_toggle.removeClass("oe-shortcut-remove");
359                 } else {
360                     $(self.session.shortcuts.binding).trigger('add', {
361                         'user_id': self.session.uid,
362                         'res_id': self.session.active_id,
363                         'resource': 'ir.ui.menu',
364                         'name': self.action.name
365                     });
366                     $shortcut_toggle.addClass("oe-shortcut-remove");
367                 }
368             });
369     }
370 });
371
372 openerp.base.Sidebar = openerp.base.Widget.extend({
373     init: function(parent, element_id) {
374         this._super(parent, element_id);
375         this.items = {};
376         this.sections = {};
377     },
378     start: function() {
379         this._super(this);
380         this.$element.html(QWeb.render('Sidebar'));
381         this.$element.find(".toggle-sidebar").click(function(e) {
382             self.do_toggle();
383         });
384     },
385     add_toolbar: function(toolbar) {
386         var self = this;
387         _.each([['print', "Reports"], ['action', "Actions"], ['relate', "Links"]], function(type) {
388             var items = toolbar[type[0]];
389             if (items.length) {
390                 for (var i = 0; i < items.length; i++) {
391                     items[i] = {
392                         label: items[i]['name'],
393                         action: items[i],
394                         classname: 'oe_sidebar_' + type[0]
395                     }
396                 }
397                 self.add_section(type[0], type[1], items);
398             }
399         });
400     },
401     add_section: function(code, name, items) {
402         // For each section, we pass a name/label and optionally an array of items.
403         // If no items are passed, then the section will be created as a custom section
404         // returning back an element_id to be used by a custom controller.
405         // Else, the section is a standard section with items displayed as links.
406         // An item is a dictonary : {
407         //    label: label to be displayed for the link,
408         //    action: action to be launch when the link is clicked,
409         //    callback: a function to be executed when the link is clicked,
410         //    classname: optional dom class name for the line,
411         //    title: optional title for the link
412         // }
413         // Note: The item should have one action or/and a callback
414         var self = this,
415             section_id = _.uniqueId(this.element_id + '_section_' + code + '_');
416         if (items) {
417             for (var i = 0; i < items.length; i++) {
418                 items[i].element_id = _.uniqueId(section_id + '_item_');
419                 this.items[items[i].element_id] = items[i];
420             }
421         }
422         var $section = $(QWeb.render("Sidebar.section", {
423             section_id: section_id,
424             name: name,
425             classname: 'oe_sidebar_' + code,
426             items: items
427         }));
428         if (items) {
429             $section.find('a.oe_sidebar_action_a').click(function() {
430                 var item = self.items[$(this).attr('id')];
431                 if (item.callback) {
432                     item.callback();
433                 }
434                 if (item.action) {
435                     item.action.flags = item.action.flags || {};
436                     item.action.flags.new_window = true;
437                     self.do_action(item.action);
438                 }
439                 return false;
440             });
441         }
442         $section.appendTo(this.$element.find('div.sidebar-actions'));
443         this.sections[code] = $section;
444         return section_id;
445     },
446     do_fold: function() {
447         this.$element.addClass('closed-sidebar').removeClass('open-sidebar');
448     },
449     do_unfold: function() {
450         this.$element.addClass('open-sidebar').removeClass('closed-sidebar');
451     },
452     do_toggle: function() {
453         this.$element.toggleClass('open-sidebar closed-sidebar');
454     }
455 });
456
457 openerp.base.TranslateDialog = openerp.base.Dialog.extend({
458     dialog_title: _t("Translations"),
459     init: function(view) {
460         this['on_button' + _t("Save")] = this.on_button_Save;
461         this['on_button' + _t("Close")] = this.on_button_Close;
462         this._super(view, {
463             width: '80%',
464             height: '80%'
465         });
466         this.view = view;
467         this.view_type = view.fields_view.type || '';
468         this.$fields_form = null;
469         this.$view_form = null;
470         this.$sidebar_form = null;
471         this.translatable_fields_keys = _.map(this.view.translatable_fields || [], function(i) { return i.name });
472         this.languages = null;
473         this.languages_loaded = $.Deferred();
474         (new openerp.base.DataSetSearch(this, 'res.lang', this.view.dataset.get_context(),
475             [['translatable', '=', '1']])).read_slice(['code', 'name'], { sort: 'id' }, this.on_languages_loaded);
476     },
477     start: function() {
478         var self = this;
479         this._super();
480         $.when(this.languages_loaded).then(function() {
481             self.$element.html(QWeb.render('TranslateDialog', { widget: self }));
482             self.$element.tabs();
483             if (!(self.view.translatable_fields && self.view.translatable_fields.length)) {
484                 self.hide_tabs('fields');
485                 self.select_tab('view');
486             }
487             self.$fields_form = self.$element.find('.oe_translation_form');
488         });
489         return this;
490     },
491     on_languages_loaded: function(langs) {
492         this.languages = langs;
493         this.languages_loaded.resolve();
494     },
495     do_load_fields_values: function(callback) {
496         var self = this,
497             deffered = [];
498         this.$fields_form.find('.oe_trad_field').val('').removeClass('touched');
499         _.each(self.languages, function(lg) {
500             var deff = $.Deferred();
501             deffered.push(deff);
502             self.rpc('/base/dataset/get', {
503                 model: self.view.dataset.model,
504                 ids: [self.view.datarecord.id],
505                 fields: self.translatable_fields_keys,
506                 context: self.view.dataset.get_context({
507                     'lang': lg.code
508                 })
509             }, function(values) {
510                 _.each(self.translatable_fields_keys, function(f) {
511                     self.$fields_form.find('.oe_trad_field[name="' + lg.code + '-' + f + '"]').val(values[0][f] || '');
512                 });
513                 deff.resolve();
514             });
515         });
516         $.when.apply(null, deffered).then(callback);
517     },
518     show_tabs: function() {
519         for (var i = 0; i < arguments.length; i++) {
520             this.$element.find('ul.oe_translate_tabs li a[href$="' + arguments[i] + '"]').parent().show();
521         }
522     },
523     hide_tabs: function() {
524         for (var i = 0; i < arguments.length; i++) {
525             this.$element.find('ul.oe_translate_tabs li a[href$="' + arguments[i] + '"]').parent().hide();
526         }
527     },
528     select_tab: function(name) {
529         this.show_tabs(name);
530         var index = this.$element.find('ul.oe_translate_tabs li a[href$="' + arguments[i] + '"]').parent().index() - 1;
531         this.$element.tabs('select', index);
532     },
533     open: function(field) {
534         var self = this,
535             sup = this._super;
536         $.when(this.languages_loaded).then(function() {
537             if (self.view.translatable_fields && self.view.translatable_fields.length) {
538                 self.do_load_fields_values(function() {
539                     sup.call(self);
540                     if (field) {
541                         // TODO: focus and scroll to field
542                     }
543                 });
544             } else {
545                 sup.call(self);
546             }
547         });
548     },
549     on_button_Save: function() {
550         this.close();
551     },
552     on_button_Close: function() {
553         this.close();
554     }
555 });
556
557 openerp.base.View = openerp.base.Widget.extend({
558     set_default_options: function(options) {
559         this.options = options || {};
560         _.defaults(this.options, {
561             // All possible views options should be defaulted here
562             sidebar_id: null,
563             sidebar: true,
564             action: null,
565             action_views_ids: {}
566         });
567     },
568     open_translate_dialog: function(field) {
569         if (!this.translate_dialog) {
570             this.translate_dialog = new openerp.base.TranslateDialog(this).start();
571         }
572         this.translate_dialog.open(field);
573     },
574     /**
575      * Fetches and executes the action identified by ``action_data``.
576      *
577      * @param {Object} action_data the action descriptor data
578      * @param {String} action_data.name the action name, used to uniquely identify the action to find and execute it
579      * @param {String} [action_data.special=null] special action handlers (currently: only ``'cancel'``)
580      * @param {String} [action_data.type='workflow'] the action type, if present, one of ``'object'``, ``'action'`` or ``'workflow'``
581      * @param {Object} [action_data.context=null] additional action context, to add to the current context
582      * @param {openerp.base.DataSet} dataset a dataset object used to communicate with the server
583      * @param {Object} [record_id] the identifier of the object on which the action is to be applied
584      * @param {Function} on_closed callback to execute when dialog is closed or when the action does not generate any result (no new action)
585      */
586     execute_action: function (action_data, dataset, record_id, on_closed) {
587         var self = this;
588         var handler = function (r) {
589             var action = r.result;
590             if (action && action.constructor == Object) {
591                 action.context = action.context || {};
592                 _.extend(action.context, {
593                     active_id: record_id || false,
594                     active_ids: [record_id || false],
595                     active_model: dataset.model
596                 });
597                 self.do_action(action, on_closed);
598             } else if (on_closed) {
599                 on_closed(action);
600             }
601         };
602
603         var context = new openerp.base.CompoundContext(dataset.get_context(), action_data.context || {});
604
605         if (action_data.special) {
606             handler({result: {"type":"ir.actions.act_window_close"}});
607         } else if (action_data.type=="object") {
608             return dataset.call_button(action_data.name, [[record_id], context], handler);
609         } else if (action_data.type=="action") {
610             return this.rpc('/base/action/load', { action_id: parseInt(action_data.name, 10), context: context }, handler);
611         } else  {
612             return dataset.exec_workflow(record_id, action_data.name, handler);
613         } 
614     },
615     /**
616      * Directly set a view to use instead of calling fields_view_get. This method must
617      * be called before start(). When an embedded view is set, underlying implementations
618      * of openerp.base.View must use the provided view instead of any other one.
619      * 
620      * @param embedded_view A view.
621      */
622     set_embedded_view: function(embedded_view) {
623         this.embedded_view = embedded_view;
624         this.options.sidebar = false;
625     },
626     do_switch_view: function(view) {
627     },
628     set_common_sidebar_sections: function(sidebar) {
629         sidebar.add_section('customize', "Customize", [
630             {
631                 label: "Manage Views",
632                 callback: this.on_sidebar_manage_view,
633                 title: "Manage views of the current object"
634             }, {
635                 label: "Edit Workflow",
636                 callback: this.on_sidebar_edit_workflow,
637                 title: "Manage views of the current object",
638                 classname: 'oe_hide oe_sidebar_edit_workflow'
639             }, {
640                 label: "Customize Object",
641                 callback: this.on_sidebar_customize_object,
642                 title: "Manage views of the current object"
643             }
644         ]);
645         sidebar.add_section('other', "Other Options", [
646             {
647                 label: "Import",
648                 callback: this.on_sidebar_import
649             }, {
650                 label: "Export",
651                 callback: this.on_sidebar_export
652             }, {
653                 label: "Translate",
654                 callback: this.on_sidebar_translate,
655                 classname: 'oe_sidebar_translate'
656             }, {
657                 label: "View Log",
658                 callback: this.on_sidebar_view_log,
659                 classname: 'oe_hide oe_sidebar_view_log'
660             }
661         ]);
662     },
663     on_sidebar_manage_view: function() {
664         if (this.fields_view && this.fields_view.arch) {
665             $('<xmp>' + openerp.base.json_node_to_xml(this.fields_view.arch, true) + '</xmp>').dialog({ width: '95%', height: 600});
666         } else {
667             this.notification.warn("Manage Views", "Could not find current view declaration");
668         }
669     },
670     on_sidebar_edit_workflow: function() {
671         this.log('Todo');
672     },
673     on_sidebar_customize_object: function() {
674         this.log('Todo');
675     },
676     on_sidebar_import: function() {
677     },
678     on_sidebar_export: function() {
679         var export_view = new openerp.base.DataExport(this, this.dataset);
680         export_view.start();
681     },
682     on_sidebar_translate: function() {
683         this.open_translate_dialog();
684     },
685     on_sidebar_view_log: function() {
686     }
687 });
688
689 /**
690  * Registry for all the main views
691  */
692 openerp.base.views = new openerp.base.Registry();
693
694 openerp.base.json_node_to_xml = function(node, single_quote, indent) {
695     // For debugging purpose, this function will convert a json node back to xml
696     // Maybe usefull for xml view editor
697     if (typeof(node.tag) !== 'string' || !node.children instanceof Array || !node.attrs instanceof Object) {
698         throw("Node a json node");
699     }
700     indent = indent || 0;
701     var sindent = new Array(indent + 1).join('\t'),
702         r = sindent + '<' + node.tag;
703     for (var attr in node.attrs) {
704         var vattr = node.attrs[attr];
705         if (typeof(vattr) !== 'string') {
706             // domains, ...
707             vattr = JSON.stringify(vattr);
708         }
709         vattr = vattr.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
710         if (single_quote) {
711             vattr = vattr.replace(/&quot;/g, "'");
712         }
713         r += ' ' + attr + '="' + vattr + '"';
714     }
715     if (node.children.length) {
716         r += '>\n';
717         var childs = [];
718         for (var i = 0, ii = node.children.length; i < ii; i++) {
719             childs.push(openerp.base.json_node_to_xml(node.children[i], single_quote, indent + 1));
720         }
721         r += childs.join('\n');
722         r += '\n' + sindent + '</' + node.tag + '>';
723         return r;
724     } else {
725         return r + '/>';
726     }
727 }
728
729 };
730
731 // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: