2011-09-14 05:37:46 +00:00
|
|
|
openerp.web.view_editor = function(openerp) {
|
2011-10-04 05:42:16 +00:00
|
|
|
var _PROPERTIES = {
|
2011-10-13 11:00:39 +00:00
|
|
|
'field' : ['name', 'string', 'required', 'readonly', 'domain', 'context', 'nolabel', 'completion',
|
2011-10-25 13:13:12 +00:00
|
|
|
'colspan', 'widget', 'eval', 'ref', 'on_change', 'groups', 'attrs'],
|
2011-10-04 05:42:16 +00:00
|
|
|
'form' : ['string', 'col', 'link'],
|
|
|
|
'notebook' : ['colspan', 'position', 'groups'],
|
|
|
|
'page' : ['string', 'states', 'attrs', 'groups'],
|
|
|
|
'group' : ['string', 'col', 'colspan', 'states', 'attrs', 'groups'],
|
|
|
|
'image' : ['filename', 'width', 'height', 'groups'],
|
|
|
|
'separator' : ['string', 'colspan', 'groups'],
|
|
|
|
'label': ['string', 'align', 'colspan', 'groups'],
|
|
|
|
'button': ['name', 'string', 'icon', 'type', 'states', 'readonly', 'special', 'target', 'confirm', 'context', 'attrs', 'groups'],
|
|
|
|
'newline' : [],
|
|
|
|
'hpaned': ['position', 'groups'],
|
|
|
|
'vpaned': ['position', 'groups'],
|
|
|
|
'child1' : ['groups'],
|
|
|
|
'child2' : ['groups'],
|
|
|
|
'action' : ['name', 'string', 'colspan', 'groups'],
|
|
|
|
'tree' : ['string', 'colors', 'editable', 'link', 'limit', 'min_rows'],
|
|
|
|
'graph' : ['string', 'type'],
|
|
|
|
'calendar' : ['string', 'date_start', 'date_stop', 'date_delay', 'day_length', 'color', 'mode'],
|
|
|
|
'view' : [],
|
|
|
|
};
|
2011-11-01 13:22:57 +00:00
|
|
|
var icons = ['','STOCK_ABOUT', 'STOCK_ADD', 'STOCK_APPLY', 'STOCK_BOLD',
|
|
|
|
'STOCK_CANCEL', 'STOCK_CDROM', 'STOCK_CLEAR', 'STOCK_CLOSE', 'STOCK_COLOR_PICKER',
|
|
|
|
'STOCK_CONNECT', 'STOCK_CONVERT', 'STOCK_COPY', 'STOCK_CUT', 'STOCK_DELETE',
|
|
|
|
'STOCK_DIALOG_AUTHENTICATION', 'STOCK_DIALOG_ERROR', 'STOCK_DIALOG_INFO',
|
|
|
|
'STOCK_DIALOG_QUESTION', 'STOCK_DIALOG_WARNING', 'STOCK_DIRECTORY', 'STOCK_DISCONNECT',
|
|
|
|
'STOCK_DND', 'STOCK_DND_MULTIPLE', 'STOCK_EDIT', 'STOCK_EXECUTE', 'STOCK_FILE',
|
|
|
|
'STOCK_FIND', 'STOCK_FIND_AND_REPLACE', 'STOCK_FLOPPY', 'STOCK_GOTO_BOTTOM',
|
|
|
|
'STOCK_GOTO_FIRST', 'STOCK_GOTO_LAST', 'STOCK_GOTO_TOP', 'STOCK_GO_BACK',
|
|
|
|
'STOCK_GO_DOWN', 'STOCK_GO_FORWARD', 'STOCK_GO_UP', 'STOCK_HARDDISK',
|
|
|
|
'STOCK_HELP', 'STOCK_HOME', 'STOCK_INDENT', 'STOCK_INDEX', 'STOCK_ITALIC',
|
|
|
|
'STOCK_JUMP_TO', 'STOCK_JUSTIFY_CENTER', 'STOCK_JUSTIFY_FILL',
|
|
|
|
'STOCK_JUSTIFY_LEFT', 'STOCK_JUSTIFY_RIGHT', 'STOCK_MEDIA_FORWARD',
|
|
|
|
'STOCK_MEDIA_NEXT', 'STOCK_MEDIA_PAUSE', 'STOCK_MEDIA_PLAY',
|
|
|
|
'STOCK_MEDIA_PREVIOUS', 'STOCK_MEDIA_RECORD', 'STOCK_MEDIA_REWIND',
|
|
|
|
'STOCK_MEDIA_STOP', 'STOCK_MISSING_IMAGE', 'STOCK_NETWORK', 'STOCK_NEW',
|
|
|
|
'STOCK_NO', 'STOCK_OK', 'STOCK_OPEN', 'STOCK_PASTE', 'STOCK_PREFERENCES',
|
|
|
|
'STOCK_PRINT', 'STOCK_PRINT_PREVIEW', 'STOCK_PROPERTIES', 'STOCK_QUIT',
|
|
|
|
'STOCK_REDO', 'STOCK_REFRESH', 'STOCK_REMOVE', 'STOCK_REVERT_TO_SAVED',
|
|
|
|
'STOCK_SAVE', 'STOCK_SAVE_AS', 'STOCK_SELECT_COLOR', 'STOCK_SELECT_FONT',
|
|
|
|
'STOCK_SORT_ASCENDING', 'STOCK_SORT_DESCENDING', 'STOCK_SPELL_CHECK',
|
|
|
|
'STOCK_STOP', 'STOCK_STRIKETHROUGH', 'STOCK_UNDELETE', 'STOCK_UNDERLINE',
|
|
|
|
'STOCK_UNDO', 'STOCK_UNINDENT', 'STOCK_YES', 'STOCK_ZOOM_100',
|
|
|
|
'STOCK_ZOOM_FIT', 'STOCK_ZOOM_IN', 'STOCK_ZOOM_OUT',
|
|
|
|
'terp-account', 'terp-crm', 'terp-mrp', 'terp-product', 'terp-purchase',
|
|
|
|
'terp-sale', 'terp-tools', 'terp-administration', 'terp-hr', 'terp-partner',
|
|
|
|
'terp-project', 'terp-report', 'terp-stock', 'terp-calendar', 'terp-graph',
|
|
|
|
];
|
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;
|
2011-10-24 12:59:12 +00:00
|
|
|
this.model = this.dataset.model;
|
2011-09-13 13:28:29 +00:00
|
|
|
this.xml_id = 0;
|
2011-10-04 06:09:03 +00:00
|
|
|
this.property = openerp.web.ViewEditor.property_widget;
|
2011-08-23 10:39:41 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2011-09-13 13:28:29 +00:00
|
|
|
this.View_editor();
|
|
|
|
},
|
2011-10-12 12:40:52 +00:00
|
|
|
View_editor : function() {
|
2011-10-04 10:45:50 +00:00
|
|
|
var self = this;
|
|
|
|
var action = {
|
|
|
|
name:'ViewEditor',
|
|
|
|
context:this.session.user_context,
|
|
|
|
domain: [["model", "=", this.dataset.model]],
|
|
|
|
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,
|
|
|
|
radio:true
|
|
|
|
},
|
|
|
|
};
|
2011-11-02 06:41:27 +00:00
|
|
|
this.view_edit_dialog = new openerp.web.Dialog(this, {
|
2011-10-04 10:45:50 +00:00
|
|
|
modal: true,
|
|
|
|
title: 'ViewEditor',
|
|
|
|
width: 750,
|
|
|
|
height: 500,
|
|
|
|
buttons: {
|
2011-11-02 06:41:27 +00:00
|
|
|
"Create": function(){
|
|
|
|
//to do
|
|
|
|
},
|
|
|
|
"Edit": function(){
|
|
|
|
self.xml_id=0;
|
|
|
|
self.get_data();
|
|
|
|
},
|
|
|
|
"Close": function(){
|
|
|
|
self.view_edit_dialog.close();
|
|
|
|
}
|
2011-10-04 10:45:50 +00:00
|
|
|
},
|
|
|
|
});
|
2011-11-02 06:17:35 +00:00
|
|
|
this.view_edit_dialog.start().open();
|
|
|
|
var action_manager = new openerp.web.ActionManager(this);
|
2011-10-14 11:21:01 +00:00
|
|
|
action_manager.appendTo(this.view_edit_dialog);
|
2011-10-04 10:45:50 +00:00
|
|
|
action_manager.do_action(action);
|
2011-09-13 13:28:29 +00:00
|
|
|
},
|
2011-10-04 10:45:50 +00:00
|
|
|
check_attr: function(xml, tag, level) {
|
2011-11-02 06:41:27 +00:00
|
|
|
var obj = {'child_id': [], 'id': this.xml_id++, 'level': level+1, 'att_list': [], 'name': ""};
|
2011-09-30 12:49:32 +00:00
|
|
|
var render_name = "<" + tag;
|
2011-10-10 12:44:52 +00:00
|
|
|
obj.att_list.push(tag);
|
2011-09-13 13:28:29 +00:00
|
|
|
$(xml).each(function() {
|
2011-10-05 11:21:27 +00:00
|
|
|
_.each(this.attributes, function(attrs){
|
2011-11-04 05:03:38 +00:00
|
|
|
if ((tag != 'button') && (tag != 'field')){
|
2011-10-04 10:45:50 +00:00
|
|
|
if (attrs.nodeName == "string" || attrs.nodeName == "name" || attrs.nodeName == "index") {
|
2011-10-12 12:40:52 +00:00
|
|
|
render_name += ' ' + attrs.nodeName + '=' + '"' + attrs.nodeValue + '"' ;
|
2011-10-04 10:45:50 +00:00
|
|
|
}
|
2011-11-02 06:41:27 +00:00
|
|
|
} else {
|
|
|
|
if (attrs.nodeName == "name") {
|
|
|
|
render_name += ' ' + attrs.nodeName + '=' + '"' + attrs.nodeValue + '"';
|
|
|
|
}
|
2011-10-04 10:45:50 +00:00
|
|
|
}
|
2011-11-02 06:41:27 +00:00
|
|
|
obj.att_list.push( [attrs.nodeName,attrs.nodeValue] );
|
2011-10-04 10:45:50 +00:00
|
|
|
});
|
2011-10-12 12:40:52 +00:00
|
|
|
render_name+= ">";
|
2011-09-30 12:49:32 +00:00
|
|
|
});
|
|
|
|
obj.name = render_name;
|
2011-09-13 13:28:29 +00:00
|
|
|
return obj;
|
|
|
|
},
|
2011-10-12 10:28:01 +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);
|
2011-10-04 10:45:50 +00:00
|
|
|
if (val.child_id.length != 0) {
|
|
|
|
_.each(val.child_id, function(val, key) {
|
2011-10-17 13:21:16 +00:00
|
|
|
if (val.id == check_id) {
|
2011-10-04 10:45:50 +00:00
|
|
|
if (p_list.length!=0) {
|
|
|
|
self.save_object(val, p_list, child_obj_list);
|
|
|
|
} else {
|
2011-09-15 12:28:37 +00:00
|
|
|
val.child_id = child_obj_list;
|
2011-10-04 10:45:50 +00:00
|
|
|
return false;
|
2011-09-15 12:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-10-04 10:45:50 +00:00
|
|
|
} else {
|
2011-09-15 12:28:37 +00:00
|
|
|
val.child_id = child_obj_list;
|
2011-09-13 13:28:29 +00:00
|
|
|
}
|
|
|
|
},
|
2011-10-12 10:28:01 +00:00
|
|
|
xml_node_create: function(xml, root, parent_list, parent_id, main_object){
|
2011-09-13 13:28:29 +00:00
|
|
|
var self = this;
|
|
|
|
var child_obj_list = [];
|
|
|
|
var children_list = $(xml).filter(root).children();
|
2011-09-16 13:24:11 +00:00
|
|
|
var parents = $(children_list[0]).parents().get();
|
2011-10-04 10:45:50 +00:00
|
|
|
_.each(children_list, function (child_node) {
|
2011-10-12 10:28:01 +00:00
|
|
|
child_obj_list.push(self.check_attr(child_node,child_node.tagName.toLowerCase(),parents.length));
|
2011-09-13 13:28:29 +00:00
|
|
|
});
|
2011-10-04 10:45:50 +00:00
|
|
|
if (children_list.length != 0) {
|
|
|
|
if (parents.length <= parent_list.length) {
|
|
|
|
parent_list.splice(parents.length - 1);
|
2011-09-30 12:49:32 +00:00
|
|
|
}
|
2011-09-15 12:28:37 +00:00
|
|
|
parent_list.push(parent_id);
|
2011-10-12 10:28:01 +00:00
|
|
|
self.save_object(main_object[0], parent_list.slice(1), child_obj_list);
|
2011-09-13 13:28:29 +00:00
|
|
|
}
|
2011-11-02 06:41:27 +00:00
|
|
|
for (var i = 0; i < children_list.length; i++) {
|
2011-10-12 10:28:01 +00:00
|
|
|
self.xml_node_create
|
2011-10-05 11:21:27 +00:00
|
|
|
(children_list[i], children_list[i].tagName.toLowerCase(),
|
|
|
|
parent_list, child_obj_list[i].id, main_object);
|
2011-09-13 13:28:29 +00:00
|
|
|
}
|
2011-10-05 11:21:27 +00:00
|
|
|
return main_object;
|
2011-09-13 13:28:29 +00:00
|
|
|
},
|
2011-10-10 13:10:50 +00:00
|
|
|
parse_xml: function(arch, view_id) {
|
2011-09-23 13:04:06 +00:00
|
|
|
var root = $(arch).filter(":first")[0];
|
|
|
|
var tag = root.tagName.toLowerCase();
|
2011-10-12 10:28:01 +00:00
|
|
|
var obj ={'child_id':[],'id':this.xml_id++,'level':0,'att_list':[],'name':"<view view_id='"+view_id+"'>"};
|
2011-10-12 12:40:52 +00:00
|
|
|
var root_object = this.check_attr(root,tag,0);
|
2011-11-01 13:22:57 +00:00
|
|
|
obj.child_id = this.xml_node_create(arch, tag, [], this.xml_id-1, [root_object], []);
|
2011-10-12 10:28:01 +00:00
|
|
|
return [obj];
|
2011-09-23 13:04:06 +00:00
|
|
|
},
|
2011-10-05 11:21:27 +00:00
|
|
|
get_data: function() {
|
2011-09-30 12:49:32 +00:00
|
|
|
var self = this;
|
2011-10-17 13:21:16 +00:00
|
|
|
var view_arch_list = [];
|
2011-11-02 11:40:34 +00:00
|
|
|
self.main_view_id =((this.view_edit_dialog.$element.find("input[name='radiogroup']:checked").parent()).parent()).attr('data-id');
|
2011-10-04 10:45:50 +00:00
|
|
|
var ve_dataset = new openerp.web.DataSet(this, 'ir.ui.view');
|
2011-11-02 11:40:34 +00:00
|
|
|
ve_dataset.read_ids([parseInt(self.main_view_id)], ['arch', 'type'], function (arch) {
|
|
|
|
one_object = self.parse_xml(arch[0].arch,self.main_view_id);
|
|
|
|
self.main_view_type = arch[0].type
|
|
|
|
view_arch_list.push({"view_id" : self.main_view_id, "arch" : arch[0].arch});
|
2011-10-04 10:45:50 +00:00
|
|
|
dataset = new openerp.web.DataSetSearch(self, 'ir.ui.view', null, null);
|
2011-11-02 11:40:34 +00:00
|
|
|
dataset.read_slice([], {domain : [['inherit_id','=', parseInt(self.main_view_id)]]}, function (result) {
|
2011-10-04 10:45:50 +00:00
|
|
|
_.each(result, function(res) {
|
2011-10-17 13:21:16 +00:00
|
|
|
view_arch_list.push({"view_id":res.id,"arch":res.arch});
|
2011-10-04 10:45:50 +00:00
|
|
|
self.inherit_view(one_object, res);
|
2011-09-30 12:49:32 +00:00
|
|
|
});
|
2011-10-07 07:37:29 +00:00
|
|
|
return self.edit_view({"main_object": one_object,
|
2011-10-17 13:21:16 +00:00
|
|
|
"parent_child_id": self.parent_child_list(one_object, []),
|
|
|
|
"arch": view_arch_list});
|
2011-09-27 07:04:13 +00:00
|
|
|
});
|
2011-09-30 12:49:32 +00:00
|
|
|
});
|
|
|
|
},
|
2011-10-10 13:24:41 +00:00
|
|
|
parent_child_list : function(one_object, p_list) {
|
2011-10-07 06:16:04 +00:00
|
|
|
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')});
|
2011-10-07 07:37:29 +00:00
|
|
|
self.parent_child_list(element.child_id, p_list);
|
2011-10-07 06:16:04 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return p_list;
|
|
|
|
},
|
2011-10-12 12:40:52 +00:00
|
|
|
inherit_view : function(one_object, result) {
|
2011-09-30 12:49:32 +00:00
|
|
|
var self = this;
|
|
|
|
var root = $(result.arch).filter('*');
|
2011-10-05 11:21:27 +00:00
|
|
|
var xml_list = [];
|
2011-10-04 10:45:50 +00:00
|
|
|
if (root[0].tagName.toLowerCase() == "data") {
|
2011-10-05 11:21:27 +00:00
|
|
|
xml_list = $(root[0]).children();
|
|
|
|
} else {
|
|
|
|
xml_list.push(root[0]);
|
2011-09-30 12:49:32 +00:00
|
|
|
}
|
2011-10-05 11:21:27 +00:00
|
|
|
_.each(xml_list , function(xml){
|
|
|
|
var parent_id;
|
|
|
|
var check_list = [];
|
2011-10-12 10:28:01 +00:00
|
|
|
var xpath_object = self.parse_xml(xml,result.id);
|
2011-10-12 11:37:46 +00:00
|
|
|
if (xml.tagName.toLowerCase() == "xpath" ) {
|
2011-10-10 12:44:52 +00:00
|
|
|
var part_expr = _.without($(xml).attr('expr').split("/"),"");
|
2011-10-11 13:34:56 +00:00
|
|
|
_.each(part_expr,function(part){
|
|
|
|
check_list.push(_.without($.trim(part.replace(/[^a-zA-Z 0-9 _]+/g,'!')).split("!"),""));
|
2011-10-04 05:42:16 +00:00
|
|
|
});
|
2011-10-05 11:21:27 +00:00
|
|
|
} else {
|
2011-11-02 06:41:27 +00:00
|
|
|
var temp = [];
|
|
|
|
_.each(xpath_object[0].child_id[0].att_list, function(list){
|
|
|
|
if(!_.include(list, "position")){
|
|
|
|
temp.push(list);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
check_list = [_.flatten(temp)];
|
2011-09-30 12:49:32 +00:00
|
|
|
}
|
2011-10-12 10:28:01 +00:00
|
|
|
self.full_path_search(check_list ,one_object ,xpath_object);
|
2011-09-30 12:49:32 +00:00
|
|
|
});
|
|
|
|
},
|
2011-10-11 13:34:56 +00:00
|
|
|
full_path_search: function(check_list ,val ,xpath_object) {
|
2011-09-30 12:49:32 +00:00
|
|
|
var self = this;
|
2011-10-11 13:34:56 +00:00
|
|
|
if(xpath_object.length!=0){
|
2011-10-12 10:28:01 +00:00
|
|
|
var check = check_list[0];
|
|
|
|
var obj;
|
2011-10-12 12:25:30 +00:00
|
|
|
switch (check.length) {
|
|
|
|
case 2:
|
|
|
|
if(parseInt(check[1])){
|
|
|
|
var list_1 = _.select(val,function(element){
|
|
|
|
var main_list = _.flatten(element.att_list);
|
|
|
|
return _.include(main_list, check[0]);
|
|
|
|
});
|
|
|
|
obj = val[_.indexOf(val,list_1[parseInt(check[1])-1])];
|
|
|
|
} else {
|
|
|
|
obj = _.detect(val, function(element){
|
|
|
|
var main_list = _.flatten(element.att_list);
|
|
|
|
return _.include(main_list, check[0]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
obj = _.detect(val,function(element){
|
2011-10-12 10:28:01 +00:00
|
|
|
var main_list = _.flatten(element.att_list);
|
2011-10-12 12:25:30 +00:00
|
|
|
check = _.uniq(check);
|
|
|
|
var insert = _.intersection(main_list,check);
|
|
|
|
if(insert.length == check.length ){return element;}
|
2011-10-12 10:28:01 +00:00
|
|
|
});
|
2011-10-12 12:25:30 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
var list_1 = _.select(val,function(element){
|
2011-10-12 10:28:01 +00:00
|
|
|
var main_list = _.flatten(element.att_list);
|
|
|
|
return _.include(main_list, check[0]);
|
|
|
|
});
|
2011-10-17 13:21:16 +00:00
|
|
|
if(list_1.length != 0){
|
2011-10-12 12:25:30 +00:00
|
|
|
(check_list.length == 1)? obj = list_1[0] : check_list.shift();
|
2011-10-12 10:28:01 +00:00
|
|
|
}
|
2011-10-12 12:25:30 +00:00
|
|
|
break;
|
2011-10-10 12:44:52 +00:00
|
|
|
}
|
2011-10-12 12:40:52 +00:00
|
|
|
if(obj) {
|
2011-10-12 10:28:01 +00:00
|
|
|
check_list.shift();
|
|
|
|
if (check_list.length !=0){
|
|
|
|
self.full_path_search(check_list ,obj.child_id ,xpath_object);
|
2011-10-12 12:40:52 +00:00
|
|
|
} else {
|
2011-10-11 13:34:56 +00:00
|
|
|
var level = obj.level+1;
|
2011-10-12 10:28:01 +00:00
|
|
|
self.increase_level(xpath_object[0], level)
|
2011-10-11 13:34:56 +00:00
|
|
|
obj.child_id.push(xpath_object[0]);
|
|
|
|
xpath_object.pop();
|
2011-10-12 10:28:01 +00:00
|
|
|
return;
|
2011-10-03 09:49:31 +00:00
|
|
|
}
|
2011-10-10 12:44:52 +00:00
|
|
|
}
|
2011-10-12 10:28:01 +00:00
|
|
|
else {
|
|
|
|
_.each(val,function(element){
|
2011-10-12 13:12:53 +00:00
|
|
|
self.full_path_search(check_list ,element.child_id ,xpath_object);
|
2011-09-16 13:24:11 +00:00
|
|
|
});
|
2011-09-30 12:49:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2011-10-04 10:45:50 +00:00
|
|
|
increase_level: function(val, level) {
|
2011-09-30 12:49:32 +00:00
|
|
|
var self = this;
|
2011-10-04 05:42:16 +00:00
|
|
|
val.level = level;
|
2011-10-04 10:45:50 +00:00
|
|
|
_.each(val.child_id, function(val, key) {
|
|
|
|
self.increase_level(val, level + 1);
|
2011-09-30 12:49:32 +00:00
|
|
|
});
|
2011-09-16 13:24:11 +00:00
|
|
|
},
|
2011-10-12 12:40:52 +00:00
|
|
|
edit_view: function(one_object) {
|
2011-09-16 13:24:11 +00:00
|
|
|
var self = this;
|
2011-10-14 11:21:01 +00:00
|
|
|
this.edit_xml_dialog = new openerp.web.Dialog(this,{
|
2011-09-22 09:00:27 +00:00
|
|
|
modal: true,
|
2011-11-02 06:41:27 +00:00
|
|
|
title: 'View Editor',
|
2011-09-22 09:00:27 +00:00
|
|
|
width: 750,
|
|
|
|
height: 500,
|
|
|
|
buttons: {
|
2011-09-30 12:49:32 +00:00
|
|
|
"Inherited View": function(){
|
|
|
|
//todo
|
|
|
|
},
|
|
|
|
"Preview": function(){
|
2011-11-02 11:40:34 +00:00
|
|
|
var action = {
|
|
|
|
context:self.session.user_context,
|
|
|
|
res_model : self.model,
|
|
|
|
views : [[self.main_view_id, self.main_view_type]],
|
|
|
|
type: 'ir.actions.act_window',
|
|
|
|
target: "new",
|
|
|
|
flags: {
|
|
|
|
sidebar: false,
|
|
|
|
views_switcher: false,
|
|
|
|
action_buttons:false,
|
|
|
|
search_view:false,
|
|
|
|
pager:false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
var action_manager = new openerp.web.ActionManager(self);
|
|
|
|
action_manager.do_action(action);
|
2011-09-30 12:49:32 +00:00
|
|
|
},
|
|
|
|
"Close": function(){
|
2011-11-01 06:54:21 +00:00
|
|
|
self.edit_xml_dialog.close();
|
2011-09-20 12:43:02 +00:00
|
|
|
}
|
2011-09-30 12:49:32 +00:00
|
|
|
}
|
2011-09-22 09:00:27 +00:00
|
|
|
});
|
2011-10-14 11:21:01 +00:00
|
|
|
this.edit_xml_dialog.start().open();
|
|
|
|
this.edit_xml_dialog.$element.html(QWeb.render('view_editor', {
|
2011-10-04 10:45:50 +00:00
|
|
|
'data': one_object['main_object'],
|
|
|
|
}));
|
2011-10-14 11:21:01 +00:00
|
|
|
this.edit_xml_dialog.$element.find("tr[id^='viewedit-']").click(function() {
|
2011-11-02 05:22:29 +00:00
|
|
|
self.edit_xml_dialog.$element.find("tr[id^='viewedit-']").removeClass('ui-selected');
|
2011-10-04 10:45:50 +00:00
|
|
|
$(this).addClass('ui-selected');
|
|
|
|
});
|
2011-10-14 11:21:01 +00:00
|
|
|
this.edit_xml_dialog.$element.find("img[id^='parentimg-']").click(function() {
|
2011-10-04 10:45:50 +00:00
|
|
|
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');
|
|
|
|
var id = this.id.split('-')[1];
|
|
|
|
self.on_collapse(this,one_object['parent_child_id'], one_object['main_object']);
|
|
|
|
}
|
|
|
|
});
|
2011-10-14 11:21:01 +00:00
|
|
|
this.edit_xml_dialog.$element.find("img[id^='side-']").click(function() {
|
2011-10-04 10:45:50 +00:00
|
|
|
var side = $(this).closest("tr[id^='viewedit-']")
|
|
|
|
var id_tr = (side.attr('id')).split('-')[1];
|
|
|
|
var img = side.find("img[id='parentimg-"+id_tr+"']").attr('src'); ;
|
2011-10-20 13:17:27 +00:00
|
|
|
var level = parseInt(side.attr('level'));
|
2011-10-04 10:45:50 +00:00
|
|
|
var list_shift =[];
|
|
|
|
var last_tr;
|
|
|
|
var cur_tr = side;
|
|
|
|
list_shift.push(side);
|
|
|
|
var next_tr;
|
2011-10-20 13:17:27 +00:00
|
|
|
var ls = side;
|
|
|
|
var view_id;
|
|
|
|
var view_xml_id;
|
|
|
|
while(1){
|
|
|
|
ls = ls.prev();
|
2011-10-31 08:52:31 +00:00
|
|
|
if((self.edit_xml_dialog.$element.find(ls).find('a').text()).search("view_id") != -1
|
|
|
|
&& parseInt(ls.attr('level')) < level){
|
2011-10-20 13:17:27 +00:00
|
|
|
view_id = parseInt(($(ls).find('a').text()).replace(/[^0-9]+/g,''));
|
|
|
|
view_xml_id = (ls.attr('id')).split('-')[1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-10-04 10:45:50 +00:00
|
|
|
switch (this.id) {
|
|
|
|
case "side-add":
|
|
|
|
break;
|
|
|
|
case "side-remove":
|
|
|
|
break;
|
|
|
|
case "side-edit":
|
2011-10-17 10:37:40 +00:00
|
|
|
var tag, fld_name;
|
|
|
|
var tr = $(this).closest("tr[id^='viewedit-']").find('a').text();
|
|
|
|
var tag_fld = tr.split(" ");
|
|
|
|
if (tag_fld.length > 3){
|
|
|
|
tag = tag_fld[1].replace(/[^a-zA-Z 0-9]+/g,'');
|
|
|
|
fld_name = tag_fld[2].split("=")[1].replace(/[^a-zA-Z _ 0-9]+/g,'');
|
|
|
|
}else{
|
|
|
|
tag = tag_fld[1].replace(/[^a-zA-Z 0-9]+/g,'');
|
2011-10-24 12:59:12 +00:00
|
|
|
fld_name= tag;
|
2011-09-30 12:49:32 +00:00
|
|
|
}
|
2011-10-17 10:37:40 +00:00
|
|
|
var properties = _PROPERTIES[tag];
|
2011-11-04 05:03:38 +00:00
|
|
|
self.on_edit_node(properties,fld_name,id_tr,one_object,view_id, view_xml_id, level);
|
2011-10-04 10:45:50 +00:00
|
|
|
break;
|
|
|
|
case "side-up":
|
|
|
|
while (1) {
|
|
|
|
var prev_tr = cur_tr.prev();
|
2011-10-20 13:17:27 +00:00
|
|
|
if(level >= parseInt(prev_tr.attr('level')) || prev_tr.length == 0) {
|
2011-10-04 10:45:50 +00:00
|
|
|
last_tr = prev_tr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cur_tr = prev_tr;
|
2011-09-30 12:49:32 +00:00
|
|
|
}
|
2011-10-04 10:45:50 +00:00
|
|
|
if (img) {
|
|
|
|
while (1) {
|
|
|
|
next_tr = side.next();
|
2011-10-20 13:17:27 +00:00
|
|
|
if ( parseInt(next_tr.attr('level')) <= level || next_tr.length == 0) {
|
2011-10-04 10:45:50 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
list_shift.push(next_tr);
|
|
|
|
side = next_tr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-02 06:41:27 +00:00
|
|
|
if (last_tr.length != 0 && parseInt(last_tr.attr('level')) == level &&
|
|
|
|
(self.edit_xml_dialog.$element.find(last_tr).find('a').text()).search("view_id") == -1) {
|
2011-10-04 10:45:50 +00:00
|
|
|
_.each(list_shift, function(rec) {
|
|
|
|
$(last_tr).before(rec);
|
|
|
|
});
|
2011-10-25 11:10:12 +00:00
|
|
|
self.save_move_arch(one_object, view_id, view_xml_id, id_tr, level, "up");
|
2011-10-04 10:45:50 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "side-down":
|
|
|
|
if (img) {
|
|
|
|
while (1) {
|
|
|
|
next_tr = cur_tr.next();
|
2011-10-20 13:17:27 +00:00
|
|
|
if ( parseInt(next_tr.attr('level')) <= level || next_tr.length == 0) {
|
2011-10-04 10:45:50 +00:00
|
|
|
last_tr = next_tr;
|
2011-09-26 11:35:01 +00:00
|
|
|
break;
|
2011-10-04 10:45:50 +00:00
|
|
|
} else {
|
2011-09-30 12:49:32 +00:00
|
|
|
list_shift.push(next_tr);
|
2011-10-04 10:45:50 +00:00
|
|
|
cur_tr = next_tr;
|
2011-10-04 05:42:16 +00:00
|
|
|
}
|
2011-10-04 10:45:50 +00:00
|
|
|
}
|
2011-09-26 11:35:01 +00:00
|
|
|
}
|
2011-10-04 10:45:50 +00:00
|
|
|
else {
|
|
|
|
last_tr = cur_tr.next();
|
2011-09-30 12:49:32 +00:00
|
|
|
}
|
2011-11-02 06:17:35 +00:00
|
|
|
if((self.edit_xml_dialog.$element.find(last_tr).find('a').text()).search("view_id") != -1){
|
|
|
|
return;
|
|
|
|
}
|
2011-10-20 13:17:27 +00:00
|
|
|
if (last_tr.length != 0 && parseInt(last_tr.attr('level')) == level) {
|
2011-10-04 10:45:50 +00:00
|
|
|
var last_tr_id = (last_tr.attr('id')).split('-')[1];
|
|
|
|
img = last_tr.find("img[id='parentimg-" + last_tr_id + "']").attr('src');
|
|
|
|
if (img) {
|
2011-11-02 05:22:29 +00:00
|
|
|
self.edit_xml_dialog.$element.find("img[id='parentimg-" + last_tr_id + "']").
|
|
|
|
attr('src', '/web/static/src/img/expand.gif');
|
2011-10-04 10:45:50 +00:00
|
|
|
while (1) {
|
|
|
|
var next_tr = last_tr.next();
|
|
|
|
if (next_tr.attr('level') <= level || next_tr.length == 0) break;
|
|
|
|
next_tr.hide();
|
|
|
|
last_tr = next_tr;
|
|
|
|
}
|
2011-09-27 05:05:03 +00:00
|
|
|
}
|
2011-10-04 10:45:50 +00:00
|
|
|
list_shift.reverse();
|
|
|
|
_.each(list_shift, function(rec) {
|
|
|
|
$(last_tr).after(rec);
|
|
|
|
});
|
2011-11-02 06:17:35 +00:00
|
|
|
self.save_move_arch(one_object, view_id, view_xml_id, id_tr, level, "down");
|
2011-09-30 12:49:32 +00:00
|
|
|
}
|
2011-10-04 10:45:50 +00:00
|
|
|
break;
|
2011-09-22 09:45:13 +00:00
|
|
|
}
|
2011-10-04 10:45:50 +00:00
|
|
|
});
|
2011-09-22 09:00:27 +00:00
|
|
|
},
|
2011-11-04 05:03:38 +00:00
|
|
|
save_move_arch: function(one_object, view_id, view_xml_id, id_tr, level, move_direct, update_values){
|
2011-10-17 13:21:16 +00:00
|
|
|
var self = this;
|
2011-10-20 13:17:27 +00:00
|
|
|
var arch = _.detect(one_object['arch'],function(element){
|
|
|
|
return element.view_id == view_id;
|
|
|
|
});
|
|
|
|
var obj = self.get_view_object(view_xml_id, one_object['main_object'], []);
|
2011-10-25 11:10:12 +00:00
|
|
|
if(($(arch.arch).filter("data")).length != 0 && view_xml_id != 0){
|
|
|
|
var check_list = _.flatten(obj[0].child_id[0].att_list);
|
|
|
|
arch.arch = _.detect($(arch.arch).children(), function(xml_child){
|
|
|
|
var temp_obj = self.check_attr(xml_child, xml_child.tagName.toLowerCase());
|
|
|
|
var main_list = _.flatten(temp_obj.att_list);
|
|
|
|
check_list = _.uniq(check_list);
|
|
|
|
var insert = _.intersection(main_list,check_list);
|
|
|
|
if(insert.length == check_list.length ){return xml_child;}
|
|
|
|
});
|
|
|
|
}
|
2011-10-20 13:17:27 +00:00
|
|
|
return self.get_node(arch.arch, obj[0].child_id[0], parseInt(id_tr), [], parseInt(level),
|
2011-11-04 05:03:38 +00:00
|
|
|
parseInt(view_id), arch, move_direct, update_values);
|
2011-10-20 13:17:27 +00:00
|
|
|
},
|
2011-10-24 12:59:12 +00:00
|
|
|
get_view_object: function(view_xml_id, one_object,result){
|
2011-10-20 13:17:27 +00:00
|
|
|
var self = this;
|
|
|
|
if(result.length==0){
|
|
|
|
var check = _.detect(one_object , function(obj){
|
|
|
|
return view_xml_id==obj.id;
|
|
|
|
});
|
|
|
|
if(check){result.push(check);};
|
|
|
|
_.each(one_object, function(obj){
|
|
|
|
self.get_view_object(view_xml_id, obj.child_id, result);
|
2011-10-19 09:50:44 +00:00
|
|
|
});
|
2011-10-20 13:17:27 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
2011-11-04 05:03:38 +00:00
|
|
|
get_node: function(arch1, obj, id, child_list, level, view_id, arch, move_direct, update_values){
|
2011-10-20 13:17:27 +00:00
|
|
|
var self = this;
|
|
|
|
var children_list = $(arch1).children();
|
2011-10-25 11:10:12 +00:00
|
|
|
var list_obj_xml = _.zip(children_list,obj.child_id);
|
2011-11-02 06:41:27 +00:00
|
|
|
if (id) {
|
|
|
|
if (obj.id == id) {
|
2011-10-20 13:17:27 +00:00
|
|
|
var parent = $(arch1).parents();
|
2011-11-02 06:41:27 +00:00
|
|
|
var index = _.indexOf(child_list, obj)
|
|
|
|
var re_insert_obj = child_list.splice(index, 1);
|
|
|
|
if (move_direct == "down") {
|
2011-10-25 11:10:12 +00:00
|
|
|
var next = $(arch1).next();
|
|
|
|
$(next).after(arch1);
|
|
|
|
child_list.splice(index+1, 0, re_insert_obj[0]);
|
2011-11-04 05:03:38 +00:00
|
|
|
}else if(move_direct == "up"){
|
2011-10-25 11:10:12 +00:00
|
|
|
var prev = $(arch1).prev();
|
|
|
|
$(prev).before(arch1);
|
|
|
|
child_list.splice(index-1, 0, re_insert_obj[0]);
|
2011-11-04 05:03:38 +00:00
|
|
|
}else if(move_direct == "update_node"){
|
|
|
|
_.each(update_values, function(val){
|
|
|
|
$(arch1).attr(val[0],val[1]);
|
|
|
|
});
|
|
|
|
var new_obj = self.check_attr(arch1,arch1.tagName.toLowerCase(),obj.level);
|
|
|
|
new_obj.id = obj.id;
|
|
|
|
self.edit_xml_dialog.$element.find("tr[id='viewedit-"+id+"']").find('a').text(new_obj.name);
|
|
|
|
child_list.splice(_.indexOf(child_list, obj), 0, new_obj);
|
2011-10-25 11:10:12 +00:00
|
|
|
}
|
2011-11-04 05:03:38 +00:00
|
|
|
|
2011-10-20 13:17:27 +00:00
|
|
|
parent = parent[parent.length-1];
|
2011-10-31 08:52:31 +00:00
|
|
|
var convert_to_utf = self.xml2Str(parent);
|
2011-11-02 06:41:27 +00:00
|
|
|
if (convert_to_utf) {
|
2011-10-31 08:52:31 +00:00
|
|
|
convert_to_utf = convert_to_utf.replace('xmlns="http://www.w3.org/1999/xhtml"', "");
|
2011-11-02 06:41:27 +00:00
|
|
|
convert_to_utf = '<?xml version="1.0"?>' + convert_to_utf;
|
2011-10-31 08:52:31 +00:00
|
|
|
arch.arch = convert_to_utf;
|
|
|
|
dataset = new openerp.web.DataSet(this, 'ir.ui.view');
|
2011-11-02 06:41:27 +00:00
|
|
|
dataset.write(parseInt(view_id),{"arch":convert_to_utf}, function(r) {
|
2011-10-31 08:52:31 +00:00
|
|
|
});
|
|
|
|
}
|
2011-10-25 11:10:12 +00:00
|
|
|
}
|
2011-11-02 06:41:27 +00:00
|
|
|
if (obj.level <= level) {
|
|
|
|
_.each(list_obj_xml, function(child_node) {
|
2011-11-04 05:03:38 +00:00
|
|
|
self.get_node(child_node[0], child_node[1], id, obj.child_id, level, view_id, arch, move_direct, update_values);
|
2011-10-20 13:17:27 +00:00
|
|
|
});
|
2011-10-17 13:21:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2011-10-31 08:52:31 +00:00
|
|
|
xml2Str: function(xmlNode) {
|
|
|
|
try {
|
|
|
|
return (new XMLSerializer()).serializeToString(xmlNode);
|
2011-10-24 12:59:12 +00:00
|
|
|
}
|
2011-10-31 08:52:31 +00:00
|
|
|
catch (e) {
|
|
|
|
try {
|
|
|
|
return xmlNode.xml;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-10-24 12:59:12 +00:00
|
|
|
},
|
2011-10-14 11:21:01 +00:00
|
|
|
on_expand: function(expand_img){
|
|
|
|
var level = parseInt($(expand_img).closest("tr[id^='viewedit-']").attr('level'));
|
|
|
|
var cur_tr = $(expand_img).closest("tr[id^='viewedit-']");
|
2011-10-04 10:45:50 +00:00
|
|
|
while (1) {
|
2011-09-22 09:00:27 +00:00
|
|
|
var nxt_tr = cur_tr.next();
|
2011-10-07 07:37:29 +00:00
|
|
|
if (parseInt(nxt_tr.attr('level')) > level){
|
2011-09-22 09:00:27 +00:00
|
|
|
cur_tr = nxt_tr;
|
|
|
|
nxt_tr.hide();
|
2011-10-04 10:45:50 +00:00
|
|
|
} else return nxt_tr;
|
2011-09-22 09:00:27 +00:00
|
|
|
}
|
|
|
|
},
|
2011-10-14 11:21:01 +00:00
|
|
|
on_collapse: function(collapse_img, parent_child_id, id, main_object) {
|
|
|
|
var self = this;
|
|
|
|
var id = collapse_img.id.split('-')[1];
|
2011-10-04 10:45:50 +00:00
|
|
|
var datas = _.detect(parent_child_id,function(res) {
|
2011-09-22 09:00:27 +00:00
|
|
|
return res.key == id;
|
|
|
|
});
|
2011-10-04 10:45:50 +00:00
|
|
|
_.each(datas.value, function(rec) {
|
2011-10-14 11:21:01 +00:00
|
|
|
var tr = self.edit_xml_dialog.$element.find("tr[id='viewedit-"+rec+"']");
|
2011-09-22 09:00:27 +00:00
|
|
|
tr.find("img[id='parentimg-"+rec+"']").attr('src','/web/static/src/img/expand.gif');
|
|
|
|
tr.show();
|
|
|
|
});
|
2011-10-04 05:42:16 +00:00
|
|
|
},
|
2011-11-04 05:03:38 +00:00
|
|
|
on_edit_node:function(properties,fld_name,id_tr,obj,view_id, view_xml_id, level){
|
2011-10-04 05:42:16 +00:00
|
|
|
var self = this;
|
2011-10-24 12:59:12 +00:00
|
|
|
this.edit_node_dialog = new openerp.web.Dialog(this,{
|
2011-10-04 05:42:16 +00:00
|
|
|
modal: true,
|
|
|
|
title: 'Properties',
|
|
|
|
width: 650,
|
2011-10-24 12:59:12 +00:00
|
|
|
height: 200,
|
2011-10-04 05:42:16 +00:00
|
|
|
buttons: {
|
|
|
|
"Update": function(){
|
2011-11-04 05:03:38 +00:00
|
|
|
//self.on_update_node();
|
|
|
|
var update_values = [];
|
|
|
|
_.each(self.edit_widget,function(widget){
|
|
|
|
update_values.push(widget.get_value());
|
|
|
|
});
|
|
|
|
update_values = _.without(update_values,undefined);
|
|
|
|
self.save_move_arch(obj, view_id, view_xml_id, id_tr, level, "update_node", update_values);
|
2011-10-04 05:42:16 +00:00
|
|
|
},
|
|
|
|
"Cancel": function(){
|
|
|
|
$(this).dialog('destroy');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-10-24 12:59:12 +00:00
|
|
|
this.edit_node_dialog.start().open();
|
|
|
|
var widget = ['readonly','required','nolabel','completion','widget','groups','position','icon','align','special','type','target'];
|
|
|
|
var arch_val = self.get_view_object(id_tr,one_object,[]);
|
2011-11-04 05:03:38 +00:00
|
|
|
self.edit_node_dialog.$element.append('<table id="rec_table" class="oe_forms"></table>');
|
|
|
|
self.edit_widget = [];
|
2011-11-02 12:08:37 +00:00
|
|
|
_.each(properties,function(record){
|
|
|
|
var id = record;
|
|
|
|
self.ready = $.when(self.on_groups(id)).then(function () {
|
|
|
|
if (_.include(widget,id)){
|
2011-11-04 05:03:38 +00:00
|
|
|
var type_widget = new (self.property.get_any(['undefined' , id, arch_val[0]['att_list'][0]])) (self.edit_node_dialog, arch_val, id);
|
|
|
|
self.edit_widget.push(type_widget);
|
2011-11-02 12:08:37 +00:00
|
|
|
self.edit_node_dialog.$element.find('table[id=rec_table]').append('<tr id="'+id+'"><td align="right">'+id+':</td><td>'+type_widget.render()+'</td></tr>');
|
2011-11-04 05:03:38 +00:00
|
|
|
(id=='groups')?type_widget.set_value(self.groups):type_widget.set_value();
|
2011-10-24 12:59:12 +00:00
|
|
|
}else{
|
2011-11-04 05:03:38 +00:00
|
|
|
var type_widget = new openerp.web.ViewEditor.FieldChar (self.edit_node_dialog,arch_val, id);
|
|
|
|
self.edit_widget.push(type_widget);
|
2011-11-02 12:08:37 +00:00
|
|
|
self.edit_node_dialog.$element.find('table[id=rec_table]').append('<tr id="'+id+'"><td align="right">'+id+':</td><td>'+type_widget.render()+'</td></tr>');
|
2011-11-04 05:03:38 +00:00
|
|
|
type_widget.set_value();
|
2011-10-24 12:59:12 +00:00
|
|
|
}
|
2011-10-04 05:42:16 +00:00
|
|
|
});
|
|
|
|
});
|
2011-10-25 13:13:12 +00:00
|
|
|
},
|
|
|
|
//for getting groups
|
2011-11-02 12:08:37 +00:00
|
|
|
on_groups: function(id){
|
|
|
|
var self = this,
|
|
|
|
def = $.Deferred();
|
|
|
|
if (id !='groups') {
|
|
|
|
self.groups = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var group_ids = [],
|
|
|
|
group_names = {},
|
|
|
|
groups = [];
|
|
|
|
var res_groups = new openerp.web.DataSetSearch(this,'res.groups', null, null),
|
|
|
|
model_data = new openerp.web.DataSetSearch(self,'ir.model.data', null, null);
|
2011-11-04 05:03:38 +00:00
|
|
|
res_groups
|
2011-11-02 12:08:37 +00:00
|
|
|
.read_slice([],{})
|
|
|
|
.done(function(res_grp) {
|
|
|
|
_.each(res_grp,function(res){
|
2011-11-02 12:27:47 +00:00
|
|
|
var key = res.id;
|
|
|
|
group_names[key]=res.name;
|
|
|
|
group_ids.push(res.id);
|
2011-11-02 12:08:37 +00:00
|
|
|
});
|
|
|
|
model_data
|
|
|
|
.read_slice([],{domain:[['res_id', 'in', group_ids],['model','=','res.groups']]})
|
|
|
|
.done(function(model_grp) {
|
|
|
|
_.each(model_grp,function(res_group){
|
2011-11-02 12:27:47 +00:00
|
|
|
groups.push([res_group.name,group_names[res_group.res_id]]);
|
|
|
|
});
|
2011-11-02 12:08:37 +00:00
|
|
|
self.groups = groups;
|
|
|
|
def.resolve();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
return def.promise();
|
2011-11-01 13:22:57 +00:00
|
|
|
},
|
2011-11-04 05:03:38 +00:00
|
|
|
/*on_update_node: function(){
|
|
|
|
var self = this;
|
|
|
|
var values = [];
|
|
|
|
_.each(self.edit_widget,function(widget){
|
|
|
|
values.push(widget.get_value());
|
|
|
|
});
|
|
|
|
values = _.without(values,undefined);
|
|
|
|
}*/
|
2011-08-23 10:39:41 +00:00
|
|
|
});
|
2011-10-24 12:59:12 +00:00
|
|
|
openerp.web.ViewEditor.Field = openerp.web.Class.extend({
|
2011-11-04 05:03:38 +00:00
|
|
|
init: function(view, node, id) {
|
2011-10-25 13:13:12 +00:00
|
|
|
var self = this;
|
2011-10-13 11:00:39 +00:00
|
|
|
this.$element = view.$element;
|
2011-10-24 12:59:12 +00:00
|
|
|
this.node = node;
|
2011-11-04 05:03:38 +00:00
|
|
|
this.dirty = false;
|
|
|
|
this.name = id;
|
2011-10-24 12:59:12 +00:00
|
|
|
},
|
|
|
|
render: function () {
|
|
|
|
return QWeb.render(this.template, {widget: this});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
openerp.web.ViewEditor.FieldBoolean = openerp.web.ViewEditor.Field.extend({
|
2011-11-04 05:03:38 +00:00
|
|
|
init: function(view, node, id) {
|
|
|
|
this._super(view, node, id);
|
2011-10-24 12:59:12 +00:00
|
|
|
this.template = "view_boolean";
|
2011-10-04 06:09:03 +00:00
|
|
|
},
|
2011-11-04 05:03:38 +00:00
|
|
|
set_value: function() {
|
|
|
|
var self = this;
|
2011-10-24 12:59:12 +00:00
|
|
|
var view_val = _.detect(this.node[0]['att_list'],function(res) {
|
2011-11-04 05:03:38 +00:00
|
|
|
return _.include(res,self.name);
|
2011-10-24 12:59:12 +00:00
|
|
|
});
|
2011-11-04 05:03:38 +00:00
|
|
|
view_val ? this.$element.find("tr[id="+ self.name+"] input").attr('checked', view_val[1]): this.$element.find("tr[id="+self.name+"] input").attr('checked', false);
|
|
|
|
},
|
|
|
|
get_value: function(){
|
|
|
|
var val = this.$element.find("tr[id="+this.name+"] input").attr('checked');
|
|
|
|
if (val){
|
|
|
|
return [this.name,val];
|
|
|
|
}
|
2011-10-13 11:00:39 +00:00
|
|
|
}
|
|
|
|
});
|
2011-10-24 12:59:12 +00:00
|
|
|
openerp.web.ViewEditor.FieldChar = openerp.web.ViewEditor.Field.extend({
|
2011-11-04 05:03:38 +00:00
|
|
|
init: function(view, node, id) {
|
|
|
|
this._super(view, node, id);
|
2011-10-24 12:59:12 +00:00
|
|
|
this.template = "view_char";
|
2011-10-13 11:00:39 +00:00
|
|
|
},
|
2011-11-04 05:03:38 +00:00
|
|
|
set_value: function() {
|
|
|
|
var self = this;
|
2011-10-24 12:59:12 +00:00
|
|
|
var view_val = _.detect(this.node[0]['att_list'],function(res) {
|
2011-11-04 05:03:38 +00:00
|
|
|
return _.include(res, self.name);
|
2011-10-24 12:59:12 +00:00
|
|
|
});
|
2011-11-04 05:03:38 +00:00
|
|
|
view_val ? this.$element.find("tr[id="+self.name +"] input").val(view_val[1]): this.$element.find("tr[id="+self.name+"] input").val();
|
|
|
|
},
|
|
|
|
get_value: function(){
|
|
|
|
var val= this.$element.find("tr[id="+this.name+"] input").val();
|
|
|
|
if (val){
|
|
|
|
return [this.name,val];
|
|
|
|
}
|
2011-10-24 12:59:12 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
openerp.web.ViewEditor.FieldSelect = openerp.web.ViewEditor.Field.extend({
|
2011-11-04 05:03:38 +00:00
|
|
|
init: function(view, node, id) {
|
|
|
|
this._super(view, node, id);
|
2011-10-24 12:59:12 +00:00
|
|
|
this.template = "view_selection";
|
|
|
|
},
|
2011-11-04 05:03:38 +00:00
|
|
|
set_value: function(value) {
|
|
|
|
var self = this;
|
2011-11-01 13:22:57 +00:00
|
|
|
var view_val = _.detect(this.node[0]['att_list'],function(res) {
|
2011-11-04 05:03:38 +00:00
|
|
|
return _.include(res,self.name);
|
2011-11-01 13:22:57 +00:00
|
|
|
});
|
|
|
|
_.each(value, function(item) {
|
|
|
|
var select_val = view_val?(view_val[1]==item[0]?true:false):false;
|
2011-11-04 05:03:38 +00:00
|
|
|
self.$element.find("tr[id="+self.name+"] select").append($("<option/>", {
|
2011-11-01 13:22:57 +00:00
|
|
|
value:(typeof(item)=='string')?item:item[0],
|
|
|
|
text:(typeof(item)=='string')?item:item[1],
|
|
|
|
selected:select_val
|
|
|
|
}));
|
|
|
|
});
|
2011-11-04 05:03:38 +00:00
|
|
|
},
|
|
|
|
get_value: function(){
|
|
|
|
var val = this.$element.find("tr[id="+this.name+"] select").find("option:selected").val();
|
|
|
|
if (val){
|
|
|
|
return [this.name,val];
|
|
|
|
}
|
2011-10-04 06:09:03 +00:00
|
|
|
}
|
|
|
|
});
|
2011-11-01 13:22:57 +00:00
|
|
|
openerp.web.ViewEditor.WidgetProperty = openerp.web.ViewEditor.FieldSelect.extend({
|
2011-11-04 05:03:38 +00:00
|
|
|
init: function(view, node, id) {
|
|
|
|
this._super(view, node, id);
|
2011-10-25 13:13:12 +00:00
|
|
|
this.registry = openerp.web.form.widgets;
|
|
|
|
},
|
2011-11-04 05:03:38 +00:00
|
|
|
set_value: function() {
|
|
|
|
var self= this;
|
2011-11-02 12:08:37 +00:00
|
|
|
var value = _.keys(this.registry.map);
|
2011-11-01 13:22:57 +00:00
|
|
|
value.push('');
|
|
|
|
value.sort();
|
2011-11-04 05:03:38 +00:00
|
|
|
this._super.apply(this,[value]);
|
2011-10-25 13:13:12 +00:00
|
|
|
}
|
|
|
|
});
|
2011-11-01 13:22:57 +00:00
|
|
|
openerp.web.ViewEditor.IconProperty = openerp.web.ViewEditor.FieldSelect.extend({
|
2011-11-04 05:03:38 +00:00
|
|
|
init: function(view, node, id) {
|
|
|
|
this._super(view, node, id);
|
2011-10-25 13:13:12 +00:00
|
|
|
},
|
2011-11-04 05:03:38 +00:00
|
|
|
set_value: function() {
|
|
|
|
var self = this;
|
2011-11-02 12:08:37 +00:00
|
|
|
var value = icons;
|
2011-11-04 05:03:38 +00:00
|
|
|
this._super.apply(this,[value]);
|
2011-10-25 13:13:12 +00:00
|
|
|
}
|
2011-11-01 13:22:57 +00:00
|
|
|
});
|
|
|
|
openerp.web.ViewEditor.ButtonTargetProperty = openerp.web.ViewEditor.FieldSelect.extend({
|
2011-11-04 05:03:38 +00:00
|
|
|
init: function(view, node, id) {
|
|
|
|
this._super(view, node, id);
|
2011-10-25 13:13:12 +00:00
|
|
|
},
|
2011-11-04 05:03:38 +00:00
|
|
|
set_value: function() {
|
|
|
|
var self = this;
|
2011-11-02 12:08:37 +00:00
|
|
|
var value = [['',''],['new','New Window']];
|
2011-11-04 05:03:38 +00:00
|
|
|
this._super.apply(this,[value]);
|
2011-10-25 13:13:12 +00:00
|
|
|
}
|
|
|
|
});
|
2011-11-01 13:22:57 +00:00
|
|
|
openerp.web.ViewEditor.ButtonTypeProperty = openerp.web.ViewEditor.FieldSelect.extend({
|
2011-11-04 05:03:38 +00:00
|
|
|
init: function(view, node, id) {
|
|
|
|
this._super(view, node, id);
|
2011-10-25 13:13:12 +00:00
|
|
|
},
|
2011-11-04 05:03:38 +00:00
|
|
|
set_value: function() {
|
|
|
|
var self = this;
|
2011-11-02 12:08:37 +00:00
|
|
|
var value = [['',''],['action', 'Action'], ['object', 'Object'], ['workflow', 'Workflow'], ['server_action', 'Server Action']];
|
2011-11-04 05:03:38 +00:00
|
|
|
this._super.apply(this,[value]);
|
2011-10-25 13:13:12 +00:00
|
|
|
}
|
|
|
|
});
|
2011-11-01 13:22:57 +00:00
|
|
|
openerp.web.ViewEditor.AlignProperty = openerp.web.ViewEditor.FieldSelect.extend({
|
2011-11-04 05:03:38 +00:00
|
|
|
init: function(view, node, id) {
|
|
|
|
this._super(view, node, id);
|
2011-10-25 13:13:12 +00:00
|
|
|
},
|
2011-11-04 05:03:38 +00:00
|
|
|
set_value: function() {
|
|
|
|
var self = this;
|
2011-11-02 12:08:37 +00:00
|
|
|
var value = [['',''],['0.0','Left'], ['0.5','Center'], ['1.0','Right']];
|
2011-11-04 05:03:38 +00:00
|
|
|
this._super.apply(this,[value]);
|
2011-10-25 13:13:12 +00:00
|
|
|
}
|
|
|
|
});
|
2011-11-01 13:22:57 +00:00
|
|
|
openerp.web.ViewEditor.ButtonSpecialProperty = openerp.web.ViewEditor.FieldSelect.extend({
|
2011-11-04 05:03:38 +00:00
|
|
|
init: function(view, node, id) {
|
|
|
|
this._super(view, node, id);
|
2011-10-25 13:13:12 +00:00
|
|
|
},
|
2011-11-04 05:03:38 +00:00
|
|
|
set_value: function() {
|
|
|
|
var self = this;
|
2011-11-02 12:08:37 +00:00
|
|
|
var value = [['',''],['save','Save Button'], ['cancel','Cancel Button'], ['open','Open Button']];
|
2011-11-04 05:03:38 +00:00
|
|
|
this._super.apply(this,[value]);
|
2011-10-25 13:13:12 +00:00
|
|
|
}
|
|
|
|
});
|
2011-11-01 13:22:57 +00:00
|
|
|
openerp.web.ViewEditor.PositionProperty = openerp.web.ViewEditor.FieldSelect.extend({
|
2011-11-04 05:03:38 +00:00
|
|
|
init: function(view, node, id) {
|
|
|
|
this._super(view, node, id);
|
2011-10-25 13:13:12 +00:00
|
|
|
},
|
2011-11-04 05:03:38 +00:00
|
|
|
set_value: function() {
|
|
|
|
var self = this;
|
2011-11-02 12:08:37 +00:00
|
|
|
var value = [['',''],['after', 'After'],['before', 'Before'],['inside', 'Inside'],['replace', 'Replace']];
|
2011-11-04 05:03:38 +00:00
|
|
|
this._super.apply(this,[value]);
|
2011-10-25 13:13:12 +00:00
|
|
|
}
|
|
|
|
});
|
2011-11-01 13:22:57 +00:00
|
|
|
openerp.web.ViewEditor.GroupsProperty = openerp.web.ViewEditor.FieldSelect.extend({
|
2011-11-04 05:03:38 +00:00
|
|
|
init: function(view, node, id) {
|
|
|
|
this._super(view, node, id);
|
2011-10-25 13:13:12 +00:00
|
|
|
},
|
2011-11-04 05:03:38 +00:00
|
|
|
set_value: function(value) {
|
|
|
|
var self = this;
|
|
|
|
this.$element.find("tr[id="+ this.name +"] select").attr('multiple', true);
|
|
|
|
this.$element.find("tr[id="+ this.name +"] select").css('height','100px');
|
|
|
|
this._super.apply(this,[value]);
|
2011-10-25 13:13:12 +00:00
|
|
|
}
|
|
|
|
});
|
2011-10-04 06:09:03 +00:00
|
|
|
openerp.web.ViewEditor.property_widget = new openerp.web.Registry({
|
|
|
|
'required' : 'openerp.web.ViewEditor.FieldBoolean',
|
|
|
|
'readonly' : 'openerp.web.ViewEditor.FieldBoolean',
|
|
|
|
'nolabel' : 'openerp.web.ViewEditor.FieldBoolean',
|
|
|
|
'completion' : 'openerp.web.ViewEditor.FieldBoolean',
|
2011-10-25 13:13:12 +00:00
|
|
|
'widget' : 'openerp.web.ViewEditor.WidgetProperty',
|
|
|
|
'groups' : 'openerp.web.ViewEditor.GroupsProperty',
|
|
|
|
'position': 'openerp.web.ViewEditor.PositionProperty',
|
2011-11-01 13:22:57 +00:00
|
|
|
'icon': 'openerp.web.ViewEditor.IconProperty',
|
2011-10-25 13:13:12 +00:00
|
|
|
'align': 'openerp.web.ViewEditor.AlignProperty',
|
|
|
|
'special': 'openerp.web.ViewEditor.ButtonSpecialProperty',
|
|
|
|
'type': 'openerp.web.ViewEditor.ButtonTypeProperty',
|
|
|
|
'target': 'openerp.web.ViewEditor.ButtonTargetProperty'
|
2011-10-04 06:09:03 +00:00
|
|
|
});
|
2011-10-04 05:42:16 +00:00
|
|
|
};
|