this.create_function = null;
this.write_function = null;
this.read_function = null;
+ this.default_get_function = null;
+ this.unlink_function = null;
},
- read_ids: function () {
+ read_ids: function (ids, fields, options) {
if (this.read_function) {
- return this.read_function.apply(null, arguments);
+ return this.read_function(ids, fields, options, this._super);
} else {
return this._super.apply(this, arguments);
}
},
default_get: function(fields, options) {
- return this._super(fields, options).then(this.on_default_get);
+ if (this.default_get_function) {
+ return this.default_get_function(fields, options, this._super);
+ } else {
+ return this._super.apply(this, arguments);
+ }
},
- on_default_get: function(result) {},
create: function(data, callback, error_callback) {
- this.on_create(data);
if (this.create_function) {
- return this.create_function(data, callback, error_callback);
+ return this.create_function(data, this._super).then(callback, error_callback);
} else {
- return $.async_when({"result": undefined}).then(callback);
+ return this._super.apply(this, arguments);
}
},
- on_create: function(data) {},
- write: function (id, data, options, callback) {
- this.on_write(id, data);
+ write: function (id, data, options, callback, error_callback) {
if (this.write_function) {
- return this.write_function(id, data, options, callback);
+ return this.write_function(id, data, options, this._super).then(callback, error_callback);
} else {
- return $.async_when({"result": true}).then(callback);
+ return this._super.apply(this, arguments);
}
},
- on_write: function(id, data) {},
unlink: function(ids, callback, error_callback) {
- this.on_unlink(ids);
- return $.async_when({"result": true}).then(callback);
+ if (this.unlink_function) {
+ return this.unlink_function(ids, this._super).then(callback, error_callback);
+ } else {
+ return this._super.apply(this, arguments);
+ }
},
- on_unlink: function(ids) {}
});
instance.web.CompoundContext = instance.web.Class.extend({
var pop = new instance.web.form.FormOpenPopup(self.o2m.view);
pop.show_element(self.o2m.field.relation, id, self.o2m.build_context(), {
title: _t("Open: ") + self.name,
- auto_write: false,
+ write_function: function(id, data, options) {
+ return self.o2m.dataset.write(id, data, {}).then(function() {
+ self.o2m.reload_current_view();
+ });
+ },
alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined,
parent_view: self.o2m.view,
child_name: self.o2m.name,
form_view_options: {'not_interactible_on_create':true},
readonly: self.o2m.get("effective_readonly")
});
- pop.on_write.add(function(id, data) {
- self.o2m.dataset.write(id, data, {}, function(r) {
- self.o2m.reload_current_view();
- });
- });
},
});
} else {
var self = this;
var pop = new instance.web.form.SelectCreatePopup(this);
- pop.on_default_get.add(self.dataset.on_default_get);
pop.select_element(
self.o2m.field.relation,
{
var pop = new instance.web.form.FormOpenPopup(self.o2m.view);
pop.show_element(self.o2m.field.relation, id, self.o2m.build_context(), {
title: _t("Open: ") + self.name,
- auto_write: false,
+ write_function: function(id, data) {
+ return self.o2m.dataset.write(id, data, {}, function(r) {
+ self.o2m.reload_current_view();
+ });
+ },
alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined,
parent_view: self.o2m.view,
child_name: self.o2m.name,
form_view_options: {'not_interactible_on_create':true},
readonly: self.o2m.get("effective_readonly")
});
- pop.on_write.add(function(id, data) {
- self.o2m.dataset.write(id, data, {}, function(r) {
- self.o2m.reload_current_view();
- });
- });
},
do_button_action: function (name, id, callback) {
var self = this;
template: "AbstractFormPopup.render",
/**
* options:
+ * -readonly: only applicable when not in creation mode, default to false
*/
init_popup: function(model, row_id, domain, context, options) {
this.row_id = row_id;
_.defaults(this.options, {
});
},
+ init_dataset: function() {
+ var self = this;
+ this.dataset = new instance.web.ProxyDataSet(this, this.model, this.context);
+ this.dataset.read_function = this.options.read_function;
+ this.dataset.create_function = function(data, sup) {
+ var fct = self.options.create_function || sup;
+ return fct.call(this, data).then(function(r) {
+ self.created_elements.push(r.result);
+ });
+ };
+ this.dataset.write_function = function(id, data, options, sup) {
+ var fct = self.options.write_function || sup;
+ return sup.call(this, id, data, options).then(self.on_write_completed);
+ };
+ this.dataset.parent_view = this.options.parent_view;
+ this.dataset.child_name = this.options.child_name;
+ },
+ display_popup: function() {
+ this.renderElement();
+ instance.web.form.dialog(this.$element, {
+ close: function() {
+ self.check_exit();
+ },
+ title: this.options.title || ""
+ });
+ this.start();
+ },
+ on_write_completed: function() {},
setup_form_view: function() {
var self = this;
var options = _.clone(self.options.form_view_options) || {};
* - read_function
*/
select_element: function(model, options, domain, context) {
+ this.init_popup(model, null, domain, context, options);
var self = this;
- this.init_popup(model, null, domain, context, _.extend({}, options, {create_mode:true}));
_.defaults(this.options, {
- "initial_view": "search",
- "create_function": function() {
+ initial_view: "search",
+ create_function: function() {
return self.create_row.apply(self, arguments);
},
read_function: null,
});
this.initial_ids = this.options.initial_ids;
this.created_elements = [];
- this.renderElement();
- instance.web.form.dialog(this.$element, {
- close: function() {
- self.check_exit();
- },
- title: options.title || ""
- });
- this.start();
+ this.display_popup();
},
start: function() {
- this._super();
var self = this;
- this.dataset = new instance.web.ProxyDataSet(this, this.model,
- this.context);
- this.dataset.create_function = function() {
- return self.options.create_function.apply(null, arguments).then(function(r) {
- self.created_elements.push(r.result);
- });
- };
- this.dataset.write_function = function() {
- return self.write_row.apply(self, arguments);
- };
- this.dataset.read_function = this.options.read_function;
- this.dataset.parent_view = this.options.parent_view;
- this.dataset.child_name = this.options.child_name;
- this.dataset.on_default_get.add(this.on_default_get);
+ this.init_dataset();
if (this.options.initial_view == "search") {
self.rpc('/web/session/eval_domain_and_context', {
domains: [],
wdataset.child_name = this.options.child_name;
return wdataset.create.apply(wdataset, arguments);
},
- write_row: function() {
- var self = this;
- var wdataset = new instance.web.DataSetSearch(this, this.model, this.context, this.domain);
- wdataset.parent_view = this.options.parent_view;
- wdataset.child_name = this.options.child_name;
- return wdataset.write.apply(wdataset, arguments);
- },
on_select_elements: function(element_ids) {
},
on_click_element: function(ids) {
if (this.created_elements.length > 0) {
this.on_select_elements(this.created_elements);
}
- this.destroy();
+ this._super();
},
- on_default_get: function(res) {}
});
instance.web.form.SelectCreateListView = instance.web.ListView.extend({
/**
* options:
* - alternative_form_view
- * - auto_write (default true)
+ * - write_function
* - read_function
* - parent_view
* - child_name
* - form_view_options
- * - readonly
*/
show_element: function(model, row_id, context, options) {
- this.init_popup(model, row_id, [], context, _.extend({}, options, {create_mode:false}));
+ this.init_popup(model, row_id, [], context, options);
_.defaults(this.options, {
- "auto_write": true,
- });
- this.renderElement();
- instance.web.dialog(this.$element, {
- title: options.title || '',
- modal: true,
- width: 960,
- height: 600
+ auto_write: true,
});
- this.start();
+ this.display_popup();
},
start: function() {
this._super();
- this.dataset = new instance.web.ProxyDataSet(this, this.model, this.context);
- this.dataset.read_function = this.options.read_function;
+ this.init_dataset();
this.dataset.ids = [this.row_id];
this.dataset.index = 0;
- this.dataset.parent_view = this.options.parent_view;
- this.dataset.child_name = this.options.child_name;
- this.dataset.on_write.add(this.write_row);
this.setup_form_view();
},
- write_row: function(id, data) {
- if (!this.options.auto_write)
- return;
- var self = this;
- var wdataset = new instance.web.DataSetSearch(this, this.model, this.context, this.domain);
- wdataset.parent_view = this.options.parent_view;
- wdataset.child_name = this.options.child_name;
- wdataset.write(id, data, {}, function(r) {
- self.on_write_completed();
- });
- },
- on_write_completed: function() {},
});
instance.web.form.FieldReference = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {