PageSourceSearch

https://fida.org.ng/wp-content/plugins/js-support-ticket/includes/js/common.js?ver=317.1789456333

js fida.org.ng collected 2026-10-02 05:50:19 UTC 16,225 bytes, 294 lines download raw bytes

1jQuery(document).ready(function(n){
2    jQuery('.specialClass').closest("div.js-form-custm-flds-wrp").removeClass('visible');
3    jQuery('.specialClass').closest("div.js-ticket-from-field-wrp").removeClass('visible');
4});
5
6function fillSpaces(string){
7	string = string.replace(" ", "%20");
8	return string;
9}
10
11function getDataForDepandantField(wpnonce, parentf, childf, type) {
12    if (type == 1) {
13        var val = jQuery("select#" + parentf).val();
14    } else if (type == 2) {
15        var val = jQuery("input[name=\'" + parentf + "\']:checked").val();
16    }
17
18    jQuery.post(ajaxurl, {action: 'jsticket_ajax', jstmod: 'fieldordering', task: 'DataForDepandantField', fvalue: val, child: childf, '_wpnonce':wpnonce}, function (data) {
19        if (data) {
20            var d = jQuery.parseJSON(data);
21            jQuery("select#" + childf).replaceWith(jsstDecodeHTML(d));
22        }
23    });
24}
25
26
27function getDataForVisibleField(wpnonce, val, fieldname, conditionGroups) {
28    // var childs = fieldname.split(",");
29    var field_type = 'required';
30    var finalShow = false;
31
32    jQuery.each(conditionGroups, function(conditionGroupIndex, conditionGroup) {
33        jQuery.each(conditionGroup, function(orConditionIndex, orCondition) {
34            var childs = orCondition[0].visibleParentField.split(",");
35            // old code start
36            jQuery.each(childs, function(childi, childf) {
37                var type = jQuery('[name="'+childf+'"]').attr("type");
38
39                // Reset the field value
40                if (type == 'text' || type == 'email' || type == 'password' || type == 'file') {
41                    jQuery('[name="'+childf+'"]').val('');
42                } else if (type == 'checkbox') {
43                    jQuery('[name="'+childf+'[]"]').prop('checked', false);
44                    jQuery('[name="'+childf+'"]').prop('checked', false);
45                } else if (type == 'radio') {
46                    jQuery('[name="'+childf+'"]').prop('checked', false);
47                } else if (jQuery('[name="'+childf+'"]').hasClass("js-ticket-custom-textarea")) {
48                    jQuery('[name="'+childf+'"]').val("");
49                } else if (jQuery('[name="'+childf+'"]').hasClass("js-ticket-custom-select")) {
50                    jQuery('[name="'+childf+'"]').prop('selectedIndex', 0);
51                } else {
52                    if (jQuery('[name="'+childf+'[]"]').attr("type") == 'checkbox') {
53                        field_type = 'notRequired';
54                    }
55                    type = "checkboxOrMultiple";
56                    if (jQuery('[name="'+childf+'[]"]').attr("multiple")) {
57                        jQuery('[name="'+childf+'[]"]').children().prop('selected', false);
58                        jQuery('[name="'+childf+'[]"]').prop('selectedIndex', 0);
59                    } else {
60                        jQuery('[name="'+childf+'[]"]').prop('checked', false);
61                    }
62                }
63
64                
65                if (val.length != 0) {
66                    if (conditionGroups.hasOwnProperty(childf)) {
67                        var conditionsArray = conditionGroups[childf];
68                        // code start
69                        finalShow = false; // Will become true if all groups pass
70
71                        if (conditionsArray.length > 0) {
72                            var allGroupsPass = true;
73
74                            jQuery.each(conditionsArray, function(groupIndex, group) {
75                                var groupPass = false; // Assume group fails unless a condition is true
76
77                                jQuery.each(group, function(conditionIndex, condition) {
78                                    console.log(condition);
79                                    var result = false;
80                                    var isUserField = condition.visibleParent.indexOf('ufield_') !== -1;
81                                    let selector;
82
83                                    if (condition.visibleCondition === "1" || condition.visibleCondition === "0") {
84                                        // Select field
85                                        selector = isUserField
86                                            ? "select#" + condition.visibleParent
87                                            : "select#" + condition.visibleParent + "id";
88
89                                        $jsst_field = jQuery(selector);
90                                        // If not found, fallback to checkbox group selector
91                                        if ($jsst_field.length === 0) {
92                                            $jsst_field = jQuery("input[type='checkbox'][id^='" + condition.visibleParent + "_']");
93                                        }
94                                        // If not found, fallback to radiobutton group selector
95                                        if ($jsst_field.length === 0) {
96                                            $jsst_field = jQuery("input[type='radio'][id^='" + condition.visibleParent + "_']");
97                                        }
98                                        // If not found, fallback to multiselect group selector
99                                        if ($jsst_field.length === 0) {
100                                            $jsst_field = jQuery("select[id^='" + condition.visibleParent + "[]']");
101                                        }
102                                        // If not found, fallback to multiselect group selector
103                                        if ($jsst_field.length === 0) {
104                                            $jsst_field = false;
105                                        }
106                                        
107                                        let fieldval = null;
108
109                                        if ($jsst_field. length > 0) {
110                                            var tag = $jsst_field.prop("tagName").toLowerCase();
111                                            var type = $jsst_field.attr("type");
112
113                                            if (tag === "select") {
114                                                // Handles both single and multi-select dropdowns
115                                                var isMultiSelect = $jsst_field.prop("multiple") === true;
116                                                if (isMultiSelect) {
117                                                    fieldval = [];
118                                                    $jsst_field.find("option:selected").each(function () {
119                                                        fieldval.push(this.value);
120                                                    });
121                                                } else {
122                                                    fieldval = $jsst_field.val(); // jQuery returns array for multi-select
123                                                }
124                                            } else if (type === "checkbox") {
125                                                // Handle checkbox group (collect all checked values)
126                                                fieldval = [];
127                                                $jsst_field.filter(":checked").each(function () {
128                                                    fieldval.push(this.value);
129                                                });
130                                            } else if (type === "radio") {
131                                                // Handle radio button group
132                                                fieldval = jQuery("input[name='" + condition.visibleParent + "']:checked").val();
133                                            } else {
134                                                // Fallback for other input types
135                                                fieldval = $jsst_field.val();
136                                            }
137                                        }
138
139                                        if (condition.visibleCondition === "1") {
140                                            result = Array.isArray(fieldval) 
141                                                ? fieldval.includes(condition.visibleValue) 
142                                                : fieldval == condition.visibleValue;
143                                        } else {
144                                            if (Array.isArray(fieldval)) {
145                                                // Prevent condition from being true when nothing is selected
146                                                result = fieldval.length > 0 && !fieldval.includes(condition.visibleValue);
147                                            } else {
148                                                result = fieldval != condition.visibleValue;
149                                            }
150                                        }
151                                    } else if (condition.visibleCondition === "2" || condition.visibleCondition === "3") {
152                                        // Input field (no 'id' suffix regardless of isUserField)
153                                        selector = "#" + condition.visibleParent;
154                                        if (selector == '#fullname') {
155                                            selector = '.js-support-ticket-form #name';
156                                        }
157                                        fieldval = jQuery(selector).val();
158
159                                        if (fieldval !== undefined && fieldval !== null) {
160                                            let fieldvalLower = decodeStoredValue(fieldval).toLowerCase();
161                                            let valueLower = decodeStoredValue(condition.visibleValue).toLowerCase();
162                                            
163                                            if (condition.visibleCondition === "2") {
164                                                result = fieldvalLower.indexOf(valueLower) !== -1;  // contains
165                                            } else {
166                                                result = fieldvalLower.indexOf(valueLower) === -1;  // does not contain
167                                            }
168                                        } else {
169                                            result = false;
170                                        }
171
172                                    } else {
173                                        result = false; // default/fallback
174                                    }
175
176                                    // Since inside a group we want OR relation
177                                    if (result) {
178                                        groupPass = true; // If any condition passes, the group passes
179                                        return false; // Break inner loop
180                                    }
181                                });
182
183                                // If any group fails, final result is false
184                                if (!groupPass) {
185                                    allGroupsPass = false;
186                                    return false; // Break outer loop
187                                }
188                            });
189
190                            finalShow = allGroupsPass;
191                        }
192
193                        // Based on finalShow, show or hide the field
194
195                        if (finalShow) {
196                            if (type == 'checkboxOrMultiple') {
197                                jQuery('[name="'+childf+'[]"]').closest("div.js-form-custm-flds-wrp").removeClass('visible');
198                                jQuery('[name="'+childf+'[]"]').closest("div.js-ticket-from-field-wrp").removeClass('visible');
199                            } else {
200                                jQuery('[name="'+childf+'"]').closest("div.js-form-custm-flds-wrp").removeClass('visible');
201                                jQuery('[name="'+childf+'"]').closest("div.js-ticket-from-field-wrp").removeClass('visible');
202                            }
203                            isFieldRequired(field_type, childf, 'show', wpnonce);
204                        } else {
205                            if (type == 'checkboxOrMultiple') {
206                                jQuery('[name="'+childf+'[]"]').closest("div.js-form-custm-flds-wrp").addClass('visible');
207                                jQuery('[name="'+childf+'[]"]').closest("div.js-ticket-from-field-wrp").addClass('visible');
208                            } else {
209                                jQuery('[name="'+childf+'"]').closest("div.js-form-custm-flds-wrp").addClass('visible');
210                                jQuery('[name="'+childf+'"]').closest("div.js-ticket-from-field-wrp").addClass('visible');
211                            }
212                            isFieldRequired(field_type, childf, 'hide', wpnonce);
213                        }
214                        // code end
215                    } else {
216                        if (type == 'checkboxOrMultiple') {
217                            jQuery('[name="'+childf+'[]"]').closest("div.js-form-custm-flds-wrp").addClass('visible');
218                            jQuery('[name="'+childf+'[]"]').closest("div.js-ticket-from-field-wrp").addClass('visible');
219                        } else {
220                            jQuery('[name="'+childf+'"]').closest("div.js-form-custm-flds-wrp").addClass('visible');
221                            jQuery('[name="'+childf+'"]').closest("div.js-ticket-from-field-wrp").addClass('visible');
222                        }
223                    }
224
225                } else {
226                    // If no value is selected, show or hide based on the field type
227                    if (type == 'checkboxOrMultiple') {
228                        jQuery('[name="'+childf+'[]"]').closest("div.js-form-custm-flds-wrp").addClass('visible');
229                        jQuery('[name="'+childf+'[]"]').closest("div.js-ticket-from-field-wrp").addClass('visible');
230                    } else {
231                        jQuery('[name="'+childf+'"]').closest("div.js-form-custm-flds-wrp").addClass('visible');
232                        jQuery('[name="'+childf+'"]').closest("div.js-ticket-from-field-wrp").addClass('visible');
233                    }
234                    isFieldRequired(field_type, childf, 'hide', wpnonce);
235                }
236            });
237            // old code end
238        });
239    });
240}
241
242function decodeStoredValue(encoded) {
243    try {
244        // Step 1: Decode HTML entities like "
245        const textarea = document.createElement("textarea");
246        textarea.innerHTML = encoded;
247        let decoded = textarea.value;
248
249        // Step 2: Decode \u4f60\u597d to real characters
250        // Wrap in double quotes and parse
251        decoded = JSON.parse('"' + decoded.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"');
252
253        return decoded;
254    } catch (e) {
255        return encoded; // fallback
256    }
257}
258
259function deleteCutomUploadedFile (field1) {
260    jQuery("input#"+field1).val(1);
261    jQuery("span."+field1).hide();
262    
263}
264
265function isFieldRequired (field_type, field, state, wpnonce) {
266    jQuery.post(ajaxurl, {action: 'jsticket_ajax', jstmod: 'ticket', task: 'isFieldRequired', field:field, '_wpnonce':wpnonce}, function (data) {
267        if (data) {
268            if (data == 1 && state == 'show' && field_type == 'required') {
269                jQuery('[name="'+field+'"]').attr('data-validation', 'required');
270                jQuery('[name="'+field+'[]"]').attr('data-validation', 'required');
271            } else if(data == 1 && state == 'hide') {
272                jQuery('[name="'+field+'"]').attr('data-validation', '');
273                jQuery('[name="'+field+'[]"]').attr('data-validation', '');
274            }
275        }
276    });
277    
278}
279
280function jsstDecodeHTML(html) {
281    var txt = document.createElement('textarea');
282    txt.innerHTML = html;
283    return txt.value;
284}
285
286function jsReplyShowLoading(){
287    jQuery('div#black_wrapper_ai_reply').show();
288    jQuery('div#js_ai_reply_loading').show();
289}
290
291function jsReplyHideLoading(){
292    jQuery('div#black_wrapper_ai_reply').hide();
293    jQuery('div#js_ai_reply_loading').hide();
294}

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.