|
Author
|
Topic: Ability to change calendars from the calendar view?
|
Keith G unregistered
|
posted August 15, 2002 05:54 PM
Maybe someone has done this or something similar - Our users would like to be able to switch back and forth between calendars from the main calendar view (default.html template) rather than having to go to Admin then Change Calendars then View Calendar. What would be great would be a selectbox (drop down box) in the main calendar view that would list all of the calendars available to a particular user and would send them to that calendar on selection. Thanks for any ideas - Keith IP: Logged |
DanO Administrator
|
posted August 16, 2002 01:35 PM
I don't know about a drop down list (that would require JavaScript code as well) but if you add the following code right after <!-- COMMAND/VIEW OPTIONS --> in the default.html template file, it will provide links at the top of the left hand calendar menus to each calendar that is defined. code:
<!-- ADDED for link to each calendar --> <TABLE BORDER="0" CLASS="thinborder" WIDTH="100" BGCOLOR="<%=$COMMAND_BGCOLOR%>"> <% $cal_db = new DBFile($main::calendars_db); %> <% $calendars = $cal_db->getRecords( {} ); %> <% foreach $cal ( sort {$a->{name} cmp $b->{name}} @$calendars) { #do whatever you wanted to do with each calendar here. #you can use $calendar->{key}, $calendar->{name}, and $calendar->{description} to access their names, keys, and descriptions. %> <TR><TD BGCOLOR="<%=(($in{'calendar'} eq $cal->{key})?$_COMMAND_OPTION_SELECTED_BGCOLOR:$_COMMAND_OPTION_BGCOLOR)%>"><B><a href="<%= $CGI_URL %>?calendar=<%= $cal->{key} %>" CLASS="commandtext"><%= $cal->{name} %></A></B></TD></TR> <% } %> </TABLE> <BR> <!-- END Added -->
You can modify the code as you see fit to acheive whatever results you like. Dan O. ------------------
[This message has been edited by DanO (edited August 16, 2002).] IP: Logged |
mooredp Junior Member
|
posted August 27, 2002 11:18 AM
How do I modify the code so that the link goes to week view?Thanks! David M. ------------------
IP: Logged |
DanO Administrator
|
posted August 27, 2002 01:32 PM
quote: How do I modify the code so that the link goes to week view?
add "&view=Week" (without the quotes) to the link URL. Dan O. ------------------
IP: Logged |
spin2cool unregistered
|
posted August 28, 2002 06:01 PM
I didn't test this, but I think it'll do what you want it to, with the pull-down box:Add this at the top of the body: code:
<script language="JavaScript"> <!-- //Hide the script from browsers with JS disabled.function openWindow(url, name, width, height) { mywin = window.open(url, name, 'width=' + width + ',height=' + height + ',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0') } // --> </script>
Then add this where you want the bar:
code:
<!-- ADDED for link to each calendar --> <% $cal_db = new DBFile($main::calendars_db); %> <% $calendars = $cal_db->getRecords( {} ); %> <form method="POST" style="font-family: Arial; font-size: 8pt" name="calendar_change"> <SELECT NAME="cal_select" size="1" onChange="window.open(this.options[this.selectedIndex].value,'_top')"> <option selected>Choose a Calendar</option> <% foreach $cal ( sort {$a->{name} cmp $b->{name}} @$calendars) { %> <option value="<%= $CGI_URL %>?calendar=<%= $cal->{key} %>"</option> <% } %> </select> </form> <BR> <!-- END Added -->
Like I said, didn't test this, so there may be a syntax error or something, but it should give you the idea, anyway. IP: Logged |
spin2cool unregistered
|
posted August 30, 2002 03:06 PM
Here's a quick revision to the last post - replace the bottom section of code with this one. I tested it and it should work fine.code:
<!-- ADDED for link to each calendar --> <% $cal_db = new DBFile($main::calendars_db); %> <% $calendars = $cal_db->getRecords( {} ); %> <form method="POST" style="font-family: Arial; font-size: 8pt" name="calendar_change"> <SELECT NAME="cal_select" size="1" onChange="window.open(this.options[this.selectedIndex].value,'_top')"> <option selected>Choose a Calendar</option> <% foreach $cal ( sort {$a->{name} cmp $b->{name}} @$calendars) { %> <option value="<%= $CGI_URL %>?calendar=<%= $cal->{key} %>"><%= $cal->{name} %></option> <% } %> </select> </form> <BR> <!-- END Added -->
IP: Logged |
Keith G unregistered
|
posted October 16, 2002 04:35 PM
That piece of code works great! Displays all of the calendars in the database and is dynamic so updates after adding or deleting calendars. There has been one request though - is there a simple line of code to add to this so the drop down list would only display calendars the users have permissions to view? Sounds like it should be simple but my knowledge of Perl is very limited. Thanks in advance for any help! Keith
IP: Logged |
DanO Administrator
|
posted October 16, 2002 06:01 PM
** is there a simple line of code to add to this so the drop down list would only display calendars the users have permissions to view? **Just after the foreach statement (and corresponding curly brace "{" )add the following line: next unless ($user->hasPermission($cal->{'key'},"VIEW")); That should skip calendars the user doesn't have permissions to view. Dan O. ------------------
IP: Logged |
Keith G unregistered
|
posted October 17, 2002 11:18 AM
Hi Dan O - Thanks for the quick reply. I added the line of code into the default.html template and when I refresh the browser window it comes up blank - All it has is the background color associated with the calendar. Is there some syntax error that I got wrong or am I putting it in the wrong place? Here is where I put the line in the code: <% foreach $cal ( sort {$a->{name} cmp $b->{name}} @$calendars) { next unless ($user->hasPermission($cal->{'key'},"VIEW")); %> <option value="<%= $CGI_URL %>?calendar=<%= $cal->{key} %>"><%= $cal->{name} %></option> Thanks again for the help and any other insight you can offer - Keith
IP: Logged |
DanO Administrator
|
posted October 17, 2002 07:12 PM
** Is there some syntax error that I got wrong or am I putting it in the wrong place? **It looks correct to me. Even if it was incorrect it shouldn't effect the rest of the calendar, just the dropdown menu. Maybe look at the calendar's source code to see what the resulting HTML code is for the page. Dan O. ------------------
IP: Logged |
Keith G unregistered
|
posted October 21, 2002 11:34 AM
It's working now. Only the calendars users have permissions to view appear in the drop down list. Thanks for the help. The problem I found was the "u" in user needed to be capitalized and that got it to work. I'm using the dayspan template so I'm not sure if this is unique to it or if it needds to be capitalized in the other templates also. Thanks again for the help - KeithIP: Logged |
DanO Administrator
|
posted October 21, 2002 08:18 PM
** The problem I found was the "u" in user needed to be capitalized **That's funny, I thought I copied that directly from a template? Actually I see now some templates use "User" while others use "user". I don't know what the difference is. Glad to hear you figured it out. Dan O. ------------------
[This message has been edited by DanO (edited October 21, 2002).] IP: Logged |
DanO Administrator
|
posted December 03, 2002 06:43 PM
quote: Actually I see now some templates use "User" while others use "user". I don't know what the difference is.
It appears that $User->hasPermission is used in calendar templates and corresponding scripts where $user->hasPermission is used in administration templates and scripts. Matt should really standardize that? JMO Dan O. [This message has been edited by DanO (edited December 03, 2002).] IP: Logged |
tw1000 Member
|
posted February 04, 2003 10:16 PM
I have installed this to my default.html file and it is working perfectly. My question is if there is a way to sort the drop down list alphabeticly? ------------------
IP: Logged |
DanO Administrator
|
posted February 05, 2003 01:46 PM
** is there is a way to sort the drop down list alphabeticly? **That's what the following line is suppose to do, sort the list by calendar name: <% foreach $cal ( sort {$a->{name} cmp $b->{name}} @$calendars) If you want to sort it by calendar key replacing the above with the following should do it:
<% foreach $cal ( sort {$a->{key} cmp $b->{key}} @$calendars) Dan O. BTW. There is a difference between upper case letters and lower case, lower will display first.
------------------
IP: Logged |
tw1000 Member
|
posted February 06, 2003 06:27 PM
Thanks, it was the upper / lower case issue I did not understand------------------
IP: Logged |
Bartman Junior Member
|
posted November 06, 2003 12:44 PM
Thanks everyone. This is exactly what I was looking for.------------------
IP: Logged |
k9barry Member
|
posted November 25, 2003 12:30 AM
Using DanO's code to add the calendars to the default.html as below:-------------------------------------------------------------------------------- <!-- ADDED for link to each calendar --> <TABLE BORDER="0" CLASS="thinborder" WIDTH="100" BGCOLOR="<%=$COMMAND_BGCOLOR%>"> <% $cal_db = new DBFile($main::calendars_db); %> <% $calendars = $cal_db->getRecords( {} ); %> <% foreach $cal ( sort {$a->{name} cmp $b->{name}} @$calendars) { #do whatever you wanted to do with each calendar here. #you can use $calendar->{key}, $calendar->{name}, and $calendar->{description} to access their names, keys, and descriptions. %> <TR><TD BGCOLOR="<%=(($in{'calendar'} eq $cal->{key})?$_COMMAND_OPTION_SELECTED_BGCOLOR:$_COMMAND_OPTION_BGCOLOR)%>"><B><a href="<%= $CGI_URL %>?calendar=<%= $cal->{key} %>" CLASS="commandtext"><%= $cal->{name} %></A></B></TD></TR> <% } %> </TABLE> <BR><!-- END Added --> -------------------------------------------------------------------------------- How do I limit the calendars to only show the calendars the user had view "VIEW" permissions? ------------------
IP: Logged |
DanO Administrator
|
posted November 25, 2003 12:21 PM
** How do I limit the calendars to only show the calendars the user had view "VIEW" permissions? **To modify the code I supplied, after the line: #do whatever you wanted to do with each calendar here. ADD next unless ($User->hasPermission($cal->{'key'},"VIEW")); --- To complete the code in the previous messages by Keith G:
* The problem I found was the "u" in user needed to be capitalized and that got it to work. * CORRECTED CODE <% foreach $cal ( sort {$a->{name} cmp $b->{name}} @$calendars) { next unless ($User->hasPermission($cal->{'key'},"VIEW")); %> <option value="<%= $CGI_URL %>?calendar=<%= $cal->{key} %>"><%= $cal->{name} %></option> Dan O.
[This message has been edited by DanO (edited November 25, 2003).] IP: Logged |
wderzawiec Junior Member
|
posted June 03, 2006 08:42 PM
Just found this code for drop-down menu and it was very very helpful. Thanks to all.------------------
IP: Logged |