<commit_before>/**
 * Created by moshensky on 5/24/15.
 */
//import {ValidateCustomAttributeViewStrategy} from 'aurelia-validation';
// TODO: move to upper import, because it should be fixed in near commit
import {ValidateCustomAttributeViewStrategyBase} from 'aurelia-validation/validation/validate-custom-attribute-view-strategy';

export class TableValidationViewStrategy extends ValidateCustomAttributeViewStrategyBase {
  constructor() {
    super();
    this.helpBlockClass = 'aurelia-validation-message';
  }

  searchFormGroup(currentElement, currentDepth) {
    if (currentDepth === 5) {
      return null;
    }
    if (currentElement.classList && currentElement.classList.contains('form-group')) {
      return currentElement;
    }
    return this.searchFormGroup(currentElement.parentNode, 1 + currentDepth);
  }

  appendMessageToElement(element, validationProperty) {
    var helpBlock = element.nextSibling;
    if (helpBlock) {
      if (!helpBlock.classList) {
        helpBlock = null;
      }
      else if (!helpBlock.classList.contains(this.helpBlockClass)) {
        helpBlock = null;
      }
    }

    if (!helpBlock) {
      helpBlock = document.createElement("p");
      helpBlock.classList.add('help-block');
      helpBlock.classList.add(this.helpBlockClass);

      if (element.nextSibling) {
        element.parentNode.insertBefore(helpBlock, element.nextSibling);
      }
      else {
        element.parentNode.appendChild(helpBlock);
      }
    }
    if (validationProperty) {
      helpBlock.textContent = validationProperty.message;
      if (validationProperty.isValid === true) {
        helpBlock.style.display = 'none';
      } else {
        helpBlock.style.display = 'block';
      }
    } else {
      helpBlock.style.display = 'none';
      helpBlock.textContent = '';
    }
  }

  appendUIVisuals(validationProperty, currentElement) {
    var formGroup = this.searchFormGroup(currentElement, 0);
    if (formGroup) {
      if (validationProperty && validationProperty.isDirty) {
        if (validationProperty.isValid) {
          formGroup.classList.remove('has-warning');
          formGroup.classList.add('has-success');
        }
        else {
          formGroup.classList.remove('has-success');
          formGroup.classList.add('has-warning');
        }
      }
      else {
        formGroup.classList.remove('has-warning');
        formGroup.classList.remove('has-success');
      }

      this.appendMessageToElement(currentElement, validationProperty);
    }
  }

  prepareElement(validationProperty, element) {
    this.appendUIVisuals(null, element);
  }

  updateElement(validationProperty, element) {
    this.appendUIVisuals(validationProperty, element);
  }
}
<commit_msg>Update table-validation-view-strategy.js<commit_after>/**
 * Created by moshensky on 5/24/15.
 */
//import {ValidateCustomAttributeViewStrategy} from 'aurelia-validation';
// TODO: move to upper import, because it should be fixed in near commit
import {ValidateCustomAttributeViewStrategyBase} from 'aurelia-validation/validate-custom-attribute-view-strategy';

export class TableValidationViewStrategy extends ValidateCustomAttributeViewStrategyBase {
  constructor() {
    super();
    this.helpBlockClass = 'aurelia-validation-message';
  }

  searchFormGroup(currentElement, currentDepth) {
    if (currentDepth === 5) {
      return null;
    }
    if (currentElement.classList && currentElement.classList.contains('form-group')) {
      return currentElement;
    }
    return this.searchFormGroup(currentElement.parentNode, 1 + currentDepth);
  }

  appendMessageToElement(element, validationProperty) {
    var helpBlock = element.nextSibling;
    if (helpBlock) {
      if (!helpBlock.classList) {
        helpBlock = null;
      }
      else if (!helpBlock.classList.contains(this.helpBlockClass)) {
        helpBlock = null;
      }
    }

    if (!helpBlock) {
      helpBlock = document.createElement("p");
      helpBlock.classList.add('help-block');
      helpBlock.classList.add(this.helpBlockClass);

      if (element.nextSibling) {
        element.parentNode.insertBefore(helpBlock, element.nextSibling);
      }
      else {
        element.parentNode.appendChild(helpBlock);
      }
    }
    if (validationProperty) {
      helpBlock.textContent = validationProperty.message;
      if (validationProperty.isValid === true) {
        helpBlock.style.display = 'none';
      } else {
        helpBlock.style.display = 'block';
      }
    } else {
      helpBlock.style.display = 'none';
      helpBlock.textContent = '';
    }
  }

  appendUIVisuals(validationProperty, currentElement) {
    var formGroup = this.searchFormGroup(currentElement, 0);
    if (formGroup) {
      if (validationProperty && validationProperty.isDirty) {
        if (validationProperty.isValid) {
          formGroup.classList.remove('has-warning');
          formGroup.classList.add('has-success');
        }
        else {
          formGroup.classList.remove('has-success');
          formGroup.classList.add('has-warning');
        }
      }
      else {
        formGroup.classList.remove('has-warning');
        formGroup.classList.remove('has-success');
      }

      this.appendMessageToElement(currentElement, validationProperty);
    }
  }

  prepareElement(validationProperty, element) {
    this.appendUIVisuals(null, element);
  }

  updateElement(validationProperty, element) {
    this.appendUIVisuals(validationProperty, element);
  }
}

{'fraction_non_alphanumeric': 0.11388483965014577, 'fraction_numerical': 0.0029154518950437317, 'mean_word_length': 3.093214019388516, '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': '3822547', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1550, 'n_words': 255}