height: 500,
buttons: {
"Create": function(){
-
+
},
"Edit": function(){
self.xml_id = 0 ;
self.get_data();
-
+
},
"Close": function(){
$(this).dialog('destroy');
},
});
- this.dialog.start();
+ this.dialog.start();
this.dialog.open();
action_manager.appendTo(this.dialog);
action_manager.do_action(action);
obj.child_id = [];
obj.id = this.xml_id++;
obj.level = level;
+ var vidhin = xml;
var att_list = [];
var name1 = "<" + tag;
+ var xml_tag = "<" + 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+'"';}
+ xml_tag += ' ' +attrs.nodeName+'='+'"'+attrs.nodeValue+'"';
+ if (tag != 'button'){
+ if(attrs.nodeName == "string" || attrs.nodeName == "name" || attrs.nodeName == "index"){
+ name1 += ' ' +attrs.nodeName+'='+'"'+attrs.nodeValue+'"';}
+ }else{
+ if(attrs.nodeName == "name"){
+ name1 += ' ' +attrs.nodeName+'='+'"'+attrs.nodeValue+'"';}
+ }
});
name1+= ">";
- });
+ xml_tag+= ">";
+ });
+ obj.main_xml = xml_tag;
obj.name = name1;
return obj;
},
}
},
- children_function : function(xml,root,parent_list,parent_id,main_object){
+ children_function : function(xml,root,parent_list,parent_id,main_object,parent_child_id){
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 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});
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(key,val) {
- self.save_object(val,parent_list.slice(1),child_obj_list);
+ 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);
+ (children_list[i],children_list[i].tagName.toLowerCase(),parent_list,child_obj_list[i].id,main_object,parent_child_id);
}
- return main_object;
+ return {"main_object":main_object,"parent_child_id":parent_child_id};
+ },
+ parse_xml :function(arch){
+ var self = this;
+ var root = $(arch).filter(":first")[0];
+ var tag = root.tagName.toLowerCase();
+ var root_object = self.check_attr(root,tag,0);
+ var one_object = self.children_function(arch,tag,[],0,[root_object],[]);
+ return self.edit_view(one_object);
},
get_data : function(){
var self = this;
var view_id =(($("input[name='radiogroup']:checked").parent()).parent()).attr('data-id');
+ dataset = new openerp.web.DataSetSearch(this,'ir.ui.view', null, null);
+ dataset.read_slice([],{domain : [['inherit_id','=',parseInt(view_id)]]},function (result) {
+ _.each(result ,function(num){console.log(result);});
+ });
var ve_dataset = new openerp.web.DataSet(this,'ir.ui.view');
ve_dataset.read_ids([parseInt(view_id)],['arch'],function (arch){
- var arch = arch[0].arch;
- var root = $(arch).filter(":first")[0];
- var tag = root.tagName.toLowerCase();
- var root_object = self.check_attr(root,tag,0);
- var one_object = self.children_function(arch,tag,[],0,[root_object]);
- return self.edit_view(one_object);
+ self.parse_xml(arch[0].arch);
});
},
- edit_view : function(o){
+ edit_view : function(one_object){
var self = this;
- this.dialog = new openerp.web.Dialog(this,{
- modal: true,
- title: 'Edit Xml',
- width: 750,
- height: 500,
- buttons: {
- "Inherited View": function(){
-
- },
- "Preview": function(){
-
- },
- "Close": function(){
- $(this).dialog('destroy');
- }
+ this.dialog = new openerp.web.Dialog(this,{
+ modal: true,
+ title: 'Edit Xml',
+ width: 750,
+ height: 500,
+ buttons: {
+ "Inherited View": function(){
+
+ },
+ "Preview": function(){
+
+ },
+ "Close": function(){
+ $(this).dialog('destroy');
}
- });
+ }
+ });
+ this.dialog.start().open();
+ this.dialog.$element.html(QWeb.render('view_editor', {
+ 'data': one_object['main_object'],
+ }));
+
+ $("tr[id^='viewedit-']").click(function() {
+ $("tr[id^='viewedit-']").removeClass('ui-selected');
+ $(this).addClass('ui-selected');
+ });
- this.dialog.start().open();
- this.dialog.$element.html(QWeb.render('view_editor', {
- 'data': o,
- }));
+ $("img[id^='parentimg-']").click(function() {
+ if ($(this).attr('src') == '/web/static/src/img/collapse.gif'){
+ $(this).attr('src', '/web/static/src/img/expand.gif');
+ self.on_expand(this);
+ }else{
+ $(this).attr('src', '/web/static/src/img/collapse.gif');
+ self.on_collapse(this,one_object['parent_child_id']);
+ }
+ });
+ $("img[id^='side-']").click(function() {
+ var side = $(this).closest("'tr[id^='viewedit-']'")
+ var id_tr = (side.attr('id')).split('-')[1];
+ switch (this.id)
+ {
+ case "side-add":
+ break;
+ case "side-remove":
+ break;
+ case "side-edit":
+ break;
+ case "side-up":
+ if(side.prev().attr('level') == side.attr('level')){
+ $(side.prev()).before(side);
+ }
+ break;
+ case "side-down":
+ var img = side.find("img[id='parentimg-"+id_tr+"']").attr('src');
+ var level = side.attr('level');
+ var list_shift =[];
+ var last_tr;
+ list_shift.push(side);
+ if(img){
+ while(1){
+ var next_tr = side.next();
+ if(next_tr.attr('level') <= level || next_tr.length==0){
+ last_tr = next_tr;
+ break;
+ }else{
+ list_shift.push(next_tr);
+ side = next_tr;
+ }
+ }
+ }else{last_tr = side.next();}
+ var last_tr_id = (last_tr.attr('id')).split('-')[1];
+ img = last_tr.find("img[id='parentimg-"+last_tr_id+"']").attr('src');
+ if(img){
+ while(1){
+ var nxt_tr = last_tr.next();
+ if (nxt_tr.attr('level') <= level || nxt_tr.length==0){break;}
+ last_tr = nxt_tr;
+ }
+ list_shift.reverse()
+
+ }
+ _.each(list_shift,function(rec){
+ $(last_tr).after(rec);
+ });
+ break;
+ }
+ });
+ },
+ on_expand: function(self){
+ var level = $(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){
+ cur_tr = nxt_tr;
+ nxt_tr.hide();
+ }else return nxt_tr;
+ }
+ },
+ on_collapse: function(self,parent_child_id,id){
+ var id = self.id.split('-')[1];
+ var datas = _.detect(parent_child_id,function(res){
+ return res.key == id;
+ });
+ _.each(datas.value,function(rec){
+ var tr = $("tr[id='viewedit-"+rec+"']");
+ tr.find("img[id='parentimg-"+rec+"']").attr('src','/web/static/src/img/expand.gif');
+ tr.show();
+ });
}
-
});
};