Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
");
gridcontainer.html(html.join(""));
html = null;
$("#cal-month-closebtn").click(closeCc);
}
function closeCc() {
$("#cal-month-cc").css("visibility", "hidden");
}
//all-day event, including more-than-one-day events
function PropareEvents(dayarrs, events, aDE, sDE) {
var l = dayarrs.length;
var el = events.length;
var fE = [];
var deB = aDE;
var deA = sDE;
for (var j = 0; j < el; j++) {
var sD = events[j][2];
var eD = events[j][3];
var s = {};
s.event = events[j];
s.day = sD.getDate();
s.year = sD.getFullYear();
s.month = sD.getMonth() + 1;
s.allday = events[j][4] == 1;
s.crossday = events[j][5] == 1;
s.reevent = events[j][6] == 1; //Recurring event
s.daystr = [s.year, s.month, s.day].join("/");
s.st = {};
s.st.hour = sD.getHours();
s.st.minute = sD.getMinutes();
s.st.p = s.st.hour * 60 + s.st.minute; // start time
s.et = {};
s.et.hour = eD.getHours();
s.et.minute = eD.getMinutes();
s.et.p = s.et.hour * 60 + s.et.minute; // end time
fE.push(s);
}
var dMax = 0;
for (var i = 0; i < l; i++) {
var da = dayarrs[i];
deA[i] = []; deB[i] = [];
da.daystr = da.year + "/" + da.month + "/" + da.day;
for (var j = 0; j < fE.length; j++) {
if (!fE[j].crossday && !fE[j].allday) {
if (da.daystr == fE[j].daystr)
deA[i].push(fE[j]);
}
else {
if (da.daystr == fE[j].daystr) {
deB[i].push(fE[j]);
dMax++;
}
else {
if (i == 0 && da.date >= fE[j].event[2] && da.date <= fE[j].event[3])//first more-than-one-day event
{
deB[i].push(fE[j]);
dMax++;
}
}
}
}
}
var lrdate = dayarrs[l - 1].date;
for (var i = 0; i < l; i++) { //to deal with more-than-one-day event
var de = deB[i];
if (de.length > 0) { //
for (var j = 0; j < de.length; j++) {
var end = DateDiff("d", lrdate, de[j].event[3]) > 0 ? lrdate : de[j].event[3];
de[j].colSpan = DateDiff("d", dayarrs[i].date, end) + 1
}
}
de = null;
}
//for all-day events
for (var i = 0; i < l; i++) {
var de = deA[i];
if (de.length > 0) {
var x = [];
var y = [];
var D = [];
var dl = de.length;
var Ia;
for (var j = 0; j < dl; ++j) {
var ge = de[j];
for (var La = ge.st.p, Ia = 0; y[Ia] > La; ) Ia++;
ge.PO = Ia; ge.ne = []; //PO is how many events before this one
y[Ia] = ge.et.p || 1440;
x[Ia] = ge;
if (!D[Ia]) {
D[Ia] = [];
}
D[Ia].push(ge);
if (Ia != 0) {
ge.pe = [x[Ia - 1]]; //previous event
x[Ia - 1].ne.push(ge); //next event
}
for (Ia = Ia + 1; y[Ia] <= La; ) Ia++;
if (x[Ia]) {
var k = x[Ia];
ge.ne.push(k);
k.pe.push(ge);
}
ge.width = 1 / (ge.PO + 1);
ge.left = 1 - ge.width;
}
var k = Array.prototype.concat.apply([], D);
x = y = D = null;
var t = k.length;
for (var y = t; y--; ) {
var H = 1;
var La = 0;
var x = k[y];
for (var D = x.ne.length; D--; ) {
var Ia = x.ne[D];
La = Math.max(La, Ia.VL);
H = Math.min(H, Ia.left)
}
x.VL = La + 1;
x.width = H / (x.PO + 1);
x.left = H - x.width;
}
for (var y = 0; y < t; y++) {
var x = k[y];
x.left = 0;
if (x.pe) for (var D = x.pe.length; D--; ) {
var H = x.pe[D];
x.left = Math.max(x.left, H.left + H.width);
}
var p = (1 - x.left) / x.VL;
x.width = Math.max(x.width, p);
x.aQ = Math.min(1 - x.left, x.width + 0.7 * p); //width offset
}
de = null;
deA[i] = k;
}
}
return dMax;
}
function BuildWT(ht, dayarrs, events, dMax) {
//1:
ht.push("
", "
");
for (var i = 0; i < dayarrs.length; i++) {
var ev, title, cl;
if (dayarrs.length == 1) {
ev = "";
title = "";
cl = "";
}
else {
ev = ""; // "onclick=\"javascript:FunProxy('week2day',event,this);\"";
title = i18n.xgcalendar.to_date_view;
cl = "wk-daylink";
}
ht.push("
", dayarrs[i].display, "
");
}
ht.push("
");
ht.push("
"); //end tr1;
//2:
if (!option.hideAllDay) {
ht.push("
");
for (var i = 0; i < dayarrs.length; i++) {
ht.push("
");
}
ht.push("
");
}
else {
var l = events.length;
var el = 0;
var x = [];
for (var j = 0; j < l; j++) {
x.push(0);
}
//var c = tc();
for (var j = 0; el < dMax; j++) {
ht.push("
");
for (var h = 0; h < l; ) {
var e = events[h][x[h]];
ht.push("
");
for (var i = option.startHour; i < option.endHour; i++) {
ht.push("");
}
ht.push("
");
//2:
ht.push("
");
ht.push("
");
//get current time
var now = new Date(); var h = now.getHours(); var m = now.getMinutes();
var mHg = gP(h, m) - 4; //make middle alignment vertically
if (mHg < option._scrollHeigth) {
ht.push("");
}
var tmt = "";
for (var i = option.startHour; i < option.endHour; i++) {
tmt = fomartTimeShow(i);
ht.push("
", tmt, "
");
}
ht.push("
");
var l = dayarrs.length;
for (var i = 0; i < l; i++) {
ht.push("
");
var istoday = dateFormat.call(dayarrs[i].date, "yyyyMMdd") == dateFormat.call(new Date(), "yyyyMMdd");
// Today
if (istoday) {
ht.push("
');
var tempquickAddHanler = temparr.join("");
temparr = null;
$(document.body).append(tempquickAddHanler);
buddle = $("#bbit-cal-buddle");
var calbutton = $("#bbit-cal-quickAddBTN");
var lbtn = $("#bbit-cal-editLink");
var closebtn = $("#bubbleClose1").click(function() {
$("#bbit-cal-buddle").css("visibility", "hidden");
realsedragevent();
});
calbutton.click(function(e) {
if (option.isloading) {
return false;
}
option.isloading = true;
var what = $("#bbit-cal-what").val();
var datestart = $("#bbit-cal-start").val();
var dateend = $("#bbit-cal-end").val();
var allday = $("#bbit-cal-allday").val();
var f = /^[^\$\<\>]+$/.test(what);
if (!f) {
alert(i18n.xgcalendar.invalid_title);
$("#bbit-cal-what").focus();
option.isloading = false;
return false;
}
var zone = new Date().getTimezoneOffset() / 60 * -1;
var param = [{ "name": "CalendarTitle", value: what },
{ "name": "CalendarStartTime", value: datestart },
{ "name": "CalendarEndTime", value: dateend },
{ "name": "IsAllDayEvent", value: allday },
{ "name": "timezone", value: zone}];
if (option.extParam) {
for (var pi = 0; pi < option.extParam.length; pi++) {
param[param.length] = option.extParam[pi];
}
}
if (option.quickAddHandler && $.isFunction(option.quickAddHandler)) {
option.quickAddHandler.call(this, param);
$("#bbit-cal-buddle").css("visibility", "hidden");
realsedragevent();
}
else {
$("#bbit-cal-buddle").css("visibility", "hidden");
var newdata = [];
var tId = -1;
option.onBeforeRequestData && option.onBeforeRequestData(2);
$.post(option.quickAddUrl, param, function(data) {
if (data) {
if (data.IsSuccess == true) {
option.isloading = false;
option.eventItems[tId][0] = data.Data;
option.eventItems[tId][8] = 1;
render();
option.onAfterRequestData && option.onAfterRequestData(2);
}
else {
option.onRequestDataError && option.onRequestDataError(2, data);
option.isloading = false;
option.onAfterRequestData && option.onAfterRequestData(2);
}
}
}, "json");
newdata.push(-1, what);
var sd = strtodate(datestart);
var ed = strtodate(dateend);
var diff = DateDiff("d", sd, ed);
newdata.push(sd, ed, allday == "1" ? 1 : 0, diff > 0 ? 1 : 0, 0);
newdata.push(-1, 0, "", "");
tId = Ind(newdata);
realsedragevent();
render();
}
});
lbtn.click(function(e) {
if (!option.EditCmdhandler) {
alert("EditCmdhandler" + i18n.xgcalendar.i_undefined);
}
else {
if (option.EditCmdhandler && $.isFunction(option.EditCmdhandler)) {
option.EditCmdhandler.call(this, ['0', $("#bbit-cal-what").val(), $("#bbit-cal-start").val(), $("#bbit-cal-end").val(), $("#bbit-cal-allday").val()]);
}
$("#bbit-cal-buddle").css("visibility", "hidden");
realsedragevent();
}
return false;
});
buddle.mousedown(function(e) { return false });
}
var dateshow = CalDateShow(start, end, !isallday, true);
var off = getbuddlepos(pos.left, pos.top);
if (off.hide) {
$("#prong2").hide()
}
else {
$("#prong2").show()
}
$("#bbit-cal-buddle-timeshow").html(dateshow);
var calwhat = $("#bbit-cal-what").val("");
$("#bbit-cal-allday").val(isallday ? "1" : "0");
$("#bbit-cal-start").val(dateFormat.call(start, i18n.xgcalendar.dateformat.fulldayvalue + " HH:mm"));
$("#bbit-cal-end").val(dateFormat.call(end, i18n.xgcalendar.dateformat.fulldayvalue + " HH:mm"));
buddle.css({ "visibility": "visible", left: off.left, top: off.top });
calwhat.blur().focus(); //add 2010-01-26 blur() fixed chrome
$(document).one("mousedown", function() {
$("#bbit-cal-buddle").css("visibility", "hidden");
realsedragevent();
});
return false;
}
//format datestring to Date Type
function strtodate(str) {
var arr = str.split(" ");
var arr2 = arr[0].split(i18n.xgcalendar.dateformat.separator);
var arr3 = arr[1].split(":");
var y = arr2[i18n.xgcalendar.dateformat.year_index];
var m = arr2[i18n.xgcalendar.dateformat.month_index].indexOf("0") == 0 ? arr2[i18n.xgcalendar.dateformat.month_index].substr(1, 1) : arr2[i18n.xgcalendar.dateformat.month_index];
var d = arr2[i18n.xgcalendar.dateformat.day_index].indexOf("0") == 0 ? arr2[i18n.xgcalendar.dateformat.day_index].substr(1, 1) : arr2[i18n.xgcalendar.dateformat.day_index];
var h = arr3[0].indexOf("0") == 0 ? arr3[0].substr(1, 1) : arr3[0];
var n = arr3[1].indexOf("0") == 0 ? arr3[1].substr(1, 1) : arr3[1];
return new Date(y, parseInt(m) - 1, d, h, n);
}
function rebyKey(key, remove) {
if (option.eventItems && option.eventItems.length > 0) {
var sl = option.eventItems.length;
var i = -1;
for (var j = 0; j < sl; j++) {
if (option.eventItems[j][0] == key) {
i = j;
break;
}
}
if (i >= 0) {
var t = option.eventItems[i];
if (remove) {
option.eventItems.splice(i, 1);
}
return t;
}
}
return null;
}
function Ind(event, i) {
var d = 0;
if (!i) {
if (option.eventItems && option.eventItems.length > 0) {
var sl = option.eventItems.length;
var s = event[2];
var d1 = s.getTime() - option.eventItems[0][2].getTime();
var d2 = option.eventItems[sl - 1][2].getTime() - s.getTime();
var diff = d1 - d2;
if (d1 < 0 || diff < 0) {
for (var j = 0; j < sl; j++) {
if (option.eventItems[j][2] >= s) {
i = j;
break;
}
}
}
else if (d2 < 0) {
i = sl;
}
else {
for (var j = sl - 1; j >= 0; j--) {
if (option.eventItems[j][2] < s) {
i = j + 1;
break;
}
}
}
}
else {
i = 0;
}
}
else {
d = 1;
}
if (option.eventItems && option.eventItems.length > 0) {
if (i == option.eventItems.length) {
option.eventItems.push(event);
}
else { option.eventItems.splice(i, d, event); }
}
else {
option.eventItems = [event];
}
return i;
}
function ResizeView() {
var _MH = document.documentElement.clientHeight;
var _viewType = option.view;
if (_viewType == "day" || _viewType == "week") {
var $dvwkcontaienr = $("#dvwkcontaienr");
var $dvtec = $("#dvtec");
if ($dvwkcontaienr.length == 0 || $dvtec.length == 0) {
alert(i18n.xgcalendar.view_no_ready); return;
}
var dvwkH = $dvwkcontaienr.height() + 2;
var calH = option.height - 8 - dvwkH;
$dvtec.height(calH);
if (typeof (option.scoll) == "undefined") {
var currentday = new Date();
var h = currentday.getHours();
var m = currentday.getMinutes();
var th = gP(h, m);
var ch = $dvtec.attr("clientHeight");
var sh = th - 0.5 * ch;
var ph = $dvtec.attr("scrollHeight");
if (sh < 0) sh = 0;
if (sh > ph - ch) sh = ph - ch - 10 * (23 - h);
$dvtec.attr("scrollTop", sh);
}
else {
$dvtec.attr("scrollTop", option.scoll);
$dvtec.scrollTop(option.scoll);
}
}
else if (_viewType == "month") {
//Resize GridContainer
}
}
function returnfalse() {
return false;
}
function initevents(viewtype) {
if (viewtype == "week" || viewtype == "day") {
$("div.chip", gridcontainer).each(function(i) {
var chip = $(this);
chip.click(dayshow);
if (chip.hasClass("drag")) {
chip.mousedown(function(e) { dragStart.call(this, "dw3", e); return false; });
//resize
chip.find("div.resizer").mousedown(function(e) {
dragStart.call($(this).parent().parent(), "dw4", e); return false;
});
}
else {
chip.mousedown(returnfalse)
}
});
$("div.rb-o", gridcontainer).each(function(i) {
var chip = $(this);
chip.click(dayshow);
if (chip.hasClass("drag") && viewtype == "week") {
//drag;
chip.mousedown(function(e) { dragStart.call(this, "dw5", e); return false; });
}
else {
chip.mousedown(returnfalse)
}
});
if (option.readonly == false) {
$("td.tg-col", gridcontainer).each(function(i) {
$(this).mousedown(function(e) { dragStart.call(this, "dw1", e); return false; });
});
$("#weekViewAllDaywk").mousedown(function(e) { dragStart.call(this, "dw2", e); return false; });
}
if (viewtype == "week") {
$("#dvwkcontaienr th.gcweekname").each(function(i) {
$(this).click(weekormonthtoday);
});
}
}
else if (viewtype = "month") {
$("div.rb-o", gridcontainer).each(function(i) {
var chip = $(this);
chip.click(dayshow);
if (chip.hasClass("drag")) {
//drag;
chip.mousedown(function(e) { dragStart.call(this, "m2", e); return false; });
}
else {
chip.mousedown(returnfalse)
}
});
$("td.st-more", gridcontainer).each(function(i) {
$(this).click(function(e) {
moreshow.call(this, $(this).parent().parent().parent().parent()[0]); return false;
}).mousedown(function() { return false; });
});
if (option.readonly == false) {
$("#mvEventContainer").mousedown(function(e) { dragStart.call(this, "m1", e); return false; });
}
}
}
function realsedragevent() {
if (_dragevent) {
_dragevent();
_dragevent = null;
}
}
function dragStart(type, e) {
var obj = $(this);
var source = e.srcElement || e.target;
realsedragevent();
switch (type) {
case "dw1":
_dragdata = { type: 1, target: obj, sx: e.pageX, sy: e.pageY };
break;
case "dw2":
var w = obj.width();
var h = obj.height();
var offset = obj.offset();
var left = offset.left;
var top = offset.top;
var l = option.view == "day" ? 1 : 7;
var py = w % l;
var pw = parseInt(w / l);
if (py > l / 2 + 1) {
pw++;
}
var xa = [];
var ya = [];
for (var i = 0; i < l; i++) {
xa.push({ s: i * pw + left, e: (i + 1) * pw + left });
}
ya.push({ s: top, e: top + h });
_dragdata = { type: 2, target: obj, sx: e.pageX, sy: e.pageY, pw: pw, xa: xa, ya: ya, h: h };
w = left = l = py = pw = xa = null;
break;
case "dw3":
var evid = obj.parent().attr("id").replace("tgCol", "");
var p = obj.parent();
var pos = p.offset();
var w = p.width() + 10;
var h = obj.height();
var data = getdata(obj);
_dragdata = { type: 4, target: obj, sx: e.pageX, sy: e.pageY,
pXMin: pos.left, pXMax: pos.left + w, pw: w, h: h,
cdi: parseInt(evid), fdi: parseInt(evid), data: data
};
break;
case "dw4": //resize;
var h = obj.height();
var data = getdata(obj);
_dragdata = { type: 5, target: obj, sx: e.pageX, sy: e.pageY, h: h, data: data };
break;
case "dw5":
var con = $("#weekViewAllDaywk");
var w = con.width();
var h = con.height();
var offset = con.offset();
var moffset = obj.offset();
var left = offset.left;
var top = offset.top;
var l = 7;
var py = w % l;
var pw = parseInt(w / l);
if (py > l / 2 + 1) {
pw++;
}
var xa = [];
var ya = [];
var di = 0;
for (var i = 0; i < l; i++) {
xa.push({ s: i * pw + left, e: (i + 1) * pw + left });
if (moffset.left >= xa[i].s && moffset.left < xa[i].e) {
di = i;
}
}
var fdi = { x: di, y: 0, di: di };
ya.push({ s: top, e: top + h });
var data = getdata(obj);
var dp = DateDiff("d", data[2], data[3]) + 1;
_dragdata = { type: 6, target: obj, sx: e.pageX, sy: e.pageY, data: data, xa: xa, ya: ya, fdi: fdi, h: h, dp: dp, pw: pw };
break;
case "m1":
var w = obj.width();
var offset = obj.offset();
var left = offset.left;
var top = offset.top;
var l = 7;
var yl = obj.children().length;
var py = w % l;
var pw = parseInt(w / l);
if (py > l / 2 + 1) {
pw++;
}
var h = $("#mvrow_0").height();
var xa = [];
var ya = [];
for (var i = 0; i < l; i++) {
xa.push({ s: i * pw + left, e: (i + 1) * pw + left });
}
var xa = [];
var ya = [];
for (var i = 0; i < l; i++) {
xa.push({ s: i * pw + left, e: (i + 1) * pw + left });
}
for (var i = 0; i < yl; i++) {
ya.push({ s: i * h + top, e: (i + 1) * h + top });
}
_dragdata = { type: 3, target: obj, sx: e.pageX, sy: e.pageY, pw: pw, xa: xa, ya: ya, h: h };
break;
case "m2":
var row0 = $("#mvrow_0");
var row1 = $("#mvrow_1");
var w = row0.width();
var offset = row0.offset();
var diffset = row1.offset();
var moffset = obj.offset();
var h = diffset.top - offset.top;
var left = offset.left;
var top = offset.top;
var l = 7;
var yl = row0.parent().children().length;
var py = w % l;
var pw = parseInt(w / l);
if (py > l / 2 + 1) {
pw++;
}
var xa = [];
var ya = [];
var xi = 0;
var yi = 0;
for (var i = 0; i < l; i++) {
xa.push({ s: i * pw + left, e: (i + 1) * pw + left });
if (moffset.left >= xa[i].s && moffset.left < xa[i].e) {
xi = i;
}
}
for (var i = 0; i < yl; i++) {
ya.push({ s: i * h + top, e: (i + 1) * h + top });
if (moffset.top >= ya[i].s && moffset.top < ya[i].e) {
yi = i;
}
}
var fdi = { x: xi, y: yi, di: yi * 7 + xi };
var data = getdata(obj);
var dp = DateDiff("d", data[2], data[3]) + 1;
_dragdata = { type: 7, target: obj, sx: e.pageX, sy: e.pageY, data: data, xa: xa, ya: ya, fdi: fdi, h: h, dp: dp, pw: pw };
break;
}
$('body').noSelect();
}
function dragMove(e) {
if (_dragdata) {
/*
if (e.pageX < 0 || e.pageY < 0
|| e.pageX > document.documentElement.clientWidth
|| e.pageY >= document.documentElement.clientHeight) {
dragEnd(e);
return false;
}
*/
var d = _dragdata;
switch (d.type) {
case 1:
var sy = d.sy;
var y = e.pageY;
var diffy = y - sy;
if (diffy > 11 || diffy < -11 || d.cpwrap) {
if (diffy == 0) { diffy = 21; }
var dy = diffy % 21;
if (dy != 0) {
diffy = dy > 0 ? diffy + 21 - dy : diffy - 21 - dy;
y = d.sy + diffy;
if (diffy < 0) {
sy = sy + 21;
}
}
if (!d.tp) {
d.tp = $(d.target).offset().top;
}
var gh = gH(sy, y, d.tp);
var ny = gP(gh.sh, gh.sm);
var tempdata;
if (!d.cpwrap) {
tempdata = buildtempdayevent(gh.sh, gh.sm, gh.eh, gh.em, gh.h);
var cpwrap = $("").html(tempdata);
$(d.target).find("div.tg-col-overlaywrapper").append(cpwrap);
d.cpwrap = cpwrap;
}
else {
if (d.cgh.sh != gh.sh || d.cgh.eh != gh.eh || d.cgh.sm != gh.sm || d.cgh.em != gh.em) {
tempdata = buildtempdayevent(gh.sh, gh.sm, gh.eh, gh.em, gh.h);
d.cpwrap.css("top", ny + "px").html(tempdata);
}
}
d.cgh = gh;
if (gh.sh == 0 || gh.eh == 23) {
dragEnd(e);
return false;
}
}
break;
case 2:
var sx = d.sx;
var x = e.pageX;
var diffx = x - sx;
if (diffx > 5 || diffx < -5 || d.lasso) {
if (!d.lasso) {
d.lasso = $("");
$(document.body).append(d.lasso);
}
if (!d.sdi) {
d.sdi = getdi(d.xa, d.ya, sx, d.sy);
}
var ndi = getdi(d.xa, d.ya, x, e.pageY);
if (!d.fdi || d.fdi.di != ndi.di) {
addlasso(d.lasso, d.sdi, ndi, d.xa, d.ya, d.h);
}
d.fdi = ndi;
}
break;
case 3:
var sx = d.sx;
var x = e.pageX;
var sy = d.sy;
var y = e.pageY;
var diffx = x - sx;
var diffy = y - sy;
if (diffx > 5 || diffx < -5 || diffy < -5 || diffy > 5 || d.lasso) {
if (!d.lasso) {
d.lasso = $("");
$(document.body).append(d.lasso);
}
if (!d.sdi) {
d.sdi = getdi(d.xa, d.ya, sx, sy);
}
var ndi = getdi(d.xa, d.ya, x, y);
if (!d.fdi || d.fdi.di != ndi.di) {
addlasso(d.lasso, d.sdi, ndi, d.xa, d.ya, d.h);
}
d.fdi = ndi;
}
break;
case 4:
var data = d.data;
if (data != null && data[8] == 1) {
var sx = d.sx;
var x = e.pageX;
var sy = d.sy;
var y = e.pageY;
var diffx = x - sx;
var diffy = y - sy;
if (diffx > 5 || diffx < -5 || diffy > 5 || diffy < -5 || d.cpwrap) {
var gh, ny, tempdata;
if (!d.cpwrap) {
gh = { sh: data[2].getHours(),
sm: data[2].getMinutes(),
eh: data[3].getHours(),
em: data[3].getMinutes(),
h: d.h
};
d.target.hide();
ny = gP(gh.sh, gh.sm);
d.top = ny;
tempdata = buildtempdayevent(gh.sh, gh.sm, gh.eh, gh.em, gh.h, data[1], false, false, data[7]);
var cpwrap = $("").html(tempdata);
var evid = d.target.parent().attr("id").replace("tgCol", "#tgOver");
$(evid).append(cpwrap);
d.cpwrap = cpwrap;
d.ny = ny;
}
else {
var pd = 0;
if (x < d.pXMin) {
pd = -1;
}
else if (x > d.pXMax) {
pd = 1;
}
if (pd != 0) {
d.cdi = d.cdi + pd;
var ov = $("#tgOver" + d.cdi);
if (ov.length == 1) {
d.pXMin = d.pXMin + d.pw * pd;
d.pXMax = d.pXMax + d.pw * pd;
ov.append(d.cpwrap);
}
else {
d.cdi = d.cdi - pd;
}
}
ny = d.top + diffy;
var pny = ny % 21;
if (pny != 0) {
ny = ny - pny;
}
if (d.ny != ny) {
//log.info("ny=" + ny);
gh = gW(ny, ny + d.h);
//log.info("sh=" + gh.sh + ",sm=" + gh.sm);
tempdata = buildtempdayevent(gh.sh, gh.sm, gh.eh, gh.em, gh.h, data[1], false, false, data[7]);
d.cpwrap.css("top", ny + "px").html(tempdata);
}
d.ny = ny;
}
}
}
if (gh.sh == 0 || gh.eh == 23) {
dragEnd(e);
return false;
}
break;
case 5:
var data = d.data;
if (data != null && data[8] == 1) {
var sy = d.sy;
var y = e.pageY;
var diffy = y - sy;
if (diffy != 0 || d.cpwrap) {
var gh, ny, tempdata;
if (!d.cpwrap) {
gh = { sh: data[2].getHours(),
sm: data[2].getMinutes(),
eh: data[3].getHours(),
em: data[3].getMinutes(),
h: d.h
};
d.target.hide();
ny = gP(gh.sh, gh.sm);
d.top = ny;
tempdata = buildtempdayevent(gh.sh, gh.sm, gh.eh, gh.em, gh.h, data[1], "100%", true, data[7]);
var cpwrap = $("").html(tempdata);
var evid = d.target.parent().attr("id").replace("tgCol", "#tgOver");
$(evid).append(cpwrap);
d.cpwrap = cpwrap;
}
else {
nh = d.h + diffy;
var pnh = nh % 21;
nh = pnh > 1 ? nh - pnh + 21 : nh - pnh;
if (d.nh != nh) {
var sp = gP(data[2].getHours(), data[2].getMinutes());
var ep = sp + nh;
gh = gW(d.top, d.top + nh);
tempdata = buildtempdayevent(gh.sh, gh.sm, gh.eh, gh.em, gh.h, data[1], "100%", true, data[7]);
d.cpwrap.html(tempdata);
}
d.nh = nh;
}
}
if (gh.sh == 0 || gh.eh == 23) {
dragEnd(e);
return false;
}
}
break;
case 6:
var sx = d.sx;
var x = e.pageX;
var y = e.pageY;
var diffx = x - sx;
if (diffx > 5 || diffx < -5 || d.lasso) {
if (!d.lasso) {
var w1 = d.dp > 1 ? (d.pw - 4) * 1.5 : (d.pw - 4);
var cp = d.target.clone();
if (d.dp > 1) {
cp.find("div.rb-i>span").prepend("(" + d.dp + " " + i18n.xgcalendar.day_plural + ") ");
}
var cpwrap = $("").append(cp).appendTo(document.body);
d.cpwrap = cpwrap;
d.lasso = $("");
$(document.body).append(d.lasso);
cp = cpwrap = null;
}
fixcppostion(d.cpwrap, e, d.xa, d.ya);
var ndi = getdi(d.xa, d.ya, x, e.pageY);
if (!d.cdi || d.cdi.di != ndi.di) {
addlasso(d.lasso, ndi, { x: ndi.x, y: ndi.y, di: ndi.di + d.dp - 1 }, d.xa, d.ya, d.h);
}
d.cdi = ndi;
}
break;
case 7:
var sx = d.sx;
var sy = d.sy;
var x = e.pageX;
var y = e.pageY;
var diffx = x - sx;
var diffy = y - sy;
if (diffx > 5 || diffx < -5 || diffy > 5 || diffy < -5 || d.lasso) {
if (!d.lasso) {
var w1 = d.dp > 1 ? (d.pw - 4) * 1.5 : (d.pw - 4);
var cp = d.target.clone();
if (d.dp > 1) {
cp.find("div.rb-i>span").prepend("(" + d.dp + " " + i18n.xgcalendar.day_plural + ") ");
}
var cpwrap = $("").append(cp).appendTo(document.body);
d.cpwrap = cpwrap;
d.lasso = $("");
$(document.body).append(d.lasso);
cp = cpwrap = null;
}
fixcppostion(d.cpwrap, e, d.xa, d.ya);
var ndi = getdi(d.xa, d.ya, x, e.pageY);
if (!d.cdi || d.cdi.di != ndi.di) {
addlasso(d.lasso, ndi, { x: ndi.x, y: ndi.y, di: ndi.di + d.dp - 1 }, d.xa, d.ya, d.h);
}
d.cdi = ndi;
}
break;
}
}
return false;
}
function dragEnd(e) {
if (_dragdata) {
var d = _dragdata;
switch (d.type) {
case 1: //day view
var wrapid = new Date().getTime();
tp = d.target.offset().top;
if (!d.cpwrap) {
var gh = gH(d.sy, d.sy + 42, tp);
var ny = gP(gh.sh, gh.sm);
var tempdata = buildtempdayevent(gh.sh, gh.sm, gh.eh, gh.em, gh.h);
d.cpwrap = $("").html(tempdata);
$(d.target).find("div.tg-col-overlaywrapper").append(d.cpwrap);
d.cgh = gh;
}
var pos = d.cpwrap.offset();
pos.left = pos.left + 30;
d.cpwrap.attr("id", wrapid);
var start = strtodate(d.target.attr("abbr") + " " + d.cgh.sh + ":" + d.cgh.sm);
var end = strtodate(d.target.attr("abbr") + " " + d.cgh.eh + ":" + d.cgh.em);
_dragevent = function() { $("#" + wrapid).remove(); $("#bbit-cal-buddle").css("visibility", "hidden"); };
quickadd(start, end, false, pos);
break;
case 2: //week view
case 3: //month view
var source = e.srcElement || e.target;
var lassoid = new Date().getTime();
if (!d.lasso) {
if ($(source).hasClass("monthdayshow"))
{
weekormonthtoday.call($(source).parent()[0],e);
break;
}
d.fdi = d.sdi = getdi(d.xa, d.ya, d.sx, d.sy);
d.lasso = $("");
$(document.body).append(d.lasso);
addlasso(d.lasso, d.sdi, d.fdi, d.xa, d.ya, d.h);
}
d.lasso.attr("id", lassoid);
var si = Math.min(d.fdi.di, d.sdi.di);
var ei = Math.max(d.fdi.di, d.sdi.di);
var firstday = option.vstart;
var start = DateAdd("d", si, firstday);
var end = DateAdd("d", ei, firstday);
_dragevent = function() { $("#" + lassoid).remove(); };
quickadd(start, end, true, { left: e.pageX, top: e.pageY });
break;
case 4: // event moving
if (d.cpwrap) {
var start = DateAdd("d", d.cdi, option.vstart);
var end = DateAdd("d", d.cdi, option.vstart);
var gh = gW(d.ny, d.ny + d.h);
start.setHours(gh.sh, gh.sm);
end.setHours(gh.eh, gh.em);
if (start.getTime() == d.data[2].getTime() && end.getTime() == d.data[3].getTime()) {
d.cpwrap.remove();
d.target.show();
}
else {
dayupdate(d.data, start, end);
}
}
break;
case 5: //Resize
if (d.cpwrap) {
var start = new Date(d.data[2].toString());
var end = new Date(d.data[3].toString());
var gh = gW(d.top, d.top + nh);
start.setHours(gh.sh, gh.sm);
end.setHours(gh.eh, gh.em);
if (start.getTime() == d.data[2].getTime() && end.getTime() == d.data[3].getTime()) {
d.cpwrap.remove();
d.target.show();
}
else {
dayupdate(d.data, start, end);
}
}
break;
case 6:
case 7:
if (d.lasso) {
d.cpwrap.remove();
d.lasso.remove();
var start = new Date(d.data[2].toString());
var end = new Date(d.data[3].toString());
var currrentdate = DateAdd("d", d.cdi.di, option.vstart);
var diff = DateDiff("d", start, currrentdate);
start = DateAdd("d", diff, start);
end = DateAdd("d", diff, end);
if (start.getTime() != d.data[2].getTime() || end.getTime() != d.data[3].getTime()) {
dayupdate(d.data, start, end);
}
}
break;
}
d = _dragdata = null;
$('body').noSelect(false);
return false;
}
}
function getdi(xa, ya, x, y) {
var ty = 0;
var tx = 0;
var lx = 0;
var ly = 0;
if (xa && xa.length != 0) {
lx = xa.length;
if (x >= xa[lx - 1].e) {
tx = lx - 1;
}
else {
for (var i = 0; i < lx; i++) {
if (x > xa[i].s && x <= xa[i].e) {
tx = i;
break;
}
}
}
}
if (ya && ya.length != 0) {
ly = ya.length;
if (y >= ya[ly - 1].e) {
ty = ly - 1;
}
else {
for (var j = 0; j < ly; j++) {
if (y > ya[j].s && y <= ya[j].e) {
ty = j;
break;
}
}
}
}
return { x: tx, y: ty, di: ty * lx + tx };
}
function addlasso(lasso, sdi, edi, xa, ya, height) {
var diff = sdi.di > edi.di ? sdi.di - edi.di : edi.di - sdi.di;
diff++;
var sp = sdi.di > edi.di ? edi : sdi;
var ep = sdi.di > edi.di ? sdi : edi;
var l = xa.length > 0 ? xa.length : 1;
var h = ya.length > 0 ? ya.length : 1;
var play = [];
var width = xa[0].e - xa[0].s;
var i = sp.x;
var j = sp.y;
var max = Math.min(document.documentElement.clientWidth, xa[l - 1].e) - 2;
while (j < h && diff > 0) {
var left = xa[i].s;
var d = i + diff > l ? l - i : diff;
var wid = width * d;
while (left + wid >= max) {
wid--;
}
play.push(Tp(__LASSOTEMP, { left: left, top: ya[j].s, height: height, width: wid }));
i = 0;
diff = diff - d;
j++;
}
lasso.html(play.join(""));
}
function fixcppostion(cpwrap, e, xa, ya) {
var x = e.pageX - 6;
var y = e.pageY - 4;
var w = cpwrap.width();
var h = 21;
var lmin = xa[0].s + 6;
var tmin = ya[0].s + 4;
var lmax = xa[xa.length - 1].e - w - 2;
var tmax = ya[ya.length - 1].e - h - 2;
if (x > lmax) {
x = lmax;
}
if (x <= lmin) {
x = lmin + 1;
}
if (y <= tmin) {
y = tmin + 1;
}
if (y > tmax) {
y = tmax;
}
cpwrap.css({ left: x, top: y });
}
$(document)
.mousemove(dragMove)
.mouseup(dragEnd);
//.mouseout(dragEnd);
var c = {
sv: function(view) { //switch view
if (view == option.view) {
return;
}
clearcontainer();
option.view = view;
render();
dochange();
},
rf: function() {
populate();
},
gt: function(d) {
if (!d) {
d = new Date();
}
option.showday = d;
render();
dochange();
},
pv: function() {
switch (option.view) {
case "day":
option.showday = DateAdd("d", -1, option.showday);
break;
case "week":
option.showday = DateAdd("w", -1, option.showday);
break;
case "month":
option.showday = DateAdd("m", -1, option.showday);
break;
}
render();
dochange();
},
nt: function() {
switch (option.view) {
case "day":
option.showday = DateAdd("d", 1, option.showday);
break;
case "week":
option.showday = DateAdd("w", 1, option.showday);
break;
case "month":
var od = option.showday.getDate();
option.showday = DateAdd("m", 1, option.showday);
var nd = option.showday.getDate();
if(od !=nd) //we go to the next month
{
option.showday= DateAdd("d", 0-nd, option.showday); //last day of last month
}
break;
}
render();
dochange();
},
go: function() {
return option;
},
so: function(p) {
option = $.extend(option, p);
}
};
this[0].bcal = c;
return this;
};
/**
* @description {Method} swtichView To switch to another view.
* @param {String} view View name, one of 'day', 'week', 'month'.
*/
$.fn.swtichView = function(view) {
return this.each(function() {
if (this.bcal) {
this.bcal.sv(view);
}
})
};
/**
* @description {Method} reload To reload event of current time range.
*/
$.fn.reload = function() {
return this.each(function() {
if (this.bcal) {
this.bcal.rf();
}
})
};
/**
* @description {Method} gotoDate To go to a range containing date.
* If view is week, it will go to a week containing date.
* If view is month, it will got to a month containing date.
* @param {Date} date. Date to go.
*/
$.fn.gotoDate = function(d) {
return this.each(function() {
if (this.bcal) {
this.bcal.gt(d);
}
})
};
/**
* @description {Method} previousRange To go to previous date range.
* If view is week, it will go to previous week.
* If view is month, it will got to previous month.
*/
$.fn.previousRange = function() {
return this.each(function() {
if (this.bcal) {
this.bcal.pv();
}
})
};
/**
* @description {Method} nextRange To go to next date range.
* If view is week, it will go to next week.
* If view is month, it will got to next month.
*/
$.fn.nextRange = function() {
return this.each(function() {
if (this.bcal) {
this.bcal.nt();
}
})
};
$.fn.BcalGetOp = function() {
if (this[0].bcal) {
return this[0].bcal.go();
}
return null;
};
$.fn.BcalSetOp = function(p) {
if (this[0].bcal) {
return this[0].bcal.so(p);
}
};
})(jQuery);
function prepareBalloon(data, eventId, options) {
var buddle = $("#bbit-cal-buddle");
if (buddle.length > 0) {
$("#bbit-cal-buddle").remove();
}
var temparr = [];
temparr.push('
');
temparr.push('
');
temparr.push('
');
temparr.push('
');
if (data[11] == '') {
temparr.push('Il giorno ', formatDate(data[2]), ' dalle ', formatTime(data[2]), ' alle ', formatTime(data[3]), '');
if (data[14] == '') {
temparr.push(', il collaboratore ', '', data[18], '', '');
} else {
temparr.push(', la camera di conciliazione ', '', data[15], '', '');
temparr.push(', presso la Sede ', '', data[13], '', '');
if (data[9] != "") {
temparr.push(' in ', data[9], '');
}
}
temparr.push(', non è disponibile');
//Motivazioni
if (data[16] != "") {
temparr.push(' per il seguente motivo: ', data[16]);
}
temparr.push('.');
temparr.push(' ');
if (!options.readonly) {
temparr.push('');
}
} else {
temparr.push('Il giorno ', formatDate(data[2]), ' dalle ', formatTime(data[2]), ' alle ', formatTime(data[3]), '');
temparr.push(', presso la Sede ', '', data[13], '', '');
if (data[9] != "") {
temparr.push(' in ', data[9], '');
}
temparr.push(', nella camera di conciliazione ', '', data[15], '', '');
temparr.push(', si tiene un incontro per la pratica di ', '', 'mediazione n° ', data[19], '', '');
}
temparr.push('