From 5bffa6a13542874ca61a2b1633f7ce0e57de845a Mon Sep 17 00:00:00 2001 From: "Vidhin Mehta (OpenERP)" Date: Wed, 5 Oct 2011 16:51:27 +0530 Subject: [PATCH 1/9] [IMP]reduce code and implement for field position. bzr revid: vme@tinyerp.com-20111005112127-wihc38e3a5iipea7 --- addons/web/static/src/js/view_editor.js | 190 ++++++++++++------------ 1 file changed, 98 insertions(+), 92 deletions(-) diff --git a/addons/web/static/src/js/view_editor.js b/addons/web/static/src/js/view_editor.js index 2650f966c7e..1e5aef495c8 100644 --- a/addons/web/static/src/js/view_editor.js +++ b/addons/web/static/src/js/view_editor.js @@ -1,7 +1,6 @@ openerp.web.view_editor = function(openerp) { var QWeb = openerp.web.qweb; openerp.web.ViewEditor = openerp.web.Widget.extend({ - init: function(parent, element_id, dataset, view, options) { this._super(parent); this.element_id = element_id @@ -61,44 +60,38 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ action_manager.do_action(action); }, - check_attr:function(xml,tag,level){ + check_attr: function(xml ,tag,level) { var obj = new Object(); obj.child_id = []; obj.id = this.xml_id++; - obj.level = level; - var att_list = []; + obj.level = level+1; var render_name = "<" + tag; - var xml_tag = "<" + tag; $(xml).each(function() { - att_list = this.attributes; - att_list = _.select(att_list, function(attrs){ - xml_tag += ' ' +attrs.nodeName+'='+'"'+attrs.nodeValue+'"'; - if (tag != 'button'){ - if(attrs.nodeName == "string" || attrs.nodeName == "name" || attrs.nodeName == "index"){ + _.each(this.attributes, function(attrs){ + if (tag != 'button') { + if (attrs.nodeName == "string" || attrs.nodeName == "name" || attrs.nodeName == "index") { render_name += ' ' +attrs.nodeName+'='+'"'+attrs.nodeValue+'"';} - }else{ - if(attrs.nodeName == "name"){ + } else { + if (attrs.nodeName == "name") { render_name += ' ' +attrs.nodeName+'='+'"'+attrs.nodeValue+'"';} } }); render_name+= ">"; - xml_tag+= ">"; }); - obj.main_xml = xml_tag; obj.name = render_name; return obj; }, - save_object : function(val,parent_list,child_obj_list){ + save_object: function(val, parent_list, child_obj_list){ var self = this; var check_id = parent_list[0]; var p_list = parent_list.slice(1); - if(val.child_id.length != 0){ - $.each(val.child_id, function(key,val) { - if(val.id==check_id){ - if(p_list.length!=0){ - self.save_object(val,p_list,child_obj_list); - }else{ + if (val.child_id.length != 0) { + $.each(val.child_id, function(key, val) { + if (val.id == check_id) { + if (p_list.length!=0) { + self.save_object(val, p_list, child_obj_list); + } else { val.child_id = child_obj_list; return; } @@ -109,56 +102,58 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ } }, - children_function : function(xml,root,parent_list,parent_id,main_object,parent_child_id){ + children_function: function(xml, root, parent_list, parent_id, main_object){ var self = this; var child_obj_list = []; - var parent_child_id = parent_child_id; - var parent_list = parent_list; - var main_object = main_object; var children_list = $(xml).filter(root).children(); var parents = $(children_list[0]).parents().get(); _.each(children_list, function(child_node){ var string = self.check_attr(child_node,child_node.tagName.toLowerCase(),parents.length); child_obj_list.push(string); }); - - if(children_list.length != 0){ - var child_ids = _.map(child_obj_list ,function(num){return num.id;}); - parent_child_id.push({'key': parent_id, 'value': child_ids}); + if (children_list.length != 0) { var parents = $(children_list[0]).parents().get(); - if(parents.length <= parent_list.length){ + if (parents.length <= parent_list.length) { parent_list.splice(parents.length-1); } parent_list.push(parent_id); - $.each(main_object, function(key,val) { - self.save_object(val,parent_list.slice(1),child_obj_list); + $.each(main_object, function(key, val) { + self.save_object(val, parent_list.slice(1), child_obj_list); }); } - - for(var i=0;i" + var root_object = self.check_attr(root,tag,0); + f_obj = self.children_function(arch, tag, [], this.xml_id-1, [root_object], []) + obj.child_id.push(f_obj[0]); + f_obj.pop(); + f_obj.push(obj); + return f_obj; }, - get_data : function(){ + get_data: function() { var self = this; var view_id =(($("input[name='radiogroup']:checked").parent()).parent()).attr('data-id'); var ve_dataset = new openerp.web.DataSet(this,'ir.ui.view'); - ve_dataset.read_ids([parseInt(view_id)],['arch'],function (arch){ + ve_dataset.read_ids([parseInt(view_id)], ['arch'], function (arch) { one_object = self.parse_xml(arch[0].arch,view_id); one_object.arch = arch[0].arch; - dataset = new openerp.web.DataSetSearch(self,'ir.ui.view', null, null); + dataset = new openerp.web.DataSetSearch(self, 'ir.ui.view', null, null); dataset.read_slice([],{domain : [['inherit_id','=',parseInt(view_id)]]},function (result) { _.each(result,function(res){ self.inherit_view(one_object,res); @@ -167,80 +162,91 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ }); }); }, - inherit_view : function(one_object,result){ + + inherit_view: function(one_object, result){ var self = this; var root = $(result.arch).filter('*'); - var xpath_list = []; - var part_expr = []; - var position ; - if(root[0].tagName.toLowerCase() == "data"){ - _.each($(root).find('xpath'),function(xpath){ - xpath_list.push(xpath); - }); - } else if(root[0].tagName.toLowerCase() == "xpath"){ - xpath_list.push(root[0]); + var xml_list = []; + var xpath_object ; + if (root[0].tagName.toLowerCase() == "data") { + xml_list = $(root[0]).children(); + } else { + xml_list.push(root[0]); } - _.each(xpath_list,function(element){ - var xpath_object = self.parse_xml(element,result.id); - var expr = $(element).attr('expr'); - var position = $(element).attr('position'); - part_expr = expr.split("/"); - if(part_expr[0]=="" && part_expr[1]==""){ - part_expr = part_expr.splice(2); - }else if(part_expr[0]==""){ - part_expr = part_expr.splice(1); - } - if(part_expr[part_expr.length-1].search("@")!=-1){ - var part = part_expr[part_expr.length-1]; - var xpath_list = $.trim(part.replace(/[^a-zA-Z 0-9 _]+/g,' ')).split(" "); - one_object['parent_child_id'].push(xpath_object['parent_child_id'][0]); - $.each(one_object['main_object'], function(key,val) { - var id = self.search_object(val,xpath_list,[],position,xpath_object['main_object'],[]); - _.detect(one_object['parent_child_id'],function(res){ - if(res.key==id){ - res.value.push(xpath_object['main_object'][0].id); - } - }); - }); + _.each(xml_list , function(xml){ + var parent_id; + var check_list = []; + var position = $(xml).attr('position'); + if (xml.tagName.toLowerCase() == "xpath") { + var part_expr = _.without($(xml).attr('expr').split("/"),"");; + xpath_object = self.parse_xml(xml,result.id); + if (part_expr[part_expr.length-1].search("@")!=-1) { + check_list = $.trim(part_expr[part_expr.length-1].replace(/[^a-zA-Z 0-9 _]+/g,' ')).split(" "); + + }else{ + //search full path... + } + } else { + var xml_child = $(xml).children(); + check_list.push(xml.tagName.toLowerCase()); + if ($(root[0]).attr('name')){ + check_list.push($(root[0]).attr('name')); + check_list.push("name"); + } + xpath_object = self.parse_xml(xml,result.id); } + $.each(function(){ + }); + self.search_object(val,check_list,[],position,xpath_object['main_object'],[]); }); }, - search_object:function(val,list,p_list,position,xpath_object,r_list){ + search_object: function(val ,list ,p_list ,position, xpath_object){ var self = this; - var return_list = r_list; var main_list = $.trim(val.name.replace(/[^a-zA-Z 0-9 _]+/g,' ')).split(" "); var insert = _.intersection(main_list,list); var check = _.indexOf(p_list.child_id,xpath_object[0]); if(check == -1){ if(insert.length == list.length){ - var level = val.level; - $.each(xpath_object, function(key,val) { - self.increase_level(val,level) + var level = val.level; + $.each(xpath_object, function(key, val) { + self.increase_level(val, level) }); var index = _.indexOf(p_list.child_id,val); - if(position == "before"){ - if(index!=0){index--;} - }else if(position == "after"){ - index++; + switch (position) + { + case "before": + if (index != 0) { index--; } + p_list.child_id.splice(index,0,xpath_object[0]); + break; + case "after": + index++; + p_list.child_id.splice(index,0,xpath_object[0]); + break; + case "inside": + val.child_id.push(xpath_object[0]); + break; + case "replace": + break; } - p_list.child_id.splice(index,0,xpath_object[0]); - return_list.push(p_list.id); + }else{ - if(val.child_id.length!=0){p_list = val;} - $.each(val.child_id, function(key,val) { - self.search_object(val,list,p_list,position,xpath_object,return_list); + if ( val.child_id.length != 0) { p_list = val; } + $.each(val.child_id, function(key, val) { + self.search_object(val, list, p_list, position, xpath_object); }); } } return return_list; }, - increase_level :function(val,level){ + + increase_level :function(val, level){ var self = this; val.level = level; - $.each(val.child_id, function(key,val) { + $.each(val.child_id, function(key, val) { self.increase_level(val,level+1); }); }, + edit_view : function(one_object){ var self = this; this.dialog = new openerp.web.Dialog(this,{ @@ -262,7 +268,7 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ }); this.dialog.start().open(); this.dialog.$element.html(QWeb.render('view_editor', { - 'data': one_object['main_object'], + 'data': one_object, })); $("tr[id^='viewedit-']").click(function() { From c36d4ddea4732e8d936fcf3805bee72b8d08cf99 Mon Sep 17 00:00:00 2001 From: "Vidhin Mehta (OpenERP)" Date: Fri, 7 Oct 2011 11:46:04 +0530 Subject: [PATCH 2/9] [IMP]create parent-child list after inherit view. bzr revid: vme@tinyerp.com-20111007061604-zv97xy6byxmm5qhv --- addons/web/static/src/js/view_editor.js | 28 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/addons/web/static/src/js/view_editor.js b/addons/web/static/src/js/view_editor.js index 1e5aef495c8..dc2d1489f80 100644 --- a/addons/web/static/src/js/view_editor.js +++ b/addons/web/static/src/js/view_editor.js @@ -60,7 +60,7 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ action_manager.do_action(action); }, - check_attr: function(xml ,tag,level) { + check_attr: function(xml ,tag, level) { var obj = new Object(); obj.child_id = []; obj.id = this.xml_id++; @@ -82,14 +82,14 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ return obj; }, - save_object: function(val, parent_list, child_obj_list){ + save_object: function(val, parent_list, child_obj_list) { var self = this; var check_id = parent_list[0]; var p_list = parent_list.slice(1); if (val.child_id.length != 0) { $.each(val.child_id, function(key, val) { if (val.id == check_id) { - if (p_list.length!=0) { + if (p_list.length != 0) { self.save_object(val, p_list, child_obj_list); } else { val.child_id = child_obj_list; @@ -152,17 +152,24 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ var ve_dataset = new openerp.web.DataSet(this,'ir.ui.view'); ve_dataset.read_ids([parseInt(view_id)], ['arch'], function (arch) { one_object = self.parse_xml(arch[0].arch,view_id); - one_object.arch = arch[0].arch; dataset = new openerp.web.DataSetSearch(self, 'ir.ui.view', null, null); dataset.read_slice([],{domain : [['inherit_id','=',parseInt(view_id)]]},function (result) { - _.each(result,function(res){ - self.inherit_view(one_object,res); - }); - return self.edit_view(one_object); + + return self.edit_view({"main_object": one_object, + "parent_child_id": self.parent_child_list(one_object, [])}); }); }); }, - + parent_child_list: function(one_object, p_list) { + var self = this; + _.each(one_object , function(element){ + if(element.child_id.length != 0){ + p_list.push({"key":element.id,"value":_.pluck(element.child_id, 'id')}); + self.parent_child_list(element.child_id,p_list); + } + }); + return p_list; + }, inherit_view: function(one_object, result){ var self = this; var root = $(result.arch).filter('*'); @@ -249,6 +256,7 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ edit_view : function(one_object){ var self = this; + console.log("++++++++++++++++++++++",one_object); this.dialog = new openerp.web.Dialog(this,{ modal: true, title: 'Edit Xml', @@ -268,7 +276,7 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ }); this.dialog.start().open(); this.dialog.$element.html(QWeb.render('view_editor', { - 'data': one_object, + 'data': one_object['main_object'], })); $("tr[id^='viewedit-']").click(function() { From 548b641acc38e822c60960c67fdf1cda003d8693 Mon Sep 17 00:00:00 2001 From: "Vidhin Mehta (OpenERP)" Date: Fri, 7 Oct 2011 13:07:29 +0530 Subject: [PATCH 3/9] [IMP]implement two type of xpath and fix level convert into integer. bzr revid: vme@tinyerp.com-20111007073729-8e0prjh64cjwp3vj --- addons/web/static/src/js/view_editor.js | 50 ++++++++++--------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/addons/web/static/src/js/view_editor.js b/addons/web/static/src/js/view_editor.js index dc2d1489f80..32f25a01471 100644 --- a/addons/web/static/src/js/view_editor.js +++ b/addons/web/static/src/js/view_editor.js @@ -154,18 +154,21 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ one_object = self.parse_xml(arch[0].arch,view_id); dataset = new openerp.web.DataSetSearch(self, 'ir.ui.view', null, null); dataset.read_slice([],{domain : [['inherit_id','=',parseInt(view_id)]]},function (result) { - - return self.edit_view({"main_object": one_object, + _.each(result, function(res) { + self.inherit_view(one_object, res); + }); + return self.edit_view({"main_object": one_object, "parent_child_id": self.parent_child_list(one_object, [])}); }); }); }, + parent_child_list: function(one_object, p_list) { var self = this; _.each(one_object , function(element){ if(element.child_id.length != 0){ p_list.push({"key":element.id,"value":_.pluck(element.child_id, 'id')}); - self.parent_child_list(element.child_id,p_list); + self.parent_child_list(element.child_id, p_list); } }); return p_list; @@ -202,48 +205,34 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ } xpath_object = self.parse_xml(xml,result.id); } - $.each(function(){ + $.each(one_object, function(key, val){ + self.search_object(val, check_list, xpath_object, []); }); - self.search_object(val,check_list,[],position,xpath_object['main_object'],[]); + }); }, - search_object: function(val ,list ,p_list ,position, xpath_object){ + + search_object: function(val ,list , xpath_object, p_list){ var self = this; var main_list = $.trim(val.name.replace(/[^a-zA-Z 0-9 _]+/g,' ')).split(" "); var insert = _.intersection(main_list,list); var check = _.indexOf(p_list.child_id,xpath_object[0]); if(check == -1){ if(insert.length == list.length){ - var level = val.level; + var level = val.level+1; $.each(xpath_object, function(key, val) { self.increase_level(val, level) }); - var index = _.indexOf(p_list.child_id,val); - switch (position) - { - case "before": - if (index != 0) { index--; } - p_list.child_id.splice(index,0,xpath_object[0]); - break; - case "after": - index++; - p_list.child_id.splice(index,0,xpath_object[0]); - break; - case "inside": - val.child_id.push(xpath_object[0]); - break; - case "replace": - break; - } - + val.child_id.push(xpath_object[0]); + return; }else{ if ( val.child_id.length != 0) { p_list = val; } $.each(val.child_id, function(key, val) { - self.search_object(val, list, p_list, position, xpath_object); + self.search_object(val, list, xpath_object, p_list); }); } } - return return_list; + }, increase_level :function(val, level){ @@ -256,7 +245,6 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ edit_view : function(one_object){ var self = this; - console.log("++++++++++++++++++++++",one_object); this.dialog = new openerp.web.Dialog(this,{ modal: true, title: 'Edit Xml', @@ -376,18 +364,18 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ }); }, on_expand: function(self){ - var level = $(self).closest("tr[id^='viewedit-']").attr('level'); + var level = parseInt($(self).closest("tr[id^='viewedit-']").attr('level')); var cur_tr = $(self).closest("tr[id^='viewedit-']"); while (1){ var nxt_tr = cur_tr.next(); - if (nxt_tr.attr('level') > level){ + if (parseInt(nxt_tr.attr('level')) > level){ cur_tr = nxt_tr; nxt_tr.hide(); }else return nxt_tr; } }, on_collapse: function(self,parent_child_id,id,main_object){ - var id = self.id.split('-')[1]; + var id = parseInt(self.id.split('-')[1]); var datas = _.detect(parent_child_id,function(res){ return res.key == id; }); From e51b619b1dfe8c3fc1ba9fd33e5a3c05c88de1df Mon Sep 17 00:00:00 2001 From: "Vidhin Mehta (OpenERP)" Date: Mon, 10 Oct 2011 18:14:52 +0530 Subject: [PATCH 4/9] [IMP]all type of xpath inherit completed bzr revid: vme@tinyerp.com-20111010124452-okzzpj9kyy9u51q3 --- addons/web/static/src/js/view_editor.js | 115 ++++++++++++++++-------- 1 file changed, 79 insertions(+), 36 deletions(-) diff --git a/addons/web/static/src/js/view_editor.js b/addons/web/static/src/js/view_editor.js index 32f25a01471..fb2e13fed74 100644 --- a/addons/web/static/src/js/view_editor.js +++ b/addons/web/static/src/js/view_editor.js @@ -65,7 +65,10 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ obj.child_id = []; obj.id = this.xml_id++; obj.level = level+1; + obj.att_list = []; var render_name = "<" + tag; + obj.att_list = []; + obj.att_list.push(tag); $(xml).each(function() { _.each(this.attributes, function(attrs){ if (tag != 'button') { @@ -75,7 +78,12 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ if (attrs.nodeName == "name") { render_name += ' ' +attrs.nodeName+'='+'"'+attrs.nodeValue+'"';} } + if (attrs.nodeName != "position") { + obj.att_list.push([attrs.nodeName,attrs.nodeValue]); + } + }); + render_name+= ">"; }); obj.name = render_name; @@ -186,55 +194,90 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ _.each(xml_list , function(xml){ var parent_id; var check_list = []; - var position = $(xml).attr('position'); - if (xml.tagName.toLowerCase() == "xpath") { - var part_expr = _.without($(xml).attr('expr').split("/"),"");; - xpath_object = self.parse_xml(xml,result.id); - if (part_expr[part_expr.length-1].search("@")!=-1) { - check_list = $.trim(part_expr[part_expr.length-1].replace(/[^a-zA-Z 0-9 _]+/g,' ')).split(" "); - - }else{ - //search full path... - } - } else { - var xml_child = $(xml).children(); - check_list.push(xml.tagName.toLowerCase()); - if ($(root[0]).attr('name')){ - check_list.push($(root[0]).attr('name')); - check_list.push("name"); - } + if (xml.tagName.toLowerCase() == "xpath" && ($(xml).attr('expr')).indexOf("//") == -1) { + var part_expr = _.without($(xml).attr('expr').split("/"),""); xpath_object = self.parse_xml(xml,result.id); + self.full_path_search(part_expr ,one_object[0].child_id ,xpath_object,one_object); + } else { + xpath_object = self.parse_xml(xml,result.id); + if($(xml).attr('expr')){ + check_list = $.trim(($(xml).attr('expr')).replace(/[^a-zA-Z 0-9 _]+/g,' ')).split(" "); + }else{ + check_list = _.flatten(xpath_object[0].child_id[0].att_list); + } + $.each(one_object, function(key, val){ + self.search_object(val, check_list, xpath_object); + }); } - $.each(one_object, function(key, val){ - self.search_object(val, check_list, xpath_object, []); - }); - }); }, - - search_object: function(val ,list , xpath_object, p_list){ + full_path_search: function(part_expr ,val ,xpath_object, one_object) { var self = this; - var main_list = $.trim(val.name.replace(/[^a-zA-Z 0-9 _]+/g,' ')).split(" "); - var insert = _.intersection(main_list,list); - var check = _.indexOf(p_list.child_id,xpath_object[0]); - if(check == -1){ - if(insert.length == list.length){ - var level = val.level+1; + var obj; + var check_list = _.without($.trim(part_expr[0].replace(/[^a-zA-Z 0-9 _]+/g,'!')).split("!"),""); + if(check_list.length == 2){ + var int_val = parseInt(check_list[1]); + if(int_val){ + var list_1 = _.select(val,function(element){ + var main_list = _.flatten(element.att_list); + return _.include(main_list, check_list[0]); + }); + obj = val[_.indexOf(val,list_1[int_val-1])]; + }else{ + obj = _.detect(val,function(element){ + var main_list = _.flatten(element.att_list); + return _.include(main_list, check_list[0]); + }); + } + }else{ + obj = _.detect(val,function(element){ + var main_list = _.flatten(element.att_list); + check_list = _.uniq(check_list); + var insert = _.intersection(main_list,check_list); + if(insert.length == check_list.length ){return element;} + }); + } + part_expr.shift(); + if (part_expr.length !=0){ + self.full_path_search(part_expr ,obj.child_id ,xpath_object,one_object); + }else{ + if(obj){ + var level = obj.level+1; $.each(xpath_object, function(key, val) { self.increase_level(val, level) - }); - val.child_id.push(xpath_object[0]); - return; + }); + obj.child_id.push(xpath_object[0]); }else{ - if ( val.child_id.length != 0) { p_list = val; } - $.each(val.child_id, function(key, val) { - self.search_object(val, list, xpath_object, p_list); + $.each(one_object, function(key, val){ + self.search_object(val, check_list, xpath_object); }); } } - + return obj; }, + search_object: function(val ,list , xpath_object){ + var self = this; + if(xpath_object.length != 0){ + var main_list = _.flatten(val.att_list); + list = _.uniq(list); + var insert = _.intersection(main_list,list); + if(insert.length == list.length ){ + var level = val.level+1; + $.each(xpath_object, function(key, val) { + self.increase_level(val, level) + }); + val.child_id.push(xpath_object[0]); + xpath_object.pop(); + return; + }else{ + $.each(val.child_id, function(key, val) { + self.search_object(val, list, xpath_object); + }); + } + } + }, + increase_level :function(val, level){ var self = this; val.level = level; From 081cca81003c596e8fe5cd845cf134cbf7f9b92c Mon Sep 17 00:00:00 2001 From: "Vidhin Mehta (OpenERP)" Date: Mon, 10 Oct 2011 18:40:50 +0530 Subject: [PATCH 5/9] [IMP] spaces done between parameter. bzr revid: vme@tinyerp.com-20111010131050-qmhx05s9qavs73rp --- addons/web/static/src/js/view_editor.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/js/view_editor.js b/addons/web/static/src/js/view_editor.js index fb2e13fed74..eecf54253ea 100644 --- a/addons/web/static/src/js/view_editor.js +++ b/addons/web/static/src/js/view_editor.js @@ -73,13 +73,13 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ _.each(this.attributes, function(attrs){ if (tag != 'button') { if (attrs.nodeName == "string" || attrs.nodeName == "name" || attrs.nodeName == "index") { - render_name += ' ' +attrs.nodeName+'='+'"'+attrs.nodeValue+'"';} + render_name += ' ' + attrs.nodeName + '=' + '"' + attrs.nodeValue + '"' ; } } else { if (attrs.nodeName == "name") { - render_name += ' ' +attrs.nodeName+'='+'"'+attrs.nodeValue+'"';} + render_name += ' ' + attrs.nodeName + '=' + '"' + attrs.nodeValue + '"'; } } if (attrs.nodeName != "position") { - obj.att_list.push([attrs.nodeName,attrs.nodeValue]); + obj.att_list.push( [attrs.nodeName,attrs.nodeValue] ); } }); @@ -115,7 +115,7 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ var child_obj_list = []; var children_list = $(xml).filter(root).children(); var parents = $(children_list[0]).parents().get(); - _.each(children_list, function(child_node){ + _.each(children_list, function( child_node ){ var string = self.check_attr(child_node,child_node.tagName.toLowerCase(),parents.length); child_obj_list.push(string); }); @@ -137,7 +137,7 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ return main_object; }, - parse_xml: function(arch,view_id) { + parse_xml: function(arch, view_id) { var self = this; var root = $(arch).filter(":first")[0]; var tag = root.tagName.toLowerCase(); @@ -148,7 +148,7 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ obj.name = "" var root_object = self.check_attr(root,tag,0); f_obj = self.children_function(arch, tag, [], this.xml_id-1, [root_object], []) - obj.child_id.push(f_obj[0]); + obj.child_id.push( f_obj[0] ); f_obj.pop(); f_obj.push(obj); return f_obj; From 22099a2d9e5f0f201cb1e64304038478f60be495 Mon Sep 17 00:00:00 2001 From: "Vidhin Mehta (OpenERP)" Date: Tue, 11 Oct 2011 19:04:56 +0530 Subject: [PATCH 6/9] [IMP]fix review's issue and try to convert single method for inherited view search bzr revid: vme@tinyerp.com-20111011133456-vq1i5cv2pmbkhixz --- addons/web/static/src/js/view_editor.js | 64 ++++++++++++++----------- addons/web/static/src/xml/base.xml | 22 +++++---- 2 files changed, 50 insertions(+), 36 deletions(-) diff --git a/addons/web/static/src/js/view_editor.js b/addons/web/static/src/js/view_editor.js index 4ab03a88a0d..530b06bdb28 100644 --- a/addons/web/static/src/js/view_editor.js +++ b/addons/web/static/src/js/view_editor.js @@ -145,6 +145,7 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ obj.child_id = []; obj.id = this.xml_id++; obj.level = 0; + obj.att_list = []; obj.name = "" var root_object = self.check_attr(root,tag,0); f_obj = self.children_function(arch, tag, [], this.xml_id-1, [root_object], []) @@ -198,7 +199,10 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ if (xml.tagName.toLowerCase() == "xpath" && ($(xml).attr('expr')).indexOf("//") == -1) { var part_expr = _.without($(xml).attr('expr').split("/"),""); xpath_object = self.parse_xml(xml,result.id); - self.full_path_search(part_expr ,one_object[0].child_id ,xpath_object,one_object); + _.each(part_expr,function(part){ + check_list.push(_.without($.trim(part.replace(/[^a-zA-Z 0-9 _]+/g,'!')).split("!"),"")); + }); + self.full_path_search(check_list ,one_object[0].child_id ,xpath_object); } else { xpath_object = self.parse_xml(xml,result.id); if($(xml).attr('expr')){ @@ -206,55 +210,61 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ }else{ check_list = _.flatten(xpath_object[0].child_id[0].att_list); } - $.each(one_object, function(key, val){ - self.search_object(val, check_list, xpath_object); - }); + + self.full_path_search(check_list ,one_object ,xpath_object); + } }); }, - full_path_search: function(part_expr ,val ,xpath_object, one_object) { + full_path_search: function(check_list ,val ,xpath_object) { var self = this; var obj; - var check_list = _.without($.trim(part_expr[0].replace(/[^a-zA-Z 0-9 _]+/g,'!')).split("!"),""); - if(check_list.length == 2){ - var int_val = parseInt(check_list[1]); + if(xpath_object.length!=0){ + var check = check_list[0]; + + if(check.length == 2){ + var int_val = parseInt(check[1]); if(int_val){ var list_1 = _.select(val,function(element){ var main_list = _.flatten(element.att_list); - return _.include(main_list, check_list[0]); + return _.include(main_list, check[0]); }); obj = val[_.indexOf(val,list_1[int_val-1])]; }else{ obj = _.detect(val,function(element){ var main_list = _.flatten(element.att_list); - return _.include(main_list, check_list[0]); + return _.include(main_list, check[0]); }); } }else{ obj = _.detect(val,function(element){ var main_list = _.flatten(element.att_list); - check_list = _.uniq(check_list); - var insert = _.intersection(main_list,check_list); - if(insert.length == check_list.length ){return element;} + check = _.uniq(check); + var insert = _.intersection(main_list,check); + if(insert.length == check.length ){return element;} }); } - part_expr.shift(); - if (part_expr.length !=0){ - self.full_path_search(part_expr ,obj.child_id ,xpath_object,one_object); - }else{ - if(obj){ - var level = obj.level+1; - $.each(xpath_object, function(key, val) { - self.increase_level(val, level) - }); - obj.child_id.push(xpath_object[0]); + if(obj){ + check_list.shift(); + if (check_list.length !=0){ + self.full_path_search(check_list ,obj.child_id ,xpath_object); }else{ - $.each(one_object, function(key, val){ - self.search_object(val, check_list, xpath_object); - }); + + var level = obj.level+1; + $.each(xpath_object, function(key, val) { + self.increase_level(val, level) + }); + obj.child_id.push(xpath_object[0]); + xpath_object.pop(); + console.log("check",check,obj) } + return obj; + }else{ + _.each(val,function(element){ + self.full_path_search(check_list ,element.child_id ,xpath_object); + }); } - return obj; + } }, search_object : function(val ,list , xpath_object){ diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index d0fbe16c6df..d8ec6f30daf 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1302,20 +1302,24 @@ - - - - -
- + + + - + + - + + - + +
From d071a3b2663ea8df0a43e0860ecea188f9b70055 Mon Sep 17 00:00:00 2001 From: "Vidhin Mehta (OpenERP)" Date: Wed, 12 Oct 2011 15:58:01 +0530 Subject: [PATCH 7/9] [IMP]optimize code and fix product inherited view. bzr revid: vme@tinyerp.com-20111012102801-i7v1aqux18gh56a3 --- addons/web/static/src/js/view_editor.js | 139 +++++++++--------------- addons/web/static/src/js/view_form.js | 7 +- 2 files changed, 59 insertions(+), 87 deletions(-) diff --git a/addons/web/static/src/js/view_editor.js b/addons/web/static/src/js/view_editor.js index 530b06bdb28..b95672ecfd8 100644 --- a/addons/web/static/src/js/view_editor.js +++ b/addons/web/static/src/js/view_editor.js @@ -90,7 +90,7 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ return obj; }, - save_object : function(val, parent_list, child_obj_list) { + save_object: function(val, parent_list, child_obj_list) { var self = this; var check_id = parent_list[0]; var p_list = parent_list.slice(1); @@ -110,27 +110,23 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ } }, - children_function: function(xml, root, parent_list, parent_id, main_object){ + xml_node_create: function(xml, root, parent_list, parent_id, main_object){ var self = this; var child_obj_list = []; var children_list = $(xml).filter(root).children(); var parents = $(children_list[0]).parents().get(); _.each(children_list, function (child_node) { - var string = self.check_attr(child_node,child_node.tagName.toLowerCase(),parents.length); - child_obj_list.push(string); + child_obj_list.push(self.check_attr(child_node,child_node.tagName.toLowerCase(),parents.length)); }); if (children_list.length != 0) { - var parents = $(children_list[0]).parents().get(); if (parents.length <= parent_list.length) { parent_list.splice(parents.length - 1); } parent_list.push(parent_id); - _.each(main_object, function (val, key) { - self.save_object(val, parent_list.slice(1), child_obj_list); - }); + self.save_object(main_object[0], parent_list.slice(1), child_obj_list); } - for (var i=0;i" + var obj ={'child_id':[],'id':this.xml_id++,'level':0,'att_list':[],'name':""}; var root_object = self.check_attr(root,tag,0); - f_obj = self.children_function(arch, tag, [], this.xml_id-1, [root_object], []) - obj.child_id.push( f_obj[0] ); - f_obj.pop(); - f_obj.push(obj); - return f_obj; + obj.child_id = self.xml_node_create(arch, tag, [], this.xml_id-1, [root_object], []) + return [obj]; }, get_data: function() { @@ -186,8 +174,6 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ var self = this; var root = $(result.arch).filter('*'); var xml_list = []; - var xpath_object ; - var part_expr = []; if (root[0].tagName.toLowerCase() == "data") { xml_list = $(root[0]).children(); } else { @@ -196,94 +182,75 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ _.each(xml_list , function(xml){ var parent_id; var check_list = []; + var xpath_object = self.parse_xml(xml,result.id); if (xml.tagName.toLowerCase() == "xpath" && ($(xml).attr('expr')).indexOf("//") == -1) { var part_expr = _.without($(xml).attr('expr').split("/"),""); - xpath_object = self.parse_xml(xml,result.id); _.each(part_expr,function(part){ check_list.push(_.without($.trim(part.replace(/[^a-zA-Z 0-9 _]+/g,'!')).split("!"),"")); }); - self.full_path_search(check_list ,one_object[0].child_id ,xpath_object); } else { - xpath_object = self.parse_xml(xml,result.id); if($(xml).attr('expr')){ - check_list = $.trim(($(xml).attr('expr')).replace(/[^a-zA-Z 0-9 _]+/g,' ')).split(" "); + check_list = [$.trim(($(xml).attr('expr')).replace(/[^a-zA-Z 0-9 _]+/g,' ')).split(" ")]; }else{ - check_list = _.flatten(xpath_object[0].child_id[0].att_list); + check_list = [_.flatten(xpath_object[0].child_id[0].att_list)]; } - - self.full_path_search(check_list ,one_object ,xpath_object); - } + self.full_path_search(check_list ,one_object ,xpath_object); }); }, full_path_search: function(check_list ,val ,xpath_object) { var self = this; - var obj; if(xpath_object.length!=0){ - var check = check_list[0]; - - if(check.length == 2){ - var int_val = parseInt(check[1]); - if(int_val){ + var check = check_list[0]; + var obj; + if(check.length == 2){ + if(parseInt(check[1])){ + var list_1 = _.select(val,function(element){ + var main_list = _.flatten(element.att_list); + return _.include(main_list, check[0]); + }); + obj = val[_.indexOf(val,list_1[parseInt(check[1])-1])]; + } else { + obj = _.detect(val, function(element){ + var main_list = _.flatten(element.att_list); + return _.include(main_list, check[0]); + }); + } + }else if(check.length == 3){ + obj = _.detect(val,function(element){ + var main_list = _.flatten(element.att_list); + check = _.uniq(check); + var insert = _.intersection(main_list,check); + if(insert.length == check.length ){return element;} + }); + }else{ var list_1 = _.select(val,function(element){ var main_list = _.flatten(element.att_list); return _.include(main_list, check[0]); }); - obj = val[_.indexOf(val,list_1[int_val-1])]; - }else{ - obj = _.detect(val,function(element){ - var main_list = _.flatten(element.att_list); - return _.include(main_list, check[0]); - }); + if(list_1 != 0){ + if(check_list.length == 1){ + obj = list_1[0]; + }else{ + check_list.shift(); + } + } } - }else{ - obj = _.detect(val,function(element){ - var main_list = _.flatten(element.att_list); - check = _.uniq(check); - var insert = _.intersection(main_list,check); - if(insert.length == check.length ){return element;} - }); - } - if(obj){ - check_list.shift(); - if (check_list.length !=0){ - self.full_path_search(check_list ,obj.child_id ,xpath_object); - }else{ - + if(obj){ + check_list.shift(); + if (check_list.length !=0){ + self.full_path_search(check_list ,obj.child_id ,xpath_object); + }else{ var level = obj.level+1; - $.each(xpath_object, function(key, val) { - self.increase_level(val, level) - }); + self.increase_level(xpath_object[0], level) obj.child_id.push(xpath_object[0]); xpath_object.pop(); - console.log("check",check,obj) + return; + } } - return obj; - }else{ - _.each(val,function(element){ + else { + _.each(val,function(element){ self.full_path_search(check_list ,element.child_id ,xpath_object); - }); - } - } - }, - - search_object : function(val ,list , xpath_object){ - var self = this; - if(xpath_object.length != 0){ - var main_list = _.flatten(val.att_list); - list = _.uniq(list); - var insert = _.intersection(main_list,list); - if(insert.length == list.length ){ - var level = val.level+1; - $.each(xpath_object, function(key, val) { - self.increase_level(val, level) - }); - val.child_id.push(xpath_object[0]); - xpath_object.pop(); - return; - }else{ - $.each(val.child_id, function(key, val) { - self.search_object(val, list, xpath_object); }); } } diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index aecb7e534ea..4f082c49fff 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -918,6 +918,11 @@ openerp.web.form.WidgetButton = openerp.web.form.Widget.extend({ on_confirmed: function() { var self = this; + if(this.node.attrs.context && (!f_context.__ref)) + _.extend(this.view.dataset.context, this.view.datatarecord); + + + return this.view.do_execute_action( this.node.attrs, this.view.dataset, this.view.datarecord.id, function () { self.view.reload(); @@ -928,7 +933,7 @@ openerp.web.form.WidgetButton = openerp.web.form.Widget.extend({ this.check_disable(); }, check_disable: function() { - if (this.force_disabled || !this.view.is_interactible_record()) { + if (this.force_disabled || !this.view.is_interactible_record() || this.readonly) { this.$element.find("button").attr("disabled", "disabled"); this.$element.find("button").css("color", "grey"); } else { From 560206d3c43903a5bf97319f09516fdb868ae6aa Mon Sep 17 00:00:00 2001 From: "Vidhin Mehta (OpenERP)" Date: Wed, 12 Oct 2011 16:06:08 +0530 Subject: [PATCH 8/9] [fix]removed other file's changes. bzr revid: vme@tinyerp.com-20111012103608-y20172v3uhcmcrs2 --- addons/web/static/src/js/view_form.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 4f082c49fff..aecb7e534ea 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -918,11 +918,6 @@ openerp.web.form.WidgetButton = openerp.web.form.Widget.extend({ on_confirmed: function() { var self = this; - if(this.node.attrs.context && (!f_context.__ref)) - _.extend(this.view.dataset.context, this.view.datatarecord); - - - return this.view.do_execute_action( this.node.attrs, this.view.dataset, this.view.datarecord.id, function () { self.view.reload(); @@ -933,7 +928,7 @@ openerp.web.form.WidgetButton = openerp.web.form.Widget.extend({ this.check_disable(); }, check_disable: function() { - if (this.force_disabled || !this.view.is_interactible_record() || this.readonly) { + if (this.force_disabled || !this.view.is_interactible_record()) { this.$element.find("button").attr("disabled", "disabled"); this.$element.find("button").css("color", "grey"); } else { From 2f2832f598445cf4266847158208b261fdeb58f4 Mon Sep 17 00:00:00 2001 From: "Vidhin Mehta (OpenERP)" Date: Wed, 12 Oct 2011 17:07:46 +0530 Subject: [PATCH 9/9] [IMP] // with any level supported. bzr revid: vme@tinyerp.com-20111012113746-9ozx06oet5l3hudx --- addons/web/static/src/js/view_editor.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/addons/web/static/src/js/view_editor.js b/addons/web/static/src/js/view_editor.js index 988a0330856..2881a9a217b 100644 --- a/addons/web/static/src/js/view_editor.js +++ b/addons/web/static/src/js/view_editor.js @@ -182,17 +182,13 @@ openerp.web.ViewEditor = openerp.web.Widget.extend({ var parent_id; var check_list = []; var xpath_object = self.parse_xml(xml,result.id); - if (xml.tagName.toLowerCase() == "xpath" && ($(xml).attr('expr')).indexOf("//") == -1) { + if (xml.tagName.toLowerCase() == "xpath" ) { var part_expr = _.without($(xml).attr('expr').split("/"),""); _.each(part_expr,function(part){ check_list.push(_.without($.trim(part.replace(/[^a-zA-Z 0-9 _]+/g,'!')).split("!"),"")); }); } else { - if($(xml).attr('expr')){ - check_list = [$.trim(($(xml).attr('expr')).replace(/[^a-zA-Z 0-9 _]+/g,' ')).split(" ")]; - }else{ check_list = [_.flatten(xpath_object[0].child_id[0].att_list)]; - } } self.full_path_search(check_list ,one_object ,xpath_object); });