英文:
Show and Hide event with checkboxes Fullcalendar6
问题
我的事件有一个名为 "nomeUtente" 的 extendedProps,它指示保存事件的用户,而且在我的日历中有这两个复选框:。当选中第一个复选框时,它应该仅显示与当前会话用户具有相同 "nomeUtente"(与事件名称旁边的 "domizianaD"、"raffaellaA" 相同)的事件。当选中第二个复选框时,它应该显示所有事件(包括具有不同 "nomeUtente" 的事件),反之亦然,当未选中它们时。
此外,事件根据类型("Normali"、"Malattia"、"Ferie")具有不同的颜色,如上面的截图所示。
我是这样做的:
eventDidMount: function(info) {
const title = info.event.title;
const nomeUtente = info.event.extendedProps.nomeUtente;
const sessionUser = $("#nomeUtente").data('value');
if (nomeUtente){
if (title == "Normali") {
info.event.setProp("backgroundColor", "#FB6B4C");
} else if (title == "Straordinarie") {
info.event.setProp("backgroundColor", "#C8FC0C");
} else if (title == "Ferie") {
info.event.setProp("backgroundColor", "#EC1C28");
} else if (title == "Malattia") {
info.event.setProp("backgroundColor", "#FFB404");;
} else if (title == "Permesso") {
info.event.setProp("backgroundColor", "#A0ACDC");
} else if (title == "Smart Working") {
info.event.setProp("backgroundColor", "#08ACC4");
} else if (title == "Trasferta") {
info.event.setProp("backgroundColor", "#00897B");
} else if (title == "Assenza non retribuita") {
info.event.setProp("backgroundColor", "#F8D2D7");
} else if (title == "Altro") {
info.event.setProp("backgroundColor", "#5E35B1");
};
cs.forEach(function(v) {
if(v.defaultValue == "Ore Personali"){
if(v.checked){
if(nomeUtente != sessionUser)
info.event.setProp("display", "none");
} else{
if(nomeUtente == sessionUser)
info.event.setProp("display", "none");
}
} else if(v.defaultValue == "Assenze"){
if(v.checked){
if(nomeUtente != sessionUser)
info.event.setProp("display", "block ruby");
}else {
if(nomeUtente != sessionUser)
info.event.setProp("display", "none");
}
}
})
}
}
如您所见,现在的情况是(与上面的截图进行比较),因为我已经选中了两个复选框,但具有不同 "nomeUtente" 的事件(与我在此会话中使用的 "domizianaD" 相同的用户)是蓝色的(fullcalendar的标准颜色),而不是如上所示的不同颜色。
可能的原因是什么?
这是如何加载我的事件(来自PHP文件):
events: [
{
title: 'Normali',
start: '2023-02-14T08:00',
end: '2023-02-14T17:30',
extendedProps: {
nomeUtente: 'domizianaD',
}
}
{
title: 'Normali',
start: '2023-02-05T08:00',
end: '2023-02-05T17:30',
extendedProps: {
nomeUtente: 'raffaellaA',
}
}
{
title: 'Ferie',
start: '2023-02-07T08:00',
end: '2023-02-07T17:30',
extendedProps: {
nomeUtente: 'domizianaD',
}
}
{
title: 'Malattia',
start: '2023-02-26T08:00',
end: '2023-02-26T17:30',
extendedProps: {
nomeUtente: 'tizianaV',
}
}{
title: 'Normali',
start: '2023-02-01T08:00',
end: '2023-02-01T17:30',
extendedProps: {
nomeUtente: 'domizianaD',
}
}
{
title: 'Normali',
start: '2023-02-04T08:00',
end: '2023-02-04T17:30',
extendedProps: {
nomeUtente: 'raffaellaA',
}
}
英文:
My events have a extendedProps, "nomeUtente" that it indicate the user that save the event and in my calendar I have these 2 checkboxes:
When the first one is checked it should show only the events with the same nomeUtente (the one next to the name event: "domizianaD", "raffaellaA") as the current session User and when the second one is checked it show all the events (even the one with different nomeUtente) and viceversa when their are not checked.
Also, events has a different color based on the type ("Normali", "Malattia", "Ferie"),as you can see in the screenshot above
I did it like this:
eventDidMount: function(info) {
const title = info.event.title;
const nomeUtente = info.event.extendedProps.nomeUtente;
const sessionUser = $("#nomeUtente").data('value');
if (nomeUtente){
if (title == "Normali") {
info.event.setProp("backgroundColor", "#FB6B4C");
} else if (title == "Straordinarie") {
info.event.setProp("backgroundColor", "#C8FC0C");
} else if (title == "Ferie") {
info.event.setProp("backgroundColor", "#EC1C28");
} else if (title == "Malattia") {
info.event.setProp("backgroundColor", "#FFB404");;
} else if (title == "Permesso") {
info.event.setProp("backgroundColor", "#A0ACDC");
} else if (title == "Smart Working") {
info.event.setProp("backgroundColor", "#08ACC4");
} else if (title == "Trasferta") {
info.event.setProp("backgroundColor", "#00897B");
} else if (title == "Assenza non retribuita") {
info.event.setProp("backgroundColor", "#F8D2D7");
} else if (title == "Altro") {
info.event.setProp("backgroundColor", "#5E35B1");
};
cs.forEach(function(v) {
if(v.defaultValue == "Ore Personali"){
if(v.checked){
if(nomeUtente != sessionUser)
info.event.setProp("display", "none");
} else{
if(nomeUtente == sessionUser)
info.event.setProp("display", "none");
}
} else if(v.defaultValue == "Assenze"){
if(v.checked){
if(nomeUtente != sessionUser)
info.event.setProp("display", "block ruby");
}else {
if(nomeUtente != sessionUser)
info.event.setProp("display", "none");
}
}
})
}
}
As you can see now: (and compare to the screenshot above) it's works because I have the two checkboxes checked but the events with a nomeUtente different from "domizianaD" (the same user i'm using in this session) are blu (standar color of fullcalendar) and not in different color as above.
What could it be?
<hr>
This is how my events are loaded (from PHP file):
events: [
{
title: 'Normali',
start":'2023-02-14T08:00',
end: '2023-02-14T17:30'
extendedProps: {
nomeUtente: 'domizianaD',
}
}
{
title: 'Normali',
start":'2023-02-05T08:00',
end: '2023-02-05T17:30'
extendedProps: {
nomeUtente: 'raffaellaA',
}
}
{
title: 'Ferie',
start":'2023-02-07T08:00',
end: '2023-02-07T17:30'
extendedProps: {
nomeUtente: 'domizianaD',
}
}
{
title: 'Malattia',
start":'2023-02-26T08:00',
end: '2023-02-26T17:30'
extendedProps: {
nomeUtente: 'tizianaV',
}
}{
title: 'Normali',
start":'2023-02-01T08:00',
end: '2023-02-01T17:30'
extendedProps: {
nomeUtente: 'domizianaD',
}
}
{
title: 'Normali',
start":'2023-02-04T08:00',
end: '2023-02-04T17:30'
extendedProps: {
nomeUtente: 'raffaellaA',
}
}
答案1
得分: 1
我要翻译的代码部分如下:
eventDidMount: function(info) {
cs.forEach(function(v) {
if(v.defaultValue == "Ore Personali"){
if(nomeUtente != sessionUser)
info.event.setProp("display", "none");
if(v.checked)
console.log("Checked")
else{
if(nomeUtente == sessionUser)
info.event.setProp("display", "none");
}
} else if(v.defaultValue == "Assenze"){
if(v.checked)
info.event.setProp("display", "inherit");
else {
if(nomeUtente != sessionUser )
info.event.setProp("display", "none");
}
}
})
}
请注意,我已将 HTML 实体字符解码,以使代码更易于阅读。
英文:
I'm gonna update how I finally find out how to do it:
eventDidMount: function(info) {
cs.forEach(function(v) {
if(v.defaultValue == "Ore Personali"){
if(nomeUtente != sessionUser)
info.event.setProp("display", "none");
if(v.checked)
console.log("Checked")
else{
if(nomeUtente == sessionUser)
info.event.setProp("display", "none");
}
} else if(v.defaultValue == "Assenze"){
if(v.checked)
info.event.setProp("display", "inherit");
else {
if(nomeUtente != sessionUser )
info.event.setProp("display", "none");
}
}
})
}
Basically for every checkbox ("OrePersonali" and "Assenze") it controll whoever saved the event and hide it if that particulary checkbox is not checked
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论