1/* 2 * Copyright 2021 Anyware Services 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17function callURL(formId, formDomId, limit, prefix) 18{ 19 if(limit == "") 20 { 21 return; 22 } 23 $j.ajax({ 24 url: prefix + 'forms/get-submissions-action', 25 method: 'POST', 26 data: { 27 formId: formId 28 }, 29 cache: false, 30 dataType: 'json', 31 success: function(data) { 32 var form = $j("#" + formDomId); 33 if (limit == "" || data.submissions < limit) 34 { 35 form.attr("data-ametys-form-state", "open") 36 } 37 else 38 { 39 form.attr("data-ametys-form-state", "closed") 40 } 41 replaceValues(form.find('*[data-ametys-form-fill ="closed-text"]'), limit, data.submissions) 42 replaceValues(form.find('*[data-ametys-form-fill ="limit-text"]'), limit, data.submissions) 43 }, 44 error: function() { 45 var form = $j("#" + formDomId); 46 form.attr("data-ametys-form-state", "error") 47 }, 48 }); 49} 50 51function replaceValues(node, limit, submissions) 52{ 53 if (node && node.length) 54 { 55 messageToDisplay = node.html().replace(/{remaining}/g, limit - submissions) 56 messageToDisplay = messageToDisplay.replace(/{submissions}/g, submissions) 57 messageToDisplay = messageToDisplay.replace(/{limit}/g, limit) 58 return node.html(messageToDisplay); 59 } 60} 61 62function checkForm(formId, formDomId, errorCheck) 63{ 64 var form = $j("#" + formDomId); 65 var dataState = form.attr("data-ametys-form-state") 66 if (dataState == "closed" || dataState == "loading" || dataState == "error") 67 { 68 return false; 69 } 70 var errors = 0; 71 var ERROR_CLASSNAME = "form-error"; 72 var ERROR_CLASSNAME2 = "invalid"; 73 74 function reset(id, type) 75 { 76 var input = $j("#" + id);
77 var divinput = $j(input.parents(".input")[0]); 78 var label = $j("#" + id + "_label"); 79 80 divinput.removeClass(ERROR_CLASSNAME2); 81 82 input.removeClass(ERROR_CLASSNAME + " " + ERROR_CLASSNAME + "-" + type); 83 input.prop('title', ''); 84 85 label.removeClass(ERROR_CLASSNAME); 86 label.prop('title', ''); 87 } 88 89 function error(id, type, message) 90 { 91 var input = $j("#" + id); 92 var divinput = $j(input.parents(".input")[0]); 93 var label = $j("#" + id + "_label"); 94 95 divinput.addClass(ERROR_CLASSNAME2); 96 97 var currentMessage = input.prop('title'); 98 currentMessage = currentMessage == null || currentMessage == "" ? message : currentMessage + " - " + message; 99 100 var currentLabelMessage = label.prop('title'); 101 currentLabelMessage = currentLabelMessage == null || currentLabelMessage == "" ? message : currentLabelMessage + " - " + message; 102 103 input.addClass(ERROR_CLASSNAME + " " + ERROR_CLASSNAME + "-" + type); 104 input.prop('title', currentMessage); 105 106 label.addClass(ERROR_CLASSNAME); 107 label.prop('title', currentLabelMessage); 108 109 errors++; 110 } 111 112 errorCheck(reset, error); 113 114 if (errors != 0) 115 { 116 alert("The form has " + errors + " error(s).\nPlease correct it (them) before proceeding.\n\nYou can hover a highlighted field with the cursor for more details."); 117 } 118 return errors == 0; 119} 120 121function computeFormCost(element) 122{ 123 var cost = 0.0; 124 125 var form = $j(element).parents("form").first(); 126 form.find("select[data-partofcost='true'] option:selected").each(function(index, option) { 127 var c = parseFloat(($j(option).attr("data-cost") || "0").trim()) 128 if (!isNaN(c)) 129 { 130 cost += c; 131 } 132 }); 133 134 form.find("input[data-unit]").each(function(index, input) { 135 input.value = cost.toLocaleString($j(input).attr("data-lang"), {style: 'currency', currency: $j(input).attr("data-unit")}); 136 }); 137}
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.