commit
f62459d5b2
|
@ -449,12 +449,6 @@ class DataSet(openerpweb.Controller):
|
|||
m = req.session.model(model)
|
||||
r = m.default_get(fields, context)
|
||||
return {'result': r}
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def name_search(self, req, model, search_str, domain=[], context={}, limit=False):
|
||||
m = req.session.model(model)
|
||||
r = m.name_search(search_str, domain, 'ilike', context, limit)
|
||||
return {'result': r}
|
||||
|
||||
class DataGroup(openerpweb.Controller):
|
||||
_cp_path = "/base/group"
|
||||
|
|
|
@ -693,6 +693,9 @@ background: linear-gradient(top, #ffffff 0%,#d8d8d8 11%,#afafaf 86%,#333333 91%,
|
|||
.openerp table.oe_frame td {
|
||||
color: #4c4c4c;
|
||||
}
|
||||
.openerp td.oe_form_frame_cell {
|
||||
padding: 2px;
|
||||
}
|
||||
.openerp .required.error {
|
||||
border: 1px solid #900;
|
||||
}
|
||||
|
@ -709,6 +712,7 @@ background: linear-gradient(top, #ffffff 0%,#d8d8d8 11%,#afafaf 86%,#333333 91%,
|
|||
.openerp label.oe_form_label, .openerp label.oe_form_label_help {
|
||||
display: block;
|
||||
text-align: right;
|
||||
margin-top: 3px;
|
||||
}
|
||||
.openerp label.oe_form_label_help span {
|
||||
font-size: 80%;
|
||||
|
|
|
@ -320,15 +320,14 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.
|
|||
args: args || []
|
||||
}, callback, error_callback);
|
||||
},
|
||||
name_search: function (search_str, limit, callback) {
|
||||
search_str = search_str || '';
|
||||
return this.rpc('/base/dataset/name_search', {
|
||||
model: this.model,
|
||||
search_str: search_str,
|
||||
domain: this.domain || [],
|
||||
context: this.context,
|
||||
limit: limit || false
|
||||
}, callback);
|
||||
/**
|
||||
* Arguments:
|
||||
* name='', args=None, operator='ilike', context=None, limit=100
|
||||
*/
|
||||
name_search: function (args, callback, error_callback) {
|
||||
return this.call('name_search',
|
||||
args,
|
||||
callback, error_callback);
|
||||
},
|
||||
exec_workflow: function (id, signal, callback) {
|
||||
return this.rpc('/base/dataset/exec_workflow', {
|
||||
|
|
|
@ -88,6 +88,9 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
|
|||
var field = this.fields[f];
|
||||
field.touched = false;
|
||||
field.set_value(this.datarecord[f] || false);
|
||||
// TODO: here we should be able to alter the 'touched' state when setting value
|
||||
// the following line will be removed by fme as soon as refactoring has been done
|
||||
field.touched = false;
|
||||
field.validate();
|
||||
}
|
||||
if (!record.id) {
|
||||
|
@ -173,8 +176,7 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
|
|||
return this.rpc(ajax, {
|
||||
model: this.dataset.model,
|
||||
method: method,
|
||||
ids: (this.datarecord.id == null ? [] : [this.datarecord.id]),
|
||||
args: args
|
||||
args: [].concat([(this.datarecord.id == null ? [] : [this.datarecord.id])], args)
|
||||
}, function(response) {
|
||||
self.on_processed_onchange(response, processed);
|
||||
});
|
||||
|
@ -1123,7 +1125,7 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
|||
|
||||
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, false, 'ilike', {}, this.limit + 1], function(data) {
|
||||
self.last_search = data.result;
|
||||
// possible selections for the m2o
|
||||
var values = _.map(data.result, function(x) {
|
||||
|
@ -1134,13 +1136,16 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
|||
if (values.length > self.limit) {
|
||||
values = values.slice(0, self.limit);
|
||||
values.push({label: "<em> Search More...</em>", action: function() {
|
||||
dataset.name_search(search_val, false, function(data) {
|
||||
dataset.name_search([search_val, false, 'ilike', {}, false], function(data) {
|
||||
self._change_int_value(null);
|
||||
self._search_create_popup("search", data.result);
|
||||
});
|
||||
}});
|
||||
}
|
||||
if (self.value === undefined) {
|
||||
var raw_result = _(data.result).map(function(x) {return x[1];})
|
||||
if (search_val.length > 0 &&
|
||||
!_.include(raw_result, search_val) &&
|
||||
(!self.value || search_val !== self.value[1])) {
|
||||
values.push({label: '<em> Create "<strong>' +
|
||||
$('<span />').text(search_val).html() + '</strong>"</em>', action: function() {
|
||||
self._quick_create(search_val);
|
||||
|
|
|
@ -1,282 +0,0 @@
|
|||
openerp.base.m2o = function(openerp){
|
||||
|
||||
/*
|
||||
<input type="text"
|
||||
t-att-name="widget.name"
|
||||
t-att-id="widget.element_id + '_field'"
|
||||
t-att-class="'field_' + widget.type"
|
||||
t-att-type="widget.type"
|
||||
style="width: 100%;"/>
|
||||
<span type='button' t-att-class="'ui_combo'" tabindex="'-1'" title="'Show All Items'"></span>
|
||||
<img t-att-id="widget.name + '_open'" t-att-alt="'Open'" t-att-title="'Create'"
|
||||
t-att-src="'/base/static/src/img/iconset-d-drop.gif'" t-att-class="'m2o_open'"/>
|
||||
*/
|
||||
|
||||
openerp.base.m2o = openerp.base.Controller.extend({
|
||||
init: function(element_id, model, dataset, session){
|
||||
this._super(element_id, model, dataset, session);
|
||||
|
||||
this.session = session;
|
||||
this.element = element_id.find('input');
|
||||
this.button = element_id.find('span');
|
||||
this.dataset = dataset;
|
||||
this.cache = {};
|
||||
var lastXhr;
|
||||
this.$input;
|
||||
this.relation = model;
|
||||
this.result_ids = [];
|
||||
this.create_option = jQuery('#'+this.element.attr('name')+ '_open');
|
||||
if (this.create_option) {
|
||||
var defaults = [
|
||||
{'text': 'Go to..', 'action': "call_Actions()"},
|
||||
{'text': 'Choose..', 'action': "call_Actions()"}
|
||||
]
|
||||
jQuery(this.create_option).click(jQuery.proxy(function(evt){
|
||||
on_context_menu(evt, this.element, defaults);
|
||||
}, this));
|
||||
}
|
||||
var self = this;
|
||||
|
||||
this.$input = this.element.autocomplete ({
|
||||
source: function(request, response){
|
||||
self.getSearch_Result(request, response);
|
||||
return;
|
||||
},
|
||||
select: function(event, ui){
|
||||
ui.item.value = ui.item.orig_val? ui.item.orig_val : self.element.data( "autocomplete" ).term;
|
||||
if (ui.item.id == 'more') {
|
||||
self.dataset.ids = self.result_ids;
|
||||
self.dataset.count = self.dataset.ids.length;
|
||||
self.dataset.domain = self.result_ids.length ? [["id", "in", self.dataset.ids]] : []
|
||||
self.element.val('');
|
||||
var pop = new openerp.base.form.Many2XSelectPopup(null, self.session);
|
||||
pop.select_element(self.relation, self.dataset);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ui.item.id == 'create') {
|
||||
var val = self.element.val();
|
||||
self.dataset.create({'name': ui.item.value},
|
||||
function(r){}, function(r){
|
||||
var element_id = _.uniqueId("act_window_dialog");
|
||||
var dialog = jQuery('<div>',
|
||||
{'id': element_id
|
||||
}).dialog({
|
||||
modal: true,
|
||||
minWidth: 800
|
||||
});
|
||||
self.element.val('');
|
||||
var event_form = new openerp.base.FormView(null,
|
||||
self.session, element_id, self.dataset, false);
|
||||
event_form.start();
|
||||
});
|
||||
$input.val(self.element.data( "autocomplete" ).term);
|
||||
return true;
|
||||
}
|
||||
self.element.attr('m2o_id', ui.item.id);
|
||||
},
|
||||
minLength: 0,
|
||||
focus: function(event, ui) {
|
||||
self.gotFocus(event, ui);
|
||||
}
|
||||
});
|
||||
|
||||
this.button.button({
|
||||
icons: {
|
||||
primary: "ui-icon-triangle-1-s"},
|
||||
text: false
|
||||
})
|
||||
.click(function() {
|
||||
// close if already visible
|
||||
if (self.$input.autocomplete("widget").is(":visible")) {
|
||||
self.$input.autocomplete( "close" );
|
||||
return;
|
||||
}
|
||||
$(this).blur();
|
||||
self.$input.autocomplete("search", "" );
|
||||
self.$input.focus();
|
||||
});
|
||||
},
|
||||
|
||||
getSearch_Result: function(request, response) {
|
||||
var search_val = request.term;
|
||||
if (search_val in this.cache) {
|
||||
response(this.cache[search_val]);
|
||||
return;
|
||||
}
|
||||
var self = this;
|
||||
//pass request to server
|
||||
lastXhr = this.dataset.name_search(search_val, function(obj, status, xhr){
|
||||
var result = obj.result;
|
||||
var values = [];
|
||||
|
||||
$.each(result, function(i, val){
|
||||
values.push({
|
||||
value: val[1],
|
||||
id: val[0],
|
||||
orig_val: val[1]
|
||||
});
|
||||
self.result_ids.push(result[i][0]);
|
||||
});
|
||||
|
||||
if (values.length > 7) {
|
||||
values = values.slice(0, 7);
|
||||
}
|
||||
values.push({'value': 'More...', id: 'more', orig_val:''},
|
||||
{'value': 'Create..'+search_val, id: 'create', orig_val: ''});
|
||||
self.cache[search_val] = values;
|
||||
response(values);
|
||||
});
|
||||
},
|
||||
|
||||
getSelected_Result: function(event, ui) {
|
||||
ui.item.value = ui.item.orig_val? ui.item.orig_val : this.element.data( "autocomplete" ).term;
|
||||
if (ui.item.id == 'more') {
|
||||
this.dataset.ids = this.result_ids;
|
||||
this.dataset.count = this.dataset.ids.length;
|
||||
this.dataset.domain = this.result_ids.length ? [["id", "in", this.dataset.ids]] : [];
|
||||
this.element.val('');
|
||||
var pop = new openerp.base.form.Many2XSelectPopup(null, this.session);
|
||||
pop.select_element(this.relation, this.dataset);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ui.item.id == 'create') {
|
||||
this.openRecords(event, ui);
|
||||
}
|
||||
this.element.attr('m2o_id', ui.item.id);
|
||||
},
|
||||
|
||||
gotFocus: function(event, ui) {
|
||||
if (ui.item.id == ('create')) {
|
||||
return true;
|
||||
}
|
||||
ui.item.value = this.element.data("autocomplete").term.length ?
|
||||
this.element.val() + '[' + ui.item.orig_val.substring(this.element.data("autocomplete").term.length) + ']' : this.lastSearch;
|
||||
},
|
||||
|
||||
openRecords: function(event, ui) {
|
||||
var val = this.element.val();
|
||||
var self = this;
|
||||
this.dataset.create({'name': ui.item.value},
|
||||
function(r){}, function(r){
|
||||
var element_id = _.uniqueId("act_window_dialog");
|
||||
var dialog = jQuery('<div>',
|
||||
{'id': element_id
|
||||
}).dialog({
|
||||
modal: true,
|
||||
minWidth: 800
|
||||
});
|
||||
self.element.val('');
|
||||
var event_form = new openerp.base.FormView(null, self.session,
|
||||
element_id, self.dataset, false);
|
||||
event_form.start();
|
||||
});
|
||||
self.$input.val(self.element.data( "autocomplete" ).term);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function call_Actions() {
|
||||
|
||||
}
|
||||
|
||||
function on_context_menu(evt, target, defaults){
|
||||
|
||||
var $target = jQuery(target || evt.target);
|
||||
var kind = $target.attr('type');
|
||||
if (!(kind && $target.is(':input, :enabled'))) {
|
||||
return;
|
||||
}
|
||||
var $menu = jQuery('#m2o_contextmenu').show();
|
||||
if (!$menu.length) {
|
||||
$menu = jQuery('<div id="m2o_contextmenu" class="m2o_contextmenu">')
|
||||
.css({position: 'absolute'})
|
||||
.hover(showContextMenu, hideContextMenu)
|
||||
.appendTo(document.body).show();
|
||||
|
||||
if (jQuery(document.documentElement).hasClass('ie')) {
|
||||
jQuery('<iframe id="m2o_contextmenu_frm" src="#" frameborder="0" scrolling="no">')
|
||||
.css({position: 'absolute'})
|
||||
.hide().appendTo(document.body);
|
||||
}
|
||||
}
|
||||
|
||||
var src = $target.attr('id');
|
||||
if (kind == 'many2one' || kind == 'reference') {
|
||||
src = src.slice(0, -5);
|
||||
}
|
||||
var $src = jQuery('[id="' + src + '"]');
|
||||
|
||||
var click_position = mousePositionDammit(evt);
|
||||
$menu.offset({top: 0, left: 0});
|
||||
$menu.offset({top: click_position.y - 5, left: click_position.x - 5});
|
||||
$menu.hide();
|
||||
makeContextMenu(src, kind, $src.attr('relation'), $src.val(), defaults);
|
||||
|
||||
if(evt.stop) {
|
||||
evt.stop();
|
||||
}
|
||||
evt.stopPropagation();
|
||||
evt.preventDefault();
|
||||
}
|
||||
|
||||
|
||||
function makeContextMenu(id, kind, relation, val, defaults){
|
||||
var $tbody = jQuery('<tbody>');
|
||||
jQuery.each(defaults, function (_, default_) {
|
||||
jQuery('<tr>').append(jQuery('<td>').append(
|
||||
jQuery('<span>').click(function () {
|
||||
hideContextMenu();
|
||||
return eval(default_.action);
|
||||
}).text(default_.text))).appendTo($tbody);
|
||||
});
|
||||
|
||||
var $menu = jQuery('#m2o_contextmenu');
|
||||
$menu.empty().append(
|
||||
jQuery('<table cellpadding="0" cellspacing="0">').append($tbody));
|
||||
|
||||
var menu_width = $menu.width();
|
||||
var body_width = jQuery(document.body).width();
|
||||
if (parseInt($menu.css("left")) + menu_width > body_width) {
|
||||
$menu.offset({ left: body_width - menu_width - 10 });
|
||||
}
|
||||
showContextMenu();
|
||||
}
|
||||
|
||||
function showContextMenu(){
|
||||
var $menu = jQuery('#m2o_contextmenu');
|
||||
var $ifrm = jQuery('#m2o_contextmenu_frm');
|
||||
console.log($menu, 8888888, $ifrm)
|
||||
$menu.show();
|
||||
if ($ifrm.length) {
|
||||
$ifrm.offset($menu.offset())
|
||||
.css({
|
||||
width: $menu.offsetWidth(),
|
||||
height: $menu.offsetHeight(),
|
||||
zIndex: 6
|
||||
}).show();
|
||||
}
|
||||
}
|
||||
|
||||
function hideContextMenu(){
|
||||
jQuery('#m2o_contextmenu, #m2o_contextmenu_frm').hide();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts mouse position on page for functions which may be bound using both
|
||||
* jQuery and MochiKit event handlers
|
||||
*
|
||||
* @param evt the library's events
|
||||
*/
|
||||
function mousePositionDammit(evt) {
|
||||
if(evt.mouse) {
|
||||
// mochikit
|
||||
return evt.mouse().page;
|
||||
}
|
||||
return {
|
||||
x: evt.pageX,
|
||||
y: evt.pageY
|
||||
}
|
||||
}
|
|
@ -417,7 +417,7 @@
|
|||
<t t-raw="console.log('Unhandled widget', widget)"/>
|
||||
</t>
|
||||
<t t-name="WidgetFrame">
|
||||
<table border="0" width="100%" cellpadding="2" cellspacing="2" class="oe_frame">
|
||||
<table border="0" width="100%" cellpadding="0" cellspacing="0" class="oe_frame">
|
||||
<tr t-foreach="widget.table" t-as="row">
|
||||
<t t-foreach="row" t-as="td">
|
||||
<td t-att-colspan="td.colspan gt 1 ? td.colspan : undefined"
|
||||
|
@ -425,7 +425,7 @@
|
|||
t-att-nowrap="td.is_field_label or td.is_field_m2o? 'true' : undefined"
|
||||
t-att-valign="td.table ? 'top' : undefined"
|
||||
t-att-id="td.element_id"
|
||||
t-att-class="'oe_form_' + (td.is_field_label ? 'label' : (td.field ? 'field_' + td.type : td.type))"
|
||||
t-att-class="'oe_form_frame_cell oe_form_' + (td.is_field_label ? 'label' : (td.field ? 'field_' + td.type : td.type))"
|
||||
>
|
||||
<t t-raw="td.render()"/>
|
||||
</td>
|
||||
|
|
Loading…
Reference in New Issue