var hideCreateDelete = FieldOne2Many.extend({
init: function (parent, name, record, options) {
this._super.apply(this, arguments);
let x = record.data['想要控制的字段'];
var arch = this.view && this.view.arch;
if (x) {
if (arch) {
this.activeActions.create = false;
this.activeActions.delete = false;
this.editable = arch.attrs.editable;
}
} else {
if (arch) {
this.activeActions.create = true;
this.activeActions.delete = true;
this.editable = arch.attrs.editable;
}
}
},
reset: function (record, ev, fieldChanged) {
let x = record.data['想要控制的字段'];
const oldCanCreate = this.canCreate;
const oldCanDelete = this.canDelete;
const oldCanLink = this.canLink;
const oldCanUnlink = this.canUnlink;
var arch = this.view && this.view.arch;
if (x) {
this.activeActions.create = false;
this.activeActions.delete = false;
this.editable = arch.attrs.editable;
} else {
this.activeActions.create = true;
this.activeActions.delete = true;
this.editable = arch.attrs.editable;
}
this._computeAvailableActions(record);
const actionsChanged =
this.canCreate !== oldCanCreate ||
this.canDelete !== oldCanDelete ||
this.canLink !== oldCanLink ||
this.canUnlink !== oldCanUnlink;
// If 'fieldChanged' is false, it means that the reset was triggered by
// the 'resetOnAnyFieldChange' mechanism. If it is the case, if neither
// the modifiers (so the visible columns) nor the available actions
// changed, the reset is skipped.
if (!fieldChanged && !actionsChanged) {
var newEval = this._evalColumnInvisibleFields();
if (_.isEqual(this.currentColInvisibleFields, newEval)) {
this._reset(record, ev); // update the internal state, but do not re-render
return Promise.resolve();
}
} else if (ev && ev.target === this && ev.data.changes && this.view.arch.tag === 'tree') {
var command = ev.data.changes[this.name];
// Here, we only consider 'UPDATE' commands with data, which occur
// with editable list view. In order to keep the current line in
// edition, we call confirmUpdate which will try to reset the widgets
// of the line being edited, and rerender the rest of the list.
// 'UPDATE' commands with no data can be ignored: they occur in
// one2manys when the record is updated from a dialog and in this
// case, we can re-render the whole subview.
if (command && command.operation === 'UPDATE' && command.data) {
var state = record.data[this.name];
var fieldNames = state.getFieldNames({viewType: 'list'});
this._reset(record, ev);
return this.renderer.confirmUpdate(state, command.id, fieldNames, ev.initialEvent);
}
}
this._reset(record, ev);
return this._super.apply(this, arguments);
},
});