<commit_before>= content_for :javascripts do
  :javascript
    var cost_object_inherited = #{@project_masterdata.cost_object_inherited};
    
    $(function() {

        if ( $('#project_masterdata_additional_information').val() == '' && 
             $('select#project_masterdata_business_criticality').val() == 'prod' 
          ) {
          $('#project_masterdata_additional_information').parent().addClass('has-error');
        }

        if (cost_object_inherited) {
          $('select#project_masterdata_cost_object_type').prop('disabled', function(i, v) { return !v; });
          $('input#project_masterdata_cost_object_name').prop('disabled', function(i, v) { return !v; });
        }
        
        // empty fields if inherited is true
        if ($('#project_masterdata_cost_object_inherited').val() == "true") {
          $('select#project_masterdata_cost_object_type').val("");
          $('input#project_masterdata_cost_object_name').val("");
        }
        
        // handle inherited true or false
        $('#project_masterdata_cost_object_inherited').change(function(){
          if ($('#project_masterdata_cost_object_inherited').val() == "true") {
            $('select#project_masterdata_cost_object_type').data('old_value',$('select#project_masterdata_cost_object_type').val());
            $('input#project_masterdata_cost_object_name').data('old_value',$('input#project_masterdata_cost_object_name').val());
            
            $('select#project_masterdata_cost_object_type').val("");
            $('input#project_masterdata_cost_object_name').val("");

            $('select#project_masterdata_cost_object_type').prop('disabled', true);
            $('input#project_masterdata_cost_object_name').prop('disabled', true);
          }
          else {
            $('select#project_masterdata_cost_object_type').val($('select#project_masterdata_cost_object_type').data('old_value'));
            $('input#project_masterdata_cost_object_name').val($('input#project_masterdata_cost_object_name').data('old_value'));

            $('select#project_masterdata_cost_object_type').prop('disabled', false);
            $('input#project_masterdata_cost_object_name').prop('disabled',false);
          }
        })

        $('textarea#project_masterdata_additional_information').on("propertychange input", function(){
           if ( $(this).val() == '' && 
                $('select#project_masterdata_business_criticality').val().match(/^prod/g) 
            ) {
              $(this).parent().addClass('has-error');
              $('#project_masterdata_business_criticality').parent().addClass('has-error');
            }
            else {
              $(this).parent().removeClass('has-error');
              $('#project_masterdata_business_criticality').parent().removeClass('has-error')
            }

            if (this.value.length > this.maxlength) {
               this.value = this.value.substring(0, this.maxlength);
            }
            
            chars_left = parseInt($(this).attr('maxlength')) - this.value.length;
            $('span#additional_information_length').html("Remaining characters "+chars_left);
        })



        $('select#project_masterdata_business_criticality').change(function(){
          if ( $(this).val().match(/^prod/g) && 
               $('#project_masterdata_additional_information').val() == ''
            ) {
            $('#project_masterdata_additional_information').parent().addClass('has-error');
            $('#project_masterdata_business_criticality').parent().addClass('has-error');
          }
          else {
            $('#project_masterdata_additional_information').parent().removeClass('has-error');
            $('#project_masterdata_business_criticality').parent().removeClass('has-error');
          }
        });
        <commit_msg>fix edge case to prevent that masterdata will end in an unusable state when inheritance on project is true and domain false<commit_after>= content_for :javascripts do
  :javascript
    var cost_object_inherited = #{@project_masterdata.cost_object_inherited};
    var domain_co_inheritance = #{@inheritance.co_inheritable};
    
    $(function() {

        if ( $('#project_masterdata_additional_information').val() == '' && 
             $('select#project_masterdata_business_criticality').val() == 'prod' 
          ) {
          $('#project_masterdata_additional_information').parent().addClass('has-error');
        }

        if (cost_object_inherited && domain_co_inheritance) {
          $('select#project_masterdata_cost_object_type').prop('disabled', function(i, v) { return !v; });
          $('input#project_masterdata_cost_object_name').prop('disabled', function(i, v) { return !v; });
        }
        
        // empty fields if inherited is true
        if ($('#project_masterdata_cost_object_inherited').val() == "true") {
          $('select#project_masterdata_cost_object_type').val("");
          $('input#project_masterdata_cost_object_name').val("");
        }
        
        // handle inherited true or false
        $('#project_masterdata_cost_object_inherited').change(function(){
          if ($('#project_masterdata_cost_object_inherited').val() == "true") {
            $('select#project_masterdata_cost_object_type').data('old_value',$('select#project_masterdata_cost_object_type').val());
            $('input#project_masterdata_cost_object_name').data('old_value',$('input#project_masterdata_cost_object_name').val());
            
            $('select#project_masterdata_cost_object_type').val("");
            $('input#project_masterdata_cost_object_name').val("");

            $('select#project_masterdata_cost_object_type').prop('disabled', true);
            $('input#project_masterdata_cost_object_name').prop('disabled', true);
          }
          else {
            $('select#project_masterdata_cost_object_type').val($('select#project_masterdata_cost_object_type').data('old_value'));
            $('input#project_masterdata_cost_object_name').val($('input#project_masterdata_cost_object_name').data('old_value'));

            $('select#project_masterdata_cost_object_type').prop('disabled', false);
            $('input#project_masterdata_cost_object_name').prop('disabled',false);
          }
        })

        $('textarea#project_masterdata_additional_information').on("propertychange input", function(){
           if ( $(this).val() == '' && 
                $('select#project_masterdata_business_criticality').val().match(/^prod/g) 
            ) {
              $(this).parent().addClass('has-error');
              $('#project_masterdata_business_criticality').parent().addClass('has-error');
            }
            else {
              $(this).parent().removeClass('has-error');
              $('#project_masterdata_business_criticality').parent().removeClass('has-error')
            }

            if (this.value.length > this.maxlength) {
               this.value = this.value.substring(0, this.maxlength);
            }
            
            chars_left = parseInt($(this).attr('maxlength')) - this.value.length;
            $('span#additional_information_length').html("Remaining characters "+chars_left);
        })

        $('select#project_masterdata_business_criticality').change(function(){
          if ( $(this).val().match(/^prod/g) && 
               $('#project_masterdata_additional_information').val() == ''
            ) {
            $('#project_masterdata_additional_information').parent().addClass('has-error');
            $('#project_masterdata_business_criticality').parent().addClass('has-error');
          }
          else {
            $('#project_masterdata_additional_information').parent().removeClass('has-error');
            $('#project_masterdata_business_criticality').parent().removeClass('has-error');
          }
        });
        
{'fraction_non_alphanumeric': 0.15631746031746033, 'fraction_numerical': 0.00025396825396825396, 'mean_word_length': 3.0410466906105693, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4829098', 'n_tokens_mistral': 2144, 'n_tokens_neox': 2118, 'n_words': 209}