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++;
70 var name1 = "<" + tag;
71 var xml_tag = "<" + tag;
72 $(xml).each(function() {
73 att_list = this.attributes;
74 att_list = _.select(att_list, function(attrs){
75 xml_tag += ' ' +attrs.nodeName+'='+'"'+attrs.nodeValue+'"';
77 if(attrs.nodeName == "string" || attrs.nodeName == "name" || attrs.nodeName == "index"){
78 name1 += ' ' +attrs.nodeName+'='+'"'+attrs.nodeValue+'"';}
80 if(attrs.nodeName == "name"){
81 name1 += ' ' +attrs.nodeName+'='+'"'+attrs.nodeValue+'"';}
87 obj.main_xml = xml_tag;
92 save_object : function(val,parent_list,child_obj_list){
94 var check_id = parent_list[0];
95 var p_list = parent_list.slice(1);
96 if(val.child_id.length != 0){
97 $.each(val.child_id, function(key,val) {
100 self.save_object(val,p_list,child_obj_list);
102 val.child_id = child_obj_list;
108 val.child_id = child_obj_list;
112 children_function : function(xml,root,parent_list,parent_id,main_object,parent_child_id){
114 var child_obj_list = [];
115 var parent_child_id = parent_child_id;
116 var parent_list = parent_list;
117 var main_object = main_object;
118 var children_list = $(xml).filter(root).children();
119 var parents = $(children_list[0]).parents().get();
120 _.each(children_list, function(child_node){
121 var string = self.check_attr(child_node,child_node.tagName.toLowerCase(),parents.length);
122 child_obj_list.push(string);
125 if(children_list.length != 0){
126 var child_ids = _.map(child_obj_list ,function(num){return num.id;});
127 parent_child_id.push({'key': parent_id, 'value': child_ids});
128 var parents = $(children_list[0]).parents().get();
129 if(parents.length <= parent_list.length){
130 parent_list.splice(parents.length-1);}
131 parent_list.push(parent_id);
132 $.each(main_object, function(key,val) {
133 self.save_object(val,parent_list.slice(1),child_obj_list);
136 for(var i=0;i<children_list.length;i++){
137 self.children_function
138 (children_list[i],children_list[i].tagName.toLowerCase(),parent_list,child_obj_list[i].id,main_object,parent_child_id);
140 return {"main_object":main_object,"parent_child_id":parent_child_id};
142 parse_xml :function(arch){
144 var root = $(arch).filter(":first")[0];
145 var tag = root.tagName.toLowerCase();
146 var root_object = self.check_attr(root,tag,0);
147 var one_object = self.children_function(arch,tag,[],0,[root_object],[]);
148 return self.edit_view(one_object);
150 get_data : function(){
152 var view_id =(($("input[name='radiogroup']:checked").parent()).parent()).attr('data-id');
153 dataset = new openerp.web.DataSetSearch(this,'ir.ui.view', null, null);
154 dataset.read_slice([],{domain : [['inherit_id','=',parseInt(view_id)]]},function (result) {
155 _.each(result ,function(num){console.log(result);});
157 var ve_dataset = new openerp.web.DataSet(this,'ir.ui.view');
158 ve_dataset.read_ids([parseInt(view_id)],['arch'],function (arch){
159 self.parse_xml(arch[0].arch);
162 edit_view : function(one_object){
164 this.dialog = new openerp.web.Dialog(this,{
170 "Inherited View": function(){
173 "Preview": function(){
177 $(this).dialog('destroy');
181 this.dialog.start().open();
182 this.dialog.$element.html(QWeb.render('view_editor', {
183 'data': one_object['main_object'],
186 $("tr[id^='viewedit-']").click(function() {
187 $("tr[id^='viewedit-']").removeClass('ui-selected');
188 $(this).addClass('ui-selected');
191 $("img[id^='parentimg-']").click(function() {
192 if ($(this).attr('src') == '/web/static/src/img/collapse.gif'){
193 $(this).attr('src', '/web/static/src/img/expand.gif');
194 self.on_expand(this);
196 $(this).attr('src', '/web/static/src/img/collapse.gif');
197 self.on_collapse(this,one_object['parent_child_id']);
200 $("img[id^='side-']").click(function() {
201 var side = $(this).closest("'tr[id^='viewedit-']'");
211 if(side.prev().attr('level') == side.attr('level')){
212 $(side.prev()).before(side);
216 if(side.next().attr('level') == side.attr('level')){
217 $(side.next()).after(side);
223 search_object:function(main_object){
226 on_expand: function(self){
227 var level = $(self).closest("tr[id^='viewedit-']").attr('level');
228 var cur_tr = $(self).closest("tr[id^='viewedit-']");
230 var nxt_tr = cur_tr.next();
231 if (nxt_tr.attr('level') > level){
237 on_collapse: function(self,parent_child_id){
238 var id = self.id.split('-')[1];
239 var datas = _.detect(parent_child_id,function(res){
240 return res.key == id;
242 _.each(datas.value,function(rec){
243 var tr = $("tr[id='viewedit-"+rec+"']");
244 tr.find("img[id='parentimg-"+rec+"']").attr('src','/web/static/src/img/expand.gif');