[MERGE] Merge with trunk upto revision no 1400.
[odoo/odoo.git] / addons / web / static / src / js / views.js
index 0441516..b6a37c8 100644 (file)
@@ -2,21 +2,21 @@
  * OpenERP web library
  *---------------------------------------------------------*/
 
-openerp.web.views = function(db) {
+openerp.web.views = function(session) {
 
-var _t = db.web._t;
+var _t = session.web._t;
 
 /**
  * Registry for all the client actions key: tag value: widget
  */
-db.web.client_actions = new db.web.Registry();
+session.web.client_actions = new session.web.Registry();
 
 /**
  * Registry for all the main views
  */
-db.web.views = new db.web.Registry();
+session.web.views = new session.web.Registry();
 
-db.web.ActionManager = db.web.Widget.extend({
+session.web.ActionManager = session.web.Widget.extend({
     identifier_prefix: "actionmanager",
     init: function(parent) {
         this._super(parent);
@@ -93,20 +93,20 @@ db.web.ActionManager = db.web.Widget.extend({
     ir_actions_act_window: function (action, on_close) {
         if (action.target === 'new') {
             if (this.dialog == null) {
-                this.dialog = new db.web.Dialog(this, { title: action.name, width: '80%' });
+                this.dialog = new session.web.Dialog(this, { title: action.name, width: '80%' });
                 if(on_close)
                     this.dialog.on_close.add(on_close);
                 this.dialog.start();
             } else {
                 this.dialog_viewmanager.stop();
             }
-            this.dialog_viewmanager = new db.web.ViewManagerAction(this, action);
+            this.dialog_viewmanager = new session.web.ViewManagerAction(this, action);
             this.dialog_viewmanager.appendTo(this.dialog.$element);
             this.dialog.open();
         } else  {
             this.dialog_stop();
             this.content_stop();
-            this.inner_viewmanager = new db.web.ViewManagerAction(this, action);
+            this.inner_viewmanager = new session.web.ViewManagerAction(this, action);
             this.inner_viewmanager.appendTo(this.$element);
             this.url_update(action);
         }
@@ -121,6 +121,12 @@ db.web.ActionManager = db.web.Widget.extend({
         if (!this.dialog && on_closed) {
             on_closed();
         }
+        if (this.dialog && action.context) {
+            var model = action.context.active_model;
+            if (model === 'base.module.upgrade' || model === 'base.setup.installer' || model === 'base.module.upgrade') {
+                session.webclient.do_reload();
+            }
+        }
         this.dialog_stop();
     },
     ir_actions_server: function (action, on_closed) {
@@ -134,7 +140,7 @@ db.web.ActionManager = db.web.Widget.extend({
     },
     ir_actions_client: function (action) {
         this.content_stop();
-        var ClientWidget = db.web.client_actions.get_object(action.tag);
+        var ClientWidget = session.web.client_actions.get_object(action.tag);
         (this.client_widget = new ClientWidget(this, action.params)).appendTo(this);
     },
     ir_actions_report_xml: function(action) {
@@ -152,15 +158,18 @@ db.web.ActionManager = db.web.Widget.extend({
                 complete: $.unblockUI
             });
         });
+    },
+    ir_actions_act_url: function (action) {
+        window.open(action.url, action.target === 'self' ? '_self' : '_blank');
     }
 });
 
-db.web.ViewManager =  db.web.Widget.extend(/** @lends db.web.ViewManager# */{
+session.web.ViewManager =  session.web.Widget.extend(/** @lends session.web.ViewManager# */{
     identifier_prefix: "viewmanager",
     template: "ViewManager",
     /**
-     * @constructs db.web.ViewManager
-     * @extends db.web.Widget
+     * @constructs session.web.ViewManager
+     * @extends session.web.Widget
      *
      * @param parent
      * @param dataset
@@ -176,10 +185,10 @@ db.web.ViewManager =  db.web.Widget.extend(/** @lends db.web.ViewManager# */{
         this.views_src = _.map(views, function(x) {return x instanceof Array? {view_id: x[0], view_type: x[1]} : x;});
         this.views = {};
         this.flags = this.flags || {};
-        this.registry = db.web.views;
+        this.registry = session.web.views;
     },
     render: function() {
-        return db.web.qweb.render(this.template, {
+        return session.web.qweb.render(this.template, {
             self: this,
             prefix: this.element_id,
             views: this.views_src});
@@ -262,6 +271,10 @@ db.web.ViewManager =  db.web.Widget.extend(/** @lends db.web.ViewManager# */{
                 }
             }
         }
+        $.when(view_promise).then(function () {
+            self.$element.find('.oe_view_title:first').text(
+                    self.display_title());
+        });
         return view_promise;
     },
     /**
@@ -275,7 +288,7 @@ db.web.ViewManager =  db.web.Widget.extend(/** @lends db.web.ViewManager# */{
         if (this.searchview) {
             this.searchview.stop();
         }
-        this.searchview = new db.web.SearchView(
+        this.searchview = new session.web.SearchView(
                 this, this.dataset,
                 view_id, search_defaults, this.flags.search_view === false);
 
@@ -322,16 +335,24 @@ db.web.ViewManager =  db.web.Widget.extend(/** @lends db.web.ViewManager# */{
     /**
      * Called by children view after executing an action
      */
-    on_action_executed: function () {}
+    on_action_executed: function () {},
+    display_title: function () {
+        var view = this.views[this.active_view];
+        if (view) {
+            // ick
+            return view.controller.fields_view.arch.attrs.string;
+        }
+        return '';
+    }
 });
 
-db.web.ViewManagerAction = db.web.ViewManager.extend(/** @lends oepnerp.web.ViewManagerAction# */{
+session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepnerp.web.ViewManagerAction# */{
     template:"ViewManagerAction",
     /**
-     * @constructs db.web.ViewManagerAction
-     * @extends db.web.ViewManager
+     * @constructs session.web.ViewManagerAction
+     * @extends session.web.ViewManager
      *
-     * @param {db.web.ActionManager} parent parent object/widget
+     * @param {session.web.ActionManager} parent parent object/widget
      * @param {Object} action descriptor for the action this viewmanager needs to manage its views.
      */
     init: function(parent, action) {
@@ -341,7 +362,7 @@ db.web.ViewManagerAction = db.web.ViewManager.extend(/** @lends oepnerp.web.View
         this._super(parent, null, action.views);
         this.session = parent.session;
         this.action = action;
-        var dataset = new db.web.DataSetSearch(this, action.res_model, action.context, action.domain);
+        var dataset = new session.web.DataSetSearch(this, action.res_model, action.context, action.domain);
         if (action.res_id) {
             dataset.ids.push(action.res_id);
             dataset.index = 0;
@@ -391,12 +412,12 @@ db.web.ViewManagerAction = db.web.ViewManager.extend(/** @lends oepnerp.web.View
 
         this.$element.find('.oe_get_xml_view').click(function () {
             // TODO: add search view?
-            $('<pre>').text(db.web.json_node_to_xml(
+            $('<pre>').text(session.web.json_node_to_xml(
                 self.views[self.active_view].controller.fields_view.arch, true))
                     .dialog({ width: '95%'});
         });
         if (this.action.help && !this.flags.low_profile) {
-            var Users = new db.web.DataSet(self, 'res.users'),
+            var Users = new session.web.DataSet(self, 'res.users'),
                 header = this.$element.find('.oe-view-manager-header');
             header.delegate('blockquote button', 'click', function() {
                 var $this = $(this);
@@ -425,10 +446,26 @@ db.web.ViewManagerAction = db.web.ViewManager.extend(/** @lends oepnerp.web.View
     on_mode_switch: function (view_type) {
         var self = this;
         return $.when(
-            this._super(view_type),
-            this.shortcut_check(this.views[view_type])).then(function () {
-                var view_id = self.views[self.active_view].controller.fields_view.view_id;
+                this._super(view_type),
+                this.shortcut_check(this.views[view_type])
+            ).then(function() {
+                var controller = self.views[self.active_view].controller,
+                    fvg = controller.fields_view,
+                    view_id = (fvg && fvg.view_id) || '--';
                 self.$element.find('.oe_get_xml_view span').text(view_id);
+                if (!self.action.name && fvg) {
+                    self.$element.find('.oe_view_title').text(fvg.arch.attrs.string || fvg.name);
+                }
+
+                var $title = self.$element.find('.oe_view_title'),
+                    $search_prefix = $title.find('span');
+                if (controller.searchable !== false) {
+                    if (!$search_prefix.length) {
+                        $title.prepend('<span>' + _t("Search:") + '</span>');
+                    }
+                } else {
+                    $search_prefix.remove();
+                }
         });
     },
     shortcut_check : function(view) {
@@ -436,7 +473,7 @@ db.web.ViewManagerAction = db.web.ViewManager.extend(/** @lends oepnerp.web.View
         var grandparent = this.widget_parent && this.widget_parent.widget_parent;
         // display shortcuts if on the first view for the action
         var $shortcut_toggle = this.$element.find('.oe-shortcut-toggle');
-        if (!(grandparent instanceof db.web.WebClient) ||
+        if (!(grandparent instanceof session.web.WebClient) ||
             !(view.view_type === this.views_src[0].view_type
                 && view.view_id === this.views_src[0].view_id)) {
             $shortcut_toggle.hide();
@@ -473,7 +510,7 @@ db.web.ViewManagerAction = db.web.ViewManager.extend(/** @lends oepnerp.web.View
      * Intercept do_action resolution from children views
      */
     on_action_executed: function () {
-        return new db.web.DataSet(this, 'res.log')
+        return new session.web.DataSet(this, 'res.log')
                 .call('get', [], this.do_display_log);
     },
     /**
@@ -497,10 +534,13 @@ db.web.ViewManagerAction = db.web.ViewManager.extend(/** @lends oepnerp.web.View
                     return false;
                 });
         });
+    },
+    display_title: function () {
+        return this.action.name;
     }
 });
 
-db.web.Sidebar = db.web.Widget.extend({
+session.web.Sidebar = session.web.Widget.extend({
     init: function(parent, element_id) {
         this._super(parent, element_id);
         this.items = {};
@@ -509,14 +549,62 @@ db.web.Sidebar = db.web.Widget.extend({
     start: function() {
         this._super(this);
         var self = this;
-        this.$element.html(db.web.qweb.render('Sidebar'));
+        this.$element.html(session.web.qweb.render('Sidebar'));
         this.$element.find(".toggle-sidebar").click(function(e) {
             self.do_toggle();
         });
     },
+
+    call_default_on_sidebar: function(item) {
+        var func_name = 'on_sidebar_' + _.underscored(item.label);
+        var fn = this.widget_parent[func_name];
+        if(typeof fn === 'function') {
+            fn(item);
+        }
+    },
+
+    add_default_sections: function() {
+        this.add_section(_t('Customize'), 'customize');
+        this.add_items('customize', [
+            {
+                label: _t("Manage Views"),
+                callback: this.call_default_on_sidebar,
+                title: _t("Manage views of the current object")
+            }, {
+                label: _t("Edit Workflow"),
+                callback: this.call_default_on_sidebar,
+                title: _t("Manage views of the current object"),
+                classname: 'oe_hide oe_sidebar_edit_workflow'
+            }, {
+                label: _t("Customize Object"),
+                callback: this.call_default_on_sidebar,
+                title: _t("Manage views of the current object")
+            }
+        ]);
+
+        this.add_section(_t('Other Options'), 'other');
+        this.add_items('other', [
+            {
+                label: _t("Import"),
+                callback: this.call_default_on_sidebar
+            }, {
+                label: _t("Export"),
+                callback: this.call_default_on_sidebar
+            }, {
+                label: _t("Translate"),
+                callback: this.call_default_on_sidebar,
+                classname: 'oe_sidebar_translate oe_hide'
+            }, {
+                label: _t("View Log"),
+                callback: this.call_default_on_sidebar,
+                classname: 'oe_hide oe_sidebar_view_log'
+            }
+        ]);
+    },
+
     add_toolbar: function(toolbar) {
         var self = this;
-        _.each([['print', "Reports"], ['action', "Actions"], ['relate', "Links"]], function(type) {
+        _.each([['print', _t("Reports")], ['action', _t("Actions")], ['relate', _t("Links")]], function(type) {
             var items = toolbar[type[0]];
             if (items.length) {
                 for (var i = 0; i < items.length; i++) {
@@ -526,15 +614,30 @@ db.web.Sidebar = db.web.Widget.extend({
                         classname: 'oe_sidebar_' + type[0]
                     }
                 }
-                self.add_section(type[0], type[1], items);
+                self.add_section(type[1], type[0]);
+                self.add_items(type[0], items);
             }
         });
     },
-    add_section: function(code, name, items) {
-        // For each section, we pass a name/label and optionally an array of items.
-        // If no items are passed, then the section will be created as a custom section
-        // returning back an element_id to be used by a custom controller.
-        // Else, the section is a standard section with items displayed as links.
+
+    add_section: function(name, code) {
+        if(!code) code = _.underscored(name);
+        var $section = this.sections[code];
+
+        if(!$section) {
+            section_id = _.uniqueId(this.element_id + '_section_' + code + '_');
+            var $section = $(session.web.qweb.render("Sidebar.section", {
+                section_id: section_id,
+                name: name,
+                classname: 'oe_sidebar_' + code
+            }));
+            $section.appendTo(this.$element.find('div.sidebar-actions'));
+            this.sections[code] = $section;
+        }
+        return $section;
+    },
+
+    add_items: function(section_code, items) {
         // An item is a dictonary : {
         //    label: label to be displayed for the link,
         //    action: action to be launch when the link is clicked,
@@ -543,25 +646,24 @@ db.web.Sidebar = db.web.Widget.extend({
         //    title: optional title for the link
         // }
         // Note: The item should have one action or/and a callback
+        //
+
         var self = this,
-            section_id = _.uniqueId(this.element_id + '_section_' + code + '_');
+            $section = this.add_section(_.titleize(section_code.replace('_', ' ')), section_code),
+            section_id = $section.attr('id');
+
         if (items) {
             for (var i = 0; i < items.length; i++) {
                 items[i].element_id = _.uniqueId(section_id + '_item_');
                 this.items[items[i].element_id] = items[i];
             }
-        }
-        var $section = $(db.web.qweb.render("Sidebar.section", {
-            section_id: section_id,
-            name: name,
-            classname: 'oe_sidebar_' + code,
-            items: items
-        }));
-        if (items) {
-            $section.find('a.oe_sidebar_action_a').click(function() {
+
+            var $items = $(session.web.qweb.render("Sidebar.section.items", {items: items}));
+
+            $items.find('a.oe_sidebar_action_a').click(function() {
                 var item = self.items[$(this).attr('id')];
                 if (item.callback) {
-                    item.callback();
+                    item.callback.apply(self, [item]);
                 }
                 if (item.action) {
                     var ids = self.widget_parent.get_selected_ids();
@@ -591,10 +693,13 @@ db.web.Sidebar = db.web.Widget.extend({
                 }
                 return false;
             });
+
+            var $ul = $section.find('ul');
+            if(!$ul.length) {
+                $ul = $('<ul/>').appendTo($section);
+            }
+            $items.appendTo($ul);
         }
-        $section.appendTo(this.$element.find('div.sidebar-actions'));
-        this.sections[code] = $section;
-        return section_id;
     },
     do_fold: function() {
         this.$element.addClass('closed-sidebar').removeClass('open-sidebar');
@@ -607,7 +712,7 @@ db.web.Sidebar = db.web.Widget.extend({
     }
 });
 
-db.web.TranslateDialog = db.web.Dialog.extend({
+session.web.TranslateDialog = session.web.Dialog.extend({
     dialog_title: _t("Translations"),
     init: function(view) {
         // TODO fme: should add the language to fields_view_get because between the fields view get
@@ -627,14 +732,14 @@ db.web.TranslateDialog = db.web.Dialog.extend({
         this.translatable_fields_keys = _.map(this.view.translatable_fields || [], function(i) { return i.name });
         this.languages = null;
         this.languages_loaded = $.Deferred();
-        (new db.web.DataSetSearch(this, 'res.lang', this.view.dataset.get_context(),
+        (new session.web.DataSetSearch(this, 'res.lang', this.view.dataset.get_context(),
             [['translatable', '=', '1']])).read_slice(['code', 'name'], { sort: 'id' }, this.on_languages_loaded);
     },
     start: function() {
         var self = this;
         this._super();
         $.when(this.languages_loaded).then(function() {
-            self.$element.html(db.web.qweb.render('TranslateDialog', { widget: self }));
+            self.$element.html(session.web.qweb.render('TranslateDialog', { widget: self }));
             self.$element.tabs();
             if (!(self.view.translatable_fields && self.view.translatable_fields.length)) {
                 self.hide_tabs('fields');
@@ -739,7 +844,7 @@ db.web.TranslateDialog = db.web.Dialog.extend({
     }
 });
 
-db.web.View = db.web.Widget.extend(/** @lends db.web.View# */{
+session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{
     template: "EmptyComponent",
     set_default_options: function(options) {
         this.options = options || {};
@@ -753,7 +858,7 @@ db.web.View = db.web.Widget.extend(/** @lends db.web.View# */{
     },
     open_translate_dialog: function(field) {
         if (!this.translate_dialog) {
-            this.translate_dialog = new db.web.TranslateDialog(this).start();
+            this.translate_dialog = new session.web.TranslateDialog(this).start();
         }
         this.translate_dialog.open(field);
     },
@@ -765,7 +870,7 @@ db.web.View = db.web.Widget.extend(/** @lends db.web.View# */{
      * @param {String} [action_data.special=null] special action handlers (currently: only ``'cancel'``)
      * @param {String} [action_data.type='workflow'] the action type, if present, one of ``'object'``, ``'action'`` or ``'workflow'``
      * @param {Object} [action_data.context=null] additional action context, to add to the current context
-     * @param {db.web.DataSet} dataset a dataset object used to communicate with the server
+     * @param {session.web.DataSet} dataset a dataset object used to communicate with the server
      * @param {Object} [record_id] the identifier of the object on which the action is to be applied
      * @param {Function} on_closed callback to execute when dialog is closed or when the action does not generate any result (no new action)
      */
@@ -777,33 +882,41 @@ db.web.View = db.web.Widget.extend(/** @lends db.web.View# */{
                 return self.widget_parent.on_action_executed.apply(null, arguments);
             }
         };
+        var context = new session.web.CompoundContext(dataset.get_context(), action_data.context || {});
+
         var handler = function (r) {
             var action = r.result;
             if (action && action.constructor == Object) {
-                return self.rpc('/web/session/eval_domain_and_context', {
-                    contexts: [dataset.get_context(), action.context || {}, {
-                        active_id: record_id || false,
-                        active_ids: [record_id || false],
+                var ncontext = new session.web.CompoundContext(context);
+                if (record_id) {
+                    ncontext.add({
+                        active_id: record_id,
+                        active_ids: [record_id],
                         active_model: dataset.model
-                    }],
+                    });
+                }
+                ncontext.add(action.context || {});
+                return self.rpc('/web/session/eval_domain_and_context', {
+                    contexts: [ncontext],
                     domains: []
                 }).pipe(function (results) {
-                    action.context = results.context
+                    action.context = results.context;
+                    /* niv: previously we were overriding once more with action_data.context,
+                     * I assumed this was not a correct behavior and removed it
+                     */
                     return self.do_action(action, result_handler);
-                });
+                }, null);
             } else {
                 return result_handler();
             }
         };
 
-        var context = new db.web.CompoundContext(dataset.get_context(), action_data.context || {});
-
         if (action_data.special) {
             return handler({result: {"type":"ir.actions.act_window_close"}});
         } else if (action_data.type=="object") {
             return dataset.call_button(action_data.name, [[record_id], context], handler);
         } else if (action_data.type=="action") {
-            return this.rpc('/web/action/load', { action_id: parseInt(action_data.name, 10), context: context }, handler);
+            return this.rpc('/web/action/load', { action_id: parseInt(action_data.name, 10), context: context, do_not_eval: true}, handler);
         } else  {
             return dataset.exec_workflow(record_id, action_data.name, handler);
         }
@@ -811,7 +924,7 @@ db.web.View = db.web.Widget.extend(/** @lends db.web.View# */{
     /**
      * Directly set a view to use instead of calling fields_view_get. This method must
      * be called before start(). When an embedded view is set, underlying implementations
-     * of db.web.View must use the provided view instead of any other one.
+     * of session.web.View must use the provided view instead of any other one.
      *
      * @param embedded_view A view.
      */
@@ -823,47 +936,16 @@ db.web.View = db.web.Widget.extend(/** @lends db.web.View# */{
     },
     do_search: function(view) {
     },
+
     set_common_sidebar_sections: function(sidebar) {
-        sidebar.add_section('customize', "Customize", [
-            {
-                label: "Manage Views",
-                callback: this.on_sidebar_manage_view,
-                title: "Manage views of the current object"
-            }, {
-                label: "Edit Workflow",
-                callback: this.on_sidebar_edit_workflow,
-                title: "Manage views of the current object",
-                classname: 'oe_hide oe_sidebar_edit_workflow'
-            }, {
-                label: "Customize Object",
-                callback: this.on_sidebar_customize_object,
-                title: "Manage views of the current object"
-            }
-        ]);
-        sidebar.add_section('other', "Other Options", [
-            {
-                label: "Import",
-                callback: this.on_sidebar_import
-            }, {
-                label: "Export",
-                callback: this.on_sidebar_export
-            }, {
-                label: "Translate",
-                callback: this.on_sidebar_translate,
-                classname: 'oe_sidebar_translate oe_hide'
-            }, {
-                label: "View Log",
-                callback: this.on_sidebar_view_log,
-                classname: 'oe_hide oe_sidebar_view_log'
-            }
-        ]);
+        sidebar.add_default_sections();
     },
-    on_sidebar_manage_view: function() {
+    on_sidebar_manage_views: function() {
         if (this.fields_view && this.fields_view.arch) {
-            var view_editor = new db.web.ViewEditor(this, this.$element, this.dataset, this.fields_view.arch);
+            var view_editor = new session.web.ViewEditor(this, this.$element, this.dataset, this.fields_view.arch);
             view_editor.start();
         } else {
-            this.notification.warn("Manage Views", "Could not find current view declaration");
+            this.do_warn("Manage Views", "Could not find current view declaration");
         }
     },
     on_sidebar_edit_workflow: function() {
@@ -873,11 +955,11 @@ db.web.View = db.web.Widget.extend(/** @lends db.web.View# */{
         console.log('Todo');
     },
     on_sidebar_import: function() {
-        var import_view = new db.web.DataImport(this, this.dataset);
+        var import_view = new session.web.DataImport(this, this.dataset);
         import_view.start();
     },
     on_sidebar_export: function() {
-        var export_view = new db.web.DataExport(this, this.dataset);
+        var export_view = new session.web.DataExport(this, this.dataset);
         export_view.start();
     },
     on_sidebar_translate: function() {
@@ -887,19 +969,19 @@ db.web.View = db.web.Widget.extend(/** @lends db.web.View# */{
     }
 });
 
-db.web.json_node_to_xml = function(node, single_quote, indent) {
+session.web.json_node_to_xml = function(node, human_readable, indent) {
     // For debugging purpose, this function will convert a json node back to xml
     // Maybe usefull for xml view editor
+    indent = indent || 0;
+    var sindent = (human_readable ? (new Array(indent + 1).join('\t')) : ''),
+        r = sindent + '<' + node.tag,
+        cr = human_readable ? '\n' : '';
 
     if (typeof(node) === 'string') {
-        return node;
-    }
-    else if (typeof(node.tag) !== 'string' || !node.children instanceof Array || !node.attrs instanceof Object) {
+        return sindent + node;
+    } else if (typeof(node.tag) !== 'string' || !node.children instanceof Array || !node.attrs instanceof Object) {
         throw("Node a json node");
     }
-    indent = indent || 0;
-    var sindent = new Array(indent + 1).join('\t'),
-        r = sindent + '<' + node.tag;
     for (var attr in node.attrs) {
         var vattr = node.attrs[attr];
         if (typeof(vattr) !== 'string') {
@@ -907,19 +989,19 @@ db.web.json_node_to_xml = function(node, single_quote, indent) {
             vattr = JSON.stringify(vattr);
         }
         vattr = vattr.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
-        if (single_quote) {
+        if (human_readable) {
             vattr = vattr.replace(/&quot;/g, "'");
         }
         r += ' ' + attr + '="' + vattr + '"';
     }
     if (node.children && node.children.length) {
-        r += '>\n';
+        r += '>' + cr;
         var childs = [];
         for (var i = 0, ii = node.children.length; i < ii; i++) {
-            childs.push(db.web.json_node_to_xml(node.children[i], single_quote, indent + 1));
+            childs.push(session.web.json_node_to_xml(node.children[i], human_readable, indent + 1));
         }
-        r += childs.join('\n');
-        r += '\n' + sindent + '</' + node.tag + '>';
+        r += childs.join(cr);
+        r += cr + sindent + '</' + node.tag + '>';
         return r;
     } else {
         return r + '/>';