﻿
Atlantis_Web_UI_Control_Manager = new Class({

    _managers: null,
    _controls: null,
    
    initialize: function()
    {
        this._managers = new Hash();
        this._controls = new Hash();

        window.addEvent('partialload', this.init.bindWithEvent(this, true));
    },
    
    register: function(configArrayName, managerClassName)
    {
        this._managers.set(configArrayName, managerClassName);
    },
    
    init: function(partial)
    {
        this._managers.each(function(managerClassName, configArrayName) {
            
            if ($globalDefined(configArrayName)) {            
                var toEval = configArrayName + '.each(function(hash) { this._onControl(managerClassName, hash, partial); }.bind(this));';
                eval(toEval);
            }
            
        }.bind(this));
    },
    
    _onControl: function(managerClassName, config, partial)
    {
        var control = this._controls.get(config.id);
        
        if (!control) {
            // no manager class for this control yet - lets create one
            eval('control = new ' + managerClassName + '();');            
            this._controls.set(config.id, control);
        }
        
        control.init(config, partial);        
    },
    
    getControl: function(id)
    {
        return this._controls.get(id);
    }
    
});
Atlantis_Web_UI_Control_Manager_Instance = new Atlantis_Web_UI_Control_Manager();


Atlantis_Web_UI_Control_Base = new Class({

    _id: null,
    _uniqueId: null,

    initialize: function() 
    {
    },
    
    getId: function() 
    { 
        return this._id;
    },
    
    init: function(config, partial)
    {
        this._id = config.id;    
        this._uniqueId = config.uniqueId;
        this._doInit(config.config, partial);
    },
    
    _doPostBack: function(string)
    {
        __doPostBack(this._uniqueId, string);
    },

    _doInit: function(config, partial)
    {
        // override in subclass
    }

});

window.addEvent('atldomready', function() {
    Atlantis_Web_UI_Control_Manager_Instance.init(false);
});
