function UpdateUserProfileViewModel(){var a=this;a.downloadProfileLock=!1;a.updateProfileLock=!1;a.saveOption=ko.observable(!1);a.userName=ko.observable("").extend({validateStringLength:{min:ApplicationSettings.minUserNameLength,max:ApplicationSettings.maxUserNameLength,validateOnInitiate:!1}});a.newPassword1=ko.observable("").extend({validateStringLength:{min:ApplicationSettings.minPasswordLength,max:ApplicationSettings.maxPasswordLength,validateOnInitiate:!1}});a.newPassword2=ko.observable("");
a.oldPassword=ko.observable("").extend({validateStringLength:{min:ApplicationSettings.minPasswordLength,max:ApplicationSettings.maxPasswordLength,validateOnInitiate:!0}});a.email=ko.observable("").extend({validateEmail:{validateOnInitiate:!1}});a.name=ko.observable("").extend({validateStringLength:{min:ApplicationSettings.minNameLength,max:ApplicationSettings.maxNameLength,validateOnInitiate:!1}});a.lastName=ko.observable("").extend({validateStringLength:{min:ApplicationSettings.minNameLength,max:ApplicationSettings.maxNameLength,
validateOnInitiate:!1}});a.address=ko.observable("").extend({validateStringLength:{min:ApplicationSettings.minDefaultLength,max:ApplicationSettings.maxDefaultLength,validateOnInitiate:!1}});a.city=ko.observable("").extend({validateStringLength:{min:ApplicationSettings.minDefaultLength,max:ApplicationSettings.maxDefaultLength,validateOnInitiate:!1}});a.zipCode=ko.observable("").extend({validateStringLength:{min:ApplicationSettings.minDefaultLength,max:ApplicationSettings.maxDefaultLength,validateOnInitiate:!1}});
a.country=ko.observable("").extend({validateStringLength:{min:ApplicationSettings.minDefaultLength,max:ApplicationSettings.maxDefaultLength,validateOnInitiate:!1}});a.bankName=ko.observable("").extend({validateStringLength:{min:ApplicationSettings.minDefaultLength,max:ApplicationSettings.maxDefaultLength,validateOnInitiate:!1}});a.accountNumber=ko.observable("").extend({validateStringLength:{min:ApplicationSettings.minDefaultLength,max:ApplicationSettings.maxDefaultLength,validateOnInitiate:!1}});
a.bankNumber=ko.observable("").extend({validateStringLength:{min:ApplicationSettings.minDefaultLength,max:ApplicationSettings.maxDefaultLength,validateOnInitiate:!1}});a.theSamePassword=ko.computed(function(){return a.newPassword1()==a.newPassword2()});a.isPasswordNotValid=ko.computed(function(){if(!a.theSamePassword()||!a.newPassword1.isValid())if(0!=a.newPassword1()||0!=a.newPassword2())return!0;return!1});a.updateFormIsValid=ko.computed(function(){return a.userName.isValid()&&!a.isPasswordNotValid()&&
a.email.isValid()&&a.name.isValid()&&a.address.isValid()&&a.city.isValid()&&a.zipCode.isValid()&&a.country.isValid()&&a.bankName.isValid()&&a.accountNumber.isValid()&&a.bankNumber.isValid()&&""!=a.email()&&""!=a.name()&&""!=a.lastName()?a.changePassword()&&!(""!=a.newPassword1()&&""!=a.newPassword2())?!1:!0:!1});a.changePassword=ko.computed(function(){return 0<a.newPassword1().Length?!0:!1});a.saveOption.subscribe(function(){a.oldPassword("");!0==a.saveOption()?$("div#UpdateUserProfilePage [data-role=collapsible]").hide():
$("div#UpdateUserProfilePage [data-role=collapsible]").show()});a.updateProfile=function(b){MainViewModel.checkInternetConnection()&&!a.updateProfileLock&&(a.updateProfileLock=!0,Overlay.create(!0,Culture.translations().stringMsgUpdatingUserProfile),ServiceDataProvider.updateUserProfile(b).done(function(){}).always(function(c){Log(c);if(this.state()==ASyncState.Resolved)c=Culture.translations().stringMsgUpdateProfileSucceeded,0<b.Password.length&&(MainViewModel.password(b.Password),Settings.logInMode()==
LogInModes.Automatic&&Settings.password(b.Password)),a.saveOption(!1),a.resetForm();else switch(c){case 3006:c=Culture.translations().stringErrorMsgUpdateProfileFailedPasswordInvaild;a.oldPassword.isValid(!1);break;case 3015:case 3016:MainViewModel.handleLostSession("UpdateUserProfile.html",a.updateProfileCommand);return;default:c=Culture.translations().stringErrorMsgUpdateProfileFailed}a.updateProfileLock=!1;Overlay.create(!1,c);Overlay.hideLoader();Overlay.showTextOnlyLoader(c);setTimeout(function(){Overlay.destroy()},
2E3)}).fail(function(){a.updateProfileLock=!1;setTimeout(function(){Overlay.destroy()},2E3)}))};a.updateProfileCommand=function(){a.updateProfile({UserName:a.userName(),Password:a.newPassword1(),OldPassword:a.oldPassword(),Email:a.email(),Name:a.name(),LastName:a.lastName(),Address:a.address(),City:a.city(),ZipCode:a.zipCode(),Country:a.country(),BankName:a.bankName(),AccountNumber:a.accountNumber(),BankNumber:a.bankNumber()})};a.setData=function(b){a.userName(b.UserName);a.email(b.Email);a.name(b.Name);
a.lastName(b.LastName);a.address(b.Address);a.city(b.City);a.zipCode(b.ZipCode);a.country(b.Country);a.bankName(b.BankName);a.accountNumber(b.AccountNumber);a.bankNumber(b.BankNumber)};a.resetForm=function(){a.oldPassword("");a.oldPassword.isValid(!1);a.newPassword1("");a.newPassword2("");a.newPassword1.isValid(!0)};a.downloadProfileCommand=function(){a.downloadProfileLock||(a.downloadProfileLock=!0,Overlay.create(!0,Culture.translations().stringMsgDownloadingUserProfile),ServiceDataProvider.downloadUserProfile().done(function(b){Log(b);
a.setData(b);setTimeout(function(){Overlay.destroy()},2E3)}).always(function(b){if(this.state()==ASyncState.Resolved)b=Culture.translations().stringMsgDownloadUserProfileSucceeded;else switch(b){case 3015:case 3016:MainViewModel.handleLostSession("UpdateUserProfile.html",a.downloadProfileCommand);return;default:b=Culture.translations().stringTextDownloadingUserProfileFailed}Overlay.hideLoader();Overlay.showTextOnlyLoader(b);a.downloadProfileLock=!1}).fail(function(){a.downloadProfileLock=!1;setTimeout(function(){Overlay.destroy()},
2E3)}))}};
