/// class ProspectDirector.Modules.EntityTypes.FeaturePropertiesFormDesign
/// using ProspectDirector.Types.Core.Feature

/**
@class FeaturePropertiesFormDesign
@namespace ProspectDirector.Modules.EntityTypes
**/
ProspectDirector.Modules.EntityTypes.FeaturePropertiesFormDesign = ProspectDirector.Types.Core.Feature.extend({

    //---------------------------
    //--- CONSTRUCTOR
    //---------------------------

    init: function (options) {

        this._super(options);

        this.get_buttonEdit().on("click", $.proxy(this.buttonEdit_onClick, this));

        this.get_layout().val(JSON.stringify(options.data.layout));

    },

    //---------------------------
    //--- PROPERTIES
    //---------------------------

    get_buttonEdit: function () {
        return this.get_container().find("INPUT[type=button]");
    },

    get_layout: function () {
        return this.get_container().find("[data-role=layout]");
    },

    //---------------------------
    //--- EVENT HANDLERS
    //---------------------------

    buttonEdit_onClick: function (e) {

        ProspectDirector.Modules.EntityTypes.Dialog.FormDeisgn.show({
            config: {
                content: {
                    type: "POST"
                },
                actions: ["Maximize", "Close"],
                resizable: true,
                width: 850,
                height: 500
            },
            params: {
                formId: this.options.data.formId,
                layout: this.get_layout().val(),
                entityTypeId: this.options.data.entityTypeId
            },
            callbacks: {
                ok: $.proxy(this.formDesign_onOk, this)
            }
        });

    },

    formDesign_onOk: function (sender, e) {

        this.updateLayout(e, true);

    },

    updateLayout: function (data, triggerChange) {

        if (data !== null) {
            this.get_layout().val(JSON.stringify(data));
        }
        else {
            this.get_layout().val("");
        }

        if (triggerChange) {
            this.get_layout().change();
        }

    },

    //---------------------------
    //--- OVERRIDDEN METHODS
    //---------------------------

    update: function (data) {
        this.updateLayout(data.layout, false);
    }

});