SyncMadeEasy/force-app/main/default/aura/AuthenticateOrg/AuthenticateOrgHelper.js

493 lines
23 KiB
JavaScript

({
InitializingHelper: function(component,event){
var accessexist = false;
var siteurl1 = component.get("v.selectedsite");
var sitelist = component.get("v.siteURLList");
var CheckSiteAccessaction = component.get("c.CheckSitefromConfiguration");
CheckSiteAccessaction.setCallback(this,function(res){
var state = res.getState();
if(state =="SUCCESS" && res.getReturnValue() != null && res.getReturnValue() != '' && res.getReturnValue() != 'false'){
component.set("v.selectedsite",res.getReturnValue());
component.set("v.URLsavedsuccess",true);
var CheckSiteClassandPageAccess = component.get("c.CheckSiteClassandPageAccess");
var guestuserid;
for(var item in sitelist ){
if(sitelist[item]['siteUrl'] == siteurl1 ){
guestuserid = sitelist[item]['siteguestid'];
}
}
CheckSiteClassandPageAccess.setParams({
'Guestuserid':guestuserid
});
CheckSiteClassandPageAccess.setCallback(this,function(res1){
var state2 = res1.getState();
if( state2 =="SUCCESS" && res1.getReturnValue() != null && (res1.getReturnValue() == true || res1.getReturnValue() == 'true')){
component.set("v.CheckSiteAccess",true);
component.set("v.CheckSiteExist" ,true);
try{
var CheckingRemoteSiteaction = component.get("c.CheckshopifycertificateandRemotesite");
CheckingRemoteSiteaction.setParams({
'Urltype':'remotesite'
});
CheckingRemoteSiteaction.setCallback(this,function(res3){
var state3 = res3.getState();
if(state3 =="SUCCESS" && (res3.getReturnValue() == true || res3.getReturnValue() == 'true' )){
component.set("v.Remotesiteexist",true);
try{
var CheckingCertifiacteactionagain = component.get("c.CheckshopifycertificateandRemotesite");
CheckingCertifiacteactionagain.setParams({
'Urltype':'certificate'
});
CheckingCertifiacteactionagain.setCallback(this,function(res4){
var state4 = res4.getState();
if(state4 =="SUCCESS" && (res4.getReturnValue() == true || res4.getReturnValue() == 'true' )){
component.set("v.CheckCertificate",true);
this.AuthenticationSuccess(component,event);
}
if(state4 =="SUCCESS" && (res4.getReturnValue() == false || res4.getReturnValue() == 'false' )){
component.set("v.CheckCertificate",false);
this.AuthenticationRequiredError(component,event);
}
});
$A.enqueueAction(CheckingCertifiacteactionagain);
}catch(e){
return false;
}
}
if(state3 =="SUCCESS" && (res3.getReturnValue() == false || res3.getReturnValue() == 'false' )){
component.set("v.CheckCertificate",false);
component.set("v.Remotesiteexist",false);
this.AuthenticationRequiredError(component,event);
}
});
$A.enqueueAction(CheckingRemoteSiteaction);
return false;
}catch(e){
return false;
}
}else{
component.set("v.CheckCertificate",false)
component.set("v.URLsavedsuccess",false);
component.set("v.CheckSiteAccess",false);
var actionDeletesitefromconfig = component.get("c.Deletesitefromconfig");
actionDeletesitefromconfig.setCallback(this,function(resDeletesitefromconfig){
var stateDeletesitefromconfig = resDeletesitefromconfig.getState();
if(stateDeletesitefromconfig =="SUCCESS" && resDeletesitefromconfig.getReturnValue() != null && resDeletesitefromconfig.getReturnValue() == true){
this.AuthenticationRequiredError(component,event);
}
});
$A.enqueueAction(actionDeletesitefromconfig);
}
return accessexist;
});
$A.enqueueAction(CheckSiteClassandPageAccess);
}else{
this.AuthenticationRequiredError(component,event);
component.set("v.CheckCertificate",false);
component.set("v.URLsavedsuccess",false);
}
});
$A.enqueueAction(CheckSiteAccessaction);
},
AuthenticationSuccess: function(component,event){
//component.set("v.Spinner",false);
var Authenticateaction = component.get("c.CreateAuthenticateURL");
Authenticateaction.setCallback(this,function(res){
var state = res.getState();
if(state =="SUCCESS" ){
component.set("v.AuthenticateButton",true);
var authenticateurl = component.get('v.AUthenticationLink')+component.get('v.viewmode');
window.open(authenticateurl,'_top');
}
});
$A.enqueueAction(Authenticateaction );
},
AuthenticationRequiredError: function(component,event){
component.set("v.Spinner",false);
//component.set("v.CheckSiteAccess",false);
//component.set("v.DisableButton",false);
component.set("v.errormessage","Authenticate required error");
var action = component.get("c.openModel");
component.set("v.Spinner", false);
$A.enqueueAction(action);
},
checksiteaccess: function(component,event,saved){
var savedthis = saved;
var accessexist = false;
var CheckSiteAccessaction = component.get("c.CheckSiteClassandPageAccess");
// var siteurl1 = component.find("beforeauthsite").get("v.value");
var siteurl1 = component.get("v.selectedsite");
if(siteurl1 == undefined || siteurl1 == null || siteurl1 == ''){
try{
siteurl1 = component.find("beforeauthsite").get("v.value");
}catch(e){
}
}
var sitelist = component.get("v.siteURLList");
var guestuserid;
var SiteName;
for(var item in sitelist ){
if(sitelist[item]['siteUrl'] == siteurl1 ){
guestuserid = sitelist[item]['siteguestid'];
SiteName = sitelist[item]['Name'];
}
}
CheckSiteAccessaction.setParams({
'Guestuserid':guestuserid
});
CheckSiteAccessaction.setCallback(this,function(res){
var state = res.getState();
if( state =="SUCCESS" && res.getReturnValue() != null && (res.getReturnValue() == true || res.getReturnValue() == 'true')){
//this.goNext(component, event);
component.set("v.Spinner", false);
try{
document.getElementById("mainSpinner").style.display = "none";
document.getElementById("Attentionfieldset").style.pointerEvents = "all";
}catch(e){
}
if(savedthis == false) return;
var actionsaveconfig = component.get("c.savesiteurlconfig");
actionsaveconfig.setParams({
"siteurl": siteurl1
});
actionsaveconfig.setCallback(this,function(res1){
var state1 = res1.getState();
if(state1 =="SUCCESS" && res1.getReturnValue() != null ){
if(res1.getReturnValue() == false || res1.getReturnValue() == 'false'){
component.set("v.CheckSiteAccess",false);
component.find("beforeauthsite").set("v.disabled",false);
component.set("v.errormessage","get error while saving site");
var action = component.get("c.openModel");
try{
document.getElementById("mainSpinner").style.display = "none";
}catch(e){
}
try{
document.getElementById("Attentionfieldset").style.pointerEvents = "all";
}catch(e){
}
component.set("v.Spinner", false);
$A.enqueueAction(action);
setTimeout(function(){
event.getSource().set("v.iconName" , 'utility:save');
event.getSource().set("v.label" , 'Save');
component.set("v.isOpen", false);
}, 1000);
component.find("beforeauthsite").set("v.disabled",false);
$A.util.addClass(component.find('DataProceesing'), 'Hidediv');
}else if(res1.getReturnValue() == true || res1.getReturnValue() == 'true'){
accessexist = res1.getReturnValue();
//component.set("v.CheckSiteAccess",false);
component.find("beforeauthsite").set("v.disabled",true);
component.set("v.SiteNotifcation","The site has been saved successfully.");
$A.util.addClass(component.find('DataProceesing'), 'Hidediv');
if(siteurl1 != null && siteurl1 != '' && siteurl1 != undefined){
component.set("v.ConfigsavedsiteUrl",siteurl1);
}
// document.getElementById("Checkstates").style.display = "none";
// document.getElementById("CancleGotosite").style.display = "none";
try{
document.getElementById("mainSpinner").style.display = "none";
}catch(e){
}
try{
document.getElementById("Attentionfieldset").style.pointerEvents = "all";
}catch(e){
}
component.set("v.Spinner", false);
component.set("v.CheckSiteAccess",true);
component.set("v.CheckSiteExist",true);
component.set("v.URLsavedsuccess",true);
component.set("v.CheckSiteExist",true);
event.getSource().set("v.iconName" , 'utility:check');
event.getSource().set("v.label" , 'Saved');
setTimeout(function(){
//event.getSource().set("v.iconName" , 'utility:download');
//event.getSource().set("v.label" , 'Save');
component.set("v.SiteModalIsOpen", false);
}, 1000);
}
}
});
$A.enqueueAction(actionsaveconfig);
}else{
if(component.get("v.SiteModalIsOpen") == true || component.get("v.SiteModalIsOpen") == 'true'){
component.find("beforeauthsite").set("v.disabled",false);
component.find("sitesavebutton").set("v.disabled",false);
}
component.set("v.URLsavedsuccess",false);
component.set("v.CheckSiteAccess",false);
//component.set("v.DisableButton",false);
component.set("v.SiteNotifcation",SiteName + "\'s site have no access or this is not active. Please active site or give site access");
/*try{
document.getElementById("mainSpinner").style.display = "none";
}catch(e){
}*/
component.set("v.Spinner", false);
$A.util.addClass(component.find('DataProceesing'), 'Hidediv');
try{
document.getElementById("mainSpinner").style.display = "none";
}catch(e){
}
try{
document.getElementById("Attentionfieldset").style.pointerEvents = "all";
}catch(e){
}
}
return accessexist;
});
$A.enqueueAction(CheckSiteAccessaction);
//return accessexist;
},
copyTextHelper : function(component,event,text) {
// Create an hidden input
var hiddenInput = document.createElement("input");
// passed text into the input
hiddenInput.setAttribute("value", text);
// Append the hiddenInput input to the body
document.body.appendChild(hiddenInput);
// select the content
hiddenInput.select();
// Execute the copy command
document.execCommand("copy");
// Remove the input from the body after copy text
document.body.removeChild(hiddenInput);
// store target button label value
var orignalLabel = component.get("v.copyurlvalue")
component.set("v.copyurlvalue",'copied');
// set timeout to reset icon and label value after 700 milliseconds
/*setTimeout(function(){
component.set("v.copyurlvalue", orignalLabel);
}, 700);*/
},
CheckSitefromConfiguration: function(component, event, helper,listofsiteexits) {
component.set("v.Spinner",true);
var CheckSiteAccessaction = component.get("c.CheckSitefromConfiguration");
CheckSiteAccessaction.setCallback(this,function(res){
var state = res.getState();
if(listofsiteexits == true && state =="SUCCESS" && res.getReturnValue() != null && res.getReturnValue() != '' && res.getReturnValue() != 'false'){
component.set("v.selectedsite",res.getReturnValue());
component.set("v.ConfigsavedsiteUrl",res.getReturnValue());
try{
document.getElementById("configsite").style.opacity = '0.6';
}catch(e){
}
component.set("v.URLsavedsuccess",true);
//change the field
//component.find("sitesavebutton").set("v.iconName" , 'utility:check');
//component.find("sitesavebutton").set("v.label" , 'Saved');
this.checksiteaccess(component, event,false);
//component.set("v.Spinner",false);
}else if( state =="SUCCESS" && res.getReturnValue() != null && res.getReturnValue() != '' && (res.getReturnValue() == 'false'|| listofsiteexits == false)){
//component.set("v.selectedsite","");
component.set("v.URLsavedsuccess",false);
try{
document.getElementById("configsite").style.opacity = 'unset';
}catch(e){
}
try{
document.getElementById("mainSpinner").style.display = "none";
}catch(e){
}
try{
document.getElementById("Attentionfieldset").style.pointerEvents = "all";
}catch(e){
}
component.set("v.Spinner",false);
}
});
$A.enqueueAction(CheckSiteAccessaction);
},
Toolingremotesite : function(component, event, helper) {
var CreateToolingRemotesite = component.get("c.createToolingRemoteSiteSettings");
CreateToolingRemotesite.setCallback(this,function(res1){
var state1 = res1.getState();
if(state1 =="SUCCESS" && (res1.getReturnValue() == true || res1.getReturnValue() == 'true' )){
component.set("v.Toolingremotesite",true);
}
if(state1 =="SUCCESS" && res1.getReturnValue().includes('http') ){
component.set("v.CreateRemotesiteSettingUrl",res1.getReturnValue());
}
window.open('/0DM/o','_blank');
});
$A.enqueueAction(CreateToolingRemotesite);
},
checkingCertificate : function(component, event) {
// if(component.get("v.CheckSiteExist") == false || component.get("v.CheckSiteAccess") == false) return;
try{
var CheckingCertifiacteaction = component.get("c.CheckshopifycertificateandRemotesite");
CheckingCertifiacteaction.setParams({
'Urltype':'certificate'
});
CheckingCertifiacteaction.setCallback(this,function(res){
var state = res.getState();
if(state =="SUCCESS" && (res.getReturnValue() == true || res.getReturnValue() == 'true' )){
component.set("v.CheckCertificate",true);
return true;
}
if(state =="SUCCESS" && (res.getReturnValue() == false || res.getReturnValue() == 'false' )){
component.set("v.CheckCertificate",false);
var cmpEvent = component.getEvent("AuthenticateErorrEvent");
cmpEvent.setParams({
"hasError" : false });
cmpEvent.fire();
return false;
}
});
$A.enqueueAction(CheckingCertifiacteaction);
return false;
}catch(e){
return false;
}
},
CheckingRemotesitesetting : function(component, event) {
// if(component.get("v.CheckSiteExist") == false || component.get("v.CheckSiteAccess") == false) return;
try{
var CheckingCertifiacteaction = component.get("c.CheckshopifycertificateandRemotesite");
CheckingCertifiacteaction.setParams({
'Urltype':'remotesite'
});
CheckingCertifiacteaction.setCallback(this,function(res){
var state = res.getState();
if(state =="SUCCESS" && (res.getReturnValue() == true || res.getReturnValue() == 'true' )){
component.set("v.Remotesiteexist",true);
return true;
}
if(state =="SUCCESS" && (res.getReturnValue() == false || res.getReturnValue() == 'false' )){
component.set("v.Remotesiteexist",false);
var cmpEvent = component.getEvent("AuthenticateErorrEvent");
cmpEvent.setParams({
"hasError" : false });
cmpEvent.fire();
return false;
}
});
$A.enqueueAction(CheckingCertifiacteaction);
return false;
}catch(e){
return false;
}
},
getSiteURLList : function( component, event,helper ) {
var action = component.get("c.getSiteURLs");
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS" && response.getReturnValue() != null ) {
component.set("v.CheckSiteExist",true);
component.set("v.CheckSiteAccess",true);
component.set("v.siteURLList",JSON.parse(response.getReturnValue()));
this.CheckSitefromConfiguration(component, event, helper, true);
}else if(state === "SUCCESS" && response.getReturnValue() == null){
component.set("v.CheckSiteExist",false);
this.CheckSitefromConfiguration(component, event, helper, false);
}
else if (state === "INCOMPLETE") {
// do something
}
else if (state === "ERROR") {
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("Error message: " +
errors[0].message);
}
} else {
console.log("Unknown error");
}
}
});
$A.enqueueAction(action);
},
})