Files
P42_UI/app/views/projects/submissions/dialogs/SubmissionFormAccessDialog.js
T
2025-08-27 07:03:09 +00:00

128 lines
4.1 KiB
JavaScript

class SubmissionFormAccessDialog extends EICDialogContent {
actions = [
{
label: 'close',
onclick: this.cancel.bind(this),
severity: 'secondary',
role: 'cancel'
}
]
DOMContentLoaded(options) {
this.mode = options.mode ? options.mode: 'read';
for(let model in options.models) this[model] = options.models[model];
this.pic = options.pic;
this.number = options.number;
this.list = new DataGrid(this.find('.list'), {
height: '320px',
headers: [
{label:'member'},
{label:'status'},
]
});
this.refreshList();
}
refreshList() {
this.list.loading = true;
let queue = [
this.organisation.list(this.pic),
this.proposal.list(this.pic, this.number)
]
Promise.allSettled(queue)
.then((results) => {
this.fill();
});
}
fill() {
this.list.clear();
this.list.loading = false;
console.log('', this.proposal.contributors)
for(let item of this.organisation.members) {
let report = this.checkContribution(item.uid);
let row = this.list.addRow(item.uid, [
`${item.firstname} ${item.lastname}`,
report.label
])
console.log('',report)
for(let button of report.actions) {
row.querySelector('.cell:last-child').append(button.el)
}
}
}
checkContribution(uid) {
let contributor = this.proposal.contributors.find(person => person.uid == uid);
let button;
let report = {
status: '',
label: 'not contributing',
actions: []
};
if(!contributor) {
button = new Button(null, {label:'add', size:'xsmall', severity:'primary'});
button.el.dataset.uid = uid;
button.addEventListener('click', this.grant.bind(this));
report.actions.push(button);
} else {
report.status = contributor.status;
switch(contributor.status) {
case 'active':
report.label = 'contributing';
button = new Button(null, {label:'revoke', size:'xsmall', severity:'danger'});
button.el.dataset.uid = uid;
button.addEventListener('click', this.revoke.bind(this));
if(uid == app.User.identity.uuid) {
button.disabled = true;
}
report.actions.push(button);
break;
case 'pending':
report.label = 'requesting access';
button = new Button(null, {label:'reject', size:'xsmall', severity:'danger'});
button.el.dataset.uid = uid;
button.addEventListener('click', this.revoke.bind(this));
report.actions.push(button);
button = new Button(null, {label:'accept', size:'xsmall', severity:'success'});
button.el.dataset.uid = uid;
button.addEventListener('click', this.grant.bind(this));
report.actions.push(button);
break;
}
}
return report;
}
grant(event) {
event.stopPropagation();
event.preventDefault();
let button = new Button(event.currentTarget);
button.loading = true;
this.proposal.grant(this.pic, this.number, button.el.dataset.uid)
.then(async payload => { this.refreshList(); })
}
revoke(event) {
event.stopPropagation();
event.preventDefault();
let button = new Button(event.currentTarget);
button.loading = true;
this.proposal.revoke(this.pic, this.number, button.el.dataset.uid)
.then(async payload => { this.refreshList(); })
}
}
app.registerClass('SubmissionFormAccessDialog', SubmissionFormAccessDialog);