<commit_before>/*
 * Wegas
 * http://wegas.albasim.ch
 *
 * Copyright (c) 2013 School of Business and Engineering Vaud, Comem
 * Licensed under the MIT License
 */
/**
 * @fileoverview
 * @author <NAME> <<EMAIL>>
 */
YUI.add('wegas-app', function(Y) {
    "use strict";

    /**
     * Create a new wegas-app
     *
     * <p><strong>Attributes</strong></p>
     * <ul>
     *    <li>base {String} base Url for app</li>
     *    <li>layoutSrc {String} location for the json config of the current page</li>
     *    <li>dataSources {Object[]} the list of datasource to be loaded on startup</li>
     *    <li>currentGameModel {Number} current game model id</li>
     *    <li>currentGame {Number} current game  id</li>
     *    <li>currentTeam {Number} current team id</li>
     *    <li>currentPlayer {Number} current player id</li>
     *    <li>currentUse {Number} current game model idObject litteral representing current user</li>
     *    <li>editorMenus {Object[]}
     *        This field is used to globally override Entities edition menus.
     *        Use the target class name as the key.
     *    </li>
     *    <li>editorForms {Object[]}
     *         This field is used to globally override Entities edition forms.
     *        Use the target class name as the key.
     *   </li>
     * </ul>
     *
     * @name Y.Wegas.App
     * @class Base class for wegas, handle initialisation of datasources and rendering
     * @extends Y.Base
     * @constructor
     * @param Object Will be used to fill attributes field
     */
    var App = Y.Base.create("wegas-app", Y.Base, [], {
        /** @lends Y.Wegas.App# */

        // ** Private fields ** //
        /**
         * Holds a reference to all the dataSources used.
         * @field
         * @private
         */
        dataSources: [],
        /**
         * Lifecycle methods
         * @function
         * @private
         */
        initializer: function() {
            Y.Wegas.app = this;
            /**
             * @name Cocktail#shake
             * @event
             * @param {MyEventObject} e
             * @param {Boolean} [e.withIce=false]
             */
            this.publish("render");
        },
        /**
         * Destructor methods.
         * @function
         * @private
         */
        destructor: function() {
            var i;
            for (i in Y.Wegas.Facade) {
                Y.Wegas.Facade[i].destroy();
            }
        },
        /**
         * Render function
         * @function
         * @private
         */
        render: function() {
            Y.io.header("Accept-Language", Y.config.lang);                      // Set the language for all requests
            Y.JSON.useNativeParse = true;                                       // @todo Shall we use browser native parser ?

            this.on("render", function() {                                      // Remove loading overlay on render
                Y.one("body").removeClass("wegas-loading-overlay");
            });

            Y.on("io:failure", function(tId, e) {                               // Add a global io failure listener
                //if (!req) {
                //    return;
                //}
                var msg = "Error sending " + e.cfg.method + " request : " + e.target.get("source") + e.request
                        + ", " + e.cfg.data + ": ";
                try {
                    var r = Y.JSON.parse(e.responseText);
                    msg += "\n Server reply " + Y.JSON.stringify(r, null, "\t");

                    if (r.exception === "org.apache.shiro.authz.UnauthenticatedException") {
                        //Y.io(this.get("base") + "/User/LoggedIn");
                        var panel = new Y.Wegas.Panel({
                            content: "<div class='icon icon-info'>You have been logged out.</div>",
                            modal: true,
                            centered: true,
                            buttons: {
                                footer: [{
                                        label: 'Click here to reconnect',
                                        action: function() {
                                            Y.config.win.location.reload();
                                            //Y.config.win.location.href = Y.config.win.location.href + "#";
                                        }
                                    }]
                            }
                        });
                        panel.render();
                        e.preventDefault();
                        return;
                    } else if (r.exception === "org.apache.shiro.authz.UnauthorizedException") {
                        // @todo Do something?
                    }
                } catch (e) {                                                   // JSON PARSE ERROR
                    msg += "\n Server reply " + (e && e.responseText);
                }
                Y.log(msg, "error");
                if (window.Muscula) {                                           // Send an event to muscula
                    window.Muscula.errors.push(new Error(msg));
                }
            }, this);

            this.initDataSources();

            /**
             * Shortcut to activate developper mode. Allow access to Y instance. Toggle.
             * Event keypress ''
             */
            Y.one("body").on("key", function() {
                Y.Wegas.app.set("devMode", !Y.Wegas.app.get("devMode"));
            }, "167");
        },
        // *** Private methods ** //
        /**
         * @function<commit_msg>Fix io:failure handler<commit_after>/*
 * Wegas
 * http://wegas.albasim.ch
 *
 * Copyright (c) 2013 School of Business and Engineering Vaud, Comem
 * Licensed under the MIT License
 */
/**
 * @fileoverview
 * @author <NAME> <<EMAIL>>
 */
YUI.add('wegas-app', function(Y) {
    "use strict";

    /**
     * Create a new wegas-app
     *
     * <p><strong>Attributes</strong></p>
     * <ul>
     *    <li>base {String} base Url for app</li>
     *    <li>layoutSrc {String} location for the json config of the current page</li>
     *    <li>dataSources {Object[]} the list of datasource to be loaded on startup</li>
     *    <li>currentGameModel {Number} current game model id</li>
     *    <li>currentGame {Number} current game  id</li>
     *    <li>currentTeam {Number} current team id</li>
     *    <li>currentPlayer {Number} current player id</li>
     *    <li>currentUse {Number} current game model idObject litteral representing current user</li>
     *    <li>editorMenus {Object[]}
     *        This field is used to globally override Entities edition menus.
     *        Use the target class name as the key.
     *    </li>
     *    <li>editorForms {Object[]}
     *         This field is used to globally override Entities edition forms.
     *        Use the target class name as the key.
     *   </li>
     * </ul>
     *
     * @name Y.Wegas.App
     * @class Base class for wegas, handle initialisation of datasources and rendering
     * @extends Y.Base
     * @constructor
     * @param Object Will be used to fill attributes field
     */
    var App = Y.Base.create("wegas-app", Y.Base, [], {
        /** @lends Y.Wegas.App# */

        // ** Private fields ** //
        /**
         * Holds a reference to all the dataSources used.
         * @field
         * @private
         */
        dataSources: [],
        /**
         * Lifecycle methods
         * @function
         * @private
         */
        initializer: function() {
            Y.Wegas.app = this;
            /**
             * @name Cocktail#shake
             * @event
             * @param {MyEventObject} e
             * @param {Boolean} [e.withIce=false]
             */
            this.publish("render");
        },
        /**
         * Destructor methods.
         * @function
         * @private
         */
        destructor: function() {
            var i;
            for (i in Y.Wegas.Facade) {
                Y.Wegas.Facade[i].destroy();
            }
        },
        /**
         * Render function
         * @function
         * @private
         */
        render: function() {
            Y.io.header("Accept-Language", Y.config.lang);                      // Set the language for all requests
            Y.JSON.useNativeParse = true;                                       // @todo Shall we use browser native parser ?

            this.on("render", function() {                                      // Remove loading overlay on render
                Y.one("body").removeClass("wegas-loading-overlay");
            });

            Y.on("io:failure", function(tId, req, e) {                          // Add a global io failure listener
                var msg;
                try {
                    msg = "Error sending " + e.cfg.method + " request : " + e.target.get("source") + e.request
                            + ", " + e.cfg.data + ": ";
                } catch (e) {
                    msg = "Error sending request: ";
                }
                try {
                    var r = Y.JSON.parse(req.responseText);
                    msg += "\n Server reply " + Y.JSON.stringify(r, null, "\t");

                    if (r.exception === "org.apache.shiro.authz.UnauthenticatedException") {
                        //Y.io(this.get("base") + "/User/LoggedIn");
                        var panel = new Y.Wegas.Panel({
                            content: "<div class='icon icon-info'>You have been logged out.</div>",
                            modal: true,
                            centered: true,
                            buttons: {
                                footer: [{
                                        label: 'Click here to reconnect',
                                        action: function() {
                                            Y.config.win.location.reload();
                                            //Y.config.win.location.href = Y.config.win.location.href + "#";
                                        }
                                    }]
                            }
                        });
                        panel.render();
                        e.preventDefault();
                        return;
                    } else if (r.exception === "org.apache.shiro.authz.UnauthorizedException") {
                        // @todo Do something?
                    }
                } catch (e) {                                                   // JSON PARSE ERROR
                    msg += "\n Server reply " + (req && req.responseText);
                }
                Y.log(msg, "error");
                if (window.Muscula) {                                           // Send an event to muscula
                    window.Muscula.errors.push(new Error(msg));
                }
            }, this);

            this.initDataSources();

            /**
             * Shortcut to activate developper mode. Allow access to Y instance. Toggle.
             * Event keypress ''
             */
            Y.one("body").on("key", function() {
                Y.Wegas.app.set("devMode", !Y.Wegas.app.get("devMode"));
            }, "167");
        },
        // *** Private methods ** //
        /**
         * @function
{'fraction_non_alphanumeric': 0.12083369976255387, 'fraction_numerical': 0.0012312021809867207, 'mean_word_length': 1.1082684464219503, 'pattern_counts': {'":': 2, '<': 65, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5445839', 'n_tokens_mistral': 2946, 'n_tokens_neox': 2832, 'n_words': 727}