SyncMadeEasy/force-app/main/default/aura/dynamicRow/dynamicRowHelper.js

901 lines
53 KiB
JavaScript

({
getConfigrationForDynamicRow : function(component,event){
var action = component.get("c.getConfigrationForDynamicRow");
action.setParams({
"store" : component.get("v.store")
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS" && response.getReturnValue() != null) {
component.set("v.configObj", JSON.parse(response.getReturnValue()));
}
else if (state === "INCOMPLETE") {
console.log('in complete');
}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);
},
getEverythingForContact: function(component,event){
try{
console.log('getEverythingForContact called');
var action = component.get("c.getEverythingForContact");
action.setParams({
"store" : (component.get("v.processForNewStore") ? 'Default' : component.get("v.store") )
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS" && response.getReturnValue() != null ) {
// Contact
if(response.getReturnValue()[0] != null && response.getReturnValue()[0] != '' && response.getReturnValue()[0] != 'Null'){
component.set("v.contactTableData1",JSON.parse(response.getReturnValue()[0]));
}
if(response.getReturnValue()[2] != null && response.getReturnValue()[2] != '' && response.getReturnValue()[2] != 'Null'){
component.set("v.contactTableData2",JSON.parse(response.getReturnValue()[2]));
}
if(response.getReturnValue()[3] != null && response.getReturnValue()[3] != '' && response.getReturnValue()[3] != 'Null'){
component.set("v.defaultFieldMappingForContact",JSON.parse(response.getReturnValue()[3]));
}
if(response.getReturnValue()[1] != null && response.getReturnValue()[1] != '' && response.getReturnValue()[1] != 'Null'){
component.set("v.contactTableRequiredData1",JSON.parse(response.getReturnValue()[1]));
}
this.fillObjectList(component, event, "v.contactTableData2", "v.defaultFieldMappingForContact", "v.contactTableData1", "Contact", "v.contactList", component.get("v.contactTableRequiredData1"), "v.contactTableRequiredData1");
// component.set("v.DoInItComplete",true);
// component.set("v.Spinner", false);
// var CloseSpinnerEventFire = $A.get("e.c:CloseSpinner");
// CloseSpinnerEventFire.setParams({ "Spinner" : false });
// CloseSpinnerEventFire.fire();
// component.set("v.GoDisableButton",false);
// component.set("v.PreDisableButton",false);
}
else if (state === "INCOMPLETE") {
console.log('in complete');
}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);
}catch(e){
console.log('error--> '+e);
}
},
getEverythingForAccount: function(component,event){
try{
console.log('getEverythingForAccount called');
var action = component.get("c.getEverythingForAccount");
action.setParams({
"store" : (component.get("v.processForNewStore") ? 'Default' : component.get("v.store") )
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS" && response.getReturnValue() != null ) {
console.log('business account required field '+response.getReturnValue()[1] );
// if(response.getReturnValue()[0] != null && response.getReturnValue()[0] != '' && response.getReturnValue()[0] != 'Null'){
// component.set("v.configObj", JSON.parse(response.getReturnValue()[0]));
// }
// Account and Person Account
if(response.getReturnValue()[0] != null && response.getReturnValue()[0] != '' && response.getReturnValue()[0] != 'Null'){
component.set("v.objectTableData1",JSON.parse(response.getReturnValue()[0]));
}
if(response.getReturnValue()[3] != null && response.getReturnValue()[3] != '' && response.getReturnValue()[3] != 'Null'){
component.set("v.objectTableData2",JSON.parse(response.getReturnValue()[3]));
}
if(response.getReturnValue()[1] != null && response.getReturnValue()[1] != '' && response.getReturnValue()[1] != 'Null'){
component.set("v.objectTableRequiredData1",JSON.parse(response.getReturnValue()[1]));
}
if(response.getReturnValue()[2] != null && response.getReturnValue()[2] != '' && response.getReturnValue()[2] != 'Null'){
component.set("v.PersonAccountTableRequiredData1",JSON.parse(response.getReturnValue()[2]));
}
if(response.getReturnValue()[4] != null && response.getReturnValue()[4] != '' && response.getReturnValue()[4] != 'Null'){
component.set("v.defaultFieldMappingForAccount",JSON.parse(response.getReturnValue()[4]));
}
var listofAllRequiredFieldsofAccount = [] ;
var objectRequiredFieldListName;
if(component.get("v.configObj.HIC_ShopifySync__Person_Account__c")){
listofAllRequiredFieldsofAccount = component.get("v.PersonAccountTableRequiredData1");
objectRequiredFieldListName = "v.PersonAccountTableRequiredData1";
}else{
listofAllRequiredFieldsofAccount = component.get("v.objectTableRequiredData1");
objectRequiredFieldListName = "v.objectTableRequiredData1";
}
this.fillObjectList(component, event, "v.objectTableData2", "v.defaultFieldMappingForAccount", "v.objectTableData1", "Account", "v.accountList", listofAllRequiredFieldsofAccount, objectRequiredFieldListName);
// component.set("v.DoInItComplete",true);
// component.set("v.Spinner", false);
// var CloseSpinnerEventFire = $A.get("e.c:CloseSpinner");
// CloseSpinnerEventFire.setParams({ "Spinner" : false });
// CloseSpinnerEventFire.fire();
// component.set("v.GoDisableButton",false);
// component.set("v.PreDisableButton",false);
}
else if (state === "INCOMPLETE") {
console.log('in complete');
}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);
}catch(e){
console.log('error--> '+e);
}
},
getEverythingForOpportunity: function(component,event){
try{
console.log('getEverythingForOpportunity called');
var action = component.get("c.getEverythingForOpportunity");
action.setParams({
"store" : (component.get("v.processForNewStore") ? 'Default' : component.get("v.store") )
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS" && response.getReturnValue() != null ) {
// Opportunity
if(response.getReturnValue()[0] != null && response.getReturnValue()[0] != '' && response.getReturnValue()[0] != 'Null'){
component.set("v.opportunityTableData1",JSON.parse(response.getReturnValue()[0]));
}
if(response.getReturnValue()[2] != null && response.getReturnValue()[2] != '' && response.getReturnValue()[2] != 'Null'){
component.set("v.opportunityTableData2",JSON.parse(response.getReturnValue()[2]));
}
if(response.getReturnValue()[3] != null && response.getReturnValue()[3] != '' && response.getReturnValue()[3] != 'Null'){
component.set("v.defaultFieldMappingForOpportunity",JSON.parse(response.getReturnValue()[3]));
}
if(response.getReturnValue()[1] != null && response.getReturnValue()[1] != '' && response.getReturnValue()[1] != 'Null'){
component.set("v.OpportunityTableRequiredData1",JSON.parse(response.getReturnValue()[1]));
}
this.fillObjectList(component, event, "v.opportunityTableData2", "v.defaultFieldMappingForOpportunity", "v.opportunityTableData1", "Opportunity", "v.opportunityList", component.get("v.OpportunityTableRequiredData1"), "v.OpportunityTableRequiredData1");
// component.set("v.DoInItComplete",true);
// component.set("v.Spinner", false);
// var CloseSpinnerEventFire = $A.get("e.c:CloseSpinner");
// CloseSpinnerEventFire.setParams({ "Spinner" : false });
// CloseSpinnerEventFire.fire();
// component.set("v.GoDisableButton",false);
// component.set("v.PreDisableButton",false);
}
else if (state === "INCOMPLETE") {
console.log('in complete');
}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);
}catch(e){
console.log('error--> '+e);
}
},
getEverythingForOpportunityProd: function(component,event){
try{
console.log('getEverythingForOpportunityProd called');
var action = component.get("c.getEverythingForOppProduct");
action.setParams({
"store" : (component.get("v.processForNewStore") ? 'Default' : component.get("v.store") )
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS" && response.getReturnValue() != null ) {
//Opportunity Product
if(response.getReturnValue()[0] != null && response.getReturnValue()[0] != '' && response.getReturnValue()[0] != 'Null'){
component.set("v.opportunityProductTableData1",JSON.parse(response.getReturnValue()[0]));
}
if(response.getReturnValue()[2] != null && response.getReturnValue()[2] != '' && response.getReturnValue()[2] != 'Null'){
component.set("v.opportunityProductTableData2",JSON.parse(response.getReturnValue()[2]));
}
if(response.getReturnValue()[3] != null && response.getReturnValue()[3] != '' && response.getReturnValue()[3] != 'Null'){
component.set("v.defaultFieldMappingForOpportunityProduct",JSON.parse(response.getReturnValue()[3]));
}
if(response.getReturnValue()[1] != null && response.getReturnValue()[1] != '' && response.getReturnValue()[1] != 'Null'){
component.set("v.OpportunityProductTableRequiredData1",JSON.parse(response.getReturnValue()[1]));
}
this.fillObjectList(component, event, "v.opportunityProductTableData2", "v.defaultFieldMappingForOpportunityProduct", "v.opportunityProductTableData1", "OpportunityLineItem", "v.opportunityProductList", component.get("v.OpportunityProductTableRequiredData1"), "v.OpportunityProductTableRequiredData1");
// component.set("v.DoInItComplete",true);
// component.set("v.Spinner", false);
// var CloseSpinnerEventFire = $A.get("e.c:CloseSpinner");
// CloseSpinnerEventFire.setParams({ "Spinner" : false });
// CloseSpinnerEventFire.fire();
// component.set("v.GoDisableButton",false);
// component.set("v.PreDisableButton",false);
}
else if (state === "INCOMPLETE") {
console.log('in complete');
}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);
}catch(e){
console.log('error--> '+e);
}
},
getEverythingForOrderOrderPrdDrfOrderandDrfOrdProduct : function(component,event){
try{
var action = component.get("c.getEverythingForOrderOrderPrdDrfOrderandDrfOrdProduct");
action.setParams({
"store" : (component.get("v.processForNewStore") ? 'Default' : component.get("v.store") )
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS" && response.getReturnValue() != null ) {
if(response.getReturnValue()[0] != null && response.getReturnValue()[0] != '' && response.getReturnValue()[0] != 'Null'){
component.set("v.orderTableData1",JSON.parse(response.getReturnValue()[0]));
}
if(response.getReturnValue()[2] != null && response.getReturnValue()[2] != '' && response.getReturnValue()[2] != 'Null'){
component.set("v.orderTableData2",JSON.parse(response.getReturnValue()[2]));
}
if(response.getReturnValue()[3] != null && response.getReturnValue()[3] != '' && response.getReturnValue()[3] != 'Null'){
component.set("v.defaultFieldMappingForOrder",JSON.parse(response.getReturnValue()[3]));
}
if(response.getReturnValue()[1] != null && response.getReturnValue()[1] != '' && response.getReturnValue()[1] != 'Null'){
component.set("v.OrderTableRequiredData1",JSON.parse(response.getReturnValue()[1]));
component.set("v.DraftOrderTableRequiredData",JSON.parse(response.getReturnValue()[1]));
}
this.fillObjectList(component, event, "v.orderTableData2", "v.defaultFieldMappingForOrder", "v.orderTableData1", "Order", "v.orderList", component.get("v.OrderTableRequiredData1"), "v.OrderTableRequiredData1");
//Order Product
if(response.getReturnValue()[4] != null && response.getReturnValue()[4] != '' && response.getReturnValue()[4] != 'Null'){
component.set("v.orderProductTableData1",JSON.parse(response.getReturnValue()[4]));
}
if(response.getReturnValue()[6] != null && response.getReturnValue()[6] != '' && response.getReturnValue()[6] != 'Null'){
component.set("v.orderProductTableData2",JSON.parse(response.getReturnValue()[6]));
}
if(response.getReturnValue()[7] != null && response.getReturnValue()[7] != '' && response.getReturnValue()[7] != 'Null'){
component.set("v.defaultFieldMappingForOrderProduct",JSON.parse(response.getReturnValue()[7]));
}
if(response.getReturnValue()[5] != null && response.getReturnValue()[5] != '' && response.getReturnValue()[5] != 'Null'){
component.set("v.OrderProductTableRequiredData1",JSON.parse(response.getReturnValue()[5]));
component.set("v.DraftOrderProductTableRequiredData",JSON.parse(response.getReturnValue()[5]));
}
this.fillObjectList(component, event, "v.orderProductTableData2", "v.defaultFieldMappingForOrderProduct", "v.orderProductTableData1", "OrderItem", "v.orderProductList", component.get("v.OrderProductTableRequiredData1"), "v.OrderProductTableRequiredData1");
//Draft Order
if(response.getReturnValue()[8] != null && response.getReturnValue()[8] != '' && response.getReturnValue()[8] != 'Null'){
component.set("v.draftOrderTableData2",JSON.parse(response.getReturnValue()[8]));
}
if(response.getReturnValue()[9] != null && response.getReturnValue()[9] != '' && response.getReturnValue()[9] != 'Null'){
component.set("v.defaultFieldMappingForDraftOrder",JSON.parse(response.getReturnValue()[9]));
}
//alert('draftOrderTableData2--> ' + component.get("v.draftOrderTableData2") +' defaultFieldMappingForDraftOrder--> '+ component.get("v.defaultFieldMappingForDraftOrder") + ' orderTableData1--> ' + component.get("v.orderTableData1")+ ' DraftOrderTableRequiredData--> '+ component.get("v.DraftOrderTableRequiredData"));
this.fillObjectList(component, event, "v.draftOrderTableData2", "v.defaultFieldMappingForDraftOrder", "v.orderTableData1", "DraftOrder", "v.draftOrderList", component.get("v.DraftOrderTableRequiredData"), "v.DraftOrderTableRequiredData");
//Draft Order Product
if(response.getReturnValue()[10] != null && response.getReturnValue()[10] != '' && response.getReturnValue()[10] != 'Null'){
component.set("v.draftOrderProductTableData2",JSON.parse(response.getReturnValue()[10]));
}
if(response.getReturnValue()[11] != null && response.getReturnValue()[11] != '' && response.getReturnValue()[11] != 'Null'){
component.set("v.defaultFieldMappingForDraftOrderProduct",JSON.parse(response.getReturnValue()[11]));
}
this.fillObjectList(component, event, "v.draftOrderProductTableData2", "v.defaultFieldMappingForDraftOrderProduct", "v.orderProductTableData1", "DraftOrderItem", "v.draftOrderProductList", component.get("v.DraftOrderProductTableRequiredData"), "v.DraftOrderProductTableRequiredData");
component.set("v.DoInItComplete",true);
component.set("v.Spinner", false);
component.set("v.GoDisableButton",false);
component.set("v.PreDisableButton",false);
var CloseSpinnerEventFire = $A.get("e.c:CloseSpinner");
CloseSpinnerEventFire.setParams({ "Spinner" : false });
CloseSpinnerEventFire.fire();
}
else if (state === "INCOMPLETE") {
console.log('in complete');
}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);
}catch(e){
console.log('error--> '+e);
}
},
getEverythingForProductAndVariant : function(component,event){
try{
var action = component.get("c.getEverythingForProductAndVariant");
action.setParams({
"store" : (component.get("v.processForNewStore") ? 'Default' : component.get("v.store") )
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS" && response.getReturnValue() != null ) {
if(response.getReturnValue()[0] != null && response.getReturnValue()[0] != '' && response.getReturnValue()[0] != 'Null'){
component.set("v.productTableData1",JSON.parse(response.getReturnValue()[0]));
}
if(response.getReturnValue()[2] != null && response.getReturnValue()[2] != '' && response.getReturnValue()[2] != 'Null'){
component.set("v.productTableData2",JSON.parse(response.getReturnValue()[2]));
}
if(response.getReturnValue()[3] != null && response.getReturnValue()[3] != '' && response.getReturnValue()[3] != 'Null'){
component.set("v.defaultFieldMappingForProduct",JSON.parse(response.getReturnValue()[3]));
}
if(response.getReturnValue()[1] != null && response.getReturnValue()[1] != '' && response.getReturnValue()[1] != 'Null'){
component.set("v.ProductTableRequiredData1",JSON.parse(response.getReturnValue()[1]));
}
this.fillObjectList(component, event, "v.productTableData2", "v.defaultFieldMappingForProduct", "v.productTableData1", "Product2", "v.productList", component.get("v.ProductTableRequiredData1"), "v.ProductTableRequiredData1");
//Variant
if(response.getReturnValue()[4] != null && response.getReturnValue()[4] != '' && response.getReturnValue()[4] != 'Null'){
component.set("v.variantTableData1",JSON.parse(response.getReturnValue()[4]));
}
if(response.getReturnValue()[6] != null && response.getReturnValue()[6] != '' && response.getReturnValue()[6] != 'Null'){
component.set("v.variantTableData2",JSON.parse(response.getReturnValue()[6]));
}
if(response.getReturnValue()[7] != null && response.getReturnValue()[7] != '' && response.getReturnValue()[7] != 'Null'){
component.set("v.defaultFieldMappingForVariant",JSON.parse(response.getReturnValue()[7]));
}
if(response.getReturnValue()[5] != null && response.getReturnValue()[5] != '' && response.getReturnValue()[5] != 'Null'){
component.set("v.VariantTableRequiredData1",JSON.parse(response.getReturnValue()[5]));
}
this.fillObjectList(component, event, "v.variantTableData2", "v.defaultFieldMappingForVariant", "v.variantTableData1", "HIC_ShopifySync__Variant__c", "v.variantList", component.get("v.VariantTableRequiredData1"), "v.VariantTableRequiredData1");
component.set("v.DoInItComplete",true);
component.set("v.Spinner", false);
component.set("v.GoDisableButton",false);
component.set("v.PreDisableButton",false);
var CloseSpinnerEventFire = $A.get("e.c:CloseSpinner");
CloseSpinnerEventFire.setParams({ "Spinner" : false });
CloseSpinnerEventFire.fire();
}
else if (state === "INCOMPLETE") {
console.log('in complete');
}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);
}catch(e){
console.log('error--> '+e);
}
},
fillObjectList : function( component, event, shopifyFieldList, defaultMappingList, SalesforceFieldList, SObjectType, objectListName, listofrequiredfieldList, objectRequiredFieldListName) {
var mapofshopifyfieldvsname = new Map();
var listofshopifyfieldcustomsetting = component.get(shopifyFieldList);
for(var item in listofshopifyfieldcustomsetting ){
if(listofshopifyfieldcustomsetting[item]["HIC_ShopifySync__Nested__c"] != null && listofshopifyfieldcustomsetting[item]["HIC_ShopifySync__Nested__c"] != ''){
mapofshopifyfieldvsname.set(listofshopifyfieldcustomsetting[item]["HIC_ShopifySync__Nested__c"]+'.'+listofshopifyfieldcustomsetting[item]["HIC_ShopifySync__Field_Name__c"],listofshopifyfieldcustomsetting[item]["Name"]);
}else{
mapofshopifyfieldvsname.set(listofshopifyfieldcustomsetting[item]["HIC_ShopifySync__Field_Name__c"],listofshopifyfieldcustomsetting[item]["Name"]);
}
}
// Optional fileds mapping account
//component.get("v.configObj.HIC_ShopifySync__Person_Account__c");
var sobjectDefaultMappingList = component.get(defaultMappingList);
var objectList = [];
var objectOptionalFieldList = component.get(SalesforceFieldList);
for(var item in sobjectDefaultMappingList){
for(var item2 in objectOptionalFieldList){
if(sobjectDefaultMappingList[item]['HIC_ShopifySync__SF_Field__c'] != null && sobjectDefaultMappingList[item]['HIC_ShopifySync__SF_Field__c'] != '' && objectOptionalFieldList[item2]['filedApiName'] == sobjectDefaultMappingList[item]['HIC_ShopifySync__SF_Field__c']){
// console.log('*****Item****');
//console.log(sobjectDefaultMappingList[item]['Name']);
var newItem = {};
newItem['sobjectType'] = SObjectType;
newItem['salesforcefields'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__SF_Field__c'];
newItem['salesforceFieldLabel'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__SF_Field__c'];
newItem['salesforceFieldType'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__SF_Field_Type__c'];
newItem['DefaultValue'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__Default_Value__c'];
// console.log(sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c']);
if(sobjectDefaultMappingList[item]['HIC_ShopifySync__Default_Value__c']){
newItem['selectedfields'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'];
}else if( sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'] !== undefined && mapofshopifyfieldvsname.has(sobjectDefaultMappingList[item]['HIC_ShopifySync__Nested__c']+'.'+sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c']) && !sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'].includes(",")){
if(sobjectDefaultMappingList[item]['HIC_ShopifySync__Nested__c'] != null && sobjectDefaultMappingList[item]['HIC_ShopifySync__Nested__c'] != ''){
newItem['selectedfields'] = mapofshopifyfieldvsname.get(sobjectDefaultMappingList[item]['HIC_ShopifySync__Nested__c']+'.'+sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c']);
}else{
newItem['selectedfields'] = mapofshopifyfieldvsname.get(sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c']);
}
}else if(sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'] !== undefined && mapofshopifyfieldvsname.has(sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c']) && !sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'].includes(",")){
newItem['selectedfields'] = mapofshopifyfieldvsname.get(sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c']);
}else if(sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'] !== undefined && sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'].includes(",")){
if(sobjectDefaultMappingList[item]['HIC_ShopifySync__Nested__c'] != null && sobjectDefaultMappingList[item]['HIC_ShopifySync__Nested__c'] != '' ){
var temp = '';
var multipleFieldList = sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'];
for(var item1 in multipleFieldList.split(",")){
// console.log('item'+multipleFieldList.split(",")[item1]);
//console.log('item'+item1);
if(temp == ''){
temp = sobjectDefaultMappingList[item]['HIC_ShopifySync__Nested__c']+'.'+multipleFieldList.split(",")[item1];
}else{
temp += ','+sobjectDefaultMappingList[item]['HIC_ShopifySync__Nested__c']+'.'+multipleFieldList.split(",")[item1];
}
}
newItem['selectedfields'] = temp;
}else if(sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'] !== undefined) {
newItem['selectedfields'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'];
}
}else{
//if (newItem['DefaultValue'] === true){
//newItem['selectedfields'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'] !== 'false';
//}else{
newItem['selectedfields'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'];
//}
}
newItem['shopifyFieldName'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'];
newItem['shopifyFieldType'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Field_Type__c'];
objectList.push(newItem);
}
}
}
if(objectList.length != 0){
component.set(objectListName,objectList);
}
var objectRequiredFieldList = listofrequiredfieldList;
for(var item in sobjectDefaultMappingList){
for(var item2 in objectRequiredFieldList){
if(sobjectDefaultMappingList[item]['HIC_ShopifySync__SF_Field__c'] != null && sobjectDefaultMappingList[item]['HIC_ShopifySync__SF_Field__c'] != '' && objectRequiredFieldList[item2]['filedApiName'].toUpperCase() == sobjectDefaultMappingList[item]['HIC_ShopifySync__SF_Field__c'].toUpperCase()){
objectRequiredFieldList[item2]['sobjectType'] = SObjectType;
objectRequiredFieldList[item2]['salesforcefields'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__SF_Field__c'];
objectRequiredFieldList[item2]['salesforceFieldLabel'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__SF_Field__c'];
objectRequiredFieldList[item2]['salesforceFieldType'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__SF_Field_Type__c'];
objectRequiredFieldList[item2]['DefaultValue'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__Default_Value__c'];
if(sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'] !== undefined && sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'] !== undefined && mapofshopifyfieldvsname.has(sobjectDefaultMappingList[item]['HIC_ShopifySync__Nested__c']+'.'+sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c']) && !sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'].includes(",")){
if(sobjectDefaultMappingList[item]['HIC_ShopifySync__Nested__c'] != null && sobjectDefaultMappingList[item]['HIC_ShopifySync__Nested__c'] != ''){
objectRequiredFieldList[item2]['selectedfields'] = mapofshopifyfieldvsname.get(sobjectDefaultMappingList[item]['HIC_ShopifySync__Nested__c']+'.'+sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c']);
}else{
objectRequiredFieldList[item2]['selectedfields'] = mapofshopifyfieldvsname.get(sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c']);
}
}else if(sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'] !== undefined && mapofshopifyfieldvsname.has(sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c']) && !sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'].includes(",")){
objectRequiredFieldList[item2]['selectedfields'] = mapofshopifyfieldvsname.get(sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c']);
}else if(sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'] !== undefined && sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'].includes(",")){
if(sobjectDefaultMappingList[item]['HIC_ShopifySync__Nested__c'] != null && sobjectDefaultMappingList[item]['HIC_ShopifySync__Nested__c'] != ''){
var temp = '';
var multipleFieldList = sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'];
for(var item1 in multipleFieldList.split(",")){
//console.log('item'+multipleFieldList.split(",")[item1]);
//console.log('item'+item1);
if(temp == ''){
temp = sobjectDefaultMappingList[item]['HIC_ShopifySync__Nested__c']+'.'+multipleFieldList.split(",")[item1];
}else{
temp += ','+sobjectDefaultMappingList[item]['HIC_ShopifySync__Nested__c']+'.'+multipleFieldList.split(",")[item1];
}
}
objectRequiredFieldList[item2]['selectedfields'] = temp;
}else{
objectRequiredFieldList[item2]['selectedfields'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'];
}
}else if(sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'] === undefined ){
objectRequiredFieldList[item2]['selectedfields'] = null;
}else{
objectRequiredFieldList[item2]['selectedfields'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'];
}
objectRequiredFieldList[item2]['shopifyFieldName'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Fields__c'];
objectRequiredFieldList[item2]['shopifyFieldType'] = sobjectDefaultMappingList[item]['HIC_ShopifySync__Shopify_Field_Type__c'];
component.set(objectRequiredFieldListName,objectRequiredFieldList);
}
}
}
},
getEverything : function( component, event ) {
var action = component.get("c.getEverything");
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS" && response.getReturnValue() != null ) {
if(response.getReturnValue()[0] != null && response.getReturnValue()[0] != '' && response.getReturnValue()[0] != 'Null'){
component.set("v.accountsList",JSON.parse(response.getReturnValue()[0]));
}
if(response.getReturnValue()[1] != null && response.getReturnValue()[1] != '' && response.getReturnValue()[1] != 'Null'){
component.set("v.opportunityStageList",JSON.parse(response.getReturnValue()[1]));
}
if(response.getReturnValue()[2] != null && response.getReturnValue()[2] != '' && response.getReturnValue()[2] != 'Null'){
component.set("v.opportunityContactRolesList",JSON.parse(response.getReturnValue()[2]));
}
}
else if (state === "INCOMPLETE") {
console.log('in complete');
}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);
},
createObjectData: function(component, event) {
var Objecttype = event.getParam("Objecttype");
if( Objecttype != null && Objecttype != '' && Objecttype != 'undefined' && Objecttype == 'Contact'){
var contactList = component.get("v.contactList");
contactList.push({
"sobjectType": 'Contact',
"fieldDisabled":false
});
component.set("v.contactList", contactList);
}else if( Objecttype != null && Objecttype != '' && Objecttype != 'undefined' && Objecttype == 'Account'){
var objectInstance = component.get("v.objectInstance");
var accountList = component.get("v.accountList");
accountList.push({
"sobjectType": 'Account',
"fieldDisabled":false
});
component.set("v.accountList", accountList);
}
else if( Objecttype != null && Objecttype != '' && Objecttype != 'undefined' && Objecttype == 'Order'){
var objectInstance = component.get("v.objectInstance");
var orderList = component.get("v.orderList");
orderList.push({
"sobjectType": 'Order',
"fieldDisabled":false
});
component.set("v.orderList", orderList);
}else if( Objecttype != null && Objecttype != '' && Objecttype != 'undefined' && Objecttype == 'OrderItem'){
var objectInstance = component.get("v.objectInstance");
var orderProductList = component.get("v.orderProductList");
orderProductList.push({
"sobjectType": 'OrderItem',
"fieldDisabled":false
});
component.set("v.orderProductList", orderProductList);
}else if( Objecttype != null && Objecttype != '' && Objecttype != 'undefined' && Objecttype == 'DraftOrder'){
var objectInstance = component.get("v.objectInstance");
var draftOrderList = component.get("v.draftOrderList");
draftOrderList.push({
"sobjectType": 'DraftOrder',
"fieldDisabled":false
});
component.set("v.draftOrderList", draftOrderList);
}else if( Objecttype != null && Objecttype != '' && Objecttype != 'undefined' && Objecttype == 'DraftOrderItem'){
var objectInstance = component.get("v.objectInstance");
var draftOrderProductList = component.get("v.draftOrderProductList");
draftOrderProductList.push({
"sobjectType": 'DraftOrderItem',
"fieldDisabled":false
});
component.set("v.draftOrderProductList", draftOrderProductList);
}else if( Objecttype != null && Objecttype != '' && Objecttype != 'undefined' && Objecttype == 'Opportunity'){
var objectInstance = component.get("v.objectInstance");
var opportunityList = component.get("v.opportunityList");
opportunityList.push({
"sobjectType": 'Opportunity',
"fieldDisabled":false
});
component.set("v.opportunityList", opportunityList);
}else if( Objecttype != null && Objecttype != '' && Objecttype != 'undefined' && Objecttype == 'OpportunityLineItem'){
var objectInstance = component.get("v.objectInstance");
var opportunityProductList = component.get("v.opportunityProductList");
opportunityProductList.push({
"sobjectType": 'OpportunityLineItem',
"fieldDisabled":false
});
component.set("v.opportunityProductList", opportunityProductList);
}else if( Objecttype != null && Objecttype != '' && Objecttype != 'undefined' && Objecttype == 'Product2'){
var objectInstance = component.get("v.objectInstance");
var productList = component.get("v.productList");
productList.push({
"sobjectType": 'Product2',
"fieldDisabled":false
});
component.set("v.productList", productList);
}else if( Objecttype != null && Objecttype != '' && Objecttype != 'undefined' && Objecttype == 'HIC_ShopifySync__Variant__c'){
var objectInstance = component.get("v.objectInstance");
var variantList = component.get("v.variantList");
variantList.push({
"sobjectType": 'HIC_ShopifySync__Variant__c',
"fieldDisabled":false
});
component.set("v.variantList", variantList);
}
},
// helper function for check if first Name is not null/blank on save
validateRequired: function(component, event) {
var isValid = true;
var allContactRows = component.get("v.contactList");
for (var indexVar = 0; indexVar < allContactRows.length; indexVar++) {
if (allContactRows[indexVar].FirstName == '') {
isValid = false;
alert('First Name Can\'t be Blank on Row Number ' + (indexVar + 1));
}
}
return isValid;
},
getDefaultAccountForContactsHelper : function( component, event ) {
console.log('store name in ----');
console.log(component.get("v.store"));
var action = component.get("c.getDefaultAccForConts");
action.setParams({
"store" : component.get("v.store")
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS" ) {
var DefaultContactAccountFM = response.getReturnValue();
if(DefaultContactAccountFM != null && DefaultContactAccountFM['HIC_ShopifySync__Shopify_Fields__c'] == 'id'){
component.set("v.Accountexist",true);
}else {
var action2 = component.get("c.getAccountDetails");
action2.setParams({ 'accId' : DefaultContactAccountFM['HIC_ShopifySync__Shopify_Fields__c'] });
action2.setCallback(this, function(response2) {
var state2 = response2.getState();
if (state2 === "SUCCESS" && response2.getReturnValue() != null ) {
component.set("v.SyncAllContactInAccount",DefaultContactAccountFM['HIC_ShopifySync__Default_Value__c']);
if(!component.get("v.configObj.HIC_ShopifySync__Default_Account__c")){
component.set("v.DefaultAccountForContacts",null);
}else{
//console.log('Default Account');
//console.log(response2.getReturnValue());
component.set("v.DefaultAccountForContacts",response2.getReturnValue());
}
// component.set("v.DefaultAccountForContacts",response2.getReturnValue());
component.set("v.Accountexist",true);
//var DefaultContactAccountNameFM = response2.getReturnValue();
var DefaultAccountForContactslist = [];
DefaultAccountForContactslist.push( response2.getReturnValue() );
component.set("v.DefaultAccountForContactslist",DefaultAccountForContactslist);
}
else if (state2 === "INCOMPLETE") {
component.set("v.Accountexist",true);
}
else if (state2 === "ERROR") {
var errors2 = response.getError();
if (errors2) {
if (errors2[0] && errors2[0].message) {
console.log("Error message: " +
errors2[0].message);
}
} else {
console.log("Unknown error");
}
component.set("v.Accountexist",true);
}else if( response2.getReturnValue() == null && state2 === "SUCCESS"){
component.set("v.Accountexist",true);
}
});
$A.enqueueAction(action2);
}
}
else if (state === "INCOMPLETE") {
component.set("v.Accountexist",true);
}
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");
}
component.set("v.Accountexist",true);
}
});
$A.enqueueAction(action);
},
getDefaultOpportunityDefaultDateHelper : function( component, event ) {
console.log('default date block');
var action = component.get("c.getDefaultOppClosedate");
console.log(component.get("v.store"));
action.setParams({
"store" : component.get("v.store")
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS" && response.getReturnValue() != null ) {
var DefaultOppClosedate = response.getReturnValue();
console.log('DefaultOppClosedate-------');
console.log(DefaultOppClosedate);
if(DefaultOppClosedate['HIC_ShopifySync__Default_Value__c'] || DefaultOppClosedate['HIC_ShopifySync__Default_Value__c'] == true ){
component.set("v.today",DefaultOppClosedate['HIC_ShopifySync__Shopify_Fields__c']);
}
}
else if (state === "INCOMPLETE") {
component.set("v.OrderAccountexist",true);
console.log('default date incomplete block');
}
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");
}
component.set("v.OrderAccountexist",true);
}
});
$A.enqueueAction(action);
},
getDefaultOpportunityStageHelper : function( component, event ) {
var action = component.get("c.getDefaultOppStage");
action.setParams({
"store" : component.get("v.store")
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS" && response.getReturnValue() != null && response.getReturnValue() !== undefined ) {
console.log('Default opp stage ---');
console.log(response.getReturnValue());
component.set("v.DefaultOpportunityStage",response.getReturnValue());
if(component.get("v.DefaultOpportunityStage") == '' || component.get("v.DefaultOpportunityStage") == ' ' || component.get("v.DefaultOpportunityStage") == undefined || component.get("v.DefaultOpportunityStage") == null){
component.set("v.DefaultOpportunityStage",'None');
}
} else if(state === "SUCCESS" && response.getReturnValue() == null){
if(component.get("v.DefaultOpportunityStage") == '' || component.get("v.DefaultOpportunityStage") == ' ' || component.get("v.DefaultOpportunityStage") == undefined || component.get("v.DefaultOpportunityStage") == null){
component.set("v.DefaultOpportunityStage",'None');
}
}
else if (state === "INCOMPLETE") {
}
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);
component.set("v.GoDisableButton",false);
component.set("v.PreDisableButton",false);
},
})