Set default value for new added fields to model group
Defines add_fields on Group and uses it instead of the one on Model. This new method is used when setting group on Screen to ensure to trigger the load of default values. issue6058 review29781003
This commit is contained in:
1 parent
da43bf0673
commit
e7ad2754a7
2 files changed
+34
-4
No files matched your search
+25
-2
@@ -11,14 +11,17 @@
|
||||
this.fields = {};
|
||||
},
|
||||
add_fields: function(descriptions) {
|
||||
var added = [];
|
||||
for (var name in descriptions) {
|
||||
if (descriptions.hasOwnProperty(name) &&
|
||||
(!(name in this.fields))) {
|
||||
var desc = descriptions[name];
|
||||
var Field = Sao.field.get(desc.type);
|
||||
this.fields[name] = new Field(desc);
|
||||
added.push(name);
|
||||
}
|
||||
}
|
||||
return added;
|
||||
},
|
||||
execute: function(method, params, context) {
|
||||
if (context === undefined) {
|
||||
@@ -339,6 +342,26 @@
|
||||
this.parent.group.children.push(this);
|
||||
}
|
||||
};
|
||||
array.add_fields = function(fields) {
|
||||
var added = this.model.add_fields(fields);
|
||||
if (jQuery.isEmptyObject(this)) {
|
||||
return;
|
||||
}
|
||||
var new_ = [];
|
||||
this.forEach(function(record) {
|
||||
if (record.id < 0) {
|
||||
new_.push(record);
|
||||
}
|
||||
});
|
||||
if (new_.length && added.length) {
|
||||
this.model.execute('default_get', [added, this.context()])
|
||||
.then(function(values) {
|
||||
new_.forEach(function(record) {
|
||||
record.set_default(values);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
array.destroy = function() {
|
||||
if (this.parent) {
|
||||
var i = this.parent.group.children.indexOf(this);
|
||||
@@ -1892,7 +1915,7 @@
|
||||
var set_value = function(fields) {
|
||||
var promises = [];
|
||||
if (!jQuery.isEmptyObject(fields)) {
|
||||
group.model.add_fields(fields);
|
||||
group.add_fields(fields);
|
||||
}
|
||||
record._values[this.name] = group;
|
||||
if (mode == 'list ids') {
|
||||
@@ -2098,7 +2121,7 @@
|
||||
|
||||
if (value.add || value.update) {
|
||||
prm.then(function(fields) {
|
||||
group.model.add_fields(fields);
|
||||
group.add_fields(fields);
|
||||
if (value.add) {
|
||||
value.add.forEach(function(vals) {
|
||||
var index = vals[0];
|
||||
|
||||
+9
-2
@@ -729,7 +729,7 @@
|
||||
.description.loading;
|
||||
}
|
||||
}
|
||||
this.model.add_fields(fields);
|
||||
this.group.add_fields(fields);
|
||||
var view_widget = Sao.View.parse(this, xml_view, view.field_childs);
|
||||
view_widget.view_id = view_id;
|
||||
this.views.push(view_widget);
|
||||
@@ -890,8 +890,14 @@
|
||||
}.bind(this));
|
||||
},
|
||||
set_group: function(group) {
|
||||
var fields = {};
|
||||
if (this.group) {
|
||||
jQuery.extend(group.model.fields, this.group.model.fields);
|
||||
for (var name in this.group.model.fields) {
|
||||
if (!this.group.model.fields.hasOwnProperty(name)) {
|
||||
continue;
|
||||
}
|
||||
fields[name] = this.group.model.fields[name].description;
|
||||
}
|
||||
this.group.screens.splice(
|
||||
this.group.screens.indexOf(this), 1);
|
||||
jQuery.extend(group.on_write, this.group.on_write);
|
||||
@@ -911,6 +917,7 @@
|
||||
} else {
|
||||
this.set_current_record(group[0]);
|
||||
}
|
||||
this.group.add_fields(fields);
|
||||
},
|
||||
new_group: function(ids) {
|
||||
var group = new Sao.Group(this.model, this.context, []);
|
||||
|
||||
Reference in new issue
Block a user