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

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

Put all the old code in the old_stuff branch.

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
10js_dateCheckFunctionGroup="""
11<SCRIPT LANGUAGE="Javascript">
12
13var frm=document.forms[0];
14var dateMinimum_1 = new Array(%s, %s, %s, %s, %s, %s);
15var dateMaximum_1 = new Array(%s, %s, %s, %s, %s, %s);
16var dateMinimum_2 = new Array(%s, %s, %s, %s, %s, %s);
17var dateMaximum_2 = new Array(%s, %s, %s, %s, %s, %s);
18
19function getFormFields(arg) {
20    // getFormFields - returns an array of form fields to manipulate based on the argument given.
21    if (arg == "start_1") {
22        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);
23    } else if (arg == "end_1") {
24        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);
25    } else if (arg == "start_2") {
26        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);
27    } else if (arg == "end_2") {
28        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);
29    }
30    return fields
31}
32
33function getOppositeFields(arg) {
34    // getOppositeFields - returns an array of form fields opposite to the argument argument given.
35    if (arg == "end_1") {
36        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);
37    } else if (arg == "start_1") {
38        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);
39    } else if (arg == "end_2") {
40        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);
41    } else if (arg == "start_2") {
42        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);
43    }
44    return fields
45}
46
47function matchFields(fields1, fields2) {
48    // matchFields - sets one set of form fields equal to another
49    for (i=0; i<6; i++) {
50        fields2[i].selectedIndex = fields1[i].selectedIndex;
51    }
52}
53
54function getDateMinimum(arg) {
55    // getDateMinimum function - to return the minimum date for the appropriate fields
56    if ((arg=="start_1") || (arg=="end_1")) {
57        var dateMinimum = dateMinimum_1;
58    } else if ((arg=="start_2") || (arg=="end_2")) {
59        var dateMinimum = dateMinimum_2;
60    }
61    return dateMinimum;
62}
63
64function getDateMaximum(arg) {
65    // getDateMaximum function - to return the maximum date for the appropriate fields
66    if ((arg=="start_1") || (arg=="end_1")) {
67        var dateMaximum = dateMaximum_1;
68    } else if ((arg=="start_2") || (arg=="end_2")) {
69        var dateMaximum = dateMaximum_2;
70    }
71    return dateMaximum;
72}
73
74function resetDate(arg) {
75    // resetDate function - resets the date field selected to either max or min possible.
76    var form_fields = getFormFields(arg);
77    var dateMinimum = getDateMinimum(arg);
78    for (i=0; i<6; i++) {
79        form_fields[i].selectedIndex = dateMinimum[i];
80    }
81}
82
83
84function resetAllDates(n) {
85    // resetAllDates function - resets all date fields to minimum allowed.
86    resetDate("start_1");
87    resetDate("end_1");
88    if (n>1) {
89        resetDate("start_2");
90        resetDate("end_2");
91    }
92}
93
94
95function checkDate(arg) {
96    // checkDate function - checks start date is not below minimum.
97    var form_fields = getFormFields(arg);
98    var dateMinimum = getDateMinimum(arg);
99    var dateMaximum = getDateMaximum(arg);
100     
101    if (form_fields[0].selectedIndex < dateMinimum[0]) {
102        resetDate(arg);
103    } else if (form_fields[0].selectedIndex == dateMinimum[0]) {
104        if (form_fields[1].selectedIndex < dateMinimum[1]) {
105            resetDate(arg);
106        } else if (form_fields[1].selectedIndex == dateMinimum[1]) {
107            if (form_fields[2].selectedIndex < dateMinimum[2]) {
108                resetDate(arg);
109            } else if (form_fields[2].selectedIndex == dateMinimum[2]) {
110                if (form_fields[3].selectedIndex < dateMinimum[3]) {
111                    resetDate(arg);
112                } else if (form_fields[3].selectedIndex == dateMinimum[3]) {
113                    if (form_fields[4].selectedIndex < dateMinimum[4]) {
114                        resetDate(arg);
115                    } else if (form_fields[4].selectedIndex == dateMinimum[4]) {
116                        if (form_fields[5].selectedIndex < dateMinimum[5]) {
117                            resetDate(arg);
118                        }
119                    }
120                }
121            }
122        }
123    } else if (form_fields[0].selectedIndex == dateMaximum[0]) {
124        if (form_fields[1].selectedIndex > dateMaximum[1]) {
125            resetDate(arg);
126        } else if (form_fields[1].selectedIndex == dateMaximum[1]) {
127            if (form_fields[2].selectedIndex > dateMaximum[2]) {
128                resetDate(arg);
129            } else if (form_fields[2].selectedIndex == dateMaximum[2]) {
130                if (form_fields[3].selectedIndex > dateMaximum[3]) {
131                    resetDate(arg);
132                } else if (form_fields[3].selectedIndex == dateMaximum[3]) {
133                    if (form_fields[4].selectedIndex > dateMaximum[4]) {
134                        resetDate(arg);
135                    } else if (form_fields[4].selectedIndex == dateMaximum[4]) {
136                        if (form_fields[5].selectedIndex > dateMaximum[5]) {
137                            resetDate(arg);
138                        }
139                    }
140                }
141            }
142        }   
143    }
144    // Now check the order of the fields to make sure start is not after end
145    var opp_fields  = getOppositeFields(arg);
146    for (i=0; i<6; i++) {
147        if ((arg=="start_1") || (arg=="start_2")) {
148            if (form_fields[i].selectedIndex > opp_fields[i].selectedIndex) {
149                matchFields(form_fields, opp_fields);
150                break;
151            } else if (form_fields[i].selectedIndex < opp_fields[i].selectedIndex) {
152                break;
153            }
154        }
155        if ((arg=="end_1") || (arg=="end_2")) {
156            if (form_fields[i].selectedIndex < opp_fields[i].selectedIndex) {
157                matchFields(form_fields, opp_fields);
158                break;
159            } else if (form_fields[i].selectedIndex > opp_fields[i].selectedIndex) {
160                break;
161            }
162        }
163    }
164}
165
166</SCRIPT>
167"""
168
169
170
Note: See TracBrowser for help on using the repository browser.