<commit_before>"use strict";

var $ = require('jquery'),
    Marionette = require('../shim/backbone.marionette'),
    shutterbug = require('../shim/shutterbug'),
    views = require('./core/views'),
    LayerPickerView = require('./core/layerPicker'),
    models = require('./core/models'),
    settings = require('./core/settings'),
    itsi = require('./core/itsiEmbed'),
    analyzeModels = require('./analyze/models'),
    userModels = require('./user/models'),
    userViews = require('./user/views');

var App = new Marionette.Application({
    initialize: function() {
        this.restApi = new RestAPI();
        this.map = new models.MapModel();
        this.layerTabs = new models.LayerTabCollection(null);
        this.state = new models.AppStateModel();

        // If in embed mode we are by default in activity mode.
        var activityMode = settings.get('itsi_enabled') &&
                settings.get('itsi_embed');
        settings.set('activityMode', activityMode);

        // Initialize embed interface if in activity mode
        if (activityMode) {
            this.itsi = new itsi.ItsiEmbed(this);
            this.itsi.getAuthInfo();
        }

        // This view is intentionally not attached to any region.
        this._mapView = new views.MapView({
            model: this.map,
            layerTabCollection: this.layerTabs,
            el: '#map'
        });

        this._mapView.on('change:needs_reset', function(needs) {
            App.currentProject.set('needs_reset', needs);
        });

        this.layerTabs.disableLayersOnZoomAndPan(this.getLeafletMap());

        this.rootView = new views.RootView({app: this});
        this.user = new userModels.UserModel({});

        this.header = new views.HeaderView({
            el: 'header',
            model: this.user,
            appState: this.state
        });

        this.header.render();

        if (settings.isLayerSelectorEnabled()) {
            this.showLayerPicker();
        }

        // Not set until modeling/controllers.js creates a
        // new project.
        this.currentProject = null;

        // Enable screenshot functionality
        initializeShutterbug();
    },

    load: function(data) {
        var mapState = data.map;
        if (mapState) {
            this.map.set({
                lat: mapState.lat,
                lng: mapState.lng,
                zoom: mapState.zoom
            });
        }
    },

    getLayerTabCollection: function() {
        return this.layerTabs;
    },

    showLayerPicker: function() {
        this.layerPickerView = new LayerPickerView({
            collection: this.layerTabs,
            leafletMap: this.getLeafletMap(),
        });
        this.rootView.layerPickerRegion.show(this.layerPickerView);
    },

    getAnalyzeCollection: function() {
        if (!this.analyzeCollection) {
            var aoi = this.map.get('areaOfInterest'),
                wkaoi = this.map.get('wellKnownAreaOfInterest');

            this.analyzeCollection = analyzeModels.createAnalyzeTaskCollection(aoi, wkaoi);
        }

        return this.analyzeCollection;
    },

    clearAnalyzeCollection: function() {
        delete this.analyzeCollection;
    },

    getMapView: function() {
        return this._mapView;
    },

    getLeafletMap: function() {
        return this._mapView._leafletMap;
    },

    getUserOrShowLoginIfNotItsiEmbed: function() {
        if (!settings.get('itsi_embed')) {
            this.getUserOrShowLogin();
        }
    },

    getUserOrShowLogin: function() {
        this.user.fetch().always(function() {
            if (App.user.get('guest')) {
                App.showLoginModal();
            }
        });
    },

    showLoginModal: function(onSuccess) {
        new userViews.LoginModalView({
            model: new userModels.LoginFormModel({
                showItsiButton: settings.get('itsi_enabled'),
                successCallback: onSuccess
            }),<commit_msg>Allow Passing Of Success-Callback To Login/Signup Prompt<commit_after>"use strict";

var $ = require('jquery'),
    Marionette = require('../shim/backbone.marionette'),
    shutterbug = require('../shim/shutterbug'),
    views = require('./core/views'),
    LayerPickerView = require('./core/layerPicker'),
    models = require('./core/models'),
    settings = require('./core/settings'),
    itsi = require('./core/itsiEmbed'),
    analyzeModels = require('./analyze/models'),
    userModels = require('./user/models'),
    userViews = require('./user/views');

var App = new Marionette.Application({
    initialize: function() {
        this.restApi = new RestAPI();
        this.map = new models.MapModel();
        this.layerTabs = new models.LayerTabCollection(null);
        this.state = new models.AppStateModel();

        // If in embed mode we are by default in activity mode.
        var activityMode = settings.get('itsi_enabled') &&
                settings.get('itsi_embed');
        settings.set('activityMode', activityMode);

        // Initialize embed interface if in activity mode
        if (activityMode) {
            this.itsi = new itsi.ItsiEmbed(this);
            this.itsi.getAuthInfo();
        }

        // This view is intentionally not attached to any region.
        this._mapView = new views.MapView({
            model: this.map,
            layerTabCollection: this.layerTabs,
            el: '#map'
        });

        this._mapView.on('change:needs_reset', function(needs) {
            App.currentProject.set('needs_reset', needs);
        });

        this.layerTabs.disableLayersOnZoomAndPan(this.getLeafletMap());

        this.rootView = new views.RootView({app: this});
        this.user = new userModels.UserModel({});

        this.header = new views.HeaderView({
            el: 'header',
            model: this.user,
            appState: this.state
        });

        this.header.render();

        if (settings.isLayerSelectorEnabled()) {
            this.showLayerPicker();
        }

        // Not set until modeling/controllers.js creates a
        // new project.
        this.currentProject = null;

        // Enable screenshot functionality
        initializeShutterbug();
    },

    load: function(data) {
        var mapState = data.map;
        if (mapState) {
            this.map.set({
                lat: mapState.lat,
                lng: mapState.lng,
                zoom: mapState.zoom
            });
        }
    },

    getLayerTabCollection: function() {
        return this.layerTabs;
    },

    showLayerPicker: function() {
        this.layerPickerView = new LayerPickerView({
            collection: this.layerTabs,
            leafletMap: this.getLeafletMap(),
        });
        this.rootView.layerPickerRegion.show(this.layerPickerView);
    },

    getAnalyzeCollection: function() {
        if (!this.analyzeCollection) {
            var aoi = this.map.get('areaOfInterest'),
                wkaoi = this.map.get('wellKnownAreaOfInterest');

            this.analyzeCollection = analyzeModels.createAnalyzeTaskCollection(aoi, wkaoi);
        }

        return this.analyzeCollection;
    },

    clearAnalyzeCollection: function() {
        delete this.analyzeCollection;
    },

    getMapView: function() {
        return this._mapView;
    },

    getLeafletMap: function() {
        return this._mapView._leafletMap;
    },

    getUserOrShowLoginIfNotItsiEmbed: function() {
        if (!settings.get('itsi_embed')) {
            this.getUserOrShowLogin();
        }
    },

    getUserOrShowLogin: function(onSuccess) {
        this.user.fetch().always(function() {
            if (App.user.get('guest')) {
                App.showLoginModal(onSuccess);
            }
        });
    },

    showLoginModal: function(onSuccess) {
        new userViews.LoginModalView({
            model: new userModels.LoginFormModel({
                showItsiButton: settings.get('itsi_enabled'),
                successCallback: onSuccess
            }),
{'fraction_non_alphanumeric': 0.1237988269062773, 'fraction_numerical': 0.0, 'mean_word_length': 2.059946544482627, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7621063', 'n_tokens_mistral': 2258, 'n_tokens_neox': 2161, 'n_words': 416}