Changeset 6977
- Timestamp:
- 10/06/10 23:04:13 (11 years ago)
- Location:
- cows_wps/trunk/cows_wps
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
cows_wps/trunk/cows_wps/public/js/ui/init_bbox_input.js
r6955 r6977 55 55 var bbox_visible = ext.toString(); 56 56 $("#bbox_show_val").html(bbox_visible); 57 57 var bbox_to_send = bbox_visible.replace(/,/g, "|"); 58 58 $("#bbox_hidden_input").val(bbox_to_send); 59 59 } -
cows_wps/trunk/cows_wps/public/js/ui/submit_utils.js
r6903 r6977 1 /* submit_utils.js 1 /* 2 3 submit_utils.js 4 ============= 2 5 3 6 A set of functions and classes related to submission forms. -
cows_wps/trunk/cows_wps/public/js/ui/validate.js
r6124 r6977 5 5 Validation of forms in the UI. 6 6 */ 7 8 // Define validation globals 9 var invalid_input_msg = "You have submitted an invalid input, please try again. "; 7 10 8 11 /* function: validate(): … … 15 18 * allowed length - relevant to arrays 16 19 */ 17 function validate(name, value, data_type, multiple, possible_values, allowed_length) { 18 20 function OLDOLDvalidate(name, value, data_type, multiple, possible_values, allowed_length) { 19 21 } 20 22 … … 32 34 return true; 33 35 } else { 34 alert( "You have submitted an invalid input, please try again. "+ msg)36 alert(invalid_input_msg + msg) 35 37 return false; 36 38 } … … 54 56 55 57 if (item.match(regex_match) == null) { 56 alert( "You have submitted an invalid input, please try again. "+ msg)58 alert(invalid_input_msg + msg) 57 59 return false; 58 60 } 59 61 } 60 62 return true; 63 } 64 65 /* 66 function: checkValidBBox(bbox1); 67 Inputs: 68 * bbox 69 Returns: 70 * true OR false depending if bbox is valid. 71 */ 72 function checkValidBBox(bbox) { 73 // Assume bbox defined as (north, west, south, east) 74 if (bbox[0] < bbox[2]) { 75 return false; 76 } else if ((bbox[0] > 90) || (bbox[2] < -90)) { 77 return false; 78 } else if ((bbox[1] < -360) || (bbox[1] > 360)) { 79 return false; 80 } else if ((bbox[3] < -360) || (bbox[3] > 360)) { 81 return false; 82 } 83 84 return true; 85 } 86 87 /* 88 function: bboxesOverlap(): 89 Checks if two bboxes overlap. 90 Inputs: 91 * bbox1 92 * bbox2 93 Returns: 94 * true OR false 95 */ 96 function bboxesOverlap(bbox1, bbox2) { 97 var bboxes = [bbox1, bbox2]; 98 for (var i = 0; i < 2; i++) { 99 if (checkValidBBox(bboxes[i]) == false) { 100 alert("BBox is invalid: " + (bboxes[i]).join("|") + "."); 101 return false; 102 } 103 } 104 105 // If we get here then bbox definitions are valid 106 if ((bbox1[2] >= bbox2[0]) || (bbox1[0] >= bbox2[2])) { 107 return false; 108 } else if ((bbox1[3] >= bbox2[1]) || (bbox1[1] >= bbox2[3])) { 109 return false; 110 } 111 return true; 112 } 113 114 /* 115 function: parseBBoxString(): 116 Takes in string version of bounding box and returns array version. 117 Inputs: 118 * bbox_string 119 Returns: 120 * bbox_array 121 */ 122 function parseBBoxString(bbox_string) { 123 var input_as_strings = bbox_string.split("|"); 124 var bbox_array = new Array(4); 125 126 for (var i = 0; i < 4; i++) { 127 bbox_array[i] = parseInt(input_as_strings[i], 10); 128 } 129 130 return bbox_array; 131 } 132 133 /* 134 function: validateBoundingBoxInput(): 135 Validates a bounding box input by checking the selected extent overlaps with 136 the prescribed extent. 137 Inputs: 138 * input 139 * allowed_extent 140 * msg 141 Returns: 142 * true OR false: if valid or not. 143 */ 144 function validateBoundingBoxInput(input, valid_bbox, msg) { 145 // Takes in input which comes as 'bbox_hidden_input' string delmited by '|' 146 // which represents (west|east|south|north) 147 // Checks domain is within spec_arg domain 148 var selected_bbox = parseBBoxString(input); 149 var valid_bbox = parseBBoxString(valid_bbox); 150 151 if (bboxesOverlap(selected_bbox, valid_bbox)) { 152 return true; 153 } 154 alert(invalid_input_msg + msg) 155 return false; 61 156 } 62 157 … … 74 169 /* ValidatorMappings is a pseudo-class */ 75 170 function ValidatorMappings() { 76 this.ids = new Array("text", "textarea" );77 this.values = new Array(validateTextInput, validateTextAreaInput );171 this.ids = new Array("text", "textarea", "bounding_box"); 172 this.values = new Array(validateTextInput, validateTextAreaInput, validateBoundingBoxInput); 78 173 79 174 function getFunction(id) { … … 116 211 var name = vdr.name; 117 212 var validation_type = vdr.validation_type; 118 var regex_match = vdr.regex_match; 213 214 // spec_arg can be a regex_match or any other object you want the validator to work with 215 var spec_arg = vdr.spec_arg; 119 216 var msg = vdr.msg; 120 217 var optional = vdr.optional; … … 129 226 res = true; 130 227 } else { 131 res = fnc.call(this, value, regex_match, msg);228 res = fnc.call(this, value, spec_arg, msg); 132 229 } 133 230 -
cows_wps/trunk/cows_wps/renderer/form_renderer.py
r6125 r6977 99 99 return html 100 100 101 def renderBBox(self, name, extent="90|-180|-90|180"):101 def OLDrenderBBox(self, name, extent="90|-180|-90|180"): 102 102 """ 103 103 Renders a bounding box and N/W/S/E/ selectors. … … 120 120 """ 121 121 Renders a bounding box and N/W/S/E selectors. 122 ``extent`` is received as a string of "north|west|south|east". 122 123 """ 123 124 if extent == False: extent = "90|-180|-90|180" … … 130 131 <div id='map'></div> 131 132 </div> 132 <input type="hidden" name="%s" id="bbox_hidden_input" /> 133 <script type="text/javascript">var initial_extent = [%s, %s, %s, %s];</script> 134 </div> 135 """ % (name, n, w, s, e) 133 <input type="hidden" name="%s" id="bbox_hidden_input" /> 134 <script type="text/javascript"> 135 var initial_extent = [%s, %s, %s, %s]; 136 addValidator('%s', 'bounding_box', extent, 'Your selected spatial bounding box must overlap with the available extent of: (%s) as ("north|west|south|east").', false); 137 </script> 138 </div> 139 """ % (name, n, w, s, e, name, extent) 140 136 141 return html 137 142
Note: See TracChangeset
for help on using the changeset viewer.