/// class PD.Manage.Modules.ObjectModel.ProcessNodeFeaturesPane
// using PD.Web.UI.Controls.Control

PD.Manage.Modules.ObjectModel.ProcessNodeFeaturesPane =
PD.Web.UI.Controls.Control.extend({

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

    get_featureEditor: function () {
        return this.get_node().find("[data-role=featuredobject]").data("featuredObjectEditor");
    },

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

    onInit: function () {
        this._initToolbar();
    },

    load: function (id, processId, role) {
        
        switch (role) {
            case "Process":
                this._loadProcessFeatures(processId);
                break;
            default:
                this._loadProcessNodeFeatures(id);
                break;
        }

    },

    //===================================
    // PROTECTED METHODS
    //===================================

    template: function () {
        return [
            "<div>",
                "<div class='-pd-title-minimal'>Settings</div>",
                "<div data-id='toolbar' style='position:absolute;height:30px;top:40px;left:0;right:0;'></div>",
                "<div data-id='features' style='position:absolute;top:80px;left:0;bottom:0;right:0;border:1px solid #DDDDDD;overflow:auto;'></div>",
            "</div>"
        ];
    },

    //===================================
    // PRIVATE METHODS
    //===================================

    _initToolbar: function () {

        var that = this,
            tree = this._tree;

        this._toolbar = new PD.Web.UI.Controls.Toolbar({
            insertAt: "[data-id=toolbar]",
            segments: [
               new PD.Manage.Modules.ObjectModel.ProcessNodeFeaturesToolbar()
            ]
        });

        this.get_children().add(this._toolbar);

    },

    _loadProcessFeatures: function (id) {

        PD.ajax({
            type: "GET",
            dataType: "html",
            url: PD.Path.resolve("~/Process/Properties/" + id + "?isDialog=false"),
            success: $.proxy(this._loadFeatures, this)
        });

    },

    _loadProcessNodeFeatures: function (id) {
    
        PD.ajax({
            type: "GET",
            dataType: "html",
            url: PD.Path.resolve("~/ProcessNode/Properties/" + id + "?isDialog=false"),
            success: $.proxy(this._loadFeatures, this)
        });

    },

    _loadFeatures: function (e) {

        var $featuresNode = this.get_node().children("[data-id='features']"),
            $observedForm = null;

        $featuresNode.empty();
        $featuresNode.html(e);

        // until such time as it can be replaced, disbale the old change tracker
        $observedForm = $featuresNode.find(".observedForm");
        if ($observedForm.length > 0) {
            $observedForm.observedForm("destroy");
        }

        PD.context.get_default().get_commands().setState({
            "pd/process-model": {
                editor: this.get_featureEditor()
            }
        });

    }

});