Remove use of screen.current_record and screen.group from views

issue8067
review62411002
This commit is contained in:
Nicolas Évrard committed 2019-03-01 15:05:50 +01:00
1 parent 5cd8a3c559
commit 296a60613b
5 files changed
+41 -33

No files matched your search

+9
View File
@@ -18,6 +18,15 @@
}
screen.set_on_write(this.attributes.on_write);
},
get record() {
return this.screen.current_record;
},
set record(value) {
this.screen.current_record = value;
},
get group() {
return this.screen.group;
},
set_value: function() {
},
get_fields: function() {
+1 -1
View File
@@ -140,7 +140,7 @@
this.events = [];
var promisses = [];
prm.then(function() {
this.screen.group.forEach(function(record) {
this.group.forEach(function(record) {
var record_promisses = [];
this.fields.forEach(function(name) {
record_promisses.push(record.load(name));
+7 -7
View File
@@ -326,7 +326,7 @@ function eval_pyson(value){
return buttons;
},
display: function() {
var record = this.screen.current_record;
var record = this.record;
var field;
var name;
var promesses = [];
@@ -363,7 +363,7 @@ function eval_pyson(value){
};
return jQuery.when.apply(jQuery,promesses)
.done(function() {
var record = this.screen.current_record;
var record = this.record;
for (name in this.widgets) {
var widgets = this.widgets[name];
field = null;
@@ -377,7 +377,7 @@ function eval_pyson(value){
}
}.bind(this))
.done(function() {
var record = this.screen.current_record;
var record = this.record;
var j;
for (j in this.state_widgets) {
var state_widget = this.state_widgets[j];
@@ -390,7 +390,7 @@ function eval_pyson(value){
}.bind(this));
},
set_value: function() {
var record = this.screen.current_record;
var record = this.record;
if (record) {
var set_value = function(widget) {
widget.set_value(record, this);
@@ -412,8 +412,8 @@ function eval_pyson(value){
});
},
get selected_records() {
if (this.screen.current_record) {
return [this.screen.current_record];
if (this.record) {
return [this.record];
}
return [];
},
@@ -442,7 +442,7 @@ function eval_pyson(value){
}
}
var record = this.screen.current_record;
var record = this.record;
if (record) {
var invalid_widgets = [];
// We use the has-error class to find the invalid elements
+1 -1
View File
@@ -73,7 +73,7 @@
return new Widget(this, xfield, yfields);
},
display: function() {
return this.widget.display(this.screen.group);
return this.widget.display(this.group);
}
});
+23 -24
View File
@@ -289,18 +289,18 @@
this.screen.order = [[column.attributes.name, 'ASC']];
}
var unsaved_records = [];
this.screen.group.forEach(function(unsaved_record) {
this.group.forEach(function(unsaved_record) {
if (unsaved_record.id < 0) {
unsaved_records = unsaved_record.group;
}
});
var search_string = this.screen.screen_container.get_text();
if ((!jQuery.isEmptyObject(unsaved_records)) ||
(this.screen.search_count == this.screen.group.length) ||
(this.screen.group.parent)) {
(this.screen.search_count == this.group.length) ||
(this.group.parent)) {
this.screen.search_filter(search_string, true).then(
function(ids) {
this.screen.group.sort(function(a, b) {
this.group.sort(function(a, b) {
a = ids.indexOf(a.id);
a = a < 0 ? ids.length : a;
b = ids.indexOf(b.id);
@@ -358,7 +358,7 @@
return buttons;
},
display: function(selected, expanded) {
var current_record = this.screen.current_record;
var current_record = this.record;
if (jQuery.isEmptyObject(selected)) {
selected = this.get_selected_paths();
if (this.selection.prop('checked') &&
@@ -370,8 +370,7 @@
});
} else {
if (current_record) {
var current_path = current_record.get_path(
this.screen.group);
var current_path = current_record.get_path(this.group);
current_path = current_path.map(function(e) {
return e[1];
});
@@ -397,18 +396,18 @@
});
}.bind(this);
var min_display_size = Math.min(
this.screen.group.length, this.display_size);
this.group.length, this.display_size);
// XXX find better check to keep focus
if (this.children_field) {
this.construct();
} else if ((min_display_size > this.rows.length) &&
Sao.common.compare(
this.screen.group.slice(0, this.rows.length),
this.group.slice(0, this.rows.length),
row_records())) {
this.construct(true);
} else if ((min_display_size != this.rows.length) ||
!Sao.common.compare(
this.screen.group.slice(0, this.rows.length),
this.group.slice(0, this.rows.length),
row_records())){
this.construct();
}
@@ -530,13 +529,13 @@
this.rows.push(tree_row);
tree_row.construct();
};
this.screen.group.slice(start, this.display_size).forEach(
this.group.slice(start, this.display_size).forEach(
add_row.bind(this));
if (!extend) {
tbody.replaceWith(this.tbody);
}
if (this.display_size < this.screen.group.length) {
if (this.display_size < this.group.length) {
var more_row = jQuery('<tr/>', {
'class': 'more-row',
});
@@ -565,7 +564,7 @@
record = this.edited_row.record;
this.edited_row.set_selection(true);
}
this.screen.current_record = record;
this.record = record;
// TODO update_children
},
update_sum: function() {
@@ -587,8 +586,8 @@
var records_ids = selected_records.map(function(record){
return record.id;
});
for (i=0; i < this.screen.group.length; i++){
record = this.screen.group[i];
for (i=0; i < this.group.length; i++) {
record = this.group[i];
if (!record.get_loaded([name]) && record.id >=0){
loaded = false;
break;
@@ -623,7 +622,7 @@
}
if (loaded) {
if (field.description.type == 'timedelta'){
var converter = field.converter(this.screen.group);
var converter = field.converter(this.group);
selected_sum = Sao.common.timedelta.format(
Sao.TimeDelta(null, selected_sum), converter);
sum_ = Sao.common.timedelta.format(
@@ -658,7 +657,7 @@
this.rows.forEach(add_record);
if (this.selection.prop('checked') &&
!this.selection.prop('indeterminate')) {
this.screen.group.slice(this.rows.length)
this.group.slice(this.rows.length)
.forEach(function(record) {
records.push(record);
});
@@ -690,7 +689,7 @@
this.selection.prop('checked', false);
} else if (selected_records.length ==
this.tbody.children().length &&
this.display_size >= this.screen.group.length) {
this.display_size >= this.group.length) {
this.selection.prop('checked', true);
} else {
this.selection.prop('indeterminate', true);
@@ -765,12 +764,12 @@
var i, root_group, path, row_path, row, column;
var row_idx, rest, td;
if (!this.screen.current_record) {
if (!this.record) {
return;
}
path = this.screen.current_record.get_index_path(this.screen.group);
path = this.record.get_index_path(this.group);
if (this.rows.length < path[0]) {
this.display_size = this.screen.group.length;
this.display_size = this.group.length;
this.display();
}
row_idx = path[0];
@@ -812,7 +811,7 @@
}
return;
}
if (!this.screen.group.parent) {
if (!this.group.parent) {
prm = this.edited_row.record.save();
} else if (this.screen.attributes.pre_validate) {
prm = this.record.pre_validate();
@@ -1100,7 +1099,7 @@
this.collapse_children();
} else {
if (this.tree.n_children(this) > Sao.config.limit) {
this.tree.screen.current_record = this.record;
this.tree.record = this.record;
this.tree.screen.switch_view('form');
} else {
this.update_expander(true);
@@ -2004,7 +2003,7 @@
button_clicked: function(event) {
var record = event.data[0];
var button = event.data[1];
if (record != this.screen.current_record) {
if (record != this.record) {
// Need to raise the event to get the record selected
return true;
}