init: function(parent, dataset, view_id, options) {
var self = this;
this._super(parent);
+ this.ViewManager = parent;
this.set_default_options(options);
this.dataset = dataset;
this.model = dataset.model;
this.mutating_mutex = new $.Mutex();
this.on_change_list = [];
this.save_list = [];
+ this.render_value_defs = [];
this.reload_mutex = new $.Mutex();
this.__clicked_inside = false;
this.__blur_timeout = null;
this.$el.off('.formBlur');
}
this._super();
+ if (this.$buttons) {
+ this.$buttons.remove();
+ }
},
load_form: function(data) {
var self = this;
});
}
return $.when();
+ }).fail(function() {
+ self.save_list.pop();
+ return $.when();
});
};
return iterate();
} else if (mode === "create") {
mode = "edit";
}
+ this.render_value_defs = [];
this.set({actual_mode: mode});
},
check_actual_mode: function(source, options) {
}
}
},
- on_button_save: function() {
+ on_button_save: function(e) {
var self = this;
+ $(e.target).attr("disabled", true);
return this.save().done(function(result) {
self.trigger("save", result);
- self.to_view_mode();
+ self.reload().then(function() {
+ self.to_view_mode();
+ var parent = self.ViewManager.ActionManager.getParent();
+ if(parent){
+ parent.menu.do_reload_needaction();
+ }
+ });
+ }).always(function(){
+ $(e.target).attr("disabled", false);
});
},
on_button_cancel: function(event) {
+ var self = this;
if (this.can_be_discarded()) {
if (this.get('actual_mode') === 'create') {
this.trigger('history_back');
} else {
this.to_view_mode();
- this.trigger('load_record', this.datarecord);
+ $.when.apply(null, this.render_value_defs).then(function(){
+ self.trigger('load_record', self.datarecord);
+ });
}
}
this.trigger('on_button_cancel');
this.has_been_loaded.done(function() {
if (self.datarecord.id && confirm(_t("Do you really want to delete this record?"))) {
self.dataset.unlink([self.datarecord.id]).done(function() {
- self.execute_pager_action('next');
+ if (self.dataset.size()) {
+ self.execute_pager_action('next');
+ } else {
+ self.do_action('history_back');
+ }
def.resolve();
});
} else {
if (save_obj.error)
return $.Deferred().reject();
return $.when.apply($, save_obj.ret);
+ }).done(function() {
+ self.$el.removeClass('oe_form_dirty');
});
},
_process_save: function(save_obj) {
try {
var form_invalid = false,
values = {},
- first_invalid_field = null;
+ first_invalid_field = null,
+ readonly_values = {};
for (var f in self.fields) {
if (!self.fields.hasOwnProperty(f)) { continue; }
f = self.fields[f];
if (!first_invalid_field) {
first_invalid_field = f;
}
- } else if (f.name !== 'id' && !f.get("readonly") && (!self.datarecord.id || f._dirty_flag)) {
+ } else if (f.name !== 'id' && (!self.datarecord.id || f._dirty_flag)) {
// Special case 'id' field, do not save this field
// on 'create' : save all non readonly fields
// on 'edit' : save non readonly modified fields
- values[f.name] = f.get_value();
+ if (!f.get("readonly")) {
+ values[f.name] = f.get_value();
+ } else {
+ readonly_values[f.name] = f.get_value();
+ }
}
}
if (form_invalid) {
var save_deferral;
if (!self.datarecord.id) {
// Creation save
- save_deferral = self.dataset.create(values).then(function(r) {
+ save_deferral = self.dataset.create(values, {readonly_fields: readonly_values}).then(function(r) {
return self.record_created(r, prepend_on_create);
}, null);
} else if (_.isEmpty(values)) {
save_deferral = $.Deferred().resolve({}).promise();
} else {
// Write save
- save_deferral = self.dataset.write(self.datarecord.id, values, {}).then(function(r) {
+ save_deferral = self.dataset.write(self.datarecord.id, values, {readonly_fields: readonly_values}).then(function(r) {
return self.record_saved(r);
}, null);
}
* @param {Object} r result of the write function.
*/
record_saved: function(r) {
- var self = this;
+ this.trigger('record_saved', r);
if (!r) {
// should not happen in the server, but may happen for internal purpose
- this.trigger('record_saved', r);
return $.Deferred().reject();
- } else {
- return $.when(this.reload()).then(function () {
- self.trigger('record_saved', r);
- return r;
- });
}
+ return r;
},
/**
* Updates the form' dataset to contain the new record:
context: {
'bin_size': true,
'future_display_name': true
- }
+ },
+ check_access_rule: true
}).then(function(r) {
self.trigger('load_record', r);
+ }).fail(function (){
+ self.do_action('history_back');
});
}
});
return value;
}
var fields = _.chain(this.fields)
- .map(function (field, name) {
+ .map(function (field) {
var value = field.get_value();
// ignore fields which are empty, invisible, readonly, o2m
// or m2m
}
return {
- name: name,
+ name: field.name,
string: field.string,
value: value,
displayed: display(field, value),
.value();
var conditions = _.chain(self.fields)
.filter(function (field) { return field.field.change_default; })
- .map(function (field, name) {
+ .map(function (field) {
var value = field.get_value();
return {
- name: name,
+ name: field.name,
string: field.string,
value: value,
displayed: display(field, value),
$(this).children().each(function() {
var $td = $(this),
$child = $td.children(':first');
+ if ($child.attr('cell-class')) {
+ $td.addClass($child.attr('cell-class'));
+ }
switch ($child[0].tagName.toLowerCase()) {
case 'separator':
break;
if (! page.__ic)
return;
page.__ic.on("change:effective_invisible", null, function() {
- if (!page.__ic.get('effective_invisible')) {
+ if (!page.__ic.get('effective_invisible') && page.autofocus) {
$new_notebook.tabs('select', i);
return;
}
if (this.node.attrs.icon && (! /\//.test(this.node.attrs.icon))) {
this.node.attrs.icon = '/web/static/src/img/icons/' + this.node.attrs.icon + '.png';
}
- this.view.on('view_content_has_changed', this, this.check_disable);
},
start: function() {
this._super.apply(this, arguments);
+ this.view.on('view_content_has_changed', this, this.check_disable);
+ this.check_disable();
this.$el.click(this.on_click);
if (this.node.attrs.help || instance.session.debug) {
this.do_attach_tooltip();
modal: true,
buttons: [
{text: _t("Cancel"), click: function() {
- def.resolve();
$(this).dialog("close");
}
},
{text: _t("Ok"), click: function() {
- self.on_confirmed().done(function() {
- def.resolve();
+ var self2 = this;
+ self.on_confirmed().always(function() {
+ $(self2).dialog("close");
});
- $(this).dialog("close");
}
}
- ]
+ ],
+ beforeClose: function() {
+ def.resolve();
+ },
});
return def.promise();
} else {
return this.view.do_execute_action(
_.extend({}, this.node.attrs, {context: context}),
- this.view.dataset, this.view.datarecord.id, function () {
- self.view.recursive_reload();
+ this.view.dataset, this.view.datarecord.id, function (reason) {
+ if (!_.isObject(reason)) {
+ self.view.recursive_reload();
+ }
});
},
check_disable: function() {
value without triggering a re-rendering.
*/
internal_set_value: function(value_) {
- var tmp = this.no_render;
+ var tmp = this.no_rerender;
this.no_rerender = true;
this.set({'value': value_});
this.no_rerender = tmp;
instance.web.form.ReinitializeFieldMixin = _.extend({}, instance.web.form.ReinitializeWidgetMixin, {
reinitialize: function() {
instance.web.form.ReinitializeWidgetMixin.reinitialize.call(this);
- this.render_value();
+ var res = this.render_value();
+ if (this.view && this.view.render_value_defs){
+ this.view.render_value_defs.push(res);
+ }
},
});
+/**
+ Some hack to make placeholders work in ie9.
+*/
+if ($.browser.msie && $.browser.version === "9.0") {
+ document.addEventListener("DOMNodeInserted",function(event){
+ var nodename = event.target.nodeName.toLowerCase();
+ if ( nodename === "input" || nodename == "textarea" ) {
+ $(event.target).placeholder();
+ }
+ });
+}
+
instance.web.form.FieldChar = instance.web.form.AbstractField.extend(instance.web.form.ReinitializeFieldMixin, {
template: 'FieldChar',
widget_class: 'oe_form_field_char',
return this.get('value') === '' || this._super();
},
focus: function() {
- this.$('input:first')[0].focus();
+ var input = this.$('input:first')[0];
+ return input ? input.focus() : false;
},
set_dimensions: function (height, width) {
this._super(height, width);
},
on_button_clicked: function() {
if (!this.get('value') || !this.is_syntax_valid()) {
- this.do_warn(_t("E-mail error"), _t("Can't send email to invalid e-mail address"));
+ this.do_warn(_t("E-mail Error"), _t("Can't send email to invalid e-mail address"));
} else {
location.href = 'mailto:' + this.get('value');
}
if (!s) {
tmp = "http://" + this.get('value');
}
- this.$el.find('a').attr('href', tmp).text(this.get('value') ? tmp : '');
+ var text = this.get('value') ? this.node.attrs.text || tmp : '';
+ this.$el.find('a').attr('href', tmp).text(text);
}
},
on_button_clicked: function() {
if (!this.get('value')) {
- this.do_warn(_t("Resource error"), _t("This resource is empty"));
+ this.do_warn(_t("Resource Error"), _t("This resource is empty"));
} else {
var url = $.trim(this.get('value'));
if(/^www\./i.test(url))
this._super.apply(this, [value_]);
},
focus: function () {
- this.$('input:first').select();
+ var $input = this.$('input:first');
+ return $input.length ? $input.select() : false;
}
});
type_of_date: "datetime",
events: {
'change .oe_datepicker_master': 'change_datetime',
- 'dragstart img.oe_datepicker_trigger': function () { return false; },
+ 'keypress .oe_datepicker_master': 'change_datetime',
},
init: function(parent) {
this._super(parent);
this.$input = this.$el.find('input.oe_datepicker_master');
this.$input_picker = this.$el.find('input.oe_datepicker_container');
+ $.datepicker.setDefaults({
+ clearText: _t('Clear'),
+ clearStatus: _t('Erase the current date'),
+ closeText: _t('Done'),
+ closeStatus: _t('Close without change'),
+ prevText: _t('<Prev'),
+ prevStatus: _t('Show the previous month'),
+ nextText: _t('Next>'),
+ nextStatus: _t('Show the next month'),
+ currentText: _t('Today'),
+ currentStatus: _t('Show the current month'),
+ monthNames: Date.CultureInfo.monthNames,
+ monthNamesShort: Date.CultureInfo.abbreviatedMonthNames,
+ monthStatus: _t('Show a different month'),
+ yearStatus: _t('Show a different year'),
+ weekHeader: _t('Wk'),
+ weekStatus: _t('Week of the year'),
+ dayNames: Date.CultureInfo.dayNames,
+ dayNamesShort: Date.CultureInfo.abbreviatedDayNames,
+ dayNamesMin: Date.CultureInfo.shortestDayNames,
+ dayStatus: _t('Set DD as first week day'),
+ dateStatus: _t('Select D, M d'),
+ firstDay: Date.CultureInfo.firstDayOfWeek,
+ initStatus: _t('Select a date'),
+ isRTL: false
+ });
+ $.timepicker.setDefaults({
+ timeOnlyTitle: _t('Choose Time'),
+ timeText: _t('Time'),
+ hourText: _t('Hour'),
+ minuteText: _t('Minute'),
+ secondText: _t('Second'),
+ currentText: _t('Now'),
+ closeText: _t('Done')
+ });
+
this.picker({
onClose: this.on_picker_select,
onSelect: this.on_picker_select,
format_client: function(v) {
return instance.web.format_value(v, {"widget": this.type_of_date});
},
- change_datetime: function() {
- if (this.is_valid_()) {
+ change_datetime: function(e) {
+ if ((e.type !== "keypress" || e.which === 13) && this.is_valid_()) {
this.set_value_from_ui_();
this.trigger("datetime_changed");
}
return this.get('value') === '' || this._super();
},
focus: function() {
- if (this.datewidget && this.datewidget.$input) {
- this.datewidget.$input[0].focus();
- }
+ var input = this.datewidget && this.datewidget.$input[0];
+ return input ? input.focus() : false;
},
set_dimensions: function (height, width) {
this._super(height, width);
- this.datewidget.$input.css('height', height);
+ if (!this.get("effective_readonly")) {
+ this.datewidget.$input.css('height', height);
+ }
}
});
e.stopPropagation();
}
},
+ 'keypress': function (e) {
+ if (e.which === $.ui.keyCode.ENTER) {
+ e.stopPropagation();
+ }
+ },
'change textarea': 'store_dom_value',
},
- init: function (field_manager, node) {
- this._super(field_manager, node);
- },
initialize_content: function() {
var self = this;
- this.$textarea = this.$el.find('textarea');
- this.auto_sized = false;
- this.default_height = this.$textarea.css('height');
- if (this.get("effective_readonly")) {
- this.$textarea.attr('disabled', 'disabled');
+ if (! this.get("effective_readonly")) {
+ this.$textarea = this.$el.find('textarea');
+ this.auto_sized = false;
+ this.default_height = this.$textarea.css('height');
+ if (this.get("effective_readonly")) {
+ this.$textarea.attr('disabled', 'disabled');
+ }
+ this.setupFocus(this.$textarea);
+ } else {
+ this.$textarea = undefined;
}
- this.setupFocus(this.$textarea);
},
commit_value: function () {
- this.store_dom_value();
+ if (! this.get("effective_readonly") && this.$textarea) {
+ this.store_dom_value();
+ }
return this._super();
},
store_dom_value: function () {
- if (!this.get('effective_readonly') && this.$('textarea').length) {
- this.internal_set_value(
- instance.web.parse_value(
- this.$textarea.val(),
- this));
- }
+ this.internal_set_value(instance.web.parse_value(this.$textarea.val(), this));
},
render_value: function() {
- var show_value = instance.web.format_value(this.get('value'), this, '');
- if (show_value === '') {
- this.$textarea.css('height', parseInt(this.default_height)+"px");
- }
- this.$textarea.val(show_value);
- if (! this.auto_sized) {
- this.auto_sized = true;
- this.$textarea.autosize();
+ if (! this.get("effective_readonly")) {
+ var show_value = instance.web.format_value(this.get('value'), this, '');
+ if (show_value === '') {
+ this.$textarea.css('height', parseInt(this.default_height)+"px");
+ }
+ this.$textarea.val(show_value);
+ if (! this.auto_sized) {
+ this.auto_sized = true;
+ this.$textarea.autosize();
+ } else {
+ this.$textarea.trigger("autosize");
+ }
} else {
- this.$textarea.trigger("autosize");
+ var txt = this.get("value") || '';
+ this.$(".oe_form_text_content").text(txt);
}
},
is_syntax_valid: function() {
return this.get('value') === '' || this._super();
},
focus: function($el) {
- this.$textarea[0].focus();
+ var input = !this.get("effective_readonly") && this.$textarea && this.$textarea[0];
+ return input ? input.focus() : false;
},
set_dimensions: function (height, width) {
this._super(height, width);
- this.$textarea.css({
- width: width,
- minHeight: height
- });
+ if (!this.get("effective_readonly") && this.$textarea) {
+ this.$textarea.css({
+ width: width,
+ minHeight: height
+ });
+ }
},
});
if (! this.get("effective_readonly")) {
self._updating_editor = false;
this.$textarea = this.$el.find('textarea');
- var width = ((this.node.attrs || {}).editor_width || '100%');
+ var width = ((this.node.attrs || {}).editor_width || 'calc(100% - 4px)');
var height = ((this.node.attrs || {}).editor_height || 250);
this.$textarea.cleditor({
width: width, // width not including margins, borders or padding
"| removeformat | bullets numbering | outdent " +
"indent | link unlink | source",
bodyStyle: // style to assign to document body contained within the editor
- "margin:4px; color:#4c4c4c; font-size:13px; font-family:\"Lucida Grande\",Helvetica,Verdana,Arial,sans-serif; cursor:text"
+ "margin:4px; color:#4c4c4c; font-size:13px; font-family:'Lucida Grande',Helvetica,Verdana,Arial,sans-serif; cursor:text"
});
this.$cleditor = this.$textarea.cleditor()[0];
this.$cleditor.change(function() {
self.internal_set_value(self.$textarea.val());
}
});
+ if (this.field.translate) {
+ var $img = $('<img class="oe_field_translate oe_input_icon" src="/web/static/src/img/icons/terp-translate.png" width="16" height="16" border="0"/>')
+ .click(this.on_translate);
+ this.$cleditor.$toolbar.append($img);
+ }
}
},
render_value: function() {
this.$checkbox[0].checked = this.get('value');
},
focus: function() {
- this.$checkbox[0].focus();
+ var input = this.$checkbox && this.$checkbox[0];
+ return input ? input.focus() : false;
}
});
}
},
focus: function() {
- this.$('select:first')[0].focus();
+ var input = this.$('select:first')[0];
+ return input ? input.focus() : false;
},
set_dimensions: function (height, width) {
this._super(height, width);
values.push({
label: _t("Search More..."),
action: function() {
- dataset.name_search(search_val, self.build_domain(), 'ilike', false).done(function(data) {
+ dataset.name_search(search_val, self.build_domain(), 'ilike', 160).done(function(data) {
self._search_create_popup("search", data);
});
},
if (self.options.quick_create === undefined || self.options.quick_create) {
new instance.web.DataSet(this, this.field.relation, self.build_context())
.name_create(name).done(function(data) {
- self.add_id(data[0]);
+ if (!self.get('effective_readonly'))
+ self.add_id(data[0]);
}).fail(function(error, event) {
event.preventDefault();
slow_create();
e.stopPropagation();
}
},
- 'dragstart .oe_m2o_drop_down_button img': function () { return false; },
- 'dragstart .oe_m2o_cm_button': function () { return false; }
},
init: function(field_manager, node) {
this._super(field_manager, node);
this.floating = false;
this.current_display = null;
this.is_started = false;
+ this.ignore_focusout = false;
},
reinit_value: function(val) {
this.internal_set_value(val);
if (!this.get("effective_readonly"))
this.render_editable();
},
+ destroy_content: function () {
+ if (this.$drop_down) {
+ this.$drop_down.off('click');
+ delete this.$drop_down;
+ }
+ if (this.$input) {
+ this.$input.closest(".ui-dialog .ui-dialog-content").off('scroll');
+ this.$input.off('keyup blur autocompleteclose autocompleteopen ' +
+ 'focus focusout change keydown');
+ delete this.$input;
+ }
+ if (this.$follow_button) {
+ this.$follow_button.off('blur focus click');
+ delete this.$follow_button;
+ }
+ },
+ destroy: function () {
+ this.destroy_content();
+ return this._super();
+ },
init_error_displayer: function() {
// nothing
},
self.display_value = {};
self.render_value();
self.focus();
+ self.trigger('changed_value');
});
});
var ed_delay = 200;
var ed_duration = 15000;
var anyoneLoosesFocus = function (e) {
+ if (self.ignore_focusout) { return; }
var used = false;
if (self.floating) {
if (self.last_search.length > 0) {
// disabled to solve a bug, but may cause others
//close: anyoneLoosesFocus,
minLength: 0,
- delay: 0
+ delay: 250
});
this.$input.autocomplete("widget").openerpClass();
// used to correct a bug when selecting an element by pushing 'enter' in an editable list
}
if (! no_recurse) {
var dataset = new instance.web.DataSetStatic(this, this.field.relation, self.build_context());
- dataset.name_get([self.get("value")]).done(function(data) {
+ this.alive(dataset.name_get([self.get("value")])).done(function(data) {
+ if (!data[0]) {
+ self.do_warn(_t("Render"), _t("No value found for the field "+self.field.string+" for value "+self.get("value")));
+ return;
+ }
self.display_value["" + self.get("value")] = data[0][1];
self.render_value(true);
});
res_model: self.field.relation,
res_id: self.get("value"),
views: [[false, 'form']],
- target: 'current'
+ target: 'current',
+ context: self.build_context().eval(),
});
return false;
});
return ! this.get("value");
},
focus: function () {
- if (!this.get('effective_readonly')) {
- this.$input[0].focus();
- }
+ var input = !this.get('effective_readonly') && this.$input && this.$input[0];
+ return input ? input.focus() : false;
},
_quick_create: function() {
this.no_ed = true;
_search_create_popup: function() {
this.no_ed = true;
this.ed_def.reject();
- return instance.web.form.CompletionFieldMixin._search_create_popup.apply(this, arguments);
+ this.ignore_focusout = true;
+ this.reinit_value(false);
+ var res = instance.web.form.CompletionFieldMixin._search_create_popup.apply(this, arguments);
+ this.ignore_focusout = false;
+ this.no_ed = false;
+ return res;
},
set_dimensions: function (height, width) {
this._super(height, width);
- this.$input.css('height', height);
+ if (!this.get("effective_readonly") && this.$input)
+ this.$input.css('height', height);
}
});
};
instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({
multi_selection: false,
- disable_utility_classes: true,
init: function(field_manager, node) {
this._super(field_manager, node);
lazy_build_o2m_kanban_view();
_.extend(view.options, {
addable: null,
selectable: self.multi_selection,
- sortable: false,
+ sortable: true,
import_enabled: false,
deletable: true
});
}
return $.when(false);
},
+ is_false: function() {
+ return this.dataset.ids.length == 0;
+ },
is_syntax_valid: function() {
if (! this.viewmanager || ! this.viewmanager.views[this.viewmanager.active_view])
return true;
var pop = new instance.web.form.FormOpenPopup(this);
pop.show_element(self.o2m.field.relation, id, self.o2m.build_context(), {
title: _t("Open: ") + self.o2m.string,
- create_function: function(data) {
- return self.o2m.dataset.create(data).done(function(r) {
+ create_function: function(data, options) {
+ return self.o2m.dataset.create(data, options).done(function(r) {
self.o2m.dataset.set_ids(self.o2m.dataset.ids.concat([r]));
self.o2m.dataset.trigger("dataset_changed", r);
});
instance.web.form.One2ManyDataSet = instance.web.BufferedDataSet.extend({
get_context: function() {
this.context = this.o2m.build_context();
+ var self = this;
+ _.each(arguments, function(context) {
+ self.context.add(context);
+ });
return this.context;
}
});
GroupsType: instance.web.form.One2ManyGroups,
ListType: instance.web.form.One2ManyList
}));
- this.on('edit:before', this, this.proxy('_before_edit'));
this.on('edit:after', this, this.proxy('_after_edit'));
this.on('save:before cancel:before', this, this.proxy('_before_unedit'));
var ret = this._super();
this.$el
.off('mousedown.handleButtons')
- .on('mousedown.handleButtons', 'table button', this.proxy('_button_down'));
+ .on('mousedown.handleButtons', 'table button, div a.oe_m2o_cm_button', this.proxy('_button_down'));
return ret;
},
changed_records: function () {
this.o2m.trigger_on_change();
},
is_valid: function () {
- var form = this.editor.form;
-
- // If the form has not been modified, the view can only be valid
- // NB: is_dirty will also be set on defaults/onchanges/whatever?
- // oe_form_dirty seems to only be set on actual user actions
- if (!form.$el.is('.oe_form_dirty')) {
+ var self = this;
+ if (!this.fields_view || !this.editable()){
return true;
}
- this.o2m._dirty_flag = true;
-
- // Otherwise validate internal form
- return _(form.fields).chain()
- .invoke(function () {
- this._check_css_flags();
- return this.is_valid();
- })
- .all(_.identity)
- .value();
+ var r;
+ return _.every(this.records.records, function(record){
+ r = record;
+ _.each(self.editor.form.fields, function(field){
+ field._inhibit_on_change_flag = true;
+ field.set_value(r.attributes[field.name]);
+ field._inhibit_on_change_flag = false;
+ });
+ return _.every(self.editor.form.fields, function(field){
+ field.process_modifiers();
+ field._check_css_flags();
+ return field.is_valid();
+ });
+ });
},
do_add_record: function () {
if (this.editable()) {
title: _t("Create: ") + self.o2m.string,
initial_view: "form",
alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined,
- create_function: function(data, callback, error_callback) {
- return self.o2m.dataset.create(data).done(function(r) {
+ create_function: function(data, options) {
+ return self.o2m.dataset.create(data, options).done(function(r) {
self.o2m.dataset.set_ids(self.o2m.dataset.ids.concat([r]));
self.o2m.dataset.trigger("dataset_changed", r);
- }).done(callback).fail(error_callback);
+ });
},
read_function: function() {
return self.o2m.dataset.read_ids.apply(self.o2m.dataset, arguments);
else
return $.when();
}).done(function () {
- self.handle_button(name, id, callback);
+ var ds = self.o2m.dataset;
+ var cached_records = _.any([ds.to_create, ds.to_delete, ds.to_write], function(value) {
+ return value.length;
+ });
+ if (!self.o2m.options.reload_on_button && !cached_records) {
+ self.handle_button(name, id, callback);
+ }else {
+ self.handle_button(name, id, function(){
+ self.o2m.view.reload();
+ });
+ }
});
},
- _before_edit: function () {
+ _after_edit: function () {
this.__ignore_blur = false;
this.editor.form.on('blurred', this, this._on_form_blur);
- },
- _after_edit: function () {
+
// The form's blur thing may be jiggered during the edition setup,
// potentially leading to the o2m instasaving the row. Cancel any
// blurring triggered the edition startup here
}
this.cancel_edition();
},
- keyup_ENTER: function () {
+ keypress_ENTER: function () {
// blurring caused by hitting the [Return] key, should skip the
// autosave-on-blur and let the handler for [Return] do its thing (save
// the current row *anyway*, then create a new one/edit the next one)
} finally {
window.confirm = confirm;
}
+ },
+ reload_record: function (record) {
+ // Evict record.id from cache to ensure it will be reloaded correctly
+ this.dataset.evict_record(record.get('id'));
+
+ return this._super(record);
}
});
instance.web.form.One2ManyGroups = instance.web.ListView.Groups.extend({
if (this.get("effective_readonly"))
return;
var self = this;
+ var ignore_blur = false;
self.$text = this.$("textarea");
self.$text.textext({
plugins : 'tags arrow autocomplete',
ext: {
autocomplete: {
selectFromDropdown: function() {
- $(this).trigger('hideDropdown');
+ this.trigger('hideDropdown');
var index = Number(this.selectedSuggestionElement().children().children().data('index'));
var data = self.search_result[index];
if (data.id) {
self.add_id(data.id);
} else {
+ ignore_blur = true;
data.action();
}
+ this.trigger('setSuggestions', {result : []});
},
},
tags: {
self.$text
.focusin(function () {
self.trigger('focused');
+ ignore_blur = false;
})
.focusout(function() {
self.$text.trigger("setInputData", "");
- self.trigger('blurred');
+ if (!ignore_blur) {
+ self.trigger('blurred');
+ }
}).keydown(function(e) {
if (e.which === $.ui.keyCode.TAB && self._drop_shown) {
self.$text.textext()[0].autocomplete().selectFromDropdown();
}
};
if (! values || values.length > 0) {
- this._display_orderer.add(dataset.name_get(values)).done(handle_names);
+ return this._display_orderer.add(dataset.name_get(values)).done(handle_names);
} else {
handle_names([]);
}
this.set({'value': _.uniq(this.get('value').concat([id]))});
},
focus: function () {
- this.$text[0].focus();
+ var input = this.$text && this.$text[0];
+ return input ? input.focus() : false;
},
});
*/
instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend(instance.web.form.ReinitializeFieldMixin, {
multi_selection: false,
- disable_utility_classes: true,
init: function(field_manager, node) {
this._super(field_manager, node);
this.is_loaded = $.Deferred();
pop.select_element(
this.model,
{
- title: _t("Add: ") + this.m2m_field.string
+ title: _t("Add: ") + this.m2m_field.string,
+ no_create: this.m2m_field.options.no_create,
},
new instance.web.CompoundDomain(this.m2m_field.build_domain(), ["!", ["id", "in", this.m2m_field.dataset.ids]]),
this.m2m_field.build_context()
});
}
},
+ is_action_enabled: function () { return true; },
});
instance.web.form.FieldMany2ManyKanban = instance.web.form.AbstractField.extend(instance.web.form.CompletionFieldMixin, {
this.created_elements = [];
this.dataset = new instance.web.ProxyDataSet(this, this.model, this.context);
this.dataset.read_function = this.options.read_function;
- this.dataset.create_function = function(data, sup) {
+ this.dataset.create_function = function(data, options, sup) {
var fct = self.options.create_function || sup;
- return fct.call(this, data).done(function(r) {
+ return fct.call(this, data, options).done(function(r) {
self.trigger('create_completed saved', r);
self.created_elements.push(r);
});
this.searchview.on('search_data', self, function(domains, contexts, groupbys) {
if (self.initial_ids) {
self.do_search(domains.concat([[["id", "in", self.initial_ids]], self.domain]),
- contexts, groupbys);
+ contexts.concat(self.context), groupbys);
self.initial_ids = undefined;
} else {
self.do_search(domains.concat([self.domain]), contexts.concat(self.context), groupbys);
this.searchview.hide();
}
if (this.view_list) {
- this.view_list.$el.hide();
+ this.view_list.do_hide();
}
this.setup_form_view();
},
.on('blurred', null, function () {self.trigger('blurred')});
this.m2o = new instance.web.form.FieldMany2One(fm, { attrs: {
- name: 'm2o',
+ name: 'Referenced Document',
modifiers: JSON.stringify({readonly: this.get('effective_readonly')}),
}});
this.m2o.on("change:value", this, this.data_changed);
this._super.apply(this, arguments);
this.render_value();
this.set_filename('');
+ },
+ set_value: function(value_){
+ var changed = value_ !== this.get_value();
+ this._super.apply(this, arguments);
+ // By default, on binary images read, the server returns the binary size
+ // This is possible that two images have the exact same size
+ // Therefore we trigger the change in case the image value hasn't changed
+ // So the image is re-rendered correctly
+ if (!changed){
+ this.trigger("change:value", this, {
+ oldValue: value_,
+ newValue: value_
+ });
+ }
}
});
* Options on attribute ; "blockui" {Boolean} block the UI or not
* during the file is uploading
*/
-instance.web.form.FieldMany2ManyBinaryMultiFiles = instance.web.form.AbstractField.extend({
+instance.web.form.FieldMany2ManyBinaryMultiFiles = instance.web.form.AbstractField.extend(instance.web.form.ReinitializeFieldMixin, {
template: "FieldBinaryFileUploader",
init: function(field_manager, node) {
this._super(field_manager, node);
this.fileupload_id = _.uniqueId('oe_fileupload_temp');
$(window).on(this.fileupload_id, _.bind(this.on_file_loaded, this));
},
- start: function() {
- this._super(this);
+ initialize_content: function() {
this.$el.on('change', 'input.oe_form_binary_file', this.on_file_change );
},
set_value: function(value_) {
// TODO : activate send on wizard and form
if (result.error || !result.id ) {
- this.do_warn( _t('Uploading error'), result.error);
+ this.do_warn( _t('Uploading Error'), result.error);
files = _.filter(files, function (val) { return !val.upload; });
} else {
for(var i in files){
this.calc_domain();
this.on("change:value", this, this.get_selection);
this.on("change:evaluated_selection_domain", this, this.get_selection);
- this.get_selection();
this.on("change:selection", this, function() {
this.selection = this.get("selection");
this.render_value();
});
+ this.get_selection();
if (this.options.clickable) {
this.$el.on('click','li',this.on_click_stage);
}
- if (this.$el.parent().is('header')) {
- this.$el.after('<div class="oe_clear"/>');
- }
this._super();
},
set_value: function(value_) {
},
calc_domain: function() {
var d = instance.web.pyeval.eval('domain', this.build_domain());
- domain = ['|', ['id', '=', this.get('value')]].concat(d);
+ var domain = []; //if there is no domain defined, fetch all the records
+
+ if (d.length) {
+ domain = ['|',['id', '=', this.get('value')]].concat(d);
+ }
+
if (! _.isEqual(domain, this.get("evaluated_selection_domain"))) {
this.set("evaluated_selection_domain", domain);
}
on_click_stage: function (ev) {
var self = this;
var $li = $(ev.currentTarget);
- var val = parseInt($li.data("id"));
+ if (this.field.type == "many2one") {
+ var val = parseInt($li.data("id"));
+ }
+ else {
+ var val = $li.data("id");
+ }
if (val != self.get('value')) {
this.view.recursive_save().done(function() {
var change = {};
});
},
parse_value: function(val, def) {
- return instance.web.parse_value(val, {type: "float"}, def);
+ return instance.web.parse_value(val, {type: "float", digits: (this.node.attrs || {}).digits || this.field.digits}, def);
},
format_value: function(val, def) {
- return instance.web.format_value(val, {type: "float"}, def);
+ return instance.web.format_value(val, {type: "float", digits: (this.node.attrs || {}).digits || this.field.digits}, def);
},
});