How to add color coded categories to your calendars with JavaScript:
Caveats:
This solution uses Calculated Fields to display colors related to a particular category. The Category column MUST be a choice column - a lookup column will not work as look-up columns are NOT allowed in Calculated Field Column equations.You must be able to add a Content Editor Web Part to the pages where the calendar will be viewed.
Part 1: Setting up the JavaScript:
- Copy the following script into a text file:
<script> _spBodyOnLoadFunctionNames.push('colorCalendarEventLinkIntercept'); function colorCalendarEventLinkIntercept() { if (SP.UI.ApplicationPages.CalendarNotify.$4a) { var OldCalendarNotify = SP.UI.ApplicationPages.CalendarNotify.$4a; SP.UI.ApplicationPages.CalendarNotify.$4a = function () { OldCalendarNotify(); colorCalendarEventLinks(); } } if (SP.UI.ApplicationPages.CalendarNotify.$4b) { var OldCalendarNotify = SP.UI.ApplicationPages.CalendarNotify.$4b; SP.UI.ApplicationPages.CalendarNotify.$4b = function () { OldCalendarNotify(); colorCalendarEventLinks(); } } // future service pack change may go here! // if (SP.UI.ApplicationPages.CalendarNotify.???) } function colorCalendarEventLinks() { var divs = document.getElementsByTagName("DIV"); for (var i=0;i
/g,'" if="" {="">'); } if (divs[i].className.toLowerCase()=="ms-acal-ctrlitem") { var links = divs[i].getElementsByTagName("A"); if (links.length==1) { links[0].href="javascript:colorCalendarEventLinks();void(0);" } } } } <script> - Save the text file to a documents folder on the sharepoint site where you intend to modify the calendar. Make sure it's a folder your customer will have rights to view.
- Copy the URL for the text file you uploaded to notepad - you will need to reference this URL later in part 4.
Part 2: Setting Up the Calendar Colors:
- Go to this the COLOR-CODING-CALENDAR-LIST site: http://usermanagedsolutions.com/SharePoint-User-Toolkit/Pages/Color-Coding-Calendar-List.aspx
- Enter the name of your Category column in the "Choice Column" field
- Enter your Categories in the "Choices" field
- Enter the name of the column that will be displaying the Calendar Appointment Title text in the "Displayed Column" (usually "Title" or "Name")
- Decide how you want the color coding displayed - you can apply it to the text, the background, or the text and the background. If you have any CSS skills you can modify this later.
- Leave the rest of the options as is for now and skip down to where the colors are displayed. You'll notice that the category choices you entered in step 3 are displayed here. Use the color pickers to select the colors you want displayed for each category.
Part 3: Setting up the Calendar:
- In another TAB or WINDOW, open the Calendar you want to apply the color coding to.
- Open the LIST SETTINGS for the Calendar
- Create a NEW Column
- Name the Column "Color", and set it to "Calculated (calculation based on other columns)"
- Open the TAB or WINDOW with the COLOR-CODING-CALENDAR-LIST site.
- Copy the code from the GREEN box under the "Paste the following formula in the Color calculated column:" text.
- Now open the TAB or WINDOW with your New Calendar Column, and paste the code into the "Formula" box.
- Click OK.
- Create another NEW Column
- Name the Column "Category-Text", and set it to "Calculated (calculation based on other columns)"
- Open the TAB or WINDOW with the COLOR-CODING-CALENDAR-LIST site.
- Copy the code from the GREEN box under the "Paste the following formula in the calculated column that will be displayed in the list or calendar:" text.
- Now open the TAB or WINDOW with your New Calendar Column, and paste the code into the "Formula" box.
- Click OK.
Part 4: Fixing the View
- In the LIST Settings, under "Views", click the "Create View" link.
- Choose the Calendar View type.
- Name the View (e.g. "Calendar-Colors")
- Under "Calendar Columns", set the "Month View Title:" "Week View Title:" and "Day View Title" to the "Category-Text" column.
- Click OK
- Make sure you are looking at the new view ("Calendar-Colors" or whatever you named it). You will see tags littering the days where you have appointments set.
- EDIT the PAGE (Site Actions > Edit Page)
- Add a Content Editor Web Part
- Click the little dropdown to "EDIT WEB PART".
- In the Content Link Box where it says "To link to a text file, type a URL." Paste the URL to the text file you uploaded in Part 1.
- Under Appearance, Set the Chrome Type to "None".
- Click OK
508 Compliance:
Make sure to provide additional views for people to view your items by category. Additionally you could modify the tags that you paste into the "Category-Text" column to include a "Title" attribute that displays the Category column.References:
http://usermanagedsolutions.com/SharePoint-User-Toolkit/Pages/Color-Coding-Calendar-List.aspx
http://techtrainingnotes.blogspot.com/2010/06/sharepoint-2010-color-coded-calendars.html
http://www.orbitone.com/en/blog/archive/2010/10/25/calendar-colour-coding-in-sharepoint.aspx
No comments:
Post a Comment