Add per-row edit button and paired column highlight to /lignes
Pencil icon opens the existing node edit form in the same AJAX modal as "+ Ajouter une ligne" -- no new form logic, reuses the form_alter validation/close-on-save already in place for the add form. Column highlight pairs with the existing row hover (from Gin's global table CSS) to form a crosshair. Column position is computed logically (accounting for colspan) rather than via DOM cellIndex, since the totals row's label cell spans 4 columns and would otherwise misalign every column after it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -71,6 +71,7 @@
|
||||
const ecart = montantHt !== null ? Math.round((montantHt - somme) * 100) / 100 : 0;
|
||||
rows.push({
|
||||
id: node.id,
|
||||
nid: attrs.drupal_internal__nid,
|
||||
date: attrs.field_date_ligne,
|
||||
type: attrs.field_type_ligne,
|
||||
client: clientTerm ? clientTerm.attributes.name : null,
|
||||
@@ -100,6 +101,7 @@
|
||||
filterYear: '',
|
||||
groupBy: 'month',
|
||||
onlyErrors: false,
|
||||
hoverCol: null,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -186,6 +188,58 @@
|
||||
progress: { type: 'throbber' },
|
||||
}).execute();
|
||||
},
|
||||
openEditForm(nid) {
|
||||
Drupal.ajax({
|
||||
url: '/node/' + nid + '/edit',
|
||||
dialogType: 'modal',
|
||||
dialog: { width: 800, title: 'Modifier la ligne comptable' },
|
||||
progress: { type: 'throbber' },
|
||||
}).execute();
|
||||
},
|
||||
onCellHover(evt) {
|
||||
const cell = evt.target.closest('td, th');
|
||||
if (!cell) return;
|
||||
// Logical column position, not DOM sibling index: the totals row's
|
||||
// first cell has colspan="4", which shifts every cell.cellIndex
|
||||
// after it out of alignment with the body rows.
|
||||
const index = this.logicalColIndex(cell);
|
||||
if (index === this.hoverCol) return;
|
||||
this.setColHover(index);
|
||||
},
|
||||
clearColHover() {
|
||||
this.setColHover(null);
|
||||
},
|
||||
logicalColIndex(cell) {
|
||||
let index = 0;
|
||||
let sib = cell.previousElementSibling;
|
||||
while (sib) {
|
||||
index += sib.colSpan || 1;
|
||||
sib = sib.previousElementSibling;
|
||||
}
|
||||
return index;
|
||||
},
|
||||
// Whole-column highlight (header + body + footer) to pair with the
|
||||
// row hover: plain DOM class toggling rather than a Vue-bound class
|
||||
// per cell, since the column count/order is fixed markup here, not
|
||||
// data-driven -- no need to thread an index through every <td>.
|
||||
setColHover(index) {
|
||||
const table = this.$refs.tableEl;
|
||||
if (!table) return;
|
||||
table.querySelectorAll('.figli-col-hover').forEach((el) => el.classList.remove('figli-col-hover'));
|
||||
this.hoverCol = index;
|
||||
if (index === null) return;
|
||||
table.querySelectorAll('tr').forEach((tr) => {
|
||||
let pos = 0;
|
||||
for (const cell of tr.children) {
|
||||
const span = cell.colSpan || 1;
|
||||
if (index >= pos && index < pos + span) {
|
||||
cell.classList.add('figli-col-hover');
|
||||
break;
|
||||
}
|
||||
pos += span;
|
||||
}
|
||||
});
|
||||
},
|
||||
async load() {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
|
||||
Reference in New Issue
Block a user