/// class ProspectDirector.Web.UI.Dialog

/**
@class Dialog
@constructor
@namespace Web.UI
@extends Web.UI.Window
**/
ProspectDirector.Web.UI.Dialog = Class.extend({

    //================================
    // FIELDS
    //================================

    _window: null,
    _eventBus: null,
    _id: null,

    //================================
    // CONSTRUCTOR
    //================================

    init: function (options) {
        this._id = uuid.v4();
        this.options = options;
        this._eventBus = new ProspectDirector.Web.UI.EventBus();
        this._eventBus.name = "DIALOG_EVENTBUS";
        this._createContext(options.config);
        this.show();
    },

    //================================
    // PROPERTIES
    //================================

    /**
    @public
    @property get_container
    @type {jQuery}
    **/
    get_container: function () {
        return this.get_window().DOM().get_container();
    },

    /**
    @public
    @property get_window
    @type {Web.UI.Window}
    **/
    get_window: function () {
        return this._window;
    },

    /**
    @public
    @property get_eventBus
    @type {Web.UI.EventBus}
    **/
    get_eventBus: function () {
        return this._eventBus;
    },

    //================================
    // EVENT HANDLERS
    //================================

    /**
    @protected
    @method _resize
    @param {jQuery.Event}
    **/
    _resize: function (e) {
        //do nothing on purpose
    },

    //================================
    // PUBLIC METHODS
    //================================

    /**
    @public
    @method show
    @param options {Object}
    **/
    show: function () {

        var that = this,
            noContentUrl = this.options.config.content === undefined || this.options.config.content === null;

        this.options = $.extend(true, {}, {
            showLoadingMessage: true,
            events: {
                refresh: function (e) {
                    that._init_dialog();
                },
                resize: $.proxy(this._resize, this)
            },
            close: function () {
                that.close();
            }
        }, this.options);

        this._window = new ProspectDirector.Web.UI.Window(this.options);

        if (noContentUrl) {
            this._init_dialog();
        }

    },

    /**
    @public
    @method hide
    **/
    hide: function (options) {
        this.close(options);
    },

    close: function (options) {
        this._destroyContext();
        this.get_window().destroy(options);
    },

    setOptions: function (options) {
        this._window.setOptions(options);
    },

    //================================
    // OVERRIDDABLE METHODS
    //================================

    /**
    @protected
    @method _init_dialog
    **/
    _init_dialog: function () {
        //do nothing on purpose
    },

    //================================
    // PRIVATE METHODS
    //================================
    
    _createContext: function (config) {
        
        PD.context.createContext({
            id: this._id,
            name: config != null ? config.title : null
        });

    },

    _destroyContext: function () {
        
        PD.context.destroyContext({
            id: this._id
        });

    }

});