Manage path for setting current_record
review18681002
This commit is contained in:
1 parent
1fc34e23db
commit
2f2bc1ae96
3 files changed
+82
-9
No files matched your search
@@ -402,6 +402,35 @@
|
||||
}
|
||||
return this.__domain4inversion[1];
|
||||
};
|
||||
array.get_by_path = function(path) {
|
||||
path = jQuery.extend([], path);
|
||||
var record = null;
|
||||
var group = this;
|
||||
|
||||
var browse_child = function() {
|
||||
if (jQuery.isEmptyObject(path)) {
|
||||
return record;
|
||||
}
|
||||
var child_name = path[0][0];
|
||||
var id = path[0][1];
|
||||
path.splice(0, 1);
|
||||
record = group.get(id);
|
||||
if (!record) {
|
||||
return null;
|
||||
}
|
||||
if (!child_name) {
|
||||
return browse_child();
|
||||
}
|
||||
return record.load(child_name).then(function() {
|
||||
group = record._values[child_name];
|
||||
if (!group) {
|
||||
return null;
|
||||
}
|
||||
return browse_child();
|
||||
});
|
||||
};
|
||||
return jQuery.when().then(browse_child);
|
||||
};
|
||||
return array;
|
||||
};
|
||||
|
||||
@@ -1080,6 +1109,21 @@
|
||||
}
|
||||
return parent;
|
||||
},
|
||||
get_path: function(group) {
|
||||
var path = [];
|
||||
var i = this;
|
||||
var child_name = '';
|
||||
while (i) {
|
||||
path.push([child_name, i.id]);
|
||||
if (i.group === group) {
|
||||
break;
|
||||
}
|
||||
child_name = i.group.child_name;
|
||||
i = i.group.parent;
|
||||
}
|
||||
path.reverse();
|
||||
return path;
|
||||
},
|
||||
deleted: function() {
|
||||
return Boolean(~this.group.record_deleted.indexOf(this));
|
||||
},
|
||||
|
||||
+23
-3
@@ -951,7 +951,7 @@
|
||||
}
|
||||
this.current_view.set_value();
|
||||
var fields = this.current_view.get_fields();
|
||||
// TODO path
|
||||
var path = this.current_record.get_path(this.group);
|
||||
var prm = jQuery.Deferred();
|
||||
if (this.current_view.view_type == 'tree') {
|
||||
prm = this.group.save();
|
||||
@@ -968,6 +968,11 @@
|
||||
}.bind(this));
|
||||
}
|
||||
var dfd = jQuery.Deferred();
|
||||
prm = prm.then(function() {
|
||||
return this.group.get_by_path(path).then(function(record) {
|
||||
this.set_current_record(record);
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
prm.then(function() {
|
||||
this.display().always(dfd.resolve);
|
||||
}.bind(this), function() {
|
||||
@@ -1015,6 +1020,10 @@
|
||||
// TODO delete children before parent
|
||||
prm = this.model.delete_(records);
|
||||
}
|
||||
var top_record = records[0];
|
||||
var top_group = top_record.group;
|
||||
var idx = top_group.indexOf(top_record);
|
||||
var path = top_record.get_path(this.group);
|
||||
return prm.then(function() {
|
||||
records.forEach(function(record) {
|
||||
record.group.remove(record, remove, true, force_remove);
|
||||
@@ -1036,8 +1045,19 @@
|
||||
// TODO destroy
|
||||
});
|
||||
}
|
||||
// TODO set current_record
|
||||
this.set_current_record(null);
|
||||
if (idx > 0) {
|
||||
var record = top_group[idx - 1];
|
||||
path.splice(-1, 1, [path[path.length - 1][0], record.id]);
|
||||
} else {
|
||||
path.splice(-1, 1);
|
||||
}
|
||||
if (!jQuery.isEmptyObject(path)) {
|
||||
prms.push(this.group.get_by_path(path).then(function(record) {
|
||||
this.set_current_record(record);
|
||||
}.bind(this)));
|
||||
} else if (self.group.length) {
|
||||
this.set_current_record(this.group[0]);
|
||||
}
|
||||
// TODO set_cursor
|
||||
return jQuery.when.apply(jQuery, prms).then(function() {
|
||||
this.display();
|
||||
|
||||
+15
-6
@@ -274,17 +274,26 @@
|
||||
var current_record = this.screen.current_record;
|
||||
if (!selected) {
|
||||
selected = this.get_selected_paths();
|
||||
if (current_record && !Sao.common.contains(selected,
|
||||
[[current_record.id]])) {
|
||||
selected = [[current_record.id]];
|
||||
if (current_record) {
|
||||
var current_path = current_record.get_path(this.screen.group);
|
||||
current_path = current_path.map(function(e) {
|
||||
return e[1];
|
||||
});
|
||||
if (!Sao.common.contains(selected, current_path)) {
|
||||
selected = [current_path];
|
||||
}
|
||||
} else if (!current_record) {
|
||||
selected = [];
|
||||
}
|
||||
}
|
||||
expanded = expanded || [];
|
||||
|
||||
if ((this.screen.group.length != this.rows.length) ||
|
||||
!Sao.common.compare(this.screen.group, this.rows.map(function(row) {
|
||||
return row.record;
|
||||
}))) {
|
||||
!Sao.common.compare(
|
||||
this.screen.group, this.rows.map(function(row) {
|
||||
return row.record;
|
||||
})) || this.children_field) { // XXX find better check
|
||||
// to keep focus
|
||||
this.construct(selected, expanded);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user