[imp] wip
bzr revid: nicolas.vanhoren@openerp.com-20110610132237-knmjwzdxjr363rot
This commit is contained in:
parent
4ced134cc3
commit
5126d74a73
|
@ -1018,5 +1018,6 @@ background: linear-gradient(top, #ffffff 0%,#ebe9e9 100%); /* W3C */
|
||||||
.openerp .oe-m2m-cm-button img {
|
.openerp .oe-m2m-cm-button img {
|
||||||
margin-bottom: -4px;
|
margin-bottom: -4px;
|
||||||
}
|
}
|
||||||
{
|
.openerp .oe-m2m-disabled-cm {
|
||||||
|
color: grey;
|
||||||
}
|
}
|
||||||
|
|
|
@ -979,34 +979,37 @@ openerp.base.form.FieldSelection = openerp.base.form.Field.extend({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var proto = $.ui.autocomplete.prototype,
|
// jquery autocomplete tweak to allow html
|
||||||
initSource = proto._initSource;
|
(function(x) {
|
||||||
|
var proto = $.ui.autocomplete.prototype,
|
||||||
function filter( array, term ) {
|
initSource = proto._initSource;
|
||||||
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
|
|
||||||
return $.grep( array, function(value) {
|
function filter( array, term ) {
|
||||||
return matcher.test( $( "<div>" ).html( value.label || value.value || value ).text() );
|
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
|
||||||
});
|
return $.grep( array, function(value) {
|
||||||
}
|
return matcher.test( $( "<div>" ).html( value.label || value.value || value ).text() );
|
||||||
|
});
|
||||||
$.extend( proto, {
|
|
||||||
_initSource: function() {
|
|
||||||
if ( this.options.html && $.isArray(this.options.source) ) {
|
|
||||||
this.source = function( request, response ) {
|
|
||||||
response( filter( this.options.source, request.term ) );
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
initSource.call( this );
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_renderItem: function( ul, item) {
|
|
||||||
return $( "<li></li>" )
|
|
||||||
.data( "item.autocomplete", item )
|
|
||||||
.append( $( "<a></a>" )[ this.options.html ? "html" : "text" ]( item.label ) )
|
|
||||||
.appendTo( ul );
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
$.extend( proto, {
|
||||||
|
_initSource: function() {
|
||||||
|
if ( this.options.html && $.isArray(this.options.source) ) {
|
||||||
|
this.source = function( request, response ) {
|
||||||
|
response( filter( this.options.source, request.term ) );
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
initSource.call( this );
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_renderItem: function( ul, item) {
|
||||||
|
return $( "<li></li>" )
|
||||||
|
.data( "item.autocomplete", item )
|
||||||
|
.append( $( "<a></a>" )[ this.options.html ? "html" : "text" ]( item.label ) )
|
||||||
|
.appendTo( ul );
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(null);
|
||||||
|
|
||||||
openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||||
init: function(view, node) {
|
init: function(view, node) {
|
||||||
|
@ -1015,6 +1018,7 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||||
this.limit = 7;
|
this.limit = 7;
|
||||||
this.value = null;
|
this.value = null;
|
||||||
this.cm_id = _.uniqueId('m2o_cm_');
|
this.cm_id = _.uniqueId('m2o_cm_');
|
||||||
|
this.last_search = [];
|
||||||
},
|
},
|
||||||
start: function() {
|
start: function() {
|
||||||
this._super();
|
this._super();
|
||||||
|
@ -1046,7 +1050,16 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
var cmenu = this.$menu_btn.contextMenu(this.cm_id, {'leftClickToo': true,
|
var cmenu = this.$menu_btn.contextMenu(this.cm_id, {'leftClickToo': true,
|
||||||
bindings: bindings});
|
bindings: bindings, itemStyle: {"color": ""},
|
||||||
|
onContextMenu: function() {
|
||||||
|
if(self.value) {
|
||||||
|
$("#" + self.cm_id + "_open").removeClass("oe-m2m-disabled-cm");
|
||||||
|
} else {
|
||||||
|
$("#" + self.cm_id + "_open").addClass("oe-m2m-disabled-cm");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// some behavior for input
|
// some behavior for input
|
||||||
this.$input.keyup(function() {
|
this.$input.keyup(function() {
|
||||||
|
@ -1064,6 +1077,19 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||||
self.$input.focus();
|
self.$input.focus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
var anyoneLoosesFocus = function() {
|
||||||
|
if (!self.$input.is(":focus") &&
|
||||||
|
!self.$input.autocomplete("widget").is(":visible") &&
|
||||||
|
!self.value) {
|
||||||
|
if(self.value === undefined && self.last_search.length > 0) {
|
||||||
|
self.value = self.last_search[0];
|
||||||
|
} else {
|
||||||
|
self.value = null;
|
||||||
|
}
|
||||||
|
self.$input.val(self.value ? self.value[1] : "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.$input.focusout(anyoneLoosesFocus);
|
||||||
|
|
||||||
// autocomplete
|
// autocomplete
|
||||||
this.$input.autocomplete({
|
this.$input.autocomplete({
|
||||||
|
@ -1071,7 +1097,7 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||||
select: function(event, ui) {
|
select: function(event, ui) {
|
||||||
var item = ui.item;
|
var item = ui.item;
|
||||||
if (item.id) {
|
if (item.id) {
|
||||||
self.value = [item.id, item.label];
|
self.value = [item.id, item.name];
|
||||||
} else if (item.action) {
|
} else if (item.action) {
|
||||||
self.value = undefined;
|
self.value = undefined;
|
||||||
item.action();
|
item.action();
|
||||||
|
@ -1081,7 +1107,8 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||||
focus: function(e, ui) {
|
focus: function(e, ui) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
},
|
},
|
||||||
html: true
|
html: true,
|
||||||
|
close: anyoneLoosesFocus
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// autocomplete component content handling
|
// autocomplete component content handling
|
||||||
|
@ -1092,9 +1119,10 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||||
var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, []);
|
var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, []);
|
||||||
|
|
||||||
dataset.name_search(search_val, this.limit + 1, function(data) {
|
dataset.name_search(search_val, this.limit + 1, function(data) {
|
||||||
|
self.last_search = data.result;
|
||||||
// possible selections for the m2o
|
// possible selections for the m2o
|
||||||
var values = _.map(data.result, function(x) {
|
var values = _.map(data.result, function(x) {
|
||||||
return {label: $('<span />').text(x[1]).html(), id:x[0]};
|
return {label: $('<span />').text(x[1]).html(), name:x[1], id:x[0]};
|
||||||
});
|
});
|
||||||
|
|
||||||
// additional selections, actions that open popup
|
// additional selections, actions that open popup
|
||||||
|
@ -1102,6 +1130,7 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||||
values = values.slice(0, self.limit);
|
values = values.slice(0, self.limit);
|
||||||
values.push({label: "<em> Search More...</em>", action: function() {
|
values.push({label: "<em> Search More...</em>", action: function() {
|
||||||
dataset.name_search(search_val, false, function(data) {
|
dataset.name_search(search_val, false, function(data) {
|
||||||
|
self.value = null;
|
||||||
self._search_create_popup("search", data.result);
|
self._search_create_popup("search", data.result);
|
||||||
});
|
});
|
||||||
}});
|
}});
|
||||||
|
@ -1109,10 +1138,12 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||||
if (self.value === undefined) {
|
if (self.value === undefined) {
|
||||||
values.push({label: '<em> Create "<strong>' +
|
values.push({label: '<em> Create "<strong>' +
|
||||||
$('<span />').text(search_val).html() + '</strong>"</em>', action: function() {
|
$('<span />').text(search_val).html() + '</strong>"</em>', action: function() {
|
||||||
|
self.value = null;
|
||||||
self._search_create_popup("form");
|
self._search_create_popup("form");
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
values.push({label: "<em> Create and Edit...</em>", action: function() {
|
values.push({label: "<em> Create and Edit...</em>", action: function() {
|
||||||
|
self.value = null;
|
||||||
self._search_create_popup("form");
|
self._search_create_popup("form");
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
|
|
@ -533,8 +533,8 @@
|
||||||
<img src="/base/static/src/img/icons/gtk-edit.png"/></span>
|
<img src="/base/static/src/img/icons/gtk-edit.png"/></span>
|
||||||
<div t-att-id="widget.cm_id" class="contextMenu" style="display:none"><ul>
|
<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 + '_search'">Search</li>
|
||||||
<li t-att-id="widget.cm_id + '_create'">Create</li>
|
<li t-att-id="widget.cm_id + '_create'">Create New</li>
|
||||||
<li t-att-id="widget.cm_id + '_open'">Open</li>
|
<li t-att-id="widget.cm_id + '_open'" style="color:grey">Open</li>
|
||||||
</ul></div>
|
</ul></div>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
|
|
Loading…
Reference in New Issue