<commit_before>/**
 * conjoon
 * (c) 2002-2009 siteartwork.de/conjoon.org
 * <EMAIL>
 *
 * $Author$
 * $Id$
 * $Date$
 * $Revision$
 * $LastChangedDate$
 * $LastChangedBy$
 * $URL$
 */


Ext.namespace('com.conjoon.groupware.service.youtube');

/**
 * A singleton for managing actions related to watching youtube videos.
 *
 *
 * @class com.conjoon.groupware.service.youtube.ViewBaton
 * @singleton
 */
com.conjoon.groupware.service.youtube.ViewBaton = function() {

    /**
     * @type {Ext.ux.YoutubePlayer} player
     */
    var player;

    /**
     * @type {Ext.Panel} basePanel
     */
    var basePanel;

    /**
     * @type {com.conjoon.groupware.service.youtube.FeaturePanel} featurePanel
     */
    var featurePanel;

    /**
     * @type {Ext.ux.YoutubePlayer.Control} control
     */
    var control;

    /**
     * @type {Ext.ux.util.FlashControl} flashControl
     */
    var flashControl;

    /**
     * Builds a new {Ext.ux.YoutubePlayer} if there was an api-key found in the registry,
     * otherwise it returns null.
     *
     * @return {Ext.ux.YoutubePlayer}
     */
    var buildPlayer = function()
    {
        var apiKey = com.conjoon.groupware.Registry.get(
            '/service/youtube/chromeless/api-key'
        );

        if (!apiKey) {
            return null;
        }

        return new Ext.ux.YoutubePlayer({
            developerKey : apiKey,
            playerId     : 'myplayer',
            ratioMode    : 'stretch',
            hideMode     : 'offsets',
            bgColor      : "#000000",
            bodyStyle    : 'background-color:#000000;'
        });
    };

    /**
     * Builds up a new control for the player used by this singleton.
     *
     * @return {Ext.ux.YoutubePlayer.Control}
     */
    var buildControl = function()
    {
        return new Ext.ux.YoutubePlayer.Control({
            player   : player,
            border   : false,
            id       : 'control',
            style    : 'border:none;',
            _onEject : function() {
                var control = this;
                var msg   = Ext.MessageBox;
                    msg.show({
                        prompt : true,
                        title   : com.conjoon.Gettext.gettext("Load video"),
                        msg     : com.conjoon.Gettext.gettext("Please submit the id or the full url of the youtube video you want to load."),
                        buttons : msg.OKCANCEL,
                        fn      : function(btn, text){
                                    if (btn != 'ok') {
                                       return;
                                    }
                                    com.conjoon.groupware.service.youtube.VideoDirector.loadVideo(text);
                                  },
                        icon    : msg.QUESTION,
                        cls     :'com-conjoon-msgbox-prompt',
                        width   : 375
                    });
            }
        });
    };

    /**
     * Returns the Ext.Panel that holds the player and its control.
     *
     * @return {Ext.Panel}
     */
    var buildBasePanel = function()
    {
       return new Ext.Panel({
            title     : 'Ytube',
            hideMode  : 'offsets',
            cls       : 'youtube',
            layout    : 'fit',
            bbar      : control
        });
    };

    /**
     * Returns the com.conjoon.groupware.service.youtube.FeaturePanel that<commit_msg> - enhancement: added "_onError"-override for Ext.ux.YoutubePlayer.Control to properly show an error dialog (SystemMessage) if any error occurres while loading/playing a video <commit_after>/**
 * conjoon
 * (c) 2002-2009 siteartwork.de/conjoon.org
 * <EMAIL>
 *
 * $Author$
 * $Id$
 * $Date$
 * $Revision$
 * $LastChangedDate$
 * $LastChangedBy$
 * $URL$
 */


Ext.namespace('com.conjoon.groupware.service.youtube');

/**
 * A singleton for managing actions related to watching youtube videos.
 *
 *
 * @class com.conjoon.groupware.service.youtube.ViewBaton
 * @singleton
 */
com.conjoon.groupware.service.youtube.ViewBaton = function() {

    /**
     * @type {Ext.ux.YoutubePlayer} player
     */
    var player;

    /**
     * @type {Ext.Panel} basePanel
     */
    var basePanel;

    /**
     * @type {com.conjoon.groupware.service.youtube.FeaturePanel} featurePanel
     */
    var featurePanel;

    /**
     * @type {Ext.ux.YoutubePlayer.Control} control
     */
    var control;

    /**
     * @type {Ext.ux.util.FlashControl} flashControl
     */
    var flashControl;

    /**
     * Builds a new {Ext.ux.YoutubePlayer} if there was an api-key found in the registry,
     * otherwise it returns null.
     *
     * @return {Ext.ux.YoutubePlayer}
     */
    var buildPlayer = function()
    {
        var apiKey = com.conjoon.groupware.Registry.get(
            '/service/youtube/chromeless/api-key'
        );

        if (!apiKey) {
            return null;
        }

        return new Ext.ux.YoutubePlayer({
            developerKey : apiKey,
            playerId     : 'myplayer',
            ratioMode    : 'stretch',
            hideMode     : 'offsets',
            bgColor      : "#000000",
            bodyStyle    : 'background-color:#000000;'
        });
    };

    /**
     * Builds up a new control for the player used by this singleton.
     *
     * @return {Ext.ux.YoutubePlayer.Control}
     */
    var buildControl = function()
    {
        return new Ext.ux.YoutubePlayer.Control({
            player   : player,
            border   : false,
            id       : 'control',
            style    : 'border:none;',
            _onEject : function() {
                var control = this;
                var msg   = Ext.MessageBox;
                    msg.show({
                        prompt : true,
                        title   : com.conjoon.Gettext.gettext("Load video"),
                        msg     : com.conjoon.Gettext.gettext("Please submit the id or the full url of the youtube video you want to load."),
                        buttons : msg.OKCANCEL,
                        fn      : function(btn, text){
                                    if (btn != 'ok') {
                                       return;
                                    }
                                    com.conjoon.groupware.service.youtube.VideoDirector.loadVideo(text);
                                  },
                        icon    : msg.QUESTION,
                        cls     :'com-conjoon-msgbox-prompt',
                        width   : 375
                    });
            },
            _onError : function(errorCode, playerPanel, player) {
                playerPanel.stopVideo();

                com.conjoon.SystemMessageManager.error(new com.conjoon.SystemMessage({
                    title : com.conjoon.Gettext.gettext("Error"),
                    text  : String.format(
                        com.conjoon.Gettext.gettext("The video you requested could not be played. Error code \"{0}\"."),
                        errorCode
                    )
                }));
            }
        });
    };

    /**
     * Returns the Ext.Panel that holds the player and its control.
     *
     * @return {Ext.Panel}
     */
    var buildBasePanel = function()
    {
       return new Ext.Panel({
            title     : 'Ytube',
            hideMode  : 'offsets',
            cls       : 'youtube',
            layout    : 'fit',
            bbar      : control
        });
    };

    /**
     * Returns the com.conjoon.groupware.service.youtube.FeaturePanel that
{'fraction_non_alphanumeric': 0.11254953764861295, 'fraction_numerical': 0.006208718626155878, 'mean_word_length': 1.3454151177199505, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6077661', 'n_tokens_mistral': 2213, 'n_tokens_neox': 2056, 'n_words': 455}