/// class ProspectDirector.Web.UI.FeatureSets.Editors.StringEditor
/// using ProspectDirector.Web.UI.FeatureSets.MicroEditorBase

/**
[NEEDS DOCUMENTATION]
@class StringEditor
@namespace Web.UI.FeatureSets.Editors
@extends Web.UI.FeatureSets.MicroEditorBase
@constructor
**/
ProspectDirector.Web.UI.FeatureSets.Editors.StringEditor =
ProspectDirector.Web.UI.FeatureSets.MicroEditorBase.extend({

    //==============================
    // CONSTRUCTOR
    //==============================

    init: function (options) {
        this._super(options);
    },

    //==============================
    // EVENT HANDLERS
    //==============================

    get_input: function () {
        return this.get_element();
    },

    //==============================
    // EVENT HANDLERS
    //==============================

    _input_onBlur: function (e) {

        var value = $(e.target).val();

        if (this.validate(value)) {
            this.setPrimaryValue(value);
        }

    },

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

    activate: function () {

        var value = this.getPrimaryValue();
        var definition = this.get_definition().get_data();

        this.get_input().on("blur", _.bind(this._input_onBlur, this));

        this.get_input().prop("readOnly", definition.readOnly);
        this.get_input().prop("disabled", definition.disabled);

        this.get_input().val(value !== null ? value : "");

    },

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

    render: function () {
        return "<input type\"text\" class=\"-pd-micro-editor-textbox\" id=\"" + this.getId() + "\" />";
    }

});