1 openerp.web.view_editor = function(openerp) {
2 var QWeb = openerp.web.qweb;
3 openerp.web.ViewEditor = openerp.web.Widget.extend({
4 init: function(parent, element_id, dataset, view, options) {
6 this.element_id = element_id
8 this.dataset = dataset;
9 this.model = dataset.model;
15 View_editor : function(){
19 context:this.session.user_context,
20 domain: [["model", "=", this.dataset.model]],
21 res_model: 'ir.ui.view',
22 views : [[false, 'list']],
23 type: 'ir.actions.act_window',
29 views_switcher: false,
36 var action_manager = new openerp.web.ActionManager(this);
37 this.dialog = new openerp.web.Dialog(this,{
52 $(this).dialog('destroy');
59 action_manager.appendTo(this.dialog);
60 action_manager.do_action(action);
63 check_attr:function(xml,tag,level){
64 var obj = new Object();
66 obj.id = this.xml_id++;
69 var name1 = "<" + tag;
70 $(xml).each(function() {
71 att_list = this.attributes;
72 att_list = _.select(att_list, function(attrs){
74 if(attrs.nodeName == "string" || attrs.nodeName == "name" || attrs.nodeName == "index"){
75 name1 += ' ' +attrs.nodeName+'='+'"'+attrs.nodeValue+'"';}
77 if(attrs.nodeName == "name"){
78 name1 += ' ' +attrs.nodeName+'='+'"'+attrs.nodeValue+'"';}
87 save_object : function(val,parent_list,child_obj_list){
89 var check_id = parent_list[0];
90 var p_list = parent_list.slice(1);
91 if(val.child_id.length != 0){
92 $.each(val.child_id, function(key,val) {
95 self.save_object(val,p_list,child_obj_list);
97 val.child_id = child_obj_list;
103 val.child_id = child_obj_list;
107 children_function : function(xml,root,parent_list,parent_id,main_object,parent_child_id){
109 var child_obj_list = [];
110 var parent_child_id = parent_child_id;
111 var parent_list = parent_list;
112 var main_object = main_object;
113 var children_list = $(xml).filter(root).children();
114 var parents = $(children_list[0]).parents().get();
115 _.each(children_list, function(child_node){
116 var string = self.check_attr(child_node,child_node.tagName.toLowerCase(),parents.length);
117 child_obj_list.push(string);
119 if(children_list.length != 0){
120 parent_child_id.push({key: parent_id, value: child_obj_list});
122 var parents = $(children_list[0]).parents().get();
123 if(parents.length <= parent_list.length){
124 parent_list.splice(parents.length-1);}
125 parent_list.push(parent_id);
126 $.each(main_object, function(key,val) {
127 self.save_object(val,parent_list.slice(1),child_obj_list);
130 for(var i=0;i<children_list.length;i++){
131 self.children_function
132 (children_list[i],children_list[i].tagName.toLowerCase(),parent_list,child_obj_list[i].id,main_object,parent_child_id);
134 return {"main_object":main_object,"parent_child_id":parent_child_id};
136 get_data : function(){
139 var view_id =(($("input[name='radiogroup']:checked").parent()).parent()).attr('data-id');
140 var ve_dataset = new openerp.web.DataSet(this,'ir.ui.view');
141 ve_dataset.read_ids([parseInt(view_id)],['arch'],function (arch){
142 var arch = arch[0].arch;
143 var root = $(arch).filter(":first")[0];
144 var tag = root.tagName.toLowerCase();
145 var root_object = self.check_attr(root,tag,0);
146 var one_object = self.children_function(arch,tag,[],0,[root_object],[]);
147 return self.edit_view(one_object);
150 edit_view : function(one_object){
152 this.dialog = new openerp.web.Dialog(this,{
158 "Inherited View": function(){
161 "Preview": function(){
165 $(this).dialog('destroy');
169 this.dialog.start().open();
170 this.dialog.$element.html(QWeb.render('view_editor', {
171 'data': one_object['main_object'],
174 $("tr[id^='viewedit-']").click(function() {
175 $("tr[id^='viewedit-']").removeClass('ui-selected');
176 $(this).addClass('ui-selected');
179 $("img[id^='parentimg-']").click(function() {
180 if ($(this).attr('src') == '/web/static/src/img/collapse.gif'){
181 $(this).attr('src', '/web/static/src/img/expand.gif');
183 $(this).attr('src', '/web/static/src/img/collapse.gif');