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

/**
[NEEDS DOCUMENTATION]
@class StringAndTagEditor
@namespace Web.UI.FeatureSets.Editors
@extends Web.UI.FeatureSets.MicroEditorBase
@constructor
**/
ProspectDirector.Web.UI.FeatureSets.Editors.StringAndTagEditor =
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);
        }

    },

    _input_onKeyUp: function (e) {
        this.checkForTags();
    },

    //==============================
    // 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().on("keyup", _.bind(this._input_onKeyUp, this));

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

        this.get_input().val(value ? value : "");

        this.checkForTags();

    },

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

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

    checkForTags: function () {

        var that = this;
        var value = this.get_input().val();

        PD.Data.DataTag.containsTags(value, function (e) {
            if (e == true) {
                that.get_input().addClass("-pd-has-tags");
            }
            else {
                that.get_input().removeClass("-pd-has-tags");
            }
        });

    }

});