zoukankan      html  css  js  c++  java
  • Using the FullCalendar Plugin in SharePoint 2013 Apps

    As we all know, SharePoint 2013 has heavy emphasis on client-side programming. Because of this, I have had my eye out for a good jQuery calendar plugin to use with JavaScript. In this post, I’ll show you how to get up and running with the FullCalendar jQuery plugin by Adam Shaw. The sample app will aggregate events from all of the calendars in the farm via search and display them in a single calendar.

    Note that this article is coming out of research I am doing to create app samples for MSDN. As a result, I’m not posting the full code solution at this point, but will announce when the samples (around 20 of them) are available.

    To get started, download the v1.6.0 FullCalendar plugin files. After creating a new SharePoint-hosted app. Add the following libraries to the scripts folder of the app:

    • ·       fullcalendar.js
    • ·       jquery-1.9.1.js

    Note that the FullCalendar plugin expects the latest version of jquery. So, you should add version 1.9.1 to your app and delete the version that is added by the project template. Now add the following style sheet to the Content folder in your app:

    • ·       fullcalendar.css

    Finally, add a div tag with an id of “corporateCalendar” to hold the calendar as shown in the following code:

    <asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">

        <div style="margin:25px;">

            <div id='corporateCalendar'></div>

        </div>

    </asp:Content>

    FullCalendar can use a function, JSON feed, or array as a data source. For this sample, I’ll keep it simple and build an array that gets loaded along with the app. The format of the array will look like the following:

    [

            {

                title  : 'Golf Trip',

                start  : '2013-01-01 12:00:00'

                end    : '2013-01-07 12:00:00'

                allDay : true

            },

            {

                title  : 'Student Visit',

                start  : '2013-02-01 09:00:00'

                end    : '2013-02-07 14:00:00'

                allDay : true

            },

            {

                title  : 'Company Picnic',

                start  : '2013-04-01 13:00:00'

                end    : '2013-04-01 15:00:00'

                allDay : false

            }

        ]

    As you navigate the calendar, FullCalendar provides events you can trap that will allow you to receive information about the start and end dates currently being displayed. You can also alter display characteristics. For example, all-day events should display without time information.

    The idea is to build the required data array based on data returned from a search. In this way, you can search all of the calendars in the farm and build a master calendar. The results of the search will be security-trimmed, which is cool because our calendar will only show events meaningful to the viewer. The problem, however, is that SharePoint 2013 doesn’t have the Managed Properties for event start date, event end date, or all-day events out of the box. So, I had to define a the following managed properties:

    Crawled

    Managed

    ows_EventDate

    EventDate

    ows_EndDate

    EndDate

    ows_fAllDayEvent

    AllDayEvent

    After a full crawl, I could then write queries like the following to return all events for CY2013:

    ContentClass:STS_ListItem_Events EventDate>1/1/2013 EventDate<12/31/2013

    With the search working, I needed to create a JavaScript library that would run the query and package up the event data. I’ll gloss over the details here because this post is about the calendar itself, but my basic approach was to use a REST call like this:

    var url = _spPageContextInfo.webAbsoluteUrl +

              "/_api/search/query?querytext='ContentClass:STS_ListItem_Events" +

              " EventDate>" + startDateString +

              " EndDate<" + endDateString +

              "'&selectproperties='Title,EventDate,EndDate,AllDayEvent,Path'";

    var deferred = $.ajax({

        url: url,

        method: "GET",

        headers: {

            "accept": "application/xml",

        },

        success: function (data) {

            //Fill event array with results

        },

        error: function (err) {

            //Handle errors

        }

    });

    return deferred.promise();

    My library also needed a function to return the event array in the form expected by FullCalendar. So I built a JSON object like this:

    Get_formattedEvents = function () {

        var json = [];

        for (var i = 0; i < events.length; i++) {

            json.push({

                title: events[i].get_title(),

                start: events[i].get_formattedStart(),

                end: events[i].get_formattedEnd(),

                allDay: events[i].get_formattedAllDay()

            });

        }

        return json;

     }

    I packaged the functions into a library called WingtipToys.Events with a load function that accepted arguments for the span of days before and after today’s date for which to run the search. The following code shows how the calendar was filled with events 90 days prior to the current date and one year into the future. Take note of how theget_formattedEvents function is called by the FullCalendar plugin. That’s really all you have to do, which makes this plugin a great addition to your SharePoint 2013 app development toolkit.

    WingtipToys.Events.load(90, 365).then(

        function (data) {

            $("#corporateCalendar").fullCalendar({

                events: WingtipToys.Events.get_formattedEvents()

            });

        },

        function (err) {

            alert(JSON.stringify(err));

        }

    );

    The final sample is going to include a separate list in which you can add “included paths” to the search query. The idea here is to allow you to select exactly which calendars to aggregate rather than take every one in the farm. Again, I'll announce when the final samples become available on MSDN.

  • 相关阅读:
    数组作业:例题5.1.一个10个元素一维数组的赋值与遍历
    java子父类初始化顺序 (1)父类静态代码块(2)父类静态变量初始化(3)子类静态代码块(4)子类静态变量初始化(5)main(6)有对象开辟空间都为0(7)父类显示初始化(8)父类构造(9)子类显示初始化(10)子类构造
    如果实现接口的类只使用一次用处不大换为如下简便写法——匿名内部类
    1、实现接口的抽象类——适配器;2、代理公司的方法——功能更强大的包装类;3、接口的使用——工厂模式(高内聚低耦合)
    内部类的作用?1、抽象类中包含一个内部接口如何实现与调用 ;2、接口中包含一个内部抽象类如何调用
    接口的多态使用; 接口应用实例:U盘、打印机可以使用共同的USB接口,插入到电脑上实现各自的功能。
    接口的定义——默认加public abstract默认全局常量;与继承不同,子类可以同时实现多个接口;抽象类实现接口;接口继承接口
    EBCDIC to ASCII
    how to pass variable from shell script to sqlplus
    关于Insufficient space for shared memory file解决办法
  • 原文地址:https://www.cnblogs.com/zyip/p/3088126.html
Copyright © 2011-2022 走看看