[merge] lot of improvements to form o2m
bzr revid: nicolas.vanhoren@openerp.com-20110727140943-zjg2tyz0jloesxw6
This commit is contained in:
@@ -291,14 +291,18 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.
|
||||
* Read the indexed record.
|
||||
*/
|
||||
read_index: function (fields, callback) {
|
||||
var def = $.Deferred().then(callback);
|
||||
if (_.isEmpty(this.ids)) {
|
||||
return $.Deferred().reject().promise();
|
||||
def.reject();
|
||||
} else {
|
||||
fields = fields || false;
|
||||
return this.read_ids([this.ids[this.index]], fields, function(records) {
|
||||
callback(records[0]);
|
||||
return this.read_ids([this.ids[this.index]], fields).then(function(records) {
|
||||
def.resolve(records[0]);
|
||||
}, function() {
|
||||
def.reject.apply(def, arguments);
|
||||
});
|
||||
}
|
||||
return def.promise();
|
||||
},
|
||||
default_get: function(fields, callback) {
|
||||
return this.rpc('/base/dataset/default_get', {
|
||||
|
||||
@@ -829,10 +829,12 @@ openerp.base.form.Field = openerp.base.form.Widget.extend({
|
||||
},
|
||||
update_dom: function() {
|
||||
this._super.apply(this, arguments);
|
||||
this.$element.toggleClass('disabled', this.readonly);
|
||||
this.$element.toggleClass('required', this.required);
|
||||
if (this.view.show_invalid) {
|
||||
this.$element.toggleClass('invalid', !this.is_valid());
|
||||
if (!this.disable_utility_classes) {
|
||||
this.$element.toggleClass('disabled', this.readonly);
|
||||
this.$element.toggleClass('required', this.required);
|
||||
if (this.view.show_invalid) {
|
||||
this.$element.toggleClass('invalid', !this.is_valid());
|
||||
}
|
||||
}
|
||||
},
|
||||
on_ui_change: function() {
|
||||
@@ -1590,6 +1592,7 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
||||
this.template = "FieldOne2Many";
|
||||
this.is_started = $.Deferred();
|
||||
this.form_last_update = $.Deferred();
|
||||
this.disable_utility_classes = true;
|
||||
},
|
||||
start: function() {
|
||||
this._super.apply(this, arguments);
|
||||
@@ -1635,12 +1638,16 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
||||
controller.on_record_loaded.add_last(function() {
|
||||
once.resolve();
|
||||
});
|
||||
controller.on_form_changed.add_last(function() {
|
||||
controller.on_pager_action.add_first(function() {
|
||||
self.save_form_view();
|
||||
});
|
||||
controller.$element.find(".oe_form_button_save_edit").hide();
|
||||
}
|
||||
self.is_started.resolve();
|
||||
});
|
||||
this.viewmanager.on_mode_switch.add_first(function() {
|
||||
self.save_form_view();
|
||||
});
|
||||
setTimeout(function () {
|
||||
self.viewmanager.start();
|
||||
}, 0);
|
||||
@@ -1710,6 +1717,9 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
||||
this._super(value);
|
||||
this.dataset.reset_ids(value);
|
||||
}
|
||||
if (this.dataset.index === null && this.dataset.ids.length > 0) {
|
||||
this.dataset.index = 0;
|
||||
}
|
||||
$.when(this.is_started).then(function() {
|
||||
self.reload_current_view();
|
||||
});
|
||||
@@ -1718,7 +1728,6 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
||||
var self = this;
|
||||
if (!this.dataset)
|
||||
return [];
|
||||
this.save_form_view();
|
||||
var val = this.dataset.delete_all ? [commands.delete_all()] : [];
|
||||
val = val.concat(_.map(this.dataset.ids, function(id) {
|
||||
var alter_order = _.detect(self.dataset.to_create, function(x) {return x.id === id;});
|
||||
@@ -1749,16 +1758,20 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
||||
} else if (!res.isResolved()) {
|
||||
throw "Asynchronous get_value() is not supported in form view.";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
is_valid: function() {
|
||||
this.validate();
|
||||
return this._super();
|
||||
},
|
||||
validate: function() {
|
||||
this.invalid = false;
|
||||
var self = this;
|
||||
var view = self.viewmanager.views[self.viewmanager.active_view].controller;
|
||||
if(self.viewmanager.active_view === "list") {
|
||||
return;
|
||||
} else if (self.viewmanager.active_view === "form") {
|
||||
if (self.viewmanager.active_view === "form") {
|
||||
for (var f in view.fields) {
|
||||
f = view.fields[f];
|
||||
if (!f.is_valid()) {
|
||||
@@ -1767,6 +1780,14 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
is_dirty: function() {
|
||||
this.save_form_view();
|
||||
return this._super();
|
||||
},
|
||||
update_dom: function() {
|
||||
this._super.apply(this, arguments);
|
||||
this.$element.toggleClass('disabled', this.readonly);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user