ng2-encrm-components
Version:
366 lines • 13.1 kB
JavaScript
"use strict";
var core_1 = require('@angular/core');
var forms_1 = require('@angular/forms');
var field_value_1 = require('./../annotations/field-value');
var Observable_1 = require('rxjs/Observable');
var noop = function () {
};
exports.EN_INPUT_CONTROL_VALUE_ACCESSOR = {
provide: forms_1.NG_VALUE_ACCESSOR,
useExisting: core_1.forwardRef(function () { return EnInputComponent; }),
multi: true
};
// Invalid input type. Using one of these will throw an MdInputUnsupportedTypeError.
var EN_INPUT_INVALID_INPUT_TYPE = [
'file',
'radio',
'checkbox',
];
var EnInputComponent = (function () {
function EnInputComponent() {
this._focused = false;
this._value = '';
/** Callback registered via registerOnTouched (ControlValueAccessor) */
this._onTouchedCallback = noop;
/** Callback registered via registerOnChange (ControlValueAccessor) */
this._onChangeCallback = noop;
/**
* Bindings.
*/
this.align = 'start';
this.autoFocus = false;
this.disabled = false;
this.id = "";
this.list = null;
this.max = null;
this.maxLength = null;
this.min = null;
this.minLength = null;
this.placeholder = null;
this.readOnly = false;
this.required = false;
this.spellCheck = false;
this.step = null;
this.tabIndex = null;
this.type = 'text';
this.name = null;
this.addonRight = false;
this._blurEmitter = new core_1.EventEmitter();
this._focusEmitter = new core_1.EventEmitter();
this.btnClick = new core_1.EventEmitter();
}
Object.defineProperty(EnInputComponent.prototype, "focused", {
// /**
// * Content directives.
// */
// @ContentChild(MdPlaceholder) _placeholderChild: MdPlaceholder;
// @ContentChildren(MdHint) _hintChildren: QueryList<MdHint>;
/** Readonly properties. */
get: function () {
return this._focused;
},
enumerable: true,
configurable: true
});
Object.defineProperty(EnInputComponent.prototype, "empty", {
get: function () {
return this._value == null || this._value === '';
},
enumerable: true,
configurable: true
});
Object.defineProperty(EnInputComponent.prototype, "characterCount", {
get: function () {
return this.empty ? 0 : ('' + this._value).length;
},
enumerable: true,
configurable: true
});
Object.defineProperty(EnInputComponent.prototype, "inputId", {
get: function () {
return "" + this.id;
},
enumerable: true,
configurable: true
});
Object.defineProperty(EnInputComponent.prototype, "floatingPlaceholder", {
get: function () {
return this._focused || !this.empty;
},
enumerable: true,
configurable: true
});
Object.defineProperty(EnInputComponent.prototype, "onBlur", {
get: function () {
return this._blurEmitter.asObservable();
},
enumerable: true,
configurable: true
});
Object.defineProperty(EnInputComponent.prototype, "onFocus", {
get: function () {
return this._focusEmitter.asObservable();
},
enumerable: true,
configurable: true
});
Object.defineProperty(EnInputComponent.prototype, "value", {
get: function () {
return this._value;
},
set: function (v) {
v = this._convertValueForInputType(v);
if (v !== this._value) {
this._value = v;
this._onChangeCallback(v);
}
},
enumerable: true,
configurable: true
});
;
EnInputComponent.prototype._btnClickHandler = function () {
this.btnClick.emit({
value: this.value
});
};
Object.defineProperty(EnInputComponent.prototype, "_align", {
// This is to remove the `align` property of the `md-input` itself. Otherwise HTML5
// might place it as RTL when we don't want to. We still want to use `align` as an
// Input though, so we use HostBinding.
get: function () {
return null;
},
enumerable: true,
configurable: true
});
/** Set focus on input */
EnInputComponent.prototype.focus = function () {
this._inputElement.nativeElement.focus();
};
EnInputComponent.prototype._handleFocus = function (event) {
this._focused = true;
this._focusEmitter.emit(event);
};
EnInputComponent.prototype._handleBlur = function (event) {
this._focused = false;
this._onTouchedCallback();
this._blurEmitter.emit(event);
};
EnInputComponent.prototype._handleChange = function (event) {
this.value = event.target.value;
this._onTouchedCallback();
};
EnInputComponent.prototype._labelClickHandler = function () {
if (!this.floatingPlaceholder) {
this._inputElement.nativeElement.focus();
}
};
// _hasPlaceholder(): boolean {
// return !!this.placeholder || this._placeholderChild != null;
// }
/**
* Implemented as part of ControlValueAccessor.
* TODO: internal
*/
EnInputComponent.prototype.writeValue = function (value) {
this._value = value;
};
/**
* Implemented as part of ControlValueAccessor.
* TODO: internal
*/
EnInputComponent.prototype.registerOnChange = function (fn) {
this._onChangeCallback = fn;
};
/**
* Implemented as part of ControlValueAccessor.
* TODO: internal
*/
EnInputComponent.prototype.registerOnTouched = function (fn) {
this._onTouchedCallback = fn;
};
/** TODO: internal */
EnInputComponent.prototype.ngAfterContentInit = function () {
this._validateConstraints();
// Trigger validation when the hint children change.
// this._hintChildren.changes.subscribe(() => {
// this._validateConstraints();
// });
};
/** TODO: internal */
EnInputComponent.prototype.ngOnChanges = function (changes) {
this._validateConstraints();
};
/**
* Convert the value passed in to a value that is expected from the type of the md-input.
* This is normally performed by the *_VALUE_ACCESSOR in forms, but since the type is bound
* on our internal input it won't work locally.
* @private
*/
EnInputComponent.prototype._convertValueForInputType = function (v) {
switch (this.type) {
case 'number':
return parseFloat(v);
default:
return v;
}
};
/**
* Ensure that all constraints defined by the API are validated, or throw errors otherwise.
* Constraints for now:
* - type attribute is not one of the forbidden types (see constant at the top).
* @private
*/
EnInputComponent.prototype._validateConstraints = function () {
if (EN_INPUT_INVALID_INPUT_TYPE.indexOf(this.type) != -1) {
throw new TypeError(this.type + " is not a valid en-input type.");
}
};
__decorate([
core_1.Input('aria-label'),
__metadata('design:type', String)
], EnInputComponent.prototype, "ariaLabel", void 0);
__decorate([
core_1.Input('aria-labelledby'),
__metadata('design:type', String)
], EnInputComponent.prototype, "ariaLabelledBy", void 0);
__decorate([
core_1.Input('aria-disabled'),
__metadata('design:type', Boolean)
], EnInputComponent.prototype, "ariaDisabled", void 0);
__decorate([
core_1.Input('aria-required'),
__metadata('design:type', Boolean)
], EnInputComponent.prototype, "ariaRequired", void 0);
__decorate([
core_1.Input('aria-invalid'),
__metadata('design:type', Boolean)
], EnInputComponent.prototype, "ariaInvalid", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Object)
], EnInputComponent.prototype, "align", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', String)
], EnInputComponent.prototype, "autoComplete", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', String)
], EnInputComponent.prototype, "autoCorrect", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', String)
], EnInputComponent.prototype, "autoCapitalize", void 0);
__decorate([
core_1.Input(),
field_value_1.BooleanFieldValue(),
__metadata('design:type', Boolean)
], EnInputComponent.prototype, "autoFocus", void 0);
__decorate([
core_1.Input(),
field_value_1.BooleanFieldValue(),
__metadata('design:type', Boolean)
], EnInputComponent.prototype, "disabled", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', String)
], EnInputComponent.prototype, "id", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', String)
], EnInputComponent.prototype, "list", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Object)
], EnInputComponent.prototype, "max", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Number)
], EnInputComponent.prototype, "maxLength", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Object)
], EnInputComponent.prototype, "min", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Number)
], EnInputComponent.prototype, "minLength", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', String)
], EnInputComponent.prototype, "placeholder", void 0);
__decorate([
core_1.Input(),
field_value_1.BooleanFieldValue(),
__metadata('design:type', Boolean)
], EnInputComponent.prototype, "readOnly", void 0);
__decorate([
core_1.Input(),
field_value_1.BooleanFieldValue(),
__metadata('design:type', Boolean)
], EnInputComponent.prototype, "required", void 0);
__decorate([
core_1.Input(),
field_value_1.BooleanFieldValue(),
__metadata('design:type', Boolean)
], EnInputComponent.prototype, "spellCheck", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Number)
], EnInputComponent.prototype, "step", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Number)
], EnInputComponent.prototype, "tabIndex", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', String)
], EnInputComponent.prototype, "type", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', String)
], EnInputComponent.prototype, "name", void 0);
__decorate([
core_1.Input(),
field_value_1.BooleanFieldValue(),
__metadata('design:type', Boolean)
], EnInputComponent.prototype, "addonRight", void 0);
__decorate([
core_1.Output('blur'),
__metadata('design:type', Observable_1.Observable)
], EnInputComponent.prototype, "onBlur", null);
__decorate([
core_1.Output('focus'),
__metadata('design:type', Observable_1.Observable)
], EnInputComponent.prototype, "onFocus", null);
__decorate([
core_1.Input(),
__metadata('design:type', Object)
], EnInputComponent.prototype, "value", null);
__decorate([
core_1.Output(),
__metadata('design:type', core_1.EventEmitter)
], EnInputComponent.prototype, "btnClick", void 0);
__decorate([
core_1.HostBinding('attr.align'),
__metadata('design:type', Object)
], EnInputComponent.prototype, "_align", null);
__decorate([
core_1.ViewChild('input'),
__metadata('design:type', core_1.ElementRef)
], EnInputComponent.prototype, "_inputElement", void 0);
EnInputComponent = __decorate([
core_1.Component({
selector: 'en-input',
template: require('./en-input.component.html'),
styles: [require('./en-input.component.scss')],
providers: [exports.EN_INPUT_CONTROL_VALUE_ACCESSOR]
}),
__metadata('design:paramtypes', [])
], EnInputComponent);
return EnInputComponent;
}());
exports.EnInputComponent = EnInputComponent;
//# sourceMappingURL=en-input.component.js.map