<commit_before>/**
 * This is a sample implementation of the API that the BIC must supply.
 */

define([
  'chai',
  'feature!promises',
  'jquery',
  'underscore',
  'moment',
  'BlinkForms',
  'definitions',
  'BMP.Blob',
  'BMP.BlinkGap',
  'feature!es5',
  'jquerymobile'
], function (chai, Promise, $, _, moment, Forms, defs) {
  'use strict';

  var $submitPopup, $footer, $grid, $colB;

  window.chai = chai;
  window.assert = chai.assert;

  window.Promise = window.Promise || Promise;

  $submitPopup = $('<div></div>').attr({
    id: 'submitPopup',
    'data-role': 'popup',
    'class': 'ui-content',
    'data-overlay-theme': 'a'
  }).appendTo(document.body);
  $footer = $('footer');
  $grid = $('<fieldset class="ui-grid-a"></fieldset>').appendTo($footer);
  $('<div class="ui-block-a"></div>').appendTo($grid);
  $colB = $('<div class="ui-block-b"></div>').appendTo($grid);
  $('<a></a>').attr({
    'id': 'previousFormPage',
    'data-role': 'button'
  }).text('Previous').appendTo($colB);
  $('<button></button>').attr({
    'data-action': 'submit',
    'data-role': 'button'
  }).text('Submit').appendTo($colB);
  $('<a></a>').attr({
    'id': 'nextFormPage',
    'data-role': 'button'
  }).text('Next').appendTo($colB);

  Forms.getDefinition = function (name, action) {
    return new Promise(function (resolve, reject) {
      var def = _.find(defs, function (d) {
        return d && d.default && d.default.name === name;
      });
      if (!def) {
        reject(def);
        return;
      }
      setTimeout(function () {
        try {
          resolve(Forms.flattenDefinition(def, action));
        } catch (err) {
          reject(err);
        }
      }, 100);
    });
  };

  BMP.Expression.fn.interaction = function (interaction, queryString) {
    return new Promise(function (resolve, reject) {
      $.ajax({
        type: 'GET',
        url: interaction + '.xml?' + queryString,
        dataType: 'xml'}).then(
        function (data) {
          resolve(data);
        }, function () {
          reject(arguments);
        }
     );
    });
  };

  BMP.Expression.fn.suitcase = function (suitcase, type) {
    return new Promise(function (resolve, reject) {
      $.ajax({
        type: 'GET',
        url: suitcase + '.xml?' + type,
        dataType: 'xml'}).then(
        function (data) {
          resolve(data);
        }, function () {
          reject(arguments);
        }
     );
    });
  };

  $submitPopup.popup();

  $(document.body).on('click', 'button[data-action=submit]', function () {
    Forms.current.getErrors();
    Forms.current.data().then(function (data) {
      var json = JSON.stringify(data, undefined, 2);
      $submitPopup.empty();
      $submitPopup.append('<pre>' + json + '</pre>');
      $submitPopup.popup('open');
    });
  });

  $(document.body).on('click', '#previousFormPage', function () {
    var index = Forms.current.get('pages').current.index();

    if (index > 0) {
      Forms.current.get('pages').goto(index - 1);
    }
  });

  $(document.body).on('click', '#nextFormPage', function () {
    var index = Forms.current.get('pages').current.index();

    if (index < Forms.current.get('pages').length - 1) {
      Forms.current.get('pages').goto(index + 1);
    }
  });

  BMP.FileInput.initialize();
});
<commit_msg>FORMS-248 # test BIC decoupled a bit from defs<commit_after>/**
 * This is a sample implementation of the API that the BIC must supply.
 */

define([
  'chai',
  'feature!promises',
  'jquery',
  'underscore',
  'moment',
  'BlinkForms',
  'BMP.Blob',
  'BMP.BlinkGap',
  'feature!es5',
  'jquerymobile'
], function (chai, Promise, $, _, moment, Forms) {
  'use strict';

  var $submitPopup, $footer, $grid, $colB;

  window.chai = chai;
  window.assert = chai.assert;

  window.Promise = window.Promise || Promise;

  $submitPopup = $('<div></div>').attr({
    id: 'submitPopup',
    'data-role': 'popup',
    'class': 'ui-content',
    'data-overlay-theme': 'a'
  }).appendTo(document.body);
  $footer = $('footer');
  $grid = $('<fieldset class="ui-grid-a"></fieldset>').appendTo($footer);
  $('<div class="ui-block-a"></div>').appendTo($grid);
  $colB = $('<div class="ui-block-b"></div>').appendTo($grid);
  $('<a></a>').attr({
    'id': 'previousFormPage',
    'data-role': 'button'
  }).text('Previous').appendTo($colB);
  $('<button></button>').attr({
    'data-action': 'submit',
    'data-role': 'button'
  }).text('Submit').appendTo($colB);
  $('<a></a>').attr({
    'id': 'nextFormPage',
    'data-role': 'button'
  }).text('Next').appendTo($colB);

  Forms.getDefinition = function (name, action) {
    return new Promise(function (resolve, reject) {
      require(['definitions'], function (defs) {
        var def = _.find(defs, function (d) {
          return d && d.default && d.default.name === name;
        });
        if (!def) {
          reject(def);
          return;
        }
        setTimeout(function () {
          try {
            resolve(Forms.flattenDefinition(def, action));
          } catch (err) {
            reject(err);
          }
        }, 100);
      });
    });
  };

  BMP.Expression.fn.interaction = function (interaction, queryString) {
    return new Promise(function (resolve, reject) {
      $.ajax({
        type: 'GET',
        url: interaction + '.xml?' + queryString,
        dataType: 'xml'}).then(
        function (data) {
          resolve(data);
        }, function () {
          reject(arguments);
        }
     );
    });
  };

  BMP.Expression.fn.suitcase = function (suitcase, type) {
    return new Promise(function (resolve, reject) {
      $.ajax({
        type: 'GET',
        url: suitcase + '.xml?' + type,
        dataType: 'xml'}).then(
        function (data) {
          resolve(data);
        }, function () {
          reject(arguments);
        }
     );
    });
  };

  $submitPopup.popup();

  $(document.body).on('click', 'button[data-action=submit]', function () {
    Forms.current.getErrors();
    Forms.current.data().then(function (data) {
      var json = JSON.stringify(data, undefined, 2);
      $submitPopup.empty();
      $submitPopup.append('<pre>' + json + '</pre>');
      $submitPopup.popup('open');
    });
  });

  $(document.body).on('click', '#previousFormPage', function () {
    var index = Forms.current.get('pages').current.index();

    if (index > 0) {
      Forms.current.get('pages').goto(index - 1);
    }
  });

  $(document.body).on('click', '#nextFormPage', function () {
    var index = Forms.current.get('pages').current.index();

    if (index < Forms.current.get('pages').length - 1) {
      Forms.current.get('pages').goto(index + 1);
    }
  });

  BMP.FileInput.initialize();
});

{'fraction_non_alphanumeric': 0.20736983440250634, 'fraction_numerical': 0.0031329255557213187, 'mean_word_length': 2.657392253136934, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '873908', 'n_tokens_mistral': 2249, 'n_tokens_neox': 2197, 'n_words': 414}