mirror of https://github.com/OCA/web.git
[RFR] in order to work properly, we need to use FieldOne2Many's caching logic
parent
8c167a5535
commit
fb6b41eb21
|
@ -29,6 +29,16 @@ In case of trouble, please check there if your issue has already been reported.
|
||||||
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
|
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
|
||||||
`here <https://github.com/OCA/web/issues/new?body=module:%20web_widget_one2many_tags%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
`here <https://github.com/OCA/web/issues/new?body=module:%20web_widget_one2many_tags%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||||
|
|
||||||
|
Known issues / Roadmap
|
||||||
|
======================
|
||||||
|
|
||||||
|
* as one2many fields are cached on the client side until the user hits `Save`
|
||||||
|
on the main form, no ``name_get`` can be called on those records, which is
|
||||||
|
why changes that update the display name are not reflected until saving, and
|
||||||
|
new records are displayed as `New record` until then. If you don't like this,
|
||||||
|
add the field `display_name` to your form and have it recomputed in an
|
||||||
|
@onchange handler.
|
||||||
|
|
||||||
Credits
|
Credits
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
|
|
@ -15,4 +15,7 @@
|
||||||
"data": [
|
"data": [
|
||||||
'views/templates.xml',
|
'views/templates.xml',
|
||||||
],
|
],
|
||||||
|
"qweb": [
|
||||||
|
'static/src/xml/web_widget_one2many_tags.xml',
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,71 +5,137 @@
|
||||||
openerp.web_widget_one2many_tags = function(instance)
|
openerp.web_widget_one2many_tags = function(instance)
|
||||||
{
|
{
|
||||||
openerp.web_widget_one2many_tags.FieldOne2ManyTags =
|
openerp.web_widget_one2many_tags.FieldOne2ManyTags =
|
||||||
instance.web.form.FieldMany2ManyTags.extend({
|
instance.web.form.FieldOne2Many.extend(instance.web.form.ReinitializeFieldMixin, {
|
||||||
|
template: "FieldOne2ManyTags",
|
||||||
|
tag_template: "FieldOne2ManyTag",
|
||||||
|
disable_utility_classes: false,
|
||||||
initialize_texttext: function()
|
initialize_texttext: function()
|
||||||
{
|
{
|
||||||
var self = this,
|
var self = this;
|
||||||
result = this._super.apply(this, arguments),
|
return {
|
||||||
removeTag = result.ext.tags.removeTag;
|
plugins: 'tags arrow filter',
|
||||||
result.plugins = 'tags arrow filter';
|
ext: {
|
||||||
result.ext.core.onSetInputData = function(e, data)
|
itemManager: {
|
||||||
{
|
itemToString: function(item) {
|
||||||
this.input().val(data);
|
return item.name;
|
||||||
};
|
},
|
||||||
result.filter = {
|
},
|
||||||
items: []
|
arrow: {
|
||||||
};
|
onArrowClick: function(e)
|
||||||
result.ext.arrow = {
|
{
|
||||||
onArrowClick: function(e)
|
var list_view = new instance.web.form.One2ManyListView(
|
||||||
{
|
self, self.dataset);
|
||||||
var context = self.build_context(),
|
list_view.o2m = self;
|
||||||
key = _.str.sprintf(
|
list_view.editable = function() { return false };
|
||||||
'default_%s', self.field.relation_field)
|
list_view.do_add_record();
|
||||||
context.add({[key]: self.field_manager.datarecord.id});
|
},
|
||||||
self._search_create_popup('form', undefined, context);
|
},
|
||||||
|
tags: {
|
||||||
|
isTagAllowed: function(tag) {
|
||||||
|
return tag.name;
|
||||||
|
},
|
||||||
|
removeTag: function(tag)
|
||||||
|
{
|
||||||
|
self.dataset.unlink([tag.data('id')]);
|
||||||
|
return $.fn.textext.TextExtTags.prototype.removeTag
|
||||||
|
.call(this, tag);
|
||||||
|
},
|
||||||
|
renderTag: function(tag) {
|
||||||
|
return $.fn.textext.TextExtTags.prototype.renderTag
|
||||||
|
.call(this, tag).data("id", tag.id);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
items: []
|
||||||
},
|
},
|
||||||
}
|
|
||||||
result.ext.tags.removeTag = function(tag)
|
|
||||||
{
|
|
||||||
var id = tag.data("id"),
|
|
||||||
dataset = new instance.web.DataSet(
|
|
||||||
self, self.field.relation, self.build_context());
|
|
||||||
dataset.unlink([id]);
|
|
||||||
return removeTag(tag);
|
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
build_context: function()
|
||||||
|
{
|
||||||
|
var context = this._super.apply(this, arguments),
|
||||||
|
key = _.str.sprintf('default_%s', this.field.relation_field);
|
||||||
|
context.add({[key]: this.field_manager.datarecord.id});
|
||||||
|
return context;
|
||||||
|
},
|
||||||
|
reload_current_view: function()
|
||||||
|
{
|
||||||
|
var self = this;
|
||||||
|
if(!self.$el.length)
|
||||||
|
{
|
||||||
|
return jQuery.when();
|
||||||
|
}
|
||||||
|
if(!self.get("effective_readonly"))
|
||||||
|
{
|
||||||
|
self.ignore_blur = false;
|
||||||
|
if(self.tags)
|
||||||
|
{
|
||||||
|
self.tags.tagElements().remove();
|
||||||
|
}
|
||||||
|
if(!self.$text || !self.$text.length)
|
||||||
|
{
|
||||||
|
self.$text = this.$("textarea");
|
||||||
|
self.$text.textext(self.initialize_texttext());
|
||||||
|
self.$text.bind('tagClick', function(e, tag, value, callback)
|
||||||
|
{
|
||||||
|
var list_view = new instance.web.form.One2ManyViewManager(
|
||||||
|
self, self.dataset);
|
||||||
|
list_view.o2m = self;
|
||||||
|
self.dataset.select_id(value.id);
|
||||||
|
list_view.switch_mode('form');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if(self.$text.textext().length)
|
||||||
|
{
|
||||||
|
self.tags = self.$text.textext()[0].tags();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self.tags = null;
|
||||||
|
self.$text = null;
|
||||||
|
}
|
||||||
|
return self.dataset.read_ids(self.dataset.ids, ['display_name'])
|
||||||
|
.then(function(names)
|
||||||
|
{
|
||||||
|
if(self.get("effective_readonly"))
|
||||||
|
{
|
||||||
|
self.$el.html(instance.web.qweb.render(
|
||||||
|
self.tag_template,
|
||||||
|
{
|
||||||
|
elements: _(names).map(function(name)
|
||||||
|
{
|
||||||
|
return [name.id, name.display_name];
|
||||||
|
})
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
else if(self.$text.textext().length)
|
||||||
|
{
|
||||||
|
self.tags.addTags(_(names).map(function(name)
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
name: name.display_name || instance.web._t('New record'),
|
||||||
|
id: name.id,
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
reinitialize: function()
|
||||||
|
{
|
||||||
|
var result = instance.web.form.ReinitializeFieldMixin.reinitialize.call(this);
|
||||||
|
this.reload_current_view();
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
initialize_content: function()
|
// defuse some functions we don't need
|
||||||
|
get_active_view: function()
|
||||||
{
|
{
|
||||||
var self = this,
|
return false;
|
||||||
result = this._super.apply(this, arguments);
|
},
|
||||||
if(!this.$text)
|
load_views: function()
|
||||||
{
|
{
|
||||||
return result;
|
return jQuery.when();
|
||||||
}
|
|
||||||
this.$text.bind('tagClick', function(e, tag, value, callback)
|
|
||||||
{
|
|
||||||
var popup = new instance.web.form.FormOpenPopup(self);
|
|
||||||
popup.show_element(
|
|
||||||
self.field.relation, value.id, self.build_context(),
|
|
||||||
{
|
|
||||||
title: instance.web._t("Open: ") + value.name,
|
|
||||||
readonly: self.get("effective_readonly"),
|
|
||||||
});
|
|
||||||
popup.on('write_completed', self, function()
|
|
||||||
{
|
|
||||||
popup.dataset.name_get(popup.dataset.ids)
|
|
||||||
.then(function(names)
|
|
||||||
{
|
|
||||||
_(names).each(function(name)
|
|
||||||
{
|
|
||||||
value.name = name[1];
|
|
||||||
callback(value, true);
|
|
||||||
})
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates>
|
||||||
|
<t t-name="FieldOne2ManyTags" t-extend="FieldMany2ManyTags" />
|
||||||
|
<t t-name="FieldOne2ManyTag" t-extend="FieldMany2ManyTag" />
|
||||||
|
</templates>
|
Loading…
Reference in New Issue