]> git.mxchange.org Git - friendica-addons.git/blob - dav/common/wdcal.js
Move StatusNet addon dependencies in own library subfolder
[friendica-addons.git] / dav / common / wdcal.js
1 function wdcal_edit_getStartEnd() {
2         "use strict";
3
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());
8
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());
13
14         return {"start": start, "end": end};
15 }
16
17 function wdcal_edit_checktime_startChanged() {
18         "use strict";
19
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);
25         }
26         wdcal_edit_recur_recalc();
27 }
28
29 function wdcal_edit_checktime_endChanged() {
30         "use strict";
31
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);
37         }
38 }
39
40 function wdcal_edit_recur_recalc() {
41         "use strict";
42
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));
58 }
59
60 function wdcal_edit_init(dateFormat, base_path) {
61         "use strict";
62
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();
67         });
68
69         $("#cal_start_time").timePicker({ step: 15 }).on("change", wdcal_edit_checktime_startChanged);
70         $("#cal_end_time").timePicker().on("change", wdcal_edit_checktime_endChanged);
71
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);
78
79         $("#rec_until_date").datepicker({ "dateFormat": dateFormat });
80
81         $("#notification").on("click change", function() {
82                 if ($(this).prop("checked")) $("#notification_detail").show();
83                 else ($("#notification_detail")).hide();
84         }).change();
85
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();
89         }).change();
90
91         $("#rec_frequency").on("click change", function() {
92                 var val = $("#rec_frequency").val();
93                 if (val == "") $("#rec_details").hide();
94                 else $("#rec_details").show();
95
96                 if (val == "daily") $(".rec_daily").show();
97                 else $(".rec_daily").hide();
98
99                 if (val == "weekly") $(".rec_weekly").show();
100                 else $(".rec_weekly").hide();
101
102                 if (val == "monthly") $(".rec_monthly").show();
103                 else $(".rec_monthly").hide();
104
105                 if (val == "yearly") $(".rec_yearly").show();
106                 else $(".rec_yearly").hide();
107         }).change();
108
109         $("#rec_until_type").on("click change", function() {
110                 var val = $("#rec_until_type").val();
111
112                 if (val == "count") $("#rec_until_count").show();
113                 else $("#rec_until_count").hide();
114
115                 if (val == "date") $("#rec_until_date").show();
116                 else $("#rec_until_date").hide();
117         }).change();
118
119         $("#rec_yearly_day option, #rec_monthly_day option").each(function() {
120                 $(this).data("orig", $(this).text());
121         });
122
123         $("#new_alarm_adder a").click(function(ev) {
124                 $("#new_alarm").val("1");
125                 $("#noti_new_row").show();
126                 $("#new_alarm_adder").hide();
127                 ev.preventDefault();
128         });
129
130         wdcal_edit_recur_recalc();
131
132         $(document).on("click", ".exception_remover", function(ev) {
133                 ev.preventDefault();
134                 var $this = $(this),
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();
140                 }
141         });
142
143         $(".exception_adder").click(function(ev) {
144                 ev.preventDefault();
145
146                 var exceptions = [];
147                 $(".rec_exceptions .except input").each(function() {
148                         exceptions.push($(this).val());
149                 });
150                 var rec_weekly_byday = [];
151                 $(".rec_weekly_byday:checked").each(function() {
152                         rec_weekly_byday.push($(this).val());
153                 });
154                 var rec_daily_byday = [];
155                 $(".rec_daily_byday:checked").each(function() {
156                         rec_daily_byday.push($(this).val());
157                 });
158                 var opts = {
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
174                 };
175                 if ($("#cal_allday").prop("checked")) opts["allday"] = 1;
176                 var $dial = $("<div id='exception_setter_dialog'>Loading...</div>");
177                 $dial.appendTo("body");
178                 $dial.dialog({
179                         "width": 400,
180                         "height": 300,
181                         "title": "Exceptions"
182                 });
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>");
189                                 var found = false;
190                                 $(".rec_exceptions_holder .except").each(function() {
191                                         if (!found && ts < $(this).data("timestamp")) {
192                                                 found = true;
193                                                 $part.insertBefore(this);
194                                         }
195                                 });
196                                 if (!found) $(".rec_exceptions_holder").append($part);
197                                 $(".rec_exceptions .rec_exceptions_holder").show();
198                                 $(".rec_exceptions .rec_exceptions_none").hide();
199
200                                 $dial.dialog("destroy").remove();
201                         })
202                 });
203         });
204 }
205
206
207 function wdcal_edit_calendars_start(dateFormat, base_path) {
208         "use strict";
209
210         $(".cal_color").colorPicker();
211
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();
214         });
215
216         $(".calendar_add_caller").click(function(ev) {
217                 $(".cal_add_row").show();
218                 $(this).parents("div").hide();
219                 ev.preventDefault();
220         });
221 }