<commit_before>/**
 * Deals with the main high level survey controls: saving, submitting etc.
 */

'use strict';

var gui = require( './gui' );
var connection = require( './connection' );
var settings = require( './settings' );
var Form = require( 'enketo-core' );
var fileManager = require( './file-manager' );
var t = require( './translator' ).t;
var records = require( './records-queue' );
var $ = require( 'jquery' );

var form;
var formSelector;
var formData;
var $formprogress;
var formOptions = {
    clearIrrelevantImmediately: true,
    printRelevantOnly: settings.printRelevantOnly
};

require( './Form-model' );
require( './Form' );

function init( selector, data ) {
    var advice;
    var loadErrors = [];

    formSelector = selector;
    formData = data;

    return _initializeRecords()
        .then( _checkAutoSavedRecord )
        .then( function( record ) {
            if ( !data.instanceStr && record && record.xml ) {
                records.setActive( records.getAutoSavedKey() );
                data.instanceStr = record.xml;
            }

            if ( data.instanceAttachments ) {
                fileManager.setInstanceAttachments( data.instanceAttachments );
            }

            form = new Form( formSelector, data, formOptions );
            loadErrors = form.init();<commit_msg>removed: OC: obsolete require statement<commit_after>/**
 * Deals with the main high level survey controls: saving, submitting etc.
 */

'use strict';

var gui = require( './gui' );
var connection = require( './connection' );
var settings = require( './settings' );
var Form = require( 'enketo-core' );
var fileManager = require( './file-manager' );
var t = require( './translator' ).t;
var records = require( './records-queue' );
var $ = require( 'jquery' );

var form;
var formSelector;
var formData;
var $formprogress;
var formOptions = {
    clearIrrelevantImmediately: true,
    printRelevantOnly: settings.printRelevantOnly
};

require( './Form' );

function init( selector, data ) {
    var advice;
    var loadErrors = [];

    formSelector = selector;
    formData = data;

    return _initializeRecords()
        .then( _checkAutoSavedRecord )
        .then( function( record ) {
            if ( !data.instanceStr && record && record.xml ) {
                records.setActive( records.getAutoSavedKey() );
                data.instanceStr = record.xml;
            }

            if ( data.instanceAttachments ) {
                fileManager.setInstanceAttachments( data.instanceAttachments );
            }

            form = new Form( formSelector, data, formOptions );
            loadErrors = form.init();
{'fraction_non_alphanumeric': 0.12939841089670828, 'fraction_numerical': 0.0, 'mean_word_length': 2.656984785615491, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '2878334', 'n_tokens_mistral': 756, 'n_tokens_neox': 730, 'n_words': 207}