Welcome, Guest. Please login or register.
Did you miss your activation email?


Login with username, password and session length

Search

 
Advanced search

8043 Posts in 1856 Topics- by 2099 Members - Latest Member: roi
Calendar Script CommunityCustomizationHacks and Mods (Moderators: scott, DanO, Marty)Ability to change calendars from the calendar view?
Pages: [1] 2   Go Down
Print
Author Topic: Ability to change calendars from the calendar view?  (Read 1201 times)
0 Members and 1 Guest are viewing this topic.
Keith G
Guest
« on: August 15, 2002, 05:54:00 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

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #1 on: August 16, 2002, 01:35:00 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).]

Logged
mooredp
New Member
*

Karma: 0
Offline Offline

Posts: 0

Librarian


« Reply #2 on: August 27, 2002, 11:18:00 AM »

How do I modify the code so that the link goes to week view?

Thanks!

David M.

------------------

Logged

David P. Moore
Huuntsville, AL
mooredp@email.uah.edu
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #3 on: August 27, 2002, 01:32:00 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.

------------------

Logged
spin2cool
Guest
« Reply #4 on: August 28, 2002, 06:01:00 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.

Logged
spin2cool
Guest
« Reply #5 on: August 30, 2002, 03:06:00 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 -->

Logged
Keith G
Guest
« Reply #6 on: October 16, 2002, 04:35:00 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

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #7 on: October 16, 2002, 06:01:00 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.

------------------

Logged
Keith G
Guest
« Reply #8 on: October 17, 2002, 11:18:00 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

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #9 on: October 17, 2002, 07:12:00 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.

------------------

Logged
Keith G
Guest
« Reply #10 on: October 21, 2002, 11:34:00 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 -
        Keith
Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #11 on: October 21, 2002, 08:18:00 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).]

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #12 on: December 03, 2002, 06:43:00 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).]

Logged
tw1000
New Member
*

Karma: 0
Offline Offline

Posts: 0


WWW
« Reply #13 on: February 04, 2003, 10:16:00 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?  

------------------

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #14 on: February 05, 2003, 01:46:00 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.

------------------

Logged
Pages: [1] 2   Go Up
Print
Jump to: