746 lines
32 KiB
JavaScript
746 lines
32 KiB
JavaScript
import {Controller} from '@hotwired/stimulus';
|
|
import Choices from 'choices.js';
|
|
import {TabulatorFull as Tabulator} from 'tabulator-tables';
|
|
|
|
export default class extends Controller {
|
|
static values = {
|
|
rolesArray: Array,
|
|
selectedRoleIds: Array,
|
|
id: Number,
|
|
aws: String,
|
|
list: Boolean,
|
|
listOrganization: Boolean,
|
|
new: Boolean,
|
|
admin: Boolean,
|
|
listSmall: Boolean,
|
|
statut: Boolean,
|
|
orgId: Number
|
|
}
|
|
|
|
static targets = ["select"];
|
|
|
|
connect() {
|
|
this.roleSelect();
|
|
if(this.listValue){
|
|
this.table();
|
|
}
|
|
if(this.newValue){
|
|
this.tableSmall();
|
|
}
|
|
if(this.adminValue){
|
|
this.tableSmallAdmin();
|
|
}
|
|
if (this.listOrganizationValue) {
|
|
this.tableOrganization()
|
|
}
|
|
|
|
}
|
|
|
|
roleSelect() {
|
|
if (this.hasSelectTarget) {
|
|
const choicesData = this.rolesArrayValue.map(role => ({
|
|
value: role.id,
|
|
label: role.name,
|
|
selected: this.selectedRoleIdsValue.includes(role.id)
|
|
}));
|
|
|
|
new Choices(this.selectTarget, {
|
|
choices: choicesData,
|
|
removeItemButton: true,
|
|
placeholder: true,
|
|
placeholderValue: 'Ajouter un ou plusieurs rôles',
|
|
});
|
|
}
|
|
}
|
|
|
|
table() {
|
|
const columns = [
|
|
{
|
|
title: "",
|
|
field: "isConnected",
|
|
width: 40, // small column
|
|
hozAlign: "center",
|
|
vertAlign: "middle",
|
|
headerSort: false,
|
|
tooltip: false,
|
|
formatter: (cell) => {
|
|
const online = !!cell.getValue();
|
|
const color = online ? "#80F20E" : "#E42E31"; // green/red
|
|
return `<span class="status-dot" style="
|
|
display:inline-block;
|
|
width:10px;height:10px;
|
|
border-radius:50%;
|
|
background:${color};
|
|
"></span>`;
|
|
},
|
|
// Optional: for accessibility
|
|
formatterPrint: (cell) => (cell.getValue() ? "online" : "offline"),
|
|
formatterClipboard: (cell) => (cell.getValue() ? "online" : "offline"),
|
|
},
|
|
{
|
|
title: "Profil",
|
|
field: "pictureUrl",
|
|
width: 80,
|
|
hozAlign: "center",
|
|
headerSort: false,
|
|
formatter: (cell) => {
|
|
const data = cell.getRow().getData();
|
|
const url = cell.getValue();
|
|
const first = (s) => (typeof s === "string" && s.length ? s.trim()[0].toUpperCase() : "");
|
|
const initials = `${first(data.name)}${first(data.prenom)}`;
|
|
|
|
const wrapper = document.createElement("div");
|
|
wrapper.className = "avatar-wrapper";
|
|
// same size for both cases
|
|
wrapper.style.width = "40px";
|
|
wrapper.style.height = "40px";
|
|
wrapper.style.display = "flex";
|
|
wrapper.style.alignItems = "center";
|
|
wrapper.style.justifyContent = "center";
|
|
wrapper.style.borderRadius = "50%";
|
|
wrapper.style.overflow = "hidden"; // ensure image clips to circle
|
|
|
|
if (!url) {
|
|
wrapper.style.background = "#6c757d"; // gray background
|
|
const span = document.createElement("span");
|
|
span.className = "avatar-initials";
|
|
span.style.color = "#fff";
|
|
span.style.fontWeight = "600";
|
|
span.style.fontSize = "14px";
|
|
span.textContent = initials || "•";
|
|
wrapper.appendChild(span);
|
|
return wrapper;
|
|
}
|
|
|
|
// Image case: make it fill the same wrapper
|
|
const img = document.createElement("img");
|
|
img.src = `${this.awsValue || ""}${url}`;
|
|
img.alt = initials || "avatar";
|
|
img.style.width = "100%";
|
|
img.style.height = "100%";
|
|
img.style.objectFit = "cover"; // keep aspect and cover circle
|
|
wrapper.appendChild(img);
|
|
|
|
// Optional: fallback if image fails
|
|
img.addEventListener("error", () => {
|
|
wrapper.innerHTML = "";
|
|
wrapper.style.background = "#6c757d";
|
|
const span = document.createElement("span");
|
|
span.className = "avatar-initials";
|
|
span.style.color = "#fff";
|
|
span.style.fontWeight = "600";
|
|
span.style.fontSize = "12px";
|
|
span.textContent = initials || "•";
|
|
wrapper.appendChild(span);
|
|
});
|
|
|
|
return wrapper;
|
|
},
|
|
},
|
|
{title: "<b>Nom</b>", field: "name", headerFilter: "input", widthGrow: 2, vertAlign: "middle"},
|
|
{title: "<b>Prénom</b>", field: "prenom", headerFilter: "input", widthGrow: 2, vertAlign: "middle"},
|
|
{title: "<b>Email</b>", field: "email", headerFilter: "input", widthGrow: 3, vertAlign: "middle"},
|
|
{
|
|
title: "<b>Actions</b>",
|
|
field: "showUrl",
|
|
hozAlign: "center",
|
|
width: 100,
|
|
vertAlign: "middle",
|
|
headerSort: false,
|
|
formatter: (cell) => {
|
|
const url = cell.getValue();
|
|
if (url) {
|
|
return `
|
|
<a href="${url}" class="p-3 align-middle color-primary" title="Voir">
|
|
<svg xmlns="http://www.w3.org/2000/svg"
|
|
width="35px"
|
|
height="35px"
|
|
viewBox="0 0 576 512">
|
|
<path fill="currentColor"
|
|
d="M288 80c-65.2 0-118.8 29.6-159.9 67.7C89.6 183.5 63 226 49.4 256C63 286 89.6 328.5 128 364.3c41.2 38.1 94.8 67.7 160 67.7s118.8-29.6 159.9-67.7C486.4 328.5 513 286 526.6 256c-13.6-30-40.2-72.5-78.6-108.3C406.8 109.6 353.2 80 288 80M95.4 112.6C142.5 68.8 207.2 32 288 32s145.5 36.8 192.6 80.6c46.8 43.5 78.1 95.4 93 131.1c3.3 7.9 3.3 16.7 0 24.6c-14.9 35.7-46.2 87.7-93 131.1C433.5 443.2 368.8 480 288 480s-145.5-36.8-192.6-80.6C48.6 356 17.3 304 2.5 268.3c-3.3-7.9-3.3-16.7 0-24.6C17.3 208 48.6 156 95.4 112.6M288 336c44.2 0 80-35.8 80-80s-35.8-80-80-80h-2c1.3 5.1 2 10.5 2 16c0 35.3-28.7 64-64 64c-5.5 0-10.9-.7-16-2v2c0 44.2 35.8 80 80 80m0-208a128 128 0 1 1 0 256a128 128 0 1 1 0-256"/></svg>
|
|
</a>
|
|
`;
|
|
}
|
|
return '';
|
|
}
|
|
}];
|
|
const tabulator = new Tabulator("#tabulator-userList", {
|
|
langs: {
|
|
fr: {
|
|
ajax: {
|
|
loading: "Chargement...",
|
|
error: "Erreur",
|
|
},
|
|
pagination: {
|
|
page_size: "Taille de page",
|
|
page_title: "Afficher la page",
|
|
first: "Premier",
|
|
first_title: "Première page",
|
|
last: "Dernier",
|
|
last_title: "Dernière page",
|
|
prev: "Précédent",
|
|
prev_title: "Page précédente",
|
|
next: "Suivant",
|
|
next_title: "Page suivante",
|
|
all: "Tout",
|
|
counter: {
|
|
showing: "Affiche",
|
|
of: "de",
|
|
rows: "lignes",
|
|
pages: "pages",
|
|
},
|
|
},
|
|
headerFilters: {
|
|
default: "Filtrer la colonne...",
|
|
columns: {},
|
|
},
|
|
data: {
|
|
loading: "Chargement des données...",
|
|
error: "Erreur de chargement des données",
|
|
},
|
|
groups: {item: "élément", items: "éléments"},
|
|
}
|
|
|
|
},
|
|
locale: "fr", //'en' for English, 'fr' for French (en is default, no need to include it)
|
|
ajaxURL: "/user/data",
|
|
ajaxConfig: "GET",
|
|
pagination: true,
|
|
paginationMode: "remote",
|
|
paginationSize: 25,
|
|
|
|
ajaxResponse: (url, params, response) => response,
|
|
paginationDataSent: {page: "page", size: "size"},
|
|
paginationDataReceived: {last_page: "last_page"},
|
|
|
|
ajaxSorting: true,
|
|
ajaxFiltering: true,
|
|
rowHeight: 60,
|
|
layout: "fitColumns", // activate French
|
|
|
|
columns
|
|
});
|
|
};
|
|
|
|
|
|
onSelectChange(row, newValue) {
|
|
const data = row.getData();
|
|
console.log("Change select" + data);
|
|
|
|
};
|
|
|
|
|
|
tableSmall() {
|
|
const columns = [
|
|
{
|
|
title: "Profil",
|
|
field: "pictureUrl",
|
|
width: 80,
|
|
hozAlign: "center",
|
|
headerSort: false,
|
|
formatter: (cell) => {
|
|
const data = cell.getRow().getData();
|
|
const url = cell.getValue();
|
|
const first = (s) => (typeof s === "string" && s.length ? s.trim()[0].toUpperCase() : "");
|
|
const initials = `${data.initials}`;
|
|
|
|
const wrapper = document.createElement("div");
|
|
wrapper.className = "avatar-wrapper";
|
|
// same size for both cases
|
|
wrapper.style.width = "40px";
|
|
wrapper.style.height = "40px";
|
|
wrapper.style.display = "flex";
|
|
wrapper.style.alignItems = "center";
|
|
wrapper.style.justifyContent = "center";
|
|
wrapper.style.borderRadius = "50%";
|
|
wrapper.style.overflow = "hidden"; // ensure image clips to circle
|
|
|
|
if (!url) {
|
|
wrapper.style.background = "#6c757d"; // gray background
|
|
const span = document.createElement("span");
|
|
span.className = "avatar-initials";
|
|
span.style.color = "#fff";
|
|
span.style.fontWeight = "600";
|
|
span.style.fontSize = "14px";
|
|
span.textContent = initials || "•";
|
|
wrapper.appendChild(span);
|
|
return wrapper;
|
|
}
|
|
|
|
// Image case: make it fill the same wrapper
|
|
const img = document.createElement("img");
|
|
img.src = `${this.awsValue || ""}${url}`;
|
|
img.alt = initials || "avatar";
|
|
img.style.width = "100%";
|
|
img.style.height = "100%";
|
|
img.style.objectFit = "cover"; // keep aspect and cover circle
|
|
wrapper.appendChild(img);
|
|
|
|
// Optional: fallback if image fails
|
|
img.addEventListener("error", () => {
|
|
wrapper.innerHTML = "";
|
|
wrapper.style.background = "#6c757d";
|
|
const span = document.createElement("span");
|
|
span.className = "avatar-initials";
|
|
span.style.color = "#fff";
|
|
span.style.fontWeight = "600";
|
|
span.style.fontSize = "12px";
|
|
span.textContent = initials || "•";
|
|
wrapper.appendChild(span);
|
|
});
|
|
|
|
return wrapper;
|
|
},
|
|
},
|
|
{title: "<b>Email</b>", field: "email", widthGrow: 3, vertAlign: "middle"},
|
|
{
|
|
title: "<b>Actions</b>",
|
|
field: "showUrl",
|
|
hozAlign: "center",
|
|
width: 100,
|
|
vertAlign: "middle",
|
|
headerSort: false,
|
|
formatter: (cell) => {
|
|
const url = cell.getValue();
|
|
if (url) {
|
|
return `
|
|
<a href="${url}" class="p-3 align-middle color-primary" title="Voir">
|
|
<svg xmlns="http://www.w3.org/2000/svg"
|
|
width="35px"
|
|
height="35px"
|
|
viewBox="0 0 576 512">
|
|
<path fill="currentColor"
|
|
d="M288 80c-65.2 0-118.8 29.6-159.9 67.7C89.6 183.5 63 226 49.4 256C63 286 89.6 328.5 128 364.3c41.2 38.1 94.8 67.7 160 67.7s118.8-29.6 159.9-67.7C486.4 328.5 513 286 526.6 256c-13.6-30-40.2-72.5-78.6-108.3C406.8 109.6 353.2 80 288 80M95.4 112.6C142.5 68.8 207.2 32 288 32s145.5 36.8 192.6 80.6c46.8 43.5 78.1 95.4 93 131.1c3.3 7.9 3.3 16.7 0 24.6c-14.9 35.7-46.2 87.7-93 131.1C433.5 443.2 368.8 480 288 480s-145.5-36.8-192.6-80.6C48.6 356 17.3 304 2.5 268.3c-3.3-7.9-3.3-16.7 0-24.6C17.3 208 48.6 156 95.4 112.6M288 336c44.2 0 80-35.8 80-80s-35.8-80-80-80h-2c1.3 5.1 2 10.5 2 16c0 35.3-28.7 64-64 64c-5.5 0-10.9-.7-16-2v2c0 44.2 35.8 80 80 80m0-208a128 128 0 1 1 0 256a128 128 0 1 1 0-256"/></svg>
|
|
</a>
|
|
`;
|
|
}
|
|
return '';
|
|
}
|
|
}
|
|
];
|
|
|
|
|
|
const tabulator = new Tabulator("#tabulator-userListSmall", {
|
|
|
|
locale: "fr", //'en' for English, 'fr' for French (en is default, no need to include it)
|
|
ajaxURL: "/user/data/new",
|
|
|
|
ajaxConfig: "GET",
|
|
pagination: false,
|
|
paginationMode: "remote",
|
|
// paginationSize: 5,
|
|
ajaxParams: { orgId: this.orgIdValue },
|
|
langs: {
|
|
fr: {
|
|
ajax: {
|
|
loading: "Chargement...",
|
|
error: "Erreur",
|
|
},
|
|
pagination: {
|
|
page_size: "Taille de page",
|
|
page_title: "Afficher la page",
|
|
first: "Premier",
|
|
first_title: "Première page",
|
|
last: "Dernier",
|
|
last_title: "Dernière page",
|
|
prev: "Précédent",
|
|
prev_title: "Page précédente",
|
|
next: "Suivant",
|
|
next_title: "Page suivante",
|
|
all: "Tout",
|
|
counter: {
|
|
showing: "Affiche",
|
|
of: "de",
|
|
rows: "lignes",
|
|
pages: "pages",
|
|
},
|
|
},
|
|
headerFilters: {
|
|
default: "Filtrer la colonne...",
|
|
columns: {},
|
|
},
|
|
data: {
|
|
loading: "Chargement des données...",
|
|
error: "Erreur de chargement des données",
|
|
},
|
|
groups: {item: "élément", items: "éléments"},
|
|
}
|
|
|
|
},
|
|
ajaxResponse: (url, params, response) => response.data,
|
|
// paginationDataSent: {page: "page", size: "size"},
|
|
// paginationDataReceived: {last_page: "last_page"},
|
|
|
|
// ajaxSorting: true,
|
|
// ajaxFiltering: true,
|
|
rowHeight: 60,
|
|
layout: "fitColumns", // activate French
|
|
|
|
columns
|
|
});
|
|
}
|
|
tableSmallAdmin() {
|
|
const columns = [
|
|
{
|
|
title: "Profil",
|
|
field: "pictureUrl",
|
|
width: 80,
|
|
hozAlign: "center",
|
|
headerSort: false,
|
|
formatter: (cell) => {
|
|
const data = cell.getRow().getData();
|
|
const url = cell.getValue();
|
|
const first = (s) => (typeof s === "string" && s.length ? s.trim()[0].toUpperCase() : "");
|
|
const initials = `${data.initials}`;
|
|
|
|
const wrapper = document.createElement("div");
|
|
wrapper.className = "avatar-wrapper";
|
|
// same size for both cases
|
|
wrapper.style.width = "40px";
|
|
wrapper.style.height = "40px";
|
|
wrapper.style.display = "flex";
|
|
wrapper.style.alignItems = "center";
|
|
wrapper.style.justifyContent = "center";
|
|
wrapper.style.borderRadius = "50%";
|
|
wrapper.style.overflow = "hidden"; // ensure image clips to circle
|
|
|
|
if (!url) {
|
|
wrapper.style.background = "#6c757d"; // gray background
|
|
const span = document.createElement("span");
|
|
span.className = "avatar-initials";
|
|
span.style.color = "#fff";
|
|
span.style.fontWeight = "600";
|
|
span.style.fontSize = "14px";
|
|
span.textContent = initials || "•";
|
|
wrapper.appendChild(span);
|
|
return wrapper;
|
|
}
|
|
|
|
// Image case: make it fill the same wrapper
|
|
const img = document.createElement("img");
|
|
img.src = `${this.awsValue || ""}${url}`;
|
|
img.alt = initials || "avatar";
|
|
img.style.width = "100%";
|
|
img.style.height = "100%";
|
|
img.style.objectFit = "cover"; // keep aspect and cover circle
|
|
wrapper.appendChild(img);
|
|
|
|
// Optional: fallback if image fails
|
|
img.addEventListener("error", () => {
|
|
wrapper.innerHTML = "";
|
|
wrapper.style.background = "#6c757d";
|
|
const span = document.createElement("span");
|
|
span.className = "avatar-initials";
|
|
span.style.color = "#fff";
|
|
span.style.fontWeight = "600";
|
|
span.style.fontSize = "12px";
|
|
span.textContent = initials || "•";
|
|
wrapper.appendChild(span);
|
|
});
|
|
|
|
return wrapper;
|
|
},
|
|
},
|
|
{title: "<b>Email</b>", field: "email", widthGrow: 3, vertAlign: "middle"},
|
|
{
|
|
title: "<b>Actions</b>",
|
|
field: "showUrl",
|
|
hozAlign: "center",
|
|
width: 100,
|
|
vertAlign: "middle",
|
|
headerSort: false,
|
|
formatter: (cell) => {
|
|
const url = cell.getValue();
|
|
if (url) {
|
|
return `
|
|
<a href="${url}" class="p-3 align-middle color-primary" title="Voir">
|
|
<svg xmlns="http://www.w3.org/2000/svg"
|
|
width="35px"
|
|
height="35px"
|
|
viewBox="0 0 576 512">
|
|
<path fill="currentColor"
|
|
d="M288 80c-65.2 0-118.8 29.6-159.9 67.7C89.6 183.5 63 226 49.4 256C63 286 89.6 328.5 128 364.3c41.2 38.1 94.8 67.7 160 67.7s118.8-29.6 159.9-67.7C486.4 328.5 513 286 526.6 256c-13.6-30-40.2-72.5-78.6-108.3C406.8 109.6 353.2 80 288 80M95.4 112.6C142.5 68.8 207.2 32 288 32s145.5 36.8 192.6 80.6c46.8 43.5 78.1 95.4 93 131.1c3.3 7.9 3.3 16.7 0 24.6c-14.9 35.7-46.2 87.7-93 131.1C433.5 443.2 368.8 480 288 480s-145.5-36.8-192.6-80.6C48.6 356 17.3 304 2.5 268.3c-3.3-7.9-3.3-16.7 0-24.6C17.3 208 48.6 156 95.4 112.6M288 336c44.2 0 80-35.8 80-80s-35.8-80-80-80h-2c1.3 5.1 2 10.5 2 16c0 35.3-28.7 64-64 64c-5.5 0-10.9-.7-16-2v2c0 44.2 35.8 80 80 80m0-208a128 128 0 1 1 0 256a128 128 0 1 1 0-256"/></svg>
|
|
</a>
|
|
`;
|
|
}
|
|
return '';
|
|
}
|
|
}
|
|
];
|
|
|
|
|
|
|
|
|
|
const tabulator = new Tabulator("#tabulator-userListSmallAdmin", {
|
|
|
|
locale: "fr", //'en' for English, 'fr' for French (en is default, no need to include it)
|
|
ajaxURL: "/user/data/admin",
|
|
|
|
ajaxConfig: "GET",
|
|
pagination: false,
|
|
paginationMode: "remote",
|
|
// paginationSize: 5,
|
|
ajaxParams: { orgId: this.orgIdValue },
|
|
langs: {
|
|
fr: {
|
|
ajax: {
|
|
loading: "Chargement...",
|
|
error: "Erreur",
|
|
},
|
|
pagination: {
|
|
page_size: "Taille de page",
|
|
page_title: "Afficher la page",
|
|
first: "Premier",
|
|
first_title: "Première page",
|
|
last: "Dernier",
|
|
last_title: "Dernière page",
|
|
prev: "Précédent",
|
|
prev_title: "Page précédente",
|
|
next: "Suivant",
|
|
next_title: "Page suivante",
|
|
all: "Tout",
|
|
counter: {
|
|
showing: "Affiche",
|
|
of: "de",
|
|
rows: "lignes",
|
|
pages: "pages",
|
|
},
|
|
},
|
|
headerFilters: {
|
|
default: "Filtrer la colonne...",
|
|
columns: {},
|
|
},
|
|
data: {
|
|
loading: "Chargement des données...",
|
|
error: "Erreur de chargement des données",
|
|
},
|
|
groups: {item: "élément", items: "éléments"},
|
|
}
|
|
|
|
},
|
|
ajaxResponse: (url, params, response) => response.data,
|
|
// paginationDataSent: {page: "page", size: "size"},
|
|
// paginationDataReceived: {last_page: "last_page"},
|
|
|
|
// ajaxSorting: true,
|
|
// ajaxFiltering: true,
|
|
rowHeight: 60,
|
|
layout: "fitColumns", // activate French
|
|
|
|
columns
|
|
});
|
|
}
|
|
|
|
tableOrganization() {
|
|
|
|
const columns = [
|
|
{
|
|
title: "",
|
|
field: "isConnected",
|
|
width: 40, // small column
|
|
hozAlign: "center",
|
|
vertAlign: "middle",
|
|
headerSort: false,
|
|
tooltip: false,
|
|
formatter: (cell) => {
|
|
const online = !!cell.getValue();
|
|
const color = online ? "#80F20E" : "#E42E31"; // green/red
|
|
return `<span class="status-dot" style="
|
|
display:inline-block;
|
|
width:10px;height:10px;
|
|
border-radius:50%;
|
|
background:${color};
|
|
"></span>`;
|
|
},
|
|
// Optional: for accessibility
|
|
formatterPrint: (cell) => (cell.getValue() ? "online" : "offline"),
|
|
formatterClipboard: (cell) => (cell.getValue() ? "online" : "offline"),
|
|
},
|
|
{
|
|
title: "Profil",
|
|
field: "pictureUrl",
|
|
width: 80,
|
|
hozAlign: "center",
|
|
headerSort: false,
|
|
formatter: (cell) => {
|
|
const data = cell.getRow().getData();
|
|
const url = cell.getValue();
|
|
const first = (s) => (typeof s === "string" && s.length ? s.trim()[0].toUpperCase() : "");
|
|
const initials = `${first(data.name)}${first(data.prenom)}`;
|
|
|
|
const wrapper = document.createElement("div");
|
|
wrapper.className = "avatar-wrapper";
|
|
// same size for both cases
|
|
wrapper.style.width = "40px";
|
|
wrapper.style.height = "40px";
|
|
wrapper.style.display = "flex";
|
|
wrapper.style.alignItems = "center";
|
|
wrapper.style.justifyContent = "center";
|
|
wrapper.style.borderRadius = "50%";
|
|
wrapper.style.overflow = "hidden"; // ensure image clips to circle
|
|
|
|
if (!url) {
|
|
wrapper.style.background = "#6c757d"; // gray background
|
|
const span = document.createElement("span");
|
|
span.className = "avatar-initials";
|
|
span.style.color = "#fff";
|
|
span.style.fontWeight = "600";
|
|
span.style.fontSize = "14px";
|
|
span.textContent = initials || "•";
|
|
wrapper.appendChild(span);
|
|
return wrapper;
|
|
}
|
|
|
|
// Image case: make it fill the same wrapper
|
|
const img = document.createElement("img");
|
|
img.src = `${this.awsValue || ""}${url}`;
|
|
img.alt = initials || "avatar";
|
|
img.style.width = "100%";
|
|
img.style.height = "100%";
|
|
img.style.objectFit = "cover"; // keep aspect and cover circle
|
|
wrapper.appendChild(img);
|
|
|
|
// Optional: fallback if image fails
|
|
img.addEventListener("error", () => {
|
|
wrapper.innerHTML = "";
|
|
wrapper.style.background = "#6c757d";
|
|
const span = document.createElement("span");
|
|
span.className = "avatar-initials";
|
|
span.style.color = "#fff";
|
|
span.style.fontWeight = "600";
|
|
span.style.fontSize = "12px";
|
|
span.textContent = initials || "•";
|
|
wrapper.appendChild(span);
|
|
});
|
|
|
|
return wrapper;
|
|
},
|
|
},
|
|
{title: "<b>Nom</b>", field: "name", headerFilter: "input", widthGrow: 2, vertAlign: "middle"},
|
|
{title: "<b>Prénom</b>", field: "prenom", headerFilter: "input", widthGrow: 2, vertAlign: "middle"},
|
|
{title: "<b>Email</b>", field: "email", headerFilter: "input", widthGrow: 3, vertAlign: "middle"},
|
|
{
|
|
title: "<b>Actions</b>",
|
|
field: "showUrl",
|
|
hozAlign: "center",
|
|
width: 100,
|
|
vertAlign: "middle",
|
|
headerSort: false,
|
|
formatter: (cell) => {
|
|
const url = cell.getValue();
|
|
if (url) {
|
|
return `
|
|
<a href="${url}" class="p-3 align-middle color-primary" title="Voir">
|
|
<svg xmlns="http://www.w3.org/2000/svg"
|
|
width="35px"
|
|
height="35px"
|
|
viewBox="0 0 576 512">
|
|
<path fill="currentColor"
|
|
d="M288 80c-65.2 0-118.8 29.6-159.9 67.7C89.6 183.5 63 226 49.4 256C63 286 89.6 328.5 128 364.3c41.2 38.1 94.8 67.7 160 67.7s118.8-29.6 159.9-67.7C486.4 328.5 513 286 526.6 256c-13.6-30-40.2-72.5-78.6-108.3C406.8 109.6 353.2 80 288 80M95.4 112.6C142.5 68.8 207.2 32 288 32s145.5 36.8 192.6 80.6c46.8 43.5 78.1 95.4 93 131.1c3.3 7.9 3.3 16.7 0 24.6c-14.9 35.7-46.2 87.7-93 131.1C433.5 443.2 368.8 480 288 480s-145.5-36.8-192.6-80.6C48.6 356 17.3 304 2.5 268.3c-3.3-7.9-3.3-16.7 0-24.6C17.3 208 48.6 156 95.4 112.6M288 336c44.2 0 80-35.8 80-80s-35.8-80-80-80h-2c1.3 5.1 2 10.5 2 16c0 35.3-28.7 64-64 64c-5.5 0-10.9-.7-16-2v2c0 44.2 35.8 80 80 80m0-208a128 128 0 1 1 0 256a128 128 0 1 1 0-256"/></svg>
|
|
</a>
|
|
`;
|
|
}
|
|
return '';
|
|
}
|
|
}];
|
|
// if (this.statutValue) {
|
|
// columns.push(
|
|
// {
|
|
// title: "Statut", field: "role", // or any field you want
|
|
// headerSort: false,
|
|
// hozAlign: "center",
|
|
// vertAlign: "middle",
|
|
// formatter: (cell) => {
|
|
// const row = cell.getRow();
|
|
// const current = cell.getValue() ?? "";
|
|
//
|
|
// const select = document.createElement("select");
|
|
// select.className = "table-select-action";
|
|
// // Options
|
|
// [
|
|
// {value: "", label: "Choisir..."},
|
|
// {value: "viewer", label: "Viewer"},
|
|
// {value: "editor", label: "Editor"},
|
|
// {value: "admin", label: "Admin"},
|
|
// ].forEach(opt => {
|
|
// const o = document.createElement("option");
|
|
// o.value = opt.value;
|
|
// o.textContent = opt.label;
|
|
// if (opt.value === current) o.selected = true;
|
|
// select.appendChild(o);
|
|
// });
|
|
//
|
|
// // Hook change
|
|
// select.addEventListener("change", (e) => {
|
|
// this.onSelectChange(row, e.target.value);
|
|
// });
|
|
//
|
|
// // Return a DOM node from a formatter → Tabulator will mount it
|
|
// return select;
|
|
// },
|
|
// // Optional: provide text for clipboard/print
|
|
// formatterClipboard: cell => cell.getValue(),
|
|
// formatterPrint: cell => cell.getValue(),
|
|
// },
|
|
// )
|
|
// }
|
|
const tabulator = new Tabulator("#tabulator-userListOrganization", {
|
|
langs: {
|
|
fr: {
|
|
ajax: {
|
|
loading: "Chargement...",
|
|
error: "Erreur",
|
|
},
|
|
pagination: {
|
|
page_size: "Taille de page",
|
|
page_title: "Afficher la page",
|
|
first: "Premier",
|
|
first_title: "Première page",
|
|
last: "Dernier",
|
|
last_title: "Dernière page",
|
|
prev: "Précédent",
|
|
prev_title: "Page précédente",
|
|
next: "Suivant",
|
|
next_title: "Page suivante",
|
|
all: "Tout",
|
|
counter: {
|
|
showing: "Affiche",
|
|
of: "de",
|
|
rows: "lignes",
|
|
pages: "pages",
|
|
},
|
|
},
|
|
headerFilters: {
|
|
default: "Filtrer la colonne...",
|
|
columns: {},
|
|
},
|
|
data: {
|
|
loading: "Chargement des données...",
|
|
error: "Erreur de chargement des données",
|
|
},
|
|
groups: {item: "élément", items: "éléments"},
|
|
}
|
|
|
|
},
|
|
locale: "fr",
|
|
ajaxURL: "/user/data/organization",
|
|
ajaxConfig: "GET",
|
|
ajaxParams: { orgId: this.orgIdValue },
|
|
|
|
pagination: true,
|
|
paginationMode: "remote",
|
|
paginationSize: 10,
|
|
|
|
ajaxResponse: (url, params, response) => response,
|
|
paginationDataSent: { page: "page", size: "size" },
|
|
paginationDataReceived: { last_page: "last_page" },
|
|
|
|
ajaxSorting: true,
|
|
ajaxFiltering: true,
|
|
rowHeight: 60,
|
|
layout: "fitColumns", // activate French
|
|
|
|
columns
|
|
});
|
|
};
|
|
} |