[imp] m2o, added context menu, made most actions work correctly
bzr revid: nicolas.vanhoren@openerp.com-20110609170851-bcr7ofczlgq0o5f8
This commit is contained in:
parent
7d05822051
commit
f9776c399a
|
@ -0,0 +1,126 @@
|
|||
(function($) {
|
||||
var menu,shadow,trigger,content,hash,currentTarget;
|
||||
var defaults= {
|
||||
menuStyle: {
|
||||
listStyle:'none',
|
||||
padding:'1px',
|
||||
margin:'0px',
|
||||
backgroundColor:'#fff',
|
||||
border:'1px solid #999',
|
||||
width:'100px'
|
||||
},
|
||||
itemStyle: {
|
||||
margin:'0px',
|
||||
color:'#000',
|
||||
display:'block',
|
||||
cursor:'default',
|
||||
padding:'3px',
|
||||
border:'1px solid #fff',
|
||||
backgroundColor:'transparent'
|
||||
},
|
||||
itemHoverStyle: {
|
||||
border:'1px solid #0a246a',
|
||||
backgroundColor:'#b6bdd2'
|
||||
},
|
||||
eventPosX:'pageX',
|
||||
eventPosY:'pageY',
|
||||
shadow:true,
|
||||
onContextMenu:null,
|
||||
onShowMenu:null
|
||||
};
|
||||
$.fn.contextMenu= function(id,options) {
|
||||
if(!menu) {
|
||||
menu=$('<div id="jqContextMenu"></div>').hide().css({
|
||||
position:'absolute',
|
||||
zIndex:'500'
|
||||
}).appendTo('body').bind('click', function(e) {
|
||||
e.stopPropagation()
|
||||
})
|
||||
}
|
||||
if(!shadow) {
|
||||
shadow=$('<div></div>').css({
|
||||
backgroundColor:'#000',
|
||||
position:'absolute',
|
||||
opacity:0.2,
|
||||
zIndex:499
|
||||
}).appendTo('body').hide()
|
||||
}
|
||||
hash=hash||[];
|
||||
hash.push({
|
||||
id:id,
|
||||
menuStyle:$.extend({},defaults.menuStyle,options.menuStyle|| {}),
|
||||
itemStyle:$.extend({},defaults.itemStyle,options.itemStyle|| {}),
|
||||
itemHoverStyle:$.extend({},defaults.itemHoverStyle,options.itemHoverStyle|| {}),
|
||||
bindings:options.bindings|| {},
|
||||
shadow:options.shadow||options.shadow===false?options.shadow:defaults.shadow,
|
||||
onContextMenu:options.onContextMenu||defaults.onContextMenu,
|
||||
onShowMenu:options.onShowMenu||defaults.onShowMenu,
|
||||
eventPosX:options.eventPosX||defaults.eventPosX,
|
||||
eventPosY:options.eventPosY||defaults.eventPosY
|
||||
});
|
||||
var index=hash.length-1;
|
||||
var callback = function(e) {
|
||||
var bShowContext=(!!hash[index].onContextMenu)?hash[index].onContextMenu(e):true;
|
||||
if(bShowContext)
|
||||
display(index,this,e,options);
|
||||
return false;
|
||||
};
|
||||
$(this).bind('contextmenu', callback);
|
||||
if(options.leftClickToo) {
|
||||
$(this).click(callback);
|
||||
}
|
||||
return this
|
||||
};
|
||||
function display(index,trigger,e,options) {
|
||||
var cur=hash[index];
|
||||
content=$('#'+cur.id).find('ul:first').clone(true);
|
||||
content.css(cur.menuStyle).find('li').css(cur.itemStyle).hover( function() {
|
||||
$(this).css(cur.itemHoverStyle)
|
||||
}, function() {
|
||||
$(this).css(cur.itemStyle)
|
||||
}).find('img').css({
|
||||
verticalAlign:'middle',
|
||||
paddingRight:'2px'
|
||||
});
|
||||
menu.html(content);
|
||||
if(!!cur.onShowMenu)
|
||||
menu=cur.onShowMenu(e,menu);
|
||||
$.each(cur.bindings, function(id,func) {
|
||||
$('#'+id,menu).bind('click', function(e) {
|
||||
hide();
|
||||
func(trigger,currentTarget)
|
||||
})
|
||||
});
|
||||
menu.css({
|
||||
'left':e[cur.eventPosX],
|
||||
'top':e[cur.eventPosY]
|
||||
}).show();
|
||||
if(cur.shadow)
|
||||
shadow.css({
|
||||
width:menu.width(),
|
||||
height:menu.height(),
|
||||
left:e.pageX+2,
|
||||
top:e.pageY+2
|
||||
}).show();
|
||||
$(document).one('click',hide)
|
||||
}
|
||||
|
||||
function hide() {
|
||||
menu.hide();
|
||||
shadow.hide()
|
||||
}
|
||||
|
||||
$.contextMenu= {
|
||||
defaults: function(userDefaults) {
|
||||
$.each(userDefaults, function(i,val) {
|
||||
if(typeof val=='object'&&defaults[i]) {
|
||||
$.extend(defaults[i],val)
|
||||
} else
|
||||
defaults[i]=val
|
||||
})
|
||||
}
|
||||
}
|
||||
})(jQuery);
|
||||
$( function() {
|
||||
$('div.contextMenu').hide()
|
||||
});
|
|
@ -19,6 +19,7 @@
|
|||
<script type="text/javascript" src="/base/static/lib/jquery.superfish/js/hoverIntent.js"></script>
|
||||
<script type="text/javascript" src="/base/static/lib/jquery.superfish/js/superfish.js"></script>
|
||||
<script type="text/javascript" src="/base/static/lib/jquery.ba-bbq/jquery.ba-bbq.js"></script>
|
||||
<script type="text/javascript" src="/base/static/lib/jquery.contextmenu/jquery.contextmenu.r2.packed.js"></script>
|
||||
<script type="text/javascript" src="/base/static/lib/datejs/date-en-US.js"></script>
|
||||
<script type="text/javascript" src="/base/static/lib/json/json2.js"></script>
|
||||
<script type="text/javascript" src="/base/static/src/js/base.js"></script>
|
||||
|
|
|
@ -985,13 +985,38 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
|||
this.template = "FieldMany2One";
|
||||
this.limit = 7;
|
||||
this.value = null;
|
||||
this.cm_id = _.uniqueId('m2o_cm_');
|
||||
},
|
||||
start: function() {
|
||||
this._super();
|
||||
var self = this;
|
||||
this.$input = this.$element.find("input");
|
||||
this.$drop_down = this.$element.find("span");
|
||||
this.$menu_btn = this.$element.find("button");
|
||||
this.$menu_btn = this.$element.find("img");
|
||||
|
||||
var bindings = {};
|
||||
bindings[this.cm_id + "_search"] = function() {
|
||||
self._search_create_popup("search");
|
||||
};
|
||||
bindings[this.cm_id + "_create"] = function() {
|
||||
self._search_create_popup("form");
|
||||
};
|
||||
bindings[this.cm_id + "_open"] = function() {
|
||||
if (!self.value) {
|
||||
return;
|
||||
}
|
||||
self.session.action_manager.do_action({
|
||||
"res_model": self.field.relation,
|
||||
"views":[[false,"form"]],
|
||||
"res_id": self.value[0],
|
||||
"type":"ir.actions.act_window",
|
||||
"view_type":"form",
|
||||
"view_mode":"form",
|
||||
"target":"new"
|
||||
});
|
||||
};
|
||||
var cmenu = this.$menu_btn.contextMenu(this.cm_id, {'leftClickToo': true,
|
||||
bindings: bindings});
|
||||
|
||||
this.$input.change(function() {
|
||||
if (self.$input.val() === "") {
|
||||
|
@ -1040,24 +1065,32 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
|||
values = values.slice(0, self.limit);
|
||||
values.push({label: " More...", action: function() {
|
||||
dataset.name_search(search_val, false, function(data) {
|
||||
var pop = new openerp.base.form.Many2XSelectPopup(null, self.view.session);
|
||||
pop.select_element(self.field.relation, _.map(data.result, function(x) {return x[0]}));
|
||||
pop.on_select_element.add(function(element_id) {
|
||||
dataset.call("name_get", [element_id], function(data) {
|
||||
self.value = data.result[0];
|
||||
self.$input.val(self.value[1]);
|
||||
pop.stop();
|
||||
});
|
||||
});
|
||||
self._search_create_popup("search", data.result);
|
||||
});
|
||||
}});
|
||||
}
|
||||
values.push({label: ' Create "' + search_val + '"', action: function() {
|
||||
self._search_create_popup("form");
|
||||
}});
|
||||
values.push({label: " Create...", action: function() {
|
||||
|
||||
self._search_create_popup("form");
|
||||
}});
|
||||
response(values);
|
||||
});
|
||||
},
|
||||
_search_create_popup: function(view, ids) {
|
||||
var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, []);
|
||||
var self = this;
|
||||
var pop = new openerp.base.form.Many2XSelectPopup(null, self.view.session);
|
||||
pop.select_element(self.field.relation, ids ? _.map(ids, function(x) {return x[0]}) : undefined, view);
|
||||
pop.on_select_element.add(function(element_id) {
|
||||
dataset.call("name_get", [element_id], function(data) {
|
||||
self.value = data.result[0];
|
||||
self.$input.val(self.value[1]);
|
||||
pop.stop();
|
||||
});
|
||||
});
|
||||
},
|
||||
set_value: function(value) {
|
||||
if (value != false) {
|
||||
this.value = value;
|
||||
|
|
|
@ -531,6 +531,11 @@
|
|||
tabindex="-1" title="Show All Items"></span>
|
||||
<img t-att-id="widget.name + '_open'" alt="Open" title="Create"
|
||||
src="/base/static/src/img/iconset-d-drop.gif" class="m2o_open"/>
|
||||
<div t-att-id="widget.cm_id" class="contextMenu" style="display:none"><ul>
|
||||
<li t-att-id="widget.cm_id + '_search'">Search</li>
|
||||
<li t-att-id="widget.cm_id + '_create'">Create</li>
|
||||
<li t-att-id="widget.cm_id + '_open'">Open</li>
|
||||
</ul></div>
|
||||
</div>
|
||||
</t>
|
||||
<t t-name="FieldOne2Many">
|
||||
|
|
Loading…
Reference in New Issue