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

/**
@class FeatureCreateFormDesign
@namespace ProspectDirector.Modules.EntityTypes
**/
ProspectDirector.Modules.EntityTypes.FeatureCreateFormDesign = 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) {

        PDJS.Canvas.Design.Dialog.open({
            data: {
                documentId: this.options.data.documentId
            },
            callbacks: {
                ok: function (sender, e) {
                    if (e.hasChanges) {
                        that.get_hasChanges().val("1");
                        that.get_hasChanges().change();
                    }
                }
            }
        });
        
    },

    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);
    }

});