CMS Made Simple Forums
https://forum.cmsmadesimple.org/

CGCalendar events conditional link
https://forum.cmsmadesimple.org/viewtopic.php?f=28&t=77695
Page 1 of 1

Author:  jakovbak [ Thu Dec 07, 2017 8:36 am ]
Post subject:  CGCalendar events conditional link

Hello everyone!
I'm trying to modify CGCalendar just a little bit but I need some help with coding.
Among others, I have two categories: "closed" and "in_progress". If an event belongs to one of those categories, users must not be able to click on the event to see details. I need to "kill" that link. And my efforts were embarrassing...
Basically, it could be something like this:
Code:
eventClick: function(event, jsEvent, view) {
     if(  category != 'closed' or category != 'in_progress' ) {
          window.location = event.none;
     }
     else {
          window.location = event.detail_url;
     }
}

I know it's far from proper code but perhaps it could illustrate what I am trying to achieve.
Thank you in advance for any kind of help!
Best regards,
Jakovbak

Author:  velden [ Mon Dec 11, 2017 10:35 am ]
Post subject:  Re: CGCalendar events conditional link

Just saying: CGCal uses fullcalendar.io for displaying the calendar(s): https://fullcalendar.io/

It might help you in your search to a solution. I'm pretty sure it can be done but it requires good understanding of JS.

Author:  jakovbak [ Mon Dec 11, 2017 12:34 pm ]
Post subject:  Re: CGCalendar events conditional link

Hello Velden!
Great link and it looks like my problem could be solved in a couple of ways. Unfortunately, so far I have only concluded (maybe I'm wrong?) there is no implementation of certain capabilities in CGCalendar module.
For instance: 'background events' don't allow eventClick and it's exactly what I was looking for but there is no parameter in CGCalendar to describe an event as 'background event'. "Category" is the only available parameter for describing an event.
However, I have yet to explore what can be done by using GoogleCalendar but I'm not very optimistic about it. From what I have seen in fullcalendar.io Docs, administrator won't be able to take care of the calendar this way, it would be far too complicated for that person.
So, I'll dig a little deeper into this stuff and maybe I figure something out after all but I'll also ask around on some other forums.
Have a great day and best regards!
Jakovbak

Author:  velden [ Mon Dec 11, 2017 2:01 pm ]
Post subject:  Re: CGCalendar events conditional link

Indeed it seams that CGCalendar only provides a fixed set of properties to the front-end calendar (fullcalendar).

Perhaps you can (mis)use categories for your purpose.
I can think of other solutions but it would mean some customizations using UDTs etc. Probably not best practice.

Author:  jakovbak [ Tue Dec 12, 2017 7:57 am ]
Post subject:  Re: CGCalendar events conditional link

That's what I had in mind - the misuse approach - but still haven't find the way to do it. But, except the tweaking the code from the top of this topic (I thought it would be the easiest way to do it), nothing else crossed my mind.
Still waiting for suggestions from js forums...

Author:  jakovbak [ Tue Dec 12, 2017 8:29 am ]
Post subject:  Re: CGCalendar events conditional link

Meanwhile, I came across this:

https://forum.cmsmadesimple.org/viewtopic.php?f=7&t=75479&hilit=CGCalendar

I have seen eventRender callback in fullcalendar.io documentation but I have no idea how to use it within CGCalendar module. This callback is used for - imagine this - giving an event a "background" status! And events with such status don't create link for detail view in the front end!

Author:  velden [ Tue Dec 12, 2017 9:05 am ]
Post subject:  Re: CGCalendar events conditional link

Do you have an url to a page using this calendar?

Watching the calendar code it seems to me as if the category is not provided to fullcalendar.

However, a 'color' and 'textColor' property are for that category.

Untested example for a category with color #ffffff

Code:
eventClick: function(event, jsEvent, view) {
     if(  event.color != '#ffffff') {
          window.location = event.detail_url;
     }
}

Author:  jakovbak [ Tue Dec 12, 2017 9:51 am ]
Post subject:  Re: CGCalendar events conditional link

It's still in progress on my computer but similar calendar is here:

http://www.bakinidvori.studioides.com/index.php?page=availability

Go to August, there is one period marked as "occupied" and in my calendar it would be marked as "closed".
Front and back colors - chosen in event editor via category - are inserted in link style. But the category itself left no trace in front end code...

Author:  jakovbak [ Tue Dec 12, 2017 10:01 am ]
Post subject:  Re: CGCalendar events conditional link

Your untested code has been tested and it works (also in August). I have tried with both expressions turned on (yours and original template code) and, no wonder, no calendar was produced at all in the front end. Guess there's only 'else' condition we have to figure out how to insert and the problem would be solved.
By "we" I don't count much on myself... ;)

Author:  velden [ Tue Dec 12, 2017 10:22 am ]
Post subject:  Re: CGCalendar events conditional link

Yeah, but your checking for color != '#ffffff' but you've set textColor.

So change your JS:


Code:
eventClick: function(event, jsEvent, view) {
     if(  event.textColor != '#ffffff') {
          window.location = event.detail_url;
     }
}

Author:  jakovbak [ Tue Dec 12, 2017 10:33 am ]
Post subject:  [SOLVED] Re: CGCalendar events conditional link

That's it!!! It works like a charm and all I can do now is to say "Thank you Velden, once again you have saved the day!"
Best regards and have great rest of the day, week and year!
Sincerely, your biggest fan,
Jakovbak
;D ;D ;D

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/