From 243e1bdb0079ea9f214696ead8228d464ecb2cfc Mon Sep 17 00:00:00 2001 From: "Vidhin Mehta (OpenERP)" Date: Tue, 13 Sep 2011 18:58:29 +0530 Subject: [PATCH] [imp]creating object for xml to display tree view in manage view. bzr revid: vme@tinyerp.com-20110913132829-qc033f3uwy7a422u --- addons/base/static/src/js/view_editor.js | 84 +++++++++++++++++++++--- addons/base/static/src/xml/base.xml | 2 +- 2 files changed, 75 insertions(+), 11 deletions(-) diff --git a/addons/base/static/src/js/view_editor.js b/addons/base/static/src/js/view_editor.js index dd1dd0a93b1..753f9ac6d4e 100644 --- a/addons/base/static/src/js/view_editor.js +++ b/addons/base/static/src/js/view_editor.js @@ -6,10 +6,12 @@ openerp.base.ViewEditor = openerp.base.Widget.extend({ this.parent = parent this.dataset = dataset; this.model = dataset.model; - this.fields_views = view; + this.xml_id = 0; }, start: function() { - + this.View_editor(); + }, + View_editor : function(){ var self = this; var action = { name:'ViewEditor', @@ -38,12 +40,14 @@ openerp.base.ViewEditor = openerp.base.Widget.extend({ height: 500, buttons: { "Create": function(){ - $(this).dialog('destroy'); + }, "Edit": function(){ - self.Edit_view(); + self.xml_id=0; + self.edit_view(); }, - " Close": function(){ + "Close": function(){ + $(this).dialog('destroy'); } }, @@ -52,10 +56,72 @@ openerp.base.ViewEditor = openerp.base.Widget.extend({ this.dialog.open(); action_manager.appendTo(this.dialog); action_manager.do_action(action); - }, - Edit_view : function(){ - + + }, + check_attr:function(xml,tag){ + var obj = new Object(); + obj.child_id = []; + obj.id = this.xml_id++; + var att_list = []; + var name1 = "<" + tag; + $(xml).each(function() { + att_list = this.attributes; + att_list = _.select(att_list, function(attrs){ + if(attrs.nodeName == "string" || attrs.nodeName == "name" || attrs.nodeName == "index"){ + name1 += ' ' +attrs.nodeName+'='+'"'+attrs.nodeValue+'"';} + }); + name1+= ">"; + }); + obj.name = name1; + return obj; + }, + recursiveFunction : function(main_object,parent_id,child_id){ + var self = this; + var check = false; + var main_object = _.detect(main_object , function(node){ + if(node.id == parent_id){ + node.child_id = child_id; + check = true; + } + return main_object; + }); + if(check){ + return main_object; + }else{ + //todo recursion for saving object into objects + } + }, + children_function : function(xml,root,main_object,parent_id){ + var self = this; + var child_obj_list = []; + var main_object = main_object; + var children_list = $(xml).filter(root).children(); + _.each(children_list, function(child_node){ + var string = self.check_attr(child_node,child_node.tagName.toLowerCase()); + child_obj_list.push(string); + }); + if(children_list.length != 0){ + main_object = self.recursiveFunction(main_object,parent_id,child_obj_list); + } + for(var i=0;i - +