Wednesday, February 29, 2012

Article 1: Color calendar


Step 1: Open your Site and click to calendar link
And see
Step 2: Click to tab Calendar
Step 3: Click to Icon Create column
Step 4: Fill information
                Column name: CategoryTitle
                Field type: Caculated and Fill to box Formula:  ="|||"&Category&"|||"&Title
                Click Ok.
Step 5: download 2 file js at Here and upload to Shared documents
Step 6: Back to list Calendar
Step 7: Click Site Action | Edit Page
Step 8: Click Add a Web Part | in Categories | Media and Content | click Content Editor | Click Add
User Interface below
Step 9: Click to content editor then click HTMl | Edit HTMl Source
Step 10: Copy code and paste to here (you must point to path to 2 file .js in your List Shared Documents)
<script type="text/javascript" src="/ViecLamNgoaiNuoc/Shared%20Documents/jquery-1.4.2.js"></script>
<script type="text/javascript" src="/ViecLamNgoaiNuoc/Shared%20Documents/QuocHungCalenderColor.js"></script>
Code QuocHungCalenderColor.js

_spBodyOnLoadFunctionNames.push('WaitForCalendarToLoad');
var SEPARATOR = "|||";
function WaitForCalendarToLoad() {
    // we will slightly rewrite this existing function as defined originally in SP.UI.ApplicationPages.Calendar.debug.js
    var pwold$4a = SP.UI.ApplicationPages.CalendarNotify.$4a;
 SP.UI.ApplicationPages.CalendarNotify.$4a = function () {
        pwold$4a();
        ColourCalendar();
    }
}
function ColourCalendar() {
if($('a:contains(' + SEPARATOR + ')') != null)
{
    $('a:contains(' + SEPARATOR + ')').each(
        function (i) {
            $box = $(this).parents('div[title]');
            var colour = GetColourCodeFromCategory(GetCategory(this.innerHTML));
            this.innerHTML = GetActualText(this.innerHTML);
            $($box).attr("title", GetActualText($($box).attr("title")));
            $box.css('background-color', colour);
        });
}
}
function GetActualText(originalText) {
    var parts = originalText.split(SEPARATOR);
    return parts[0] + parts[2];
}
function GetCategory(originalText) {
    var parts = originalText.split(SEPARATOR);
    return parts[1];
}
function GetColourCodeFromCategory(category) {
    var colour = null;
  
    switch (category.trim().toLowerCase()) {
        case 'meeting':
            colour = '#4FDB51';
            break;
        case 'work hours':
            colour = '#4FB8DB';
            break;
        case 'business':
            colour = "#F08616";
            break;
        case 'holiday':
            colour = "#F55875";
            break;
        case 'get-together':
            colour = "#E0F558";
            break;
        case 'gifts':
            colour = "#F558D5";
            break;
        case 'birthday':
            colour = "#6E80FA";
            break;
        case 'anniversary':
            colour = "#FF4040";
            break;
    }
    return colour;
}
Step 11: Stop Editing
Step 12: On list calendar click to Tab Calendar then click Modify View
Step 13: Modify View
Month View Title: choose CategoryTitle
Week View Title: choose CategoryTitle
Day View Title: choose CategoryTitle

Step 14: Click Ok and see result below

0 comments:

Post a Comment