/// class ProspectDirector.Web.UI.FeatureSets.Editors.ResourceSelectorEditor
/// using ProspectDirector.Web.UI.FeatureSets.Editors.CompositeEditor

/**
[NEEDS DOCUMENTATION]
@class ResourceSelectorEditor
@namespace Web.UI.FeatureSets.Editors
@extends Web.UI.FeatureSets.Editors.CompositeEditor
@constructor
**/

ProspectDirector.Web.UI.FeatureSets.Editors.ResourceSelectorEditor =
ProspectDirector.Web.UI.FeatureSets.Editors.CompositeEditor.extend({

    //==============================
    // PROPERTIES
    //==============================
    
    get_input: function () {
        return this.get_element().find("INPUT[type=text]");
    },
    
    //==============================
    // EVENT HANDLERS
    //==============================

    _button_onClick: function () {

        var that = this;

        PD.Manage.Modules.Resources.ResourceSelectionDialog.open({
            extensions: this.get_definition().get_data()["extensions"],
            selectMode: {
                type: "files",
                multiple: false
            },
            callbacks: {
                ok: function (sender, e) {
                    var file = _.first(e.files);
                    that.setPrimaryValue(e.path + "/" + file.name);
                    that.get_input().val(e.path + "/" + file.name);
                }
            }
        });

    },

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

    activate: function () {
        this._super();
        this.get_input().val(this.getPrimaryValue());
    },
    
    render: function () {

        return "<div id=\"" + this.getId() + "\" class=\"-pd-micro-editor-composite\">" +
            "<input type=\"text\" readonly style=\"color:#AAAAAA;padding-left:5px;\">" +
            "<input type=\"button\" value=\"...\">" +
            "<img src='" + PD.Path.resolve("~/application/icons/misc/cancel.png") + "' style='position:absolute;right:25px;top:3px;display:none;'/>"
            "</div>";

    }

});