1"use strict"; 2 3{ 4 window.GFACL = { 5 logic: {}, 6 }; 7 if (window.GFACL.logic !== undefined) { 8 console.debug("GFACL Logic already exists", GFACL); 9 } 10 11 window.GFACL_Logic = function (args) { 12 console.debug("Setup GFACL_Logic", GFACL); 13 //This will now be initalized each page load (so could be called multiple times in a single browser page if ajax is enabled) 14 if (!args.formId) { 15 console.warn("formid is required for GFACL_Logic", args); 16 return; 17 } 18 19 if (window.GFACL.logic[args.formId] !== undefined) { 20 console.warn("GFACL_Logic already exists for formId", args.formId); 21 return; 22 } 23 24 // add the logic to the global object 25 console.debug("setup GFACL_Logic", args, this); 26 27 var self = this; 28 29 // copy all args to current object: (list expected props) 30 for (const prop in args) { 31 if (args.hasOwnProperty(prop)) { 32 self[prop] = args[prop]; 33 } 34 } 35 36 //self.formId = args.formId; 37 38 self.doingLogic = false; 39 40 gform.addAction( 41 "gform_frontend_pages_evaluated", 42 function (pages, formId, pageObject) { 43 console.debug("gform_frontend_pages_evaluated", formId); 44 if (formId == self.formId) { 45 self.pageObject = pageObject; 46 } 47 } 48 ); 49 50 self.is_value_match = function (isMatch, formId, rule) { 51 if (formId != self.formId) { 52 return isMatch; 53 } 54 55 if (rule.value == "__return_true") { 56 isMatch = true; 57 } else if (rule.value == "__return_false") { 58 isMatch = false; 59 } 60 61 // console.debug("is_value_match", isMatch, formId, rule); 62 return isMatch; 63 }; 64 65 // add filter to allow for pre-evaluation of rules 66 self.rule_pre_evaluation = function (rule, formId, conditionalLogic) { 67 // console.debug("rule_pre_evaluation", rule, formId, conditionalLogic); 68 if ( 69 formId != self.formId || 70 !rule || 71 rule.fieldId != "__adv_cond_logic" 72 ) { 73 return rule; 74 } 75 76 var logic = self.logic[rule.value]; 77 if (!logic) { 78 console.warn("No advanced logic found for ", rule.value); 79 return rule; 80 } 81 82 for (var i in logic.groups) { 83 if (logic.groups.hasOwnProperty(i)) { 84 var group = logic.groups[i];
85 group.rules.forEach((r) => (r.value = String(r.value))); 86 var action = gf_get_field_action(formId, group); 87 if (action == "show" || action == "send") { 88 rule.value = "__return_true"; 89 break; 90 } else { 91 rule.value = "__return_false"; 92 } 93 } 94 } 95 rule.fieldId = "__adv_cond_logic-processed"; 96 97 return rule; 98 //get the relevant logic 99 }; 100 101 // do the magic 102 103 self.getFieldIds = function () { 104 var fieldIds = []; 105 if (!self.logic) { 106 return fieldIds; 107 } 108 109 Object.keys(self.logic).forEach(function (logickey) { 110 if (!logickey.startsWith("field")) { 111 return; 112 } else { 113 var fieldId = logickey.split("/")[1]; 114 if (fieldId && !self.pages?.includes?.(String(fieldId))) { 115 fieldIds.push(fieldId); 116 } 117 } 118 }); 119 return fieldIds; 120 }; 121 122 /** 123 * Initiate the logic and apply the rules to the form 124 */ 125 self.init = function () { 126 console.debug("init", self.formId, self.logic, self.pages); 127 128 gform.addFilter("gform_rule_pre_evaluation", self.rule_pre_evaluation); 129 gform.addFilter("gform_is_value_match", self.is_value_match); 130 131 // var fieldIds = self.getFieldIds(); 132 // gf_apply_rules(self.formId, fieldIds, true); 133 }; 134 self.init(); 135 }; 136 137 /** 138 * @param {Number} formId 139 * @param {Number|String} rawFieldId 140 * @returns {String|Number} The Field Values 141 */ 142 window.gfacl_get_field_values = function (formId, rawFieldId) { 143 var $ = jQuery, 144 fieldId = gformExtractFieldId(rawFieldId), 145 inputIndex = gformExtractInputIndex(rawFieldId), 146 isInputSpecific = inputIndex !== false, 147 $inputs, 148 formattedValues = new Array(), 149 values = new Array(); 150 151 if (isInputSpecific) { 152 $inputs = $( 153 "#input_{0}_{1}_{2}".gformFormat(formId, fieldId, inputIndex) 154 ); 155 } else { 156 $inputs = $( 157 'input[id="input_{0}_{1}"], input[id^="input_{0}_{1}_"], input[id^="choice_{0}_{1}_"], select#input_{0}_{1}, textarea#input_{0}_{1}'.gformFormat( 158 formId, 159 fieldId 160 ) 161 ); 162 } 163 164 var isCheckable = 165 $.inArray($inputs.attr("type"), ["checkbox", "radio"]) !== -1; 166 167 if (isCheckable) { 168 $inputs.each(function () { 169 var $input = jQuery(this); 170 var theFieldValue = gf_get_value($input.val()); 171 172 // force an empty value for unchecked items 173 if (!$input.is(":checked")) { 174 theFieldValue = ""; 175 values.push(""); 176 } 177 // if the 'other' choice is selected, get the value from the 'other' text input 178 else if (fieldValue == "gf_other_choice") { 179 theFieldValue = $( 180 "#input_{0}_{1}_other".gformFormat(formId, fieldId) 181 ).val(); 182 } 183 values.push(theFieldValue); 184 }); 185 //handle multiple values 186 } else { 187 var val = $inputs.eq(0).val(); 188 if (val instanceof Array) { 189 // handle cases where a single field has multiple values (e.g., a select allowing multiple selections) 190 values = val.map(gf_get_value); 191 } else { 192 // handle single values 193 val = gf_get_value(val); 194 values = val instanceof Array ? val : [val]; 195 } 196 } 197 198 for (var i = 0; i < values.length; i++) { 199 var hasLabel = values[i] ? values[i].indexOf("|") >= 0 : true, 200 fieldValue = gf_get_value(values[i]); 201 202 var fieldNumberFormat = gf_get_field_number_format( 203 rawFieldId, 204 formId, 205 "value" 206 ); 207 if (fieldNumberFormat && !hasLabel) { 208 fieldValue = gf_format_number(fieldValue, fieldNumberFormat); 209 } 210 211 formattedValues.push(fieldValue); 212 } 213 214 return formattedValues; 215 }; 216 217 /** 218 * @deprecated 219 * @param {*} formId 220 * @param {*} rawFieldId 221 */ 222 window.advLog_get_field_values = function (formId, rawFieldId) { 223 return window.gfacl_get_field_values(formId, rawFieldId); 224 }; 225}
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.