vidhin mehta[Open Erp] has proposed merging
lp:~openerp-dev/openerp-web/trunk-vieweditor-all_xpath-vme into
lp:~openerp-dev/openerp-web/trunk-vieweditor-sma.
Requested reviews:
OpenERP R&D Team (openerp-dev)
For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-vieweditor-all_xpath-vme/+merge/78912
In View Editor all inherited view xml displayed with its proper position.
--
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-vieweditor-all_xpath-vme/+merge/78912
Your team OpenERP R&D Team is requested to review the proposed merge of
lp:~openerp-dev/openerp-web/trunk-vieweditor-all_xpath-vme into
lp:~openerp-dev/openerp-web/trunk-vieweditor-sma.
=== modified file 'addons/web/static/src/js/view_editor.js'
--- addons/web/static/src/js/view_editor.js 2011-10-04 10:45:50 +0000
+++ addons/web/static/src/js/view_editor.js 2011-10-11 05:10:41 +0000
@@ -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
@@ -65,26 +64,28 @@
var obj = new Object();
obj.child_id = [];
obj.id = this.xml_id++;
- obj.level = level;
- var att_list = [];
+ obj.level = level+1;
+ obj.att_list = [];
var render_name = "<" + tag;
- var xml_tag = "<" + tag;
+ obj.att_list = [];
+ obj.att_list.push(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") {
- render_name += ' ' + attrs.nodeName + '=' + '"' + attrs.nodeValue + '"';
- }
- } else {
- if (attrs.nodeName == "name") render_name += ' ' + attrs.nodeName + '=' + '"' + attrs.nodeValue + '"';
- }
- });
- render_name += ">";
- xml_tag += ">";
- });
- obj.main_xml = xml_tag;
+ _.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") {
+ render_name += ' ' + attrs.nodeName + '=' + '"' + attrs.nodeValue + '"'; }
+ }
+ if (attrs.nodeName != "position") {
+ obj.att_list.push( [attrs.nodeName,attrs.nodeValue] );
+ }
+
+ });
+
+ render_name+= ">";
+ });
obj.name = render_name;
return obj;
},
@@ -109,12 +110,9 @@
}
},
- 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) {
@@ -122,8 +120,6 @@
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});
var parents = $(children_list[0]).parents().get();
if (parents.length <= parent_list.length) {
parent_list.splice(parents.length - 1);
@@ -133,22 +129,32 @@
self.save_object(val, parent_list.slice(1), child_obj_list);
});
}
-
- for(var i=0; i<children_list.length; i++){
- self.children_function(children_list[i], children_list[i].tagName.toLowerCase(),
- parent_list,child_obj_list[i].id, main_object,parent_child_id);
+ for (var i=0;i<children_list.length;i++) {
+ self.children_function
+ (children_list[i], children_list[i].tagName.toLowerCase(),
+ parent_list, child_obj_list[i].id, main_object);
}
- return {"main_object": main_object, "parent_child_id": parent_child_id};
+ 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();
- var root_object = this.check_attr(root, tag, this.xml_id);
- return this.children_function(arch, tag, [], this.xml_id - 1, [root_object], []);
+ var obj = new Object();
+ obj.child_id = [];
+ obj.id = this.xml_id++;
+ obj.level = 0;
+ obj.name = "<view view_id='"+view_id+"'>"
+ 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');
@@ -160,76 +166,117 @@
_.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('*');
- var xpath_list = [];
+ var xml_list = [];
+ var xpath_object ;
var part_expr = [];
- var position ;
if (root[0].tagName.toLowerCase() == "data") {
- _.each($(root).find('xpath'), function(xpath) {
- xpath_list.push(xpath);
+ xml_list = $(root[0]).children();
+ } else {
+ xml_list.push(root[0]);
+ }
+ _.each(xml_list , function(xml){
+ var parent_id;
+ var check_list = [];
+ 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);
+ });
+ }
+ });
+ },
+ full_path_search: function(part_expr ,val ,xpath_object, one_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(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;}
});
- } else if(root[0].tagName.toLowerCase() == "xpath") {
- xpath_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(val, key) {
- 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);
- }
- });
- });
- }
- });
+ }
+ 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]);
+ }else{
+ $.each(one_object, function(key, val){
+ self.search_object(val, check_list, xpath_object);
+ });
+ }
+ }
+ return obj;
},
- search_object:function(val, list, p_list, position, xpath_object, r_list) {
+
+ search_object : function(val ,list , 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(val, key) {
+ 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)
});
- var index = _.indexOf(p_list.child_id, val);
- if (position == "before") {
- if (index != 0) { index--; }
- } else if (position == "after") {
- index++;
- }
- 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(val, key) {
- self.search_object(val, list, p_list, position, xpath_object, return_list);
+ 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);
});
}
}
- return return_list;
},
increase_level: function(val, level) {
var self = this;
@@ -238,6 +285,7 @@
self.increase_level(val, level + 1);
});
},
+
edit_view : function(one_object){
var self = this;
this.dialog = new openerp.web.Dialog(this,{
@@ -358,11 +406,11 @@
});
},
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;
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp