2011-09-14 05:37:46 +00:00
|
|
|
openerp.web.view_editor = function(openerp) {
|
2011-09-15 12:28:37 +00:00
|
|
|
var QWeb = openerp.web.qweb;
|
|
|
|
openerp.web.ViewEditor = openerp.web.Widget.extend({
|
2011-08-23 10:39:41 +00:00
|
|
|
init: function(parent, element_id, dataset, view, options) {
|
|
|
|
this._super(parent);
|
|
|
|
this.element_id = element_id
|
|
|
|
this.parent = parent
|
|
|
|
this.dataset = dataset;
|
|
|
|
this.model = dataset.model;
|
2011-09-13 13:28:29 +00:00
|
|
|
this.xml_id = 0;
|
2011-08-23 10:39:41 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2011-09-13 13:28:29 +00:00
|
|
|
this.View_editor();
|
|
|
|
},
|
|
|
|
View_editor : function(){
|
2011-08-23 10:39:41 +00:00
|
|
|
var self = this;
|
2011-08-23 10:40:54 +00:00
|
|
|
var action = {
|
|
|
|
name:'ViewEditor',
|
|
|
|
context:this.session.user_context,
|
2011-08-31 11:00:36 +00:00
|
|
|
domain: [["model", "=", this.dataset.model]],
|
2011-08-23 10:40:54 +00:00
|
|
|
res_model: 'ir.ui.view',
|
|
|
|
views : [[false, 'list']],
|
|
|
|
type: 'ir.actions.act_window',
|
|
|
|
target: "current",
|
|
|
|
limit : 80,
|
|
|
|
auto_search : true,
|
|
|
|
flags: {
|
|
|
|
sidebar: false,
|
|
|
|
views_switcher: false,
|
|
|
|
action_buttons:false,
|
|
|
|
search_view:false,
|
|
|
|
pager:false,
|
2011-09-05 12:32:36 +00:00
|
|
|
radio:true
|
2011-08-23 10:40:54 +00:00
|
|
|
},
|
|
|
|
};
|
2011-09-14 05:37:46 +00:00
|
|
|
var action_manager = new openerp.web.ActionManager(this);
|
|
|
|
this.dialog = new openerp.web.Dialog(this,{
|
2011-08-23 10:40:54 +00:00
|
|
|
modal: true,
|
|
|
|
title: 'ViewEditor',
|
2011-09-05 12:32:36 +00:00
|
|
|
width: 750,
|
2011-08-23 10:40:54 +00:00
|
|
|
height: 500,
|
|
|
|
buttons: {
|
2011-09-05 12:32:36 +00:00
|
|
|
"Create": function(){
|
2011-09-13 13:28:29 +00:00
|
|
|
|
2011-08-23 10:40:54 +00:00
|
|
|
},
|
2011-09-05 12:32:36 +00:00
|
|
|
"Edit": function(){
|
2011-09-16 13:24:11 +00:00
|
|
|
self.xml_id = 0 ;
|
|
|
|
self.get_data();
|
|
|
|
|
2011-08-23 10:40:54 +00:00
|
|
|
},
|
2011-09-13 13:28:29 +00:00
|
|
|
"Close": function(){
|
|
|
|
$(this).dialog('destroy');
|
2011-08-23 10:40:54 +00:00
|
|
|
}
|
|
|
|
},
|
2011-09-05 12:32:36 +00:00
|
|
|
|
2011-08-23 10:40:54 +00:00
|
|
|
});
|
2011-09-05 12:32:36 +00:00
|
|
|
this.dialog.start();
|
2011-08-23 10:40:54 +00:00
|
|
|
this.dialog.open();
|
|
|
|
action_manager.appendTo(this.dialog);
|
|
|
|
action_manager.do_action(action);
|
2011-09-13 13:28:29 +00:00
|
|
|
},
|
2011-09-16 13:24:11 +00:00
|
|
|
|
|
|
|
check_attr:function(xml,tag,level){
|
2011-09-13 13:28:29 +00:00
|
|
|
var obj = new Object();
|
|
|
|
obj.child_id = [];
|
|
|
|
obj.id = this.xml_id++;
|
2011-09-16 13:24:11 +00:00
|
|
|
obj.level = level;
|
2011-09-13 13:28:29 +00:00
|
|
|
var att_list = [];
|
|
|
|
var name1 = "<" + tag;
|
|
|
|
$(xml).each(function() {
|
|
|
|
att_list = this.attributes;
|
|
|
|
att_list = _.select(att_list, function(attrs){
|
2011-09-20 12:43:02 +00:00
|
|
|
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+'"';}
|
|
|
|
}
|
|
|
|
});
|
2011-09-13 13:28:29 +00:00
|
|
|
name1+= ">";
|
|
|
|
});
|
|
|
|
obj.name = name1;
|
|
|
|
return obj;
|
|
|
|
},
|
2011-09-16 13:24:11 +00:00
|
|
|
|
2011-09-15 12:28:37 +00:00
|
|
|
save_object : function(val,parent_list,child_obj_list){
|
2011-09-13 13:28:29 +00:00
|
|
|
var self = this;
|
2011-09-15 12:28:37 +00:00
|
|
|
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{
|
|
|
|
val.child_id = child_obj_list;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
val.child_id = child_obj_list;
|
2011-09-13 13:28:29 +00:00
|
|
|
}
|
|
|
|
},
|
2011-09-16 13:24:11 +00:00
|
|
|
|
2011-09-20 13:39:11 +00:00
|
|
|
children_function : function(xml,root,parent_list,parent_id,main_object,parent_child_id){
|
2011-09-13 13:28:29 +00:00
|
|
|
var self = this;
|
|
|
|
var child_obj_list = [];
|
2011-09-20 13:39:11 +00:00
|
|
|
var parent_child_id = parent_child_id;
|
2011-09-15 12:28:37 +00:00
|
|
|
var parent_list = parent_list;
|
2011-09-13 13:28:29 +00:00
|
|
|
var main_object = main_object;
|
|
|
|
var children_list = $(xml).filter(root).children();
|
2011-09-16 13:24:11 +00:00
|
|
|
var parents = $(children_list[0]).parents().get();
|
2011-09-13 13:28:29 +00:00
|
|
|
_.each(children_list, function(child_node){
|
2011-09-16 13:24:11 +00:00
|
|
|
var string = self.check_attr(child_node,child_node.tagName.toLowerCase(),parents.length);
|
2011-09-13 13:28:29 +00:00
|
|
|
child_obj_list.push(string);
|
|
|
|
});
|
|
|
|
if(children_list.length != 0){
|
2011-09-20 13:39:11 +00:00
|
|
|
parent_child_id.push({key: parent_id, value: child_obj_list});
|
|
|
|
|
2011-09-15 12:28:37 +00:00
|
|
|
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);
|
|
|
|
});
|
2011-09-13 13:28:29 +00:00
|
|
|
}
|
|
|
|
for(var i=0;i<children_list.length;i++){
|
2011-09-15 12:28:37 +00:00
|
|
|
self.children_function
|
2011-09-20 13:39:11 +00:00
|
|
|
(children_list[i],children_list[i].tagName.toLowerCase(),parent_list,child_obj_list[i].id,main_object,parent_child_id);
|
2011-09-13 13:28:29 +00:00
|
|
|
}
|
2011-09-20 13:39:11 +00:00
|
|
|
return {"main_object":main_object,"parent_child_id":parent_child_id};
|
2011-09-13 13:28:29 +00:00
|
|
|
},
|
2011-09-16 13:24:11 +00:00
|
|
|
get_data : function(){
|
2011-09-20 13:39:11 +00:00
|
|
|
|
2011-09-13 13:28:29 +00:00
|
|
|
var self = this;
|
|
|
|
var view_id =(($("input[name='radiogroup']:checked").parent()).parent()).attr('data-id');
|
2011-09-14 05:37:46 +00:00
|
|
|
var ve_dataset = new openerp.web.DataSet(this,'ir.ui.view');
|
2011-09-16 13:24:11 +00:00
|
|
|
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);
|
2011-09-20 13:39:11 +00:00
|
|
|
var one_object = self.children_function(arch,tag,[],0,[root_object],[]);
|
2011-09-16 13:24:11 +00:00
|
|
|
return self.edit_view(one_object);
|
|
|
|
});
|
|
|
|
},
|
2011-09-20 12:43:02 +00:00
|
|
|
edit_view : function(one_object){
|
2011-09-16 13:24:11 +00:00
|
|
|
var self = this;
|
2011-09-14 05:37:46 +00:00
|
|
|
this.dialog = new openerp.web.Dialog(this,{
|
2011-09-16 13:24:11 +00:00
|
|
|
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', {
|
2011-09-20 13:39:11 +00:00
|
|
|
'data': one_object['main_object'],
|
2011-09-16 13:24:11 +00:00
|
|
|
}));
|
2011-09-20 12:43:02 +00:00
|
|
|
|
|
|
|
$("tr[id^='viewedit-']").click(function() {
|
|
|
|
$("tr[id^='viewedit-']").removeClass('ui-selected');
|
|
|
|
$(this).addClass('ui-selected');
|
|
|
|
});
|
|
|
|
|
|
|
|
$("img[id^='parentimg-']").click(function() {
|
|
|
|
if ($(this).attr('src') == '/web/static/src/img/collapse.gif'){
|
|
|
|
$(this).attr('src', '/web/static/src/img/expand.gif');
|
|
|
|
}else{
|
|
|
|
$(this).attr('src', '/web/static/src/img/collapse.gif');
|
|
|
|
}
|
|
|
|
});
|
2011-09-05 12:32:36 +00:00
|
|
|
}
|
2011-09-20 12:43:02 +00:00
|
|
|
|
2011-09-05 12:32:36 +00:00
|
|
|
|
2011-08-23 10:39:41 +00:00
|
|
|
});
|
|
|
|
};
|