Skip to content
This repository has been archived by the owner on Jan 25, 2025. It is now read-only.

Commit

Permalink
Merge pull request #89 from SalesforceFoundation/feature/8493-blank-s…
Browse files Browse the repository at this point in the history
…ettings-page

Cleaning things up. Adding prefix when necessary to view settings. St…
  • Loading branch information
ceiroa committed Nov 3, 2015
2 parents 6d87bb4 + d98ea1d commit 62345d4
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 27 deletions.
56 changes: 47 additions & 9 deletions src/aura/STG_CMP_Affl/STG_CMP_AfflHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,27 @@

loadAfflMappings : function(component) {
var action = component.get("c.getAfflMappings");
action.setCallback(this, function(response) {
component.set("v.afflMappings", response.getReturnValue());
action.setCallback(this, function(response) {
if(response.getState() === "SUCCESS") {
if(namespace_prefix && namespace_prefix.length > 0) {
var settings = response.getReturnValue();
var settings_no_prefix = {};
//Remove package prefix from each custom field
for(var key in settings) {
if(key.endsWith('__c') && namespace_prefix && namespace_prefix.length > 0) {
var key_no_prefix = key.replace(namespace_prefix, '');
settings_no_prefix[key_no_prefix] = settings[key];
} else {
settings_no_prefix[key] = settings[key];
}
}
component.set("v.afflMappings", settings_no_prefix);
} else {
component.set("v.afflMappings", response.getReturnValue());
}
} else if(response.getState() === "ERROR") {
this.displayError(response);
}
});
$A.enqueueAction(action);
},
Expand All @@ -18,17 +37,36 @@

saveAfflSettings : function(component) {
var saveAction = component.get("c.saveAfflMappings");
saveAction.setParams({"afflMappings" : component.get("v.afflMappings")});
saveAction.setCallback(this, function(response) {
if(response.getState() === "ERROR") {
var errors = response.getError();
if (errors && errors[0] && errors[0].message) {
$A.error("Error message: " + errors[0].message);
var settings = component.get("v.afflMappings");
if(namespace_prefix && namespace_prefix.length > 0) {
var settings_w_prefix = {};
//Add package prefix to each custom field
for(var key in settings) {
if(key.endsWith('__c')) {
var key_w_prefix = namespace_prefix + key;
settings_w_prefix[key_w_prefix] = settings[key];
} else {
$A.error("Unknown error");
settings_w_prefix[key] = settings[key];
}
}
saveAction.setParams({"afflMappings" : settings_w_prefix});
} else {
saveAction.setParams({"afflMappings" : settings});
}
saveAction.setCallback(this, function(response) {
if(response.getState() === "ERROR") {
this.displayError(response);
}
});
$A.enqueueAction(saveAction);
},

displayError : function(response) {
var errors = response.getError();
if (errors && errors[0] && errors[0].message) {
$A.error("Error message: " + errors[0].message);
} else {
$A.error("Unknown error");
}
}
})
4 changes: 0 additions & 4 deletions src/aura/STG_CMP_Header/STG_CMP_HeaderController.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
({
init : function(component, event, helper) {
component.set("v.isView", true);
//var namespace_prefix = document.getElementById("namespace_prefix").value;
var namespace_prefix = component.get("v.namespace_prefix");
console.log("Namespace read in Header component: " + namespace_prefix);
//component.set("v.namespace_prefix", namespace_prefix);
},

edit : function(component, event, helper) {
Expand Down
52 changes: 48 additions & 4 deletions src/aura/STG_CMP_Rel/STG_CMP_RelHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,64 @@

loadReciprocalSettings : function(component, event, helper) {
var reciprocalSettingsAction = component.get("c.getReciprocalSettings");
reciprocalSettingsAction.setCallback(this, function(data) {
component.set("v.reciprocalSettings", data.getReturnValue());
reciprocalSettingsAction.setCallback(this, function(response) {
if(response.getState() === "SUCCESS") {
if(namespace_prefix && namespace_prefix.length > 0) {
component.set("v.reciprocalSettings", this.removePrefix(response.getReturnValue()));
} else {
component.set("v.reciprocalSettings", response.getReturnValue());
}
} else if(response.getState() === "ERROR") {
this.displayError(response);
}
});
$A.enqueueAction(reciprocalSettingsAction);
},

loadRelAutoCreateSettings : function(component) {
var autoCreateSettingsAction = component.get("c.getAutoCreateSettings");
autoCreateSettingsAction.setCallback(this, function(data) {
component.set("v.autoCreateSettings", data.getReturnValue());
autoCreateSettingsAction.setCallback(this, function(response) {
if(response.getState() === "SUCCESS") {
if(namespace_prefix && namespace_prefix.length > 0) {
component.set("v.autoCreateSettings", this.removePrefix(response.getReturnValue()));
} else {
component.set("v.autoCreateSettings", response.getReturnValue());
}
} else if(response.getState() === "ERROR") {
this.displayError(response);
}
});
$A.enqueueAction(autoCreateSettingsAction);
},

removePrefix : function(settings) {
var settings_no_prefix = {};
//Remove package prefix from each custom field
for(var key in settings) {
if(key.endsWith('__c')) {
var key_no_prefix = key.replace(namespace_prefix, '');
settings_no_prefix[key_no_prefix] = settings[key];
} else {
settings_no_prefix[key] = settings[key];
}
}
return settings_no_prefix;
},

addPrefix : function(settings) {
var settings_w_prefix = {};
//Add package prefix to each custom field
for(var key in settings) {
if(key.endsWith('__c')) {
var key_w_prefix = namespace_prefix + key;
settings_w_prefix[key_w_prefix] = settings[key];
} else {
settings_w_prefix[key] = settings[key];
}
}
return settings_w_prefix;
},

settsLinkClicked : function(component) {
$A.util.addClass(component.find("settsTab"), "slds-active");
$A.util.removeClass(component.find("recSettsTab"), "slds-active");
Expand Down
4 changes: 0 additions & 4 deletions src/aura/STG_CMP_Tabs/STG_CMP_TabsController.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
({
init : function(component, event, helper) {
helper.init(component);
//var namespace_prefix = document.getElementById("namespace_prefix").value;
var namespace_prefix = component.get("v.namespace_prefix");
console.log("Namespace read in Tabs component: " + namespace_prefix);
//component.set("v.namespace_prefix", namespace_prefix);
},

saveSettings : function(component, event, helper) {
Expand Down
1 change: 0 additions & 1 deletion src/aura/STG_CMP_Tabs/STG_CMP_TabsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
for(var key in settings) {
if(key.endsWith('__c')) {
var key_no_prefix = key.replace(namespace_prefix, '');
console.log('Repacing ' + key + ' with ' + key_no_prefix);
settings_no_prefix[key_no_prefix] = settings[key];
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/pages/STG_Settings.page
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
<div id="tabSettings"></div>
<br/>

<!-- <div id="namespace_prefix" style="display: none;"></div> -->

</div>

<script>
Expand All @@ -36,9 +34,6 @@
}

$Lightning.use(namespace + ":STG_App", function() {
/*$Lightning.createComponent("aura:text", { value: namespace_prefix }, "namespace_prefix", function(auraTextComponent, status, statusMessagesList) {
console.log("Namespace in Settings page: " + namespace_prefix);
});*/
loadComponents(namespace_prefix);
});

Expand Down

0 comments on commit 62345d4

Please sign in to comment.