1 function wdcal_edit_getStartEnd() {
4 var start = $("#cal_start_date").datepicker("getDate");
5 var start_time = $.timePicker("#cal_start_time").getTime();
6 start.setHours(start_time.getHours());
7 start.setMinutes(start_time.getMinutes());
9 var end = $("#cal_end_date").datepicker("getDate");
10 var end_time = $.timePicker("#cal_end_time").getTime();
11 end.setHours(end_time.getHours());
12 end.setMinutes(end_time.getMinutes());
14 return {"start": start, "end": end};
17 function wdcal_edit_checktime_startChanged() {
20 var time = wdcal_edit_getStartEnd();
21 if (time.start.getTime() >= time.end.getTime()) {
22 var newend = new Date(time.start.getTime() + 3600000);
23 $("#cal_end_date").datepicker("setDate", newend);
24 $.timePicker("#cal_end_time").setTime(newend);
26 wdcal_edit_recur_recalc();
29 function wdcal_edit_checktime_endChanged() {
32 var time = wdcal_edit_getStartEnd();
33 if (time.start.getTime() >= time.end.getTime()) {
34 var newstart = new Date(time.end.getTime() - 3600000);
35 $("#cal_start_date").datepicker("setDate", newstart);
36 $.timePicker("#cal_start_time").setTime(newstart);
40 function wdcal_edit_recur_recalc() {
43 var start = $("#cal_start_date").datepicker("getDate");
44 $(".rec_month_name").text($.datepicker._defaults.monthNames[start.getMonth()]);
45 $("#rec_yearly_day option[value=bymonthday]").text($("#rec_yearly_day option[value=bymonthday]").data("orig").replace("#num#", start.getDate()));
46 $("#rec_monthly_day option[value=bymonthday]").text($("#rec_monthly_day option[value=bymonthday]").data("orig").replace("#num#", start.getDate()));
47 var month = new Date(start.getFullYear(), start.getMonth() + 1, 0);
48 var monthlast = month.getDate() - start.getDate() + 1;
49 $("#rec_yearly_day option[value=bymonthday_neg]").text($("#rec_yearly_day option[value=bymonthday_neg]").data("orig").replace("#num#", monthlast));
50 $("#rec_monthly_day option[value=bymonthday_neg]").text($("#rec_monthly_day option[value=bymonthday_neg]").data("orig").replace("#num#", monthlast));
51 var wk = Math.ceil(start.getDate() / 7);
52 var wkname = $.datepicker._defaults.dayNames[start.getDay()];
53 $("#rec_yearly_day option[value=byday]").text($("#rec_yearly_day option[value=byday]").data("orig").replace("#num#", wk).replace("#wkday#", wkname));
54 $("#rec_monthly_day option[value=byday]").text($("#rec_monthly_day option[value=byday]").data("orig").replace("#num#", wk).replace("#wkday#", wkname));
55 var wk_inv = Math.ceil(monthlast / 7);
56 $("#rec_yearly_day option[value=byday_neg]").text($("#rec_yearly_day option[value=byday_neg]").data("orig").replace("#num#", wk_inv).replace("#wkday#", wkname));
57 $("#rec_monthly_day option[value=byday_neg]").text($("#rec_monthly_day option[value=byday_neg]").data("orig").replace("#num#", wk_inv).replace("#wkday#", wkname));
60 function wdcal_edit_init(dateFormat, base_path) {
63 $("#cal_color").colorPicker();
64 $("#color_override").on("click", function() {
65 if ($("#color_override").prop("checked")) $("#cal_color_holder").show();
66 else $("#cal_color_holder").hide();
69 $("#cal_start_time").timePicker({ step: 15 }).on("change", wdcal_edit_checktime_startChanged);
70 $("#cal_end_time").timePicker().on("change", wdcal_edit_checktime_endChanged);
72 $("#cal_start_date").datepicker({
73 "dateFormat": dateFormat
74 }).on("change", wdcal_edit_checktime_startChanged);
75 $("#cal_end_date").datepicker({
76 "dateFormat": dateFormat
77 }).on("change", wdcal_edit_checktime_endChanged);
79 $("#rec_until_date").datepicker({ "dateFormat": dateFormat });
81 $("#notification").on("click change", function() {
82 if ($(this).prop("checked")) $("#notification_detail").show();
83 else ($("#notification_detail")).hide();
86 $("#cal_allday").on("click change", function() {
87 if ($(this).prop("checked")) $("#cal_end_time, #cal_start_time").hide();
88 else $("#cal_end_time, #cal_start_time").show();
91 $("#rec_frequency").on("click change", function() {
92 var val = $("#rec_frequency").val();
93 if (val == "") $("#rec_details").hide();
94 else $("#rec_details").show();
96 if (val == "daily") $(".rec_daily").show();
97 else $(".rec_daily").hide();
99 if (val == "weekly") $(".rec_weekly").show();
100 else $(".rec_weekly").hide();
102 if (val == "monthly") $(".rec_monthly").show();
103 else $(".rec_monthly").hide();
105 if (val == "yearly") $(".rec_yearly").show();
106 else $(".rec_yearly").hide();
109 $("#rec_until_type").on("click change", function() {
110 var val = $("#rec_until_type").val();
112 if (val == "count") $("#rec_until_count").show();
113 else $("#rec_until_count").hide();
115 if (val == "date") $("#rec_until_date").show();
116 else $("#rec_until_date").hide();
119 $("#rec_yearly_day option, #rec_monthly_day option").each(function() {
120 $(this).data("orig", $(this).text());
123 $("#new_alarm_adder a").click(function(ev) {
124 $("#new_alarm").val("1");
125 $("#noti_new_row").show();
126 $("#new_alarm_adder").hide();
130 wdcal_edit_recur_recalc();
132 $(document).on("click", ".exception_remover", function(ev) {
135 $par = $this.parents(".rec_exceptions");
136 $this.parents(".except").remove();
137 if ($par.find(".rec_exceptions_holder").children().length == 0) {
138 $par.find(".rec_exceptions_holder").hide();
139 $par.find(".rec_exceptions_none").show();
143 $(".exception_adder").click(function(ev) {
147 $(".rec_exceptions .except input").each(function() {
148 exceptions.push($(this).val());
150 var rec_weekly_byday = [];
151 $(".rec_weekly_byday:checked").each(function() {
152 rec_weekly_byday.push($(this).val());
154 var rec_daily_byday = [];
155 $(".rec_daily_byday:checked").each(function() {
156 rec_daily_byday.push($(this).val());
159 "start_date": $("input[name=start_date]").val(),
160 "start_time": $("input[name=start_time]").val(),
161 "end_date": $("input[name=end_date]").val(),
162 "end_time": $("input[name=end_time]").val(),
163 "rec_frequency": $("#rec_frequency").val(),
164 "rec_interval": $("#rec_interval").val(),
165 "rec_until_type": $("#rec_until_type").val(),
166 "rec_until_count": $("#rec_until_count").val(),
167 "rec_until_date": $("#rec_until_date").val(),
168 "rec_weekly_byday": rec_weekly_byday,
169 "rec_daily_byday": rec_daily_byday,
170 "rec_weekly_wkst": $("input[name=rec_weekly_wkst]:checked").val(),
171 "rec_monthly_day": $("#rec_monthly_day").val(),
172 "rec_yearly_day": $("#rec_yearly_day").val(),
173 "rec_exceptions": exceptions
175 if ($("#cal_allday").prop("checked")) opts["allday"] = 1;
176 var $dial = $("<div id='exception_setter_dialog'>Loading...</div>");
177 $dial.appendTo("body");
181 "title": "Exceptions"
183 $dial.load(base_path + "getExceptionDates/", opts, function() {
184 $dial.find(".exception_selector_link").click(function(ev2) {
185 ev2.preventDefault();
186 var ts = $(this).data("timestamp");
187 var str = $(this).html();
188 var $part = $("<div data-timestamp='" + ts + "' class='except'><input type='hidden' class='rec_exception' name='rec_exceptions[]' value='" + ts + "'><a href='#' class='exception_remover'>[remove]</a> " + str + "</div>");
190 $(".rec_exceptions_holder .except").each(function() {
191 if (!found && ts < $(this).data("timestamp")) {
193 $part.insertBefore(this);
196 if (!found) $(".rec_exceptions_holder").append($part);
197 $(".rec_exceptions .rec_exceptions_holder").show();
198 $(".rec_exceptions .rec_exceptions_none").hide();
200 $dial.dialog("destroy").remove();
207 function wdcal_edit_calendars_start(dateFormat, base_path) {
210 $(".cal_color").colorPicker();
212 $(".delete_cal").click(function(ev) {
213 if (!confirm("Do you really want to delete this calendar? All events will be moved to another private calendar.")) ev.preventDefault();
216 $(".calendar_add_caller").click(function(ev) {
217 $(".cal_add_row").show();
218 $(this).parents("div").hide();