if (!window.console) window.console = {};
if (!window.console.log) window.console.log = function () { };
// modify Calendar markup to open items in dialog
function setCalendarItemsToOpenInDialog() {
try {
var time = new Date();
console.log(time.getSeconds() + ":" + time.getMilliseconds() + " Modifying Calendar Links..");
jQuery('a[href*="DispForm.aspx"]').each(function () {
var co = $("div.ms-acal-title").html();
var col = $("div.ms-acal-time").text();
var coindex = col.indexOf("-");
col = col.substring(0, coindex - 1);
jQuery(this).attr('onclick', 'openDialog("' + $(this).attr('href') + '")');
jQuery(this).attr('href', 'javascript:void(0)');
jQuery(this).removeAttr("target");
//console.log("I'm logging " + jQuery(this).html());
//$("div.ms-acal-time").text(coindex[0]+ " " +coindex[1]+ " ");
//$(co).insertBefore("div.ms-acal-time");
//console.log($(this).parent().html());
//var aft = $(this).parent().html();
//aft = " " +aft;
//$("div.ms-acal-time").html(col+ " " +$(this).parent().html());
//$(aft).appendTo("div.ms-acal-sdiv");
//$("div.ms-acal-title").remove();
var linktext = $(this).text();
if(linktext.toLowerCase().split("canceled").length > 1){
$(this).parent().parent().css('background-color', '#808080');
}else if(linktext.toLowerCase().split("held").length > 1){
$(this).parent().parent().css('background-color', '#808080');
}else if(linktext.toLowerCase().split("gta").length > 1){
$(this).parent().parent().css('background-color', '#f23f58');
}else if(linktext.toLowerCase().split("general tax").length > 1){
$(this).parent().parent().css('background-color', '#f23f58');
}else if(linktext.toLowerCase().split("pto").length > 1){
$(this).parent().parent().css('background-color', '#00aca1');
}else if(linktext.toLowerCase().split("property tax").length > 1){
$(this).parent().parent().css('background-color', '#00aca1');
}else if(linktext.toLowerCase().split("csp").length > 1){
$(this).parent().parent().css('background-color', '#051a54');
}else if(linktext.toLowerCase().split("child suppoprt").length > 1){
$(this).parent().parent().css('background-color', '#051a54');
}else if(linktext.toLowerCase().split("canceled").length > 1){
$(this).parent().parent().css('background-color', '#808080');
}else if(linktext.toLowerCase().split("cabinet").length > 1){
$(this).parent().parent().css('background-color', '#782F40');
} else if(linktext.toLowerCase().split("public").length > 1){
$(this).parent().parent().css('background-color', '#990099');
}else{
$(this).parent().parent().css('background-color', '#00aca1');
}
});
} catch (e) {
//console.log("Exception in setCalendarItemsToOpenInDialog: " + e.name + ", " + e.message);
}
}
function myCalendarHook() {
try {
// save the original onItemsSucceed function
var _onItemsSucceed = SP.UI.ApplicationPages.CalendarStateHandler.prototype.onItemsSucceed;
// override a function that is called whenever calendar items are loaded (onItemsSucceed)
SP.UI.ApplicationPages.CalendarStateHandler.prototype.onItemsSucceed = function($p0, $p1) {
// call the original onItemsSucceed to make sure that all calendar functionality is as it used to be
_onItemsSucceed.call(this, $p0, $p1);
// modify Calendar links
setCalendarItemsToOpenInDialog();
// For more than 3 items per day there is 'Show n more items' link.
// This link rewrites all modified links when clicked, so we need to wait a little and call our function again:
jQuery('a.ms-cal-nav').on('click', function() {
setTimeout(function() {
setCalendarItemsToOpenInDialog();
}, 500);
});
};
} catch (e) {
// console.log("Exception in myCalendarHook: " + e.name + ", " + e.message);
}
}
function openDialog(urlParameter) {
var idArray = urlParameter.split("=");
var idEvent = idArray[1];
var queryLookup = ""+ idEvent +"";
var AttachmentURL="";
// Call GetListItems to return the ID
$().SPServices({
operation: "GetAttachmentCollection",
async: false,
listName: "Rules Calendar",
ID: idEvent,
completefunc: function(xData,Status) {
$(xData.responseXML).find("Attachments > Attachment").each(function(i, el) {
var $node = $(this);
var filePath = $node.text();
AttachmentURL = filePath;
})
}
});
console.log("Attachments is " + AttachmentURL);
//var ag = '/rules/Lists/Rules%20Calendar/Attachments/' + idEvent + '/agenda.pdf';
var ag = AttachmentURL;
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
if(!isMobile.any()) {
console.log("urlParameter is " + urlParameter);
var options = {
url: ag,
title: 'Agenda',
allowMaximize: false,
showClose: true,
width: 750,
height: 700,
top: 60,
autoSizeStartWidth: 550,
dialogReturnValueCallback: function(dialogResult)
{
SP.UI.ModalDialog.RefreshPage(dialogResult)
}
};
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
setTimeout(function() {
setCalendarItemsToOpenInDialog();
}, 500);
return false;
} else { location.assign(ag);}
}
ExecuteOrDelayUntilScriptLoaded(function () {
myCalendarHook();
}, "SP.UI.ApplicationPages.Calendar.js");
setTimeout(function() {
if(navigator.userAgent.match(/CriOS| FxiOS/i)){
jQuery('a[href*="DispForm.aspx"]').each(function () {
jQuery(this).removeAttr("href");
});
}
}, 6000);