<commit_before>hqDefine("app_manager/js/details/case_list_callout", function() {
    var caseListLookupViewModel = function($el, state, lang, saveButton) {
        'use strict';
        var self = this,
            detail_type = $el.data('detail-type');

        var ObservableKeyValue = function(obs){
            this.key = ko.observable(obs.key);
            this.value = ko.observable(obs.value);
        };

        var _fireChange = function(){
            saveButton.fire('change');
        };

        self.initSaveButtonListeners = function($el){
            $el.find('input[type=text], textarea').on('textchange', _fireChange);
            $el.find('input[type=checkbox]').on('change', _fireChange);
            $el.find(".case-list-lookup-icon button").on("click", _fireChange); // Trigger save button when icon upload buttons are clicked
        };

        var _remove_empty = function(type){
            self[type].remove(function(t){
                var is_blank = (!t.key() && !t.value());
                return is_blank;
            });
        };

        self.add_item = function(type){
            _remove_empty(type);
            var data = (type === 'extras') ? {key: '', value: ''} : {key: ''};
            self[type].push(new ObservableKeyValue(data));
        };

        self.remove_item = function(type, item){
            self[type].remove(item);
            if (self[type]().length === 0){
                self.add_item(type);
            }
            _fireChange();
        };

        var _trimmed_extras = function(){
            return _.compact(_.map(self.extras(), function(extra){
                if (!(extra.key() === "" && extra.value() ==="")){
                    return {key: extra.key(), value: extra.value()};
                }
            }));
        };

        var _trimmed_responses = function(){
            return _.compact(_.map(self.responses(), function(response){
                if (response.key() !== ""){
                    return {key: response.key()};
                }
            }));
        };

        self.serialize = function(){
            var image_path = $el.find(".case-list-lookup-icon input[type=hidden]").val() || null;

            var data = {
                lookup_enabled: self.lookup_enabled(),
                lookup_autolaunch: self.lookup_autolaunch(),
                lookup_action: self.lookup_action(),
                lookup_name: self.lookup_name(),
                lookup_extras: _trimmed_extras(),
                lookup_responses: _trimmed_responses(),
                lookup_image: image_path,
                lookup_display_results: self.lookup_display_results(),
                lookup_field_header: self.lookup_field_header.val(),
                lookup_field_template: self.lookup_field_template(),
            };

            return data;
        };

        var _validate_inputs = function(errors){
            errors = errors || [];
            $el.find('input[required]').each(function(){
                var $this = $(this);
                if ($this.val().trim().length === 0){
                    $this.closest('.form-group').addClass('has-error');
                    var $help = $this.siblings('.help-block');
                    $help.show();
                    errors.push($help.text());
                }
                else {
                    $this.closest('.form-group').removeClass('has-error');
                    $this.siblings('.help-block').hide();
                }
            });
            return errors;
        };

        var _validate_extras = function(errors){
            errors = errors || [];
            var $extras = $el.find("." + detail_type + "-extras"),
                $extra_help = $extras.find(".help-block");

            if (!_trimmed_extras().length){
                $extras.addClass('has-error');
                $extra_help.show();
                errors.push($extra_help.text());
            }
        else {
            $extras.removeClass('has-error');
                $extra_help.hide();
            }
            return errors;
        };

        var _validate_responses = function(errors){
            errors = errors || [];
            var $responses = $el.find("." + detail_type + "-responses"),
                $response_help = $responses.find(".help-block");

            if (!_trimmed_responses().length){
                $responses.addClass('has-error');
                $response_help.show();
                errors.push($response_help.text());
            }
            else {
                $responses.removeClass('has-error');
                $response_help.hide();<commit_msg>fix spacing<commit_after>hqDefine("app_manager/js/details/case_list_callout", function() {
    var caseListLookupViewModel = function($el, state, lang, saveButton) {
        'use strict';
        var self = this,
            detail_type = $el.data('detail-type');

        var ObservableKeyValue = function(obs){
            this.key = ko.observable(obs.key);
            this.value = ko.observable(obs.value);
        };

        var _fireChange = function(){
            saveButton.fire('change');
        };

        self.initSaveButtonListeners = function($el){
            $el.find('input[type=text], textarea').on('textchange', _fireChange);
            $el.find('input[type=checkbox]').on('change', _fireChange);
            $el.find(".case-list-lookup-icon button").on("click", _fireChange); // Trigger save button when icon upload buttons are clicked
        };

        var _remove_empty = function(type){
            self[type].remove(function(t){
                var is_blank = (!t.key() && !t.value());
                return is_blank;
            });
        };

        self.add_item = function(type){
            _remove_empty(type);
            var data = (type === 'extras') ? {key: '', value: ''} : {key: ''};
            self[type].push(new ObservableKeyValue(data));
        };

        self.remove_item = function(type, item){
            self[type].remove(item);
            if (self[type]().length === 0){
                self.add_item(type);
            }
            _fireChange();
        };

        var _trimmed_extras = function(){
            return _.compact(_.map(self.extras(), function(extra){
                if (!(extra.key() === "" && extra.value() ==="")){
                    return {key: extra.key(), value: extra.value()};
                }
            }));
        };

        var _trimmed_responses = function(){
            return _.compact(_.map(self.responses(), function(response){
                if (response.key() !== ""){
                    return {key: response.key()};
                }
            }));
        };

        self.serialize = function(){
            var image_path = $el.find(".case-list-lookup-icon input[type=hidden]").val() || null;

            var data = {
                lookup_enabled: self.lookup_enabled(),
                lookup_autolaunch: self.lookup_autolaunch(),
                lookup_action: self.lookup_action(),
                lookup_name: self.lookup_name(),
                lookup_extras: _trimmed_extras(),
                lookup_responses: _trimmed_responses(),
                lookup_image: image_path,
                lookup_display_results: self.lookup_display_results(),
                lookup_field_header: self.lookup_field_header.val(),
                lookup_field_template: self.lookup_field_template(),
            };

            return data;
        };

        var _validate_inputs = function(errors){
            errors = errors || [];
            $el.find('input[required]').each(function(){
                var $this = $(this);
                if ($this.val().trim().length === 0){
                    $this.closest('.form-group').addClass('has-error');
                    var $help = $this.siblings('.help-block');
                    $help.show();
                    errors.push($help.text());
                }
                else {
                    $this.closest('.form-group').removeClass('has-error');
                    $this.siblings('.help-block').hide();
                }
            });
            return errors;
        };

        var _validate_extras = function(errors){
            errors = errors || [];
            var $extras = $el.find("." + detail_type + "-extras"),
                $extra_help = $extras.find(".help-block");

            if (!_trimmed_extras().length){
                $extras.addClass('has-error');
                $extra_help.show();
                errors.push($extra_help.text());
            }
            else {
                $extras.removeClass('has-error');
                $extra_help.hide();
            }
            return errors;
        };

        var _validate_responses = function(errors){
            errors = errors || [];
            var $responses = $el.find("." + detail_type + "-responses"),
                $response_help = $responses.find(".help-block");

            if (!_trimmed_responses().length){
                $responses.addClass('has-error');
                $response_help.show();
                errors.push($response_help.text());
            }
            else {
                $responses.removeClass('has-error');
                $response_help.hide();
{'fraction_non_alphanumeric': 0.14841901484190148, 'fraction_numerical': 0.00043020004302000433, 'mean_word_length': 1.5830555555555557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3752971', 'n_tokens_mistral': 2516, 'n_tokens_neox': 2401, 'n_words': 394}