<commit_before>// Namespace for caAERS-specific shared functions and classes
var AE = { }


AE.DWR_ERROR_HANDLER_REGISTERED=false;
AE.SUBMISSION_INPROGRESS=false;

AE.INDICATOR_REF_COUNTS = { };
AE.hash = new Hash();
// This flag determins whether to check for modification, pages can override this to false.
AE.checkForModification = false; 

//True if the form fields are modified
AE.formFieldModified=false;

//no of fields available in the form, when page loaded.
AE.formFieldCount=0;

//will store the selected reports
AE.checkedReports = new Array();

// this stuff should technically be synchronized.  Let see if it causes a problem.
AE.showIndicator = function(id) {
    if (!AE.INDICATOR_REF_COUNTS[id]) AE.INDICATOR_REF_COUNTS[id] = 0;
    AE.INDICATOR_REF_COUNTS[id] += 1
    AE.updateIndicatorVisibility(id)
}

AE.hideIndicator = function(id) {
    if (!AE.INDICATOR_REF_COUNTS[id]) AE.INDICATOR_REF_COUNTS[id] = 0;
    AE.INDICATOR_REF_COUNTS[id] -= 1;
    if (AE.INDICATOR_REF_COUNTS[id] < 0) AE.INDICATOR_REF_COUNTS[id] = 0;
    AE.updateIndicatorVisibility(id)
}

AE.updateIndicatorVisibility = function(id) {
    if (AE.INDICATOR_REF_COUNTS[id] > 0) {
        $(id).reveal();
    } else {
        $(id).conceal();
    }
}

////// PROTOTYPE EXTENSIONS
// TODO: This code is shared with PSC.

Element.addMethods( {
    // Like prototype's hide(), but uses the visibility CSS prop instead of display
    conceal: function() {
        for (var i = 0; i < arguments.length; i++) {
            var element = $(arguments[i]);
            element.style.visibility = 'hidden';
        }
    },

    // Like prototype's show(), but uses the visibility CSS prop instead of display
    reveal: function() {
        for (var i = 0; i < arguments.length; i++) {
            var element = $(arguments[i]);
            element.style.visibility = 'visible';
        }
    },

    // Disable all form elements contained in this element and add the class "disabled"
    disableDescendants: function() {
        for (var i = 0; i < arguments.length; i++) {
            var element = $(arguments[i]);
            element.addClassName("disabled")
            element.descendants().each(function(elt) {
                if (elt.disable) elt.disable()
            })
        }
    },

    // Enable all form elements contained in this element and remove the class "disabled"
    enableDescendants: function() {
        for (var i = 0; i < arguments.length; i++) {
            var element = $(arguments[i]);
            element.removeClassName("disabled")
            element.descendants().each(function(elt) {
                if (elt.enable) elt.enable()
            })
        }
    }
} );

Form.selectedRadioValue = function(form, radioName) {
    var pair = $A($(form)[radioName])
        .collect(Form.Element.Serializers.inputSelector)
        .detect(function(e) { return e != null })
    return pair ? pair[1] : null;
}

////// CALENDAR POPUP HANDLERS

AE.registerCalendarPopups = function(containerId) {
    var sel = "input.date"
    if (containerId) sel = "#" + containerId + " " + sel
    $$(sel).each(function(input) {
        var anchorId = input.id + "-calbutton"
        Calendar.setup(
            {
                inputField  : input.id,
                button      : anchorId,
                ifFormat    : "%m/%d/%Y", // TODO: get this from the configuration
                weekNumbers : false,
                onSelect    : function(cal) {
                    input.value = cal.date.print('%m') + "/" + cal.date.print('%d') + "/" + cal.date.print('%Y');
                    ValidationManager.setNormalState(input);
                    if(cal.dateClicked)
	                    cal.callCloseHandler();
                }
            }
        );
    })
    
    //for split-date
    sel ="input.split-date"
    if (containerId) sel = "#" + containerId + " " + sel
    $$(sel).each(function(input) {
    	var yearInputId = input.id
		var baseInputId = input.id.substring(0, input.id.lastIndexOf('.yearString'))
        var anchorId = baseInputId + "-calbutton"
        var monthInputId = baseInputId + ".monthString"
        var dayInputId = baseInputId + ".dayString"
        
        Calendar.setup(
            {
                'yearInputId' : yearInputId,
                'monthInputId': monthInputId,
                'dayInputId'  :dayInputId,
                button        : anchorId,
                ifFormat      : "%m/%d/%Y", // TODO: get this from the configuration
                weekNumbers   : false,
                onSelect      : function(cal){
                	$(cal.params['dayInputId']).value = cal.date.print('%d');
                	$(cal.params['monthInputId']).value = cal.date.print('%m');
                	$(cal.params['yearInputId']).value =  cal.date.print('%Y');

                    ValidationManager.setNormalState($(cal.params['dayInputId']));
                    ValidationManager.setNormalState($(cal.params['monthInputId']));
                    ValidationManager.setNormalState($(cal.params['yearInputId']));
                    
                    if(cal.dateClicked)
	                    cal.callCloseHandler();
                }
            }
        );
    })    
}


////// FORM EDITING

// Provides a uniform set of functions for editing a form containing a<commit_msg>CAAERS-4448<commit_after>// Namespace for caAERS-specific shared functions and classes
var AE = { }


AE.DWR_ERROR_HANDLER_REGISTERED=false;
AE.SUBMISSION_INPROGRESS=false;

AE.INDICATOR_REF_COUNTS = { };
AE.hash = new Hash();
// This flag determins whether to check for modification, pages can override this to false.
AE.checkForModification = false; 

//True if the form fields are modified
AE.formFieldModified=false;

//no of fields available in the form, when page loaded.
AE.formFieldCount=0;

//will store the selected reports
AE.checkedReports = new Array();

// this stuff should technically be synchronized.  Let see if it causes a problem.
AE.showIndicator = function(id) {
    if (!AE.INDICATOR_REF_COUNTS[id]) AE.INDICATOR_REF_COUNTS[id] = 0;
    AE.INDICATOR_REF_COUNTS[id] += 1
    AE.updateIndicatorVisibility(id)
}

AE.hideIndicator = function(id) {
    if (!AE.INDICATOR_REF_COUNTS[id]) AE.INDICATOR_REF_COUNTS[id] = 0;
    AE.INDICATOR_REF_COUNTS[id] -= 1;
    if (AE.INDICATOR_REF_COUNTS[id] < 0) AE.INDICATOR_REF_COUNTS[id] = 0;
    AE.updateIndicatorVisibility(id)
}

AE.updateIndicatorVisibility = function(id) {
    if (AE.INDICATOR_REF_COUNTS[id] > 0) {
        $(id).reveal();
    } else {
        $(id).conceal();
    }
}

////// PROTOTYPE EXTENSIONS
// TODO: This code is shared with PSC.

Element.addMethods( {
    // Like prototype's hide(), but uses the visibility CSS prop instead of display
    conceal: function() {
        for (var i = 0; i < arguments.length; i++) {
            var element = $(arguments[i]);
            element.style.visibility = 'hidden';
        }
    },

    // Like prototype's show(), but uses the visibility CSS prop instead of display
    reveal: function() {
        for (var i = 0; i < arguments.length; i++) {
            var element = $(arguments[i]);
            element.style.visibility = 'visible';
        }
    },

    // Disable all form elements contained in this element and add the class "disabled"
    disableDescendants: function() {
        for (var i = 0; i < arguments.length; i++) {
            var element = $(arguments[i]);
            element.addClassName("disabled")
            element.descendants().each(function(elt) {
                if (elt.disable) elt.disable()
            })
        }
    },

    // Enable all form elements contained in this element and remove the class "disabled"
    enableDescendants: function() {
        for (var i = 0; i < arguments.length; i++) {
            var element = $(arguments[i]);
            element.removeClassName("disabled")
            element.descendants().each(function(elt) {
                if (elt.enable) elt.enable()
            })
        }
    }
} );

Form.selectedRadioValue = function(form, radioName) {
    var pair = $A($(form)[radioName])
        .collect(Form.Element.Serializers.inputSelector)
        .detect(function(e) { return e != null })
    return pair ? pair[1] : null;
}

////// CALENDAR POPUP HANDLERS

AE.registerCalendarPopups = function(containerId) {
    var sel = "input.date"
    if (containerId) sel = "#" + containerId + " " + sel
    $$(sel).each(function(input) {
        var anchorId = input.id + "-calbutton"
        Calendar.setup(
            {
                inputField  : input.id,
                button      : anchorId,
                ifFormat    : "%m/%d/%Y", // TODO: get this from the configuration
                weekNumbers : false,
                onSelect    : function(cal) {
                    input.value = cal.date.print('%m') + "/" + cal.date.print('%d') + "/" + cal.date.print('%Y');
                    ValidationManager.setNormalState(input);
                    if(cal.dateClicked)
	                    cal.callCloseHandler();
                }
            }
        );
    })
    
    //for split-date
    sel ="input.split-date"
    if (containerId) sel = "#" + containerId + " " + sel
    $$(sel).each(function(input) {
    	var yearInputId = input.id
		var baseInputId = input.id.substring(0, input.id.lastIndexOf('.yearString'))
        var anchorId = baseInputId + "-calbutton"
        var monthInputId = baseInputId + ".monthString"
        var dayInputId = baseInputId + ".dayString"
        
        Calendar.setup(
            {
                'yearInputId' : yearInputId,
                'monthInputId': monthInputId,
                'dayInputId'  :dayInputId,
                button        : anchorId,
                ifFormat      : "%m/%d/%Y", // TODO: get this from the configuration
                weekNumbers   : false,
                onSelect      : function(cal){
                	$(cal.params['dayInputId']).value = cal.date.print('%d');
                	$(cal.params['monthInputId']).value = cal.date.print('%m');
                	$(cal.params['yearInputId']).value =  cal.date.print('%Y');

                   if(ValidationManager.isRequired($(cal.params['dayInputId']))) {
                         ValidationManager.setNormalState($(cal.params['dayInputId']));
                   }

                    if(ValidationManager.isRequired($(cal.params['dayInputId']))) {
                         ValidationManager.setNormalState($(cal.params['monthInputId']));
                   }

                    if(ValidationManager.isRequired($(cal.params['dayInputId']))) {
                         ValidationManager.setNormalState($(cal.params['yearInputId']));
                   }



                    
                    if(cal.dateClicked)
	                    cal.callCloseHandler();
                }
            }
        );
    })    
}


////// FORM EDITING

// Provides a uniform set of functions for editing a form containing a
{'fraction_non_alphanumeric': 0.13010204081632654, 'fraction_numerical': 0.0029154518950437317, 'mean_word_length': 2.0198074277854197, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2005436', 'n_tokens_mistral': 3329, 'n_tokens_neox': 3161, 'n_words': 716}