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

/**
@class PasswordEditor
@namespace Web.UI.FeatureSets.Editors
@extends Web.UI.FeatureSets.MicroEditorBase
@constructor
**/
ProspectDirector.Web.UI.FeatureSets.Editors.PasswordEditor =
ProspectDirector.Web.UI.FeatureSets.MicroEditorBase.extend({

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

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

    //==============================
    // PROPERTIES
    //==============================

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

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

    activate: function () {

        var that = this,
            definition = this.get_definition().get_data();

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

        this.get_element().on("blur", $.proxy(function (e) {

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

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

            that._showPasswordMask(value === "");

        }, this));


        this.get_element().parent().css({
            position: "relative"
        });

        this.get_element().on("focus", $.proxy(function (e) {
            that._showPasswordMask(false);
        }, this));


        this.get_mask().on("focus", function (e) {
            that.get_mask().hide();
            that.get_element().focus();
        });

        this._showPasswordMask(true);

    },

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

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

    _showPasswordMask: function (show) {

        if (show) {
            this.get_mask().show();
        }
        else {
            this.get_mask().hide();
        }

    }

});