Ext.define('RadioButtonClass15', {
    extend: 'DisplayableAction',
    constructor: function(cfgXML, o, actionSequence){
        this.OptionButton = null;
        this.OptionButtonWidth = 0;
        this.OptionButtonHeight = 0;
        this.TextBoxLayout = {
            Left: 0,
            Top: 0,
            Width: 0,
            Height: 0
        };
        this.TextBlock = null;
        this.Text = "";
        this.TextAlignmentH = 'Center';
        this.IsChecked = false;
        this.FontFamily = 'Arial';
        this.FontSize = 14;
        this.FontWeight = 'Normal';
        this.FontStyle = 'Normal';
        this.TextDecoration = 'none';
        this.callParent([cfgXML, o, actionSequence]);
        //start self
        this.Text = XmlHelper.getString(cfgXML, "text");
        this.FontFamily = XmlHelper.getString(cfgXML, "fontFamily");
        this.FontSize = XmlHelper.getFloat(cfgXML, "fontSize");
        this.TextDecoration = XmlHelper.getString(cfgXML, "textDecoration");
        this.FontStyle = XmlHelper.getString(cfgXML, "fontStyle");
        this.FontWeight = XmlHelper.getString(cfgXML, "fontWeight");
        this.FontColor = XmlHelper.getString(cfgXML, "fontColor");
        this.TextAlignmentH = XmlHelper.getString(cfgXML, "textAlignmentH");
        this.InitialValue = XmlHelper.tryGetValue(cfgXML, "value", TryGetValueOption.Normal, "False");
        this.OptionGroup = XmlHelper.tryGetValue(cfgXML, "optionGroup", TryGetValueOption.Normal, null);
        this.RespondToClick = XmlHelper.getBoolean(cfgXML, "respondToClick");
        this.setInitialCheckState();
    },
    setInitialCheckState: function(){
        var value = ExpressionEngine.evalExpression(this.InitialValue);
        if (value === 'False') {
            value = false;
        }
        this.IsChecked = new Boolean(value).valueOf();  //0,null,"",false,undefined,NaN is false, otherwise is true
    },
    reset: function(){
        this.setInitialCheckState();
        this.IsChecked = false;
        this.setButtonAppearanceBaseOnStatus();
    },
    getInteractionValue: function(){
        return this.IsChecked.toString();
    },
    calculateTextBoxLayout: function(){
        this.TextBoxLayout = {
            Width: this.ContentContainerWidth - 20,
            Height: this.ContentContainerHeight,
            Left: 20,
            Top: 0
        };
    },
    setButtonAppearanceBaseOnStatus: function(){
        if (this.OptionButton == null)
            return;
        if (this.OptionButton.dom.checked != this.IsChecked)
            this.OptionButton.dom.checked = this.IsChecked;
    },
    getTextStyle: function(){
        var textStyle = "position:absolute;left:" + this.TextBoxLayout.Left + "px;width:" + this.TextBoxLayout.Width + "px;text-align:" + this.TextAlignmentH + ";";
        textStyle += "font-family:" + this.FontFamily + ";";
        textStyle += "font-size:" + this.FontSize + "px;";
        textStyle += "font-style:" + this.FontStyle + ";";
        textStyle += "font-weight:" + this.FontWeight + ";";
        textStyle += "text-decoration:" + this.TextDecoration + ";";
        textStyle += "color:" + this.FontColor + ";";
        textStyle += "white-space:pre-wrap;"

        return textStyle;
    },
    initializeDC: function(bg){
        this.initializeDisplayComponent(bg);
        //initialize the pictureBox first
        this.OptionButton = this.ContentContainer.createChild({
            tag: "input",
            id: this.ObjectType + "-" + this.id + "-OptionButton",
            type: "radio",
            style: "position:absolute;"
        });
        this.OptionButtonWidth = this.OptionButton.getWidth();
        this.OptionButtonHeight = this.OptionButton.getHeight();
        this.OptionButton.applyStyles("left: 0" + "px;top:" + ((this.ContentContainerHeight - this.OptionButtonHeight) / 2 - 1) + "px;");
        this.OptionButton.applyStyles("margin: 1px 1px 1px 1px;");
        this.calculateTextBoxLayout();
        this.TextBlock = this.ContentContainer.createChild({
            tag: 'div',
            id: this.ObjectType + "-" + this.id + "-TextBlock",
            style: this.getTextStyle(),
            html: this.Text
        });
        var tH = this.TextBlock.getHeight();
        this.TextBlock.setStyle('top', ((this.TextBoxLayout.Height - tH) / 2) + "px");
        this.setButtonAppearanceBaseOnStatus();
        this.setupEventListeners();
    },
    setupEventListeners: function(){
        this.ContentContainer.addListener("click", this.onClick, this);
    },
    onClick: function(evt, el, o){
        this.IsChecked = true;
        this.setButtonAppearanceBaseOnStatus();
        if (this.IsChecked) {
            this.checkReset();
        }
        evt.stopPropagation();
        if (this.RespondToClick) {
            var v = this.getInteractionValue();
            Author.DisplayManager.tryToTriggerResponse(this.Name, v, this.Name);
        }
    },
    checkReset: function(){
        Author.CurrentStateManager.CurrentActionList.each(function(item, index, length){
            if (item.ObjectType == "RADIOBUTTON" && item.OptionGroup == this.OptionGroup) {
                if (item.id != this.id) {
                    item.IsChecked = false;
                    item.setButtonAppearanceBaseOnStatus();
                }
            }
        }, this);
    },
    processAction: function(bg){
        if (this.IsChangeAction) {
            Author.DisplayManager.changeAction(this);
        }
        this.initializeDC(bg);
        this.setInitialVisibility();
        this.applyEffect();
        return {MoveOn: true, Interval: 0};
    }
});






