Show and Hide event with checkboxes Fullcalendar6

huangapple go评论67阅读模式
英文:

Show and Hide event with checkboxes Fullcalendar6

问题

我的事件有一个名为 "nomeUtente" 的 extendedProps,它指示保存事件的用户,而且在我的日历中有这两个复选框:Show and Hide event with checkboxes Fullcalendar6。当选中第一个复选框时,它应该仅显示与当前会话用户具有相同 "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");
                }
            }                
        })
    }
}

如您所见,现在的情况是Show and Hide event with checkboxes Fullcalendar6(与上面的截图进行比较),因为我已经选中了两个复选框,但具有不同 "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:
Show and Hide event with checkboxes Fullcalendar6
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: Show and Hide event with checkboxes Fullcalendar6 (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: &#39;Normali&#39;,
start&quot;:&#39;2023-02-14T08:00&#39;,
end: &#39;2023-02-14T17:30&#39;
extendedProps: {
nomeUtente: &#39;domizianaD&#39;,
}
}
{
title: &#39;Normali&#39;,
start&quot;:&#39;2023-02-05T08:00&#39;,
end: &#39;2023-02-05T17:30&#39;
extendedProps: {
nomeUtente: &#39;raffaellaA&#39;,
}
}
{
title: &#39;Ferie&#39;,
start&quot;:&#39;2023-02-07T08:00&#39;,
end: &#39;2023-02-07T17:30&#39;
extendedProps: {
nomeUtente: &#39;domizianaD&#39;,
}
}
{
title: &#39;Malattia&#39;,
start&quot;:&#39;2023-02-26T08:00&#39;,
end: &#39;2023-02-26T17:30&#39;
extendedProps: {
nomeUtente: &#39;tizianaV&#39;,
}
}{
title: &#39;Normali&#39;,
start&quot;:&#39;2023-02-01T08:00&#39;,
end: &#39;2023-02-01T17:30&#39;
extendedProps: {
nomeUtente: &#39;domizianaD&#39;,
}
}
{
title: &#39;Normali&#39;,
start&quot;:&#39;2023-02-04T08:00&#39;,
end: &#39;2023-02-04T17:30&#39;
extendedProps: {
nomeUtente: &#39;raffaellaA&#39;,
}
}

答案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 == &quot;Ore Personali&quot;){
if(nomeUtente != sessionUser) 
info.event.setProp(&quot;display&quot;, &quot;none&quot;); 
if(v.checked)
console.log(&quot;Checked&quot;)                 
else{ 
if(nomeUtente == sessionUser) 
info.event.setProp(&quot;display&quot;, &quot;none&quot;);                             
}
} else if(v.defaultValue == &quot;Assenze&quot;){
if(v.checked)   
info.event.setProp(&quot;display&quot;, &quot;inherit&quot;);
else {
if(nomeUtente != sessionUser ) 
info.event.setProp(&quot;display&quot;, &quot;none&quot;);
}
}                
})
}

Basically for every checkbox ("OrePersonali" and "Assenze") it controll whoever saved the event and hide it if that particulary checkbox is not checked

huangapple
  • 本文由 发表于 2023年3月3日 18:20:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75625812.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定