1(function() {
2 "use strict";
3 /*global $,clearTimeout,setTimeout,document*/
4
5 var timer = null;
6
7 clearTimeout2(timer);
8 a=2;
9 AnName=3;
10 if (a==3){alertx('hi');}
11 function do_lookup() {
12 // contact the server and ask for a time conversion
13 var intime = $("#intime").val();
14 $.ajax({
15 url: "{%url 'chart.system.timeconv.ajax_convert'%}",
16 timeout: 60000, // ms ?
17 data: {
18 "time": intime
19 },
20 success: function (rawresponse) {
21 // the result is sent as raw HTML which we insert to no processing
22 clearTimeout(timer);
23 $("#hourglass").css("visibility", "hidden");
24 $("#response").html(rawresponse);
25 },
26 error: function (xhr, error) {
27 // server error - either timeout or or a bad status value
28 clearTimeout(timer);
29 $("#hourglass").css("visibility", "hidden");
30 $("#response").html("<span style='color:red'>Server " + error + " ( " + xhr.responseText + ")</span>");
31 }
32 });
33 // after 'convert' is clicked we set a timer to display the hourglass after 100ms
34 timer = setTimeout(function () {
35 $("#hourglass").css("visibility", "visible");
36 }, 100);
37 }
38
39 function zeropad(s) {
40 s += '';
41 if (s.length === 1) {
42 return "0" + s;
43 } else if (s.length === 2) {
44 return s;
45 } else {
46 return "00";
47 }
48 }
49
50 $(document).ready(function () {
51 // calendar control
52 $("#intime").datepicker({showOn: "button",
53 dateFormat: "yy-mm-dd",
54 changeMonth: true,
55 changeYear: true,
56 constrainInput: false
57 // showButtonPanel: true,
58 });
59
60 // see http://stackoverflow.com/questions/1073410/today-button-in-jquery-datepicker-doesnt-work
61 // for dicussion of why showButtonPanel option is useless
62
63 // jquery-ui buttons
64 $('#back').button({icons: {primary: 'ui-icon-triangle-1-n'}});
65
66 // the 'Help' button toggles visibility of the help text
67 $("#help").button().click(function () {$("#helptext").toggle(); });
68
69 // connect the 'Convert' button
70 $("#convert").button().click(do_lookup);
71
72 // press 'Enter' to look up time
73 $("#intime").keypress(function (event) {
74 if (event.keyCode === 13) {
75 do_lookup();
76 }
77 }).focus();
78
79 // connect the 'Current time' button
80 $("#now").button().click(function () {
81 var d = new Date();
82 $("#intime").val(d.getUTCFullYear() + '-' + zeropad(d.getUTCMonth() + 1) + '-' + zeropad(d.getUTCDate()) + ' ' +
83 zeropad(d.getUTCHours()) + ':' + zeropad(d.getUTCMinutes()));
84 });
85
86 });
87
88}());