I'm trying to use client settings in Alchemy to enable/disable some command (RibbonToolbarExtension), but I don't know how can I use the "getSettings" service, because is an asynchronous service, that provides the value with a promise, but the isEnabled function gets executed before the promise is returned.
The code we are using is something like:
isEnabled: function (selection) {
// see configuration to decide
var p = selection.properties;
Alchemy.Plugins["${PluginName}"].Api.getSettings()
.success(function (settings) {
//alert("settings are: " + JSON.stringify(settings));
console.log(settings);
for (var i = 0; i < settings.AllowedPublications.length; i++) {
var idPub = settings.AllowedPublications[i].IdPub;
if (p.parentItemUri == "tcm:0-" + idPub + "-1") {
// true when the publication is configured
return true;
}
}
}).error(function () {
console.log("error reading settings");
});
return false;
},
I am not able to use the returned value "true" of the settings logic, before the isenabled "return false" is executed.
Is there any example of using client settings to enable/disable commands in Alchemy?
console.log(settings);
, Is it null ? Also Could you put thealert(settings.AllowedPublications.length);
just before the for loop, Just to make sure it returns the allowed publications.