source: TI03-DataExtractor/branches/old_stuff/dx-webservice/js_funcs.py @ 793

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/branches/old_stuff/dx-webservice/js_funcs.py@793
Revision 793, 6.7 KB checked in by astephen, 13 years ago (diff)

Put all the old code in the old_stuff branch.

  • Property svn:executable set to *
Line 
1"""
2js_funcs.py
3===========
4
5Holder module for Javascript functions that will be inserted into the header
6of relevant web pages for checking purposes.
7
8"""
9
10# js_dateCheckFunctionGroup - a string containing a list of javascript
11# functions for checking date/time fields on a web form. These are
12# inserted into HTML output by the UserInterface class in the userInterface
13# module.
14js_dateCheckFunctionGroup="""
15<SCRIPT LANGUAGE="Javascript">
16
17// Set up global variables for all functions
18var frm=document.forms[0];
19var dateMinimum_1 = new Array(%s, %s, %s, %s, %s, %s);
20var dateMaximum_1 = new Array(%s, %s, %s, %s, %s, %s);
21var dateMinimum_2 = new Array(%s, %s, %s, %s, %s, %s);
22var dateMaximum_2 = new Array(%s, %s, %s, %s, %s, %s);
23
24function getFormFields(arg) {
25    // getFormFields - returns an array of form fields to manipulate based on the argument given.
26    if (arg == "start_1") {
27        var fields = new Array(frm.start_year_1, frm.start_month_1, frm.start_day_1, frm.start_hour_1, frm.start_min_1, frm.start_sec_1);
28    } else if (arg == "end_1") {
29        var fields = new Array(frm.end_year_1, frm.end_month_1, frm.end_day_1, frm.end_hour_1, frm.end_min_1, frm.end_sec_1);
30    } else if (arg == "start_2") {
31        var fields = new Array(frm.start_year_2, frm.start_month_2, frm.start_day_2, frm.start_hour_2, frm.start_min_2, frm.start_sec_2);
32    } else if (arg == "end_2") {
33        var fields = new Array(frm.end_year_2, frm.end_month_2, frm.end_day_2, frm.end_hour_2, frm.end_min_2, frm.end_sec_2);
34    }
35    return fields
36}
37
38function getOppositeFields(arg) {
39    // getOppositeFields - returns an array of form fields opposite to the argument argument given.
40    if (arg == "end_1") {
41        var fields = new Array(frm.start_year_1, frm.start_month_1, frm.start_day_1, frm.start_hour_1, frm.start_min_1, frm.start_sec_1);
42    } else if (arg == "start_1") {
43        var fields = new Array(frm.end_year_1, frm.end_month_1, frm.end_day_1, frm.end_hour_1, frm.end_min_1, frm.end_sec_1);
44    } else if (arg == "end_2") {
45        var fields = new Array(frm.start_year_2, frm.start_month_2, frm.start_day_2, frm.start_hour_2, frm.start_min_2, frm.start_sec_2);
46    } else if (arg == "start_2") {
47        var fields = new Array(frm.end_year_2, frm.end_month_2, frm.end_day_2, frm.end_hour_2, frm.end_min_2, frm.end_sec_2);
48    }
49    return fields
50}
51
52function matchFields(fields1, fields2) {
53    // matchFields - sets one set of form fields equal to another
54    for (i=0; i<6; i++) {
55        fields2[i].selectedIndex = fields1[i].selectedIndex;
56    }
57}
58
59function getDateMinimum(arg) {
60    // getDateMinimum function - to return the minimum date for the appropriate fields
61    if ((arg=="start_1") || (arg=="end_1")) {
62        var dateMinimum = dateMinimum_1;
63    } else if ((arg=="start_2") || (arg=="end_2")) {
64        var dateMinimum = dateMinimum_2;
65    }
66    return dateMinimum;
67}
68
69function getDateMaximum(arg) {
70    // getDateMaximum function - to return the maximum date for the appropriate fields
71    if ((arg=="start_1") || (arg=="end_1")) {
72        var dateMaximum = dateMaximum_1;
73    } else if ((arg=="start_2") || (arg=="end_2")) {
74        var dateMaximum = dateMaximum_2;
75    }
76    return dateMaximum;
77}
78
79function resetDate(arg) {
80    // resetDate function - resets the date field selected to either max or min possible.
81    var form_fields = getFormFields(arg);
82    var dateMinimum = getDateMinimum(arg);
83    for (i=0; i<6; i++) {
84        form_fields[i].selectedIndex = dateMinimum[i];
85    }
86}
87
88
89function resetAllDates(n) {
90    // resetAllDates function - resets all date fields to minimum allowed.
91    resetDate("start_1");
92    resetDate("end_1");
93    if (n>1) {
94        resetDate("start_2");
95        resetDate("end_2");
96    }
97}
98
99
100function checkDate(arg) {
101    // checkDate function - checks start date is not below minimum.
102    var form_fields = getFormFields(arg);
103    var dateMinimum = getDateMinimum(arg);
104    var dateMaximum = getDateMaximum(arg);
105     
106    if (form_fields[0].selectedIndex < dateMinimum[0]) {
107        resetDate(arg);
108    } else if (form_fields[0].selectedIndex == dateMinimum[0]) {
109        if (form_fields[1].selectedIndex < dateMinimum[1]) {
110            resetDate(arg);
111        } else if (form_fields[1].selectedIndex == dateMinimum[1]) {
112            if (form_fields[2].selectedIndex < dateMinimum[2]) {
113                resetDate(arg);
114            } else if (form_fields[2].selectedIndex == dateMinimum[2]) {
115                if (form_fields[3].selectedIndex < dateMinimum[3]) {
116                    resetDate(arg);
117                } else if (form_fields[3].selectedIndex == dateMinimum[3]) {
118                    if (form_fields[4].selectedIndex < dateMinimum[4]) {
119                        resetDate(arg);
120                    } else if (form_fields[4].selectedIndex == dateMinimum[4]) {
121                        if (form_fields[5].selectedIndex < dateMinimum[5]) {
122                            resetDate(arg);
123                        }
124                    }
125                }
126            }
127        }
128    } else if (form_fields[0].selectedIndex == dateMaximum[0]) {
129        if (form_fields[1].selectedIndex > dateMaximum[1]) {
130            resetDate(arg);
131        } else if (form_fields[1].selectedIndex == dateMaximum[1]) {
132            if (form_fields[2].selectedIndex > dateMaximum[2]) {
133                resetDate(arg);
134            } else if (form_fields[2].selectedIndex == dateMaximum[2]) {
135                if (form_fields[3].selectedIndex > dateMaximum[3]) {
136                    resetDate(arg);
137                } else if (form_fields[3].selectedIndex == dateMaximum[3]) {
138                    if (form_fields[4].selectedIndex > dateMaximum[4]) {
139                        resetDate(arg);
140                    } else if (form_fields[4].selectedIndex == dateMaximum[4]) {
141                        if (form_fields[5].selectedIndex > dateMaximum[5]) {
142                            resetDate(arg);
143                        }
144                    }
145                }
146            }
147        }   
148    }
149    // Now check the order of the fields to make sure start is not after end
150    var opp_fields  = getOppositeFields(arg);
151    for (i=0; i<6; i++) {
152        if ((arg=="start_1") || (arg=="start_2")) {
153            if (form_fields[i].selectedIndex > opp_fields[i].selectedIndex) {
154                matchFields(form_fields, opp_fields);
155                break;
156            } else if (form_fields[i].selectedIndex < opp_fields[i].selectedIndex) {
157                break;
158            }
159        }
160        if ((arg=="end_1") || (arg=="end_2")) {
161            if (form_fields[i].selectedIndex < opp_fields[i].selectedIndex) {
162                matchFields(form_fields, opp_fields);
163                break;
164            } else if (form_fields[i].selectedIndex > opp_fields[i].selectedIndex) {
165                break;
166            }
167        }
168    }
169}
170
171</SCRIPT>
172"""
173
174
175
Note: See TracBrowser for help on using the repository browser.