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

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

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

    _input_onChange: function (e) {
        var val = this.get_element().val();
        this.setPrimaryValue(val);
    },

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

    activate: function () {

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

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

        this.get_element().on("change", $.proxy(this._input_onChange, this));

    },

    validate: function (value) {

        var convertedValue = parseInt(value),
            isValid = !isNaN(convertedValue),
            message = "\"" + value + "\" is not a valid value.";

        this.setValid(isValid, message);

        if (isValid) {
            this.setPrimaryValue(convertedValue);
        }
        else {
            this.get_input().select();
            this.get_input().focus();
            alert(message);
        }

    }

});