/// class ProspectDirector.Modules.Processes.ProcessNodes.FeatureDecisionDirectives
/// using ProspectDirector.Types.Core.Feature

ProspectDirector.Modules.Processes.ProcessNodes.FeatureDecisionDirectives = ProspectDirector.Types.Core.Feature.extend({

    init: function (options) {

        this._super(options);

        this.init_stageOnExecute();
        this.init_statusOnExecuteList();

    },

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

    get_stageOnExecute: function () {
        return this.get_container().find("[data-id=stageOnExecute]");
    },

    get_stageOnExecuteName: function () {
        return this.get_container().find("[data-id=stageOnExecuteName]");
    },

    get_statusOnExecute: function () {
        return this.get_container().find("[data-id=statusOnExecute]");
    },

    get_statusOnExecuteList: function () {
        return this.get_container().find("[data-id=statusOnExecuteList]");
    },

    get_statusOnExecuteListTemplate: function () {
        return this.get_container().find("[data-id=statusOnExecuteList-template]");
    },

    //---------------------------
    //--- INITIALIZERS
    //---------------------------

    init_stageOnExecute: function () {

        this.get_stageOnExecuteName().popUpBox({
            click: $.proxy(function (e) {

                ProspectDirector.Modules.Processes.ProcessNodes.StageOnExecuteDialog.Dialog.show({
                    params: {
                        processId: this.options.data.processId
                    },
                    callbacks: {
                        ok: $.proxy(function (sender, e) {
                            this.get_stageOnExecute().val(e.id);
                            this.get_stageOnExecuteName().val(e.name);
                        }, this)
                    }
                });

            }, this)
        });

    },

    init_statusOnExecuteList: function () {

        var value = this.get_statusOnExecute().val(),
            list = null,
            data = null,
            item = null;

        list = this.get_statusOnExecuteList().kendoListView({
            dataSource: {
                data: this.options.data.statusList,
                schema: {
                    model: {
                        id: "value"
                    }
                }
            },
            template: kendo.template(this.get_statusOnExecuteListTemplate().html()),
            selectable: true,
            change: $.proxy(this.statusOnExecuteList_onChange, this)
        }).data("kendoListView");

        if (value === "") {
            list.select(list.element.children().first());
        }
        else {
            data = list.dataSource.get(value);
            if (data !== undefined && data !== null) {
                item = this.get_statusOnExecuteList().find("[data-uid=" + data.uid + "]");
                list.select(item);
            }
        }

    },

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

    statusOnExecuteList_onChange: function (e) {

        var list = this.get_statusOnExecuteList().data("kendoListView"),
            uid = list.select().data().uid,
            value = list.dataSource.getByUid(uid).value;

        this.get_statusOnExecute().val(value);

    }

    //---------------------------
    //--- METHODS
    //---------------------------

});