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

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

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

  • Property svn:eol-style set to native
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 /* NOTE: this file is different between Bedework web applications and is
21    therefore not currently interchangable between apps.  This will be normalized
22    in the coming versions, but for now don't try to exchange them. */
23
24 /* Global variables / properties */
25 // URLs
26 var timezoneUrl = "/tzsvr/?names";
27 var carddavUrl = "/ucarddav/find";
28
29 var debug = false; // very basic debugging for now
30
31 /* COMMON and GENERAL FUNCTIONS */
32
33 function changeClass(id, newClass) {
34   var identity = document.getElementById(id);
35   if (identity == null) {
36     alert("No element with id: " + id + " to set to class: " + newClass);
37   }
38   identity.className=newClass;
39 }
40 // set a field's value by ID
41 // typically used to set the value of a hidden field
42 function setField(id,val) {
43   field = document.getElementById(id);
44   field.value = val;
45 }
46
47 // show hide items using a checkbox
48 function swapVisible(obj,id) {
49   if (obj.checked) {
50     changeClass(id,'visible');
51   } else {
52     changeClass(id,'invisible');
53   }
54 }
55 // hide a group of items
56 // send IDs as parameters
57 function hide() {
58   if (arguments.length != 0) {
59     for (i = 0; i < arguments.length; i++) {
60       changeClass(arguments[i],'invisible');
61     }
62   }
63 }
64 // show a group of items
65 // send IDs as parameters
66 function show() {
67   if (arguments.length != 0) {
68     for (i = 0; i < arguments.length; i++) {
69       changeClass(arguments[i],'visible');
70     }
71   }
72 }
73 // show and hide an item based on its current
74 // visibility; if visible, hide it; if invisible
75 // show it.
76 function toggleVisibility(id,newClass) {
77   if (document.getElementById(id).className == 'invisible') {
78     if (newClass != "") {
79       changeClass(id,newClass);
80     } else {
81       changeClass(id,'visible');
82     }
83   } else {
84     changeClass(id,'invisible');
85   }
86 }
87 function setTab(listId,listIndex) {
88   var list = document.getElementById(listId);
89   var elementArray = new Array();
90   for (i = 0; i < list.childNodes.length; i++) {
91     if (list.childNodes[i].nodeName == "LI") {
92       elementArray.push(list.childNodes[i]);
93     }
94   }
95   for (i = 0; i < elementArray.length; i++) {
96     if (i == listIndex) {
97       elementArray[i].className = 'selected';
98     } else {
99       elementArray[i].className = '';
100     }
101   }
102 }
103 function getSelectedRadioButtonVal(radioCollection) {
104   for(var i = 0; i < radioCollection.length; i++) {
105     if(radioCollection[i].checked == true) {
106        return radioCollection[i].value;
107     }
108   }
109 }
110 // returns an array of collected checkbox values
111 function collectRecurChkBoxVals(valArray,chkBoxes,dayPos) {
112   if (chkBoxes) {
113     if (typeof chkBoxes.length != 'undefined') {
114       for (i = 0; i < chkBoxes.length; i++) {
115         if (chkBoxes[i].checked == true) {
116           if (dayPos) {
117             valArray.push(dayPos + chkBoxes[i].value);
118           } else {
119             valArray.push(chkBoxes[i].value);
120           }
121         }
122       }
123     }
124   }
125   return valArray;
126 }
127 // launch a simple window for displaying information; no header or status bar
128 function launchSimpleWindow(URL) {
129   simpleWindow = window.open(URL, "simpleWindow", "width=800,height=600,scrollbars=yes,resizable=yes,alwaysRaised=yes,menubar=no,toolbar=no");
130   window.simpleWindow.focus();
131 }
132
133 // launch a size parameterized window for displaying information; no header or status bar
134 function launchSizedWindow(URL,width,height) {
135   paramStr = "width=" + width + ",height=" + height + ",scrollbars=yes,resizable=yes,alwaysRaised=yes,menubar=no,toolbar=no";
136   sizedWindow = window.open(URL, "sizedWindow", paramStr);
137   window.sizedWindow.focus();
138 }
139
140 // launches new browser window with print-friendly version of page when
141 // print icon is clicked
142 function launchPrintWindow(URL) {
143   printWindow = window.open(URL, "printWindow", "width=640,height=500,scrollbars=yes,resizable=yes,alwaysRaised=yes,menubar=yes,toolbar=yes");
144   window.printWindow.focus();
145 }
146 // launch the calSelect pop-up window for selecting a calendar when creating,
147 // editing, and importing events
148 function launchCalSelectWindow(URL) {
149   calSelect = window.open(URL, "calSelect", "width=500,height=600,scrollbars=yes,resizable=yes,alwaysRaised=yes,menubar=no,toolbar=no");
150   window.calSelect.focus();
151 }
152 // used to update the calendar in various forms from
153 // the calSelect pop-up window.  We must do two things: update the hidden calendar
154 // input field and update the displayed text.
155 function updateEventFormCalendar(newCalPath,calDisplay) {
156   if (window.opener.document.eventForm) {
157     window.opener.document.eventForm.newCalPath.value = newCalPath;
158     bwCalDisplay = window.opener.document.getElementById("bwEventCalDisplay");
159     bwCalDisplay.innerHTML = calDisplay;
160   } else {
161     alert("The event form is not available.");
162   }
163   window.close();
164 }
165 // used to update a calendar subscription (alias) We must do two things: update the hidden
166 // calendar input field and update the displayed text
167 function updatePublicCalendarAlias(newCalPath,calDisplay,calendarCollection) {
168   var calendarAliasHolder = document.getElementById("publicAliasHolder");
169   var bwCalDisplay = document.getElementById("bwPublicCalDisplay");
170   calendarAliasHolder.value = newCalPath;
171   bwCalDisplay.innerHTML = '<strong>' + calDisplay + '</strong> <button type="button" onclick="showPublicCalAliasTree();">change</button>';
172   changeClass("publicSubscriptionTree","invisible");
173 }
174 function showPublicCalAliasTree() {
175   changeClass("publicSubscriptionTree","calendarTree");
176 }
177 // set the subscription URI when creating or updating a subscription
178 function setCalendarAlias(formObj) {
179   if (!formObj) {
180     alert("The subscription form is not available.");
181     return false;
182   }
183
184   // set the aliasUri to an empty string.  Only set it if user
185   // has requested a subscription.
186   formObj.aliasUri.value == "";
187
188   if (formObj.type.value == "folder") {
189     formObj.calendarCollection.value = "false";
190   } else if (formObj.type.value == "subscription") {
191     switch (formObj.subType.value) {
192       case "publicTree":
193         // do nothing: when adding a subscription to the public tree, we set the fields directly.
194         break;
195       case "public":
196         formObj.aliasUri.value = "bwcal://" + formObj.publicAliasHolder.value;
197         break;
198       case "user":
199         //the "/user/" string is temporary; it needs to be passed as a param.
200         formObj.aliasUri.value = "bwcal:///user/" + formObj.userIdHolder.value + "/" + formObj.userCalHolder.value;
201         break;
202       case "external":
203         formObj.aliasUri.value = formObj.aliasUriHolder.value;
204         break;
205     }
206   }
207   return true;
208 }
209 // build a uri based on user and path in the subscription form
210 // DEPRECATED - use setCalendarAlias() above.
211 function setSubscriptionUri(formObj,prefix) {
212   if (formObj) {
213     var fullUri =  prefix + formObj.userId.value;
214     if (formObj.userPath.value != "") {
215       if (formObj.userPath.value.substring(0,1) == "/") {
216         fullUri += formObj.userPath.value;
217       } else {
218         fullUri += "/" + formObj.userPath.value;
219       }
220     }
221     formObj.calUri.value = fullUri;
222     return true;
223   } else {
224     alert("The subscription form is not available.");
225     return false;
226   }
227 }
228 function exportCalendar(formId,name,calPath) {
229   var formObj = document.getElementById(formId);
230   formObj.calPath.value = calPath;
231   formObj.contentName.value = name + '.ics';
232   formObj.submit();
233 }
234
235 // checkboxes for all categories and preferred categories are on the page
236 // simultaneously.  The use can toggle between which is shown and which is
237 // hidden.  When a checkbox from one collection is changed, the corresponding
238 // checkbox should be changed in the other set if it exists.
239 function setCatChBx(thiscat,othercat) {
240   thisCatCheckBox = document.getElementById(thiscat);
241   if (document.getElementById(othercat)) {
242     otherCatCheckBox = document.getElementById(othercat);
243     otherCatCheckBox.checked =  thisCatCheckBox.checked;
244   }
245 }
246 function checkPrefCategories(formObj){
247   var hasACat = false;
248
249   if (typeof formObj.defaultCategory.length != 'undefined') {
250     for (i = 0; i < formObj.defaultCategory.length; i++) {
251       if (formObj.defaultCategory[i].checked) {
252         hasACat = true;
253         break;
254       }
255     }
256   }
257   if (!hasACat) {
258     // no category is checked;
259     // create an empty catUid element to alert the backend
260     // so we can clear the cats
261     var hiddenCat = document.createElement("div");
262     hiddenCat.innerHTML = '<input type="hidden" name="defaultCategory" value=""/>';
263     formObj.appendChild(hiddenCat);
264   }
265 }
266 // set category filters on calendar collections
267 function setCatFilters(formObj) {
268   if (typeof formObj.filterCatUid.length != 'undefined') {
269     var filterExpression = "catuid=(";
270     var filterExists = false;
271     for (i = 0; i < formObj.filterCatUid.length; i++) {
272       if (formObj.filterCatUid[i].checked) {
273         filterExists = true;
274         filterExpression += "'" + formObj.filterCatUid[i].value + "',";
275       }
276     }
277     if (filterExists) {
278       // remove the last comma and close off the expression
279       filterExpression = filterExpression.substring(0,filterExpression.length-1) + ")";
280       // set the form value
281       formObj.fexpr.value = filterExpression;
282     }
283   }
284 }
Note: See TracBrowser for help on using the browser.