Globalization |
Used for conversion of different units of measurements.
Syntax
HTML |
<div cordysType="wcp.library.ui.Globalization" id=globalID > ... </div> |
where, globalID denotes the ID of the component attached to the page.
The component is used for converting units of measurements like currency, weight, distance, volume, temperature, and date. It can be extended to support custom conversions defined by the user. The default conversions supported by the globalization component are as follows.
Table 1. Conversions supported by default
Unit |
Base |
Conversion Types |
---|---|---|
Distance |
kilometer (km) |
meter, centimeter (cm), millimeter (mm), mile, feet, inch and yard. |
Weight |
kilogram (kg) |
gram (gm), ounce, milligram (milligm), tonne and pound. |
Volume |
litre |
milliliter, centiliter, deciliter, cubicmeter, cubicinch, cubicfeet, cubicyard. |
Temperature |
celsius |
fahrenheit, kelvin |
Date |
- |
UTC date, locale date |
where, UTC is the Universal Coordinated Time, which refers to the time as set by the World Time Standard (Previously referred to as Greenwich Mean Time or GMT).
To dynamically add and initialize this component, you can use theinitializeHTMLElementsoraddTypemethods of the Application object.
The attributes and methods exposed by the component are as follows:
Table 2. List of Attributes
Attribute |
Property |
Description |
---|---|---|
currency |
N/A |
Required. Pointer to an XML Object that defines the conversion data for currencies. |
extension |
N/A |
Required. Pointer to an XML Object that extends the existing list of conversion data. |
Table 3. List of Methods
Method |
Description |
---|---|
getUTCDate(date) |
Returns the UTC equivalent of date. The date is optional, and if not given the "local date" object is taken. The date object could be from a proper JScript Date object, or a JScript parsable string. |
getLocaleDate(date) |
Returns the local equivalent of given UTC date. The date parameter is mandatory. This could be a date object or a JScript parsable string. |
setCurrency |
Sets the currency property, which is a pointer to an XML Object that defines the conversion data for currencies. |
setExtension |
Sets the extension property, which is a pointer to an XML Object that extends the existing list of conversion data. |
Apart from the above methods defined, the globalization component defines a convention for calling the conversion methods for various defined units of measurements (Including Currencies). More information can be found in the link Conversion Methods.
Example
The following example shows the usage of this component:
<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Globalization Demo</title> <script type="text/javascript" src="/cordys/wcp/application.js"></script> </head> <script type="cordys/xml" id="currencyInput"> <currency base="USD"> <GBP>.75</GBP> <INR>50</INR> <EUR>1</EUR> <NLG>20</NLG> </currency> </script> <script type="text/javascript"> function wtToPound() { application.notify(global.weight.convertkgTopound(document.getElementById("weightData").value) + ' pounds'); } function volToLitre() { application.notify(global.volume.convertmilliliterTocentiliter(document.getElementById("volumeData").value) + ' centilitre'); } function currToEuro() { application.notify(global.currency.convertCurrency('INR', 'EUR', document.getElementById("currencyData").value) + ' euro'); } function tempToFheit() { application.notify(global.temperature.convertcelsiusTofahrenheit(document.getElementById("temperatureData").value) + ' f'); } function dateToUTC() { application.notify('UTC Date : ' + global.getUTCDate(document.getElementById("dateData").value)); } </script> <body leftmargin="50px"> <div cordysType="wcp.library.util.Globalization" id="global" currency="currencyInput.XMLDocument"> </div> <div cordysType="wcp.library.util.Validate" id="validate"> </div> <div cordysType="wcp.library.ui.Calendar" id="cal" showTitle="true" showInputBox="false" style="position:absolute;width:150;height:137;display:none"> </div> <h4><font face="arial">Globalization Conversions</font></h4> <input id="weightData">kg <button style="width:250px" class="medium" onclick="wtToPound()">Weight - Kg to Pound</button> <br><br> <input id="volumeData">ml <button style="width:250px" class="medium" onclick="volToLitre()">Volume - Millilitre to Centilitre</button> <br><br> <input id="currencyData">Rs. <button style="width:250px" class="medium" onclick="currToEuro()">Currency - Indian to Euro</button> <br><br> <input id="temperatureData">c <button style="width:250px" class="medium" onclick="tempToFheit()">Temperature - Celsius to Fahrenheit</button> <br><br> <input id="dateData" fieldType="date" displayFormat="MM/DD/YYYY" calendar="cal"> <button style="width:250px" class="medium" onclick="dateToUTC()">Date - Locale to UTC</button> </body> </html>