CalendarXP.net Support Forum Index CalendarXP.net Support
Most forums here are private and invisible to public.
 
 FAQFAQ   SearchSearch   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

toggle dates

 
Post new topic   Reply to topic    CalendarXP.net Support Forum Index -> FlatCalendarXP Related
View previous topic :: View next topic  
Author Message
jackb



Joined: 11 Sep 2006
Posts: 27

PostPosted: Wed Jan 31, 2007 12:53 am    Post subject: toggle dates Reply with quote

Need help with code

I have a calendar with preloaded "available/unavailable", or "booked" dates in the agenda file taken from a database

if a person is available, the available dates are loaded in the calendar as available (blue), if a person is unavailable on certain dates, these dates are loaded in the calendar as unavailable (orange), if a person is booked, the dates are loaded as (gray) and are disabled.

What I need to be able to do is toggle available/unavailable dates. The best way for me to be able to handle it on the backend would be - If a preloaded date is available(blue) toggle would turn it unavailable(orange) and add it to a hidden list field named lets say "update-unavailable", toggle it back and it would just remove the item from the list. If the date was preloaded as unavailable (orange) then just the opposite, it would add it to a hidden list field "update-available" and a toggle back would just remove it from the list.

For dates that are not preloaded in the agenda, I would need to toggle, available(blue), unavailable(orange), and back to unselected. These dates would need to be added to a hidden list field add-available and add-unavailable. The first click (blue) would add date to add-available list, second click would toggle to (orange) and remove it from add-available list and add it to add-unavailable list, and the third click "back to unselected" would remove date from add-unavailable list.

For the week header, I would need it to toggle all three (available, unavailable, and unselected) just like above, but ignore any dates that are preloaded from the agenda file.

I am using the multi-select plugin.

Also, I saw the example at http://www.calendarxp.net/forum/viewtopic.php?t=71&highlight=status using the function fAfterSelected(y,m,d,e), I would like the color change to occur right after the date is clicked on, rather than after the mouse moves off the object.


I hope this will be possible

Thank You!
Joe
Back to top
View user's profile Send private message
calendarxp
Site Admin


Joined: 30 Jan 2005
Posts: 409

PostPosted: Wed Jan 31, 2007 4:46 am    Post subject: Reply with quote

Joe,

Multi-select plugin can only handle 2 statuses - selected and unselected. In your case 3 statuses are required, but it can only be done without the multi-select (drag-drop select) capability. That's why the FAQ you mentioned won't apply to the multi-select demo. You have to choose between these 2 features.

Here is an example of how to code your requirement but without multi-select plugin:

1) go to the themes/xp directory in the product package, as we'll modify it to demo the change;

2) change the giMarkSelected option in the xp.js file from 1 to 0, which disables the default background color change for the selected date.

3) now add the following code to plugins.js: (note the last param)
Code:
function fAfterSelected(y,m,d,e) {
  var evt=fGetEvent(y,m,d);
  if (evt==null) {
    fAddEvent(y,m,d,"Available","","blue",null,null,null,null,11);
    // use your code to add y-m-d to add-available list
  } else if (evt[7]==11) {
    fAddEvent(y,m,d,"Unavailable","","orange",null,null,null,null,12);
    // use your code to add y-m-d to add-unavailable list
    // use your code to remove y-m-d from add-available list
  } else if (evt[7]==12) {
    fRemoveEvent(y,m,d);
    // use your code to remove y-m-d from add-unavailable list
  } else if (evt[0]=="Available") {
    fAddEvent(y,m,d,"Unavailable","","orange",null,null,null,null);
    // use your code to add y-m-d to update-unavailable list
    // use your code to remove y-m-d from update-available list
  } else if (evt[0]=="Unavailable") {
    fAddEvent(y,m,d,"Available","","blue",null,null,null,null);
    // use your code to add y-m-d to update-available list
    // use your code to remove y-m-d from update-unavailable list
  }

  fRepaint();
}

4) Now, everything is in place. We just need to config the agenda.js to load proper events from database - you just need to make sure the "message" param for the available and unavailable dates has to be exactly set as "Available" and "Unavailable" respectively. In other words, they must match the if-else conditions set in the above plugins.js.

5) The booked dates are the most simply ones, as they don't join the toggle - simply make sure the "action" param of such events is set to null so that it won't accept any click (disabled). Of course, you may give it a gray background color, e.g.
Code:
fAddEvent(2007,1,30,"Booked",null,"gray");

Please refer to the agenda setup tutorial if you want to know how to setup DB connection.

Finally, to access the hidden form field from within the plugins.js, you could use the predefined gContainer reference, e.g.
Code:
gContainer.forms[0].update_list.value="abcd...";

_________________
Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved.
Back to top
View user's profile Send private message
jackb



Joined: 11 Sep 2006
Posts: 27

PostPosted: Fri Feb 02, 2007 6:28 am    Post subject: Thanks! Reply with quote

Got it! Thanks so much! Once again, your calendar (and support) is AWESOME!!!!

Cheers,
Joseph
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    CalendarXP.net Support Forum Index -> FlatCalendarXP Related All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Copyright 2003- Idemfactor Solutions, Inc. All rights reserved.
Powered by phpBB © 2001, 2005 phpBB Group