1 2document.wa_form_v2_flags = {}; 3 4 5 6class WafxFormV2InputFile 7{ 8 static getLabelInputFile(el) 9 { 10 var node_label = el.parentNode.querySelector(".wafx-input-field-label"); 11 return node_label; 12 } 13 static getWrapperLabelInputFile(el) 14 { 15 var node_label = el.parentNode.querySelector(".wafx-input-field-label-wrap"); 16 return node_label; 17 } 18 static markState(el,b,b_override_text) 19 { 20 var node_label_wrap = WafxFormV2InputFile.getWrapperLabelInputFile(el); 21 var node_label = WafxFormV2InputFile.getLabelInputFile(el); 22 23 if (b_override_text) 24 { 25 node_label.innerHTML = node_label.dataset.labelPlaceholder; 26 } 27 28 if (b) 29 { 30 node_label.style.color="darkgray" 31 node_label_wrap.style.backgroundColor="white"; 32 } 33 else 34 { 35 el.value="" 36 node_label.style.color="white" 37 node_label_wrap.style.backgroundColor="red"; 38 } 39 } 40 41 42 static validate(el) 43 { 44 if (el.type=="file") 45 { 46 var maxUpload = el.dataset.maxUpload; 47 48 var total_size = 0; 49 for (var i_file=0;i_file<el.files.length;i_file++) 50 { 51 var file = el.files[i_file]; 52 total_size += file.size; 53 } 54 if (total_size > maxUpload) 55 { 56 WafxFormV2InputFile.markState(el,false,true); 57 return false; 58 } 59 WafxFormV2InputFile.markState(el,true); 60 } 61 return true; 62 } 63} 64 65class WafxFormV2 66{ 67 static clickFile(field) 68 { 69 var f = document.querySelector('input[name="'+field+'"]'); 70 f.click(); 71 } 72 73 static changeInputFile(field) 74 { 75 setTimeout(function(){ 76 77 78 var f = document.querySelector('input[name="'+field+'"]'); 79 var txt = ""; 80 for (var i = 0; i < f.files.length; i++) 81 { 82 var file = f.files[i]; 83 txt +=file.name+" " 84 } 85 WafxFormV2InputFile.markState(f,true); 86 var node_label = WafxFormV2InputFile.getLabelInputFile(f); 87 node_label.innerHTML= txt; 88 89 90 }, 300); 91 92 } 93 94 static alert(txt) 95 { 96 alert(txt) 97 } 98 static send(id_form) 99 { 100 var b_valid = true; 101 var settings = WafxFormV2.m_map_settings[id_form]; 102 103 104 105 var formData = new FormData(); 106 formData.append("wafx_lang",WaPageContext.lang); 107 108 //formData.append("MAX_FILE_SIZE",1000); 109 110 var list_inputs = Array.from(document.querySelectorAll(".wafx-form-input[data-uuid-form='"+id_form+"']")); 111 // alert(list_images.length) 112 list_inputs.sort(function (a, b) 113 { 114 if (a.tabIndex < b.tabIndex) return -1; 115 if (a.tabIndex > b.tabIndex) return 1; 116 117 return 0; 118 }); 119 120 for (var el of list_inputs) 121 { 122 var name = el.getAttribute("name"); 123 { 124 var valField =""; 125 if (el.type=="file") 126 { 127 valField = el.files[0]; 128 129 if (WafxFormV2InputFile.validate(el)==false) 130 { 131 b_valid = false; 132 break; 133 } 134 } 135 else 136 if (el.type=="radio") 137 { 138 if (el.checked) 139 { 140 valField = el.value; 141 } 142 } 143 else 144 if (el.type=="checkbox") 145 { 146 valField = false; 147 if (el.checked) valField = true; 148 } 149 else 150 { 151 valField = el.value; 152 } 153 154 if (el.checkValidity()==false) 155 { 156 el.reportValidity() 157 b_valid = false;; 158 break; 159 } 160 161 if (formData.get(name)!=undefined) 162 { 163 if (valField.length == 0) 164 { 165 valField = formData.get(name); 166 } 167 } 168 else 169 { 170 formData.set(name,valField); 171 } 172 173 // alert("set "+name+"="+valField+" "+el.checked) 174 formData.set(name,valField); 175 } 176 }; 177 178 if ((settings.warning_message!=undefined)&&(settings.warning_message.length>0)) 179 { 180 WafxFormV2.alert(settings.warning_message); 181 return; 182 } 183 // alert(list_inputs.length+" "+JSON.stringify(formData)) 184 185 186 if (b_valid==false) 187 { 188 return; 189 } 190 191 if (WaContext.preview) 192 { 193 194 195 WafxFormV2.alert(settings.preview_message); 196 return; 197 } 198 199 var flag = document.wa_form_v2_flags[id_form]; 200 if (flag==true) 201 { 202 return; 203 } 204 205 document.wa_form_v2_flags[id_form] = true; 206 207 208 for (var el of list_inputs) 209 { 210 var name = el.getAttribute("name"); 211 212 var valField =""; 213 if (el.type=="radio") 214 { 215 el.checked = false; 216 } 217 else 218 if (el.type=="checkbox") 219 { 220 el.checked = false; 221 } 222 else 223 if (el.type=="select") 224 { 225 el.selectedIndex = -1; 226 } 227 else 228 if (el.type=="file") 229 { 230 el.value=''; 231 WafxFormV2InputFile.markState(el,true,true); 232 } 233 else 234 { 235 el.value=''; 236 } 237 238 }; 239 240 fetch(settings.url, { 241 method: "POST", 242 body: formData 243 }) 244 .then(function(response) { 245 return response.text(); 246 }) 247 .then(function(text) { 248 249 var json = JSON.parse(text); 250 if (json.success) 251 { 252 var success_message = settings.success_message; 253 if (success_message.length==0)success_message="Sent successfully !"; 254 WafxFormV2.alert(success_message) 255 } 256 else 257 { 258 WafxFormV2.alert(json.message) 259 } 260 261 document.wa_form_v2_flags[id_form] = false; 262 //alert('Request successful='+text, text); 263 264 }) 265 .catch(function(error) { 266 WafxFormV2.alert('Request failed', error); 267 document.wa_form_v2_flags[id_form] = false; 268 });
269 } 270 271 272 static init(map_settings) 273 { 274 WafxFormV2.m_map_settings = map_settings; 275 //document.addEventListener("DOMContentLoaded", function() {}); 276 } 277} 278
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.