<commit_before>var _ = require('lodash'),
  dom = require('./dom'),
  ds = require('dollar-slice'),
  paneController = require('../controllers/pane'),
  publishPaneController = require('../controllers/publish-pane'),
  toolbar = dom.find('.kiln-toolbar');

/**
 * create pane
 * @param {string} header
 * @param {Element|DocumentFragment} innerEl
 * @returns {Element}
 */
function createPane(header, innerEl) {
  var template = dom.find('.kiln-pane-template'),
    el = document.importNode(template.content, true);

  close();
  // add header and contents
  el.querySelector('.pane-header').innerHTML = header;
  el.querySelector('.pane-inner').appendChild(innerEl);

  return el;
}

/**
 * close an open pane
 */
function close() {
  var pane  = dom.find('.kiln-toolbar-pane-background');

  if (pane) {
    dom.removeElement(pane);
  }
}

/**
 * open publish pane
 */
function openPublish() {
  var header = 'Schedule Publish',
    actionsEl = dom.create(`
      <div class="actions">
        <button class="publish-now">Publish Now</button>
      </div>
    `),
    el = createPane(header, actionsEl);

  dom.insertBefore(toolbar, el);
  // init controller for pane background
  ds.controller('pane', paneController);
  ds.get('pane', toolbar.previousElementSibling);
  // init controller for publish pane
  ds.controller('publish-pane', publishPaneController);
  ds.get('publish-pane', toolbar.previousElementSibling.querySelector('.actions'));
}

function addErrors(errors) {
  return _.reduce(errors, function (el, error) {
    var errorEl = dom.create(`
        <div class="publish-error">
          <span class="label">${error.rule.label}:</span>
          <span class="description">${error.rule.description}</span>
          <ul class="errors"></ul>
        </div>
      `),
      list = dom.find(errorEl, 'ul');

    // add each place where the error occurs
    _.each(error.errors, function (item) {
      var itemEl = dom.create(`<li>${item.label}</li>`);

      list.appendChild(itemEl);
    });

    el.appendChild(errorEl);
    return el;
  }, document.createDocumentFragment());
}

function openValidationErrors(errors) {
  var header = 'Before you can publish&hellip;',
    messageEl = dom.create(`
      <div class="error-message">This page is missing things needed to publish.<br />Address the following and try publishing again.</div>
    `),
    errorsEl = addErrors(errors),
    innerEl = document.createDocumentFragment(),
    el;

  innerEl.appendChild(messageEl);
  innerEl.appendChild(errorsEl);

  el = createPane(header, innerEl);

  dom.insertBefore(toolbar, el);
  // init controller for pane background
  ds.controller('pane', paneController);
  ds.get('pane', toolbar.previousElementSibling);
}<commit_msg>it's not adding .noscroll to the body when opening validation pane<commit_after>var _ = require('lodash'),
  dom = require('./dom'),
  ds = require('dollar-slice'),
  paneController = require('../controllers/pane'),
  publishPaneController = require('../controllers/publish-pane'),
  toolbar = dom.find('.kiln-toolbar');

/**
 * create pane
 * @param {string} header
 * @param {Element|DocumentFragment} innerEl
 * @returns {Element}
 */
function createPane(header, innerEl) {
  var template = dom.find('.kiln-pane-template'),
    el = document.importNode(template.content, true);

  // add header and contents
  el.querySelector('.pane-header').innerHTML = header;
  el.querySelector('.pane-inner').appendChild(innerEl);

  return el;
}

/**
 * close an open pane
 */
function close() {
  var pane  = dom.find('.kiln-toolbar-pane-background');

  if (pane) {
    dom.removeElement(pane);
  }
}

/**
 * open publish pane
 */
function openPublish() {
  var header = 'Schedule Publish',
    actionsEl = dom.create(`
      <div class="actions">
        <button class="publish-now">Publish Now</button>
      </div>
    `),
    el = createPane(header, actionsEl);

  close();
  dom.insertBefore(toolbar, el);
  // init controller for pane background
  ds.controller('pane', paneController);
  ds.get('pane', toolbar.previousElementSibling);
  // init controller for publish pane
  ds.controller('publish-pane', publishPaneController);
  ds.get('publish-pane', toolbar.previousElementSibling.querySelector('.actions'));
}

function addErrors(errors) {
  return _.reduce(errors, function (el, error) {
    var errorEl = dom.create(`
        <div class="publish-error">
          <span class="label">${error.rule.label}:</span>
          <span class="description">${error.rule.description}</span>
          <ul class="errors"></ul>
        </div>
      `),
      list = dom.find(errorEl, 'ul');

    // add each place where the error occurs
    _.each(error.errors, function (item) {
      var itemEl = dom.create(`<li>${item.label}</li>`);

      list.appendChild(itemEl);
    });

    el.appendChild(errorEl);
    return el;
  }, document.createDocumentFragment());
}

function openValidationErrors(errors) {
  var header = 'Before you can publish&hellip;',
    messageEl = dom.create(`
      <div class="error-message">This page is missing things needed to publish.<br />Address the following and try publishing again.</div>
    `),
    errorsEl = addErrors(errors),
    innerEl = document.createDocumentFragment(),
    el;

  innerEl.appendChild(messageEl);
  innerEl.appendChild(errorsEl);

  el = createPane(header, innerEl);

  close();
  dom.insertBefore(toolbar, el);
  // init controller for pane background
  ds.controller('pane', paneController);
  ds.get('pane', toolbar.previousElementSibling);
}
{'fraction_non_alphanumeric': 0.15644171779141106, 'fraction_numerical': 0.0, 'mean_word_length': 3.677637130801688, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '1826088', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1649, 'n_words': 371}