<commit_before>/*global Marionette, Backbone */

var FormplayerFrontend = new Marionette.Application();

var hideLoading = hqImport('cloudcare/js/util.js').hideLoading;
var showError = hqImport('cloudcare/js/util.js').showError;
var showSuccess = hqImport('cloudcare/js/util.js').showSuccess;
var showLoading = hqImport('cloudcare/js/util.js').showLoading;
var tfLoading = hqImport('cloudcare/js/util.js').tfLoading;
var tfLoadingComplete = hqImport('cloudcare/js/util.js').tfLoadingComplete;
var tfSyncComplete = hqImport('cloudcare/js/util.js').tfSyncComplete;

FormplayerFrontend.on("before:start", function () {
    var RegionContainer = Marionette.LayoutView.extend({
        el: "#app-container",

        regions: {
            main: "#main-region",
        },
    });

    FormplayerFrontend.regions = new RegionContainer();
});

FormplayerFrontend.navigate = function (route, options) {
    options || (options = {});
    Backbone.history.navigate(route, options);
};

FormplayerFrontend.getCurrentRoute = function () {
    return Backbone.history.fragment;
};

FormplayerFrontend.reqres.setHandler('currentUser', function () {
    if (FormplayerFrontend.currentUser) return FormplayerFrontend.currentUser;
    return new FormplayerFrontend.Entities.UserModel();
});

FormplayerFrontend.reqres.setHandler('startForm', function (data) {
    var loadSession = function () {
        data.onLoading = tfLoading;
        data.onLoadingComplete = tfLoadingComplete;
        data.xform_url="/webforms/player_proxy";
        data.domain = "test"
        data.onerror = function (resp) {
            showError(resp.human_readable_message || resp.message, $("#cloudcare-notifications"));
            //cloudCare.dispatch.trigger("form:error", form, caseModel);
        };
        data.onload = function (adapter, resp) {
            //cloudCare.dispatch.trigger("form:ready", form, caseModel);
        };
        data.onsubmit = function (xml) {
            window.mainView.router.view.dirty = false;
            // post to receiver
            $.ajax({
                type: 'POST',
                url: submitUrl,
                data: xml,
                success: function () {
                    //self._clearFormPlayer();
                    //self.showModule(selectedModule);
                    //cloudCare.dispatch.trigger("form:submitted");
                    showSuccess(translatedStrings.saved, $("#cloudcare-notifications"), 2500);
                },
                error: function (resp, status, message) {
                    if (message) {
                        message = translatedStrings.errSavingDetail + message;
                    } else {
                        message = translatedStrings.unknownError + status + " " + resp.status;
                        if (resp.status === 0) {
                            message = (message + ". "
                                + translatedStrings.unknownErrorDetail + " (" + submitUrl + ")");
                        }
                    }
                    data.onerror({message: message});
                    // TODO change submit button text to something other than
                    // "Submitting..." and prevent "All changes saved!" message
                    // banner at top of the form.
                }
            });
        };
        var sess = new WebFormSession(data);
        sess.initDirect(data, $('#webforms'), FormplayerFrontend.request('currentUser').language);
    };
    loadSession();
});

FormplayerFrontend.on("start", function (apps, language) {
    FormplayerFrontend.request('currentUser').language = language;
    if (Backbone.history) {
        Backbone.history.start();
        FormplayerFrontend.trigger("apps:storeapps", apps);
        var user = FormplayerFrontend.request('currentUser');
        // will be the same for every domain. TODO: get domain/username/pass from django
        user.domain = apps[0].domain;
        if (this.getCurrentRoute() === "") {
            FormplayerFrontend.trigger("apps:list", apps);<commit_msg>loadDirect<commit_after>/*global Marionette, Backbone */

var FormplayerFrontend = new Marionette.Application();

var hideLoading = hqImport('cloudcare/js/util.js').hideLoading;
var showError = hqImport('cloudcare/js/util.js').showError;
var showSuccess = hqImport('cloudcare/js/util.js').showSuccess;
var showLoading = hqImport('cloudcare/js/util.js').showLoading;
var tfLoading = hqImport('cloudcare/js/util.js').tfLoading;
var tfLoadingComplete = hqImport('cloudcare/js/util.js').tfLoadingComplete;
var tfSyncComplete = hqImport('cloudcare/js/util.js').tfSyncComplete;

FormplayerFrontend.on("before:start", function () {
    var RegionContainer = Marionette.LayoutView.extend({
        el: "#app-container",

        regions: {
            main: "#main-region",
        },
    });

    FormplayerFrontend.regions = new RegionContainer();
});

FormplayerFrontend.navigate = function (route, options) {
    options || (options = {});
    Backbone.history.navigate(route, options);
};

FormplayerFrontend.getCurrentRoute = function () {
    return Backbone.history.fragment;
};

FormplayerFrontend.reqres.setHandler('currentUser', function () {
    if (FormplayerFrontend.currentUser) return FormplayerFrontend.currentUser;
    return new FormplayerFrontend.Entities.UserModel();
});

FormplayerFrontend.reqres.setHandler('startForm', function (data) {
    var loadSession = function () {
        data.onLoading = tfLoading;
        data.onLoadingComplete = tfLoadingComplete;
        data.xform_url="/webforms/player_proxy";
        data.domain = "test"
        data.onerror = function (resp) {
            showError(resp.human_readable_message || resp.message, $("#cloudcare-notifications"));
            //cloudCare.dispatch.trigger("form:error", form, caseModel);
        };
        data.onload = function (adapter, resp) {
            //cloudCare.dispatch.trigger("form:ready", form, caseModel);
        };
        data.onsubmit = function (xml) {
            window.mainView.router.view.dirty = false;
            // post to receiver
            $.ajax({
                type: 'POST',
                url: submitUrl,
                data: xml,
                success: function () {
                    //self._clearFormPlayer();
                    //self.showModule(selectedModule);
                    //cloudCare.dispatch.trigger("form:submitted");
                    showSuccess(translatedStrings.saved, $("#cloudcare-notifications"), 2500);
                },
                error: function (resp, status, message) {
                    if (message) {
                        message = translatedStrings.errSavingDetail + message;
                    } else {
                        message = translatedStrings.unknownError + status + " " + resp.status;
                        if (resp.status === 0) {
                            message = (message + ". "
                                + translatedStrings.unknownErrorDetail + " (" + submitUrl + ")");
                        }
                    }
                    data.onerror({message: message});
                    // TODO change submit button text to something other than
                    // "Submitting..." and prevent "All changes saved!" message
                    // banner at top of the form.
                }
            });
        };
        var sess = new WebFormSession(data);
        sess.loadDirect(data, $('#webforms'), FormplayerFrontend.request('currentUser').language);
    };
    loadSession();
});

FormplayerFrontend.on("start", function (apps, language) {
    FormplayerFrontend.request('currentUser').language = language;
    if (Backbone.history) {
        Backbone.history.start();
        FormplayerFrontend.trigger("apps:storeapps", apps);
        var user = FormplayerFrontend.request('currentUser');
        // will be the same for every domain. TODO: get domain/username/pass from django
        user.domain = apps[0].domain;
        if (this.getCurrentRoute() === "") {
            FormplayerFrontend.trigger("apps:list", apps);
{'fraction_non_alphanumeric': 0.1261595547309833, 'fraction_numerical': 0.001484230055658627, 'mean_word_length': 2.2382859431317583, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1690999', 'n_tokens_mistral': 2138, 'n_tokens_neox': 2059, 'n_words': 399}