<commit_before>/**
 *
 *
 */
(function () {
    'use strict';
    CPM.namespace('console');
    core.console = CPM.console; // core.console for compatibility ... @deprecated

    (function (console, core) {

        core.initPermissions = function () {
            location.reload(); // FIXME: to refactor
        };

        console.getProfile = function () {
            return console.profile;
        };

        console.openUserLoginDialog = function (action) {
            var loginDialog = core.getView('#user-status-dialog', console.UserLoginDialog);
            if (!loginDialog) {
                core.getHtml('/libs/composum/nodes/console/dialogs.user-status.html',
                    _.bind(function (content) {
                        loginDialog = core.addLoadedDialog(console.UserLoginDialog, content);
                        if (loginDialog) {
                            if (_.isFunction(action)) {
                                action(loginDialog);
                            } else {
                                loginDialog.show();
                            }
                        }
                    }, this));
            } else {
                if (_.isFunction(action)) {
                    action(loginDialog);
                } else {
                    loginDialog.show();
                }
            }
        };

        console.authorize = function (retryThisFailedCall) {
            console.openUserLoginDialog(_.bind(function (loginDialog) {
                loginDialog.handleUnauthorized(retryThisFailedCall);
            }, this));
        };

        //
        // login and profile
        //

        console.profile = new core.LocalProfile('composum.core');

        console.UserLoginDialog = core.components.Dialog.extend({

            initialize: function (options) {
                core.components.Dialog.prototype.initialize.apply(this, [options]);
                this.$content = this.$('.modal-content');
                this.$form = this.$('form');
                this.$login = this.$('button.login');
                this.$logout = this.$('button.logout');
                this.$form.on('submit', _.bind(this.login, this));
                this.$login.click(_.bind(this.login, this));
                this.$logout.click(_.bind(this.logout, this));
                this.$el.on('shown.bs.modal', _.bind(this.onShown, this));
                this.callsToRetry = [];
                this.showing = false;
            },

            /**
             * collect all failed request calls to retry after successful login
             * @param retryThisFailedCall the call to retry after login
             */
            handleUnauthorized: function (retryThisFailedCall) {
                if (this.showing) {
                    // collect all failed calls during login
                    this.callsToRetry.push(retryThisFailedCall);
                } else {
                    // show login dialog and collect failed calls...
                    this.showing = true;
                    this.callsToRetry = [retryThisFailedCall];
                    this.show(undefined, _.bind(function () {
                        // retry after login all collected calls
                        this.callsToRetry.forEach(function (retryThisFailedCall) {
                            retryThisFailedCall();
                        });
                        this.showing = false;
                        this.callsToRetry = [];
                    }, this), 'authorization');
                }
            },

            show: function (initView, callback, type) {
                this.$content.removeClass();
                this.$content.addClass('modal-content');
                if (type) {
                    this.$content.addClass(type);
                }
                core.components.Dialog.prototype.show.apply(this, [initView, callback]);
            },

            /**
             * initialization after shown...
             */
            onShown: function () {
                this.$('input[name="j_username"]').focus();
            },

            logout: function (event) {
                event.preventDefault();
                var url = this.$logout.data('url');
                if (!url) {
                    url = '/system/sling/logout.html?logout=true&GLO=true';
                }
                core.getHtml(url, undefined, undefined, _.bind(function (data) {
                    this.hide();
                    core.initPermissions();
                }, this));
            },

            login: function (event) {
                event.preventDefault();
                this.submitForm(_.bind(function () {
                        if (_.isFunction(this.callback)) {
                            this.hide();
                        } else {
                            core.initPermissions();
                        }
                    }, this),
                    _.bind(function (result) {
                        this.alert('danger', core.resultMessage(result));
                    }, this));
                return false;
            }
        });

        //
        // navbar
        //

        console.NavBar = Backbone.View.extend({

            el: $('header.navbar')[0],

            initialize: function () {
                var consoleId = $('body').attr('id');
                this.$('.nav-item.' + consoleId).addClass('active');
                this.$('.nav-user-status').on('click', _.bind(function () {
                    console.openUserLoginDialog();
                }, this));
                this.$status = this.$('.system-health-monitor');
                this.$healthState = this.$status.find('span');
                this.$status.click(_.bind(this.showStatus, this));
                this.system = core.getWidget(this.$status, '.composum-nodes-system', CPM.nodes.system.Status);
                $(document).on('system:health', _.bind(this.onSystemHealth, this));
            },

            onSystemHealth: function (event, status, data) {
                this.$healthState.removeClass().addClass(
                    'system-health-state system-health-' + (status ? status : 'unknown'));
            },

            showStatus: function () {
                if (this.$healthState.is('.system-health-state')) { // if status visible (accessible and loaded)...
                    core.openFormDialog('/libs/composum/nodes/commons/components/system/dialog.html',
                        CPM.nodes.system.StatusDialog);
                }
            }
        });

        console.navbar = new core.console.NavBar();

        //
        // detail view (generalized base class)
        //

        /**
         * the base 'class' for all detail tabs
         */
        console.DetailTab = Backbone.View.extend({

            reload: function () {<commit_msg>fix for the navbar initialiazing error in the standalone code editor page<commit_after>/**
 *
 *
 */
(function () {
    'use strict';
    CPM.namespace('console');
    core.console = CPM.console; // core.console for compatibility ... @deprecated

    (function (console, core) {

        core.initPermissions = function () {
            location.reload(); // FIXME: to refactor
        };

        console.getProfile = function () {
            return console.profile;
        };

        console.openUserLoginDialog = function (action) {
            var loginDialog = core.getView('#user-status-dialog', console.UserLoginDialog);
            if (!loginDialog) {
                core.getHtml('/libs/composum/nodes/console/dialogs.user-status.html',
                    _.bind(function (content) {
                        loginDialog = core.addLoadedDialog(console.UserLoginDialog, content);
                        if (loginDialog) {
                            if (_.isFunction(action)) {
                                action(loginDialog);
                            } else {
                                loginDialog.show();
                            }
                        }
                    }, this));
            } else {
                if (_.isFunction(action)) {
                    action(loginDialog);
                } else {
                    loginDialog.show();
                }
            }
        };

        console.authorize = function (retryThisFailedCall) {
            console.openUserLoginDialog(_.bind(function (loginDialog) {
                loginDialog.handleUnauthorized(retryThisFailedCall);
            }, this));
        };

        //
        // login and profile
        //

        console.profile = new core.LocalProfile('composum.core');

        console.UserLoginDialog = core.components.Dialog.extend({

            initialize: function (options) {
                core.components.Dialog.prototype.initialize.apply(this, [options]);
                this.$content = this.$('.modal-content');
                this.$form = this.$('form');
                this.$login = this.$('button.login');
                this.$logout = this.$('button.logout');
                this.$form.on('submit', _.bind(this.login, this));
                this.$login.click(_.bind(this.login, this));
                this.$logout.click(_.bind(this.logout, this));
                this.$el.on('shown.bs.modal', _.bind(this.onShown, this));
                this.callsToRetry = [];
                this.showing = false;
            },

            /**
             * collect all failed request calls to retry after successful login
             * @param retryThisFailedCall the call to retry after login
             */
            handleUnauthorized: function (retryThisFailedCall) {
                if (this.showing) {
                    // collect all failed calls during login
                    this.callsToRetry.push(retryThisFailedCall);
                } else {
                    // show login dialog and collect failed calls...
                    this.showing = true;
                    this.callsToRetry = [retryThisFailedCall];
                    this.show(undefined, _.bind(function () {
                        // retry after login all collected calls
                        this.callsToRetry.forEach(function (retryThisFailedCall) {
                            retryThisFailedCall();
                        });
                        this.showing = false;
                        this.callsToRetry = [];
                    }, this), 'authorization');
                }
            },

            show: function (initView, callback, type) {
                this.$content.removeClass();
                this.$content.addClass('modal-content');
                if (type) {
                    this.$content.addClass(type);
                }
                core.components.Dialog.prototype.show.apply(this, [initView, callback]);
            },

            /**
             * initialization after shown...
             */
            onShown: function () {
                this.$('input[name="j_username"]').focus();
            },

            logout: function (event) {
                event.preventDefault();
                var url = this.$logout.data('url');
                if (!url) {
                    url = '/system/sling/logout.html?logout=true&GLO=true';
                }
                core.getHtml(url, undefined, undefined, _.bind(function (data) {
                    this.hide();
                    core.initPermissions();
                }, this));
            },

            login: function (event) {
                event.preventDefault();
                this.submitForm(_.bind(function () {
                        if (_.isFunction(this.callback)) {
                            this.hide();
                        } else {
                            core.initPermissions();
                        }
                    }, this),
                    _.bind(function (result) {
                        this.alert('danger', core.resultMessage(result));
                    }, this));
                return false;
            }
        });

        //
        // navbar
        //

        console.NavBar = Backbone.View.extend({

            el: $('header.navbar')[0],

            initialize: function () {
                var consoleId = $('body').attr('id');
                this.$('.nav-item.' + consoleId).addClass('active');
                this.$('.nav-user-status').on('click', _.bind(function () {
                    console.openUserLoginDialog();
                }, this));
                if (CPM.nodes && CPM.nodes.system) {
                    this.$status = this.$('.system-health-monitor');
                    this.$healthState = this.$status.find('span');
                    this.$status.click(_.bind(this.showStatus, this));
                    this.system = core.getWidget(this.$status, '.composum-nodes-system', CPM.nodes.system.Status);
                    $(document).on('system:health', _.bind(this.onSystemHealth, this));
                }
            },

            onSystemHealth: function (event, status, data) {
                this.$healthState.removeClass().addClass(
                    'system-health-state system-health-' + (status ? status : 'unknown'));
            },

            showStatus: function () {
                if (this.$healthState.is('.system-health-state')) { // if status visible (accessible and loaded)...
                    core.openFormDialog('/libs/composum/nodes/commons/components/system/dialog.html',
                        CPM.nodes.system.StatusDialog);
                }
            }
        });

        console.navbar = new core.console.NavBar();

        //
        // detail view (generalized base class)
        //

        /**
         * the base 'class' for all detail tabs
         */
        console.DetailTab = Backbone.View.extend({

            reload: function () {
{'fraction_non_alphanumeric': 0.1241811244690807, 'fraction_numerical': 0.0001439781153264704, 'mean_word_length': 1.24607922392886, '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': '1892442', 'n_tokens_mistral': 3376, 'n_tokens_neox': 3182, 'n_words': 572}