在SharePoint日曆中,如何禁用拖拽事件

Hi all! Based on this sharepoint.stackexchange question.

May be in some reasons you want to disable all drag-and-drop event for your calendar list. I don’t know if it possible through C# code, but it’s possible through javascript. In SP.UI.ApplicationPages.Calendar.js there is a factory method SP.UI.ApplicationPages.CalendarContainerFactory.create.This method creates and initializes instance of calendar using javascript. Among other parameters this function accepts context object that contains initialization info about calendar (cctx object). This object contains property DataSources (Array) and each array element is an object that has property named disableDrag. disableDrag false by default. The main idea is to substitute factory method and pass updated cctx object, that has disableDrag=true for every datasource. Edit page with calendar and add content editor web part. In content past this code:

<script type='text/javascript'>

ExecuteOrDelayUntilScriptLoaded(function(){

var calendarCreate = SP.UI.ApplicationPages.CalendarContainerFactory.create;

SP.UI.ApplicationPages.CalendarContainerFactory.create = function(elem, cctx, viewType, date, startupData) {

if(cctx.dataSources && cctx.dataSources instanceof Array && cctx.dataSources.length &gt; 0){

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

cctx.dataSources[i].disableDrag = true;

}

}

calendarCreate(elem, cctx, viewType, date, startupData);

}

}, 'SP.UI.ApplicationPages.Calendar.js');

&lt;/script>

or through code (don’t forget about proper disposing):

var site = new SPSite("http://localhost/sites/test/");

var web = site.OpenWeb();

var wpManager = web.GetLimitedWebPartManager("Lists/cal/calendar.aspx", PersonalizationScope.Shared);

var contentEditor = new ContentEditorWebPart();

var xmlDoc = new XmlDocument();

var xmlElement = xmlDoc.CreateElement("HtmlContent");

xmlElement.InnerText = @"<script type='text/javascript'>

ExecuteOrDelayUntilScriptLoaded(function(){

var calendarCreate = SP.UI.ApplicationPages.CalendarContainerFactory.create;

SP.UI.ApplicationPages.CalendarContainerFactory.create = function(elem, cctx, viewType, date, startupData) {

if(cctx.dataSources && cctx.dataSources instanceof Array && cctx.dataSources.length &gt; 0){

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

cctx.dataSources[i].disableDrag = true;

}

}

calendarCreate(elem, cctx, viewType, date, startupData);

}

}, 'SP.UI.ApplicationPages.Calendar.js');

&lt;/script>";

contentEditor.Content = xmlElement;

wpManager.AddWebPart(contentEditor, "Main", 0);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章