ProspectDirector.Web.UI.Packagers.ContextValueProvider =
ProspectDirector.Web.UI.Packagers.PackagerValueProvider.extend({

    //================================
    // FIELDS
    //================================

    _regex: /context:(.*)/,

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

    getValue: function (context, command) {

        var result = null,
            id = this._processValue(command.get_value());

        if (id) {
            result = context.form.options.data[id];
        }

        this._checkIsRequired(command, id, result);

        return result;

    },

    canProcessValue: function (value) {
        return value != null
            && ProspectDirector.Web.Type.isString(value)
            && value.match(this._regex) !== null;
    },

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

    _processValue: function (value) {
        var result = value.match(this._regex);
        if (result) {
            result = result[1];
        }
        return result;
    },

    _checkIsRequired: function (command, label, providedValue) {

        var required = command.get_required();

        if (required && providedValue == null) {
            command.get_errors().add(field.options.data.label + " must have a value.");
        }

    }

});