<commit_before>var _ = require('underscore');
var backbone = require('backbone');
var backboneBase = require('backbone-base');
var deepEmpty = require('deep-empty');
var outfile = require('datapackage-outfile');
var validator = require('datapackage-validate');


// Download validated datapackage
module.exports = backbone.BaseView.extend({
  reset: function(descriptor, schema) {
    var form = window.APP.layout.descriptorEdit.layout.form;


    this.$el.addClass('disabled');

    // Drop errors of empty fields which are actually not required
    validator.validate(descriptor, schema).then((function(R) {
      var errors = _.filter(R.errors, function(E) {
        var editor = form.getEditor('root' + E.dataPath.replace(/\//g, '.'));
        var isRequired = editor.parent && _.contains(editor.parent.schema.required, editor.key);
        var value = editor.getValue();


        return isRequired || !isRequired && editor.getValue() && !_.isEmpty(deepEmpty(editor.getValue()));
      });

      if(!errors.length)
        this.$el
          .removeClass('disabled')

          .attr('href', outfile(descriptor, {
            IE9: window.APP.browser.name == 'ie' && parseInt(window.APP.browser.version.split('.')[0]) <= 9
          }));
    }).bind(this));

    return this;
  }
});
<commit_msg>Display .anyOf schema validation errors (#102)<commit_after>var _ = require('underscore');
var backbone = require('backbone');
var backboneBase = require('backbone-base');
var deepEmpty = require('deep-empty');
var outfile = require('datapackage-outfile');
var validator = require('datapackage-validate');


// Returns path for json-editor
function convertPath(path) { return 'root' + path.replace(/\//g, '.'); }

// Download validated datapackage
module.exports = backbone.BaseView.extend({
  reset: function(descriptor, schema) {
    var form = window.APP.layout.descriptorEdit.layout.form;


    this.$el.addClass('disabled');

    // Drop errors of empty fields which are actually not required
    validator.validate(descriptor, schema).then((function(R) {
      var errors = _.filter(R.errors, function(E) {
        var editor = form.getEditor(convertPath(E.dataPath));
        var isRequired = editor.parent && _.contains(editor.parent.schema.required, editor.key);
        var value = editor.getValue();


        return isRequired || !isRequired && editor.getValue() && !_.isEmpty(deepEmpty(editor.getValue()));
      });

      // Place .anyOf validation errors on form
      _.each(errors, function(E) {
        if(parseInt(E.code) === 10)
          form.getEditor(convertPath(E.dataPath)).showValidationErrors([{
            message: 'Any of these fields should not be empty: ' + _.map(E.subErrors, function(E) {
              return E.params.key;
            }).join(', '),

            path: convertPath(E.dataPath)
          }]);
      });

      if(!errors.length)
        this.$el
          .removeClass('disabled')

          .attr('href', outfile(descriptor, {
            IE9: window.APP.browser.name == 'ie' && parseInt(window.APP.browser.version.split('.')[0]) <= 9
          }));
    }).bind(this));

    return this;
  }
});

{'fraction_non_alphanumeric': 0.15878056525881232, 'fraction_numerical': 0.003493172435693871, 'mean_word_length': 3.112271540469974, 'pattern_counts': {'":': 0, '<': 5, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3865581', 'n_tokens_mistral': 920, 'n_tokens_neox': 883, 'n_words': 190}