﻿/*
Javascript button control
*/

var WebButton = Class.create();

WebButton.prototype =
{
    // Constructor
    initialize : function(piText)
    {
        // Declare variable holding the button text
        this._text = piText;
        // Declare variable holding the click event handler function
        this.OnClick;
    },
    
    GetHtml : function()
    {
        try
        {
            // Create button container
            var button = Builder.node('ul');
            button.className = 'WebButton';
            
            // Create left button part
            var buttonPartLeft = Builder.node('li');
            buttonPartLeft.className = 'ButtonPartLeft';
            
            // Create center button part
            var buttonPartCenter = Builder.node('li');
            buttonPartCenter.appendChild(document.createTextNode(this._text));
            buttonPartCenter.className = 'ButtonPartCenter';
            
            // Create right button part
            var buttonPartRight = Builder.node('li');
            buttonPartRight.className = 'ButtonPartRight';
            
            // Append button parts to button container
            button.appendChild(buttonPartLeft);
            button.appendChild(buttonPartCenter);
            button.appendChild(buttonPartRight);
            
            // Register click event handler if this.OnClick is not null
            if(this.OnClick != null)
            {
                Event.observe(button, 'click', this.OnClick);
            }
            
            return button;
        }
        catch(e)
        {
            Logs.WriteException('EXCEPTION_GENERAL', 'GetHtml', arguments, 'WEBBUTTON', null, e, false)
        }
    }
}