PageSourceSearch

https://holyspirit.act.edu.au//js/cf/edit.js

js holyspirit.act.edu.au collected 2026-10-09 00:57:13 UTC 17,775 bytes, 560 lines download raw bytes

1function LoteCfForm() {
2
3}
4
5LoteCfForm.prototype.getCfValues = function (formData, cfArrayName) {
6    const promises = $(".custom_field_edit").map(function (i, e) {
7        if (LoteCfForm.prototype.isInVisibleGroup(e)) {
8            var f = $(e).data('function');
9            if (f && typeof LoteCfForm.prototype[f] == 'function') {
10                return LoteCfForm.prototype[f](formData, e, cfArrayName);
11            }
12        }
13    });
14
15    return Promise.all(promises);
16};
17
18LoteCfForm.prototype.isInVisibleGroup = function (e) {
19    return ! $(".custom_group_edit[data-value='" + $(e).data('group') + "']").hasClass("group_disabled");;
20};
21
22LoteCfForm.prototype.getTextValue = function (formData, e, cfArrayName) {
23    formData[cfArrayName][$(e).attr("data-id")] = $(e).val();
24};
25
26LoteCfForm.prototype.getWysiwygValue = function (formData, e, cfArrayName) {
27    formData[cfArrayName][$(e).attr("data-id")] = getWysiwygValue($(e).attr("id"));
28};
29
30LoteCfForm.prototype.getDateTimeValue = function (formData, e, cfArrayName) {
31    var id = $(e).attr('id');
32    var element = $('#' + id + '_time');
33    var time = timepickiConvert(element);
34
35    var value = null;
36    var date = $('#' + id + '_date_alt').val();
37    if (date && time) {
38        value = date + ' ' + time;
39    }
40    else if (date) {
41        value = date;
42    }
43    else if (time) {
44        value = time;
45    }
46    formData[cfArrayName][$(e).attr("data-id")] = value;
47};
48
49LoteCfForm.prototype.getDateValue = function (formData, e, cfArrayName) {
50    var id = $(e).attr('id');
51    formData[cfArrayName][$(e).attr("data-id")] = $('#' + id + '_date_alt').val();
52};
53
54LoteCfForm.prototype.getTimeValue = function (formData, e, cfArrayName) {
55    var id = $(e).attr('id');
56    var element = $('#' + id + '_time');
57    var time = timepickiConvert(element);
58
59    formData[cfArrayName][$(e).attr("data-id")] = time;
60};
61
62LoteCfForm.prototype.getCheckboxValues = function (formData, e, cfArrayName) {
63    var id = $(e).data('id');
64    var counter = 0;
65    var values = [];
66    $(e.form).find('input[name="checkbox_' + id + '"]').each(function (i, el) {
67        if ($(el).is(":checked")) {
68            values[counter] = $(el).val();
69            counter++;
70        }
71    });
72    if (values.length === 0) {
73        values = "";
74    }
75    formData[cfArrayName][$(e).attr("data-id")] = values;
76};
77
78LoteCfForm.prototype.getRadioValue = function (formData, e, cfArrayName) {
79    var id = $(e).attr('id');
80    var baseObj = [];
81    $.each($(e).find('input[type="radio"]'), function (index, item) {
82        var obj = {};
83        if ($(item).is(':checked')) {
84            obj['id'] = $(item).val();
85
86            var itemValid = true;
87            if ($(item).val() == 0 && $('#cf_field_edit_radio_' + $(e).data('id') + '_custom').is(':visible')) {
88                var customInput = $('#cf_field_edit_radio_' + $(e).data('id') + '_custom').val();
89                obj['value'] = customInput;
90                itemValid = customInput !== '';
91            } else {
92                obj['value'] = $(item).data('value');
93            }
94
95            if (itemValid) {
96                baseObj.push(obj);
97            }
98        }
99    });
100    formData[cfArrayName][$(e).attr("data-id")] = '';
101    if (baseObj.length > 0) {
102        formData[cfArrayName][$(e).attr("data-id")] = JSON.stringify(baseObj);
103    }
104};
105
106LoteCfForm.prototype.getMatrixValues = function (formData, e, cfArrayName) {
107    if (typeof(formData[cfArrayName][$(e).attr("data-default")]) == 'undefined') {
108        formData[cfArrayName][$(e).attr("data-default")] = {};
109    }
110    formData[cfArrayName][$(e).attr("data-default")][$(e).attr("data-id")] = $(e).val();
111};
112
113LoteCfForm.prototype.getRecaptchaValue = function (formData, e, cfArrayName) {
114    formData[cfArrayName][$(e).attr("data-id")] = grecaptcha.getResponse();
115};
116
117LoteCfForm.prototype.getFileValues = function (formData, e, cfArrayName) {
118    return new Promise((resolve, reject) => {
119        var file = e.files[0];
120        if (!file) {
121            return resolve();
122        }
123        var r = new FileReader();
124
125        r.onload = function(read) {
126            var contents = read.target.result;
127            var attr = $(e).attr("data-id")
128            formData[cfArrayName][attr] = contents;
129            resolve();
130        }
131
132        r.readAsDataURL(file)
133    })
134};
135
136LoteCfForm.prototype.getCheckedValues = function (formData, e, cfArrayName) {
137    var name = $(e).data('name');
138    var counter = 0;
139    var values = [];
140    $(e).find('input[name="' + name + '"]').each(function (i, el) {
141        if ($(el).is(":checked")) {
142            values[counter] = $(this).val();
143            counter++;
144        }
145    });
146    formData[cfArrayName][$(e).attr("data-id")] = values;
147};
148
149LoteCfForm.prototype.getOptionValue = function (formData, e, cfArrayName) {
150    var id = $(e).attr('id');
151    var obj = {
152        id: $(e).val()
153    };
154
155    if ($(e).val() == 0 && $('#' + id + '_custom').is(':visible')) {
156        obj['value'] = $('#' + id + '_custom').val();
157    } else if ($(e).val() !== '') {
158        obj['value'] = $(e).find(':selected').data('value');
159    }
160
161    formData[cfArrayName][$(e).attr("data-id")] = '';
162    if (obj.value !== undefined) {
163        formData[cfArrayName][$(e).attr("data-id")] = JSON.stringify([obj]);
164    }
165};
166
167LoteCfForm.prototype.getOptionMultiValue = function (formData, e, cfArrayName) {
168    var id = $(e).attr('id');
169    var baseObj = [];
170    if ($(e).val() !== null) {
171        $.each($(e).val(), function (index, itemId) {
172            var obj = {
173                id: itemId,
174                value: ''
175            };
176
177            var itemValid = true;
178            if (itemId == 0 && $('#' + id + "_custom").is(':visible')) {
179                var customInput = $('#' + id + "_custom").val();
180                obj['value'] = customInput;
181                itemValid = customInput !== '';
182            } else {
183                obj['value'] = $('#' + id + '_option_' + itemId).data('value');
184            }
185
186            if (itemValid) {
187                baseObj.push(obj);
188            }
189        });
190    }
191
192    formData[cfArrayName][$(e).attr("data-id")] = '';
193    if (baseObj.length > 0) {
194        formData[cfArrayName][$(e).attr("data-id")] = JSON.stringify(baseObj);
195    }
196};
197
198var customBaseObjectRemove = [];
199
200LoteCfForm.prototype.getMultiCheckboxValue = function (formData, e, cfArrayName) {
201    var baseObj = [];
202    $.each($(e).find('input[type="checkbox"]'), function (index, item) {
203        var obj = {};
204        if ($(item).is(':checked')) {
205            obj['id'] = $(item).val();
206
207            var itemValid = true;
208            var cfField = $('#cf_field_edit_' + $(e).data('id') + '_custom');
209            if ($(item).val() === 0 && cfField.is(':visible')) {
210                var customInput = cfField.val();
211                obj['value'] = customInput;
212                itemValid = customInput !== '';
213            } else {
214                obj['value'] = $(item).data('value');
215            }
216
217            if (itemValid) {
218                baseObj.push(obj);
219            }
220        } else {
221            obj['id'] = $(item).data('id');
222            customBaseObjectRemove.push(obj);
223        }
224
225    });
226    if (baseObj.length > 0) {
227        formData[cfArrayName][$(e).attr("data-id")] = JSON.stringify(baseObj);
228    }
229    if (baseObj.length === 0 && customBaseObjectRemove.length > 0) {
230        console.log("Remove object", e);
231        formData['_custom_remove'] = JSON.stringify(customBaseObjectRemove);
232    }
233};
234
235function loteCfEditBeforeSerialise(parentForm)
236{
237    var f = new LoteCfForm();
238    f.beforeCfSerialise(parentForm);
239}
240
241function loteCfEditBeforeSubmit(parentForm)
242{
243    var f = new LoteCfForm();
244    return f.beforeCfSubmit(parentForm);
245}
246
247async function getLoteCfEditValues(formData, cfArrayName, parentForm) {
248    formData[cfArrayName] = {};
249    var f = new LoteCfForm();
250    if (parentForm) {
251        await f.getFormCfValues(formData, cfArrayName, parentForm);
252    }
253    else {
254        await f.getCfValues(formData, cfArrayName);
255    }
256    return formData;
257}
258
259
260LoteCfForm.prototype.getFormCfValues = function (formData, cfArrayName, parentForm) {
261    $(parentForm).find(".custom_field_edit").each(function (i, e) {
262        var f = $(e).data('function');
263        if (f && typeof LoteCfForm.prototype[f] == 'function') {
264            LoteCfForm.prototype[f](formData, e, cfArrayName);
265        }
266    });
267};
268
269
270LoteCfForm.prototype.beforeCfSerialise = function (parentForm) {
271    $(parentForm).find(".custom_field_edit").each(function (i, e) {
272        var f = $(e).data('serialise-function');
273        if (f && typeof LoteCfForm.prototype[f] == 'function') {
274            LoteCfForm.prototype[f](parentForm, e);
275        }
276    });
277};
278
279LoteCfForm.prototype.beforeCfSubmit = function (parentForm) {
280    var fields = [];
281    var emptyFields = [];
282    $(parentForm).find('input[type="radio"].custom_field_edit.required').each(function (i, e) {
283        if($(e).is(':checked')) {
284            fields[$(e).attr('name')] = 'required';
285        }
286    });
287    $(parentForm).find('input[type="radio"].custom_field_edit.required').each(function (i, e) {
288        if($(e).is(':checked')) {
289
290        } else {
291            if($(e).attr('name') != undefined && fields[$(e).attr('name')] == undefined) emptyFields[$(e).attr('name')] = 'required';
292        }
293    });
294    setCfErrors(emptyFields, parentForm);
295    if(emptyFields.length > 0) {
296        $('.form_buttons').show();
297        $('.form_processing').hide();
298        return false;
299    }
300};
301
302LoteCfForm.prototype.beforeCfSerialisePublicGroup = function (formData, e, cfArrayName) {
303    var name = $(e).data('name');
304    var publicGroups = {};
305    $(e).parent().find('input[data-key="' + name + '"]').each(function (i, el) {
306        if($(el).is(":checked")){
307            publicGroups[$(el).attr("data-value")] = "1";
308        }
309        else {
310            publicGroups[$(el).attr("data-value")] = "0";
311        }
312    });
313    $(e).val(JSON.stringify(publicGroups));
314};
315
316LoteCfForm.prototype.beforeCfSerialiseMediaFile = function (formData, e, cfArrayName) {
317    var container = jQuery(e).closest('.media_field_container');
318    var numInProgress = jQuery('li.qq-in-progress', container).length;
319    if(numInProgress > 0) {
320        jQuery(e).val("in-progress");
321    } else {
322        jQuery(e).val(jQuery(e).attr('data-media-files'));
323    }
324};
325
326LoteCfForm.prototype.beforeCfSerialiseMatrix = function (formData, e, cfArrayName) {
327    var values = {};
328    var id = $(e).data('id');
329    var matrixType = $(e).data('matrix-type');
330    if(matrixType=="radio" || matrixType=="checkbox") {
331        $(e.form).find('input[data-id="matrix_'+matrixType+'_' + id + '"]').each(function (i, el) {
332            if ($(el).is(":checked")) {
333                if(typeof(values[$(el).data("matrix-row")]) == 'undefined') {
334                    values[$(el).data("matrix-row")] = {};
335                }
336                values[$(el).data("matrix-row")][$(el).data("matrix-column")] = 1;
337            }
338        });
339    }
340    else {
341        $(e.form).find('input[data-id="matrix_text_' + id + '"]').each(function (i, el) {
342            if($(el).val()) {
343                if(typeof(values[$(el).data("matrix-row")]) == 'undefined') {
344                    values[$(el).data("matrix-row")] = {};
345                }
346                values[$(el).data("matrix-row")][$(el).data("matrix-column")] = $(el).val();
347            }
348        });
349    }
350    $(e).val(JSON.stringify(values));
351};
352
353LoteCfForm.prototype.beforeCfSerialiseRecaptcha = function (parentForm, e) {
354    var dataElement = $('#' + $(e).data('id'));
355    $(dataElement).val(grecaptcha.getResponse());
356};
357
358LoteCfForm.prototype.beforeCfSerialiseDate = function (parentForm, e) {
359    var id = $(e).attr('id');
360    $(e).val($('#' + id + '_date_alt').val());
361};
362
363LoteCfForm.prototype.beforeCfSerialiseTime = function (parentForm, e) {
364    var id = $(e).attr('id');
365    var element = $('#' + id + '_time');
366    var time = timepickiConvert(element);
367    $(e).val(time);
368};
369
370LoteCfForm.prototype.beforeCfSerialiseDateTime = function (formData, e, cfArrayName) {
371    var id = $(e).attr('id');
372    var element = $('#' + id + '_time');
373    var time = timepickiConvert(element);
374
375    var value = null;
376    var date = $('#' + id + '_date_alt').val();
377    if (date && time) {
378        value = date + ' ' + time;
379    }
380    else if (date) {
381        value = date;
382    }
383    else if (time) {
384        value = time;
385    }
386    $(e).val(value);
387};
388LoteCfForm.prototype.beforeCfSerialiseSignature = function (formData, e, cfArrayName) {
389
390};
391
392LoteCfForm.prototype.beforeCfSerialiseMultiSelect = function (parentForm, e) {
393    var id = $(e).attr('id');
394    var baseObj = [];
395    if ($(e).val() !== null) {
396        $.each($(e).val(), function (index, itemId) {
397            var obj = {
398                id: itemId,
399                value: ''
400            };
401
402            var itemValid = true;
403            if (itemId == 0 && $('#' + id + "_custom").is(':visible')) {
404                var customInput = $('#' + id + "_custom").val();
405                obj['value'] = customInput;
406                itemValid = customInput !== '';
407            } else {
408                obj['value'] = $('#' + id + '_option_' + itemId).data('value');
409            }
410
411            if (itemValid) {
412                baseObj.push(obj);
413            }
414        });
415    }
416
417    var dataField = $(parentForm).find("input[name='"+$(e).data('id')+"']");
418    if (baseObj.length > 0) {
419        dataField.val(JSON.stringify(baseObj));
420    }
421};
422
423
424LoteCfForm.prototype.beforeCfSerialiseCheckBox = function (parentForm, e) {
425    var id = $(e).attr('id');
426    var dataField = $(parentForm).find("input[name='" + $(e).data('id') + "']");
427    var baseObj = [];
428    $.each($(e).find('input[type="checkbox"]'), function (index, item) {
429        var obj = {};
430        if ($(item).is(':checked')) {
431            obj['id'] = $(item).val();
432
433            var itemValid = true;
434            if ($(item).val() == 0 && $('#cf_field_edit_' + $(e).data('id') + '_custom').is(':visible')) {
435                var customInput = $('#cf_field_edit_' + $(e).data('id') + '_custom').val();
436                obj['value'] = customInput;
437                itemValid = customInput !== '';
438            } else {
439                obj['value'] = $(item).data('value');
440            }
441
442            if (itemValid) {
443                baseObj.push(obj);
444            }
445        }
446    });
447    if (baseObj.length > 0) {
448        dataField.val(JSON.stringify(baseObj));
449    }
450};
451
452
453LoteCfForm.prototype.beforeCfSerialiseRadioButton = function (parentForm, e) {
454    var id = $(e).attr('id');
455    var dataField = $(parentForm).find("input[name='" + $(e).data('id') + "']");
456    var baseObj = [];
457    $.each($(e).find('input[type="radio"]'), function (index, item) {
458        var obj = {};
459        if ($(item).is(':checked')) {
460            obj['id'] = $(item).val();
461
462            var itemValid = true;
463            if ($(item).val() == 0 && $('#cf_field_edit_radio_' + $(e).data('id') + '_custom').is(':visible')) {
464                var customInput = $('#cf_field_edit_radio_' + $(e).data('id') + '_custom').val();
465                obj['value'] = customInput;
466                itemValid = customInput !== '';
467            } else {
468                obj['value'] = $(item).data('value');
469            }
470
471            if (itemValid) {
472                baseObj.push(obj);
473            }
474        }
475    });
476    if (baseObj.length > 0) {
477        dataField.val(JSON.stringify(baseObj));
478    } else {
479        dataField.val("");
480    }
481};
482
483
484LoteCfForm.prototype.beforeCfSerialiseSingleSelect = function (parentForm, e) {
485    var id = $(e).attr('id');
486    var dataField = $(parentForm).find("input[name='"+$(e).data('id')+"']");
487    var obj = {
488        id: $(e).val()
489    };
490
491    var itemValid = true;
492    if ($(e).val() == '0' && $('#' + id + '_custom').is(':visible')) {
493        var customInput = $('#' + id + '_custom').val();
494        obj['value'] = customInput;
495        itemValid = customInput !== '';
496    } else if ($(e).val() !== '') {
497        obj['value'] = $(e).find(':selected').data('value');
498    } else {
499        itemValid = false;
500    }
501
502    var baseObj = [obj];
503
504    if (itemValid) {
505        dataField.val(JSON.stringify(baseObj));
506    }
507};
508
509
510
511
512
513function setCfErrors(errors, form) {
514    for (var f in errors) {
515        if (form) {
516            var htmlError = document.createElement('div');
517            htmlError.textContent = 'There are errors within your form. Please check that all your mandatory fields are completed.';
518            htmlError.setAttribute('class','errorDiv');
519
520            $(form).find('#cf_field_edit_error_' + f).html(errors[f]).closest('.fwrp').addClass('fer');
521            if ($('div.errorDiv').length) {
522
523            } else {
524                $(form).find('.form_buttons').prepend(htmlError);
525            }
526        }
527        else {
528            $('#cf_field_edit_error_' + f).html(errors[f]).closest('.fwrp').addClass('fer');
529        }
530    }
531
532}
533
534function setFormProcessing(form, isProcessing, isBack) {
535    if (isProcessing) {
536        if(isBack){
537            $(form).addClass("is-processing-back");
538        }
539        else{
540            $(form).find('input[type="submit"], button[type="submit"]').prop('disabled', true).addClass("loading");
541            $(form).addClass("is-processing");
542        }
543    }
544    else {
545        if(isBack){
546            $(form).removeClass("is-processing-back");
547        }
548        else{
549            $(form).find('input[type="submit"], button[type="submit"]').prop('disabled', false).removeClass("loading");
550            $(form).removeClass("is-processing");
551        }
552    }
553}
554
555$(function() {
556    $('.only_one_radio').off().on('click', function() {
557        $('.only_one_radio').prop('checked', false);
558        $(this).prop('checked', true);
559    });
560});

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.