root/trunk/deployment/webadmin/webapp/resources/resources/includes.js

Revision 2850 (checked in by bleibson, 6 months ago)

o update javascript files to have Jasig licensing info.
o remove RPI copyright notice

Line 
1 /*
2    Licensed to Jasig under one or more contributor license
3    agreements. See the NOTICE file distributed with this work
4    for additional information regarding copyright ownership.
5    Jasig licenses this file to you under the Apache License,
6    Version 2.0 (the "License"); you may not use this file
7    except in compliance with the License. You may obtain a
8    copy of the License at:
9  
10    http://www.apache.org/licenses/LICENSE-2.0
11  
12    Unless required by applicable law or agreed to in writing,
13    software distributed under the License is distributed on
14    an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15    KIND, either express or implied. See the License for the
16    specific language governing permissions and limitations
17    under the License. 
18 */
19
20 var debug = false; // very basic debugging for now
21
22 function changeClass(id, newClass) {
23   identity = document.getElementById(id);
24   identity.className=newClass;
25 }
26 // show hide items using a checkbox
27 function swapVisible(obj,id) {
28   if (obj.checked) {
29     changeClass(id,'shown');
30   } else {
31     changeClass(id,'invisible');
32   }
33 }
34 function swapAllDayEvent(obj) {
35   allDayStartDateField = document.getElementById("allDayStartDateField");
36   allDayEndDateField = document.getElementById("allDayEndDateField");
37   if (obj.checked) {
38     //lets keep it simple for now: just show or hide time fields
39     changeClass('startTimeFields','invisible');
40     changeClass('endTimeFields','invisible');
41     changeClass('durationHrMin','invisible');
42     allDayStartDateField.value = "on";
43     allDayEndDateField.value = "on";
44   } else {
45     changeClass('startTimeFields','timeFields');
46     changeClass('endTimeFields','timeFields');
47     changeClass('durationHrMin','shown');
48     allDayStartDateField.value = "off";
49     allDayEndDateField.value = "off";
50   }
51 }
52 function swapFloatingTime(obj) {
53   startTimezone = document.getElementById("startTzid");
54   endTimezone = document.getElementById("endTzid");
55   startFloating = document.getElementById("startFloating");
56   endFloating = document.getElementById("endFloating");
57   if (obj.checked) {
58     document.getElementById("storeUTCFlag").checked = false;
59     startTimezone.disabled = true;
60     endTimezone.disabled = true;
61     startFloating.value = "on";
62     endFloating.value = "on";
63   } else {
64     startTimezone.disabled = false;
65     endTimezone.disabled = false;
66     startFloating.value = "off";
67     endFloating.value = "off";
68   }
69 }
70 function swapStoreUTC(obj) {
71   startTimezone = document.getElementById("startTzid");
72   endTimezone = document.getElementById("endTzid");
73   startStoreUTC = document.getElementById("startStoreUTC");
74   endStoreUTC = document.getElementById("endStoreUTC");
75   if (obj.checked) {
76     document.getElementById("floatingFlag").checked = false;
77     startTimezone.disabled = false;
78     endTimezone.disabled = false;
79     startStoreUTC.value = "on";
80     endStoreUTC.value = "on";
81   } else {
82     startStoreUTC.value = "off";
83     endStoreUTC.value = "off";
84   }
85 }
86 function swapDurationType(type) {
87   // get the components we need to manipulate
88   daysDurationElement = document.getElementById("durationDays");
89   hoursDurationElement = document.getElementById("durationHours");
90   minutesDurationElement = document.getElementById("durationMinutes");
91   weeksDurationElement = document.getElementById("durationWeeks");
92   if (type == 'week') {
93     weeksDurationElement.disabled = false;
94     daysDurationElement.disabled = true;
95     hoursDurationElement.disabled = true;
96     minutesDurationElement.disabled = true;
97   } else {
98     daysDurationElement.disabled = false;
99     hoursDurationElement.disabled = false;
100     minutesDurationElement.disabled = false;
101     // we are using day, hour, minute -- zero out the weeks.
102     weeksDurationElement.value = "0";
103     weeksDurationElement.disabled = true;
104   }
105 }
106 function swapRecurrence(obj) {
107   if (obj.checked) {
108     changeClass('recurrenceFields','dateStartEndBox');
109     changeClass('recurrenceUiSwitch','shown');
110   } else {
111     changeClass('recurrenceFields','invisible');
112     changeClass('recurrenceUiSwitch','invisible');
113   }
114 }
115 // reveal and hide recurrence fields
116 function showRecurrence(freq) {
117   changeClass('recurrenceUntilRules','shown');
118
119   if (freq == 'NONE') {
120     changeClass('noneRecurrenceRules','shown');
121     changeClass('recurrenceUntilRules','invisible');
122   } else {
123     changeClass('noneRecurrenceRules','invisible');
124   }
125   if (freq == 'HOURLY') {
126     changeClass('hourlyRecurrenceRules','shown');
127   } else {
128     changeClass('hourlyRecurrenceRules','invisible');
129   }
130   if (freq == 'DAILY') {
131     changeClass('dailyRecurrenceRules','shown');
132   } else {
133     changeClass('dailyRecurrenceRules','invisible');
134   }
135   if (freq == 'WEEKLY') {
136     changeClass('weeklyRecurrenceRules','shown');
137   } else {
138     changeClass('weeklyRecurrenceRules','invisible');
139   }
140   if (freq == 'MONTHLY') {
141     changeClass('monthlyRecurrenceRules','shown');
142   } else {
143     changeClass('monthlyRecurrenceRules','invisible');
144   }
145   if (freq == 'YEARLY') {
146     changeClass('yearlyRecurrenceRules','shown');
147   } else {
148     changeClass('yearlyRecurrenceRules','invisible');
149   }
150 }
151 function recurSelectWeekends(id) {
152   chkBoxCollection = document.getElementById(id).getElementsByTagName('input');
153   if (chkBoxCollection) {
154     if (typeof chkBoxCollection.length != 'undefined') {
155       for (i = 0; i < chkBoxCollection.length; i++) {
156         if (chkBoxCollection[i].value == 'SU' || chkBoxCollection[i].value == 'SA') {
157            chkBoxCollection[i].checked = true;
158         } else {
159           chkBoxCollection[i].checked = false;
160         }
161       }
162     }
163   }
164 }
165 function recurSelectWeekdays(id) {
166   chkBoxCollection = document.getElementById(id).getElementsByTagName('input');
167   if (chkBoxCollection) {
168     if (typeof chkBoxCollection.length != 'undefined') {
169       for (i = 0; i < chkBoxCollection.length; i++) {
170         if (chkBoxCollection[i].value == 'SU' || chkBoxCollection[i].value == 'SA') {
171            chkBoxCollection[i].checked = false;
172         } else {
173           chkBoxCollection[i].checked = true;
174         }
175       }
176     }
177   }
178 }
179 function selectRecurCountUntil(id) {
180   document.getElementById(id).checked = true;
181 }
182 // Assemble the recurrence rules if recurrence is specified.
183 // Request params to set ('freq' is always set):
184 // interval, count, until (count OR until, not both)
185 // possibly: byday, bymonthday, bymonth, byyearday
186 function setRecurrence(formObj) {
187   if (formObj.recurrenceFlag.checked) {
188     var freq = getSelectedRadioButtonVal(formObj.freq);
189     if (freq != 'NONE') {
190       // build up recurrence rules
191       switch (freq) {
192         case "DAILY":
193           var bymonth = new Array();
194           // get the bymonth values
195           bymonth = collectRecurChkBoxVals(bymonth,document.getElementById('dayMonthCheckBoxList').getElementsByTagName('input'),false);
196           // set the form values
197           formObj.bymonth.value = bymonth.join(',');
198           formObj.interval.value = formObj.dailyInterval.value;
199           break;
200         case "WEEKLY":
201           var byday = new Array();
202           byday = collectRecurChkBoxVals(byday, document.getElementById('weekRecurFields').getElementsByTagName('input'),false);
203           formObj.byday.value = byday.join(',');
204           if (formObj.weekWkst.selectedIndex != -1) {
205             formObj.wkst.value = formObj.weekWkst[formObj.weekWkst.selectedIndex].value;
206           }
207           formObj.interval.value = formObj.weeklyInterval.value;
208           break;
209         case "MONTHLY":
210           var i = 1;
211           var monthByDayId = 'monthRecurFields' + i;
212           var byday = new Array();
213           var bymonthday = new Array();
214           var byyearday = new Array();
215           // get the byday values
216           while (document.getElementById(monthByDayId)) {
217             var monthFields = document.getElementById(monthByDayId);
218             var dayPosSelect = monthFields.getElementsByTagName('select');
219             var dayPos = dayPosSelect[0][dayPosSelect[0].selectedIndex].value;
220             if (dayPos) {
221               byday = collectRecurChkBoxVals(byday,monthFields.getElementsByTagName('input'),dayPos);
222             }
223             monthByDayId = monthByDayId.substring(0,monthByDayId.length-1) + ++i;
224           }
225           // get the bymonthday values
226           bymonthday = collectRecurChkBoxVals(bymonthday,document.getElementById('monthDaysCheckBoxList').getElementsByTagName('input'),false);
227           // set the form values
228           formObj.byday.value = byday.join(',');
229           formObj.bymonthday.value = bymonthday.join(',');
230           formObj.interval.value = formObj.monthlyInterval.value;
231           break;
232         case "YEARLY":
233           var i = 1;
234           var yearByDayId = 'yearRecurFields' + i;
235           var byday = new Array();
236           var bymonthday = new Array();
237           var bymonth = new Array();
238           var byweekno = new Array();
239           var byyearday = new Array();
240           // get the byday values
241           while (document.getElementById(yearByDayId)) {
242             var yearFields = document.getElementById(yearByDayId);
243             var dayPosSelect = yearFields.getElementsByTagName('select');
244             var dayPos = dayPosSelect[0][dayPosSelect[0].selectedIndex].value;
245             if (dayPos) {
246               byday = collectRecurChkBoxVals(byday,yearFields.getElementsByTagName('input'),dayPos);
247             }
248             yearByDayId = yearByDayId.substring(0,yearByDayId.length-1) + ++i;
249           }
250           // get the bymonth values
251           bymonth = collectRecurChkBoxVals(bymonth,document.getElementById('yearMonthCheckBoxList').getElementsByTagName('input'),false);
252           // get the bymonthday values
253           bymonthday = collectRecurChkBoxVals(bymonthday,document.getElementById('yearMonthDaysCheckBoxList').getElementsByTagName('input'),false);
254           // get the byweekno values
255           byweekno = collectRecurChkBoxVals(byweekno,document.getElementById('yearWeeksCheckBoxList').getElementsByTagName('input'),false);
256           // get the byyearday values
257           byyearday = collectRecurChkBoxVals(byyearday,document.getElementById('yearDaysCheckBoxList').getElementsByTagName('input'),false);
258
259           // set the form values
260           formObj.byday.value = byday.join(',');
261           formObj.bymonth.value = bymonth.join(',');
262           formObj.bymonthday.value = bymonthday.join(',');
263           formObj.byweekno.value = byweekno.join(',');
264           formObj.byyearday.value = byyearday.join(',');
265           if (formObj.yearWkst.selectedIndex != -1) {
266             formObj.wkst.value = formObj.yearWkst[formObj.yearWkst.selectedIndex].value;
267           }
268           formObj.interval.value = formObj.yearlyInterval.value;
269           break;
270       }
271       // build up count or until values
272       var recur = getSelectedRadioButtonVal(formObj.recurCountUntil);
273       switch (recur) {
274         case "forever":
275           // do nothing
276           break;
277         case "count":
278           formObj.count.value = formObj.countHolder.value;
279           break;
280         case "until":
281           // pad the month and day with zeros if only a single digit
282           var paddedMonth = (formObj.untilMonth.value < 10) ? '0'+formObj.untilMonth.value : formObj.untilMonth.value;
283           var paddedDay = (formObj.untilDay.value < 10) ? '0'+formObj.untilDay.value : formObj.untilDay.value;
284           formObj.until.value = formObj.untilYear.value + paddedMonth + paddedDay;
285           break;
286       }
287     }
288   }
289   if (debug) {
290     alert("frequency: " + freq + "\ninterval: " + formObj.interval.value + "\ncount: " + formObj.count.value + "\nuntil: " + formObj.until.value + "\nbyday: " + formObj.byday.value + "\nbymonthday: " + formObj.bymonthday.value + "\nbymonth: " + formObj.bymonth.value + "\nbyyearday: " + formObj.byyearday.value + "\nwkst: " + formObj.wkst.value);
291   }
292   return true;
293 }
294 function getSelectedRadioButtonVal(radioCollection) {
295   for(var i = 0; i < radioCollection.length; i++) {
296     if(radioCollection[i].checked == true) {
297        return radioCollection[i].value;
298     }
299   }
300 }
301 // returns an array of collected checkbox values
302 function collectRecurChkBoxVals(valArray,chkBoxes,dayPos) {
303   if (chkBoxes) {
304     if (typeof chkBoxes.length != 'undefined') {
305       for (i = 0; i < chkBoxes.length; i++) {
306         if (chkBoxes[i].checked == true) {
307           if (dayPos) {
308             valArray.push(dayPos + chkBoxes[i].value);
309           } else {
310             valArray.push(chkBoxes[i].value);
311           }
312         }
313       }
314     }
315   }
316   return valArray;
317 }
318 // launch a simple window for displaying information; no header or status bar
319 function launchSimpleWindow(URL) {
320   simpleWindow = window.open(URL, "simpleWindow", "width=800,height=600,scrollbars=yes,resizable=yes,alwaysRaised=yes,menubar=no,toolbar=no");
321   window.simpleWindow.focus();
322 }
323
324 // launch a size parameterized window for displaying information; no header or status bar
325 function launchSizedWindow(URL,width,height) {
326   paramStr = "width=" + width + ",height=" + height + ",scrollbars=yes,resizable=yes,alwaysRaised=yes,menubar=no,toolbar=no";
327   sizedWindow = window.open(URL, "sizedWindow", paramStr);
328   window.sizedWindow.focus();
329 }
330
331 // launches new browser window with print-friendly version of page when
332 // print icon is clicked
333 function launchPrintWindow(URL) {
334   printWindow = window.open(URL, "printWindow", "width=640,height=500,scrollbars=yes,resizable=yes,alwaysRaised=yes,menubar=yes,toolbar=yes");
335   window.printWindow.focus();
336 }
337
338 function startDateCalWidgetCallback(date, month, year) {
339   today = new Date();
340   if (year < today.getFullYear()) {
341     alert("You may not use this widget to \n create an event in a previous year.");
342   } else {
343     document.peForm['eventStartDate.month'].value = month;
344     document.peForm['eventStartDate.day'].value = date;
345     document.peForm['eventStartDate.year'].value = year;
346   }
347 }
348 function endDateCalWidgetCallback(date, month, year) {
349   today = new Date();
350   if (year < today.getFullYear()) {
351     alert("You may not use this widget to \n create an event in a previous year.");
352   } else {
353     document.peForm['eventEndDate.month'].value = month;
354     document.peForm['eventEndDate.day'].value = date;
355     document.peForm['eventEndDate.year'].value = year;
356   }
357 }
358 function untilDateCalWidgetCallback(date, month, year) {
359   if (year < today.getFullYear()) {
360     alert("You may not use this widget to \n create an event in a previous year.");
361   } else {
362     document.peForm['untilMonth'].value = month;
363     document.peForm['untilDay'].value = date;
364     document.peForm['untilYear'].value = year;
365     selectRecurCountUntil('recurUntil');
366   }
367 }
368 // launch the calSelect pop-up window for selecting a calendar when creating,
369 // editing, and importing events
370 function launchCalSelectWindow(URL) {
371   calSelect = window.open(URL, "calSelect", "width=500,height=600,scrollbars=yes,resizable=yes,alwaysRaised=yes,menubar=no,toolbar=no");
372   window.calSelect.focus();
373 }
374 // used to update the calendar in an upload event form from
375 // the calSelect pop-up window.  We must do two things: update the hidden calendar
376 // input field and update the displayed text.
377 function updateEventFormCalendar(newCalPath,calDisplay) {
378   if (window.opener.document.eventForm) {
379     window.opener.document.eventForm.newCalPath.value = newCalPath;
380     bwCalDisplay = window.opener.document.getElementById("bwEventCalDisplay");
381     bwCalDisplay.innerHTML = calDisplay;
382   } else {
383     alert("The event form is not available.");
384   }
385   window.close();
386 }
387
388 // checkboxes for all categories and preferred categories are on the page
389 // simultaneously.  The use can toggle between which is shown and which is
390 // hidden.  When a checkbox from one collection is changed, the corresponding
391 // checkbox should be changed in the other set if it exists.
392 function setCatChBx(thiscat,othercat) {
393   thisCatCheckBox = document.getElementById(thiscat);
394   if (document.getElementById(othercat)) {
395     otherCatCheckBox = document.getElementById(othercat);
396     otherCatCheckBox.checked =  thisCatCheckBox.checked;
397   }
398 }
Note: See TracBrowser for help on using the browser.