"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var user_service_1 = require("./user.service");
//import { ChangeUserPasswordService } from '../ChangePassword/changeuserpassword.service';
var router_1 = require("@angular/router");
var forms_1 = require("@angular/forms");
var datamodel_1 = require("../UserEntity/datamodel");
var confirm_service_1 = require("../../Shared/Confirm/confirm.service");
require("rxjs/Rx");
require("rxjs/add/operator/map");
require("rxjs/add/operator/filter");
var ChangeUserPassword = /** @class */ (function () {
function ChangeUserPassword(changeUserPasswordService, router, fb, _confirmService) {
this.changeUserPasswordService = changeUserPasswordService;
this.router = router;
this.fb = fb;
this._confirmService = _confirmService;
}
ChangeUserPassword.prototype.ngOnInit = function () {
this.user = new datamodel_1.User();
this.alerts = '';
this.changeUserPasswordFrm = this.fb.group({
userId: [''],
loginId: ['', forms_1.Validators.required],
oldPassword: ['', forms_1.Validators.required],
newPassword: ['', [forms_1.Validators.required, forms_1.Validators.minLength(8)]],
confirmPassword: ['', forms_1.Validators.required]
});
this.GetUserById();
};
ChangeUserPassword.prototype.GetUserById = function () {
var _this = this;
this.changeUserPasswordService.GetUserById()
.subscribe(function (x) { _this.BindFormFields(x); }, function (error) { return _this.error = error; });
};
ChangeUserPassword.prototype.onFormSubmit = function () {
var _this = this;
this.alerts = '';
if (this.user.Password != this.changeUserPasswordFrm.value.oldPassword) {
this.alerts = 'Old password is invalid';
}
if (this.user.Password == this.changeUserPasswordFrm.value.newPassword) {
this.alerts += 'New password and old password must be different';
}
if (this.changeUserPasswordFrm.value.newPassword != this.changeUserPasswordFrm.value.confirmPassword) {
this.alerts += 'New password and confirm password must be same';
}
if (this.alerts == '') {
var obj = this.changeUserPasswordFrm.value;
return this.changeUserPasswordService.ChangeUserPassword(obj)
.subscribe(function (n) { return (_this.AfterInsertData(n)); }, function (error) { return _this.error = error; });
}
};
ChangeUserPassword.prototype.AfterInsertData = function (data) {
if (data.Status == "false") {
this.alerts = "Password change unsuccessfull";
}
else {
this._confirmService.activate("Password changed successfully.", "alertMsg");
//this.alerts = "Password changed successfully";
}
};
ChangeUserPassword.prototype.BindFormFields = function (data) {
this.user = data[0];
this.changeUserPasswordFrm.controls['userId'].setValue(this.user.Id);
this.changeUserPasswordFrm.controls['loginId'].setValue(this.user.LoginId);
};
ChangeUserPassword.prototype.ResetFormFields = function () {
this.changeUserPasswordFrm.reset();
this.changeUserPasswordFrm.controls['loginId'].setValue(this.user.LoginId);
this.changeUserPasswordFrm.controls['oldPassword'].setValue('');
this.changeUserPasswordFrm.controls['newPassword'].setValue('');
this.changeUserPasswordFrm.controls['confirmPassword'].setValue('');
this.alerts = '';
};
ChangeUserPassword = __decorate([
core_1.Component({
templateUrl: './changeuserpassword.component.html'
}),
__metadata("design:paramtypes", [user_service_1.UserService, router_1.Router, forms_1.FormBuilder, confirm_service_1.ConfirmService])
], ChangeUserPassword);
return ChangeUserPassword;
}());
exports.ChangeUserPassword = ChangeUserPassword;
//# sourceMappingURL=changeuserpassword.component.js.map