| 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 bwClockHour = null; |
|---|
| 21 |
var bwClockMinute = null; |
|---|
| 22 |
var bwClockRequestedType = null; |
|---|
| 23 |
var bwClockCurrentType = null; |
|---|
| 24 |
|
|---|
| 25 |
function bwClockLaunch(type) { |
|---|
| 26 |
// type: type of clock "eventStartDate" or "eventEndDate" |
|---|
| 27 |
if ((document.getElementById("clock").className == "visible") && (bwClockCurrentType == type)) { |
|---|
| 28 |
// if the clock with the same type is visible, toggle it off |
|---|
| 29 |
changeClass("clock","invisible"); |
|---|
| 30 |
} else { |
|---|
| 31 |
// otherwise, turn it on and display the correct type |
|---|
| 32 |
changeClass("clock","visible"); |
|---|
| 33 |
bwClockRequestedType = type; |
|---|
| 34 |
bwClockCurrentType = type; |
|---|
| 35 |
// reset hours and minutes to null |
|---|
| 36 |
bwClockHour = null; |
|---|
| 37 |
bwClockMinute = null; |
|---|
| 38 |
var bwClockIndicator = document.getElementById("bwClockDateTypeIndicator"); |
|---|
| 39 |
var bwClockSwitch = document.getElementById("bwClockSwitch"); |
|---|
| 40 |
document.getElementById("bwClockTime").innerHTML = "select time"; |
|---|
| 41 |
if (type == 'eventStartDate') { |
|---|
| 42 |
bwClockIndicator.innerHTML = "Start Time"; |
|---|
| 43 |
bwClockSwitch.innerHTML = '<a href="javascript:bwClockLaunch(\'eventEndDate\');">switch to end</a>'; |
|---|
| 44 |
} else { |
|---|
| 45 |
bwClockIndicator.innerHTML = "End Time"; |
|---|
| 46 |
bwClockSwitch.innerHTML = '<a href="javascript:bwClockLaunch(\'eventStartDate\');">switch to start</a>'; |
|---|
| 47 |
} |
|---|
| 48 |
} |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
function bwClockClose() { |
|---|
| 52 |
changeClass("clock","invisible"); |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
function bwClockUpdateDateTimeForm(valType,val,hour24) { |
|---|
| 56 |
// valType: "hour" or "minute" |
|---|
| 57 |
// val: hour or minute value as integer |
|---|
| 58 |
// hour24: true (24hr clock) or false (12hr clock + am/pm) |
|---|
| 59 |
if (bwClockRequestedType) { |
|---|
| 60 |
try { |
|---|
| 61 |
if (valType == 'minute') { |
|---|
| 62 |
var fieldName = bwClockRequestedType + ".minute" |
|---|
| 63 |
window.document.eventForm[fieldName].value = val; |
|---|
| 64 |
if (val < 10) { |
|---|
| 65 |
val = "0" + val; // pad the value for display |
|---|
| 66 |
} |
|---|
| 67 |
bwClockMinute = val; |
|---|
| 68 |
} else { |
|---|
| 69 |
var fieldName = bwClockRequestedType + ".hour" |
|---|
| 70 |
if (hour24) { |
|---|
| 71 |
window.document.eventForm[fieldName].value = val; |
|---|
| 72 |
if (val < 10) { |
|---|
| 73 |
val = "0" + val; // pad the value for display |
|---|
| 74 |
} |
|---|
| 75 |
bwClockHour = val; |
|---|
| 76 |
} else { |
|---|
| 77 |
var hour12 = val; |
|---|
| 78 |
if (hour12 > 12) { |
|---|
| 79 |
hour12 -= 12; |
|---|
| 80 |
} else if (hour12 == 12) { |
|---|
| 81 |
hour12 = 0; // noon and midnight are both represented by '0' in 12hr mode |
|---|
| 82 |
} |
|---|
| 83 |
window.document.eventForm[fieldName].value = hour12; |
|---|
| 84 |
if (val < 10) { |
|---|
| 85 |
val = "0" + val; // pad the value for display |
|---|
| 86 |
} |
|---|
| 87 |
bwClockHour = val; |
|---|
| 88 |
// now set the am/pm field |
|---|
| 89 |
fieldName = bwClockRequestedType + ".ampm"; |
|---|
| 90 |
window.document.eventForm[fieldName].value = bwClockGetAmPm(bwClockHour); |
|---|
| 91 |
} |
|---|
| 92 |
} |
|---|
| 93 |
if (bwClockHour && bwClockMinute) { |
|---|
| 94 |
document.getElementById("bwClockTime").innerHTML = bwClockHour + ":" + bwClockMinute + " , " + bwClockConvertAmPm(bwClockHour) + ":" + bwClockMinute + " " + bwClockGetAmPm(bwClockHour); |
|---|
| 95 |
} else if (bwClockMinute) { |
|---|
| 96 |
document.getElementById("bwClockTime").innerHTML = ":" + bwClockMinute; |
|---|
| 97 |
} else { |
|---|
| 98 |
document.getElementById("bwClockTime").innerHTML = bwClockHour + " , " + bwClockConvertAmPm(bwClockHour) + " " + bwClockGetAmPm(bwClockHour); |
|---|
| 99 |
} |
|---|
| 100 |
} catch(e) { |
|---|
| 101 |
alert("There was an error:\n" + e ); |
|---|
| 102 |
} |
|---|
| 103 |
} else { |
|---|
| 104 |
alert("The date type is null."); |
|---|
| 105 |
} |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
function bwClockConvertAmPm(hour24) { |
|---|
| 109 |
hour24 = parseInt(hour24,10); |
|---|
| 110 |
if (hour24 == 0) { |
|---|
| 111 |
return 12; |
|---|
| 112 |
} else if (hour24 > 12) { |
|---|
| 113 |
return hour24 - 12; |
|---|
| 114 |
} else { |
|---|
| 115 |
return hour24; |
|---|
| 116 |
} |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
function bwClockGetAmPm(hour24) { |
|---|
| 120 |
hour24 = parseInt(hour24,10); |
|---|
| 121 |
if (hour24 < 12) { |
|---|
| 122 |
return 'am'; |
|---|
| 123 |
} else { |
|---|
| 124 |
return 'pm'; |
|---|
| 125 |
} |
|---|
| 126 |
} |
|---|