2012-04-17 12:09:49 +00:00
|
|
|
|
openerp.web.form = function (instance) {
|
|
|
|
|
var _t = instance.web._t,
|
|
|
|
|
_lt = instance.web._lt;
|
|
|
|
|
var QWeb = instance.web.qweb;
|
2011-08-18 17:43:22 +00:00
|
|
|
|
|
2012-04-09 23:36:15 +00:00
|
|
|
|
/** @namespace */
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form = {};
|
2011-03-30 14:00:48 +00:00
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.views.add('form', 'instance.web.FormView');
|
|
|
|
|
instance.web.FormView = instance.web.View.extend({
|
2011-04-01 10:45:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* Indicates that this view is not searchable, and thus that no search
|
|
|
|
|
* view should be displayed (if there is one active).
|
|
|
|
|
*/
|
|
|
|
|
searchable: false,
|
2012-03-12 15:34:52 +00:00
|
|
|
|
template: "FormView",
|
2011-12-16 13:00:00 +00:00
|
|
|
|
display_name: _lt('Form'),
|
2012-04-05 16:03:15 +00:00
|
|
|
|
view_type: "form",
|
2011-04-01 10:45:00 +00:00
|
|
|
|
/**
|
2012-04-17 12:09:49 +00:00
|
|
|
|
* @constructs instance.web.FormView
|
|
|
|
|
* @extends instance.web.View
|
2011-10-19 12:50:34 +00:00
|
|
|
|
*
|
2012-04-17 12:09:49 +00:00
|
|
|
|
* @param {instance.web.Session} session the current openerp session
|
|
|
|
|
* @param {instance.web.DataSet} dataset the dataset this view will work with
|
2011-04-01 10:45:00 +00:00
|
|
|
|
* @param {String} view_id the identifier of the OpenERP view object
|
2011-12-21 17:16:02 +00:00
|
|
|
|
* @param {Object} options
|
|
|
|
|
* - resize_textareas : [true|false|max_height]
|
2011-06-03 09:43:02 +00:00
|
|
|
|
*
|
2012-04-17 12:09:49 +00:00
|
|
|
|
* @property {instance.web.Registry} registry=instance.web.form.widgets widgets registry for this form view instance
|
2011-04-01 10:45:00 +00:00
|
|
|
|
*/
|
2011-09-14 14:30:28 +00:00
|
|
|
|
init: function(parent, dataset, view_id, options) {
|
|
|
|
|
this._super(parent);
|
2011-08-08 17:32:30 +00:00
|
|
|
|
this.set_default_options(options);
|
2011-03-30 14:00:48 +00:00
|
|
|
|
this.dataset = dataset;
|
|
|
|
|
this.model = dataset.model;
|
2011-09-20 10:08:23 +00:00
|
|
|
|
this.view_id = view_id || false;
|
2011-04-04 15:06:19 +00:00
|
|
|
|
this.fields_view = {};
|
2011-03-30 14:00:48 +00:00
|
|
|
|
this.fields = {};
|
2011-12-01 15:50:29 +00:00
|
|
|
|
this.fields_order = [];
|
2011-04-05 15:14:40 +00:00
|
|
|
|
this.datarecord = {};
|
2011-06-20 18:25:49 +00:00
|
|
|
|
this.default_focus_field = null;
|
|
|
|
|
this.default_focus_button = null;
|
2012-04-17 12:09:49 +00:00
|
|
|
|
this.fields_registry = instance.web.form.widgets;
|
|
|
|
|
this.tags_registry = instance.web.form.tags;
|
2011-06-17 14:19:45 +00:00
|
|
|
|
this.has_been_loaded = $.Deferred();
|
2011-08-24 15:13:57 +00:00
|
|
|
|
this.translatable_fields = [];
|
2011-12-05 13:50:37 +00:00
|
|
|
|
_.defaults(this.options, {
|
2012-04-10 10:07:41 +00:00
|
|
|
|
"not_interactible_on_create": false,
|
|
|
|
|
"initial_mode": "view",
|
2011-12-05 13:50:37 +00:00
|
|
|
|
});
|
2012-01-10 14:41:13 +00:00
|
|
|
|
this.is_initialized = $.Deferred();
|
|
|
|
|
this.mutating_mutex = new $.Mutex();
|
2012-01-10 14:44:20 +00:00
|
|
|
|
this.on_change_mutex = new $.Mutex();
|
|
|
|
|
this.reload_mutex = new $.Mutex();
|
2012-04-17 12:09:49 +00:00
|
|
|
|
this.rendering_engine = new instance.web.form.FormRenderingEngineReadonly(this);
|
2012-04-16 14:45:42 +00:00
|
|
|
|
this.qweb = null; // A QWeb instance will be created if the view is a QWeb template
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2012-02-21 16:29:12 +00:00
|
|
|
|
destroy: function() {
|
2012-03-19 17:03:36 +00:00
|
|
|
|
_.each(this.get_widgets(), function(w) {
|
2012-02-21 16:29:12 +00:00
|
|
|
|
w.destroy();
|
2011-07-11 16:15:46 +00:00
|
|
|
|
});
|
2011-09-28 15:16:13 +00:00
|
|
|
|
this._super();
|
2011-07-11 16:15:46 +00:00
|
|
|
|
},
|
2011-03-30 14:00:48 +00:00
|
|
|
|
on_loaded: function(data) {
|
|
|
|
|
var self = this;
|
2012-02-07 12:05:39 +00:00
|
|
|
|
if (!data) {
|
2012-03-12 15:34:52 +00:00
|
|
|
|
throw new Error("No data provided.");
|
2012-02-07 13:01:25 +00:00
|
|
|
|
}
|
2012-03-12 15:34:52 +00:00
|
|
|
|
if (this.arch) {
|
|
|
|
|
throw "Form view does not support multiple calls to on_loaded";
|
2011-09-20 11:21:47 +00:00
|
|
|
|
}
|
2012-02-07 12:05:39 +00:00
|
|
|
|
this.fields_order = [];
|
|
|
|
|
this.fields_view = data;
|
|
|
|
|
|
2012-04-10 12:21:10 +00:00
|
|
|
|
this.rendering_engine.set_fields_registry(this.fields_registry);
|
|
|
|
|
this.rendering_engine.set_tags_registry(this.tags_registry);
|
2012-04-16 14:45:42 +00:00
|
|
|
|
if (!this.extract_qweb_template(data)) {
|
|
|
|
|
this.rendering_engine.set_fields_view(data);
|
|
|
|
|
var $dest = this.$element.hasClass("oe_form_container") ? this.$element : this.$element.find('.oe_form_container');
|
|
|
|
|
this.rendering_engine.render_to($dest);
|
|
|
|
|
}
|
2012-03-12 15:34:52 +00:00
|
|
|
|
|
2012-04-09 18:44:45 +00:00
|
|
|
|
this.$sidebar = this.options.$sidebar || this.$element.find('.oe_form_sidebar');
|
|
|
|
|
|
2012-04-10 13:55:37 +00:00
|
|
|
|
this.$buttons = $(QWeb.render("FormView.buttons", {'widget':self}));
|
2012-04-10 07:59:14 +00:00
|
|
|
|
if (this.options.$buttons) {
|
|
|
|
|
this.$buttons.appendTo(this.options.$buttons);
|
|
|
|
|
} else {
|
|
|
|
|
this.$element.find('.oe_form_buttons').replaceWith(this.$buttons);
|
|
|
|
|
}
|
2012-04-19 20:44:18 +00:00
|
|
|
|
this.$buttons.on('click','.oe_form_button_create',this.on_button_create);
|
|
|
|
|
this.$buttons.on('click','.oe_form_button_edit',this.on_button_edit);
|
|
|
|
|
this.$buttons.on('click','.oe_form_button_duplicate',this.on_button_duplicate);
|
|
|
|
|
this.$buttons.on('click','.oe_form_button_delete',this.on_button_delete);
|
|
|
|
|
this.$buttons.on('click','.oe_form_button_save',this.on_button_save);
|
|
|
|
|
this.$buttons.on('click','.oe_form_button_cancel',this.on_button_cancel);
|
2012-04-09 20:16:47 +00:00
|
|
|
|
|
2012-04-10 13:55:37 +00:00
|
|
|
|
this.$pager = $(QWeb.render("FormView.pager", {'widget':self}));
|
2012-04-10 11:26:56 +00:00
|
|
|
|
if (this.options.$pager) {
|
2012-04-10 12:19:21 +00:00
|
|
|
|
this.$pager.appendTo(this.options.$pager);
|
2012-04-10 11:26:56 +00:00
|
|
|
|
} else {
|
2012-04-10 12:19:21 +00:00
|
|
|
|
this.$element.find('.oe_form_pager').replaceWith(this.$pager);
|
2012-04-10 11:26:56 +00:00
|
|
|
|
}
|
|
|
|
|
this.$pager.on('click','a[data-pager-action]',function() {
|
2011-04-05 08:57:50 +00:00
|
|
|
|
var action = $(this).data('pager-action');
|
|
|
|
|
self.on_pager_action(action);
|
|
|
|
|
});
|
2011-04-05 14:34:25 +00:00
|
|
|
|
|
2012-04-18 14:24:39 +00:00
|
|
|
|
if (!this.sidebar && this.options.$sidebar) {
|
2012-04-17 12:09:49 +00:00
|
|
|
|
this.sidebar = new instance.web.Sidebar(this);
|
2012-04-09 18:44:45 +00:00
|
|
|
|
this.sidebar.appendTo(this.$sidebar);
|
2012-04-17 13:32:42 +00:00
|
|
|
|
if(this.fields_view.toolbar) {
|
|
|
|
|
this.sidebar.add_toolbar(this.fields_view.toolbar);
|
|
|
|
|
}
|
2012-04-09 18:44:45 +00:00
|
|
|
|
this.sidebar.add_items('other', [{
|
2012-02-08 12:21:53 +00:00
|
|
|
|
label: _t('Set Default'),
|
|
|
|
|
form: this,
|
|
|
|
|
callback: function (item) {
|
|
|
|
|
item.form.open_defaults_dialog();
|
|
|
|
|
}
|
|
|
|
|
}]);
|
2011-07-26 21:00:05 +00:00
|
|
|
|
}
|
2012-04-10 10:07:41 +00:00
|
|
|
|
this.on("change:mode", this, this.switch_mode);
|
2012-04-10 10:14:15 +00:00
|
|
|
|
this.set({mode: this.options.initial_mode});
|
2011-06-17 14:19:45 +00:00
|
|
|
|
this.has_been_loaded.resolve();
|
2012-04-05 16:03:15 +00:00
|
|
|
|
return $.when();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2012-04-16 14:45:42 +00:00
|
|
|
|
extract_qweb_template: function(fvg) {
|
|
|
|
|
for (var i=0, ii=fvg.arch.children.length; i < ii; i++) {
|
|
|
|
|
var child = fvg.arch.children[i];
|
|
|
|
|
if (child.tag === "templates") {
|
|
|
|
|
this.qweb = new QWeb2.Engine();
|
2012-04-17 12:09:49 +00:00
|
|
|
|
this.qweb.add_template(instance.web.json_node_to_xml(child));
|
2012-04-16 14:45:42 +00:00
|
|
|
|
if (!this.qweb.has_template('form')) {
|
|
|
|
|
throw new Error("No QWeb template found for form view");
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.qweb = null;
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
get_fvg_from_qweb: function(record) {
|
|
|
|
|
var view = this.qweb.render('form', this.get_qweb_context(record));
|
|
|
|
|
var fvg = _.clone(this.fields_view);
|
2012-04-17 12:09:49 +00:00
|
|
|
|
fvg.arch = instance.web.xml_to_json(instance.web.str_to_xml(view).firstChild);
|
2012-04-16 14:45:42 +00:00
|
|
|
|
return fvg;
|
|
|
|
|
},
|
|
|
|
|
get_qweb_context: function(record) {
|
|
|
|
|
var self = this,
|
|
|
|
|
new_record = {};
|
2012-04-17 14:32:27 +00:00
|
|
|
|
_.each(record, function(value_, name) {
|
2012-04-16 14:45:42 +00:00
|
|
|
|
var r = _.clone(self.fields_view.fields[name] || {});
|
2012-04-17 14:32:27 +00:00
|
|
|
|
if ((r.type === 'date' || r.type === 'datetime') && value_) {
|
|
|
|
|
r.raw_value = instance.web.auto_str_to_date(value_);
|
2012-04-16 14:45:42 +00:00
|
|
|
|
} else {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
r.raw_value = value_;
|
2012-04-16 14:45:42 +00:00
|
|
|
|
}
|
2012-04-17 14:32:27 +00:00
|
|
|
|
r.value = instance.web.format_value(value_, r);
|
2012-04-16 14:45:42 +00:00
|
|
|
|
new_record[name] = r;
|
|
|
|
|
});
|
|
|
|
|
return {
|
|
|
|
|
record : new_record,
|
|
|
|
|
new_record : !record.id
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
kill_current_form: function() {
|
|
|
|
|
_.each(this.getChildren(), function(el) {
|
|
|
|
|
el.destroy();
|
|
|
|
|
});
|
|
|
|
|
this.fields = {};
|
|
|
|
|
this.fields_order = [];
|
|
|
|
|
this.default_focus_field = null;
|
|
|
|
|
this.default_focus_button = null;
|
|
|
|
|
this.translatable_fields = [];
|
|
|
|
|
this.$element.find('.oe_form_container').empty();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2012-02-01 15:44:42 +00:00
|
|
|
|
do_load_state: function(state, warm) {
|
2011-12-15 14:29:39 +00:00
|
|
|
|
if (state.id && this.datarecord.id != state.id) {
|
2012-02-01 15:44:42 +00:00
|
|
|
|
if (!this.dataset.get_id_index(state.id)) {
|
2012-01-25 08:53:10 +00:00
|
|
|
|
this.dataset.ids.push(state.id);
|
2011-12-15 14:29:39 +00:00
|
|
|
|
}
|
2012-02-01 15:44:42 +00:00
|
|
|
|
this.dataset.select_id(state.id);
|
|
|
|
|
if (warm) {
|
|
|
|
|
this.do_show();
|
|
|
|
|
}
|
2011-12-15 14:29:39 +00:00
|
|
|
|
}
|
2011-10-26 14:42:18 +00:00
|
|
|
|
},
|
2011-04-06 21:10:37 +00:00
|
|
|
|
do_show: function () {
|
2012-01-04 17:01:18 +00:00
|
|
|
|
var self = this;
|
2012-04-09 19:35:09 +00:00
|
|
|
|
if (this.sidebar) {
|
|
|
|
|
this.sidebar.$element.show();
|
|
|
|
|
}
|
2012-04-09 19:43:33 +00:00
|
|
|
|
if (this.$buttons) {
|
2012-04-10 07:59:14 +00:00
|
|
|
|
this.$buttons.show();
|
2012-04-09 20:10:17 +00:00
|
|
|
|
this.$buttons.find('.oe_form_button_save').removeClass('oe_form_button_save_dirty');
|
2012-04-09 19:43:33 +00:00
|
|
|
|
}
|
|
|
|
|
if (this.$pager) {
|
2012-04-10 11:26:56 +00:00
|
|
|
|
this.$pager.show();
|
2012-04-09 19:43:33 +00:00
|
|
|
|
}
|
2012-01-10 12:54:13 +00:00
|
|
|
|
this.$element.show().css('visibility', 'hidden');
|
2012-02-15 12:39:01 +00:00
|
|
|
|
this.$element.removeClass('oe_form_dirty');
|
2012-01-04 17:01:18 +00:00
|
|
|
|
return this.has_been_loaded.pipe(function() {
|
|
|
|
|
var result;
|
2011-12-19 16:30:51 +00:00
|
|
|
|
if (self.dataset.index === null) {
|
|
|
|
|
// null index means we should start a new record
|
2012-01-04 17:01:18 +00:00
|
|
|
|
result = self.on_button_new();
|
2011-12-19 16:30:51 +00:00
|
|
|
|
} else {
|
2012-01-11 12:49:11 +00:00
|
|
|
|
result = self.dataset.read_index(_.keys(self.fields_view.fields), {
|
|
|
|
|
context : { 'bin_size' : true }
|
|
|
|
|
}).pipe(self.on_record_loaded);
|
2011-12-19 16:30:51 +00:00
|
|
|
|
}
|
2012-01-09 10:45:40 +00:00
|
|
|
|
result.pipe(function() {
|
2012-01-10 12:54:13 +00:00
|
|
|
|
self.$element.css('visibility', 'visible');
|
2012-01-09 10:45:40 +00:00
|
|
|
|
});
|
2012-01-04 17:01:18 +00:00
|
|
|
|
return result;
|
2011-12-19 16:30:51 +00:00
|
|
|
|
});
|
2011-04-06 21:10:37 +00:00
|
|
|
|
},
|
|
|
|
|
do_hide: function () {
|
2011-07-26 21:00:05 +00:00
|
|
|
|
if (this.sidebar) {
|
|
|
|
|
this.sidebar.$element.hide();
|
|
|
|
|
}
|
2012-04-09 20:53:34 +00:00
|
|
|
|
if (this.$buttons) {
|
2012-04-10 07:59:14 +00:00
|
|
|
|
this.$buttons.hide();
|
2012-04-09 20:53:34 +00:00
|
|
|
|
}
|
|
|
|
|
if (this.$pager) {
|
2012-04-10 11:26:56 +00:00
|
|
|
|
this.$pager.hide();
|
2012-04-09 20:53:34 +00:00
|
|
|
|
}
|
2011-12-14 17:18:11 +00:00
|
|
|
|
this._super();
|
2011-04-06 21:10:37 +00:00
|
|
|
|
},
|
2011-03-30 14:00:48 +00:00
|
|
|
|
on_record_loaded: function(record) {
|
2011-12-13 15:33:43 +00:00
|
|
|
|
var self = this, set_values = [];
|
2011-06-23 15:55:09 +00:00
|
|
|
|
if (!record) {
|
2012-02-13 12:38:05 +00:00
|
|
|
|
this.do_warn("Form", "The record could not be found in the database.", true);
|
|
|
|
|
return $.Deferred().reject();
|
2011-06-23 15:55:09 +00:00
|
|
|
|
}
|
|
|
|
|
this.datarecord = record;
|
2011-11-17 16:00:09 +00:00
|
|
|
|
|
2012-04-16 14:45:42 +00:00
|
|
|
|
if (this.qweb) {
|
|
|
|
|
this.kill_current_form();
|
|
|
|
|
this.rendering_engine.set_fields_view(this.get_fvg_from_qweb(record));
|
|
|
|
|
var $dest = this.$element.hasClass("oe_form_container") ? this.$element : this.$element.find('.oe_form_container');
|
|
|
|
|
this.rendering_engine.render_to($dest);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-17 16:00:09 +00:00
|
|
|
|
_(this.fields).each(function (field, f) {
|
2012-04-18 11:50:04 +00:00
|
|
|
|
field._dirty_flag = false;
|
2011-11-17 16:00:09 +00:00
|
|
|
|
var result = field.set_value(self.datarecord[f] || false);
|
2011-12-13 15:33:43 +00:00
|
|
|
|
set_values.push(result);
|
2011-11-17 16:00:09 +00:00
|
|
|
|
});
|
2012-01-04 17:01:18 +00:00
|
|
|
|
return $.when.apply(null, set_values).pipe(function() {
|
2011-11-17 12:43:19 +00:00
|
|
|
|
if (!record.id) {
|
2011-12-01 15:50:29 +00:00
|
|
|
|
// New record: Second pass in order to trigger the onchanges
|
|
|
|
|
// respecting the fields order defined in the view
|
|
|
|
|
_.each(self.fields_order, function(field_name) {
|
|
|
|
|
if (record[field_name] !== undefined) {
|
|
|
|
|
var field = self.fields[field_name];
|
2012-04-18 11:50:04 +00:00
|
|
|
|
field._dirty_flag = true;
|
2011-11-17 12:43:19 +00:00
|
|
|
|
self.do_onchange(field);
|
|
|
|
|
}
|
2011-12-01 15:50:29 +00:00
|
|
|
|
});
|
2011-04-07 13:07:25 +00:00
|
|
|
|
}
|
2011-11-17 12:43:19 +00:00
|
|
|
|
self.on_form_changed();
|
2012-01-10 14:41:13 +00:00
|
|
|
|
self.is_initialized.resolve();
|
2011-11-17 12:43:19 +00:00
|
|
|
|
self.do_update_pager(record.id == null);
|
|
|
|
|
if (self.sidebar) {
|
2012-04-17 01:19:33 +00:00
|
|
|
|
self.sidebar.do_attachement_update(self.dataset, self.datarecord.id);
|
2011-11-17 12:43:19 +00:00
|
|
|
|
}
|
2012-03-05 17:20:21 +00:00
|
|
|
|
if (self.default_focus_field) {
|
2011-11-17 12:43:19 +00:00
|
|
|
|
self.default_focus_field.focus();
|
|
|
|
|
}
|
2011-12-14 16:09:58 +00:00
|
|
|
|
if (record.id) {
|
|
|
|
|
self.do_push_state({id:record.id});
|
|
|
|
|
}
|
2012-01-30 14:07:25 +00:00
|
|
|
|
self.$element.removeClass('oe_form_dirty');
|
2012-04-09 20:10:17 +00:00
|
|
|
|
self.$buttons.find('.oe_form_button_save').removeClass('oe_form_button_save_dirty');
|
2011-11-17 12:43:19 +00:00
|
|
|
|
});
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2012-02-15 10:34:05 +00:00
|
|
|
|
on_form_changed: function() {
|
2012-03-26 14:41:29 +00:00
|
|
|
|
this.trigger("view_content_has_changed");
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2012-02-15 10:34:05 +00:00
|
|
|
|
do_notify_change: function() {
|
|
|
|
|
this.$element.addClass('oe_form_dirty');
|
2012-04-09 20:10:17 +00:00
|
|
|
|
this.$buttons.find('.oe_form_button_save').addClass('oe_form_button_save_dirty');
|
2012-02-15 10:34:05 +00:00
|
|
|
|
},
|
2011-04-06 21:10:37 +00:00
|
|
|
|
on_pager_action: function(action) {
|
2011-09-14 21:09:02 +00:00
|
|
|
|
if (this.can_be_discarded()) {
|
|
|
|
|
switch (action) {
|
|
|
|
|
case 'first':
|
|
|
|
|
this.dataset.index = 0;
|
|
|
|
|
break;
|
|
|
|
|
case 'previous':
|
|
|
|
|
this.dataset.previous();
|
|
|
|
|
break;
|
|
|
|
|
case 'next':
|
|
|
|
|
this.dataset.next();
|
|
|
|
|
break;
|
|
|
|
|
case 'last':
|
|
|
|
|
this.dataset.index = this.dataset.ids.length - 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
this.reload();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
2011-04-06 21:10:37 +00:00
|
|
|
|
},
|
2011-04-11 11:55:07 +00:00
|
|
|
|
do_update_pager: function(hide_index) {
|
|
|
|
|
var index = hide_index ? '-' : this.dataset.index + 1;
|
2012-04-10 11:26:56 +00:00
|
|
|
|
this.$pager.find('button').prop('disabled', this.dataset.ids.length < 2).end()
|
|
|
|
|
.find('span.oe_pager_index').html(index).end()
|
|
|
|
|
.find('span.oe_pager_count').html(this.dataset.ids.length);
|
2011-04-06 21:10:37 +00:00
|
|
|
|
},
|
2011-11-21 12:04:13 +00:00
|
|
|
|
parse_on_change: function (on_change, widget) {
|
|
|
|
|
var self = this;
|
|
|
|
|
var onchange = _.str.trim(on_change);
|
|
|
|
|
var call = onchange.match(/^\s?(.*?)\((.*?)\)\s?$/);
|
|
|
|
|
if (!call) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-21 12:45:32 +00:00
|
|
|
|
var method = call[1];
|
2011-11-21 12:28:45 +00:00
|
|
|
|
if (!_.str.trim(call[2])) {
|
2011-11-21 12:45:32 +00:00
|
|
|
|
return {method: method, args: [], context_index: null}
|
2011-11-21 12:28:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-21 12:04:13 +00:00
|
|
|
|
var argument_replacement = {
|
|
|
|
|
'False': function () {return false;},
|
|
|
|
|
'True': function () {return true;},
|
|
|
|
|
'None': function () {return null;},
|
|
|
|
|
'context': function (i) {
|
|
|
|
|
context_index = i;
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var ctx = new instance.web.CompoundContext(self.dataset.get_context(), widget.build_context() ? widget.build_context() : {});
|
2011-11-21 12:04:13 +00:00
|
|
|
|
return ctx;
|
|
|
|
|
}
|
|
|
|
|
};
|
2011-11-21 12:45:32 +00:00
|
|
|
|
var parent_fields = null, context_index = null;
|
|
|
|
|
var args = _.map(call[2].split(','), function (a, i) {
|
2011-11-21 12:04:13 +00:00
|
|
|
|
var field = _.str.trim(a);
|
2011-11-21 12:41:45 +00:00
|
|
|
|
|
|
|
|
|
// literal constant or context
|
2011-11-21 12:04:13 +00:00
|
|
|
|
if (field in argument_replacement) {
|
2011-11-21 12:45:32 +00:00
|
|
|
|
return argument_replacement[field](i);
|
2011-11-21 12:41:45 +00:00
|
|
|
|
}
|
2011-11-22 12:43:53 +00:00
|
|
|
|
// literal number
|
|
|
|
|
if (/^-?\d+(\.\d+)?$/.test(field)) {
|
|
|
|
|
return Number(field);
|
|
|
|
|
}
|
2011-11-21 12:41:45 +00:00
|
|
|
|
// form field
|
|
|
|
|
if (self.fields[field]) {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
var value_ = self.fields[field].get_value();
|
|
|
|
|
return value_ == null ? false : value_;
|
2011-11-21 12:41:45 +00:00
|
|
|
|
}
|
|
|
|
|
// parent field
|
|
|
|
|
var splitted = field.split('.');
|
|
|
|
|
if (splitted.length > 1 && _.str.trim(splitted[0]) === "parent" && self.dataset.parent_view) {
|
|
|
|
|
if (parent_fields === null) {
|
2011-12-19 17:30:55 +00:00
|
|
|
|
parent_fields = self.dataset.parent_view.get_fields_values([self.dataset.child_name]);
|
2011-11-21 12:04:13 +00:00
|
|
|
|
}
|
2011-11-21 12:41:45 +00:00
|
|
|
|
var p_val = parent_fields[_.str.trim(splitted[1])];
|
|
|
|
|
if (p_val !== undefined) {
|
2011-11-21 12:45:32 +00:00
|
|
|
|
return p_val == null ? false : p_val;
|
2011-11-21 12:41:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// string literal
|
|
|
|
|
var first_char = field[0], last_char = field[field.length-1];
|
|
|
|
|
if ((first_char === '"' && last_char === '"')
|
|
|
|
|
|| (first_char === "'" && last_char === "'")) {
|
2011-11-21 12:45:32 +00:00
|
|
|
|
return field.slice(1, -1);
|
2011-11-21 12:04:13 +00:00
|
|
|
|
}
|
2011-11-21 12:41:45 +00:00
|
|
|
|
|
2011-11-21 12:05:09 +00:00
|
|
|
|
throw new Error("Could not get field with name '" + field +
|
|
|
|
|
"' for onchange '" + onchange + "'");
|
2011-11-21 12:04:13 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
method: method,
|
|
|
|
|
args: args,
|
|
|
|
|
context_index: context_index
|
|
|
|
|
};
|
|
|
|
|
},
|
2011-04-07 17:09:29 +00:00
|
|
|
|
do_onchange: function(widget, processed) {
|
2011-10-12 15:08:30 +00:00
|
|
|
|
var self = this;
|
2012-01-10 14:47:09 +00:00
|
|
|
|
return this.on_change_mutex.exec(function() {
|
2011-10-12 15:08:30 +00:00
|
|
|
|
try {
|
2012-02-07 16:01:58 +00:00
|
|
|
|
var response = {}, can_process_onchange = $.Deferred();
|
2011-11-21 12:04:13 +00:00
|
|
|
|
processed = processed || [];
|
2012-02-07 16:17:33 +00:00
|
|
|
|
processed.push(widget.name);
|
2011-11-21 12:04:13 +00:00
|
|
|
|
var on_change = widget.node.attrs.on_change;
|
|
|
|
|
if (on_change) {
|
|
|
|
|
var change_spec = self.parse_on_change(on_change, widget);
|
|
|
|
|
if (change_spec) {
|
|
|
|
|
var ajax = {
|
2012-01-20 10:56:08 +00:00
|
|
|
|
url: '/web/dataset/onchange',
|
2011-11-21 12:04:13 +00:00
|
|
|
|
async: false
|
|
|
|
|
};
|
2012-02-07 16:01:58 +00:00
|
|
|
|
can_process_onchange = self.rpc(ajax, {
|
2011-11-21 12:04:13 +00:00
|
|
|
|
model: self.dataset.model,
|
|
|
|
|
method: change_spec.method,
|
|
|
|
|
args: [(self.datarecord.id == null ? [] : [self.datarecord.id])].concat(change_spec.args),
|
|
|
|
|
context_id: change_spec.context_index == undefined ? null : change_spec.context_index + 1
|
2012-02-07 16:01:58 +00:00
|
|
|
|
}).then(function(r) {
|
|
|
|
|
_.extend(response, r);
|
2011-11-21 12:04:13 +00:00
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
console.warn("Wrong on_change format", on_change);
|
|
|
|
|
}
|
2011-10-12 15:08:30 +00:00
|
|
|
|
}
|
2012-02-07 16:01:58 +00:00
|
|
|
|
// fail if onchange failed
|
|
|
|
|
if (can_process_onchange.isRejected()) {
|
|
|
|
|
return can_process_onchange;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (widget.field['change_default']) {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
var fieldname = widget.name, value_;
|
2012-02-07 16:01:58 +00:00
|
|
|
|
if (response.value && (fieldname in response.value)) {
|
|
|
|
|
// Use value from onchange if onchange executed
|
2012-04-17 14:32:27 +00:00
|
|
|
|
value_ = response.value[fieldname];
|
2012-02-07 16:01:58 +00:00
|
|
|
|
} else {
|
|
|
|
|
// otherwise get form value for field
|
2012-04-17 14:32:27 +00:00
|
|
|
|
value_ = self.fields[fieldname].get_value();
|
2012-02-07 16:01:58 +00:00
|
|
|
|
}
|
2012-04-17 14:32:27 +00:00
|
|
|
|
var condition = fieldname + '=' + value_;
|
2012-02-07 16:01:58 +00:00
|
|
|
|
|
2012-04-17 14:32:27 +00:00
|
|
|
|
if (value_) {
|
2012-02-07 16:01:58 +00:00
|
|
|
|
can_process_onchange = self.rpc({
|
|
|
|
|
url: '/web/dataset/call',
|
|
|
|
|
async: false
|
|
|
|
|
}, {
|
|
|
|
|
model: 'ir.values',
|
|
|
|
|
method: 'get_defaults',
|
|
|
|
|
args: [self.model, condition]
|
|
|
|
|
}).then(function (results) {
|
|
|
|
|
if (!results.length) { return; }
|
|
|
|
|
if (!response.value) {
|
|
|
|
|
response.value = {};
|
|
|
|
|
}
|
|
|
|
|
for(var i=0; i<results.length; ++i) {
|
|
|
|
|
// [whatever, key, value]
|
|
|
|
|
var triplet = results[i];
|
|
|
|
|
response.value[triplet[1]] = triplet[2];
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (can_process_onchange.isRejected()) {
|
|
|
|
|
return can_process_onchange;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self.on_processed_onchange(response, processed);
|
2011-10-12 15:08:30 +00:00
|
|
|
|
} catch(e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
return $.Deferred().reject();
|
|
|
|
|
}
|
2012-01-10 14:47:09 +00:00
|
|
|
|
});
|
2011-04-06 14:51:13 +00:00
|
|
|
|
},
|
2011-04-07 17:09:29 +00:00
|
|
|
|
on_processed_onchange: function(response, processed) {
|
2011-10-12 15:08:30 +00:00
|
|
|
|
try {
|
2011-07-15 09:55:27 +00:00
|
|
|
|
var result = response;
|
2011-04-06 14:51:13 +00:00
|
|
|
|
if (result.value) {
|
|
|
|
|
for (var f in result.value) {
|
2012-01-20 10:56:08 +00:00
|
|
|
|
if (!result.value.hasOwnProperty(f)) { continue; }
|
2011-04-06 14:51:13 +00:00
|
|
|
|
var field = this.fields[f];
|
2011-07-14 13:18:49 +00:00
|
|
|
|
// If field is not defined in the view, just ignore it
|
2011-04-06 14:51:13 +00:00
|
|
|
|
if (field) {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
var value_ = result.value[f];
|
|
|
|
|
if (field.get_value() != value_) {
|
|
|
|
|
field.set_value(value_);
|
2012-04-18 11:50:04 +00:00
|
|
|
|
field._dirty_flag = true;
|
2012-02-07 16:17:33 +00:00
|
|
|
|
if (!_.contains(processed, field.name)) {
|
2011-04-07 17:09:29 +00:00
|
|
|
|
this.do_onchange(field, processed);
|
|
|
|
|
}
|
2011-04-06 14:51:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-07 17:09:29 +00:00
|
|
|
|
this.on_form_changed();
|
2011-04-06 14:51:13 +00:00
|
|
|
|
}
|
2011-07-06 08:32:14 +00:00
|
|
|
|
if (!_.isEmpty(result.warning)) {
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.dialog($(QWeb.render("CrashManagerWarning", result.warning)), {
|
2011-04-06 14:51:13 +00:00
|
|
|
|
modal: true,
|
2011-12-15 10:40:31 +00:00
|
|
|
|
buttons: [
|
|
|
|
|
{text: _t("Ok"), click: function() { $(this).dialog("close"); }}
|
|
|
|
|
]
|
2011-04-06 14:51:13 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (result.domain) {
|
2012-01-20 10:56:08 +00:00
|
|
|
|
function edit_domain(node) {
|
|
|
|
|
var new_domain = result.domain[node.attrs.name];
|
|
|
|
|
if (new_domain) {
|
|
|
|
|
node.attrs.domain = new_domain;
|
|
|
|
|
}
|
|
|
|
|
_(node.children).each(edit_domain);
|
|
|
|
|
}
|
|
|
|
|
edit_domain(this.fields_view.arch);
|
2011-04-06 14:51:13 +00:00
|
|
|
|
}
|
2011-10-12 15:08:30 +00:00
|
|
|
|
return $.Deferred().resolve();
|
|
|
|
|
} catch(e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
return $.Deferred().reject();
|
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2012-04-10 10:07:41 +00:00
|
|
|
|
switch_mode: function() {
|
2012-04-09 21:30:43 +00:00
|
|
|
|
var self = this;
|
2012-04-19 15:55:14 +00:00
|
|
|
|
if(this.get("mode") == "view") {
|
2012-04-09 21:30:43 +00:00
|
|
|
|
self.$buttons.find('.oe_form_buttons_edit').hide();
|
|
|
|
|
self.$buttons.find('.oe_form_buttons_view').show();
|
|
|
|
|
_.each(this.fields,function(field){
|
|
|
|
|
field.set({"force_readonly": true});
|
|
|
|
|
});
|
2012-04-09 23:36:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
self.$buttons.find('.oe_form_buttons_edit').show();
|
|
|
|
|
self.$buttons.find('.oe_form_buttons_view').hide();
|
|
|
|
|
_.each(this.fields,function(field){
|
|
|
|
|
field.set({"force_readonly": false});
|
|
|
|
|
});
|
2012-04-09 21:30:43 +00:00
|
|
|
|
}
|
2012-04-09 20:53:34 +00:00
|
|
|
|
},
|
2011-11-09 15:12:39 +00:00
|
|
|
|
on_button_save: function() {
|
2011-04-07 13:07:25 +00:00
|
|
|
|
var self = this;
|
2011-12-07 15:31:01 +00:00
|
|
|
|
return this.do_save().then(function(result) {
|
2012-04-10 10:07:41 +00:00
|
|
|
|
self.set({mode: "view"});
|
2011-04-07 13:07:25 +00:00
|
|
|
|
});
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2012-04-19 20:44:18 +00:00
|
|
|
|
on_button_cancel: function(event) {
|
2012-02-15 12:39:01 +00:00
|
|
|
|
if (this.can_be_discarded()) {
|
2012-04-10 10:07:41 +00:00
|
|
|
|
this.set({mode: "view"});
|
2012-02-15 12:39:01 +00:00
|
|
|
|
}
|
2012-04-19 20:44:18 +00:00
|
|
|
|
return false;
|
2011-11-07 13:45:39 +00:00
|
|
|
|
},
|
2011-12-01 12:22:33 +00:00
|
|
|
|
on_button_new: function() {
|
2011-11-07 13:45:39 +00:00
|
|
|
|
var self = this;
|
2012-04-10 10:18:33 +00:00
|
|
|
|
this.set({mode: "edit"});
|
2011-11-07 13:45:39 +00:00
|
|
|
|
var def = $.Deferred();
|
|
|
|
|
$.when(this.has_been_loaded).then(function() {
|
2011-09-15 08:12:41 +00:00
|
|
|
|
if (self.can_be_discarded()) {
|
2011-12-01 12:22:33 +00:00
|
|
|
|
var keys = _.keys(self.fields_view.fields);
|
|
|
|
|
if (keys.length) {
|
|
|
|
|
self.dataset.default_get(keys).pipe(self.on_record_loaded).then(function() {
|
2011-11-10 10:36:50 +00:00
|
|
|
|
def.resolve();
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2011-12-01 12:22:33 +00:00
|
|
|
|
self.on_record_loaded({}).then(function() {
|
|
|
|
|
def.resolve();
|
|
|
|
|
});
|
2011-11-10 10:36:50 +00:00
|
|
|
|
}
|
2011-09-15 08:12:41 +00:00
|
|
|
|
}
|
2011-04-07 13:07:25 +00:00
|
|
|
|
});
|
2011-07-18 15:28:07 +00:00
|
|
|
|
return def.promise();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2012-04-09 20:53:34 +00:00
|
|
|
|
on_button_edit: function() {
|
2012-04-10 10:07:41 +00:00
|
|
|
|
return this.set({mode: "edit"});
|
2012-04-09 20:53:34 +00:00
|
|
|
|
},
|
|
|
|
|
on_button_create: function() {
|
|
|
|
|
this.dataset.index = null;
|
2012-04-09 23:36:15 +00:00
|
|
|
|
this.do_show();
|
2012-04-09 20:53:34 +00:00
|
|
|
|
},
|
|
|
|
|
on_button_duplicate: function() {
|
|
|
|
|
var self = this;
|
|
|
|
|
var def = $.Deferred();
|
|
|
|
|
$.when(this.has_been_loaded).then(function() {
|
|
|
|
|
self.dataset.call('copy', [self.datarecord.id, {}, self.dataset.context]).then(function(new_id) {
|
|
|
|
|
return self.on_created({ result : new_id });
|
|
|
|
|
}).then(function() {
|
2012-04-10 10:07:41 +00:00
|
|
|
|
return self.set({mode: "edit"});
|
2012-04-09 20:53:34 +00:00
|
|
|
|
}).then(function() {
|
|
|
|
|
def.resolve();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
return def.promise();
|
|
|
|
|
},
|
|
|
|
|
on_button_delete: function() {
|
|
|
|
|
var self = this;
|
|
|
|
|
var def = $.Deferred();
|
|
|
|
|
$.when(this.has_been_loaded).then(function() {
|
|
|
|
|
if (self.datarecord.id && confirm(_t("Do you really want to delete this record?"))) {
|
|
|
|
|
self.dataset.unlink([self.datarecord.id]).then(function() {
|
|
|
|
|
self.on_pager_action('next');
|
|
|
|
|
def.resolve();
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
$.async_when().then(function () {
|
|
|
|
|
def.reject();
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return def.promise();
|
|
|
|
|
},
|
2011-09-14 21:09:02 +00:00
|
|
|
|
can_be_discarded: function() {
|
2012-02-15 10:56:28 +00:00
|
|
|
|
return !this.$element.is('.oe_form_dirty') || confirm(_t("Warning, the record has been modified, your changes will be discarded."));
|
2011-09-14 21:09:02 +00:00
|
|
|
|
},
|
2011-06-06 13:11:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* Triggers saving the form's record. Chooses between creating a new
|
|
|
|
|
* record or saving an existing one depending on whether the record
|
|
|
|
|
* already has an id property.
|
|
|
|
|
*
|
|
|
|
|
* @param {Function} success callback on save success
|
|
|
|
|
* @param {Boolean} [prepend_on_create=false] if ``do_save`` creates a new record, should that record be inserted at the start of the dataset (by default, records are added at the end)
|
|
|
|
|
*/
|
|
|
|
|
do_save: function(success, prepend_on_create) {
|
2011-04-11 11:35:16 +00:00
|
|
|
|
var self = this;
|
2012-01-10 14:47:09 +00:00
|
|
|
|
return this.mutating_mutex.exec(function() { return self.is_initialized.pipe(function() {
|
2011-10-12 14:10:07 +00:00
|
|
|
|
try {
|
2011-11-15 14:58:06 +00:00
|
|
|
|
var form_invalid = false,
|
2011-10-11 15:35:35 +00:00
|
|
|
|
values = {},
|
|
|
|
|
first_invalid_field = null;
|
|
|
|
|
for (var f in self.fields) {
|
|
|
|
|
f = self.fields[f];
|
|
|
|
|
if (!f.is_valid()) {
|
|
|
|
|
form_invalid = true;
|
|
|
|
|
if (!first_invalid_field) {
|
|
|
|
|
first_invalid_field = f;
|
|
|
|
|
}
|
2012-04-18 11:50:04 +00:00
|
|
|
|
} else if (f.name !== 'id' && !f.get("readonly") && (!self.datarecord.id || f._dirty_flag)) {
|
2011-11-21 12:40:30 +00:00
|
|
|
|
// Special case 'id' field, do not save this field
|
|
|
|
|
// on 'create' : save all non readonly fields
|
|
|
|
|
// on 'edit' : save non readonly modified fields
|
2011-10-11 15:35:35 +00:00
|
|
|
|
values[f.name] = f.get_value();
|
2011-06-22 12:25:42 +00:00
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
2011-10-11 15:35:35 +00:00
|
|
|
|
if (form_invalid) {
|
2012-04-18 12:20:39 +00:00
|
|
|
|
self.set({'display_invalid_fields': true});
|
2011-10-11 15:35:35 +00:00
|
|
|
|
first_invalid_field.focus();
|
|
|
|
|
self.on_invalid();
|
|
|
|
|
return $.Deferred().reject();
|
2011-04-11 11:35:16 +00:00
|
|
|
|
} else {
|
2012-04-18 12:20:39 +00:00
|
|
|
|
self.set({'display_invalid_fields': false});
|
2011-12-08 12:38:46 +00:00
|
|
|
|
var save_deferral;
|
2011-10-11 15:35:35 +00:00
|
|
|
|
if (!self.datarecord.id) {
|
2012-01-12 12:44:56 +00:00
|
|
|
|
//console.log("FormView(", self, ") : About to create", values);
|
2011-12-08 12:38:46 +00:00
|
|
|
|
save_deferral = self.dataset.create(values).pipe(function(r) {
|
2011-10-11 15:35:35 +00:00
|
|
|
|
return self.on_created(r, undefined, prepend_on_create);
|
2011-12-08 12:38:46 +00:00
|
|
|
|
}, null);
|
2012-04-18 15:18:44 +00:00
|
|
|
|
} else if (_.isEmpty(values) && ! self.force_dirty) {
|
2012-01-12 12:44:56 +00:00
|
|
|
|
//console.log("FormView(", self, ") : Nothing to save");
|
2011-12-08 12:38:46 +00:00
|
|
|
|
save_deferral = $.Deferred().resolve({}).promise();
|
2011-10-11 15:35:35 +00:00
|
|
|
|
} else {
|
2012-04-18 15:18:44 +00:00
|
|
|
|
self.force_dirty = false;
|
2012-01-12 12:44:56 +00:00
|
|
|
|
//console.log("FormView(", self, ") : About to save", values);
|
2011-12-08 12:38:46 +00:00
|
|
|
|
save_deferral = self.dataset.write(self.datarecord.id, values, {}).pipe(function(r) {
|
2011-10-11 15:35:35 +00:00
|
|
|
|
return self.on_saved(r);
|
2011-12-08 12:38:46 +00:00
|
|
|
|
}, null);
|
2011-10-11 15:35:35 +00:00
|
|
|
|
}
|
2011-12-08 12:38:46 +00:00
|
|
|
|
return save_deferral.then(success);
|
2011-04-11 11:35:16 +00:00
|
|
|
|
}
|
2011-10-12 14:10:07 +00:00
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
return $.Deferred().reject();
|
|
|
|
|
}
|
2012-01-10 14:47:09 +00:00
|
|
|
|
});});
|
2011-04-05 14:34:25 +00:00
|
|
|
|
},
|
2011-03-30 14:00:48 +00:00
|
|
|
|
on_invalid: function() {
|
2011-04-05 17:35:12 +00:00
|
|
|
|
var msg = "<ul>";
|
|
|
|
|
_.each(this.fields, function(f) {
|
2011-07-27 10:25:19 +00:00
|
|
|
|
if (!f.is_valid()) {
|
2012-03-14 17:09:49 +00:00
|
|
|
|
msg += "<li>" + f.node.attrs.string + "</li>";
|
2011-04-05 17:35:12 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
msg += "</ul>";
|
2011-10-13 10:26:53 +00:00
|
|
|
|
this.do_warn("The following fields are invalid :", msg);
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2011-04-11 15:59:46 +00:00
|
|
|
|
on_saved: function(r, success) {
|
2011-04-05 15:14:40 +00:00
|
|
|
|
if (!r.result) {
|
2011-09-12 14:07:53 +00:00
|
|
|
|
// should not happen in the server, but may happen for internal purpose
|
2011-09-26 12:39:29 +00:00
|
|
|
|
return $.Deferred().reject();
|
2011-04-05 15:53:48 +00:00
|
|
|
|
} else {
|
[FIX] synchronization of o2m widget saving, avoid race condition when clicking on button of unsaved record
After saving, the formview would both refresh the form and lauch the
action itself, which launches a refresh of its own.
Issue is that o2m's filling of themselves (a read) is async and
triggered by the set_value on the o2m field, so the second reload of
the form would be interspersed (between the first reload and the end
of the o2ms loading), resulting in corrupted state for the o2ms if the
button's action somehow changed the contents of the o2m (it would
remove the old records and return brand new ids during the refresh):
the set_value on the o2m would empty the o2m's dataset cache, and the
returning fetch request would try to find in cache values removed from
it, or something, blowing up everything.
Anyway, this was fixed by ensuring the button action is only executed
after the form is completely done doing its post-save reload (using
the new async set_value). This is a tiny bit brittle in that onchanges
are synchronous but call set_value, so a set_value on an o2m from an
onchange may have issues. It also increases the flicker of the view,
as the o2m is reloaded twice in quick succession.
lp bug: https://launchpad.net/bugs/885658 fixed
bzr revid: xmo@openerp.com-20111117161426-72jzhvv3dm387uom
2011-11-17 16:14:26 +00:00
|
|
|
|
return $.when(this.reload()).pipe(function () {
|
|
|
|
|
return $.when(r).then(success); }, null);
|
2011-04-11 15:59:46 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2011-06-06 13:11:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* Updates the form' dataset to contain the new record:
|
|
|
|
|
*
|
|
|
|
|
* * Adds the newly created record to the current dataset (at the end by
|
|
|
|
|
* default)
|
|
|
|
|
* * Selects that record (sets the dataset's index to point to the new
|
|
|
|
|
* record's id).
|
|
|
|
|
* * Updates the pager and sidebar displays
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} r
|
|
|
|
|
* @param {Function} success callback to execute after having updated the dataset
|
|
|
|
|
* @param {Boolean} [prepend_on_create=false] adds the newly created record at the beginning of the dataset instead of the end
|
|
|
|
|
*/
|
|
|
|
|
on_created: function(r, success, prepend_on_create) {
|
2011-04-11 15:59:46 +00:00
|
|
|
|
if (!r.result) {
|
2011-09-12 14:07:53 +00:00
|
|
|
|
// should not happen in the server, but may happen for internal purpose
|
2011-09-26 12:39:29 +00:00
|
|
|
|
return $.Deferred().reject();
|
2011-04-11 15:59:46 +00:00
|
|
|
|
} else {
|
2011-06-06 13:11:08 +00:00
|
|
|
|
this.datarecord.id = r.result;
|
|
|
|
|
if (!prepend_on_create) {
|
2012-02-14 15:20:31 +00:00
|
|
|
|
this.dataset.alter_ids(this.dataset.ids.concat([this.datarecord.id]));
|
2011-06-06 13:11:08 +00:00
|
|
|
|
this.dataset.index = this.dataset.ids.length - 1;
|
|
|
|
|
} else {
|
2012-04-17 01:19:33 +00:00
|
|
|
|
this.dataset.alter_ids([this.datarecord.id].concat(this.dataset.ids));
|
2011-06-06 13:11:08 +00:00
|
|
|
|
this.dataset.index = 0;
|
|
|
|
|
}
|
2011-04-11 15:59:46 +00:00
|
|
|
|
this.do_update_pager();
|
2011-07-26 21:00:05 +00:00
|
|
|
|
if (this.sidebar) {
|
2012-04-17 01:19:33 +00:00
|
|
|
|
this.sidebar.do_attachement_update(this.dataset, this.datarecord.id);
|
2011-07-26 21:00:05 +00:00
|
|
|
|
}
|
2012-04-17 12:09:49 +00:00
|
|
|
|
//instance.log("The record has been created with id #" + this.datarecord.id);
|
2011-10-13 08:51:00 +00:00
|
|
|
|
this.reload();
|
2011-10-12 14:10:07 +00:00
|
|
|
|
return $.when(_.extend(r, {created: true})).then(success);
|
2011-04-05 15:14:40 +00:00
|
|
|
|
}
|
2011-03-31 14:44:22 +00:00
|
|
|
|
},
|
2011-04-01 10:44:54 +00:00
|
|
|
|
on_action: function (action) {
|
2011-09-12 13:56:03 +00:00
|
|
|
|
console.debug('Executing action', action);
|
2011-04-08 10:37:36 +00:00
|
|
|
|
},
|
2011-07-26 21:00:05 +00:00
|
|
|
|
reload: function() {
|
2011-10-12 14:10:07 +00:00
|
|
|
|
var self = this;
|
2012-01-10 14:47:09 +00:00
|
|
|
|
return this.reload_mutex.exec(function() {
|
2012-04-10 08:33:21 +00:00
|
|
|
|
if (self.dataset.index == null) {
|
|
|
|
|
self.do_prev_view();
|
2012-04-09 23:36:15 +00:00
|
|
|
|
return $.Deferred().reject().promise();
|
|
|
|
|
}
|
2011-10-12 14:10:07 +00:00
|
|
|
|
if (self.dataset.index == null || self.dataset.index < 0) {
|
|
|
|
|
return $.when(self.on_button_new());
|
|
|
|
|
} else {
|
2012-01-11 12:49:11 +00:00
|
|
|
|
return self.dataset.read_index(_.keys(self.fields_view.fields), {
|
|
|
|
|
context : { 'bin_size' : true }
|
|
|
|
|
}).pipe(self.on_record_loaded);
|
2011-10-12 14:10:07 +00:00
|
|
|
|
}
|
2012-01-10 14:47:09 +00:00
|
|
|
|
});
|
2011-07-26 21:00:05 +00:00
|
|
|
|
},
|
2012-03-19 17:03:36 +00:00
|
|
|
|
get_widgets: function() {
|
|
|
|
|
return _.filter(this.getChildren(), function(obj) {
|
2012-04-17 12:09:49 +00:00
|
|
|
|
return obj instanceof instance.web.form.Widget;
|
2012-03-19 17:03:36 +00:00
|
|
|
|
});
|
|
|
|
|
},
|
2011-12-19 17:30:55 +00:00
|
|
|
|
get_fields_values: function(blacklist) {
|
|
|
|
|
blacklist = blacklist || [];
|
2011-07-26 21:00:05 +00:00
|
|
|
|
var values = {};
|
2012-01-18 16:15:17 +00:00
|
|
|
|
var ids = this.get_selected_ids();
|
|
|
|
|
values["id"] = ids.length > 0 ? ids[0] : false;
|
2012-04-17 14:32:27 +00:00
|
|
|
|
_.each(this.fields, function(value_, key) {
|
2011-12-19 17:30:55 +00:00
|
|
|
|
if (_.include(blacklist, key))
|
|
|
|
|
return;
|
2012-04-17 14:32:27 +00:00
|
|
|
|
var val = value_.get_value();
|
2011-07-26 21:00:05 +00:00
|
|
|
|
values[key] = val;
|
|
|
|
|
});
|
|
|
|
|
return values;
|
2011-08-26 13:03:35 +00:00
|
|
|
|
},
|
|
|
|
|
get_selected_ids: function() {
|
|
|
|
|
var id = this.dataset.ids[this.dataset.index];
|
|
|
|
|
return id ? [id] : [];
|
2011-09-26 12:39:29 +00:00
|
|
|
|
},
|
|
|
|
|
recursive_save: function() {
|
|
|
|
|
var self = this;
|
|
|
|
|
return $.when(this.do_save()).pipe(function(res) {
|
2011-09-26 16:00:57 +00:00
|
|
|
|
if (self.dataset.parent_view)
|
|
|
|
|
return self.dataset.parent_view.recursive_save();
|
2011-09-26 12:39:29 +00:00
|
|
|
|
});
|
2011-09-30 15:46:12 +00:00
|
|
|
|
},
|
2011-11-15 14:58:06 +00:00
|
|
|
|
is_dirty: function() {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
return _.any(this.fields, function (value_) {
|
2012-04-18 11:50:04 +00:00
|
|
|
|
return value_._dirty_flag;
|
2011-11-16 07:52:46 +00:00
|
|
|
|
});
|
2011-11-15 14:58:06 +00:00
|
|
|
|
},
|
2011-09-30 15:46:12 +00:00
|
|
|
|
is_interactible_record: function() {
|
|
|
|
|
var id = this.datarecord.id;
|
|
|
|
|
if (!id) {
|
|
|
|
|
if (this.options.not_interactible_on_create)
|
|
|
|
|
return false;
|
|
|
|
|
} else if (typeof(id) === "string") {
|
2012-04-17 12:09:49 +00:00
|
|
|
|
if(instance.web.BufferedDataSet.virtual_id_regex.test(id))
|
2011-09-30 15:46:12 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2011-11-21 14:14:18 +00:00
|
|
|
|
},
|
|
|
|
|
sidebar_context: function () {
|
2011-12-19 17:30:55 +00:00
|
|
|
|
return this.do_save().pipe(_.bind(function() {return this.get_fields_values();}, this));
|
2012-02-08 12:21:53 +00:00
|
|
|
|
},
|
|
|
|
|
open_defaults_dialog: function () {
|
|
|
|
|
var self = this;
|
|
|
|
|
var fields = _.chain(this.fields)
|
|
|
|
|
.map(function (field, name) {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
var value_ = field.get_value();
|
2012-02-08 12:21:53 +00:00
|
|
|
|
// ignore fields which are empty, invisible, readonly, o2m
|
|
|
|
|
// or m2m
|
2012-04-17 14:32:27 +00:00
|
|
|
|
if (!value_
|
2012-03-26 16:29:34 +00:00
|
|
|
|
|| field.get('invisible')
|
2012-03-20 15:51:11 +00:00
|
|
|
|
|| field.get("readonly")
|
2012-02-08 12:21:53 +00:00
|
|
|
|
|| field.field.type === 'one2many'
|
|
|
|
|
|| field.field.type === 'many2many') {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2012-02-09 15:14:10 +00:00
|
|
|
|
var displayed;
|
|
|
|
|
switch(field.field.type) {
|
|
|
|
|
case 'selection':
|
|
|
|
|
displayed = _(field.values).find(function (option) {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
return option[0] === value_;
|
2012-02-09 15:14:10 +00:00
|
|
|
|
})[1];
|
|
|
|
|
break;
|
|
|
|
|
case 'many2one':
|
2012-04-17 14:32:27 +00:00
|
|
|
|
displayed = value_;
|
2012-02-09 15:14:10 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2012-04-17 14:32:27 +00:00
|
|
|
|
displayed = value_;
|
2012-02-09 15:14:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-08 12:21:53 +00:00
|
|
|
|
return {
|
|
|
|
|
name: name,
|
2012-03-13 15:58:52 +00:00
|
|
|
|
string: field.node_atts.string,
|
2012-04-17 14:32:27 +00:00
|
|
|
|
value: value_,
|
2012-02-09 15:14:10 +00:00
|
|
|
|
displayed: displayed,
|
2012-02-08 12:21:53 +00:00
|
|
|
|
// convert undefined to false
|
|
|
|
|
change_default: !!field.field.change_default
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.compact()
|
2012-03-13 15:58:52 +00:00
|
|
|
|
.sortBy(function (field) { return field.node_atts.string; })
|
2012-02-08 12:21:53 +00:00
|
|
|
|
.value();
|
|
|
|
|
var conditions = _.chain(fields)
|
|
|
|
|
.filter(function (field) { return field.change_default; })
|
|
|
|
|
.value();
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var d = new instance.web.Dialog(this, {
|
2012-02-08 12:21:53 +00:00
|
|
|
|
title: _t("Set Default"),
|
|
|
|
|
args: {
|
|
|
|
|
fields: fields,
|
|
|
|
|
conditions: conditions
|
|
|
|
|
},
|
|
|
|
|
buttons: [
|
|
|
|
|
{text: _t("Close"), click: function () { d.close(); }},
|
|
|
|
|
{text: _t("Save default"), click: function () {
|
|
|
|
|
var $defaults = d.$element.find('#formview_default_fields');
|
|
|
|
|
var field_to_set = $defaults.val();
|
|
|
|
|
if (!field_to_set) {
|
2012-03-26 12:29:50 +00:00
|
|
|
|
$defaults.parent().addClass('oe_form_invalid');
|
2012-02-08 12:21:53 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var condition = d.$element.find('#formview_default_conditions').val(),
|
|
|
|
|
all_users = d.$element.find('#formview_default_all').is(':checked');
|
2012-04-17 12:09:49 +00:00
|
|
|
|
new instance.web.DataSet(self, 'ir.values').call(
|
2012-02-08 12:21:53 +00:00
|
|
|
|
'set_default', [
|
|
|
|
|
self.dataset.model,
|
|
|
|
|
field_to_set,
|
|
|
|
|
self.fields[field_to_set].get_value(),
|
|
|
|
|
all_users,
|
|
|
|
|
false,
|
|
|
|
|
condition || false
|
|
|
|
|
]).then(function () { d.close(); });
|
|
|
|
|
}}
|
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
|
d.template = 'FormView.set_default';
|
|
|
|
|
d.open();
|
2012-04-16 15:08:39 +00:00
|
|
|
|
},
|
|
|
|
|
register_field: function(field, name) {
|
|
|
|
|
this.fields[name] = field;
|
|
|
|
|
this.fields_order.push(name);
|
2012-04-17 13:33:07 +00:00
|
|
|
|
if (this.get_field(name).translate) {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this.translatable_fields.push(field);
|
2012-04-17 13:33:07 +00:00
|
|
|
|
}
|
2012-04-18 09:57:58 +00:00
|
|
|
|
field.on('changed_value', this, function() {
|
2012-04-18 13:31:37 +00:00
|
|
|
|
field._dirty_flag = true;
|
2012-04-18 11:50:04 +00:00
|
|
|
|
if (field.is_syntax_valid()) {
|
|
|
|
|
this.do_onchange(field);
|
|
|
|
|
this.on_form_changed(true);
|
|
|
|
|
this.do_notify_change();
|
|
|
|
|
}
|
2012-04-18 09:57:58 +00:00
|
|
|
|
});
|
2012-04-17 13:33:07 +00:00
|
|
|
|
},
|
|
|
|
|
get_field: function(field_name) {
|
|
|
|
|
return this.fields_view.fields[field_name];
|
2012-04-16 15:08:39 +00:00
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
is_create_mode: function() {
|
|
|
|
|
return !this.datarecord.id;
|
|
|
|
|
},
|
2011-07-26 21:00:05 +00:00
|
|
|
|
});
|
2012-03-14 17:09:49 +00:00
|
|
|
|
|
2012-03-20 16:26:16 +00:00
|
|
|
|
/**
|
|
|
|
|
* Interface to be implemented by rendering engines for the form view.
|
|
|
|
|
*/
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FormRenderingEngineInterface = {
|
2012-03-20 16:26:16 +00:00
|
|
|
|
set_fields_view: function(fields_view) {},
|
2012-04-10 12:21:10 +00:00
|
|
|
|
set_fields_registry: function(fields_registry) {},
|
2012-03-20 16:26:16 +00:00
|
|
|
|
render_to: function($element) {},
|
|
|
|
|
};
|
|
|
|
|
|
2012-03-20 16:18:06 +00:00
|
|
|
|
/**
|
|
|
|
|
* Default rendering engine for the form view.
|
|
|
|
|
*
|
|
|
|
|
* It is necessary to set the view using set_view() before usage.
|
|
|
|
|
*/
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FormRenderingEngine = instance.web.Class.extend({
|
2012-03-20 16:18:06 +00:00
|
|
|
|
init: function(view) {
|
|
|
|
|
this.view = view;
|
|
|
|
|
},
|
|
|
|
|
set_fields_view: function(fvg) {
|
2012-03-14 17:09:49 +00:00
|
|
|
|
this.fvg = fvg;
|
2012-03-20 16:18:06 +00:00
|
|
|
|
},
|
2012-04-10 12:09:38 +00:00
|
|
|
|
set_tags_registry: function(tags_registry) {
|
|
|
|
|
this.tags_registry = tags_registry;
|
2012-03-20 16:18:06 +00:00
|
|
|
|
},
|
2012-04-10 12:21:10 +00:00
|
|
|
|
set_fields_registry: function(fields_registry) {
|
|
|
|
|
this.fields_registry = fields_registry;
|
|
|
|
|
},
|
|
|
|
|
render_to: function($target) {
|
2012-03-20 16:18:06 +00:00
|
|
|
|
var self = this;
|
2012-04-10 12:21:10 +00:00
|
|
|
|
this.$target = $target;
|
2012-03-21 10:53:36 +00:00
|
|
|
|
|
2012-03-14 17:09:49 +00:00
|
|
|
|
// TODO: I know this will save the world and all the kitten for a moment,
|
|
|
|
|
// but one day, we will have to get rid of xml2json
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var xml = instance.web.json_node_to_xml(this.fvg.arch);
|
2012-03-28 10:41:18 +00:00
|
|
|
|
this.$form = $('<div class="oe_form">' + xml + '</div>');
|
2012-04-09 21:43:48 +00:00
|
|
|
|
if (this.fvg.arch.attrs && this.fvg.arch.attrs['layout'] !== 'manual') {
|
2012-04-10 10:29:51 +00:00
|
|
|
|
this.$form.attr('layout', 'auto');
|
2012-04-09 21:43:48 +00:00
|
|
|
|
}
|
2012-03-14 17:09:49 +00:00
|
|
|
|
|
2012-04-10 13:04:44 +00:00
|
|
|
|
this.fields_to_init = [];
|
|
|
|
|
this.tags_to_init = [];
|
2012-03-27 12:47:04 +00:00
|
|
|
|
this.labels = {};
|
2012-03-20 14:35:16 +00:00
|
|
|
|
this.process(this.$form);
|
2012-03-21 10:53:36 +00:00
|
|
|
|
|
2012-04-10 12:21:10 +00:00
|
|
|
|
this.$form.appendTo(this.$target);
|
2012-03-14 17:09:49 +00:00
|
|
|
|
|
2012-04-10 13:04:44 +00:00
|
|
|
|
_.each(this.fields_to_init, function($elem) {
|
|
|
|
|
var name = $elem.attr("name");
|
|
|
|
|
if (!self.fvg.fields[name]) {
|
|
|
|
|
throw new Error("Field '" + name + "' specified in view could not be found.");
|
|
|
|
|
}
|
2012-04-10 13:26:57 +00:00
|
|
|
|
var obj = self.fields_registry.get_any([$elem.attr('widget'), self.fvg.fields[name].type]);
|
|
|
|
|
if (!obj) {
|
2012-04-10 13:04:44 +00:00
|
|
|
|
throw new Error("Widget type '"+ key + "' is not implemented");
|
|
|
|
|
}
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var w = new (obj)(self.view, instance.web.xml_to_json($elem[0]));
|
2012-04-10 13:04:44 +00:00
|
|
|
|
var $label = self.labels[$elem.attr("name")];
|
|
|
|
|
if ($label) {
|
|
|
|
|
w.set_input_id($label.attr("for"));
|
2012-03-14 17:09:49 +00:00
|
|
|
|
}
|
2012-04-10 13:04:44 +00:00
|
|
|
|
self.alter_field(w);
|
2012-04-16 15:08:39 +00:00
|
|
|
|
self.view.register_field(w, $elem.attr("name"));
|
2012-04-10 13:04:44 +00:00
|
|
|
|
w.replace($elem);
|
2012-03-14 17:09:49 +00:00
|
|
|
|
});
|
2012-04-10 13:04:44 +00:00
|
|
|
|
_.each(this.tags_to_init, function($elem) {
|
|
|
|
|
var tag_name = $elem[0].tagName.toLowerCase();
|
|
|
|
|
var obj = self.tags_registry.get_object(tag_name);
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var w = new (obj)(self.view, instance.web.xml_to_json($elem[0]));
|
2012-04-10 13:04:44 +00:00
|
|
|
|
w.replace($elem);
|
|
|
|
|
})
|
2012-04-16 14:45:42 +00:00
|
|
|
|
// TODO: return a deferred
|
2012-03-21 10:53:36 +00:00
|
|
|
|
},
|
2012-04-10 10:29:51 +00:00
|
|
|
|
render_element: function(template, layout/* dictionaries */) {
|
|
|
|
|
var dicts = [].slice.call(arguments).slice(2);
|
|
|
|
|
dicts.unshift({ 'layout' : layout });
|
|
|
|
|
var dict = _.extend.apply(_, dicts);
|
|
|
|
|
dict['classnames'] = dict['class'] || ''; // class is a reserved word and might caused problem to Safari when used from QWeb
|
|
|
|
|
var alt_template = template + '.' + layout;
|
|
|
|
|
template = QWeb.has_template(alt_template) ? alt_template : template;
|
2012-03-21 10:53:36 +00:00
|
|
|
|
return $(QWeb.render(template, dict));
|
2012-03-20 11:01:15 +00:00
|
|
|
|
},
|
2012-04-09 21:43:48 +00:00
|
|
|
|
alter_field: function(field) {
|
|
|
|
|
},
|
2012-03-21 10:53:36 +00:00
|
|
|
|
toggle_layout_debugging: function() {
|
2012-04-10 12:21:10 +00:00
|
|
|
|
if (!this.$target.has('.oe_layout_debug_cell:first').length) {
|
2012-04-18 16:10:39 +00:00
|
|
|
|
this.$target.find('[title]').removeAttr('title');
|
2012-04-10 12:21:10 +00:00
|
|
|
|
this.$target.find('.oe_form_group_cell').each(function() {
|
2012-04-18 16:10:39 +00:00
|
|
|
|
var text = 'W:' + ($(this).attr('width') || '') + ' - C:' + $(this).attr('colspan');
|
|
|
|
|
$(this).attr('title', text);
|
2012-03-20 11:01:15 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2012-04-10 12:21:10 +00:00
|
|
|
|
this.$target.toggleClass('oe_layout_debugging');
|
2012-03-14 17:09:49 +00:00
|
|
|
|
},
|
2012-04-10 10:29:51 +00:00
|
|
|
|
process: function($tag, layout) {
|
2012-03-20 11:05:29 +00:00
|
|
|
|
var self = this;
|
2012-04-10 10:29:51 +00:00
|
|
|
|
if ($tag.attr('layout') === 'auto') {
|
|
|
|
|
$tag.addClass('oe_form_autolayout');
|
|
|
|
|
}
|
|
|
|
|
layout = $tag.attr('layout') || layout || 'auto';
|
|
|
|
|
$tag.removeAttr('layout');
|
2012-03-20 11:05:29 +00:00
|
|
|
|
var tagname = $tag[0].nodeName.toLowerCase();
|
2012-04-10 13:04:44 +00:00
|
|
|
|
if (this.tags_registry.contains(tagname)) {
|
|
|
|
|
this.tags_to_init.push($tag);
|
|
|
|
|
return $tag;
|
2012-03-20 11:05:29 +00:00
|
|
|
|
}
|
2012-04-10 13:04:44 +00:00
|
|
|
|
var fn = self['process_' + tagname];
|
2012-03-20 14:35:16 +00:00
|
|
|
|
if (fn) {
|
|
|
|
|
var args = [].slice.call(arguments);
|
|
|
|
|
args[0] = $tag;
|
2012-04-10 10:29:51 +00:00
|
|
|
|
args[1] = layout;
|
2012-03-20 15:04:57 +00:00
|
|
|
|
return fn.apply(self, args);
|
2012-03-20 14:35:16 +00:00
|
|
|
|
} else {
|
|
|
|
|
// generic tag handling, just process children
|
|
|
|
|
$tag.children().each(function() {
|
2012-04-10 10:29:51 +00:00
|
|
|
|
self.process($(this), layout);
|
2012-03-20 11:05:29 +00:00
|
|
|
|
});
|
2012-03-29 09:55:24 +00:00
|
|
|
|
self.handle_common_properties($tag, $tag);
|
2012-03-27 09:39:38 +00:00
|
|
|
|
$tag.removeAttr("modifiers");
|
2012-03-20 15:04:57 +00:00
|
|
|
|
return $tag;
|
2012-03-20 11:05:29 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2012-04-10 10:29:51 +00:00
|
|
|
|
process_sheet: function() {
|
|
|
|
|
this.process_form.apply(this, arguments);
|
|
|
|
|
},
|
|
|
|
|
process_form: function($form, layout) {
|
|
|
|
|
var $new_form = this.render_element('FormRenderingForm', layout, $form.getAttributes());
|
|
|
|
|
var $dst = (layout === 'auto') ? $new_form.find('group:first') : $new_form;
|
2012-03-27 09:45:11 +00:00
|
|
|
|
$new_form.attr("modifiers", $form.attr("modifiers"));
|
2012-03-21 15:57:22 +00:00
|
|
|
|
$form.children().appendTo($dst);
|
|
|
|
|
if ($form[0] === this.$form[0]) {
|
|
|
|
|
// If root element, replace it
|
|
|
|
|
this.$form = $new_form;
|
2012-03-21 10:53:36 +00:00
|
|
|
|
} else {
|
2012-03-21 15:57:22 +00:00
|
|
|
|
$form.before($new_form).remove();
|
2012-03-21 10:53:36 +00:00
|
|
|
|
}
|
2012-03-21 15:57:22 +00:00
|
|
|
|
this.process($new_form);
|
2012-03-21 10:53:36 +00:00
|
|
|
|
},
|
2012-03-20 15:18:01 +00:00
|
|
|
|
preprocess_field: function($field) {
|
2012-04-10 13:17:46 +00:00
|
|
|
|
var self = this;
|
2012-03-14 17:09:49 +00:00
|
|
|
|
var name = $field.attr('name'),
|
2012-03-26 16:29:34 +00:00
|
|
|
|
field_colspan = parseInt($field.attr('colspan'), 10),
|
|
|
|
|
field_modifiers = JSON.parse($field.attr('modifiers') || '{}');
|
2012-04-10 10:29:51 +00:00
|
|
|
|
|
2012-03-27 12:21:54 +00:00
|
|
|
|
if ($field.attr('nolabel') === '1')
|
|
|
|
|
return;
|
|
|
|
|
$field.attr('nolabel', '1');
|
|
|
|
|
var found = false;
|
|
|
|
|
this.$form.find('label[for="' + name + '"]').each(function(i ,el) {
|
2012-04-10 13:17:46 +00:00
|
|
|
|
$(el).parents().each(function(unused, tag) {
|
2012-04-10 13:20:31 +00:00
|
|
|
|
var name = tag.tagName.toLowerCase();
|
|
|
|
|
if (name === "field" || name in self.tags_registry.map)
|
2012-04-10 13:17:46 +00:00
|
|
|
|
found = true;
|
|
|
|
|
});
|
2012-03-27 12:21:54 +00:00
|
|
|
|
});
|
|
|
|
|
if (found)
|
|
|
|
|
return;
|
2012-04-10 10:29:51 +00:00
|
|
|
|
|
2012-03-27 12:21:54 +00:00
|
|
|
|
$label = $('<label/>').attr({
|
|
|
|
|
'for' : name,
|
|
|
|
|
"modifiers": JSON.stringify({invisible: field_modifiers.invisible}),
|
|
|
|
|
"string": $field.attr('string'),
|
|
|
|
|
"help": $field.attr('help'),
|
|
|
|
|
});
|
|
|
|
|
$label.insertBefore($field);
|
|
|
|
|
if (field_colspan > 1) {
|
|
|
|
|
$field.attr('colspan', field_colspan - 1);
|
2012-03-20 15:18:01 +00:00
|
|
|
|
}
|
2012-03-27 12:21:54 +00:00
|
|
|
|
return $label;
|
2012-03-20 15:18:01 +00:00
|
|
|
|
},
|
2012-04-10 10:29:51 +00:00
|
|
|
|
process_field: function($field, layout) {
|
2012-03-20 15:18:01 +00:00
|
|
|
|
var $label = this.preprocess_field($field);
|
|
|
|
|
if ($label)
|
2012-04-10 10:29:51 +00:00
|
|
|
|
this.process($label, layout);
|
2012-04-10 13:04:44 +00:00
|
|
|
|
this.fields_to_init.push($field);
|
2012-03-20 15:18:01 +00:00
|
|
|
|
return $field;
|
2012-03-14 17:09:49 +00:00
|
|
|
|
},
|
2012-04-10 10:29:51 +00:00
|
|
|
|
process_group: function($group, layout) {
|
2012-03-20 11:05:29 +00:00
|
|
|
|
var self = this;
|
2012-03-26 12:14:49 +00:00
|
|
|
|
if ($group.parent().is('.oe_form_group_cell')) {
|
|
|
|
|
$group.parent().addClass('oe_form_group_nested');
|
|
|
|
|
}
|
2012-03-20 15:18:01 +00:00
|
|
|
|
$group.children('field').each(function() {
|
|
|
|
|
self.preprocess_field($(this));
|
2012-03-20 11:05:29 +00:00
|
|
|
|
});
|
2012-04-10 10:29:51 +00:00
|
|
|
|
var $new_group = this.render_element('FormRenderingGroup', layout, $group.getAttributes()),
|
2012-03-15 19:32:45 +00:00
|
|
|
|
$table;
|
2012-03-14 17:09:49 +00:00
|
|
|
|
if ($new_group.is('table')) {
|
|
|
|
|
$table = $new_group;
|
|
|
|
|
} else {
|
|
|
|
|
$table = $new_group.find('table:first');
|
|
|
|
|
}
|
|
|
|
|
$table.addClass('oe_form_group');
|
2012-03-26 09:44:18 +00:00
|
|
|
|
var $tr, $td,
|
2012-03-14 17:09:49 +00:00
|
|
|
|
cols = parseInt($group.attr('col') || 4, 10),
|
|
|
|
|
row_cols = cols;
|
|
|
|
|
|
2012-03-20 13:19:39 +00:00
|
|
|
|
var children = [];
|
2012-03-26 09:44:18 +00:00
|
|
|
|
$group.children().each(function(a,b,c) {
|
2012-03-14 17:09:49 +00:00
|
|
|
|
var $child = $(this),
|
2012-03-15 14:16:22 +00:00
|
|
|
|
colspan = parseInt($child.attr('colspan') || 1, 10),
|
|
|
|
|
tagName = $child[0].tagName.toLowerCase();
|
|
|
|
|
if (tagName === 'newline') {
|
2012-03-14 17:09:49 +00:00
|
|
|
|
$tr = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!$tr || row_cols < colspan) {
|
|
|
|
|
$tr = $('<tr/>').addClass('oe_form_group_row').appendTo($table);
|
|
|
|
|
row_cols = cols;
|
|
|
|
|
}
|
|
|
|
|
row_cols -= colspan;
|
2012-04-10 10:29:51 +00:00
|
|
|
|
|
2012-03-26 09:44:18 +00:00
|
|
|
|
$td = $('<td/>').addClass('oe_form_group_cell').attr('colspan', colspan);
|
2012-03-26 16:49:05 +00:00
|
|
|
|
// invisibility transfer
|
2012-03-27 09:39:38 +00:00
|
|
|
|
var field_modifiers = JSON.parse($child.attr('modifiers') || '{}');
|
|
|
|
|
var invisible = field_modifiers.invisible;
|
|
|
|
|
field_modifiers.invisible = undefined;
|
|
|
|
|
$child.attr('modifiers', JSON.stringify(field_modifiers));
|
2012-03-29 09:55:24 +00:00
|
|
|
|
self.handle_common_properties($td, $("<dummy>").attr("modifiers", JSON.stringify({invisible: invisible})));
|
2012-04-10 10:29:51 +00:00
|
|
|
|
|
2012-03-14 17:09:49 +00:00
|
|
|
|
$tr.append($td.append($child));
|
2012-03-20 13:19:39 +00:00
|
|
|
|
children.push($child[0]);
|
2012-03-14 17:09:49 +00:00
|
|
|
|
});
|
2012-03-27 10:18:32 +00:00
|
|
|
|
if (row_cols && $td) {
|
2012-03-26 09:44:18 +00:00
|
|
|
|
$td.attr('colspan', parseInt($td.attr('colspan'), 10) + row_cols);
|
|
|
|
|
}
|
2012-03-14 17:09:49 +00:00
|
|
|
|
$group.before($new_group).remove();
|
2012-03-15 21:58:10 +00:00
|
|
|
|
|
|
|
|
|
// Now compute width of cells
|
2012-04-10 13:04:20 +00:00
|
|
|
|
$table.find('> tbody > tr').each(function() {
|
2012-03-15 19:32:45 +00:00
|
|
|
|
var to_compute = [],
|
2012-03-20 12:06:21 +00:00
|
|
|
|
row_cols = cols,
|
2012-03-15 19:32:45 +00:00
|
|
|
|
total = 100;
|
2012-03-15 21:58:10 +00:00
|
|
|
|
$(this).children().each(function() {
|
2012-03-15 19:32:45 +00:00
|
|
|
|
var $td = $(this),
|
|
|
|
|
$child = $td.children(':first');
|
|
|
|
|
switch ($child[0].tagName.toLowerCase()) {
|
|
|
|
|
case 'separator':
|
|
|
|
|
if ($child.attr('orientation') === 'vertical') {
|
|
|
|
|
$td.addClass('oe_vertical_separator').attr('width', '1');
|
|
|
|
|
$td.empty();
|
2012-03-20 12:06:21 +00:00
|
|
|
|
row_cols--;
|
2012-03-15 19:32:45 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'label':
|
|
|
|
|
if ($child.attr('for')) {
|
|
|
|
|
$td.attr('width', '1%');
|
2012-03-20 12:06:21 +00:00
|
|
|
|
row_cols--;
|
2012-03-15 19:32:45 +00:00
|
|
|
|
total--;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2012-04-19 15:33:41 +00:00
|
|
|
|
var width = _.str.trim($child.attr('width') || ''),
|
|
|
|
|
iwidth = parseInt(width, 10);
|
|
|
|
|
if (iwidth) {
|
|
|
|
|
if (width.substr(-1) === '%') {
|
|
|
|
|
total -= iwidth;
|
|
|
|
|
width = iwidth + '%';
|
|
|
|
|
}
|
|
|
|
|
$td.attr('width', width);
|
|
|
|
|
$child.removeAttr('width');
|
|
|
|
|
row_cols--;
|
|
|
|
|
} else {
|
|
|
|
|
to_compute.push($td);
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-15 19:32:45 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2012-03-20 12:06:21 +00:00
|
|
|
|
var unit = Math.floor(total / row_cols);
|
2012-03-15 19:32:45 +00:00
|
|
|
|
_.each(to_compute, function($td, i) {
|
|
|
|
|
var width = parseInt($td.attr('colspan'), 10) * unit;
|
|
|
|
|
$td.attr('width', ((i == to_compute.length - 1) ? total : width) + '%');
|
|
|
|
|
total -= width;
|
|
|
|
|
});
|
2012-03-15 21:58:10 +00:00
|
|
|
|
});
|
2012-03-20 13:19:39 +00:00
|
|
|
|
_.each(children, function(el) {
|
2012-03-20 15:18:01 +00:00
|
|
|
|
self.process($(el));
|
2012-03-20 13:19:39 +00:00
|
|
|
|
});
|
2012-03-29 09:55:24 +00:00
|
|
|
|
this.handle_common_properties($new_group, $group);
|
2012-03-20 15:04:57 +00:00
|
|
|
|
return $new_group;
|
2012-03-15 19:32:45 +00:00
|
|
|
|
},
|
2012-04-10 10:29:51 +00:00
|
|
|
|
process_notebook: function($notebook, layout) {
|
2012-03-20 11:05:29 +00:00
|
|
|
|
var self = this;
|
2012-03-15 10:53:24 +00:00
|
|
|
|
var pages = [];
|
|
|
|
|
$notebook.find('> page').each(function() {
|
2012-04-01 21:55:07 +00:00
|
|
|
|
var $page = $(this);
|
|
|
|
|
var page_attrs = $page.getAttributes();
|
2012-03-15 10:53:24 +00:00
|
|
|
|
page_attrs.id = _.uniqueId('notebook_page_');
|
|
|
|
|
pages.push(page_attrs);
|
2012-04-10 10:29:51 +00:00
|
|
|
|
var $new_page = self.render_element('FormRenderingNotebookPage', layout, page_attrs);
|
|
|
|
|
var $dst = (layout === 'auto') ? $new_page.find('group:first') : $new_page;
|
2012-03-21 10:53:36 +00:00
|
|
|
|
$page.children().appendTo($dst);
|
2012-03-15 10:53:24 +00:00
|
|
|
|
$page.before($new_page).remove();
|
2012-03-29 09:55:24 +00:00
|
|
|
|
self.handle_common_properties($new_page, $page);
|
2012-03-15 10:53:24 +00:00
|
|
|
|
});
|
2012-04-10 10:29:51 +00:00
|
|
|
|
var $new_notebook = this.render_element('FormRenderingNotebook', layout, { pages : pages });
|
2012-03-15 10:53:24 +00:00
|
|
|
|
$notebook.children().appendTo($new_notebook);
|
|
|
|
|
$notebook.before($new_notebook).remove();
|
2012-03-21 10:53:36 +00:00
|
|
|
|
$new_notebook.children().each(function() {
|
|
|
|
|
self.process($(this));
|
|
|
|
|
});
|
2012-03-15 10:53:24 +00:00
|
|
|
|
$new_notebook.tabs();
|
2012-03-29 09:55:24 +00:00
|
|
|
|
this.handle_common_properties($new_notebook, $notebook);
|
2012-03-20 15:04:57 +00:00
|
|
|
|
return $new_notebook;
|
2012-03-14 17:09:49 +00:00
|
|
|
|
},
|
2012-04-10 10:29:51 +00:00
|
|
|
|
process_separator: function($separator, layout) {
|
|
|
|
|
var $new_separator = this.render_element('FormRenderingSeparator', layout, $separator.getAttributes());
|
2012-03-15 14:16:22 +00:00
|
|
|
|
$separator.before($new_separator).remove();
|
2012-03-29 09:55:24 +00:00
|
|
|
|
this.handle_common_properties($new_separator, $separator);
|
2012-03-20 15:04:57 +00:00
|
|
|
|
return $new_separator;
|
2012-03-14 17:09:49 +00:00
|
|
|
|
},
|
2012-04-10 10:29:51 +00:00
|
|
|
|
process_label: function($label, layout) {
|
2012-03-27 12:21:54 +00:00
|
|
|
|
var name = $label.attr("for"),
|
|
|
|
|
field_orm = this.fvg.fields[name];
|
|
|
|
|
var dict = {
|
2012-03-27 14:31:33 +00:00
|
|
|
|
string: $label.attr('string') || (field_orm || {}).string || '',
|
|
|
|
|
help: $label.attr('help') || (field_orm || {}).help || '',
|
2012-03-29 15:01:36 +00:00
|
|
|
|
_for: name ? _.uniqueId('oe-field-input-') : undefined,
|
2012-03-27 12:21:54 +00:00
|
|
|
|
};
|
2012-03-19 10:29:04 +00:00
|
|
|
|
var align = parseFloat(dict.align);
|
|
|
|
|
if (isNaN(align) || align === 1) {
|
|
|
|
|
align = 'right';
|
|
|
|
|
} else if (align === 0) {
|
|
|
|
|
align = 'left';
|
|
|
|
|
} else {
|
|
|
|
|
align = 'center';
|
|
|
|
|
}
|
|
|
|
|
dict.align = align;
|
2012-04-10 10:29:51 +00:00
|
|
|
|
var $new_label = this.render_element('FormRenderingLabel', layout, dict);
|
2012-03-14 17:09:49 +00:00
|
|
|
|
$label.before($new_label).remove();
|
2012-03-29 09:55:24 +00:00
|
|
|
|
this.handle_common_properties($new_label, $label);
|
2012-03-29 15:01:36 +00:00
|
|
|
|
if (name) {
|
|
|
|
|
this.labels[name] = $new_label;
|
|
|
|
|
}
|
2012-03-20 15:04:57 +00:00
|
|
|
|
return $new_label;
|
2012-03-26 15:14:37 +00:00
|
|
|
|
},
|
2012-04-10 12:21:10 +00:00
|
|
|
|
handle_common_properties: function($new_element, $node) {
|
2012-03-29 09:55:24 +00:00
|
|
|
|
var str_modifiers = $node.attr("modifiers") || "{}"
|
|
|
|
|
var modifiers = JSON.parse(str_modifiers);
|
|
|
|
|
if (modifiers.invisible !== undefined)
|
2012-04-17 12:09:49 +00:00
|
|
|
|
new instance.web.form.InvisibilityChanger(this.view, this.view, modifiers.invisible, $new_element);
|
2012-04-10 12:21:10 +00:00
|
|
|
|
$new_element.addClass($node.attr("class") || "");
|
2012-03-26 16:29:34 +00:00
|
|
|
|
},
|
2012-03-14 17:09:49 +00:00
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FormRenderingEngineReadonly = instance.web.form.FormRenderingEngine.extend({
|
2012-04-09 23:36:15 +00:00
|
|
|
|
alter_field: function(field) {
|
|
|
|
|
field.set({"force_readonly": true});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FormDialog = instance.web.Dialog.extend({
|
2011-09-07 14:53:11 +00:00
|
|
|
|
init: function(parent, options, view_id, dataset) {
|
|
|
|
|
this._super(parent, options);
|
|
|
|
|
this.dataset = dataset;
|
|
|
|
|
this.view_id = view_id;
|
|
|
|
|
return this;
|
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this._super();
|
2012-04-17 12:09:49 +00:00
|
|
|
|
this.form = new instance.web.FormView(this, this.dataset, this.view_id, {
|
2011-09-07 14:53:11 +00:00
|
|
|
|
pager: false
|
|
|
|
|
});
|
2011-09-14 15:14:59 +00:00
|
|
|
|
this.form.appendTo(this.$element);
|
2011-09-07 14:53:11 +00:00
|
|
|
|
this.form.on_created.add_last(this.on_form_dialog_saved);
|
|
|
|
|
this.form.on_saved.add_last(this.on_form_dialog_saved);
|
|
|
|
|
return this;
|
|
|
|
|
},
|
2011-10-20 16:30:08 +00:00
|
|
|
|
select_id: function(id) {
|
|
|
|
|
if (this.form.dataset.select_id(id)) {
|
|
|
|
|
return this.form.do_show();
|
|
|
|
|
} else {
|
|
|
|
|
this.do_warn("Could not find id in dataset");
|
|
|
|
|
return $.Deferred().reject();
|
|
|
|
|
}
|
2011-09-07 14:53:11 +00:00
|
|
|
|
},
|
2011-09-12 13:36:39 +00:00
|
|
|
|
on_form_dialog_saved: function(r) {
|
2011-09-07 14:53:11 +00:00
|
|
|
|
this.close();
|
|
|
|
|
}
|
|
|
|
|
});
|
2011-07-26 21:00:05 +00:00
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.compute_domain = function(expr, fields) {
|
2011-04-11 17:36:43 +00:00
|
|
|
|
var stack = [];
|
2011-04-11 17:50:25 +00:00
|
|
|
|
for (var i = expr.length - 1; i >= 0; i--) {
|
2011-04-11 17:36:43 +00:00
|
|
|
|
var ex = expr[i];
|
|
|
|
|
if (ex.length == 1) {
|
2011-04-11 17:50:25 +00:00
|
|
|
|
var top = stack.pop();
|
2011-05-17 09:35:03 +00:00
|
|
|
|
switch (ex) {
|
2011-04-11 17:50:25 +00:00
|
|
|
|
case '|':
|
|
|
|
|
stack.push(stack.pop() || top);
|
|
|
|
|
continue;
|
|
|
|
|
case '&':
|
|
|
|
|
stack.push(stack.pop() && top);
|
|
|
|
|
continue;
|
|
|
|
|
case '!':
|
|
|
|
|
stack.push(!top);
|
|
|
|
|
continue;
|
|
|
|
|
default:
|
2012-02-03 08:48:52 +00:00
|
|
|
|
throw new Error(_.str.sprintf(
|
|
|
|
|
_t("Unknown operator %s in domain %s"),
|
|
|
|
|
ex, JSON.stringify(expr)));
|
2011-04-11 17:50:25 +00:00
|
|
|
|
}
|
2011-04-11 17:36:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-10 15:42:38 +00:00
|
|
|
|
var field = fields[ex[0]];
|
|
|
|
|
if (!field) {
|
2012-02-03 08:48:52 +00:00
|
|
|
|
throw new Error(_.str.sprintf(
|
|
|
|
|
_t("Unknown field %s in domain %s"),
|
|
|
|
|
ex[0], JSON.stringify(expr)));
|
2011-08-10 15:42:38 +00:00
|
|
|
|
}
|
2012-04-18 09:16:13 +00:00
|
|
|
|
var field_value = field.get_value ? field.get_value() : field.value;
|
2011-04-11 17:36:43 +00:00
|
|
|
|
var op = ex[1];
|
|
|
|
|
var val = ex[2];
|
|
|
|
|
|
|
|
|
|
switch (op.toLowerCase()) {
|
|
|
|
|
case '=':
|
|
|
|
|
case '==':
|
2011-08-10 15:42:38 +00:00
|
|
|
|
stack.push(field_value == val);
|
2011-04-11 17:36:43 +00:00
|
|
|
|
break;
|
|
|
|
|
case '!=':
|
|
|
|
|
case '<>':
|
2011-08-10 15:42:38 +00:00
|
|
|
|
stack.push(field_value != val);
|
2011-04-11 17:36:43 +00:00
|
|
|
|
break;
|
|
|
|
|
case '<':
|
2011-08-10 15:42:38 +00:00
|
|
|
|
stack.push(field_value < val);
|
2011-04-11 17:36:43 +00:00
|
|
|
|
break;
|
|
|
|
|
case '>':
|
2011-08-10 15:42:38 +00:00
|
|
|
|
stack.push(field_value > val);
|
2011-04-11 17:36:43 +00:00
|
|
|
|
break;
|
|
|
|
|
case '<=':
|
2011-08-10 15:42:38 +00:00
|
|
|
|
stack.push(field_value <= val);
|
2011-04-11 17:36:43 +00:00
|
|
|
|
break;
|
|
|
|
|
case '>=':
|
2011-08-10 15:42:38 +00:00
|
|
|
|
stack.push(field_value >= val);
|
2011-04-11 17:36:43 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'in':
|
2012-01-16 13:25:54 +00:00
|
|
|
|
if (!_.isArray(val)) val = [val];
|
2011-08-10 15:42:38 +00:00
|
|
|
|
stack.push(_(val).contains(field_value));
|
2011-04-11 17:36:43 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'not in':
|
2012-01-16 13:25:54 +00:00
|
|
|
|
if (!_.isArray(val)) val = [val];
|
2011-08-10 15:42:38 +00:00
|
|
|
|
stack.push(!_(val).contains(field_value));
|
2011-04-11 17:36:43 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2012-02-03 08:48:52 +00:00
|
|
|
|
console.warn(
|
|
|
|
|
_t("Unsupported operator %s in domain %s"),
|
|
|
|
|
op, JSON.stringify(expr));
|
2011-04-11 17:36:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-07-14 14:29:58 +00:00
|
|
|
|
return _.all(stack, _.identity);
|
2011-05-17 09:35:03 +00:00
|
|
|
|
};
|
2011-05-11 14:49:10 +00:00
|
|
|
|
|
2012-03-26 16:29:34 +00:00
|
|
|
|
/**
|
2012-04-19 13:43:41 +00:00
|
|
|
|
* Must be applied over an class already possessing the PropertiesMixin.
|
2012-03-26 16:29:34 +00:00
|
|
|
|
*
|
|
|
|
|
* Apply the result of the "invisible" domain to this.$element.
|
|
|
|
|
*/
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.InvisibilityChangerMixin = {
|
2012-03-26 16:29:34 +00:00
|
|
|
|
init: function(field_manager, invisible_domain) {
|
|
|
|
|
this._ic_field_manager = field_manager
|
|
|
|
|
this._ic_invisible_modifier = invisible_domain;
|
|
|
|
|
this._ic_field_manager.on("view_content_has_changed", this, function() {
|
|
|
|
|
var result = this._ic_invisible_modifier === undefined ? false :
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.compute_domain(this._ic_invisible_modifier, this._ic_field_manager.fields);
|
2012-03-26 16:29:34 +00:00
|
|
|
|
this.set({"invisible": result});
|
|
|
|
|
});
|
|
|
|
|
this.set({invisible: this._ic_invisible_modifier === true});
|
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
var check_visibility = function() {
|
|
|
|
|
if (this.get("invisible")) {
|
|
|
|
|
this.$element.hide();
|
|
|
|
|
} else {
|
|
|
|
|
this.$element.show();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
this.on("change:invisible", this, check_visibility);
|
|
|
|
|
_.bind(check_visibility, this)();
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2012-04-19 13:43:41 +00:00
|
|
|
|
instance.web.form.InvisibilityChanger = instance.web.Class.extend(_.extend({}, instance.web.PropertiesMixin, instance.web.form.InvisibilityChangerMixin, {
|
2012-03-26 16:29:34 +00:00
|
|
|
|
init: function(parent, field_manager, invisible_domain, $element) {
|
|
|
|
|
this.setParent(parent);
|
2012-04-19 13:43:41 +00:00
|
|
|
|
instance.web.PropertiesMixin.init.call(this);
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.InvisibilityChangerMixin.init.call(this, field_manager, invisible_domain);
|
2012-03-26 16:29:34 +00:00
|
|
|
|
this.$element = $element;
|
|
|
|
|
this.start();
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.Widget = instance.web.Widget.extend(_.extend({}, instance.web.form.InvisibilityChangerMixin, {
|
2011-09-12 11:43:50 +00:00
|
|
|
|
/**
|
2012-04-17 12:09:49 +00:00
|
|
|
|
* @constructs instance.web.form.Widget
|
|
|
|
|
* @extends instance.web.Widget
|
2011-09-12 11:43:50 +00:00
|
|
|
|
*
|
|
|
|
|
* @param view
|
|
|
|
|
* @param node
|
|
|
|
|
*/
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
2012-03-26 16:29:34 +00:00
|
|
|
|
this._super(view);
|
2011-03-30 14:00:48 +00:00
|
|
|
|
this.view = view;
|
|
|
|
|
this.node = node;
|
2011-07-07 10:37:40 +00:00
|
|
|
|
this.modifiers = JSON.parse(this.node.attrs.modifiers || '{}');
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.InvisibilityChangerMixin.init.call(this, view, this.modifiers.invisible);
|
2011-08-31 12:45:38 +00:00
|
|
|
|
|
2012-03-26 14:41:29 +00:00
|
|
|
|
this.view.on("view_content_has_changed", this, this.process_modifiers);
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2012-03-29 09:55:24 +00:00
|
|
|
|
renderElement: function() {
|
|
|
|
|
this._super();
|
|
|
|
|
this.$element.addClass(this.node.attrs["class"] || "");
|
|
|
|
|
},
|
2012-03-26 16:29:34 +00:00
|
|
|
|
start: function() {
|
|
|
|
|
this._super();
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.InvisibilityChangerMixin.start.call(this);
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2012-02-21 16:29:12 +00:00
|
|
|
|
destroy: function() {
|
2012-02-09 13:59:39 +00:00
|
|
|
|
$.fn.tipsy.clear();
|
2012-03-26 16:29:34 +00:00
|
|
|
|
this._super.apply(this, arguments);
|
2012-01-26 14:37:34 +00:00
|
|
|
|
},
|
2011-07-07 10:37:40 +00:00
|
|
|
|
process_modifiers: function() {
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var compute_domain = instance.web.form.compute_domain;
|
2012-03-20 15:51:11 +00:00
|
|
|
|
var to_set = {};
|
2011-07-07 10:37:40 +00:00
|
|
|
|
for (var a in this.modifiers) {
|
2012-03-26 16:29:34 +00:00
|
|
|
|
if (!_.include(["invisible"], a)) {
|
|
|
|
|
var val = compute_domain(this.modifiers[a], this.view.fields);
|
|
|
|
|
to_set[a] = val;
|
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
2012-03-20 15:51:11 +00:00
|
|
|
|
this.set(to_set);
|
2011-10-13 09:38:14 +00:00
|
|
|
|
},
|
2011-11-14 20:59:16 +00:00
|
|
|
|
do_attach_tooltip: function(widget, trigger, options) {
|
|
|
|
|
widget = widget || this;
|
|
|
|
|
trigger = trigger || this.$element;
|
|
|
|
|
options = _.extend({
|
2012-01-26 13:24:41 +00:00
|
|
|
|
delayIn: 500,
|
|
|
|
|
delayOut: 0,
|
|
|
|
|
fade: true,
|
|
|
|
|
title: function() {
|
2012-03-15 16:21:07 +00:00
|
|
|
|
var template = widget.template + '.tooltip';
|
2011-11-14 20:59:16 +00:00
|
|
|
|
if (!QWeb.has_template(template)) {
|
|
|
|
|
template = 'WidgetLabel.tooltip';
|
|
|
|
|
}
|
|
|
|
|
return QWeb.render(template, {
|
2012-04-17 12:09:49 +00:00
|
|
|
|
debug: instance.connection.debug,
|
2011-11-14 20:59:16 +00:00
|
|
|
|
widget: widget
|
2012-01-26 13:24:41 +00:00
|
|
|
|
})},
|
2012-02-09 10:54:01 +00:00
|
|
|
|
gravity: $.fn.tipsy.autoBounds(50, 'nw'),
|
2012-01-26 13:24:41 +00:00
|
|
|
|
html: true,
|
|
|
|
|
opacity: 0.85,
|
|
|
|
|
trigger: 'hover'
|
2011-11-14 20:59:16 +00:00
|
|
|
|
}, options || {});
|
2012-01-26 13:24:41 +00:00
|
|
|
|
trigger.tipsy(options);
|
2011-11-14 20:59:16 +00:00
|
|
|
|
},
|
2012-01-03 17:17:13 +00:00
|
|
|
|
_build_view_fields_values: function(blacklist) {
|
2011-10-13 09:38:14 +00:00
|
|
|
|
var a_dataset = this.view.dataset;
|
2012-01-03 17:17:13 +00:00
|
|
|
|
var fields_values = this.view.get_fields_values(blacklist);
|
2011-11-15 13:29:14 +00:00
|
|
|
|
var active_id = a_dataset.ids[a_dataset.index];
|
|
|
|
|
_.extend(fields_values, {
|
|
|
|
|
active_id: active_id || false,
|
|
|
|
|
active_ids: active_id ? [active_id] : [],
|
|
|
|
|
active_model: a_dataset.model,
|
2011-12-19 17:30:55 +00:00
|
|
|
|
parent: {}
|
2011-11-15 13:29:14 +00:00
|
|
|
|
});
|
2011-12-19 17:30:55 +00:00
|
|
|
|
if (a_dataset.parent_view) {
|
|
|
|
|
fields_values.parent = a_dataset.parent_view.get_fields_values([a_dataset.child_name]);
|
|
|
|
|
}
|
2011-10-13 09:38:14 +00:00
|
|
|
|
return fields_values;
|
|
|
|
|
},
|
2012-01-03 17:17:13 +00:00
|
|
|
|
_build_eval_context: function(blacklist) {
|
2011-10-13 09:38:14 +00:00
|
|
|
|
var a_dataset = this.view.dataset;
|
2012-04-17 12:09:49 +00:00
|
|
|
|
return new instance.web.CompoundContext(a_dataset.get_context(), this._build_view_fields_values(blacklist));
|
2011-10-13 09:38:14 +00:00
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Builds a new context usable for operations related to fields by merging
|
|
|
|
|
* the fields'context with the action's context.
|
|
|
|
|
*/
|
2012-01-03 17:17:13 +00:00
|
|
|
|
build_context: function(blacklist) {
|
2012-01-10 14:20:55 +00:00
|
|
|
|
// only use the model's context if there is not context on the node
|
|
|
|
|
var v_context = this.node.attrs.context;
|
|
|
|
|
if (! v_context) {
|
|
|
|
|
v_context = (this.field || {}).context || {};
|
2011-10-13 09:38:14 +00:00
|
|
|
|
}
|
2012-01-10 14:20:55 +00:00
|
|
|
|
|
|
|
|
|
if (v_context.__ref || true) { //TODO: remove true
|
2012-01-03 17:17:13 +00:00
|
|
|
|
var fields_values = this._build_eval_context(blacklist);
|
2012-04-17 12:09:49 +00:00
|
|
|
|
v_context = new instance.web.CompoundContext(v_context).set_eval_context(fields_values);
|
2011-10-13 09:38:14 +00:00
|
|
|
|
}
|
2012-01-10 14:20:55 +00:00
|
|
|
|
return v_context;
|
2011-10-13 09:38:14 +00:00
|
|
|
|
},
|
|
|
|
|
build_domain: function() {
|
|
|
|
|
var f_domain = this.field.domain || [];
|
|
|
|
|
var n_domain = this.node.attrs.domain || null;
|
|
|
|
|
// if there is a domain on the node, overrides the model's domain
|
|
|
|
|
var final_domain = n_domain !== null ? n_domain : f_domain;
|
2012-01-03 17:17:13 +00:00
|
|
|
|
if (!(final_domain instanceof Array) || true) { //TODO: remove true
|
2011-10-13 09:38:14 +00:00
|
|
|
|
var fields_values = this._build_eval_context();
|
2012-04-17 12:09:49 +00:00
|
|
|
|
final_domain = new instance.web.CompoundDomain(final_domain).set_eval_context(fields_values);
|
2011-10-13 09:38:14 +00:00
|
|
|
|
}
|
|
|
|
|
return final_domain;
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
2012-03-26 16:29:34 +00:00
|
|
|
|
}));
|
2011-07-11 14:48:51 +00:00
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.WidgetButton = instance.web.form.Widget.extend({
|
2012-03-13 15:58:52 +00:00
|
|
|
|
template: 'WidgetButton',
|
2011-03-30 14:00:48 +00:00
|
|
|
|
init: function(view, node) {
|
|
|
|
|
this._super(view, node);
|
2011-09-30 16:15:06 +00:00
|
|
|
|
this.force_disabled = false;
|
2012-03-14 17:09:49 +00:00
|
|
|
|
this.string = (this.node.attrs.string || '').replace(/_/g, '');
|
|
|
|
|
if (this.node.attrs.default_focus == '1') {
|
2011-06-20 18:25:49 +00:00
|
|
|
|
// TODO fme: provide enter key binding to widgets
|
|
|
|
|
this.view.default_focus_button = this;
|
|
|
|
|
}
|
2012-04-18 12:20:39 +00:00
|
|
|
|
this.view.on('view_content_has_changed', this, this.check_disable);
|
2011-04-11 15:59:46 +00:00
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
2012-03-13 17:46:19 +00:00
|
|
|
|
this.$element.click(this.on_click);
|
2012-04-17 12:09:49 +00:00
|
|
|
|
if (this.node.attrs.help || instance.connection.debug) {
|
2011-11-14 20:59:16 +00:00
|
|
|
|
this.do_attach_tooltip();
|
|
|
|
|
}
|
2011-04-11 15:59:46 +00:00
|
|
|
|
},
|
2011-09-26 12:39:29 +00:00
|
|
|
|
on_click: function() {
|
2011-09-30 16:15:06 +00:00
|
|
|
|
var self = this;
|
|
|
|
|
this.force_disabled = true;
|
|
|
|
|
this.check_disable();
|
|
|
|
|
this.execute_action().always(function() {
|
|
|
|
|
self.force_disabled = false;
|
|
|
|
|
self.check_disable();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
execute_action: function() {
|
2011-04-11 15:59:46 +00:00
|
|
|
|
var self = this;
|
2011-09-26 12:39:29 +00:00
|
|
|
|
var exec_action = function() {
|
|
|
|
|
if (self.node.attrs.confirm) {
|
2011-09-30 16:15:06 +00:00
|
|
|
|
var def = $.Deferred();
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var dialog = instance.web.dialog($('<div/>').text(self.node.attrs.confirm), {
|
2011-12-15 10:06:52 +00:00
|
|
|
|
title: _t('Confirm'),
|
2011-04-11 15:59:46 +00:00
|
|
|
|
modal: true,
|
2011-12-15 10:40:31 +00:00
|
|
|
|
buttons: [
|
2012-01-17 15:33:33 +00:00
|
|
|
|
{text: _t("Cancel"), click: function() {
|
|
|
|
|
def.resolve();
|
|
|
|
|
$(this).dialog("close");
|
|
|
|
|
}
|
|
|
|
|
},
|
2011-12-15 10:40:31 +00:00
|
|
|
|
{text: _t("Ok"), click: function() {
|
|
|
|
|
self.on_confirmed().then(function() {
|
|
|
|
|
def.resolve();
|
|
|
|
|
});
|
|
|
|
|
$(this).dialog("close");
|
|
|
|
|
}
|
2011-04-11 15:59:46 +00:00
|
|
|
|
}
|
2011-12-15 10:40:31 +00:00
|
|
|
|
]
|
2011-04-11 15:59:46 +00:00
|
|
|
|
});
|
2011-09-30 16:15:06 +00:00
|
|
|
|
return def.promise();
|
2011-04-11 15:59:46 +00:00
|
|
|
|
} else {
|
2011-09-30 16:15:06 +00:00
|
|
|
|
return self.on_confirmed();
|
2011-04-11 15:59:46 +00:00
|
|
|
|
}
|
2011-09-26 12:39:29 +00:00
|
|
|
|
};
|
2011-10-12 14:10:07 +00:00
|
|
|
|
if (!this.node.attrs.special) {
|
2012-04-18 15:18:44 +00:00
|
|
|
|
this.view.force_dirty = true;
|
2011-09-30 16:15:06 +00:00
|
|
|
|
return this.view.recursive_save().pipe(exec_action);
|
2011-09-26 12:39:29 +00:00
|
|
|
|
} else {
|
2011-09-30 16:15:06 +00:00
|
|
|
|
return exec_action();
|
2011-04-11 15:59:46 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
on_confirmed: function() {
|
2011-05-04 09:12:33 +00:00
|
|
|
|
var self = this;
|
2011-10-19 12:50:34 +00:00
|
|
|
|
|
2011-10-13 09:38:14 +00:00
|
|
|
|
var context = this.node.attrs.context;
|
|
|
|
|
if (context && context.__ref) {
|
2012-04-17 12:09:49 +00:00
|
|
|
|
context = new instance.web.CompoundContext(context);
|
2011-10-13 09:38:14 +00:00
|
|
|
|
context.set_eval_context(this._build_eval_context());
|
|
|
|
|
}
|
2011-05-04 09:12:33 +00:00
|
|
|
|
|
2011-09-30 16:15:06 +00:00
|
|
|
|
return this.view.do_execute_action(
|
2011-10-13 09:38:14 +00:00
|
|
|
|
_.extend({}, this.node.attrs, {context: context}),
|
|
|
|
|
this.view.dataset, this.view.datarecord.id, function () {
|
2011-06-28 10:30:49 +00:00
|
|
|
|
self.view.reload();
|
2011-04-12 15:09:55 +00:00
|
|
|
|
});
|
2011-09-30 15:46:12 +00:00
|
|
|
|
},
|
2011-09-30 16:15:06 +00:00
|
|
|
|
check_disable: function() {
|
2012-03-20 15:51:11 +00:00
|
|
|
|
var disabled = (this.force_disabled || !this.view.is_interactible_record());
|
2012-03-13 17:46:19 +00:00
|
|
|
|
this.$element.prop('disabled', disabled);
|
|
|
|
|
this.$element.css('color', disabled ? 'grey' : '');
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2012-03-15 16:43:26 +00:00
|
|
|
|
/**
|
|
|
|
|
* Interface implemented by the form view or any other object
|
|
|
|
|
* able to provide the features necessary for the fields to work.
|
|
|
|
|
*
|
|
|
|
|
* Properties:
|
2012-04-18 13:05:40 +00:00
|
|
|
|
* - display_invalid_fields : if true, all fields where is_valid() return true should
|
|
|
|
|
* be displayed as invalid.
|
2012-03-26 14:41:29 +00:00
|
|
|
|
* Events:
|
|
|
|
|
* - view_content_has_changed : when the values of the fields have changed. When
|
|
|
|
|
* this event is triggered all fields should reprocess their modifiers.
|
2012-03-15 16:43:26 +00:00
|
|
|
|
*/
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldManagerInterface = {
|
2012-04-17 13:33:07 +00:00
|
|
|
|
/**
|
|
|
|
|
* Must return the asked field as in fields_get.
|
|
|
|
|
*/
|
|
|
|
|
get_field: function(field_name) {},
|
|
|
|
|
/**
|
|
|
|
|
* Called by the field when the translate button is clicked.
|
|
|
|
|
*/
|
|
|
|
|
open_translate_dialog: function(field) {},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns true when the view is in create mode.
|
|
|
|
|
*/
|
|
|
|
|
is_create_mode: function() {},
|
2012-03-15 16:43:26 +00:00
|
|
|
|
};
|
2011-03-30 14:00:48 +00:00
|
|
|
|
|
2012-03-13 16:37:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* Interface to be implemented by fields.
|
|
|
|
|
*
|
2012-03-15 16:43:26 +00:00
|
|
|
|
* Properties:
|
|
|
|
|
* - readonly: boolean. If set to true the field should appear in readonly mode.
|
2012-03-20 16:18:06 +00:00
|
|
|
|
* - force_readonly: boolean, When it is true, the field should always appear
|
|
|
|
|
* in read only mode, no matter what the value of the "readonly" property can be.
|
2012-03-15 16:43:26 +00:00
|
|
|
|
* Events:
|
2012-04-18 13:05:40 +00:00
|
|
|
|
* - changed_value: triggered to inform the view to check on_changes
|
2012-03-13 16:37:19 +00:00
|
|
|
|
*
|
|
|
|
|
*/
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldInterface = {
|
2012-03-15 16:43:26 +00:00
|
|
|
|
/**
|
|
|
|
|
* Constructor takes 2 arguments:
|
|
|
|
|
* - field_manager: Implements FieldManagerInterface
|
|
|
|
|
* - node: the "<field>" node in json form
|
|
|
|
|
*/
|
|
|
|
|
init: function(field_manager, node) {},
|
2012-03-13 16:37:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* Called by the form view to indicate the value of the field.
|
|
|
|
|
*
|
|
|
|
|
* set_value() may return an object that can be passed to $.when() that represents the moment when
|
|
|
|
|
* the field has finished all operations necessary before the user can effectively use the widget.
|
|
|
|
|
*
|
|
|
|
|
* Multiple calls to set_value() can occur at any time and must be handled correctly by the implementation,
|
|
|
|
|
* regardless of any asynchronous operation currently running and the status of any promise that a
|
|
|
|
|
* previous call to set_value() could have returned.
|
|
|
|
|
*
|
|
|
|
|
* set_value() must be able, at any moment, to handle the syntax returned by the "read" method of the
|
|
|
|
|
* osv class in the OpenERP server as well as the syntax used by the set_value() (see below). It must
|
|
|
|
|
* also be able to handle any other format commonly used in the _defaults key on the models in the addons
|
|
|
|
|
* as well as any format commonly returned in a on_change. It must be able to autodetect those formats as
|
|
|
|
|
* no information is ever given to know which format is used.
|
|
|
|
|
*/
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {},
|
2012-03-13 16:37:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get the current value of the widget.
|
|
|
|
|
*
|
|
|
|
|
* Must always return a syntaxically correct value to be passed to the "write" method of the osv class in
|
|
|
|
|
* the OpenERP server, although it is not assumed to respect the constraints applied to the field.
|
|
|
|
|
* For example if the field is marqued as "required", a call to get_value() can return false.
|
|
|
|
|
*
|
|
|
|
|
* get_value() can also be called *before* a call to set_value() and, in that case, is supposed to
|
|
|
|
|
* return a defaut value according to the type of field.
|
|
|
|
|
*
|
|
|
|
|
* This method is always assumed to perform synchronously, it can not return a promise.
|
|
|
|
|
*
|
|
|
|
|
* If there was no user interaction to modify the value of the field, it is always assumed that
|
|
|
|
|
* get_value() return the same semantic value than the one passed in the last call to set_value(),
|
|
|
|
|
* altough the syntax can be different. This can be the case for type of fields that have a different
|
|
|
|
|
* syntax for "read" and "write" (example: m2o: set_value([0, "Administrator"]), get_value() => 0).
|
|
|
|
|
*/
|
|
|
|
|
get_value: function() {},
|
2012-03-27 12:47:04 +00:00
|
|
|
|
/**
|
|
|
|
|
* Inform the current object of the id it should use to match a html <label> that exists somewhere in the
|
|
|
|
|
* view.
|
|
|
|
|
*/
|
2012-04-18 11:50:04 +00:00
|
|
|
|
set_input_id: function(id) {},
|
2012-04-18 13:05:40 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns true if is_syntax_valid() returns true and the value is semantically
|
|
|
|
|
* valid too according to the semantic restrictions applied to the field.
|
|
|
|
|
*/
|
2012-04-18 11:50:04 +00:00
|
|
|
|
is_valid: function() {},
|
2012-04-18 13:05:40 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns true if the field holds a value which is syntaxically correct, ignoring
|
|
|
|
|
* the potential semantic restrictions applied to the field.
|
|
|
|
|
*/
|
2012-04-18 11:50:04 +00:00
|
|
|
|
is_syntax_valid: function() {},
|
2012-04-18 13:05:40 +00:00
|
|
|
|
/**
|
|
|
|
|
* Must set the focus on the field.
|
|
|
|
|
*/
|
2012-04-18 12:37:04 +00:00
|
|
|
|
focus: function() {},
|
2012-03-13 16:37:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2012-03-16 10:23:44 +00:00
|
|
|
|
* Abstract class for classes implementing FieldInterface.
|
2012-03-15 16:43:26 +00:00
|
|
|
|
*
|
|
|
|
|
* Properties:
|
|
|
|
|
* - effective_readonly: when it is true, the widget is displayed as readonly. Vary depending
|
|
|
|
|
* the values of the "readonly" property and the "force_readonly" property on the field manager.
|
2012-04-18 13:05:40 +00:00
|
|
|
|
* - value: useful property to hold the value of the field. By default, set_value() and get_value()
|
|
|
|
|
* set and retrieve the value property. Changing the value property also triggers automatically
|
|
|
|
|
* a 'changed_value' event that inform the view to trigger on_changes.
|
2012-03-15 16:43:26 +00:00
|
|
|
|
*
|
2012-03-13 16:37:19 +00:00
|
|
|
|
*/
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.AbstractField = instance.web.form.Widget.extend(/** @lends instance.web.form.AbstractField# */{
|
2011-09-12 11:43:50 +00:00
|
|
|
|
/**
|
2012-04-17 12:09:49 +00:00
|
|
|
|
* @constructs instance.web.form.AbstractField
|
|
|
|
|
* @extends instance.web.form.Widget
|
2011-09-12 11:43:50 +00:00
|
|
|
|
*
|
2012-03-15 16:43:26 +00:00
|
|
|
|
* @param field_manager
|
2011-09-12 11:43:50 +00:00
|
|
|
|
* @param node
|
|
|
|
|
*/
|
2012-03-15 16:43:26 +00:00
|
|
|
|
init: function(field_manager, node) {
|
|
|
|
|
this._super(field_manager, node);
|
2012-04-17 13:33:07 +00:00
|
|
|
|
this.field_manager = field_manager;
|
2012-03-14 17:09:49 +00:00
|
|
|
|
this.name = this.node.attrs.name;
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this.set({'value': false});
|
2012-04-17 13:33:07 +00:00
|
|
|
|
this.field = this.field_manager.get_field(this.name);
|
2012-03-27 13:02:54 +00:00
|
|
|
|
this.set({required: this.modifiers['required'] === true});
|
2012-03-15 16:43:26 +00:00
|
|
|
|
|
|
|
|
|
// some events to make the property "effective_readonly" sync automatically with "readonly" and
|
|
|
|
|
// "force_readonly"
|
|
|
|
|
this.set({"readonly": this.modifiers['readonly'] === true});
|
|
|
|
|
var test_effective_readonly = function() {
|
2012-04-05 14:41:18 +00:00
|
|
|
|
this.set({"effective_readonly": this.get("readonly") || !!this.get("force_readonly")});
|
2012-03-15 16:43:26 +00:00
|
|
|
|
};
|
2012-03-20 09:58:19 +00:00
|
|
|
|
this.on("change:readonly", this, test_effective_readonly);
|
2012-03-20 16:18:06 +00:00
|
|
|
|
this.on("change:force_readonly", this, test_effective_readonly);
|
2012-03-15 16:43:26 +00:00
|
|
|
|
_.bind(test_effective_readonly, this)();
|
2012-04-17 15:45:05 +00:00
|
|
|
|
|
|
|
|
|
this.on("change:value", this, function() {
|
2012-04-18 09:57:58 +00:00
|
|
|
|
if (! this._inhibit_on_change)
|
2012-04-18 12:23:41 +00:00
|
|
|
|
this.trigger('changed_value');
|
|
|
|
|
this._check_css_flags();
|
2012-04-18 12:20:39 +00:00
|
|
|
|
});
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2011-08-24 15:13:57 +00:00
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
if (this.field.translate) {
|
2012-02-14 16:34:43 +00:00
|
|
|
|
this.$element.addClass('oe_form_field_translatable');
|
2012-04-18 12:37:04 +00:00
|
|
|
|
this.$element.find('.oe_field_translate').click(_.bind(function() {
|
|
|
|
|
this.field_manager.open_translate_dialog(this);
|
|
|
|
|
}, this));
|
2011-08-24 15:13:57 +00:00
|
|
|
|
}
|
2012-04-17 13:33:07 +00:00
|
|
|
|
if (instance.connection.debug) {
|
2012-01-26 13:24:41 +00:00
|
|
|
|
this.do_attach_tooltip(this, this.$element);
|
2011-11-14 20:59:16 +00:00
|
|
|
|
}
|
2012-03-27 13:02:54 +00:00
|
|
|
|
if (!this.disable_utility_classes) {
|
|
|
|
|
var set_required = function() {
|
|
|
|
|
this.$element.toggleClass('oe_form_required', this.get("required"));
|
|
|
|
|
};
|
|
|
|
|
this.on("change:required", this, set_required);
|
|
|
|
|
_.bind(set_required, this)();
|
|
|
|
|
}
|
2011-08-24 15:13:57 +00:00
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {
|
2012-04-17 15:45:05 +00:00
|
|
|
|
this._inhibit_on_change = true;
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this.set({'value': value_});
|
2012-04-17 15:45:05 +00:00
|
|
|
|
this._inhibit_on_change = false;
|
2011-08-24 15:13:57 +00:00
|
|
|
|
},
|
2011-04-05 14:34:25 +00:00
|
|
|
|
get_value: function() {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
return this.get('value');
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2011-07-27 10:25:19 +00:00
|
|
|
|
is_valid: function() {
|
2012-04-18 09:50:43 +00:00
|
|
|
|
return this.is_syntax_valid() && (! this.get('required') || ! this.is_false());
|
2011-07-27 10:25:19 +00:00
|
|
|
|
},
|
2012-04-18 09:50:43 +00:00
|
|
|
|
is_syntax_valid: function() {
|
2012-04-18 09:16:13 +00:00
|
|
|
|
return true;
|
2011-07-27 10:25:19 +00:00
|
|
|
|
},
|
2012-04-18 13:05:40 +00:00
|
|
|
|
/**
|
|
|
|
|
* Method useful to implement to ease validity testing. Must return true if the current
|
|
|
|
|
* value is similar to false in OpenERP.
|
|
|
|
|
*/
|
2012-04-18 09:50:43 +00:00
|
|
|
|
is_false: function() {
|
|
|
|
|
return this.get('value') === false;
|
2011-06-29 16:21:36 +00:00
|
|
|
|
},
|
2012-04-18 12:23:41 +00:00
|
|
|
|
_check_css_flags: function(show_invalid) {
|
2011-08-29 14:08:39 +00:00
|
|
|
|
if (this.field.translate) {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this.$element.find('.oe_field_translate').toggle(!this.field_manager.is_create_mode());
|
2011-08-29 14:08:39 +00:00
|
|
|
|
}
|
2011-07-27 09:09:05 +00:00
|
|
|
|
if (!this.disable_utility_classes) {
|
2012-04-18 12:20:39 +00:00
|
|
|
|
if (this.field_manager.get('display_invalid_fields')) {
|
2012-03-26 12:29:50 +00:00
|
|
|
|
this.$element.toggleClass('oe_form_invalid', !this.is_valid());
|
2011-07-27 09:09:05 +00:00
|
|
|
|
}
|
2011-04-11 11:35:16 +00:00
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2012-04-18 12:37:04 +00:00
|
|
|
|
focus: function() {
|
2011-06-20 18:25:49 +00:00
|
|
|
|
},
|
2012-04-18 12:37:04 +00:00
|
|
|
|
/**
|
|
|
|
|
* Utility method to focus an element, but only after a small amount of time.
|
|
|
|
|
*/
|
|
|
|
|
delay_focus: function($elem) {
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
$elem.focus();
|
|
|
|
|
}, 50);
|
2011-12-21 15:08:31 +00:00
|
|
|
|
},
|
2012-04-18 12:37:04 +00:00
|
|
|
|
/**
|
|
|
|
|
* Utility method to get the widget options defined in the field xml description.
|
|
|
|
|
*/
|
2011-12-21 15:32:29 +00:00
|
|
|
|
get_definition_options: function() {
|
|
|
|
|
if (!this.definition_options) {
|
2011-12-21 15:08:31 +00:00
|
|
|
|
var str = this.node.attrs.options || '{}';
|
2011-12-21 15:32:29 +00:00
|
|
|
|
this.definition_options = JSON.parse(str);
|
2011-12-21 15:08:31 +00:00
|
|
|
|
}
|
2011-12-21 15:32:29 +00:00
|
|
|
|
return this.definition_options;
|
2012-03-27 12:47:04 +00:00
|
|
|
|
},
|
|
|
|
|
set_input_id: function(id) {
|
|
|
|
|
this.id_for_label = id;
|
|
|
|
|
},
|
2011-03-30 14:00:48 +00:00
|
|
|
|
});
|
|
|
|
|
|
2012-03-19 10:31:16 +00:00
|
|
|
|
/**
|
|
|
|
|
* A mixin to apply on any field that has to completely re-render when its readonly state
|
|
|
|
|
* switch.
|
|
|
|
|
*/
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.ReinitializeFieldMixin = {
|
2012-03-20 10:17:47 +00:00
|
|
|
|
/**
|
|
|
|
|
* Default implementation of start(), use it or call explicitly initialize_field().
|
|
|
|
|
*/
|
2011-03-30 14:00:48 +00:00
|
|
|
|
start: function() {
|
2012-03-20 10:17:47 +00:00
|
|
|
|
this._super();
|
|
|
|
|
this.initialize_field();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2012-03-20 10:17:47 +00:00
|
|
|
|
initialize_field: function() {
|
2012-03-16 11:22:23 +00:00
|
|
|
|
this.on("change:effective_readonly", this, function() {
|
2012-03-20 10:17:47 +00:00
|
|
|
|
this.destroy_content();
|
2012-03-19 10:06:39 +00:00
|
|
|
|
this.renderElement();
|
2012-03-20 10:17:47 +00:00
|
|
|
|
this.initialize_content();
|
2012-03-16 11:22:23 +00:00
|
|
|
|
this.render_value();
|
|
|
|
|
});
|
2012-03-20 10:17:47 +00:00
|
|
|
|
this.initialize_content();
|
2012-03-23 15:04:48 +00:00
|
|
|
|
this.render_value();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2012-03-20 10:17:47 +00:00
|
|
|
|
/**
|
|
|
|
|
* Called to destroy anything that could have been created previously, called before a
|
|
|
|
|
* re-initialization.
|
|
|
|
|
*/
|
|
|
|
|
destroy_content: function() {},
|
|
|
|
|
/**
|
|
|
|
|
* Called to initialize the content.
|
|
|
|
|
*/
|
|
|
|
|
initialize_content: function() {},
|
|
|
|
|
/**
|
|
|
|
|
* Called to render the value. Should also be explicitly called at the end of a set_value().
|
|
|
|
|
*/
|
2012-03-19 10:31:16 +00:00
|
|
|
|
render_value: function() {},
|
|
|
|
|
};
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldChar = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {
|
2012-03-19 10:31:16 +00:00
|
|
|
|
template: 'FieldChar',
|
2012-04-18 12:45:20 +00:00
|
|
|
|
init: function (field_manager, node) {
|
|
|
|
|
this._super(field_manager, node);
|
2012-03-19 10:31:16 +00:00
|
|
|
|
this.password = this.node.attrs.password === 'True' || this.node.attrs.password === '1';
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2012-03-20 10:17:47 +00:00
|
|
|
|
initialize_content: function() {
|
2012-04-17 15:45:05 +00:00
|
|
|
|
var self = this;
|
|
|
|
|
this.$element.find('input').change(function() {
|
|
|
|
|
self.set({'value': instance.web.parse_value(self.$element.find('input').val(), self)});
|
|
|
|
|
});
|
2011-04-11 11:35:16 +00:00
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {
|
2012-04-17 15:45:05 +00:00
|
|
|
|
this._super(value_);
|
2012-03-16 11:22:23 +00:00
|
|
|
|
this.render_value();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2012-03-16 11:22:23 +00:00
|
|
|
|
render_value: function() {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
var show_value = instance.web.format_value(this.get('value'), this, '');
|
2012-03-16 11:22:23 +00:00
|
|
|
|
if (!this.get("effective_readonly")) {
|
|
|
|
|
this.$element.find('input').val(show_value);
|
|
|
|
|
} else {
|
|
|
|
|
if (this.password) {
|
|
|
|
|
show_value = new Array(show_value.length + 1).join('*');
|
|
|
|
|
}
|
|
|
|
|
this.$element.text(show_value);
|
2011-04-11 11:35:16 +00:00
|
|
|
|
}
|
2011-06-20 18:25:49 +00:00
|
|
|
|
},
|
2012-04-18 09:50:43 +00:00
|
|
|
|
is_syntax_valid: function() {
|
2012-03-19 15:34:06 +00:00
|
|
|
|
if (!this.get("effective_readonly")) {
|
|
|
|
|
try {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
var value_ = instance.web.parse_value(this.$element.find('input').val(), this, '');
|
2012-04-18 09:50:43 +00:00
|
|
|
|
return true;
|
2012-03-19 15:34:06 +00:00
|
|
|
|
} catch(e) {
|
2012-04-18 09:16:13 +00:00
|
|
|
|
return false;
|
2012-03-19 15:34:06 +00:00
|
|
|
|
}
|
2011-04-11 11:35:16 +00:00
|
|
|
|
}
|
2012-04-18 09:16:13 +00:00
|
|
|
|
return true;
|
2011-06-20 18:25:49 +00:00
|
|
|
|
},
|
2012-04-18 09:50:43 +00:00
|
|
|
|
is_false: function() {
|
|
|
|
|
return this.get('value') === '';
|
|
|
|
|
},
|
2012-04-18 12:37:04 +00:00
|
|
|
|
focus: function() {
|
|
|
|
|
this.delay_focus(this.$element.find('input:first'));
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
2012-03-19 10:31:16 +00:00
|
|
|
|
}));
|
2011-03-30 14:00:48 +00:00
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldID = instance.web.form.FieldChar.extend({
|
2012-03-19 10:31:16 +00:00
|
|
|
|
|
2012-01-25 14:04:38 +00:00
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldEmail = instance.web.form.FieldChar.extend({
|
2012-03-13 20:28:23 +00:00
|
|
|
|
template: 'FieldEmail',
|
2012-03-20 10:17:47 +00:00
|
|
|
|
initialize_content: function() {
|
2012-03-16 11:33:22 +00:00
|
|
|
|
this._super();
|
2011-05-12 16:25:50 +00:00
|
|
|
|
this.$element.find('button').click(this.on_button_clicked);
|
|
|
|
|
},
|
2012-03-16 11:33:22 +00:00
|
|
|
|
render_value: function() {
|
|
|
|
|
if (!this.get("effective_readonly")) {
|
|
|
|
|
this._super();
|
|
|
|
|
} else {
|
|
|
|
|
this.$element.find('a')
|
2012-04-17 14:32:27 +00:00
|
|
|
|
.attr('href', 'mailto:' + this.get('value'))
|
|
|
|
|
.text(this.get('value'));
|
2012-03-16 11:33:22 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2011-05-12 16:25:50 +00:00
|
|
|
|
on_button_clicked: function() {
|
2012-04-18 09:50:43 +00:00
|
|
|
|
if (!this.get('value') || !this.is_syntax_valid()) {
|
2011-10-13 10:26:53 +00:00
|
|
|
|
this.do_warn("E-mail error", "Can't send email to invalid e-mail address");
|
2011-05-12 16:25:50 +00:00
|
|
|
|
} else {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
location.href = 'mailto:' + this.get('value');
|
2011-05-12 16:25:50 +00:00
|
|
|
|
}
|
2011-04-11 11:35:16 +00:00
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldUrl = instance.web.form.FieldChar.extend({
|
2012-03-13 20:28:23 +00:00
|
|
|
|
template: 'FieldUrl',
|
2012-03-20 10:17:47 +00:00
|
|
|
|
initialize_content: function() {
|
2012-03-16 11:44:24 +00:00
|
|
|
|
this._super();
|
2011-05-19 13:55:22 +00:00
|
|
|
|
this.$element.find('button').click(this.on_button_clicked);
|
|
|
|
|
},
|
2012-03-16 11:44:24 +00:00
|
|
|
|
render_value: function() {
|
|
|
|
|
if (!this.get("effective_readonly")) {
|
|
|
|
|
this._super();
|
|
|
|
|
} else {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
var tmp = this.get('value');
|
2012-03-16 11:44:24 +00:00
|
|
|
|
var s = /(\w+):(.+)/.exec(tmp);
|
|
|
|
|
if (!s) {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
tmp = "http://" + this.get('value');
|
2012-03-16 11:44:24 +00:00
|
|
|
|
}
|
|
|
|
|
this.$element.find('a').attr('href', tmp).text(tmp);
|
|
|
|
|
}
|
|
|
|
|
},
|
2011-05-19 13:55:22 +00:00
|
|
|
|
on_button_clicked: function() {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
if (!this.get('value')) {
|
2011-10-13 10:26:53 +00:00
|
|
|
|
this.do_warn("Resource error", "This resource is empty");
|
2011-05-19 13:55:22 +00:00
|
|
|
|
} else {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
var url = $.trim(this.get('value'));
|
2012-04-16 23:32:07 +00:00
|
|
|
|
if(/^www\./i.test(url))
|
|
|
|
|
url = 'http://'+url;
|
|
|
|
|
window.open(url);
|
2011-05-19 13:55:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldFloat = instance.web.form.FieldChar.extend({
|
2012-03-29 10:20:48 +00:00
|
|
|
|
is_field_number: true,
|
2012-04-18 12:45:20 +00:00
|
|
|
|
init: function (field_manager, node) {
|
|
|
|
|
this._super(field_manager, node);
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this.set({'value': 0});
|
2012-03-14 17:09:49 +00:00
|
|
|
|
if (this.node.attrs.digits) {
|
2012-03-27 15:13:57 +00:00
|
|
|
|
this.digits = py.eval(node.attrs.digits);
|
2011-10-21 12:22:56 +00:00
|
|
|
|
} else {
|
2012-03-13 20:28:23 +00:00
|
|
|
|
this.digits = this.field.digits;
|
2011-10-21 12:22:56 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {
|
|
|
|
|
if (value_ === false || value_ === undefined) {
|
2011-05-09 15:19:23 +00:00
|
|
|
|
// As in GTK client, floats default to 0
|
2012-04-17 14:32:27 +00:00
|
|
|
|
value_ = 0;
|
2011-05-09 15:19:23 +00:00
|
|
|
|
}
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this._super.apply(this, [value_]);
|
2011-07-07 08:55:15 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.DateTimeWidget = instance.web.OldWidget.extend({
|
2011-09-21 10:41:36 +00:00
|
|
|
|
template: "web.datetimepicker",
|
|
|
|
|
jqueryui_object: 'datetimepicker',
|
|
|
|
|
type_of_date: "datetime",
|
2011-11-16 22:27:05 +00:00
|
|
|
|
init: function(parent) {
|
|
|
|
|
this._super(parent);
|
|
|
|
|
this.name = parent.name;
|
|
|
|
|
},
|
2011-04-05 14:34:25 +00:00
|
|
|
|
start: function() {
|
2011-09-14 15:46:10 +00:00
|
|
|
|
var self = this;
|
2011-11-16 22:27:05 +00:00
|
|
|
|
this.$input = this.$element.find('input.oe_datepicker_master');
|
|
|
|
|
this.$input_picker = this.$element.find('input.oe_datepicker_container');
|
|
|
|
|
this.$input.change(this.on_change);
|
2011-09-14 15:46:10 +00:00
|
|
|
|
this.picker({
|
|
|
|
|
onSelect: this.on_picker_select,
|
|
|
|
|
changeMonth: true,
|
|
|
|
|
changeYear: true,
|
|
|
|
|
showWeek: true,
|
2011-11-16 22:27:05 +00:00
|
|
|
|
showButtonPanel: true
|
2011-09-14 15:46:10 +00:00
|
|
|
|
});
|
|
|
|
|
this.$element.find('img.oe_datepicker_trigger').click(function() {
|
2012-03-20 15:51:11 +00:00
|
|
|
|
if (!self.get("effective_readonly") && !self.picker('widget').is(':visible')) {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
self.picker('setDate', self.get('value') ? instance.web.auto_str_to_date(self.get('value')) : new Date());
|
2011-11-16 22:27:05 +00:00
|
|
|
|
self.$input_picker.show();
|
|
|
|
|
self.picker('show');
|
|
|
|
|
self.$input_picker.hide();
|
2011-09-14 15:46:10 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2011-09-21 11:50:54 +00:00
|
|
|
|
this.set_readonly(false);
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this.set({'value': false});
|
2011-05-12 10:36:01 +00:00
|
|
|
|
},
|
2011-09-14 15:46:10 +00:00
|
|
|
|
picker: function() {
|
2011-11-16 22:27:05 +00:00
|
|
|
|
return $.fn[this.jqueryui_object].apply(this.$input_picker, arguments);
|
2011-09-14 15:46:10 +00:00
|
|
|
|
},
|
2012-04-17 11:43:58 +00:00
|
|
|
|
on_picker_select: function(text, instance_) {
|
2011-09-14 15:46:10 +00:00
|
|
|
|
var date = this.picker('getDate');
|
2011-11-16 22:27:05 +00:00
|
|
|
|
this.$input.val(date ? this.format_client(date) : '').change();
|
2011-09-14 15:46:10 +00:00
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {
|
|
|
|
|
this.set({'value': value_});
|
|
|
|
|
this.$input.val(value_ ? this.format_client(value_) : '');
|
2011-09-14 15:46:10 +00:00
|
|
|
|
},
|
|
|
|
|
get_value: function() {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
return this.get('value');
|
2011-05-12 10:36:01 +00:00
|
|
|
|
},
|
2012-04-17 15:45:05 +00:00
|
|
|
|
set_value_from_ui_: function() {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
var value_ = this.$input.val() || false;
|
|
|
|
|
this.set({'value': this.parse_client(value_)});
|
2011-05-12 10:36:01 +00:00
|
|
|
|
},
|
2011-09-21 10:41:36 +00:00
|
|
|
|
set_readonly: function(readonly) {
|
|
|
|
|
this.readonly = readonly;
|
2012-02-13 16:31:20 +00:00
|
|
|
|
this.$input.prop('readonly', this.readonly);
|
2011-09-21 10:41:36 +00:00
|
|
|
|
this.$element.find('img.oe_datepicker_trigger').toggleClass('oe_input_icon_disabled', readonly);
|
2011-06-30 09:40:53 +00:00
|
|
|
|
},
|
2012-04-18 09:50:43 +00:00
|
|
|
|
is_valid_: function() {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
var value_ = this.$input.val();
|
|
|
|
|
if (value_ === "") {
|
2012-03-26 14:31:12 +00:00
|
|
|
|
return true;
|
2011-06-30 12:10:08 +00:00
|
|
|
|
} else {
|
2011-09-14 15:46:10 +00:00
|
|
|
|
try {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this.parse_client(value_);
|
2011-09-21 10:41:36 +00:00
|
|
|
|
return true;
|
2011-09-14 15:46:10 +00:00
|
|
|
|
} catch(e) {
|
2011-09-21 10:41:36 +00:00
|
|
|
|
return false;
|
2011-09-14 15:46:10 +00:00
|
|
|
|
}
|
2011-06-30 12:10:08 +00:00
|
|
|
|
}
|
2011-05-12 10:36:01 +00:00
|
|
|
|
},
|
2011-09-14 15:46:10 +00:00
|
|
|
|
parse_client: function(v) {
|
2012-04-17 12:09:49 +00:00
|
|
|
|
return instance.web.parse_value(v, {"widget": this.type_of_date});
|
2011-09-14 15:46:10 +00:00
|
|
|
|
},
|
|
|
|
|
format_client: function(v) {
|
2012-04-17 12:09:49 +00:00
|
|
|
|
return instance.web.format_value(v, {"widget": this.type_of_date});
|
2011-09-21 10:41:36 +00:00
|
|
|
|
},
|
|
|
|
|
on_change: function() {
|
2012-04-18 09:50:43 +00:00
|
|
|
|
if (this.is_valid_()) {
|
2012-04-17 15:45:05 +00:00
|
|
|
|
this.set_value_from_ui_();
|
2011-09-21 10:41:36 +00:00
|
|
|
|
}
|
2011-09-01 15:22:24 +00:00
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.DateWidget = instance.web.DateTimeWidget.extend({
|
2011-09-21 10:41:36 +00:00
|
|
|
|
jqueryui_object: 'datepicker',
|
2011-11-16 22:27:05 +00:00
|
|
|
|
type_of_date: "date"
|
2011-03-30 14:00:48 +00:00
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldDatetime = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {
|
2012-03-15 16:21:07 +00:00
|
|
|
|
template: "EmptyComponent",
|
2011-09-21 10:41:36 +00:00
|
|
|
|
build_widget: function() {
|
2012-04-17 12:09:49 +00:00
|
|
|
|
return new instance.web.DateTimeWidget(this);
|
2011-09-21 10:41:36 +00:00
|
|
|
|
},
|
2012-03-20 10:17:47 +00:00
|
|
|
|
destroy_content: function() {
|
2012-03-19 15:10:45 +00:00
|
|
|
|
if (this.datewidget) {
|
2012-03-20 09:58:19 +00:00
|
|
|
|
this.datewidget.destroy();
|
2012-03-19 15:10:45 +00:00
|
|
|
|
this.datewidget = undefined;
|
|
|
|
|
}
|
2011-09-21 10:41:36 +00:00
|
|
|
|
},
|
2012-03-20 10:17:47 +00:00
|
|
|
|
initialize_content: function() {
|
2012-03-19 15:10:45 +00:00
|
|
|
|
if (!this.get("effective_readonly")) {
|
|
|
|
|
this.datewidget = this.build_widget();
|
2012-04-17 15:45:05 +00:00
|
|
|
|
this.datewidget.on_change.add_last(_.bind(function() {
|
|
|
|
|
this.set({'value': this.datewidget.get_value()});
|
|
|
|
|
}, this));
|
2012-03-19 15:10:45 +00:00
|
|
|
|
this.datewidget.appendTo(this.$element);
|
|
|
|
|
}
|
2011-09-21 10:41:36 +00:00
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {
|
|
|
|
|
this._super(value_);
|
2012-03-19 15:10:45 +00:00
|
|
|
|
this.render_value();
|
2011-09-21 10:41:36 +00:00
|
|
|
|
},
|
2012-03-19 15:10:45 +00:00
|
|
|
|
render_value: function() {
|
|
|
|
|
if (!this.get("effective_readonly")) {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this.datewidget.set_value(this.get('value'));
|
2012-03-19 15:10:45 +00:00
|
|
|
|
} else {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this.$element.text(instance.web.format_value(this.get('value'), this, ''));
|
2012-03-19 15:10:45 +00:00
|
|
|
|
}
|
2011-09-21 10:41:36 +00:00
|
|
|
|
},
|
2012-04-18 09:50:43 +00:00
|
|
|
|
is_syntax_valid: function() {
|
2012-03-26 14:31:12 +00:00
|
|
|
|
if (!this.get("effective_readonly")) {
|
2012-04-18 09:50:43 +00:00
|
|
|
|
return this.datewidget.is_valid_();
|
2012-03-26 14:31:12 +00:00
|
|
|
|
}
|
2012-04-18 09:16:13 +00:00
|
|
|
|
return true;
|
2011-09-21 10:41:36 +00:00
|
|
|
|
},
|
2012-04-18 09:50:43 +00:00
|
|
|
|
is_false: function() {
|
|
|
|
|
return this.get('value') === '';
|
2011-09-21 10:41:36 +00:00
|
|
|
|
},
|
2012-04-18 12:37:04 +00:00
|
|
|
|
focus: function() {
|
|
|
|
|
if (this.datewidget && this.datewidget.$input)
|
|
|
|
|
this.delay_focus(this.datewidget.$input);
|
2011-09-21 10:41:36 +00:00
|
|
|
|
}
|
2012-03-19 15:10:45 +00:00
|
|
|
|
}));
|
2011-09-21 10:41:36 +00:00
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldDate = instance.web.form.FieldDatetime.extend({
|
2011-09-21 10:41:36 +00:00
|
|
|
|
build_widget: function() {
|
2012-04-17 12:09:49 +00:00
|
|
|
|
return new instance.web.DateWidget(this);
|
2011-09-21 10:41:36 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldText = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {
|
2012-03-13 20:28:23 +00:00
|
|
|
|
template: 'FieldText',
|
2012-03-20 10:17:47 +00:00
|
|
|
|
initialize_content: function() {
|
2012-04-18 16:10:47 +00:00
|
|
|
|
this.$textarea = this.$element.find('textarea');
|
2011-12-21 17:16:02 +00:00
|
|
|
|
this.resized = false;
|
2012-03-19 15:18:23 +00:00
|
|
|
|
if (!this.get("effective_readonly")) {
|
2012-04-17 15:45:05 +00:00
|
|
|
|
this.$textarea.change(_.bind(function() {
|
|
|
|
|
this.set({'value': instance.web.parse_value(this.$textarea.val(), this)});
|
|
|
|
|
}, this));
|
2012-04-18 16:10:47 +00:00
|
|
|
|
} else {
|
|
|
|
|
this.$textarea.attr('disabled', 'disabled');
|
2012-03-19 15:18:23 +00:00
|
|
|
|
}
|
2011-04-05 09:55:49 +00:00
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {
|
2011-04-05 09:55:49 +00:00
|
|
|
|
this._super.apply(this, arguments);
|
2012-03-19 15:18:23 +00:00
|
|
|
|
this.render_value();
|
2011-04-05 09:55:49 +00:00
|
|
|
|
},
|
2012-03-19 15:18:23 +00:00
|
|
|
|
render_value: function() {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
var show_value = instance.web.format_value(this.get('value'), this, '');
|
2012-04-18 16:10:47 +00:00
|
|
|
|
this.$textarea.val(show_value);
|
2011-12-21 17:16:02 +00:00
|
|
|
|
if (!this.resized && this.view.options.resize_textareas) {
|
|
|
|
|
this.do_resize(this.view.options.resize_textareas);
|
|
|
|
|
this.resized = true;
|
|
|
|
|
}
|
2011-04-05 09:55:49 +00:00
|
|
|
|
},
|
2012-04-18 09:50:43 +00:00
|
|
|
|
is_syntax_valid: function() {
|
2012-03-19 15:18:23 +00:00
|
|
|
|
if (!this.get("effective_readonly")) {
|
|
|
|
|
try {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
var value_ = instance.web.parse_value(this.$textarea.val(), this, '');
|
2012-04-18 09:50:43 +00:00
|
|
|
|
return true;
|
2012-03-19 15:18:23 +00:00
|
|
|
|
} catch(e) {
|
2012-04-18 09:16:13 +00:00
|
|
|
|
return false;
|
2012-03-19 15:18:23 +00:00
|
|
|
|
}
|
2011-04-11 11:35:16 +00:00
|
|
|
|
}
|
2012-04-18 09:16:13 +00:00
|
|
|
|
return true;
|
2011-06-20 18:25:49 +00:00
|
|
|
|
},
|
2012-04-18 09:50:43 +00:00
|
|
|
|
is_false: function() {
|
|
|
|
|
return this.get('value') === '';
|
2011-06-20 18:25:49 +00:00
|
|
|
|
},
|
2012-01-12 15:15:27 +00:00
|
|
|
|
focus: function($element) {
|
2012-04-18 12:37:04 +00:00
|
|
|
|
this.delay_focus(this.$textarea);
|
2011-12-21 17:16:02 +00:00
|
|
|
|
},
|
|
|
|
|
do_resize: function(max_height) {
|
|
|
|
|
max_height = parseInt(max_height, 10);
|
2012-03-13 20:28:23 +00:00
|
|
|
|
var $input = this.$textarea,
|
2011-12-21 17:16:02 +00:00
|
|
|
|
$div = $('<div style="position: absolute; z-index: 1000; top: 0"/>').width($input.width()),
|
|
|
|
|
new_height;
|
|
|
|
|
$div.text($input.val());
|
|
|
|
|
_.each('font-family,font-size,white-space'.split(','), function(style) {
|
|
|
|
|
$div.css(style, $input.css(style));
|
|
|
|
|
});
|
2012-01-04 15:53:29 +00:00
|
|
|
|
$div.appendTo($('body'));
|
2011-12-21 17:16:02 +00:00
|
|
|
|
new_height = $div.height();
|
|
|
|
|
if (new_height < 90) {
|
|
|
|
|
new_height = 90;
|
|
|
|
|
}
|
|
|
|
|
if (!isNaN(max_height) && new_height > max_height) {
|
|
|
|
|
new_height = max_height;
|
|
|
|
|
}
|
|
|
|
|
$div.remove();
|
|
|
|
|
$input.height(new_height);
|
|
|
|
|
},
|
2012-03-19 15:18:23 +00:00
|
|
|
|
}));
|
2011-03-30 14:00:48 +00:00
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldBoolean = instance.web.form.AbstractField.extend({
|
2012-03-13 20:28:23 +00:00
|
|
|
|
template: 'FieldBoolean',
|
2011-04-05 09:55:49 +00:00
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
2012-03-16 11:52:43 +00:00
|
|
|
|
this.$checkbox = $("input", this.$element);
|
2012-04-17 15:45:05 +00:00
|
|
|
|
this.$element.click(_.bind(function() {
|
|
|
|
|
this.set({'value': this.$checkbox.is(':checked')});
|
|
|
|
|
}, this));
|
2012-03-16 11:52:43 +00:00
|
|
|
|
var check_readonly = function() {
|
|
|
|
|
this.$checkbox.prop('disabled', this.get("effective_readonly"));
|
|
|
|
|
};
|
|
|
|
|
this.on("change:effective_readonly", this, check_readonly);
|
|
|
|
|
_.bind(check_readonly, this)();
|
2011-04-11 11:35:16 +00:00
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {
|
2011-04-05 14:34:25 +00:00
|
|
|
|
this._super.apply(this, arguments);
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this.$checkbox[0].checked = value_;
|
2011-04-05 14:34:25 +00:00
|
|
|
|
},
|
2012-04-18 12:37:04 +00:00
|
|
|
|
focus: function() {
|
|
|
|
|
this.delay_focus(this.$checkbox);
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldProgressBar = instance.web.form.AbstractField.extend({
|
2012-03-15 16:21:07 +00:00
|
|
|
|
template: 'FieldProgressBar',
|
2011-04-12 09:26:31 +00:00
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
2012-03-15 16:21:07 +00:00
|
|
|
|
this.$element.progressbar({
|
2012-04-17 14:32:27 +00:00
|
|
|
|
value: this.get('value'),
|
2012-03-20 15:51:11 +00:00
|
|
|
|
disabled: this.get("effective_readonly")
|
2011-04-12 09:26:31 +00:00
|
|
|
|
});
|
2011-05-09 14:10:01 +00:00
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {
|
2011-05-09 14:10:01 +00:00
|
|
|
|
this._super.apply(this, arguments);
|
2012-04-17 14:32:27 +00:00
|
|
|
|
var show_value = Number(value_);
|
2011-07-04 12:10:57 +00:00
|
|
|
|
if (isNaN(show_value)) {
|
2011-05-09 14:10:01 +00:00
|
|
|
|
show_value = 0;
|
|
|
|
|
}
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var formatted_value = instance.web.format_value(show_value, { type : 'float' }, '0');
|
2012-03-15 16:21:07 +00:00
|
|
|
|
this.$element.progressbar('option', 'value', show_value).find('span').html(formatted_value + '%');
|
2011-04-12 09:26:31 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldTextXml = instance.web.form.AbstractField.extend({
|
2011-03-30 14:00:48 +00:00
|
|
|
|
// to replace view editor
|
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldSelection = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {
|
2012-03-13 17:46:19 +00:00
|
|
|
|
template: 'FieldSelection',
|
2012-04-18 12:45:20 +00:00
|
|
|
|
init: function(field_manager, node) {
|
2011-09-07 16:33:15 +00:00
|
|
|
|
var self = this;
|
2012-04-18 12:45:20 +00:00
|
|
|
|
this._super(field_manager, node);
|
2011-11-24 13:46:27 +00:00
|
|
|
|
this.values = _.clone(this.field.selection);
|
2011-09-07 16:33:15 +00:00
|
|
|
|
_.each(this.values, function(v, i) {
|
|
|
|
|
if (v[0] === false && v[1] === '') {
|
|
|
|
|
self.values.splice(i, 1);
|
|
|
|
|
}
|
2011-07-07 14:19:24 +00:00
|
|
|
|
});
|
2011-09-07 16:33:15 +00:00
|
|
|
|
this.values.unshift([false, '']);
|
2011-03-30 14:00:48 +00:00
|
|
|
|
},
|
2012-03-20 10:17:47 +00:00
|
|
|
|
initialize_content: function() {
|
2011-07-08 12:38:53 +00:00
|
|
|
|
// Flag indicating whether we're in an event chain containing a change
|
|
|
|
|
// event on the select, in order to know what to do on keyup[RETURN]:
|
|
|
|
|
// * If the user presses [RETURN] as part of changing the value of a
|
|
|
|
|
// selection, we should just let the value change and not let the
|
|
|
|
|
// event broadcast further (e.g. to validating the current state of
|
|
|
|
|
// the form in editable list view, which would lead to saving the
|
|
|
|
|
// current row or switching to the next one)
|
|
|
|
|
// * If the user presses [RETURN] with a select closed (side-effect:
|
|
|
|
|
// also if the user opened the select and pressed [RETURN] without
|
|
|
|
|
// changing the selected value), takes the action as validating the
|
|
|
|
|
// row
|
|
|
|
|
var ischanging = false;
|
|
|
|
|
this.$element.find('select')
|
2012-04-17 15:45:05 +00:00
|
|
|
|
.change(_.bind(function() {
|
|
|
|
|
this.set({'value': this.values[this.$element.find('select')[0].selectedIndex][0]});
|
|
|
|
|
}, this))
|
2011-07-08 12:38:53 +00:00
|
|
|
|
.change(function () { ischanging = true; })
|
|
|
|
|
.click(function () { ischanging = false; })
|
|
|
|
|
.keyup(function (e) {
|
|
|
|
|
if (e.which !== 13 || !ischanging) { return; }
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
ischanging = false;
|
|
|
|
|
});
|
2011-04-05 14:34:25 +00:00
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {
|
|
|
|
|
value_ = value_ === null ? false : value_;
|
|
|
|
|
value_ = value_ instanceof Array ? value_[0] : value_;
|
|
|
|
|
this._super(value_);
|
2012-03-16 12:23:31 +00:00
|
|
|
|
this.render_value();
|
2011-04-11 11:35:16 +00:00
|
|
|
|
},
|
2012-03-16 12:23:31 +00:00
|
|
|
|
render_value: function() {
|
|
|
|
|
if (!this.get("effective_readonly")) {
|
|
|
|
|
var index = 0;
|
|
|
|
|
for (var i = 0, ii = this.values.length; i < ii; i++) {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
if (this.values[i][0] === this.get('value')) index = i;
|
2012-03-16 12:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
this.$element.find('select')[0].selectedIndex = index;
|
|
|
|
|
} else {
|
|
|
|
|
var self = this;
|
|
|
|
|
var option = _(this.values)
|
2012-04-17 14:32:27 +00:00
|
|
|
|
.detect(function (record) { return record[0] === self.get('value'); });
|
2012-03-16 12:23:31 +00:00
|
|
|
|
this.$element.text(option ? option[1] : this.values[0][1]);
|
2011-09-07 16:33:15 +00:00
|
|
|
|
}
|
2011-04-05 14:34:25 +00:00
|
|
|
|
},
|
2012-04-18 09:50:43 +00:00
|
|
|
|
is_syntax_valid: function() {
|
2012-03-16 12:23:31 +00:00
|
|
|
|
if (this.get("effective_readonly")) {
|
2012-04-18 09:16:13 +00:00
|
|
|
|
return true;
|
2012-03-16 12:23:31 +00:00
|
|
|
|
}
|
2012-04-17 14:32:27 +00:00
|
|
|
|
var value_ = this.values[this.$element.find('select')[0].selectedIndex];
|
2012-04-18 09:50:43 +00:00
|
|
|
|
return !! value_;
|
2011-06-20 18:25:49 +00:00
|
|
|
|
},
|
2012-04-18 12:37:04 +00:00
|
|
|
|
focus: function() {
|
|
|
|
|
this.delay_focus(this.$element.find('select:first'));
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
2012-03-19 10:31:16 +00:00
|
|
|
|
}));
|
2011-03-30 14:00:48 +00:00
|
|
|
|
|
2011-06-10 13:22:37 +00:00
|
|
|
|
// jquery autocomplete tweak to allow html
|
2011-06-20 14:43:48 +00:00
|
|
|
|
(function() {
|
2011-06-10 13:22:37 +00:00
|
|
|
|
var proto = $.ui.autocomplete.prototype,
|
|
|
|
|
initSource = proto._initSource;
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-10 13:22:37 +00:00
|
|
|
|
function filter( array, term ) {
|
|
|
|
|
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
|
2012-04-17 14:32:27 +00:00
|
|
|
|
return $.grep( array, function(value_) {
|
|
|
|
|
return matcher.test( $( "<div>" ).html( value_.label || value_.value || value_ ).text() );
|
2011-06-10 13:22:37 +00:00
|
|
|
|
});
|
2011-06-10 10:31:55 +00:00
|
|
|
|
}
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-10 13:22:37 +00:00
|
|
|
|
$.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 );
|
|
|
|
|
}
|
|
|
|
|
},
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-10 13:22:37 +00:00
|
|
|
|
_renderItem: function( ul, item) {
|
|
|
|
|
return $( "<li></li>" )
|
|
|
|
|
.data( "item.autocomplete", item )
|
|
|
|
|
.append( $( "<a></a>" )[ this.options.html ? "html" : "text" ]( item.label ) )
|
|
|
|
|
.appendTo( ul );
|
|
|
|
|
}
|
|
|
|
|
});
|
2011-06-20 14:43:48 +00:00
|
|
|
|
})();
|
2011-06-10 10:31:55 +00:00
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.dialog = function(content, options) {
|
2011-07-14 10:09:33 +00:00
|
|
|
|
options = _.extend({
|
|
|
|
|
width: '90%',
|
2012-01-10 14:51:29 +00:00
|
|
|
|
height: 'auto',
|
2012-01-10 15:21:10 +00:00
|
|
|
|
min_width: '800px'
|
2011-07-14 10:09:33 +00:00
|
|
|
|
}, options || {});
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var dialog = new instance.web.Dialog(null, options, content).open();
|
2012-01-11 11:06:48 +00:00
|
|
|
|
return dialog.$element;
|
2011-09-06 08:58:53 +00:00
|
|
|
|
};
|
2011-07-14 10:09:33 +00:00
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {
|
2012-03-20 10:26:50 +00:00
|
|
|
|
template: "FieldMany2One",
|
2012-04-18 12:45:20 +00:00
|
|
|
|
init: function(field_manager, node) {
|
|
|
|
|
this._super(field_manager, node);
|
2011-06-06 16:50:43 +00:00
|
|
|
|
this.limit = 7;
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this.set({'value': false});
|
2012-04-05 14:41:18 +00:00
|
|
|
|
this.display_value = {};
|
2011-06-10 13:22:37 +00:00
|
|
|
|
this.last_search = [];
|
2012-04-05 14:41:18 +00:00
|
|
|
|
this.floating = false;
|
2012-04-05 14:53:22 +00:00
|
|
|
|
this.inhibit_on_change = false;
|
2012-04-19 09:15:52 +00:00
|
|
|
|
this.orderer = new instance.web.DropMisordered();
|
2011-04-27 12:20:51 +00:00
|
|
|
|
},
|
|
|
|
|
start: function() {
|
2011-06-06 16:50:43 +00:00
|
|
|
|
this._super();
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.ReinitializeFieldMixin.start.call(this);
|
2012-04-05 14:41:18 +00:00
|
|
|
|
this.on("change:value", this, function() {
|
|
|
|
|
this.floating = false;
|
|
|
|
|
this.render_value();
|
|
|
|
|
});
|
2012-03-16 09:54:59 +00:00
|
|
|
|
},
|
2012-03-20 10:26:50 +00:00
|
|
|
|
initialize_content: function() {
|
2012-03-15 16:43:26 +00:00
|
|
|
|
if (!this.get("effective_readonly"))
|
2012-03-13 15:14:35 +00:00
|
|
|
|
this.render_editable();
|
|
|
|
|
this.render_value();
|
|
|
|
|
},
|
|
|
|
|
render_editable: function() {
|
2011-06-06 16:50:43 +00:00
|
|
|
|
var self = this;
|
|
|
|
|
this.$input = this.$element.find("input");
|
2012-04-05 12:44:33 +00:00
|
|
|
|
|
|
|
|
|
self.$input.tipsy({
|
|
|
|
|
title: function() {
|
|
|
|
|
return "No element was selected, you should create or select one from the dropdown list.";
|
|
|
|
|
},
|
|
|
|
|
trigger:'manual',
|
|
|
|
|
fade: true,
|
|
|
|
|
});
|
|
|
|
|
|
2011-06-10 14:58:01 +00:00
|
|
|
|
this.$drop_down = this.$element.find(".oe-m2o-drop-down-button");
|
2012-04-05 13:12:18 +00:00
|
|
|
|
this.$follow_button = $(".oe-m2o-cm-button", this.$element);
|
2012-04-05 12:07:18 +00:00
|
|
|
|
|
|
|
|
|
this.$follow_button.click(function() {
|
2012-04-05 14:41:18 +00:00
|
|
|
|
if (!self.get('value')) {
|
2012-04-05 12:07:18 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var pop = new instance.web.form.FormOpenPopup(self.view);
|
2012-04-05 12:07:18 +00:00
|
|
|
|
pop.show_element(
|
|
|
|
|
self.field.relation,
|
2012-04-05 14:41:18 +00:00
|
|
|
|
self.get("value"),
|
2012-04-05 12:07:18 +00:00
|
|
|
|
self.build_context(),
|
|
|
|
|
{
|
|
|
|
|
title: _t("Open: ") + (self.string || self.name)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
pop.on_write_completed.add_last(function() {
|
2012-04-05 14:41:18 +00:00
|
|
|
|
self.display_value = {};
|
|
|
|
|
self.render_value();
|
2011-08-25 14:21:26 +00:00
|
|
|
|
});
|
2011-06-10 13:22:37 +00:00
|
|
|
|
});
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-10 10:31:55 +00:00
|
|
|
|
// some behavior for input
|
|
|
|
|
this.$input.keyup(function() {
|
2011-06-08 15:29:44 +00:00
|
|
|
|
if (self.$input.val() === "") {
|
2012-04-05 14:41:18 +00:00
|
|
|
|
self.set({value: false});
|
|
|
|
|
} else {
|
|
|
|
|
self.floating = true;
|
2011-06-08 15:29:44 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2011-06-09 17:36:44 +00:00
|
|
|
|
this.$drop_down.click(function() {
|
2011-06-08 15:47:44 +00:00
|
|
|
|
if (self.$input.autocomplete("widget").is(":visible")) {
|
2011-06-08 15:29:44 +00:00
|
|
|
|
self.$input.autocomplete("close");
|
|
|
|
|
} else {
|
2012-04-05 14:41:18 +00:00
|
|
|
|
if (self.get("value") && ! self.floating) {
|
2011-06-10 13:55:26 +00:00
|
|
|
|
self.$input.autocomplete("search", "");
|
|
|
|
|
} else {
|
|
|
|
|
self.$input.autocomplete("search");
|
|
|
|
|
}
|
2011-06-08 15:47:44 +00:00
|
|
|
|
self.$input.focus();
|
2011-06-08 15:29:44 +00:00
|
|
|
|
}
|
2011-06-06 16:50:43 +00:00
|
|
|
|
});
|
2012-04-05 12:44:33 +00:00
|
|
|
|
var tip_def = $.Deferred();
|
|
|
|
|
var untip_def = $.Deferred();
|
|
|
|
|
var tip_delay = 200;
|
|
|
|
|
var tip_duration = 3000;
|
2011-06-10 13:22:37 +00:00
|
|
|
|
var anyoneLoosesFocus = function() {
|
2012-04-05 14:41:18 +00:00
|
|
|
|
if (self.floating) {
|
|
|
|
|
if (self.last_search.length > 0) {
|
|
|
|
|
if (self.last_search[0][0] != self.get("value")) {
|
|
|
|
|
self.display_value = {};
|
|
|
|
|
self.display_value["" + self.last_search[0][0]] = self.last_search[0][1];
|
|
|
|
|
self.set({value: self.last_search[0][0]});
|
|
|
|
|
} else {
|
|
|
|
|
self.render_value();
|
|
|
|
|
}
|
2011-06-10 13:22:37 +00:00
|
|
|
|
} else {
|
2012-04-05 14:41:18 +00:00
|
|
|
|
self.set({value: false});
|
2011-06-10 13:22:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-05 14:41:18 +00:00
|
|
|
|
if (! self.get("value")) {
|
2012-04-05 12:44:33 +00:00
|
|
|
|
tip_def.reject();
|
|
|
|
|
untip_def.reject();
|
|
|
|
|
tip_def = $.Deferred();
|
|
|
|
|
tip_def.then(function() {
|
|
|
|
|
self.$input.tipsy("show");
|
|
|
|
|
});
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
tip_def.resolve();
|
|
|
|
|
untip_def.reject();
|
|
|
|
|
untip_def = $.Deferred();
|
|
|
|
|
untip_def.then(function() {
|
|
|
|
|
self.$input.tipsy("hide");
|
|
|
|
|
});
|
|
|
|
|
setTimeout(function() {untip_def.resolve();}, tip_duration);
|
|
|
|
|
}, tip_delay);
|
|
|
|
|
} else {
|
|
|
|
|
tip_def.reject();
|
|
|
|
|
}
|
2011-09-06 08:58:53 +00:00
|
|
|
|
};
|
2011-06-10 13:22:37 +00:00
|
|
|
|
this.$input.focusout(anyoneLoosesFocus);
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-07-12 14:16:10 +00:00
|
|
|
|
var isSelecting = false;
|
2011-06-10 10:31:55 +00:00
|
|
|
|
// autocomplete
|
2011-06-06 16:50:43 +00:00
|
|
|
|
this.$input.autocomplete({
|
2011-06-08 15:29:44 +00:00
|
|
|
|
source: function(req, resp) { self.get_search_result(req, resp); },
|
2011-06-09 13:20:04 +00:00
|
|
|
|
select: function(event, ui) {
|
2011-07-12 14:16:10 +00:00
|
|
|
|
isSelecting = true;
|
2011-06-08 15:29:44 +00:00
|
|
|
|
var item = ui.item;
|
|
|
|
|
if (item.id) {
|
2012-04-05 14:41:18 +00:00
|
|
|
|
self.display_value = {};
|
|
|
|
|
self.display_value["" + item.id] = item.name;
|
|
|
|
|
self.set({value: item.id});
|
2011-06-08 15:29:44 +00:00
|
|
|
|
} else if (item.action) {
|
2012-04-05 14:41:18 +00:00
|
|
|
|
self.floating = true;
|
2011-06-08 15:29:44 +00:00
|
|
|
|
item.action();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-06-10 10:31:55 +00:00
|
|
|
|
},
|
2011-06-10 12:15:45 +00:00
|
|
|
|
focus: function(e, ui) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
},
|
2011-06-10 13:22:37 +00:00
|
|
|
|
html: true,
|
2011-06-10 13:55:26 +00:00
|
|
|
|
close: anyoneLoosesFocus,
|
2011-06-10 13:58:35 +00:00
|
|
|
|
minLength: 0,
|
|
|
|
|
delay: 0
|
2011-06-06 16:50:43 +00:00
|
|
|
|
});
|
2012-02-17 13:45:23 +00:00
|
|
|
|
this.$input.autocomplete("widget").addClass("openerp");
|
2011-07-12 14:16:10 +00:00
|
|
|
|
// used to correct a bug when selecting an element by pushing 'enter' in an editable list
|
|
|
|
|
this.$input.keyup(function(e) {
|
|
|
|
|
if (e.which === 13) {
|
|
|
|
|
if (isSelecting)
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
isSelecting = false;
|
|
|
|
|
});
|
2011-06-06 16:50:43 +00:00
|
|
|
|
},
|
2011-06-10 10:31:55 +00:00
|
|
|
|
// autocomplete component content handling
|
2011-06-06 16:50:43 +00:00
|
|
|
|
get_search_result: function(request, response) {
|
|
|
|
|
var search_val = request.term;
|
|
|
|
|
var self = this;
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2012-04-19 08:12:13 +00:00
|
|
|
|
var dataset = new instance.web.DataSet(this, this.field.relation, self.build_context());
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2012-03-02 08:39:41 +00:00
|
|
|
|
this.orderer.add(dataset.name_search(
|
|
|
|
|
search_val, self.build_domain(), 'ilike', this.limit + 1)).then(function(data) {
|
2011-07-15 09:55:27 +00:00
|
|
|
|
self.last_search = data;
|
2011-06-10 10:31:55 +00:00
|
|
|
|
// possible selections for the m2o
|
2011-07-15 09:55:27 +00:00
|
|
|
|
var values = _.map(data, function(x) {
|
2012-01-31 09:02:26 +00:00
|
|
|
|
return {
|
|
|
|
|
label: _.str.escapeHTML(x[1]),
|
|
|
|
|
value:x[1],
|
|
|
|
|
name:x[1],
|
|
|
|
|
id:x[0]
|
|
|
|
|
};
|
2011-06-06 16:50:43 +00:00
|
|
|
|
});
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-15 09:54:07 +00:00
|
|
|
|
// search more... if more results that max
|
2011-06-09 13:20:04 +00:00
|
|
|
|
if (values.length > self.limit) {
|
|
|
|
|
values = values.slice(0, self.limit);
|
2011-08-16 07:54:05 +00:00
|
|
|
|
values.push({label: _t("<em> Search More...</em>"), action: function() {
|
2011-06-30 13:07:13 +00:00
|
|
|
|
dataset.name_search(search_val, self.build_domain(), 'ilike'
|
2011-06-28 17:18:52 +00:00
|
|
|
|
, false, function(data) {
|
2011-07-15 09:55:27 +00:00
|
|
|
|
self._search_create_popup("search", data);
|
2011-06-09 13:20:04 +00:00
|
|
|
|
});
|
|
|
|
|
}});
|
2011-06-06 16:50:43 +00:00
|
|
|
|
}
|
2011-06-15 09:54:07 +00:00
|
|
|
|
// quick create
|
2011-09-06 08:58:53 +00:00
|
|
|
|
var raw_result = _(data.result).map(function(x) {return x[1];});
|
2011-06-14 08:10:46 +00:00
|
|
|
|
if (search_val.length > 0 &&
|
|
|
|
|
!_.include(raw_result, search_val) &&
|
2012-04-05 14:41:18 +00:00
|
|
|
|
(!self.get("value") || self.floating)) {
|
2011-11-15 12:30:59 +00:00
|
|
|
|
values.push({label: _.str.sprintf(_t('<em> Create "<strong>%s</strong>"</em>'),
|
2011-08-16 07:54:05 +00:00
|
|
|
|
$('<span />').text(search_val).html()), action: function() {
|
2011-06-10 16:16:29 +00:00
|
|
|
|
self._quick_create(search_val);
|
2011-06-10 10:31:55 +00:00
|
|
|
|
}});
|
|
|
|
|
}
|
2011-06-15 09:54:07 +00:00
|
|
|
|
// create...
|
2011-08-16 07:54:05 +00:00
|
|
|
|
values.push({label: _t("<em> Create and Edit...</em>"), action: function() {
|
2011-07-04 15:05:54 +00:00
|
|
|
|
self._search_create_popup("form", undefined, {"default_name": search_val});
|
2011-06-09 13:20:04 +00:00
|
|
|
|
}});
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-06-06 16:50:43 +00:00
|
|
|
|
response(values);
|
|
|
|
|
});
|
2011-04-05 09:20:50 +00:00
|
|
|
|
},
|
2011-06-10 16:16:29 +00:00
|
|
|
|
_quick_create: function(name) {
|
|
|
|
|
var self = this;
|
2012-01-25 08:53:10 +00:00
|
|
|
|
var slow_create = function () {
|
2011-06-17 14:19:45 +00:00
|
|
|
|
self._search_create_popup("form", undefined, {"default_name": name});
|
2012-01-25 08:53:10 +00:00
|
|
|
|
};
|
2011-12-21 15:32:29 +00:00
|
|
|
|
if (self.get_definition_options().quick_create === undefined || self.get_definition_options().quick_create) {
|
2012-04-19 08:12:13 +00:00
|
|
|
|
new instance.web.DataSet(this, this.field.relation, self.build_context())
|
2012-03-01 16:04:52 +00:00
|
|
|
|
.name_create(name, function(data) {
|
2012-04-19 08:12:13 +00:00
|
|
|
|
self.display_value = {};
|
|
|
|
|
self.display_value["" + data[0]] = data[1];
|
|
|
|
|
self.set({value: data[0]});
|
2012-03-01 16:04:52 +00:00
|
|
|
|
}).fail(function(error, event) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
slow_create();
|
|
|
|
|
});
|
2011-12-21 15:08:31 +00:00
|
|
|
|
} else
|
|
|
|
|
slow_create();
|
2011-06-10 16:16:29 +00:00
|
|
|
|
},
|
2011-06-10 10:31:55 +00:00
|
|
|
|
// all search/create popup handling
|
2011-06-17 14:19:45 +00:00
|
|
|
|
_search_create_popup: function(view, ids, context) {
|
2011-06-09 17:08:51 +00:00
|
|
|
|
var self = this;
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var pop = new instance.web.form.SelectCreatePopup(this);
|
2011-12-22 09:40:12 +00:00
|
|
|
|
pop.select_element(
|
|
|
|
|
self.field.relation,
|
|
|
|
|
{
|
|
|
|
|
title: (view === 'search' ? _t("Search: ") : _t("Create: ")) + (this.string || this.name),
|
2011-06-15 15:04:40 +00:00
|
|
|
|
initial_ids: ids ? _.map(ids, function(x) {return x[0]}) : undefined,
|
|
|
|
|
initial_view: view,
|
|
|
|
|
disable_multiple_selection: true
|
2011-12-22 09:40:12 +00:00
|
|
|
|
},
|
|
|
|
|
self.build_domain(),
|
2012-04-17 12:09:49 +00:00
|
|
|
|
new instance.web.CompoundContext(self.build_context(), context || {})
|
2011-12-22 09:40:12 +00:00
|
|
|
|
);
|
2011-06-15 15:04:40 +00:00
|
|
|
|
pop.on_select_elements.add(function(element_ids) {
|
2012-04-05 14:41:18 +00:00
|
|
|
|
self.set({value: element_ids[0]});
|
2011-06-09 17:08:51 +00:00
|
|
|
|
});
|
|
|
|
|
},
|
2012-04-05 14:41:18 +00:00
|
|
|
|
render_value: function(no_recurse) {
|
|
|
|
|
var self = this;
|
|
|
|
|
if (! this.get("value")) {
|
|
|
|
|
this.display_string("");
|
|
|
|
|
return;
|
2011-06-28 16:22:06 +00:00
|
|
|
|
}
|
2012-04-05 14:41:18 +00:00
|
|
|
|
var display = this.display_value["" + this.get("value")];
|
|
|
|
|
if (display) {
|
|
|
|
|
this.display_string(display);
|
2011-06-28 16:22:06 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2012-04-05 14:41:18 +00:00
|
|
|
|
if (! no_recurse) {
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var dataset = new instance.web.DataSetStatic(this, this.field.relation, self.view.dataset.get_context());
|
2012-04-05 14:41:18 +00:00
|
|
|
|
dataset.name_get([self.get("value")], function(data) {
|
|
|
|
|
self.display_value["" + self.get("value")] = data[0][1];
|
|
|
|
|
self.render_value(true);
|
|
|
|
|
});
|
2011-04-05 14:34:25 +00:00
|
|
|
|
}
|
2011-05-03 08:50:44 +00:00
|
|
|
|
},
|
2012-04-05 14:41:18 +00:00
|
|
|
|
display_string: function(str) {
|
2011-06-23 12:40:16 +00:00
|
|
|
|
var self = this;
|
2012-03-15 16:43:26 +00:00
|
|
|
|
if (!this.get("effective_readonly")) {
|
2012-04-05 14:41:18 +00:00
|
|
|
|
this.$input.val(str);
|
2011-06-23 12:40:16 +00:00
|
|
|
|
} else {
|
2012-04-05 14:41:18 +00:00
|
|
|
|
this.$element.find('a')
|
2012-03-13 15:14:35 +00:00
|
|
|
|
.unbind('click')
|
2012-04-05 14:41:18 +00:00
|
|
|
|
.text(str)
|
2012-03-13 15:14:35 +00:00
|
|
|
|
.click(function () {
|
|
|
|
|
self.do_action({
|
|
|
|
|
type: 'ir.actions.act_window',
|
|
|
|
|
res_model: self.field.relation,
|
2012-04-05 14:41:18 +00:00
|
|
|
|
res_id: self.get("value"),
|
2012-03-13 15:14:35 +00:00
|
|
|
|
context: self.build_context(),
|
2012-04-09 21:30:43 +00:00
|
|
|
|
views: [[false, 'form']],
|
2012-03-13 15:14:35 +00:00
|
|
|
|
target: 'current'
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
});
|
2011-06-10 14:58:01 +00:00
|
|
|
|
}
|
2011-08-25 17:04:10 +00:00
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {
|
2011-08-25 17:04:10 +00:00
|
|
|
|
var self = this;
|
2012-04-17 14:32:27 +00:00
|
|
|
|
if (value_ instanceof Array) {
|
2012-04-05 14:41:18 +00:00
|
|
|
|
this.display_value = {};
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this.display_value["" + value_[0]] = value_[1];
|
|
|
|
|
value_ = value_[0];
|
2011-06-23 12:40:16 +00:00
|
|
|
|
}
|
2012-04-17 14:32:27 +00:00
|
|
|
|
value_ = value_ || false;
|
2012-04-05 14:53:22 +00:00
|
|
|
|
this.inhibit_on_change = true;
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this._super(value_);
|
2012-04-05 14:53:22 +00:00
|
|
|
|
this.inhibit_on_change = false;
|
2011-10-06 12:04:25 +00:00
|
|
|
|
},
|
2012-04-18 09:50:43 +00:00
|
|
|
|
is_false: function() {
|
|
|
|
|
return ! this.get("value");
|
2011-10-24 15:20:56 +00:00
|
|
|
|
},
|
2012-04-18 12:37:04 +00:00
|
|
|
|
focus: function () {
|
|
|
|
|
this.delay_focus(this.$input);
|
2011-06-10 13:29:26 +00:00
|
|
|
|
}
|
2012-03-20 10:26:50 +00:00
|
|
|
|
}));
|
2011-03-30 14:00:48 +00:00
|
|
|
|
|
2011-06-21 12:12:22 +00:00
|
|
|
|
/*
|
|
|
|
|
# Values: (0, 0, { fields }) create
|
|
|
|
|
# (1, ID, { fields }) update
|
|
|
|
|
# (2, ID) remove (delete)
|
|
|
|
|
# (3, ID) unlink one (target id or target of relation)
|
|
|
|
|
# (4, ID) link
|
|
|
|
|
# (5) unlink all (only valid for one2many)
|
|
|
|
|
*/
|
2011-06-28 08:22:55 +00:00
|
|
|
|
var commands = {
|
|
|
|
|
// (0, _, {values})
|
|
|
|
|
CREATE: 0,
|
2011-06-28 08:30:50 +00:00
|
|
|
|
'create': function (values) {
|
|
|
|
|
return [commands.CREATE, false, values];
|
|
|
|
|
},
|
2011-06-28 08:22:55 +00:00
|
|
|
|
// (1, id, {values})
|
|
|
|
|
UPDATE: 1,
|
2011-06-28 08:30:50 +00:00
|
|
|
|
'update': function (id, values) {
|
|
|
|
|
return [commands.UPDATE, id, values];
|
|
|
|
|
},
|
2011-06-28 08:22:55 +00:00
|
|
|
|
// (2, id[, _])
|
|
|
|
|
DELETE: 2,
|
2011-06-28 08:30:50 +00:00
|
|
|
|
'delete': function (id) {
|
|
|
|
|
return [commands.DELETE, id, false];
|
|
|
|
|
},
|
2011-06-28 08:22:55 +00:00
|
|
|
|
// (3, id[, _]) removes relation, but not linked record itself
|
|
|
|
|
FORGET: 3,
|
2011-06-28 08:30:50 +00:00
|
|
|
|
'forget': function (id) {
|
|
|
|
|
return [commands.FORGET, id, false];
|
|
|
|
|
},
|
2011-06-28 08:22:55 +00:00
|
|
|
|
// (4, id[, _])
|
|
|
|
|
LINK_TO: 4,
|
2011-06-28 08:30:50 +00:00
|
|
|
|
'link_to': function (id) {
|
|
|
|
|
return [commands.LINK_TO, id, false];
|
|
|
|
|
},
|
2011-06-28 08:22:55 +00:00
|
|
|
|
// (5[, _[, _]])
|
2011-06-29 15:35:26 +00:00
|
|
|
|
DELETE_ALL: 5,
|
|
|
|
|
'delete_all': function () {
|
2011-06-28 08:30:50 +00:00
|
|
|
|
return [5, false, false];
|
|
|
|
|
},
|
2011-06-28 08:22:55 +00:00
|
|
|
|
// (6, _, ids) replaces all linked records with provided ids
|
2011-06-28 08:30:50 +00:00
|
|
|
|
REPLACE_WITH: 6,
|
|
|
|
|
'replace_with': function (ids) {
|
|
|
|
|
return [6, false, ids];
|
|
|
|
|
}
|
2011-06-28 08:22:55 +00:00
|
|
|
|
};
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({
|
2011-07-04 15:00:17 +00:00
|
|
|
|
multi_selection: false,
|
2012-03-29 10:03:08 +00:00
|
|
|
|
disable_utility_classes: true,
|
2012-04-18 12:45:20 +00:00
|
|
|
|
init: function(field_manager, node) {
|
|
|
|
|
this._super(field_manager, node);
|
2012-04-06 12:30:28 +00:00
|
|
|
|
lazy_build_o2m_kanban_view();
|
2011-10-26 15:31:09 +00:00
|
|
|
|
this.is_loaded = $.Deferred();
|
|
|
|
|
this.initial_is_loaded = this.is_loaded;
|
2011-10-17 16:22:28 +00:00
|
|
|
|
this.is_setted = $.Deferred();
|
2011-07-18 15:28:07 +00:00
|
|
|
|
this.form_last_update = $.Deferred();
|
2011-10-12 16:13:22 +00:00
|
|
|
|
this.init_form_last_update = this.form_last_update;
|
2011-04-05 10:04:50 +00:00
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-05-31 14:11:19 +00:00
|
|
|
|
var self = this;
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
this.dataset = new instance.web.form.One2ManyDataSet(this, this.field.relation);
|
2011-06-29 14:35:06 +00:00
|
|
|
|
this.dataset.o2m = this;
|
|
|
|
|
this.dataset.parent_view = this.view;
|
2011-12-19 17:30:55 +00:00
|
|
|
|
this.dataset.child_name = this.name;
|
|
|
|
|
//this.dataset.child_name =
|
2011-06-21 12:12:22 +00:00
|
|
|
|
this.dataset.on_change.add_last(function() {
|
2012-01-03 17:17:13 +00:00
|
|
|
|
self.trigger_on_change();
|
2011-05-31 14:11:19 +00:00
|
|
|
|
});
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-10-26 12:55:24 +00:00
|
|
|
|
this.is_setted.then(function() {
|
|
|
|
|
self.load_views();
|
|
|
|
|
});
|
2012-03-16 10:48:59 +00:00
|
|
|
|
this.is_loaded.then(function() {
|
|
|
|
|
self.on("change:effective_readonly", self, function() {
|
|
|
|
|
self.is_loaded = self.is_loaded.pipe(function() {
|
|
|
|
|
self.viewmanager.destroy();
|
|
|
|
|
return $.when(self.load_views()).then(function() {
|
|
|
|
|
self.reload_current_view();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2011-10-26 12:55:24 +00:00
|
|
|
|
},
|
2012-01-03 17:17:13 +00:00
|
|
|
|
trigger_on_change: function() {
|
|
|
|
|
var tmp = this.doing_on_change;
|
|
|
|
|
this.doing_on_change = true;
|
2012-04-18 12:23:41 +00:00
|
|
|
|
this.trigger('changed_value');
|
2012-01-03 17:17:13 +00:00
|
|
|
|
this.doing_on_change = tmp;
|
|
|
|
|
},
|
2011-10-26 12:55:24 +00:00
|
|
|
|
load_views: function() {
|
|
|
|
|
var self = this;
|
|
|
|
|
|
2011-06-06 07:04:51 +00:00
|
|
|
|
var modes = this.node.attrs.mode;
|
2011-10-25 12:42:51 +00:00
|
|
|
|
modes = !!modes ? modes.split(",") : ["tree"];
|
2011-06-06 07:04:51 +00:00
|
|
|
|
var views = [];
|
|
|
|
|
_.each(modes, function(mode) {
|
2011-08-08 17:32:30 +00:00
|
|
|
|
var view = {
|
|
|
|
|
view_id: false,
|
|
|
|
|
view_type: mode == "tree" ? "list" : mode,
|
2012-04-18 14:24:39 +00:00
|
|
|
|
options: {}
|
2011-08-08 17:32:30 +00:00
|
|
|
|
};
|
2011-06-06 07:04:51 +00:00
|
|
|
|
if (self.field.views && self.field.views[mode]) {
|
2011-06-16 14:25:30 +00:00
|
|
|
|
view.embedded_view = self.field.views[mode];
|
|
|
|
|
}
|
|
|
|
|
if(view.view_type === "list") {
|
2011-08-08 17:32:30 +00:00
|
|
|
|
view.options.selectable = self.multi_selection;
|
2012-03-16 10:48:59 +00:00
|
|
|
|
if (self.get("effective_readonly")) {
|
2011-10-26 14:11:48 +00:00
|
|
|
|
view.options.addable = null;
|
|
|
|
|
view.options.deletable = null;
|
2011-12-28 16:29:52 +00:00
|
|
|
|
view.options.isClarkGable = false;
|
2011-10-26 14:11:48 +00:00
|
|
|
|
}
|
2011-09-30 15:46:12 +00:00
|
|
|
|
} else if (view.view_type === "form") {
|
2012-03-16 10:48:59 +00:00
|
|
|
|
if (self.get("effective_readonly")) {
|
2012-04-09 21:30:43 +00:00
|
|
|
|
view.view_type = 'form';
|
2011-12-07 09:42:42 +00:00
|
|
|
|
}
|
2011-09-30 15:46:12 +00:00
|
|
|
|
view.options.not_interactible_on_create = true;
|
2011-06-06 07:04:51 +00:00
|
|
|
|
}
|
|
|
|
|
views.push(view);
|
|
|
|
|
});
|
2011-06-16 16:37:09 +00:00
|
|
|
|
this.views = views;
|
2011-12-07 09:42:42 +00:00
|
|
|
|
|
2012-04-18 14:27:14 +00:00
|
|
|
|
this.viewmanager = new instance.web.ViewManager(this, this.dataset, views, {
|
|
|
|
|
$sidebar: false,
|
|
|
|
|
});
|
2011-12-13 14:49:55 +00:00
|
|
|
|
this.viewmanager.template = 'One2Many.viewmanager';
|
2012-04-17 12:09:49 +00:00
|
|
|
|
this.viewmanager.registry = instance.web.views.extend({
|
|
|
|
|
list: 'instance.web.form.One2ManyListView',
|
|
|
|
|
form: 'instance.web.form.One2ManyFormView',
|
|
|
|
|
kanban: 'instance.web.form.One2ManyKanbanView',
|
2011-07-18 15:28:07 +00:00
|
|
|
|
});
|
|
|
|
|
var once = $.Deferred().then(function() {
|
2011-10-12 16:13:22 +00:00
|
|
|
|
self.init_form_last_update.resolve();
|
2011-06-28 08:22:28 +00:00
|
|
|
|
});
|
2011-10-26 12:55:24 +00:00
|
|
|
|
var def = $.Deferred().then(function() {
|
2011-10-26 15:31:09 +00:00
|
|
|
|
self.initial_is_loaded.resolve();
|
2011-10-26 12:55:24 +00:00
|
|
|
|
});
|
2011-06-01 08:23:58 +00:00
|
|
|
|
this.viewmanager.on_controller_inited.add_last(function(view_type, controller) {
|
2012-04-06 12:30:28 +00:00
|
|
|
|
controller.o2m = self;
|
2011-05-31 15:28:07 +00:00
|
|
|
|
if (view_type == "list") {
|
2012-03-16 10:48:59 +00:00
|
|
|
|
if (self.get("effective_readonly"))
|
2011-10-26 14:11:48 +00:00
|
|
|
|
controller.set_editable(false);
|
2012-04-10 14:29:01 +00:00
|
|
|
|
} else if (view_type === "form") {
|
|
|
|
|
if (self.get("effective_readonly")) {
|
2011-12-23 11:12:11 +00:00
|
|
|
|
$(".oe_form_buttons", controller.$element).children().remove();
|
|
|
|
|
}
|
2011-07-18 15:28:07 +00:00
|
|
|
|
controller.on_record_loaded.add_last(function() {
|
|
|
|
|
once.resolve();
|
|
|
|
|
});
|
2011-07-27 14:03:32 +00:00
|
|
|
|
controller.on_pager_action.add_first(function() {
|
2011-11-10 11:02:06 +00:00
|
|
|
|
self.save_any_view();
|
2011-07-27 14:03:32 +00:00
|
|
|
|
});
|
2011-10-07 16:21:56 +00:00
|
|
|
|
} else if (view_type == "graph") {
|
|
|
|
|
self.reload_current_view()
|
2011-05-31 13:01:54 +00:00
|
|
|
|
}
|
2011-10-26 12:55:24 +00:00
|
|
|
|
def.resolve();
|
2011-05-31 13:01:54 +00:00
|
|
|
|
});
|
2011-10-26 15:39:44 +00:00
|
|
|
|
this.viewmanager.on_mode_switch.add_first(function(n_mode, b, c, d, e) {
|
2011-11-10 11:02:06 +00:00
|
|
|
|
$.when(self.save_any_view()).then(function() {
|
2011-10-26 15:39:44 +00:00
|
|
|
|
if(n_mode === "list")
|
2011-12-19 16:28:05 +00:00
|
|
|
|
$.async_when().then(function() {self.reload_current_view();});
|
2011-10-26 15:39:44 +00:00
|
|
|
|
});
|
2011-07-27 14:03:32 +00:00
|
|
|
|
});
|
2011-10-17 16:22:28 +00:00
|
|
|
|
this.is_setted.then(function() {
|
2011-12-19 16:28:05 +00:00
|
|
|
|
$.async_when().then(function () {
|
2011-10-17 16:22:28 +00:00
|
|
|
|
self.viewmanager.appendTo(self.$element);
|
2011-12-19 16:28:05 +00:00
|
|
|
|
});
|
2011-10-17 16:22:28 +00:00
|
|
|
|
});
|
2011-10-26 12:55:24 +00:00
|
|
|
|
return def;
|
2011-04-04 15:52:09 +00:00
|
|
|
|
},
|
2011-06-16 16:37:09 +00:00
|
|
|
|
reload_current_view: function() {
|
|
|
|
|
var self = this;
|
[FIX] synchronization of o2m widget saving, avoid race condition when clicking on button of unsaved record
After saving, the formview would both refresh the form and lauch the
action itself, which launches a refresh of its own.
Issue is that o2m's filling of themselves (a read) is async and
triggered by the set_value on the o2m field, so the second reload of
the form would be interspersed (between the first reload and the end
of the o2ms loading), resulting in corrupted state for the o2ms if the
button's action somehow changed the contents of the o2m (it would
remove the old records and return brand new ids during the refresh):
the set_value on the o2m would empty the o2m's dataset cache, and the
returning fetch request would try to find in cache values removed from
it, or something, blowing up everything.
Anyway, this was fixed by ensuring the button action is only executed
after the form is completely done doing its post-save reload (using
the new async set_value). This is a tiny bit brittle in that onchanges
are synchronous but call set_value, so a set_value on an o2m from an
onchange may have issues. It also increases the flicker of the view,
as the o2m is reloaded twice in quick succession.
lp bug: https://launchpad.net/bugs/885658 fixed
bzr revid: xmo@openerp.com-20111117161426-72jzhvv3dm387uom
2011-11-17 16:14:26 +00:00
|
|
|
|
return self.is_loaded = self.is_loaded.pipe(function() {
|
2011-12-07 09:42:42 +00:00
|
|
|
|
var active_view = self.viewmanager.active_view;
|
|
|
|
|
var view = self.viewmanager.views[active_view].controller;
|
|
|
|
|
if(active_view === "list") {
|
2011-10-26 15:31:09 +00:00
|
|
|
|
return view.reload_content();
|
2012-04-10 14:29:01 +00:00
|
|
|
|
} else if (active_view === "form") {
|
2011-10-26 15:31:09 +00:00
|
|
|
|
if (self.dataset.index === null && self.dataset.ids.length >= 1) {
|
|
|
|
|
self.dataset.index = 0;
|
|
|
|
|
}
|
|
|
|
|
var act = function() {
|
|
|
|
|
return view.do_show();
|
2011-12-07 09:42:42 +00:00
|
|
|
|
};
|
2011-10-26 15:31:09 +00:00
|
|
|
|
self.form_last_update = self.form_last_update.pipe(act, act);
|
|
|
|
|
return self.form_last_update;
|
2012-04-06 12:03:47 +00:00
|
|
|
|
} else if (view.do_search) {
|
2011-10-26 15:31:09 +00:00
|
|
|
|
return view.do_search(self.build_domain(), self.dataset.get_context(), []);
|
2011-10-12 12:49:23 +00:00
|
|
|
|
}
|
2011-12-07 09:42:42 +00:00
|
|
|
|
}, undefined);
|
2011-06-16 16:37:09 +00:00
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {
|
|
|
|
|
value_ = value_ || [];
|
2011-06-23 10:42:22 +00:00
|
|
|
|
var self = this;
|
2011-06-29 15:35:26 +00:00
|
|
|
|
this.dataset.reset_ids([]);
|
2012-04-17 14:32:27 +00:00
|
|
|
|
if(value_.length >= 1 && value_[0] instanceof Array) {
|
2011-06-27 09:05:32 +00:00
|
|
|
|
var ids = [];
|
2012-04-17 14:32:27 +00:00
|
|
|
|
_.each(value_, function(command) {
|
2011-06-28 08:22:55 +00:00
|
|
|
|
var obj = {values: command[2]};
|
|
|
|
|
switch (command[0]) {
|
|
|
|
|
case commands.CREATE:
|
|
|
|
|
obj['id'] = _.uniqueId(self.dataset.virtual_id_prefix);
|
2011-09-28 11:55:37 +00:00
|
|
|
|
obj.defaults = {};
|
2011-06-28 08:22:55 +00:00
|
|
|
|
self.dataset.to_create.push(obj);
|
2012-02-14 16:15:58 +00:00
|
|
|
|
self.dataset.cache.push(_.extend(_.clone(obj), {values: _.clone(command[2])}));
|
2011-06-28 08:22:55 +00:00
|
|
|
|
ids.push(obj.id);
|
|
|
|
|
return;
|
|
|
|
|
case commands.UPDATE:
|
|
|
|
|
obj['id'] = command[1];
|
|
|
|
|
self.dataset.to_write.push(obj);
|
2012-02-14 16:15:58 +00:00
|
|
|
|
self.dataset.cache.push(_.extend(_.clone(obj), {values: _.clone(command[2])}));
|
2011-06-28 08:22:55 +00:00
|
|
|
|
ids.push(obj.id);
|
|
|
|
|
return;
|
|
|
|
|
case commands.DELETE:
|
|
|
|
|
self.dataset.to_delete.push({id: command[1]});
|
|
|
|
|
return;
|
|
|
|
|
case commands.LINK_TO:
|
|
|
|
|
ids.push(command[1]);
|
|
|
|
|
return;
|
2011-06-29 15:35:26 +00:00
|
|
|
|
case commands.DELETE_ALL:
|
|
|
|
|
self.dataset.delete_all = true;
|
|
|
|
|
return;
|
2011-06-27 09:05:32 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this._super(ids);
|
|
|
|
|
this.dataset.set_ids(ids);
|
2012-04-17 14:32:27 +00:00
|
|
|
|
} else if (value_.length >= 1 && typeof(value_[0]) === "object") {
|
2011-06-30 09:14:39 +00:00
|
|
|
|
var ids = [];
|
|
|
|
|
this.dataset.delete_all = true;
|
2012-04-17 14:32:27 +00:00
|
|
|
|
_.each(value_, function(command) {
|
2011-06-30 09:14:39 +00:00
|
|
|
|
var obj = {values: command};
|
|
|
|
|
obj['id'] = _.uniqueId(self.dataset.virtual_id_prefix);
|
2011-09-28 11:55:37 +00:00
|
|
|
|
obj.defaults = {};
|
2011-06-30 09:14:39 +00:00
|
|
|
|
self.dataset.to_create.push(obj);
|
|
|
|
|
self.dataset.cache.push(_.clone(obj));
|
|
|
|
|
ids.push(obj.id);
|
|
|
|
|
});
|
|
|
|
|
this._super(ids);
|
|
|
|
|
this.dataset.set_ids(ids);
|
2011-06-27 09:05:32 +00:00
|
|
|
|
} else {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this._super(value_);
|
|
|
|
|
this.dataset.reset_ids(value_);
|
2011-06-27 09:05:32 +00:00
|
|
|
|
}
|
2011-07-27 09:09:05 +00:00
|
|
|
|
if (this.dataset.index === null && this.dataset.ids.length > 0) {
|
|
|
|
|
this.dataset.index = 0;
|
|
|
|
|
}
|
[FIX] synchronization of o2m widget saving, avoid race condition when clicking on button of unsaved record
After saving, the formview would both refresh the form and lauch the
action itself, which launches a refresh of its own.
Issue is that o2m's filling of themselves (a read) is async and
triggered by the set_value on the o2m field, so the second reload of
the form would be interspersed (between the first reload and the end
of the o2ms loading), resulting in corrupted state for the o2ms if the
button's action somehow changed the contents of the o2m (it would
remove the old records and return brand new ids during the refresh):
the set_value on the o2m would empty the o2m's dataset cache, and the
returning fetch request would try to find in cache values removed from
it, or something, blowing up everything.
Anyway, this was fixed by ensuring the button action is only executed
after the form is completely done doing its post-save reload (using
the new async set_value). This is a tiny bit brittle in that onchanges
are synchronous but call set_value, so a set_value on an o2m from an
onchange may have issues. It also increases the flicker of the view,
as the o2m is reloaded twice in quick succession.
lp bug: https://launchpad.net/bugs/885658 fixed
bzr revid: xmo@openerp.com-20111117161426-72jzhvv3dm387uom
2011-11-17 16:14:26 +00:00
|
|
|
|
self.is_setted.resolve();
|
|
|
|
|
return self.reload_current_view();
|
2011-05-31 13:38:17 +00:00
|
|
|
|
},
|
2011-06-21 12:12:22 +00:00
|
|
|
|
get_value: function() {
|
2011-06-27 09:05:32 +00:00
|
|
|
|
var self = this;
|
2011-06-29 14:35:06 +00:00
|
|
|
|
if (!this.dataset)
|
|
|
|
|
return [];
|
2011-12-05 15:38:13 +00:00
|
|
|
|
this.save_any_view();
|
2011-06-29 15:35:26 +00:00
|
|
|
|
var val = this.dataset.delete_all ? [commands.delete_all()] : [];
|
|
|
|
|
val = val.concat(_.map(this.dataset.ids, function(id) {
|
2011-06-27 09:05:32 +00:00
|
|
|
|
var alter_order = _.detect(self.dataset.to_create, function(x) {return x.id === id;});
|
|
|
|
|
if (alter_order) {
|
2011-06-28 08:30:50 +00:00
|
|
|
|
return commands.create(alter_order.values);
|
2011-06-27 09:05:32 +00:00
|
|
|
|
}
|
|
|
|
|
alter_order = _.detect(self.dataset.to_write, function(x) {return x.id === id;});
|
|
|
|
|
if (alter_order) {
|
2011-06-28 08:30:50 +00:00
|
|
|
|
return commands.update(alter_order.id, alter_order.values);
|
2011-06-27 09:05:32 +00:00
|
|
|
|
}
|
2011-06-28 08:30:50 +00:00
|
|
|
|
return commands.link_to(id);
|
2011-06-29 15:35:26 +00:00
|
|
|
|
}));
|
2011-06-28 08:30:50 +00:00
|
|
|
|
return val.concat(_.map(
|
|
|
|
|
this.dataset.to_delete, function(x) {
|
|
|
|
|
return commands['delete'](x.id);}));
|
2011-06-21 12:12:22 +00:00
|
|
|
|
},
|
2011-11-10 11:02:06 +00:00
|
|
|
|
save_any_view: function() {
|
2012-01-03 17:17:13 +00:00
|
|
|
|
if (this.doing_on_change)
|
|
|
|
|
return false;
|
2011-12-19 16:14:41 +00:00
|
|
|
|
return this.session.synchronized_mode(_.bind(function() {
|
|
|
|
|
if (this.viewmanager && this.viewmanager.views && this.viewmanager.active_view &&
|
|
|
|
|
this.viewmanager.views[this.viewmanager.active_view] &&
|
|
|
|
|
this.viewmanager.views[this.viewmanager.active_view].controller) {
|
|
|
|
|
var view = this.viewmanager.views[this.viewmanager.active_view].controller;
|
|
|
|
|
if (this.viewmanager.active_view === "form") {
|
2012-01-10 14:58:29 +00:00
|
|
|
|
if (!view.is_initialized.isResolved()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-12-19 16:14:41 +00:00
|
|
|
|
var res = $.when(view.do_save());
|
|
|
|
|
if (!res.isResolved() && !res.isRejected()) {
|
|
|
|
|
console.warn("Asynchronous get_value() is not supported in form view.");
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
} else if (this.viewmanager.active_view === "list") {
|
|
|
|
|
var res = $.when(view.ensure_saved());
|
|
|
|
|
if (!res.isResolved() && !res.isRejected()) {
|
|
|
|
|
console.warn("Asynchronous get_value() is not supported in list view.");
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}, this));
|
2011-07-26 15:37:47 +00:00
|
|
|
|
},
|
2012-04-18 09:50:43 +00:00
|
|
|
|
is_syntax_valid: function() {
|
2011-10-12 09:11:47 +00:00
|
|
|
|
if (!this.viewmanager.views[this.viewmanager.active_view])
|
2012-04-18 09:16:13 +00:00
|
|
|
|
return true;
|
2011-09-16 13:22:28 +00:00
|
|
|
|
var view = this.viewmanager.views[this.viewmanager.active_view].controller;
|
|
|
|
|
if (this.viewmanager.active_view === "form") {
|
2011-07-26 15:37:47 +00:00
|
|
|
|
for (var f in view.fields) {
|
|
|
|
|
f = view.fields[f];
|
2011-07-27 10:25:19 +00:00
|
|
|
|
if (!f.is_valid()) {
|
2012-04-18 09:16:13 +00:00
|
|
|
|
return false;
|
2011-07-26 15:37:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-18 09:16:13 +00:00
|
|
|
|
return true;
|
2011-07-27 13:36:28 +00:00
|
|
|
|
},
|
2011-03-30 14:00:48 +00:00
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.One2ManyDataSet = instance.web.BufferedDataSet.extend({
|
2011-06-29 14:35:06 +00:00
|
|
|
|
get_context: function() {
|
2012-01-03 17:17:13 +00:00
|
|
|
|
this.context = this.o2m.build_context([this.o2m.name]);
|
2011-06-29 14:35:06 +00:00
|
|
|
|
return this.context;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.One2ManyListView = instance.web.ListView.extend({
|
2011-12-13 14:49:55 +00:00
|
|
|
|
_template: 'One2Many.listview',
|
2011-06-16 16:37:09 +00:00
|
|
|
|
do_add_record: function () {
|
2011-07-04 08:38:58 +00:00
|
|
|
|
if (this.options.editable) {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
} else {
|
|
|
|
|
var self = this;
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var pop = new instance.web.form.SelectCreatePopup(this);
|
2011-09-26 16:00:57 +00:00
|
|
|
|
pop.on_default_get.add(self.dataset.on_default_get);
|
2011-12-22 09:40:12 +00:00
|
|
|
|
pop.select_element(
|
|
|
|
|
self.o2m.field.relation,
|
|
|
|
|
{
|
|
|
|
|
title: _t("Create: ") + self.name,
|
|
|
|
|
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).then(function(r) {
|
|
|
|
|
self.o2m.dataset.set_ids(self.o2m.dataset.ids.concat([r.result]));
|
|
|
|
|
self.o2m.dataset.on_change();
|
|
|
|
|
}).then(callback, error_callback);
|
|
|
|
|
},
|
|
|
|
|
read_function: function() {
|
|
|
|
|
return self.o2m.dataset.read_ids.apply(self.o2m.dataset, arguments);
|
|
|
|
|
},
|
|
|
|
|
parent_view: self.o2m.view,
|
2012-01-03 16:34:42 +00:00
|
|
|
|
child_name: self.o2m.name,
|
2011-12-22 09:40:12 +00:00
|
|
|
|
form_view_options: {'not_interactible_on_create':true}
|
2011-10-10 12:45:16 +00:00
|
|
|
|
},
|
2011-12-22 09:40:12 +00:00
|
|
|
|
self.o2m.build_domain(),
|
|
|
|
|
self.o2m.build_context()
|
|
|
|
|
);
|
2011-08-11 16:03:47 +00:00
|
|
|
|
pop.on_select_elements.add_last(function() {
|
|
|
|
|
self.o2m.reload_current_view();
|
2011-06-23 17:07:34 +00:00
|
|
|
|
});
|
2011-07-04 08:38:58 +00:00
|
|
|
|
}
|
2011-07-13 11:05:32 +00:00
|
|
|
|
},
|
|
|
|
|
do_activate_record: function(index, id) {
|
|
|
|
|
var self = this;
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var pop = new instance.web.form.FormOpenPopup(self.o2m.view);
|
2011-12-22 09:52:48 +00:00
|
|
|
|
pop.show_element(self.o2m.field.relation, id, self.o2m.build_context(), {
|
|
|
|
|
title: _t("Open: ") + self.name,
|
2011-07-13 11:05:32 +00:00
|
|
|
|
auto_write: false,
|
|
|
|
|
alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined,
|
2011-08-29 12:13:30 +00:00
|
|
|
|
parent_view: self.o2m.view,
|
2011-12-19 17:30:55 +00:00
|
|
|
|
child_name: self.o2m.name,
|
2011-08-29 12:13:30 +00:00
|
|
|
|
read_function: function() {
|
|
|
|
|
return self.o2m.dataset.read_ids.apply(self.o2m.dataset, arguments);
|
2011-09-30 15:46:12 +00:00
|
|
|
|
},
|
2011-10-31 10:43:04 +00:00
|
|
|
|
form_view_options: {'not_interactible_on_create':true},
|
2012-03-16 10:48:59 +00:00
|
|
|
|
readonly: self.o2m.get("effective_readonly")
|
2011-07-13 11:05:32 +00:00
|
|
|
|
});
|
|
|
|
|
pop.on_write.add(function(id, data) {
|
2011-08-29 14:08:39 +00:00
|
|
|
|
self.o2m.dataset.write(id, data, {}, function(r) {
|
2011-07-13 11:05:32 +00:00
|
|
|
|
self.o2m.reload_current_view();
|
|
|
|
|
});
|
|
|
|
|
});
|
2011-12-22 13:24:47 +00:00
|
|
|
|
},
|
|
|
|
|
do_button_action: function (name, id, callback) {
|
|
|
|
|
var self = this;
|
|
|
|
|
var def = $.Deferred().then(callback).then(function() {self.o2m.view.reload();});
|
|
|
|
|
return this._super(name, id, _.bind(def.resolve, def));
|
2012-01-17 13:28:43 +00:00
|
|
|
|
}
|
2011-06-16 16:37:09 +00:00
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.One2ManyFormView = instance.web.FormView.extend({
|
2011-12-21 16:43:35 +00:00
|
|
|
|
form_template: 'One2Many.formview',
|
|
|
|
|
on_loaded: function(data) {
|
|
|
|
|
this._super(data);
|
2012-01-11 14:37:12 +00:00
|
|
|
|
var self = this;
|
2012-04-18 15:17:05 +00:00
|
|
|
|
this.$buttons.find('button.oe_form_button_create').click(function() {
|
2012-01-11 14:37:12 +00:00
|
|
|
|
self.do_save().then(self.on_button_new);
|
|
|
|
|
});
|
2012-02-15 10:34:05 +00:00
|
|
|
|
},
|
|
|
|
|
do_notify_change: function() {
|
|
|
|
|
if (this.dataset.parent_view) {
|
|
|
|
|
this.dataset.parent_view.do_notify_change();
|
|
|
|
|
} else {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
}
|
2011-12-21 16:43:35 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2012-04-06 12:30:28 +00:00
|
|
|
|
var lazy_build_o2m_kanban_view = function() {
|
2012-04-17 12:09:49 +00:00
|
|
|
|
if (! instance.web_kanban || instance.web.form.One2ManyKanbanView)
|
2012-04-06 12:30:28 +00:00
|
|
|
|
return;
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.One2ManyKanbanView = instance.web_kanban.KanbanView.extend({
|
2012-04-06 12:30:28 +00:00
|
|
|
|
open_record: function(id) {
|
|
|
|
|
var self = this;
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var pop = new instance.web.form.FormOpenPopup(self.o2m.view);
|
2012-04-06 12:30:28 +00:00
|
|
|
|
pop.show_element(self.o2m.field.relation, id, self.o2m.build_context(), {
|
|
|
|
|
title: _t("Open: ") + self.name,
|
|
|
|
|
auto_write: false,
|
|
|
|
|
alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined,
|
|
|
|
|
parent_view: self.o2m.view,
|
|
|
|
|
child_name: self.o2m.name,
|
|
|
|
|
read_function: function() {
|
|
|
|
|
return self.o2m.dataset.read_ids.apply(self.o2m.dataset, arguments);
|
|
|
|
|
},
|
|
|
|
|
form_view_options: {'not_interactible_on_create':true},
|
2012-04-06 14:05:37 +00:00
|
|
|
|
readonly: self.o2m.get("effective_readonly"),
|
2012-04-06 12:30:28 +00:00
|
|
|
|
});
|
|
|
|
|
pop.on_write.add(function(id, data) {
|
|
|
|
|
self.o2m.dataset.write(id, data, {}, function(r) {
|
|
|
|
|
self.o2m.reload_current_view();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-16 10:39:31 +00:00
|
|
|
|
/*
|
|
|
|
|
* TODO niv: clean those deferred stuff, it could be better
|
|
|
|
|
*/
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend({
|
2011-07-04 15:00:17 +00:00
|
|
|
|
multi_selection: false,
|
2012-03-29 10:03:08 +00:00
|
|
|
|
disable_utility_classes: true,
|
2012-04-18 12:45:20 +00:00
|
|
|
|
init: function(field_manager, node) {
|
|
|
|
|
this._super(field_manager, node);
|
2011-10-26 15:23:05 +00:00
|
|
|
|
this.is_loaded = $.Deferred();
|
|
|
|
|
this.initial_is_loaded = this.is_loaded;
|
2011-10-25 16:20:31 +00:00
|
|
|
|
this.is_setted = $.Deferred();
|
2011-04-22 15:54:52 +00:00
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2011-05-31 14:11:19 +00:00
|
|
|
|
var self = this;
|
2011-06-20 14:43:48 +00:00
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
this.dataset = new instance.web.form.Many2ManyDataSet(this, this.field.relation);
|
2011-07-01 10:27:27 +00:00
|
|
|
|
this.dataset.m2m = this;
|
2011-05-31 14:11:19 +00:00
|
|
|
|
this.dataset.on_unlink.add_last(function(ids) {
|
2012-04-17 15:45:05 +00:00
|
|
|
|
self.dataset_changed();
|
2011-05-31 14:11:19 +00:00
|
|
|
|
});
|
2011-10-25 16:20:31 +00:00
|
|
|
|
|
|
|
|
|
this.is_setted.then(function() {
|
|
|
|
|
self.load_view();
|
2011-05-31 15:28:07 +00:00
|
|
|
|
});
|
2012-03-16 10:39:31 +00:00
|
|
|
|
this.is_loaded.then(function() {
|
|
|
|
|
self.on("change:effective_readonly", self, function() {
|
2012-03-16 10:48:59 +00:00
|
|
|
|
self.is_loaded = self.is_loaded.pipe(function() {
|
|
|
|
|
self.list_view.destroy();
|
|
|
|
|
return $.when(self.load_view()).then(function() {
|
|
|
|
|
self.reload_content();
|
|
|
|
|
});
|
2012-03-16 10:39:31 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
})
|
2011-04-22 15:54:52 +00:00
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {
|
|
|
|
|
value_ = value_ || [];
|
|
|
|
|
if (value_.length >= 1 && value_[0] instanceof Array) {
|
|
|
|
|
value_ = value_[0][2];
|
2011-06-27 09:05:32 +00:00
|
|
|
|
}
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this._super(value_);
|
|
|
|
|
this.dataset.set_ids(value_);
|
2011-06-23 10:42:22 +00:00
|
|
|
|
var self = this;
|
2011-10-26 15:23:05 +00:00
|
|
|
|
self.reload_content();
|
2011-10-25 16:20:31 +00:00
|
|
|
|
this.is_setted.resolve();
|
2011-04-26 12:11:46 +00:00
|
|
|
|
},
|
2011-10-25 16:20:31 +00:00
|
|
|
|
load_view: function() {
|
|
|
|
|
var self = this;
|
2012-04-17 12:09:49 +00:00
|
|
|
|
this.list_view = new instance.web.form.Many2ManyListView(this, this.dataset, false, {
|
2012-03-16 10:39:31 +00:00
|
|
|
|
'addable': self.get("effective_readonly") ? null : _t("Add"),
|
|
|
|
|
'deletable': self.get("effective_readonly") ? false : true,
|
2011-12-28 16:29:52 +00:00
|
|
|
|
'selectable': self.multi_selection,
|
2012-03-16 10:39:31 +00:00
|
|
|
|
'isClarkGable': self.get("effective_readonly") ? false : true
|
2011-10-25 16:20:31 +00:00
|
|
|
|
});
|
2011-11-10 14:07:54 +00:00
|
|
|
|
var embedded = (this.field.views || {}).tree;
|
|
|
|
|
if (embedded) {
|
|
|
|
|
this.list_view.set_embedded_view(embedded);
|
|
|
|
|
}
|
2011-10-25 16:20:31 +00:00
|
|
|
|
this.list_view.m2m_field = this;
|
|
|
|
|
var loaded = $.Deferred();
|
|
|
|
|
this.list_view.on_loaded.add_last(function() {
|
2011-10-26 15:23:05 +00:00
|
|
|
|
self.initial_is_loaded.resolve();
|
2011-10-25 16:20:31 +00:00
|
|
|
|
loaded.resolve();
|
|
|
|
|
});
|
2011-12-19 16:28:05 +00:00
|
|
|
|
$.async_when().then(function () {
|
2012-03-19 12:49:45 +00:00
|
|
|
|
self.list_view.appendTo(self.$element);
|
2011-12-19 16:28:05 +00:00
|
|
|
|
});
|
2011-10-25 16:20:31 +00:00
|
|
|
|
return loaded;
|
|
|
|
|
},
|
2011-10-26 15:23:05 +00:00
|
|
|
|
reload_content: function() {
|
|
|
|
|
var self = this;
|
|
|
|
|
this.is_loaded = this.is_loaded.pipe(function() {
|
|
|
|
|
return self.list_view.reload_content();
|
|
|
|
|
});
|
|
|
|
|
},
|
2012-04-17 15:45:05 +00:00
|
|
|
|
dataset_changed: function() {
|
|
|
|
|
this.set({'value': [commands.replace_with(this.dataset.ids)]});
|
|
|
|
|
},
|
2011-07-01 10:27:27 +00:00
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.Many2ManyDataSet = instance.web.DataSetStatic.extend({
|
2011-07-01 10:27:27 +00:00
|
|
|
|
get_context: function() {
|
|
|
|
|
this.context = this.m2m.build_context();
|
|
|
|
|
return this.context;
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-09-12 11:43:50 +00:00
|
|
|
|
/**
|
|
|
|
|
* @class
|
2012-04-17 12:09:49 +00:00
|
|
|
|
* @extends instance.web.ListView
|
2011-09-12 11:43:50 +00:00
|
|
|
|
*/
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.Many2ManyListView = instance.web.ListView.extend(/** @lends instance.web.form.Many2ManyListView# */{
|
2011-05-27 15:10:00 +00:00
|
|
|
|
do_add_record: function () {
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var pop = new instance.web.form.SelectCreatePopup(this);
|
2011-12-22 09:40:12 +00:00
|
|
|
|
pop.select_element(
|
|
|
|
|
this.model,
|
|
|
|
|
{
|
|
|
|
|
title: _t("Add: ") + this.name
|
|
|
|
|
},
|
2012-04-17 12:09:49 +00:00
|
|
|
|
new instance.web.CompoundDomain(this.m2m_field.build_domain(), ["!", ["id", "in", this.m2m_field.dataset.ids]]),
|
2011-12-22 09:40:12 +00:00
|
|
|
|
this.m2m_field.build_context()
|
|
|
|
|
);
|
2011-05-09 11:52:33 +00:00
|
|
|
|
var self = this;
|
2011-06-15 15:04:40 +00:00
|
|
|
|
pop.on_select_elements.add(function(element_ids) {
|
2012-03-19 16:41:31 +00:00
|
|
|
|
_.each(element_ids, function(one_id) {
|
|
|
|
|
if(! _.detect(self.dataset.ids, function(x) {return x == one_id;})) {
|
|
|
|
|
self.dataset.set_ids([].concat(self.dataset.ids, [one_id]));
|
2012-04-17 15:45:05 +00:00
|
|
|
|
self.m2m_field.dataset_changed();
|
2011-06-15 15:04:40 +00:00
|
|
|
|
self.reload_content();
|
|
|
|
|
}
|
|
|
|
|
});
|
2011-05-09 11:52:33 +00:00
|
|
|
|
});
|
2011-04-26 14:13:34 +00:00
|
|
|
|
},
|
2011-05-27 15:10:00 +00:00
|
|
|
|
do_activate_record: function(index, id) {
|
2011-07-13 09:59:49 +00:00
|
|
|
|
var self = this;
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var pop = new instance.web.form.FormOpenPopup(this);
|
2011-12-22 09:40:12 +00:00
|
|
|
|
pop.show_element(this.dataset.model, id, this.m2m_field.build_context(), {
|
2011-12-22 09:52:48 +00:00
|
|
|
|
title: _t("Open: ") + this.name,
|
2012-03-16 10:39:31 +00:00
|
|
|
|
readonly: this.getParent().get("effective_readonly")
|
2011-12-22 09:40:12 +00:00
|
|
|
|
});
|
2011-07-13 09:59:49 +00:00
|
|
|
|
pop.on_write_completed.add_last(function() {
|
|
|
|
|
self.reload_content();
|
2011-04-26 14:13:34 +00:00
|
|
|
|
});
|
2011-03-30 14:00:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-09-12 11:43:50 +00:00
|
|
|
|
/**
|
|
|
|
|
* @class
|
2012-04-17 12:09:49 +00:00
|
|
|
|
* @extends instance.web.OldWidget
|
2011-09-12 11:43:50 +00:00
|
|
|
|
*/
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.SelectCreatePopup = instance.web.OldWidget.extend(/** @lends instance.web.form.SelectCreatePopup# */{
|
2011-06-16 15:17:22 +00:00
|
|
|
|
template: "SelectCreatePopup",
|
2011-06-15 15:04:40 +00:00
|
|
|
|
/**
|
|
|
|
|
* options:
|
|
|
|
|
* - initial_ids
|
|
|
|
|
* - initial_view: form or search (default search)
|
|
|
|
|
* - disable_multiple_selection
|
2011-06-16 16:37:09 +00:00
|
|
|
|
* - alternative_form_view
|
2011-08-11 16:03:47 +00:00
|
|
|
|
* - create_function (defaults to a naive saving behavior)
|
2011-06-29 14:35:06 +00:00
|
|
|
|
* - parent_view
|
2011-12-19 17:30:55 +00:00
|
|
|
|
* - child_name
|
2011-09-30 15:46:12 +00:00
|
|
|
|
* - form_view_options
|
|
|
|
|
* - list_view_options
|
2011-10-10 12:40:44 +00:00
|
|
|
|
* - read_function
|
2011-06-15 15:04:40 +00:00
|
|
|
|
*/
|
2011-06-17 08:41:33 +00:00
|
|
|
|
select_element: function(model, options, domain, context) {
|
2011-08-11 16:03:47 +00:00
|
|
|
|
var self = this;
|
2011-05-03 16:17:25 +00:00
|
|
|
|
this.model = model;
|
2011-06-17 12:08:34 +00:00
|
|
|
|
this.domain = domain || [];
|
|
|
|
|
this.context = context || {};
|
2011-08-11 16:03:47 +00:00
|
|
|
|
this.options = _.defaults(options || {}, {"initial_view": "search", "create_function": function() {
|
|
|
|
|
return self.create_row.apply(self, arguments);
|
2011-10-10 12:40:44 +00:00
|
|
|
|
}, read_function: null});
|
2011-06-15 15:04:40 +00:00
|
|
|
|
this.initial_ids = this.options.initial_ids;
|
2011-08-11 16:03:47 +00:00
|
|
|
|
this.created_elements = [];
|
2012-02-29 11:07:44 +00:00
|
|
|
|
this.renderElement();
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.dialog(this.$element, {
|
2011-12-22 09:40:12 +00:00
|
|
|
|
close: function() {
|
|
|
|
|
self.check_exit();
|
|
|
|
|
},
|
|
|
|
|
title: options.title || ""
|
|
|
|
|
});
|
2011-05-03 16:17:25 +00:00
|
|
|
|
this.start();
|
2011-05-09 10:05:41 +00:00
|
|
|
|
},
|
|
|
|
|
start: function() {
|
2011-05-09 11:52:33 +00:00
|
|
|
|
this._super();
|
2011-10-10 09:44:38 +00:00
|
|
|
|
var self = this;
|
2012-04-17 12:09:49 +00:00
|
|
|
|
this.dataset = new instance.web.ProxyDataSet(this, this.model,
|
2011-07-04 15:20:27 +00:00
|
|
|
|
this.context);
|
2011-10-10 09:44:38 +00:00
|
|
|
|
this.dataset.create_function = function() {
|
|
|
|
|
return self.options.create_function.apply(null, arguments).then(function(r) {
|
|
|
|
|
self.created_elements.push(r.result);
|
|
|
|
|
});
|
2011-10-10 12:40:44 +00:00
|
|
|
|
};
|
2011-10-10 09:44:38 +00:00
|
|
|
|
this.dataset.write_function = function() {
|
2011-10-10 13:12:02 +00:00
|
|
|
|
return self.write_row.apply(self, arguments);
|
2011-10-10 12:40:44 +00:00
|
|
|
|
};
|
|
|
|
|
this.dataset.read_function = this.options.read_function;
|
2011-06-29 14:35:06 +00:00
|
|
|
|
this.dataset.parent_view = this.options.parent_view;
|
2011-12-19 17:30:55 +00:00
|
|
|
|
this.dataset.child_name = this.options.child_name;
|
2011-09-26 16:00:57 +00:00
|
|
|
|
this.dataset.on_default_get.add(this.on_default_get);
|
2011-06-23 16:57:17 +00:00
|
|
|
|
if (this.options.initial_view == "search") {
|
2011-11-23 10:30:00 +00:00
|
|
|
|
self.rpc('/web/session/eval_domain_and_context', {
|
2011-11-24 10:43:05 +00:00
|
|
|
|
domains: [],
|
|
|
|
|
contexts: [this.context]
|
|
|
|
|
}, function (results) {
|
|
|
|
|
var search_defaults = {};
|
2012-04-17 14:32:27 +00:00
|
|
|
|
_.each(results.context, function (value_, key) {
|
2011-11-24 10:43:05 +00:00
|
|
|
|
var match = /^search_default_(.*)$/.exec(key);
|
|
|
|
|
if (match) {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
search_defaults[match[1]] = value_;
|
2011-11-24 10:43:05 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
self.setup_search_view(search_defaults);
|
2011-11-23 10:30:00 +00:00
|
|
|
|
});
|
2011-06-09 13:20:04 +00:00
|
|
|
|
} else { // "form"
|
|
|
|
|
this.new_object();
|
2011-05-16 11:02:42 +00:00
|
|
|
|
}
|
2011-05-09 10:05:41 +00:00
|
|
|
|
},
|
2012-02-24 09:53:10 +00:00
|
|
|
|
stop: function () {
|
|
|
|
|
this.$element.dialog('close');
|
|
|
|
|
this._super();
|
|
|
|
|
},
|
2011-11-22 10:41:45 +00:00
|
|
|
|
setup_search_view: function(search_defaults) {
|
2011-05-09 10:05:41 +00:00
|
|
|
|
var self = this;
|
|
|
|
|
if (this.searchview) {
|
2012-02-21 16:29:12 +00:00
|
|
|
|
this.searchview.destroy();
|
2011-05-09 10:05:41 +00:00
|
|
|
|
}
|
2012-04-17 12:09:49 +00:00
|
|
|
|
this.searchview = new instance.web.SearchView(this,
|
2011-11-22 10:41:45 +00:00
|
|
|
|
this.dataset, false, search_defaults);
|
2011-05-09 11:52:33 +00:00
|
|
|
|
this.searchview.on_search.add(function(domains, contexts, groupbys) {
|
2011-06-09 13:20:04 +00:00
|
|
|
|
if (self.initial_ids) {
|
2011-10-06 09:22:47 +00:00
|
|
|
|
self.do_search(domains.concat([[["id", "in", self.initial_ids]], self.domain]),
|
2011-06-17 14:19:45 +00:00
|
|
|
|
contexts, groupbys);
|
2011-06-09 13:20:04 +00:00
|
|
|
|
self.initial_ids = undefined;
|
|
|
|
|
} else {
|
2012-01-27 11:20:50 +00:00
|
|
|
|
self.do_search(domains.concat([self.domain]), contexts.concat(self.context), groupbys);
|
2011-06-09 13:20:04 +00:00
|
|
|
|
}
|
2011-05-09 11:52:33 +00:00
|
|
|
|
});
|
2011-05-10 10:30:46 +00:00
|
|
|
|
this.searchview.on_loaded.add_last(function () {
|
2012-04-17 12:09:49 +00:00
|
|
|
|
self.view_list = new instance.web.form.SelectCreateListView(self,
|
2011-09-14 15:22:08 +00:00
|
|
|
|
self.dataset, false,
|
2011-10-31 15:49:07 +00:00
|
|
|
|
_.extend({'deletable': false,
|
|
|
|
|
'selectable': !self.options.disable_multiple_selection
|
|
|
|
|
}, self.options.list_view_options || {}));
|
2011-05-10 12:15:51 +00:00
|
|
|
|
self.view_list.popup = self;
|
2012-03-19 16:41:31 +00:00
|
|
|
|
self.view_list.appendTo($(".oe-select-create-popup-view-list", self.$element)).pipe(function() {
|
2011-09-15 10:08:08 +00:00
|
|
|
|
self.view_list.do_show();
|
|
|
|
|
}).pipe(function() {
|
2011-06-09 13:20:04 +00:00
|
|
|
|
self.searchview.do_search();
|
2011-05-10 12:15:51 +00:00
|
|
|
|
});
|
2011-12-28 15:53:33 +00:00
|
|
|
|
self.view_list.on_loaded.add_last(function() {
|
|
|
|
|
var $buttons = self.view_list.$element.find(".oe-actions");
|
|
|
|
|
$buttons.prepend(QWeb.render("SelectCreatePopup.search.buttons"));
|
|
|
|
|
var $cbutton = $buttons.find(".oe_selectcreatepopup-search-close");
|
|
|
|
|
$cbutton.click(function() {
|
2012-02-21 16:29:12 +00:00
|
|
|
|
self.destroy();
|
2011-12-28 15:53:33 +00:00
|
|
|
|
});
|
|
|
|
|
var $sbutton = $buttons.find(".oe_selectcreatepopup-search-select");
|
|
|
|
|
if(self.options.disable_multiple_selection) {
|
|
|
|
|
$sbutton.hide();
|
|
|
|
|
}
|
|
|
|
|
$sbutton.click(function() {
|
|
|
|
|
self.on_select_elements(self.selected_ids);
|
2012-02-21 16:29:12 +00:00
|
|
|
|
self.destroy();
|
2011-12-28 15:53:33 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2011-05-10 10:30:46 +00:00
|
|
|
|
});
|
2012-03-19 16:41:31 +00:00
|
|
|
|
this.searchview.appendTo($(".oe-select-create-popup-view-list", self.$element));
|
2011-05-09 10:05:41 +00:00
|
|
|
|
},
|
2011-10-06 09:22:47 +00:00
|
|
|
|
do_search: function(domains, contexts, groupbys) {
|
|
|
|
|
var self = this;
|
|
|
|
|
this.rpc('/web/session/eval_domain_and_context', {
|
|
|
|
|
domains: domains || [],
|
|
|
|
|
contexts: contexts || [],
|
|
|
|
|
group_by_seq: groupbys || []
|
|
|
|
|
}, function (results) {
|
|
|
|
|
self.view_list.do_search(results.domain, results.context, results.group_by);
|
|
|
|
|
});
|
|
|
|
|
},
|
2011-10-10 09:44:38 +00:00
|
|
|
|
create_row: function() {
|
|
|
|
|
var self = this;
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var wdataset = new instance.web.DataSetSearch(this, this.model, this.context, this.domain);
|
2011-10-10 09:44:38 +00:00
|
|
|
|
wdataset.parent_view = this.options.parent_view;
|
2011-12-19 17:30:55 +00:00
|
|
|
|
wdataset.child_name = this.options.child_name;
|
2011-10-10 09:44:38 +00:00
|
|
|
|
return wdataset.create.apply(wdataset, arguments);
|
|
|
|
|
},
|
|
|
|
|
write_row: function() {
|
2011-06-23 16:57:17 +00:00
|
|
|
|
var self = this;
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var wdataset = new instance.web.DataSetSearch(this, this.model, this.context, this.domain);
|
2011-07-13 09:44:11 +00:00
|
|
|
|
wdataset.parent_view = this.options.parent_view;
|
2011-12-19 17:30:55 +00:00
|
|
|
|
wdataset.child_name = this.options.child_name;
|
2011-10-10 09:44:38 +00:00
|
|
|
|
return wdataset.write.apply(wdataset, arguments);
|
2011-06-23 16:57:17 +00:00
|
|
|
|
},
|
2011-06-15 15:04:40 +00:00
|
|
|
|
on_select_elements: function(element_ids) {
|
|
|
|
|
},
|
|
|
|
|
on_click_element: function(ids) {
|
|
|
|
|
this.selected_ids = ids || [];
|
|
|
|
|
if(this.selected_ids.length > 0) {
|
2011-06-16 15:17:22 +00:00
|
|
|
|
this.$element.find(".oe_selectcreatepopup-search-select").removeAttr('disabled');
|
2011-06-15 15:04:40 +00:00
|
|
|
|
} else {
|
2011-06-16 15:17:22 +00:00
|
|
|
|
this.$element.find(".oe_selectcreatepopup-search-select").attr('disabled', "disabled");
|
2011-06-15 15:04:40 +00:00
|
|
|
|
}
|
2011-05-10 10:30:46 +00:00
|
|
|
|
},
|
|
|
|
|
new_object: function() {
|
|
|
|
|
var self = this;
|
2011-06-09 13:20:04 +00:00
|
|
|
|
if (this.searchview) {
|
|
|
|
|
this.searchview.hide();
|
|
|
|
|
}
|
|
|
|
|
if (this.view_list) {
|
|
|
|
|
this.view_list.$element.hide();
|
|
|
|
|
}
|
2011-05-10 10:30:46 +00:00
|
|
|
|
this.dataset.index = null;
|
2012-04-17 12:09:49 +00:00
|
|
|
|
this.view_form = new instance.web.FormView(this, this.dataset, false, self.options.form_view_options);
|
2011-06-16 16:37:09 +00:00
|
|
|
|
if (this.options.alternative_form_view) {
|
|
|
|
|
this.view_form.set_embedded_view(this.options.alternative_form_view);
|
|
|
|
|
}
|
2012-03-19 16:41:31 +00:00
|
|
|
|
this.view_form.appendTo(this.$element.find(".oe-select-create-popup-view-form"));
|
2011-05-10 10:30:46 +00:00
|
|
|
|
this.view_form.on_loaded.add_last(function() {
|
|
|
|
|
var $buttons = self.view_form.$element.find(".oe_form_buttons");
|
2011-08-11 16:03:47 +00:00
|
|
|
|
$buttons.html(QWeb.render("SelectCreatePopup.form.buttons", {widget:self}));
|
|
|
|
|
var $nbutton = $buttons.find(".oe_selectcreatepopup-form-save-new");
|
|
|
|
|
$nbutton.click(function() {
|
2011-10-10 13:12:02 +00:00
|
|
|
|
$.when(self.view_form.do_save()).then(function() {
|
2012-01-10 16:58:02 +00:00
|
|
|
|
self.view_form.reload_mutex.exec(function() {
|
2011-10-12 14:10:07 +00:00
|
|
|
|
self.view_form.on_button_new();
|
|
|
|
|
});
|
2011-08-11 16:03:47 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2011-06-16 15:17:22 +00:00
|
|
|
|
var $nbutton = $buttons.find(".oe_selectcreatepopup-form-save");
|
2011-05-10 10:30:46 +00:00
|
|
|
|
$nbutton.click(function() {
|
2011-10-10 13:12:02 +00:00
|
|
|
|
$.when(self.view_form.do_save()).then(function() {
|
2012-01-10 16:58:02 +00:00
|
|
|
|
self.view_form.reload_mutex.exec(function() {
|
2011-10-12 14:10:07 +00:00
|
|
|
|
self.check_exit();
|
|
|
|
|
});
|
2011-08-11 16:03:47 +00:00
|
|
|
|
});
|
2011-05-10 10:30:46 +00:00
|
|
|
|
});
|
2011-06-16 15:17:22 +00:00
|
|
|
|
var $cbutton = $buttons.find(".oe_selectcreatepopup-form-close");
|
2011-05-10 10:30:46 +00:00
|
|
|
|
$cbutton.click(function() {
|
2011-08-11 16:03:47 +00:00
|
|
|
|
self.check_exit();
|
|
|
|
|
});
|
|
|
|
|
});
|
2011-05-10 10:30:46 +00:00
|
|
|
|
this.view_form.do_show();
|
2011-08-11 16:03:47 +00:00
|
|
|
|
},
|
|
|
|
|
check_exit: function() {
|
|
|
|
|
if (this.created_elements.length > 0) {
|
|
|
|
|
this.on_select_elements(this.created_elements);
|
|
|
|
|
}
|
2012-02-21 16:29:12 +00:00
|
|
|
|
this.destroy();
|
2011-09-26 16:00:57 +00:00
|
|
|
|
},
|
|
|
|
|
on_default_get: function(res) {}
|
2011-05-03 16:17:25 +00:00
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.SelectCreateListView = instance.web.ListView.extend({
|
2011-06-15 15:06:58 +00:00
|
|
|
|
do_add_record: function () {
|
|
|
|
|
this.popup.new_object();
|
|
|
|
|
},
|
2011-05-24 08:35:58 +00:00
|
|
|
|
select_record: function(index) {
|
2011-06-15 15:04:40 +00:00
|
|
|
|
this.popup.on_select_elements([this.dataset.ids[index]]);
|
2012-02-21 16:29:12 +00:00
|
|
|
|
this.popup.destroy();
|
2011-06-15 15:04:40 +00:00
|
|
|
|
},
|
|
|
|
|
do_select: function(ids, records) {
|
|
|
|
|
this._super(ids, records);
|
|
|
|
|
this.popup.on_click_element(ids);
|
2011-05-09 11:52:33 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-09-12 11:43:50 +00:00
|
|
|
|
/**
|
|
|
|
|
* @class
|
2012-04-17 12:09:49 +00:00
|
|
|
|
* @extends instance.web.OldWidget
|
2011-09-12 11:43:50 +00:00
|
|
|
|
*/
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FormOpenPopup = instance.web.OldWidget.extend(/** @lends instance.web.form.FormOpenPopup# */{
|
2011-07-13 09:44:11 +00:00
|
|
|
|
template: "FormOpenPopup",
|
|
|
|
|
/**
|
|
|
|
|
* options:
|
|
|
|
|
* - alternative_form_view
|
|
|
|
|
* - auto_write (default true)
|
2011-08-29 12:13:30 +00:00
|
|
|
|
* - read_function
|
2011-07-13 09:44:11 +00:00
|
|
|
|
* - parent_view
|
2011-12-19 17:30:55 +00:00
|
|
|
|
* - child_name
|
2011-09-30 15:46:12 +00:00
|
|
|
|
* - form_view_options
|
2011-10-31 10:43:04 +00:00
|
|
|
|
* - readonly
|
2011-07-13 09:44:11 +00:00
|
|
|
|
*/
|
|
|
|
|
show_element: function(model, row_id, context, options) {
|
|
|
|
|
this.model = model;
|
|
|
|
|
this.row_id = row_id;
|
|
|
|
|
this.context = context || {};
|
|
|
|
|
this.options = _.defaults(options || {}, {"auto_write": true});
|
2012-02-29 11:07:44 +00:00
|
|
|
|
this.renderElement();
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.dialog(this.$element, {
|
2011-12-22 09:40:12 +00:00
|
|
|
|
title: options.title || '',
|
|
|
|
|
modal: true,
|
|
|
|
|
width: 960,
|
|
|
|
|
height: 600
|
|
|
|
|
});
|
2011-07-13 09:44:11 +00:00
|
|
|
|
this.start();
|
|
|
|
|
},
|
|
|
|
|
start: function() {
|
|
|
|
|
this._super();
|
2012-04-17 12:09:49 +00:00
|
|
|
|
this.dataset = new instance.web.form.FormOpenDataset(this, this.model, this.context);
|
2011-08-29 12:13:30 +00:00
|
|
|
|
this.dataset.fop = this;
|
2011-07-13 09:44:11 +00:00
|
|
|
|
this.dataset.ids = [this.row_id];
|
|
|
|
|
this.dataset.index = 0;
|
|
|
|
|
this.dataset.parent_view = this.options.parent_view;
|
2011-12-19 17:30:55 +00:00
|
|
|
|
this.dataset.child_name = this.options.child_name;
|
2011-07-13 09:44:11 +00:00
|
|
|
|
this.setup_form_view();
|
|
|
|
|
},
|
|
|
|
|
on_write: function(id, data) {
|
|
|
|
|
if (!this.options.auto_write)
|
|
|
|
|
return;
|
|
|
|
|
var self = this;
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var wdataset = new instance.web.DataSetSearch(this, this.model, this.context, this.domain);
|
2011-07-13 09:44:11 +00:00
|
|
|
|
wdataset.parent_view = this.options.parent_view;
|
2011-12-19 17:30:55 +00:00
|
|
|
|
wdataset.child_name = this.options.child_name;
|
2011-08-29 14:08:39 +00:00
|
|
|
|
wdataset.write(id, data, {}, function(r) {
|
2011-07-13 09:53:52 +00:00
|
|
|
|
self.on_write_completed();
|
2011-07-13 09:44:11 +00:00
|
|
|
|
});
|
|
|
|
|
},
|
2011-07-13 09:53:52 +00:00
|
|
|
|
on_write_completed: function() {},
|
2011-07-13 09:44:11 +00:00
|
|
|
|
setup_form_view: function() {
|
|
|
|
|
var self = this;
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var FormClass = instance.web.views.get_object('form');
|
2012-04-18 16:34:36 +00:00
|
|
|
|
var options = _.clone(self.options.form_view_options) || {};
|
2012-04-10 15:36:25 +00:00
|
|
|
|
options.initial_mode = this.options.readonly ? "view" : "edit";
|
|
|
|
|
this.view_form = new FormClass(this, this.dataset, false, options);
|
2011-07-13 09:44:11 +00:00
|
|
|
|
if (this.options.alternative_form_view) {
|
|
|
|
|
this.view_form.set_embedded_view(this.options.alternative_form_view);
|
|
|
|
|
}
|
2012-03-19 16:41:31 +00:00
|
|
|
|
this.view_form.appendTo(this.$element.find(".oe-form-open-popup-form-view"));
|
2011-07-13 09:44:11 +00:00
|
|
|
|
this.view_form.on_loaded.add_last(function() {
|
|
|
|
|
var $buttons = self.view_form.$element.find(".oe_form_buttons");
|
|
|
|
|
$buttons.html(QWeb.render("FormOpenPopup.form.buttons"));
|
|
|
|
|
var $nbutton = $buttons.find(".oe_formopenpopup-form-save");
|
|
|
|
|
$nbutton.click(function() {
|
2011-10-13 11:58:28 +00:00
|
|
|
|
self.view_form.do_save().then(function() {
|
2012-02-21 16:29:12 +00:00
|
|
|
|
self.destroy();
|
2011-10-13 11:58:28 +00:00
|
|
|
|
});
|
2011-07-13 09:44:11 +00:00
|
|
|
|
});
|
|
|
|
|
var $cbutton = $buttons.find(".oe_formopenpopup-form-close");
|
|
|
|
|
$cbutton.click(function() {
|
2012-02-21 16:29:12 +00:00
|
|
|
|
self.destroy();
|
2011-07-13 09:44:11 +00:00
|
|
|
|
});
|
2011-10-31 11:09:37 +00:00
|
|
|
|
if (self.options.readonly) {
|
|
|
|
|
$nbutton.hide();
|
|
|
|
|
$cbutton.text(_t("Close"));
|
|
|
|
|
}
|
2011-07-13 09:44:11 +00:00
|
|
|
|
self.view_form.do_show();
|
|
|
|
|
});
|
|
|
|
|
this.dataset.on_write.add(this.on_write);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FormOpenDataset = instance.web.ProxyDataSet.extend({
|
2011-08-29 12:13:30 +00:00
|
|
|
|
read_ids: function() {
|
|
|
|
|
if (this.fop.options.read_function) {
|
|
|
|
|
return this.fop.options.read_function.apply(null, arguments);
|
|
|
|
|
} else {
|
2011-08-29 12:28:37 +00:00
|
|
|
|
return this._super.apply(this, arguments);
|
2011-08-29 12:13:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldReference = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {
|
2012-03-15 16:21:07 +00:00
|
|
|
|
template: 'FieldReference',
|
2012-04-18 12:45:20 +00:00
|
|
|
|
init: function(field_manager, node) {
|
|
|
|
|
this._super(field_manager, node);
|
2011-12-08 12:28:51 +00:00
|
|
|
|
this.reference_ready = true;
|
2011-08-18 17:45:08 +00:00
|
|
|
|
},
|
|
|
|
|
on_nop: function() {
|
|
|
|
|
},
|
|
|
|
|
on_selection_changed: function() {
|
2011-12-08 12:28:51 +00:00
|
|
|
|
if (this.reference_ready) {
|
|
|
|
|
var sel = this.selection.get_value();
|
|
|
|
|
this.m2o.field.relation = sel;
|
2012-04-17 15:45:05 +00:00
|
|
|
|
this.m2o.set_value(false);
|
2011-12-08 12:28:51 +00:00
|
|
|
|
this.m2o.$element.toggle(sel !== false);
|
|
|
|
|
}
|
2011-08-18 17:45:08 +00:00
|
|
|
|
},
|
2012-03-20 10:17:47 +00:00
|
|
|
|
destroy_content: function() {
|
2012-03-19 13:09:52 +00:00
|
|
|
|
if (this.selection) {
|
2012-03-20 09:58:19 +00:00
|
|
|
|
this.selection.destroy();
|
2012-03-19 13:09:52 +00:00
|
|
|
|
this.selection = undefined;
|
|
|
|
|
}
|
|
|
|
|
if (this.m2o) {
|
2012-03-20 09:58:19 +00:00
|
|
|
|
this.m2o.destroy();
|
2012-04-10 11:58:08 +00:00
|
|
|
|
this.m2o = undefined;
|
2012-03-19 13:09:52 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2012-03-20 10:17:47 +00:00
|
|
|
|
initialize_content: function() {
|
2012-04-17 12:09:49 +00:00
|
|
|
|
this.selection = new instance.web.form.FieldSelection(this, { attrs: {
|
2012-04-20 09:20:07 +00:00
|
|
|
|
name: 'selection'
|
2012-04-10 11:58:08 +00:00
|
|
|
|
}});
|
2012-04-20 09:20:07 +00:00
|
|
|
|
this.selection.view = this.view;
|
2012-04-10 11:58:08 +00:00
|
|
|
|
this.selection.set({readonly: this.get('effective_readonly')});
|
2012-04-17 15:45:05 +00:00
|
|
|
|
this.selection.on("change:value", this, this.on_selection_changed);
|
2012-02-20 10:09:58 +00:00
|
|
|
|
this.selection.$element = $(".oe_form_view_reference_selection", this.$element);
|
2012-02-29 11:07:44 +00:00
|
|
|
|
this.selection.renderElement();
|
2011-08-18 17:45:08 +00:00
|
|
|
|
this.selection.start();
|
2012-04-10 11:58:08 +00:00
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
this.m2o = new instance.web.form.FieldMany2One(this, { attrs: {
|
2012-04-20 09:20:07 +00:00
|
|
|
|
name: 'm2o'
|
2012-03-19 13:09:52 +00:00
|
|
|
|
}});
|
2012-04-20 09:20:07 +00:00
|
|
|
|
this.m2o.view = this.view;
|
2012-03-19 13:09:52 +00:00
|
|
|
|
this.m2o.set({"readonly": this.get("effective_readonly")});
|
2012-04-17 15:45:05 +00:00
|
|
|
|
this.m2o.on("change:value", this, this.data_changed);
|
2012-02-20 10:09:58 +00:00
|
|
|
|
this.m2o.$element = $(".oe_form_view_reference_m2o", this.$element);
|
2012-02-29 11:07:44 +00:00
|
|
|
|
this.m2o.renderElement();
|
2011-08-18 17:45:08 +00:00
|
|
|
|
this.m2o.start();
|
|
|
|
|
},
|
2012-04-18 09:50:43 +00:00
|
|
|
|
is_false: function() {
|
|
|
|
|
return typeof(this.get_value()) !== 'string';
|
2011-08-18 17:45:08 +00:00
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {
|
|
|
|
|
this._super(value_);
|
2012-03-19 13:09:52 +00:00
|
|
|
|
this.render_value();
|
2011-08-18 17:45:08 +00:00
|
|
|
|
},
|
2012-04-20 09:20:07 +00:00
|
|
|
|
get_value: function() {
|
|
|
|
|
var tmp = this._super();
|
|
|
|
|
debugger;
|
|
|
|
|
return tmp;
|
|
|
|
|
},
|
2012-03-19 13:09:52 +00:00
|
|
|
|
render_value: function() {
|
2011-12-08 12:28:51 +00:00
|
|
|
|
this.reference_ready = false;
|
|
|
|
|
var vals = [], sel_val, m2o_val;
|
2012-04-17 14:32:27 +00:00
|
|
|
|
if (typeof(this.get('value')) === 'string') {
|
|
|
|
|
vals = this.get('value').split(',');
|
2011-08-18 17:45:08 +00:00
|
|
|
|
}
|
2011-12-08 12:28:51 +00:00
|
|
|
|
sel_val = vals[0] || false;
|
|
|
|
|
m2o_val = vals[1] ? parseInt(vals[1], 10) : false;
|
2012-03-19 13:09:52 +00:00
|
|
|
|
if (!this.get("effective_readonly")) {
|
|
|
|
|
this.selection.set_value(sel_val);
|
|
|
|
|
}
|
2011-12-08 12:28:51 +00:00
|
|
|
|
this.m2o.field.relation = sel_val;
|
|
|
|
|
this.m2o.set_value(m2o_val);
|
|
|
|
|
this.m2o.$element.toggle(sel_val !== false);
|
|
|
|
|
this.reference_ready = true;
|
2011-08-18 17:45:08 +00:00
|
|
|
|
},
|
2012-04-17 15:45:05 +00:00
|
|
|
|
data_changed: function() {
|
2011-08-18 17:45:08 +00:00
|
|
|
|
var model = this.selection.get_value(),
|
|
|
|
|
id = this.m2o.get_value();
|
|
|
|
|
if (typeof(model) === 'string' && typeof(id) === 'number') {
|
2012-04-17 15:45:05 +00:00
|
|
|
|
this.set({'value': model + ',' + id});
|
2011-08-18 17:45:08 +00:00
|
|
|
|
} else {
|
2012-04-17 15:45:05 +00:00
|
|
|
|
this.set({'value': false});
|
2011-08-18 17:45:08 +00:00
|
|
|
|
}
|
2012-04-17 15:45:05 +00:00
|
|
|
|
},
|
2012-04-20 09:20:07 +00:00
|
|
|
|
get_field: function(name) {
|
|
|
|
|
if (name === "selection") {
|
|
|
|
|
return {
|
|
|
|
|
selection: this.view.fields_view.fields[this.name].selection,
|
|
|
|
|
type: "selection",
|
|
|
|
|
};
|
|
|
|
|
} else if (name === "m2o") {
|
|
|
|
|
return {
|
|
|
|
|
relation: null,
|
|
|
|
|
type: "many2one",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
throw Exception("Should not happen");
|
|
|
|
|
},
|
2012-03-19 13:09:52 +00:00
|
|
|
|
}));
|
2011-08-18 17:45:08 +00:00
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {
|
2012-04-18 12:45:20 +00:00
|
|
|
|
init: function(field_manager, node) {
|
|
|
|
|
this._super(field_manager, node);
|
2011-05-18 22:36:16 +00:00
|
|
|
|
this.iframe = this.element_id + '_iframe';
|
2011-05-19 12:58:45 +00:00
|
|
|
|
this.binary_value = false;
|
2011-05-12 15:22:48 +00:00
|
|
|
|
},
|
2012-03-20 10:17:47 +00:00
|
|
|
|
initialize_content: function() {
|
2011-05-18 22:36:16 +00:00
|
|
|
|
this.$element.find('input.oe-binary-file').change(this.on_file_change);
|
2011-05-23 13:38:40 +00:00
|
|
|
|
this.$element.find('button.oe-binary-file-save').click(this.on_save_as);
|
2011-05-19 12:58:45 +00:00
|
|
|
|
this.$element.find('.oe-binary-file-clear').click(this.on_clear);
|
2011-05-18 15:33:56 +00:00
|
|
|
|
},
|
2011-05-19 12:58:45 +00:00
|
|
|
|
human_filesize : function(size) {
|
|
|
|
|
var units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
|
|
|
var i = 0;
|
|
|
|
|
while (size >= 1024) {
|
|
|
|
|
size /= 1024;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return size.toFixed(2) + ' ' + units[i];
|
2011-05-19 10:17:26 +00:00
|
|
|
|
},
|
2011-05-23 13:38:40 +00:00
|
|
|
|
on_file_change: function(e) {
|
2011-05-19 10:17:26 +00:00
|
|
|
|
// TODO: on modern browsers, we could directly read the file locally on client ready to be used on image cropper
|
|
|
|
|
// http://www.html5rocks.com/tutorials/file/dndfiles/
|
|
|
|
|
// http://deepliquid.com/projects/Jcrop/demos.php?demo=handler
|
2011-05-18 22:36:16 +00:00
|
|
|
|
window[this.iframe] = this.on_file_uploaded;
|
2011-05-23 13:38:40 +00:00
|
|
|
|
if ($(e.target).val() != '') {
|
|
|
|
|
this.$element.find('form.oe-binary-form input[name=session_id]').val(this.session.session_id);
|
|
|
|
|
this.$element.find('form.oe-binary-form').submit();
|
2011-10-10 13:33:52 +00:00
|
|
|
|
this.$element.find('.oe-binary-progress').show();
|
|
|
|
|
this.$element.find('.oe-binary').hide();
|
2011-05-23 13:38:40 +00:00
|
|
|
|
}
|
2011-05-18 22:36:16 +00:00
|
|
|
|
},
|
2011-09-06 11:49:21 +00:00
|
|
|
|
on_file_uploaded: function(size, name, content_type, file_base64) {
|
2011-05-18 22:36:16 +00:00
|
|
|
|
delete(window[this.iframe]);
|
|
|
|
|
if (size === false) {
|
2011-10-13 10:26:53 +00:00
|
|
|
|
this.do_warn("File Upload", "There was a problem while uploading your file");
|
2011-08-11 02:42:46 +00:00
|
|
|
|
// TODO: use openerp web crashmanager
|
2011-09-12 13:56:03 +00:00
|
|
|
|
console.warn("Error while uploading file : ", name);
|
2011-05-18 22:36:16 +00:00
|
|
|
|
} else {
|
2011-05-19 12:58:45 +00:00
|
|
|
|
this.on_file_uploaded_and_valid.apply(this, arguments);
|
2011-05-18 22:36:16 +00:00
|
|
|
|
}
|
2011-10-10 13:33:52 +00:00
|
|
|
|
this.$element.find('.oe-binary-progress').hide();
|
|
|
|
|
this.$element.find('.oe-binary').show();
|
2011-05-18 22:36:16 +00:00
|
|
|
|
},
|
2011-09-06 11:49:21 +00:00
|
|
|
|
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
|
2011-05-19 12:58:45 +00:00
|
|
|
|
},
|
2011-05-23 13:38:40 +00:00
|
|
|
|
on_save_as: function() {
|
2012-02-08 10:39:35 +00:00
|
|
|
|
$.blockUI();
|
|
|
|
|
this.session.get_file({
|
|
|
|
|
url: '/web/binary/saveas_ajax',
|
|
|
|
|
data: {data: JSON.stringify({
|
|
|
|
|
model: this.view.dataset.model,
|
|
|
|
|
id: (this.view.datarecord.id || ''),
|
|
|
|
|
field: this.name,
|
|
|
|
|
filename_field: (this.node.attrs.filename || ''),
|
|
|
|
|
context: this.view.dataset.get_context()
|
|
|
|
|
})},
|
|
|
|
|
complete: $.unblockUI,
|
2012-04-17 12:09:49 +00:00
|
|
|
|
error: instance.webclient.crashmanager.on_rpc_error
|
2012-02-08 10:39:35 +00:00
|
|
|
|
});
|
2011-05-23 13:38:40 +00:00
|
|
|
|
},
|
2011-05-18 15:33:56 +00:00
|
|
|
|
on_clear: function() {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
if (this.get('value') !== false) {
|
2011-05-19 12:58:45 +00:00
|
|
|
|
this.binary_value = false;
|
2012-04-17 15:45:05 +00:00
|
|
|
|
this.set({'value': false});
|
2011-05-18 15:33:56 +00:00
|
|
|
|
}
|
2011-05-19 10:17:26 +00:00
|
|
|
|
return false;
|
2011-05-19 12:58:45 +00:00
|
|
|
|
}
|
2012-03-19 16:13:58 +00:00
|
|
|
|
}));
|
2011-05-19 12:58:45 +00:00
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldBinaryFile = instance.web.form.FieldBinary.extend({
|
2012-03-15 16:21:07 +00:00
|
|
|
|
template: 'FieldBinaryFile',
|
2012-03-20 10:17:47 +00:00
|
|
|
|
initialize_content: function() {
|
2012-03-19 16:18:56 +00:00
|
|
|
|
this._super();
|
2012-03-19 16:13:58 +00:00
|
|
|
|
if (this.get("effective_readonly")) {
|
|
|
|
|
var self = this;
|
|
|
|
|
this.$element.find('a').click(function() {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
if (self.get('value')) {
|
2012-03-19 16:13:58 +00:00
|
|
|
|
self.on_save_as();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
}
|
2011-10-10 13:33:52 +00:00
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {
|
2011-05-19 12:58:45 +00:00
|
|
|
|
this._super.apply(this, arguments);
|
2012-03-19 16:13:58 +00:00
|
|
|
|
this.render_value();
|
|
|
|
|
},
|
|
|
|
|
render_value: function() {
|
|
|
|
|
if (!this.get("effective_readonly")) {
|
|
|
|
|
var show_value;
|
|
|
|
|
if (this.node.attrs.filename) {
|
|
|
|
|
show_value = this.view.datarecord[this.node.attrs.filename] || '';
|
|
|
|
|
} else {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
show_value = (this.get('value') != null && this.get('value') !== false) ? this.get('value') : '';
|
2012-03-19 16:13:58 +00:00
|
|
|
|
}
|
|
|
|
|
this.$element.find('input').eq(0).val(show_value);
|
2011-12-15 12:04:15 +00:00
|
|
|
|
} else {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this.$element.find('a').show(!!this.get('value'));
|
|
|
|
|
if (this.get('value')) {
|
2012-03-19 16:13:58 +00:00
|
|
|
|
var show_value = _t("Download") + " " + (this.view.datarecord[this.node.attrs.filename] || '');
|
|
|
|
|
this.$element.find('a').text(show_value);
|
|
|
|
|
}
|
2011-12-15 12:04:15 +00:00
|
|
|
|
}
|
2011-05-19 12:58:45 +00:00
|
|
|
|
},
|
2011-09-06 11:49:21 +00:00
|
|
|
|
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
|
2011-05-19 12:58:45 +00:00
|
|
|
|
this.binary_value = true;
|
2012-04-17 15:45:05 +00:00
|
|
|
|
this.set({'value': file_base64});
|
2011-12-15 12:04:15 +00:00
|
|
|
|
var show_value = name + " (" + this.human_filesize(size) + ")";
|
2011-05-19 12:58:45 +00:00
|
|
|
|
this.$element.find('input').eq(0).val(show_value);
|
|
|
|
|
this.set_filename(name);
|
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_filename: function(value_) {
|
2011-05-19 12:58:45 +00:00
|
|
|
|
var filename = this.node.attrs.filename;
|
|
|
|
|
if (this.view.fields[filename]) {
|
2012-04-17 15:45:05 +00:00
|
|
|
|
this.view.fields[filename].set({value: value_});
|
2011-05-19 12:58:45 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
on_clear: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
this.$element.find('input').eq(0).val('');
|
|
|
|
|
this.set_filename('');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({
|
2012-03-15 16:21:07 +00:00
|
|
|
|
template: 'FieldBinaryImage',
|
2012-03-20 10:17:47 +00:00
|
|
|
|
initialize_content: function() {
|
2012-03-19 16:18:56 +00:00
|
|
|
|
this._super();
|
2012-03-23 15:04:48 +00:00
|
|
|
|
this.$placeholder = $(".oe_form_field-binary-image-placeholder", this.$element);
|
2012-03-19 16:13:58 +00:00
|
|
|
|
if (!this.get("effective_readonly"))
|
|
|
|
|
this.$element.find('.oe-binary').show();
|
|
|
|
|
else
|
|
|
|
|
this.$element.find('.oe-binary').hide();
|
2011-05-19 12:58:45 +00:00
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {
|
2011-10-10 13:33:52 +00:00
|
|
|
|
this._super.apply(this, arguments);
|
2012-03-19 16:13:58 +00:00
|
|
|
|
this.render_value();
|
2011-10-10 13:33:52 +00:00
|
|
|
|
},
|
2012-03-19 16:13:58 +00:00
|
|
|
|
render_value: function() {
|
2012-03-08 14:06:36 +00:00
|
|
|
|
var url;
|
2012-04-17 14:32:27 +00:00
|
|
|
|
if (this.get('value') && this.get('value').substr(0, 10).indexOf(' ') == -1) {
|
|
|
|
|
url = 'data:image/png;base64,' + this.get('value');
|
|
|
|
|
} else if (this.get('value')) {
|
2012-03-08 14:06:36 +00:00
|
|
|
|
url = '/web/binary/image?session_id=' + this.session.session_id + '&model=' +
|
|
|
|
|
this.view.dataset.model +'&id=' + (this.view.datarecord.id || '') + '&field=' + this.name + '&t=' + (new Date().getTime());
|
2012-03-23 15:04:48 +00:00
|
|
|
|
} else {
|
|
|
|
|
url = "/web/static/src/img/placeholder.png";
|
2012-03-08 14:06:36 +00:00
|
|
|
|
}
|
2012-03-23 15:04:48 +00:00
|
|
|
|
var rendered = QWeb.render("FieldBinaryImage-img", {widget: this, url: url});;
|
|
|
|
|
this.$placeholder.html(rendered);
|
2011-05-19 12:58:45 +00:00
|
|
|
|
},
|
|
|
|
|
on_file_change: function() {
|
2012-03-23 15:04:48 +00:00
|
|
|
|
this.render_value();
|
2011-05-19 12:58:45 +00:00
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
},
|
2011-09-06 11:49:21 +00:00
|
|
|
|
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
|
2012-04-17 14:32:27 +00:00
|
|
|
|
this.set({'value': file_base64});
|
2011-05-19 12:58:45 +00:00
|
|
|
|
this.binary_value = true;
|
2012-03-23 15:04:48 +00:00
|
|
|
|
this.render_value();
|
2011-05-19 12:58:45 +00:00
|
|
|
|
},
|
|
|
|
|
on_clear: function() {
|
|
|
|
|
this._super.apply(this, arguments);
|
2012-03-23 15:04:48 +00:00
|
|
|
|
this.render_value();
|
2011-05-12 15:22:48 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({
|
2012-03-15 16:21:07 +00:00
|
|
|
|
template: "EmptyComponent",
|
2011-09-08 14:58:45 +00:00
|
|
|
|
start: function() {
|
2011-09-08 15:06:45 +00:00
|
|
|
|
this._super();
|
2011-09-08 16:35:36 +00:00
|
|
|
|
this.selected_value = null;
|
2011-10-19 12:50:34 +00:00
|
|
|
|
|
2011-09-08 15:06:45 +00:00
|
|
|
|
this.render_list();
|
2011-09-08 14:58:45 +00:00
|
|
|
|
},
|
2012-04-17 14:32:27 +00:00
|
|
|
|
set_value: function(value_) {
|
|
|
|
|
this._super(value_);
|
|
|
|
|
this.selected_value = value_;
|
2011-10-19 12:50:34 +00:00
|
|
|
|
|
2011-09-08 15:06:45 +00:00
|
|
|
|
this.render_list();
|
2011-09-08 14:58:45 +00:00
|
|
|
|
},
|
2011-09-08 15:06:45 +00:00
|
|
|
|
render_list: function() {
|
2011-09-08 16:35:36 +00:00
|
|
|
|
var self = this;
|
|
|
|
|
var shown = _.map(((this.node.attrs || {}).statusbar_visible || "").split(","),
|
2011-11-15 12:30:59 +00:00
|
|
|
|
function(x) { return _.str.trim(x); });
|
2011-09-13 09:34:09 +00:00
|
|
|
|
shown = _.select(shown, function(x) { return x.length > 0; });
|
2011-10-19 12:50:34 +00:00
|
|
|
|
|
2011-09-08 16:35:36 +00:00
|
|
|
|
if (shown.length == 0) {
|
|
|
|
|
this.to_show = this.field.selection;
|
|
|
|
|
} else {
|
|
|
|
|
this.to_show = _.select(this.field.selection, function(x) {
|
|
|
|
|
return _.indexOf(shown, x[0]) !== -1 || x[0] === self.selected_value;
|
|
|
|
|
});
|
|
|
|
|
}
|
2011-10-19 12:50:34 +00:00
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
var content = instance.web.qweb.render("FieldStatus.content", {widget: this, _:_});
|
2011-09-08 15:09:32 +00:00
|
|
|
|
this.$element.html(content);
|
2011-10-19 12:50:34 +00:00
|
|
|
|
|
2011-09-09 14:34:50 +00:00
|
|
|
|
var colors = JSON.parse((this.node.attrs || {}).statusbar_colors || "{}");
|
2011-09-08 17:00:12 +00:00
|
|
|
|
var color = colors[this.selected_value];
|
|
|
|
|
if (color) {
|
|
|
|
|
var elem = this.$element.find("li.oe-arrow-list-selected span");
|
|
|
|
|
elem.css("border-color", color);
|
2011-10-17 12:09:01 +00:00
|
|
|
|
if (this.check_white(color))
|
|
|
|
|
elem.css("color", "white");
|
2011-09-08 17:00:12 +00:00
|
|
|
|
elem = this.$element.find("li.oe-arrow-list-selected .oe-arrow-list-before");
|
|
|
|
|
elem.css("border-left-color", "rgba(0,0,0,0)");
|
|
|
|
|
elem = this.$element.find("li.oe-arrow-list-selected .oe-arrow-list-after");
|
|
|
|
|
elem.css("border-color", "rgba(0,0,0,0)");
|
|
|
|
|
elem.css("border-left-color", color);
|
|
|
|
|
}
|
2011-10-17 12:09:01 +00:00
|
|
|
|
},
|
|
|
|
|
check_white: function(color) {
|
|
|
|
|
var div = $("<div></div>");
|
|
|
|
|
div.css("display", "none");
|
|
|
|
|
div.css("color", color);
|
2012-01-04 15:53:29 +00:00
|
|
|
|
div.appendTo($("body"));
|
2011-10-17 12:09:01 +00:00
|
|
|
|
var ncolor = div.css("color");
|
|
|
|
|
div.remove();
|
|
|
|
|
var res = /^\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/.exec(ncolor);
|
|
|
|
|
if (!res) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
var comps = [parseInt(res[1]), parseInt(res[2]), parseInt(res[3])];
|
|
|
|
|
var lum = comps[0] * 0.3 + comps[1] * 0.59 + comps[1] * 0.11;
|
|
|
|
|
if (lum < 128) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2011-09-08 14:58:45 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-03-31 10:57:51 +00:00
|
|
|
|
/**
|
2012-04-17 12:09:49 +00:00
|
|
|
|
* Registry of form widgets, called by :js:`instance.web.FormView`
|
2011-03-31 10:57:51 +00:00
|
|
|
|
*/
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.widgets = new instance.web.Registry({
|
|
|
|
|
'char' : 'instance.web.form.FieldChar',
|
|
|
|
|
'id' : 'instance.web.form.FieldID',
|
|
|
|
|
'email' : 'instance.web.form.FieldEmail',
|
|
|
|
|
'url' : 'instance.web.form.FieldUrl',
|
|
|
|
|
'text' : 'instance.web.form.FieldText',
|
|
|
|
|
'date' : 'instance.web.form.FieldDate',
|
|
|
|
|
'datetime' : 'instance.web.form.FieldDatetime',
|
|
|
|
|
'selection' : 'instance.web.form.FieldSelection',
|
|
|
|
|
'many2one' : 'instance.web.form.FieldMany2One',
|
|
|
|
|
'many2many' : 'instance.web.form.FieldMany2Many',
|
|
|
|
|
'one2many' : 'instance.web.form.FieldOne2Many',
|
|
|
|
|
'one2many_list' : 'instance.web.form.FieldOne2Many',
|
|
|
|
|
'reference' : 'instance.web.form.FieldReference',
|
|
|
|
|
'boolean' : 'instance.web.form.FieldBoolean',
|
|
|
|
|
'float' : 'instance.web.form.FieldFloat',
|
|
|
|
|
'integer': 'instance.web.form.FieldFloat',
|
|
|
|
|
'float_time': 'instance.web.form.FieldFloat',
|
|
|
|
|
'progressbar': 'instance.web.form.FieldProgressBar',
|
|
|
|
|
'image': 'instance.web.form.FieldBinaryImage',
|
|
|
|
|
'binary': 'instance.web.form.FieldBinaryFile',
|
|
|
|
|
'statusbar': 'instance.web.form.FieldStatus'
|
2011-03-31 10:57:51 +00:00
|
|
|
|
});
|
2011-10-31 10:27:52 +00:00
|
|
|
|
|
2012-04-17 12:09:49 +00:00
|
|
|
|
instance.web.form.tags = new instance.web.Registry({
|
|
|
|
|
'button' : 'instance.web.form.WidgetButton',
|
2012-04-10 13:04:44 +00:00
|
|
|
|
});
|
2011-03-30 14:00:48 +00:00
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|