function RequestUserView(options){var self=this;
self.userServiceFacade=options.userServiceFacade;
self.inet=options.inet;
self.i18n=options.i18n;
self.messageHandler=options.messageHandler;
self.idRecaptcha=null;
self._init();
$("body").loader("hide");
}RequestUserView.prototype._init=function(){var self=this;
self._loadStep("requestUserWelcome",{i18n:self.i18n});
$(document).off("submit","#formRequestUserWelcome").on("submit","#formRequestUserWelcome",function(event){event.preventDefault();
self._submitRequestUserOption();
});
$(document).off("click","#requestUserCreate").on("click","#requestUserCreate",function(event){event.preventDefault();
self._renderRequestUserCreate();
});
$(document).off("submit","#formRequestUserCreate").on("submit","#formRequestUserCreate",function(event){event.preventDefault();
self._submitCreateForm();
});
$(document).off("click","#requestUserCheck").on("click","#requestUserCheck",function(event){event.preventDefault();
self._renderRequestUserCheck();
});
$(document).off("submit","#formRequestUserCheckStatus").on("submit","#formRequestUserCheckStatus",function(event){event.preventDefault();
self._submitRequestForInfo();
});
$(document).off("click","#requestUserHelp").on("click","#requestUserHelp",function(event){event.preventDefault();
self._renderRequestUserHelp();
});
$(document).off("submit","#formRequestUserHelp").on("submit","#formRequestUserHelp",function(event){event.preventDefault();
self._submitRequestForHelp();
});
$(document).off("submit","#recoverUserFormStepFinal").on("submit","#recoverUserFormStepFinal",function(event){event.preventDefault();
self._submitFormFinalStep();
});
$("body").loader("show");
};
RequestUserView.prototype._submitFormFinalStep=function(){var login=$("#recoverUserFormStepFinal").val();
$("#userLogin").val(login);
$("#recoveryView").modal("hide");
$("#real_pass").focus();
};
RequestUserView.prototype._loadStep=function(action,params,module){var self=this;
captcha.hide();
if(!module&&module!=""){module="requestUser";
}self.inet.loadStep(action,params,module);
$(".modal-content.custom-modal").css("height","452px");
};
RequestUserView.prototype._submitRequestUserOption=function(){this._loadStep("requestUserOptions",{i18n:self.i18n});
};
RequestUserView.prototype._renderRequestUserCreate=function(){this._loadStep("requestUserCreate",{i18n:self.i18n});
this._renderCountries();
this._renderBrands();
this._renderApps();
$("#requestUserCreateCountrySelect").selectpicker({width:"295px",height:"35px",dropupAuto:false,size:7});
$("#requestUserCreateBrandSelect").selectpicker({width:"295px",height:"35px",dropupAuto:false,size:7});
$(".modal-content.custom-modal").css("height","610px");
$(".modal-content.custom-modal").css("width","800px");
$(".mCSB_container.mCS_y_hidden.mCS_no_scrollbar_y").css("height","562px");
};
RequestUserView.prototype._renderCountries=function(){var clazz=".countrySelect";
var countrySelect=$(clazz);
self.userServiceFacade.getMarkets(function(data){var html="";
for(i=0;
i"+data[i].country+"";
}countrySelect.html(html);
},function(){},this);
};
RequestUserView.prototype._renderBrands=function(){var clazz=".brandSelect";
var brandSelect=$(clazz);
self.userServiceFacade.getBrands(function(data){var html="";
for(i=0;
i"+data[i].brand+"";
}brandSelect.html(html);
},function(){},this);
};
RequestUserView.prototype._renderApps=function(){var clazz=".appSelect";
var appSelect=$(clazz);
self.userServiceFacade.getApps(function(data){var html="";
for(i=1;
i"+data[i].app+"";
}appSelect.html(html);
},function(){},this);
};
RequestUserView.prototype._renderRequestUserHelp=function(){this._loadStep("requestUserHelp",{i18n:self.i18n});
this._renderCountries();
$("#requestUserHelpCountrySelect").selectpicker({width:"295px",height:"35px",dropupAuto:false,size:7});
$(".modal-content.custom-modal").css("height","420px");
};
RequestUserView.prototype._renderRequestUserCheck=function(){this._loadStep("requestUserStatus",{i18n:self.i18n});
$(".modal-content.custom-modal").css("height","235px");
};
RequestUserView.prototype._submitCreateForm=function(){var self=this;
var company=$.trim($("#requestUserCreateCompany").val());
var firstName=$.trim($("#requestUserCreateName").val());
var lastName=$.trim($("#requestUserCreateLastName").val());
var email=$.trim($("#requestUserCreateEmail").val());
var phone=$.trim($("#requestUserCreatePhone").val());
var countryId=$.trim($("#requestUserCreateCountrySelect").val());
var brandId=$.trim($("#requestUserCreateBrandSelect").val());
var contact=$.trim($("#requestUserCreateContact").val());
var supplierId=$.trim($("#requestUserCreateSupplierId").val());
var supplierCompanyCode=$.trim($("#requestUserCreateSupplierCode").val());
var app=$.trim($("#requestUserCreateAppSelect").val());
var hasEmptyFields=false;
if(company!=""){this._removeValidationWarning("requestUserCreateCompany",hasEmptyFields);
}else{hasEmptyFields=true;
this._addValidationWarning("requestUserCreateCompany",this.i18n.msg("createUserForm.field.company.required"),null);
}if(firstName!=""){this._removeValidationWarning("requestUserCreateName",hasEmptyFields);
}else{hasEmptyFields=true;
this._addValidationWarning("requestUserCreateName",this.i18n.msg("createUserForm.field.name.required"),null);
}if(lastName!=""){this._removeValidationWarning("requestUserCreateLastName",hasEmptyFields);
}else{hasEmptyFields=true;
this._addValidationWarning("requestUserCreateLastName",this.i18n.msg("createUserForm.field.lastname.required"),null);
}if(email!=""){this._removeValidationWarning("requestUserCreateEmail",hasEmptyFields);
}else{hasEmptyFields=true;
this._addValidationWarning("requestUserCreateEmail",this.i18n.msg("createUserForm.field.email.required"),null);
}if(phone!=""){this._removeValidationWarning("requestUserCreatePhone",hasEmptyFields);
}else{hasEmptyFields=true;
this._addValidationWarning("requestUserCreatePhone",this.i18n.msg("createUserForm.field.phone"),null);
}if(countryId!=""&&countryId!="-1"){this._removeValidationWarning("requestUserCreateCountryDiv");
}else{hasEmptyFields=true;
this._addValidationWarning("requestUserCreateCountryDiv","",null);
}if(brandId!=""&&brandId!="-1"){this._removeValidationWarning("requestUserCreateBrandDiv",hasEmptyFields);
}else{hasEmptyFields=true;
this._addValidationWarning("requestUserCreateBrandDiv","",null);
}if(contact!=""){this._removeValidationWarning("requestUserCreateContact",hasEmptyFields);
}else{hasEmptyFields=true;
this._addValidationWarning("requestUserCreateContact",this.i18n.msg("createUserForm.field.email.contact.required"),null);
}if(supplierId!=""||supplierCompanyCode!=""){this._removeValidationWarning("requestUserCreateSupplierId",hasEmptyFields);
this._removeValidationWarning("requestUserCreateSupplierCode",hasEmptyFields);
}else{hasEmptyFields=true;
this._addValidationWarning("requestUserCreateSupplierId",this.i18n.msg("createUserForm.field.supplierId.required"),null);
this._addValidationWarning("requestUserCreateSupplierCode",this.i18n.msg("createUserForm.field.supplierId.required"),null);
}if(app!=""&&app!="-1"){this._removeValidationWarning("requestUserCreateAppSelect",hasEmptyFields);
}else{hasEmptyFields=true;
this._addValidationWarning("requestUserCreateAppSelect",this.i18n.msg("createUserForm.field.app.required"),null);
}if(hasEmptyFields==false){var requestSupplier={requestedCompany:company,firstName:firstName,lastName:lastName,personalMail:email,personalPhone:phone?phone:null,countryId:countryId,brandId:brandId,itxContactMail:contact,supplierOrganizationId:supplierId!==""?supplierId:null,supplierCode:supplierCompanyCode!==""?supplierCompanyCode:null,app:app};
self.userServiceFacade.createSupplier(requestSupplier,self._onSuccessRequestCreate,self._onErrorRequestCreate,self);
self.inet.loadStep("requestUserSendingRequest",{title:i18n.msg("createUserForm.description.checkmail.title"),message:i18n.msg("pasoFinal.createuser.sending"),},"requestUser");
$(".modal-content.custom-modal").css("height","200px");
$("body").loader("hide");
}};
RequestUserView.prototype._onSuccessRequestCreate=function(data){if(data.status=="CREATED"){self.inet.loadStep("requestUserCreateFinalStep",{data:data},"requestUser");
$(".modal-content.custom-modal").css("height","230px");
$("body").loader("hide");
}else{var errorMessage=this.i18n.msg(data.message);
self.inet.loadStep("requestUserErrorFinalStep",{title:i18n.msg("createUserForm.description.createaccount.title"),message:errorMessage!==""&&errorMessage!==undefined?errorMessage:i18n.msg("pasoFinal.createuser.error"),},"requestUser");
$(".modal-content.custom-modal").css("height","200px");
$("body").loader("hide");
}};
RequestUserView.prototype._onErrorRequestCreate=function(data){var errorMessage=this.i18n.msg(data.message);
self.inet.loadStep("requestUserErrorFinalStep",{title:i18n.msg("createUserForm.description.createaccount.title"),message:errorMessage!==""&&errorMessage!==undefined?errorMessage:i18n.msg("pasoFinal.createuser.error"),},"requestUser");
$(".modal-content.custom-modal").css("height","200px");
$("body").loader("hide");
};
RequestUserView.prototype._submitRequestForInfo=function(){var requestId=$.trim($("#requestUserCheckStatusRequestId").val());
var hasEmptyFields=false;
if(requestId!=""){this._removeValidationWarning("requestUserCheckStatusRequestId",hasEmptyFields);
}else{hasEmptyFields=true;
this._addValidationWarning("requestUserCheckStatusRequestId",this.i18n.msg("createUserForm.field.requestId.required"),null);
}if(hasEmptyFields==false){self.userServiceFacade.getStatus(requestId,this._onSuccessRequestStatus,this._onErrorRequestStatus,self);
self.inet.loadStep("requestUserSendingRequest",{title:i18n.msg("createUserForm.description.checkmail.title"),message:i18n.msg("findRequestForm.legend.get"),},"requestUser");
$(".modal-content.custom-modal").css("height","200px");
$("body").loader("hide");
}};
RequestUserView.prototype._onSuccessRequestStatus=function(data){if(data.status!==""){self.inet.loadStep("requestUserStatusFinalStep",{data:data},"requestUser");
$(".modal-content.custom-modal").css("height","240px");
$("body").loader("hide");
}else{var errorMessage=this.i18n.msg(data.message);
self.inet.loadStep("requestUserErrorFinalStep",{title:i18n.msg("createUserForm.description.checkmail.title"),message:errorMessage!==""&&errorMessage!==undefined?errorMessage:i18n.msg("serviceError"),},"requestUser");
$(".modal-content.custom-modal").css("height","200px");
$("body").loader("hide");
}};
RequestUserView.prototype._onErrorRequestStatus=function(data){var errorMessage=this.i18n.msg(data.message);
self.inet.loadStep("requestUserErrorFinalStep",{title:i18n.msg("createUserForm.description.checkmail.title"),message:errorMessage!==""&&errorMessage!==undefined?errorMessage:i18n.msg("serviceError"),},"requestUser");
$(".modal-content.custom-modal").css("height","200px");
$("body").loader("hide");
};
RequestUserView.prototype._submitRequestForHelp=function(){var email=$.trim($("#requestUserHelpEmail").val());
var contact=$.trim($("#requestUserHelpContact").val());
var company=$.trim($("#requestUserHelpCompany").val());
var countryId=$.trim($("#requestUserHelpCountrySelect").val());
var issue=$.trim($("#requestUserHelpIssue").val());
var hasEmptyFields=false;
if(email!=""){this._removeValidationWarning("requestUserHelpEmail",hasEmptyFields);
}else{hasEmptyFields=true;
this._addValidationWarning("requestUserHelpEmail",this.i18n.msg("createUserForm.field.email.required"),null);
}if(contact!=""){this._removeValidationWarning("requestUserHelpContact",hasEmptyFields);
}else{hasEmptyFields=true;
this._addValidationWarning("requestUserHelpContact",this.i18n.msg("createUserForm.field.email.contact.required"),null);
}if(company!=""){this._removeValidationWarning("requestUserHelpCompany",hasEmptyFields);
}else{hasEmptyFields=true;
this._addValidationWarning("requestUserHelpCompany",this.i18n.msg("createUserForm.field.company.required"),null);
}if(countryId!=""&&countryId!="-1"){this._removeValidationWarning("requestUserHelpCountryDiv",hasEmptyFields);
}else{hasEmptyFields=true;
this._addValidationWarning("requestUserHelpCountryDiv",this.i18n.msg("createUserForm.field.country.required"),null);
}if(issue!=""){this._removeValidationWarning("requestUserHelpIssue",hasEmptyFields);
}else{hasEmptyFields=true;
this._addValidationWarning("requestUserHelpIssue",this.i18n.msg("mailForm.field.issue.required"),null);
}if(hasEmptyFields==false){var requestSupplierHelp={personalMail:email,itxContactMail:contact,requestedCompany:company,countryId:countryId,issue:issue};
self.userServiceFacade.supplierHelp(requestSupplierHelp,this._onSuccessRequestHelp,this._onErrorRequestHelp,self);
self.inet.loadStep("requestUserSendingRequest",{title:i18n.msg("createUserForm.description.checkmail.title"),message:i18n.msg("pasoFinal.mailform.sending"),},"requestUser");
$(".modal-content.custom-modal").css("height","200px");
$("body").loader("hide");
}};
RequestUserView.prototype._onSuccessRequestHelp=function(data){if(data.status=="CREATED"){self.inet.loadStep("requestUserHelpFinalStep",{data:data},"requestUser");
$(".modal-content.custom-modal").css("height","200px");
$("body").loader("hide");
}else{self.inet.loadStep("requestUserErrorFinalStep",{title:i18n.msg("createUserForm.description.question.title"),message:this.i18n.msg("mail.fail.sent")},"requestUser");
$(".modal-content.custom-modal").css("height","200px");
$("body").loader("hide");
}};
RequestUserView.prototype._onErrorRequestHelp=function(data){self.inet.loadStep("requestUserErrorFinalStep",{title:i18n.msg("createUserForm.description.question.title"),message:this.i18n.msg("mail.fail.sent")},"requestUser");
$(".modal-content.custom-modal").css("height","200px");
$("body").loader("hide");
};
RequestUserView.prototype._addValidationWarning=function(idDiv,msg,response){var self=this;
$("#"+idDiv).addClass("rojo");
if((null==msg||msg=="")&&null===response){msg=this.i18n.msg("error.required.field");
$("#"+idDiv+" + span").html(msg).removeClass("hide");
}else{if(msg!==null&&response===null){$("#"+idDiv+" + span").html(msg).removeClass("hide");
}else{var message=$.parseJSON(response.responseText).message;
$("#"+idDiv+" + span").html(message).removeClass("hide");
}}};
RequestUserView.prototype._removeValidationWarning=function(idDiv,hasEmptyFields){$("#"+idDiv).removeClass("rojo");
$("#"+idDiv+" + span").addClass("hide");
};