PageSourceSearch

https://www.sanantoniomag.com/wp-content/plugins/event-calendar-pr…/js/vendor/event-recurrence.js?ver=1.0.5

js sanantoniomag.com collected 2026-10-01 10:43:54 UTC 12,827 bytes, 412 lines download raw bytes

1function showRecurChoices(radio) {
2	var choices = new Array("daily","weekly","monthly","yearly");
3	var div;
4	//hide all the recurrence divs
5	for(var i = 0; i < choices.length; i++) {
6		div = document.getElementById(choices[i] + 'div');
7		if (div)
8			div.style.display='none';
9	}
10	//show the div that corresponds to the passed in radio button
11	div = document.getElementById(radio.id + 'div');
12	if(div && radio.checked) {
13		div.style.display = 'block';
14	}
15}
16/**
17 * hides the recurring options div
18 */
19function hideRecurringChoices()
20{
21	var div=document.getElementById('recurringdiv');
22	div.style.display='none';
23
24}
25
26/**
27 * displays the recurring options div
28 */
29function showRecurringChoices()
30{
31	var div=document.getElementById('recurringdiv');
32	div.style.display = 'block';
33
34}
35
36/**
37 * On page refresh, detect if any of the recurring
38 * radio buttons have been previously selected and
39 * restore the state.
40 *
41 */
42function initRecurringChoices() {
43	var checkedRecurrence = null;
44	var radioButtons = document.getElementsByName("params[eventtype]");
45	for (var i = 0, len = radioButtons.length; i < len; i++) {
46		if (radioButtons[i].checked == true) {
47			checkedRecurrence = radioButtons[i];
48			break;
49		}
50	}
51	if (checkedRecurrence == null) {
52		checkedRecurrence = radioButtons[0];
53		radioButtons[0].checked = true;
54	}
55	if (checkedRecurrence.id == "recurring") {
56		setRecurringChoice();
57	} else {
58		showRecurChoices(null);
59		hideRecurringChoices();
60	}
61}
62
63/**
64 * If the recurring button is checked on page refresh, or if the
65 * recurring button is pressed, restore any previously checked
66 * sub-radio button and its choices.
67 *
68 */
69function setRecurringChoice() {
70	var checkedRecurType = null;
71	var radioButtons = document.getElementsByName("params[recurtype]")
72	for (i = 0, len = radioButtons.length; i < len; i++) {
73		if (radioButtons[i].checked == true) {
74			checkedRecurType = radioButtons[i];
75			break;
76		}
77	}
78	showRecurringChoices();
79	if (checkedRecurType != null) {
80		showRecurChoices(checkedRecurType);
81	}
82}
83
84/**
85 * input form validation function.
86 * @formname - the name of the form to validate
87 * @buttonname - the name of the button that is used to trigger form submission.
88 */
89function doFormPost(formname,buttonname) {
90	var msg='';
91	//event datetime validation
92	if("save,apply,update,savenew".indexOf(buttonname)>=0) {
93		var once = document.getElementById('once');
94		var recur = document.getElementById('recurring');
95		//check to see if event type (one|recurring) was selected
96
97		if((once != null && recur != null) && ( !once.checked && !recur.checked))
98			msg+='You must select either One Time Event or Recurring Event';
99		//validate date input fields for one-time events
100		if(once && once.checked) {
101			msg += _checkdate();
102		}
103
104		var  categoriesRequired = document.getElementById('calendarevent_categoriesrequired');
105		if (categoriesRequired && 'true' == categoriesRequired.value) {
106			msg += _checkAtLeastOneCategorySelected();
107		}
108		//recurring event validation
109		if(recur && recur.checked) {
110			var daily = document.getElementById("daily");
111			var weekly = document.getElementById("weekly");
112			var monthly = document.getElementById("monthly");
113			var yearly = document.getElementById("yearly");
114			//check if reocurrence type (daily|monthy..) was selected
115			if((daily && weekly && monthly && yearly) && (!daily.checked && !weekly.checked && !monthly.checked && !yearly.checked)) {
116				msg += "You must select either 'daily', 'weekly', 'monthly', or 'yearly' as a recurring event mode.\n";
117				daily.focus();
118			}
119			if (daily.checked) { //check daily recurrence
120				msg += _checkDailyRecurrence();
121			} else if (weekly.checked) { //check weekly recurrence
122				msg += _checkWeeklyRecurrence();
123			} else if (monthly.checked) { //check monthly recurrence
124				msg += _checkMonthlyRecurrence();
125			} else if(yearly.checked) { //check yearly recurrence
126				msg += _checkYearlyRecurrence();
127			}
128			//lastly, check the recurrence dates
129			msg += _checkdate();
130		} //end recurring event validation
131
132
133		msg += _checkTitle();
134		//msg += _checkDescription();
135		if(msg != '') {
136			alert(msg);
137			return false;
138		}
139		return autocheck(document.getElementById(formname));
140	} //end event datetime validation
141	return true;
142}
143
144//------------------------------------------------------------------------------
145// internal functions
146//------------------------------------------------------------------------------
147
148
149// @todo: Replace all of this from these specialized functions to generic functions
150// @todo: Port over to jQuery and simplify code
151/**
152 * get the title and trim the result.
153 * this does NOT affect the saved result, just what we are testing.
154 *
155 *
156 * @returns {String}
157 */
158function _checkTitle() {
159	if(rjQuery("#ops_calendarevent_title").val().trim().length == 0){
160		return "Event Title is required.\n";
161	}
162	return "";
163}
164
165/*
166 * @see doFormPost();
167 */
168function _checkDailyRecurrence() {
169	var msg = "";
170	var daily_daily = document.getElementById('daily_daily');
171	var daily_ndays = document.getElementById('daily_ndays');
172	var daily_weekdays = document.getElementById('daily_weekdays');
173	if (daily_daily && daily_weekdays && (!daily_daily.checked && !daily_weekdays.checked)) {
174		msg += "You must select a daily recurrence pattern.\n";
175		daily_daily.focus();
176	}
177	if (daily_daily && daily_ndays && daily_daily.checked) {
178		var daily_ndays_val = daily_ndays.value;
179		if (daily_ndays_val) {
180			daily_ndays_val = parseInt(daily_ndays_val, 10);
181			if (isNaN(daily_ndays_val) || daily_ndays_val < 1) {
182				msg += "You must specify a valid interval for daily event recurrence.\n";
183				daily_ndays.focus();
184			} else {
185				daily_ndays.value = daily_ndays_val;
186			}
187		}
188	}
189	return msg;
190}
191
192/*
193 * @see doFormPost();
194 */
195function _checkWeeklyRecurrence() {
196	var msg = "";
197	var i = 0;
198	var weekly_nweeks = document.getElementById('weekly_nweeks');
199	if (weekly_nweeks) {
200
201		var weekly_nweeks_val = parseInt(weekly_nweeks.value, 10);
202		if (isNaN(weekly_nweeks_val) || weekly_nweeks_val < 1) {
203
204			msg += "You must specify a valid interval for weekly event recurrence.\n";
205			weekly_nweeks.focus();
206		} else {
207			weekly_nweeks.value = weekly_nweeks_val;
208		}
209	}
210	var weekdays = document.getElementsByName("params[weekly_weekdays][]");
211	if (weekdays) {
212		var isWeekdayChecked = false;
213		for(i = 0; i < weekdays.length; i++) {
214			if(weekdays[i].checked) {
215				isWeekdayChecked = true;
216				break;
217			}
218		}
219		if (!isWeekdayChecked) {
220			msg += "You must specify at least one weekday for weekly event recurrence.\n";
221			weekdays[0].focus();
222		}
223	}
224	return msg;
225}
226/*
227 * @see doFormPost();
228 */
229function _checkMonthlyRecurrence() {
230	var msg = "";
231	var i = 0;
232	var monthly_recurdom = document.getElementById("monthly_recurdom");
233	var monthly_recurnday = document.getElementById("monthly_recurnday");
234	if (monthly_recurdom && monthly_recurnday && (!monthly_recurdom.checked && !monthly_recurnday.checked)) {
235		msg += "You must select a monthly recurrence pattern.\n";
236		monthly_recurdom.focus();
237	}
238	if (monthly_recurdom.checked) {
239		var monthly_recurdom_day = document.getElementById("monthly_recurdom_day");
240		if (monthly_recurdom_day) {
241			var monthly_recurdom_day_val = parseInt(monthly_recurdom_day.value,10);
242			if (isNaN(monthly_recurdom_day_val) || monthly_recurdom_day_val < 1 || monthly_recurdom_day_val > 31) {
243				msg += "You must specify a valid day-of-month for monthly event recurrence.\n";
244				monthly_recurdom_day.focus();
245			} else {
246				monthly_recurdom_day.value = monthly_recurdom_day_val;
247			}
248		}
249		var monthly_recurdom_month = document.getElementById("monthly_recurdom_month");
250		if (monthly_recurdom_month) {
251			var monthly_recurdom_month_val = parseInt(monthly_recurdom_month.value, 10);
252			if (isNaN(monthly_recurdom_month_val) || monthly_recurdom_month_val < 1) {
253				msg += "You must specify a valid month value for monthly event recurrence.\n";
254				monthly_recurdom_month.focus();
255			} else {
256				monthly_recurdom_month.value = monthly_recurdom_month_val;
257			}
258		}
259	} else if (monthly_recurnday.checked) {
260		var monthly_recurnday_interval  = document.getElementsByName("params[monthly_interval][]");
261		if (monthly_recurnday_interval) {
262			var isIntervalChecked = false;
263			for(i = 0; i < monthly_recurnday_interval.length; i++) {
264				if(monthly_recurnday_interval[i].checked) {
265					isIntervalChecked = true;
266					break;
267				}
268			}
269			if (!isIntervalChecked) {
270				msg += "You must select at least one interval (first, second, fourth, ...) for monthly event recurrence.\n";
271				monthly_recurnday_interval[0].focus();
272			}
273		}
274		var monthly_recurnday_weekdays  = document.getElementsByName("params[monthly_weekdays][]");
275		if (monthly_recurnday_weekdays) {
276			var isWeekdayChecked = false;
277			for(i = 0; i < monthly_recurnday_weekdays.length; i++) {
278				if(monthly_recurnday_weekdays[i].checked) {
279					isWeekdayChecked = true;
280					break;
281				}
282			}
283			if (!isWeekdayChecked) {
284				msg += "You must select at least one week day for monthly event recurrence.\n";
285				monthly_recurnday_weekdays[0].focus();
286			}
287		}
288		var monthly_recurnday_months  = document.getElementsByName("params[monthly_months][]");
289		if (monthly_recurnday_months) {
290			var isMonthChecked = false;
291			for(i = 0; i < monthly_recurnday_months.length; i++) {
292				if(monthly_recurnday_months[i].checked) {
293					isMonthChecked = true;
294					break;
295				}
296			}
297			if (!isMonthChecked) {
298				msg += "You must select at least one month for monthly event recurrence.\n";
299				monthly_recurnday_months[0].focus();
300			}
301		}
302	}
303	return msg;
304}
305/**
306 * @see doFormPost();
307 */
308function _checkYearlyRecurrence() {
309	var msg = "";
310	var yearly_recurdom = document.getElementById("yearly_recurdom");
311	var yearly_recurdoy = document.getElementById("yearly_recurdoy");
312	if (yearly_recurdom && yearly_recurdoy && (!yearly_recurdom.checked && !yearly_recurdoy.checked)) {
313		msg += "You must select a yearly recurrence pattern.\n";
314		yearly_recurdom.focus();
315	}
316	if (yearly_recurdom.checked){
317		var yearly_recurdom_day = document.getElementById("yearly_day");
318		if (yearly_recurdom_day) {
319			var yearly_recurdom_day_var = parseInt(yearly_recurdom_day.value);
320			if (isNaN(yearly_recurdom_day_var) || yearly_recurdom_day_var < 1 || yearly_recurdom_day_var > 31) {
321				msg += "You must specify a valid day-of-month for yearly event recurrence.\n";
322				yearly_recurdom_day.focus();
323			} else {
324				yearly_recurdom_day.value = yearly_recurdom_day_var;
325			}
326		}
327		var yearly_recurdom_month = document.getElementById("yearly_dommonth");
328		if (!yearly_recurdom_month) {
329			msg += "You must select a month for yearly event recurrence.\n";
330			yearly_recurdom_month.focus();
331		}
332	} else if (yearly_recurdoy.checked) {
333		var yearly_recurdoy_month = document.getElementById("yearly_doymonth");
334		if(yearly_recurdoy_month && yearly_recurdoy_month.selectedIndex <= 0) {
335			msg += "You must select a month for yearly event recurrence.\n";
336			yearly_recurdoy_month.focus();
337		}
338	}
339	return msg;
340}
341
342
343function _y2k(number) {
344	return (number < 1000) ? number + 1900 : number;
345}
346
347function _checkdate() {
348	var msg = '';
349	var startdate = document.getElementById('startdate');
350	var enddate = document.getElementById('enddate');
351	//check if start date is present and valid
352	if (startdate) {
353		var startTs = Date.parse(startdate.value.replace(/-/g,'/'));
354		if (isNaN(startTs)) {
355			return "You must enter full and valid Start Date.\n";
356		}
357	} else {
358		return "You must enter full and valid Start Date.\n";
359	}
360	//if start date is ok, compare it against a provided end date
361	if (enddate && enddate.value) {
362		var endTs = Date.parse(enddate.value.replace(/-/g,'/'));
363		if (isNaN(endTs)) {
364			return "End Date must be valid.\n";
365		}
366		if (endTs < startTs) {
367			return "End Date should not be less than Start Date.\n";
368		}
369	} else {
370		enddate.value=startdate.value;
371		// return "You must enter full and valid End Date.\n";
372	}
373	return msg;
374}
375
376function _daysInMonth(iMonth, iYear){
377	var days, isleap;
378	days = [31,28,31,30,31,30,31,31,30,31,30,31];
379	if( iMonth != 2 ) {
380		return days[iMonth-1];
381	} else {
382		isleap =(iYear % 4 == 0 && iYear %100 !=0) || (iYear % 400 ==0) ? 29 : 28;
383		return isleap;
384	}
385}
386
387/**
388 * Checks if at least one of the event category checkboxes is selected.
389 * @return string - an empty string is validation was successful, otherwise and error msg is returned.
390 */
391function _checkAtLeastOneCategorySelected()
392{
393	var msg = "";
394	var isChecked = false;
395	// get the checkboxes
396	var categories = document.getElementsByName("calendarevent_categories[]");
397	// must exist and must contrain at least one elem.
398	if (categories && categories.length) {
399		for (var i =0; i < categories.length; i++) {
400			if (categories[i].checked) {
401				isChecked = true;
402				break;
403			}
404		}
405		if (!isChecked) {
406			categories[0].focus();
407			msg = "You must select at least one category.\n";
408
409		}
410	}
411	return msg;
412}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.