Ext.define('CheckboxClass15', {
    extend: 'DisplayableAction',
    constructor: function(cfgXML, o, actionSequence){
        this.CheckBox = null;
        this.CheckBoxWidth = 0;
        this.CheckBoxHeight = 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.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();
    },
    initializeDC: function(bg){
        this.initializeDisplayComponent(bg);
        //initialize the pictureBox first
        this.CheckBox = this.ContentContainer.createChild({
            tag: "input",
            id: this.ObjectType + "-" + this.id + "-OptionButton",
            type: "checkbox",
            style: "position:absolute;"
        });
        this.CheckBoxWidth = this.CheckBox.getWidth();
        this.CheckBoxHeight = this.CheckBox.getHeight();
 //       this.CheckBox.applyStyles("left:" + (40 - this.CheckBoxWidth) / 2 + "px;top:" + (this.ContentContainerHeight - this.CheckBoxHeight) / 2 + "px;");
        this.CheckBox.applyStyles("left: 0" + "px;top:" + ((this.ContentContainerHeight - this.CheckBoxHeight) / 2 - 1) + "px;");
        this.CheckBox.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);
    },
    getInteractionValue: function(){

        return this.IsChecked.toString();
    },
    onClick: function(evt, el, o){
        this.IsChecked = !this.IsChecked;
        this.setButtonAppearanceBaseOnStatus();
        evt.stopPropagation();
        if (this.RespondToClick) {
            var v = this.getInteractionValue();
            Author.DisplayManager.tryToTriggerResponse(this.Name, v, this.Name);
        }
    },
    calculateTextBoxLayout: function(){
        this.TextBoxLayout = {
            Width: this.ContentContainerWidth - 20,
            Height: this.ContentContainerHeight,
            Left: 20,
            Top: 0
        };
    },
    setButtonAppearanceBaseOnStatus: function(){
        if (this.CheckBox == null)
            return;
        this.CheckBox.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;
    },
    processAction: function(bg){
        if (this.IsChangeAction) {
            Author.DisplayManager.changeAction(this);
        }
        this.initializeDC(bg);
        this.setInitialVisibility();
        this.applyEffect();
        return {MoveOn: true, Interval: 0};
    }
});














