My favorites | Sign in
Project Home Issues
New issue   Search
for
  Advanced search   Search tips   Subscriptions

Issue 601 attachment: schedulingcalendar-example.txt (9.0 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
$('#calendar1').fullCalendar({
header: {
left: 'none',
center: 'title',
right: 'none'
},
defaultView: 'month',
timeFormat: 'h:mmt{ - h:mm}t',
allDay: false,
events: MyEvents,
eventClick: function(event) {
var month_value = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");
var start = new Date(event.start);
var end = new Date(event.end);
alert(start + " " + end);

$('#EditTitle').val(event.title);
$('#EditStart').val(month_value[start.getMonth()] + '/' + ((start.getDate() < 10 ? '0' : '') + start.getDate()) + '/' + start.getFullYear() + ' ' + start.toLocaleTimeString().toLowerCase());
$('#EditStop').val(month_value[end.getMonth()] + '/' + ((end.getDate() < 10 ? '0' : '') + end.getDate()) + '/' + end.getFullYear() + ' ' + end.toLocaleTimeString().toLowerCase());

$('#tblEdit').show();
TriggerCalendarForDateTimeExisting();
$('#dialogEdit').dialog('open');
return false; //should stop dialog from jump
},
eventRender: function(event, element) {
$('*').qtip('hide');
element.qtip({
content: event.title + '<br/>' + event.duration + '<br/>' + event.repeat,
show: 'mouseover',
hide: 'mouseout',
style: {
classes: 'ui-tooltip-custom',
tip: true
},
position: {
my: 'left bottom',
at: 'top right'
}
});
},
lazyFetching: true
});


function MyEvents(start, end, callback) {
$.ajax({
type: "Get",
dataType: "json",
url: "/portal/Alarms/CalendarData?scheduleid=<%=Model.ScheduleId %>",
success: function(data) {
if (data.length == 0 || data.length == null) return;

var maxEnd = new Date();
maxEnd.setFullYear(maxEnd.getFullYear() + 1);

var sUnixToLocal = new Date((data[0].start) * 1000);
var eUnixToLocal = new Date((data[0].end) * 1000);

//==========Calculate Repeat===========//
var oneDay = 1000 * 60 * 60 * 24;
var date1 = sUnixToLocal.getTime();
var date2 = eUnixToLocal.getTime();
var difference = Math.abs(date1 - date2);
var days = Math.abs(difference / oneDay);

//==========Calculate Duration========//
//add days to a date to get a new date (2 days for your schedule)
//then add another 5 days (to complete the week) to start the repeat.
//Compare that date to your end date to see if you've finished.

var events = [];

var startDateTime = new Date(sUnixToLocal.getFullYear(), sUnixToLocal.getMonth(), sUnixToLocal.getDate(),
sUnixToLocal.getHours(),
sUnixToLocal.getMinutes(),
sUnixToLocal.getSeconds(),
sUnixToLocal.getMilliseconds());

var endDateTime = new Date(eUnixToLocal.getFullYear(), eUnixToLocal.getMonth(), eUnixToLocal.getDate(),
eUnixToLocal.getHours(),
eUnixToLocal.getMinutes(),
eUnixToLocal.getSeconds(),
eUnixToLocal.getMilliseconds());

for (var i = 0; i < data.length; i++) {
while (startDateTime <= maxEnd) {
if ((data[i].repeat == "" || data[i].repeat == null) && (data[i].duration == "" || data[i].duration == null)) {
var endDate = new Date();
endDate.setDate(startDateTime.getDate() + days);
endDate.setHours(endDateTime.getHours(), endDateTime.getMinutes(), endDateTime.getSeconds());

events.push({
id: data[i].id,
scheduleid: data[i].scheduleid,
title: data[i].title,
start: new Date(startDateTime.valueOf()),
end: endDate,
repeat: data[i].repeat,
duration: data[i].duration,
allDay: false
});
var repeatVal = CheckRepeat(data[i].repeat);
var durationVal = CheckDuration(data[i].duration);
GetScheduleRepeat(repeatVal, startDateTime);
}
else if ((data[i].repeat != "" || data[i].repeat != null) && (data[i].duration == "" || data[i].duration == null)) {
var endDate = new Date();
endDate.setFullYear(startDateTime.getFullYear().valueOf());
endDate.setMonth(startDateTime.getMonth().valueOf());
endDate.setDate(startDateTime.getDate() + days);
endDate.setHours(endDateTime.getHours(), endDateTime.getMinutes(), endDateTime.getSeconds());

events.push({
id: data[i].id,
scheduleid: data[i].scheduleid,
title: data[i].title,
start: new Date(startDateTime.valueOf()),
end: endDate,
repeat: data[i].repeat,
duration: data[i].duration,
allDay: false
});
var repeatVal = CheckRepeat(data[i].repeat);
var durationVal = CheckDuration(data[i].duration);
GetScheduleRepeat(repeatVal, startDateTime);
}
else {
var durationVal = CheckDuration(data[i].duration);
var endDate = new Date();
endDate.setFullYear(startDateTime.getFullYear().valueOf());
endDate.setMonth(startDateTime.getMonth().valueOf());
endDate.setDate(startDateTime.getDate() + durationVal);
endDate.setHours(endDateTime.getHours(), endDateTime.getMinutes(), endDateTime.getSeconds());

events.push({
id: data[i].id,
scheduleid: data[i].scheduleid,
title: data[i].title,
start: new Date(startDateTime.valueOf()),
end: endDate,
repeat: data[i].repeat,
duration: data[i].duration,
allDay: false
});
var repeatVal = CheckRepeat(data[i].repeat);
GetScheduleRepeat(repeatVal, startDateTime);
}
}
}
callback(events);
}
});
}

function CheckRepeat(repeat) {
if (repeat == "") return 0;
if (repeat == "Every 1 Week") return 7;
if (repeat == "Every 2 Weeks") return 14;
if (repeat == "Every 3 Weeks") return 21;
if (repeat == "Every 4 Weeks") return 28;
if (repeat == "Every 5 Weeks") return 35;
if (repeat == "Every 6 Weeks") return 42;
if (repeat == "Every 7 Weeks") return 49;
if (repeat == "Every 8 Weeks") return 56;
if (repeat == "Every 9 Weeks") return 63;
if (repeat == "Every 1 Year") return 365;
}

function CheckDuration(duration) {
if (duration == "") return 0;
if (duration == "1 day") return 0;
if (duration == "2 days") return 1;
if (duration == "3 days") return 2;
if (duration == "4 days") return 3;
if (duration == "5 days") return 4;
if (duration == "6 days") return 5;
if (duration == "1 week") return 6;
if (duration == "2 weeks") return 13;
if (duration == "3 weeks") return 20;
}

function GetScheduleRepeat(repeatVal, startDateTime) {
if (repeatVal == 0)
startDateTime.setDate(startDateTime);
else {
startDateTime.setDate(startDateTime.getDate() + repeatVal);
}
}

Powered by Google Project Hosting