Dans cet article
Extensions settings allow to customize the Extension, for example:
- Setting for the printing.
- Header of a report that are set once only.
Function settingsDialog()
If you provide customization you should add a function settingDialog().
This function will called:
- When the user click on the Set Parameters on the Manage Extensions dialog.
- For Import extension in the Dialog Import > Button Settings.
- For Report extensions in the Printing Dialog > Button Settings.
Take care that:
- The extension is responsible to manage to load and save the settings.
- Return value.
- null if the user ha clicked on cancel button.
- any other value if the user has changed the settings.
A simple and powerful way to let the user customize the setting is by using the:
Saving the settings
The function settingDialog() should:
- Read the existing setting with the Banana.document.getScriptSettings();
- Request user to enter the information
- Set the modified values with the function Banana.document.setScriptSettings(paramToString);
The JSon text will be saved within the accounting file.
function settingsDialog() {
var param = initParam();
var savedParam = Banana.document.getScriptSettings();
if (savedParam.length > 0) {
param = JSON.parse(savedParam);
}
param = verifyParam(param);
param.isr_bank_name = Banana.Ui.getText('Settings', texts.param_isr_bank_name, param.isr_bank_name);
if (param.isr_bank_name === undefined)
return;
var paramToString = JSON.stringify(param);
Banana.document.setScriptSettings(paramToString);
}
Reading the settings
the function Exec() or any other function should then read the settings using the Banana.document.getScriptSettings().
Before using the setting you should check that they are valid and possibly provide a function that verify and eventually update the settings.
function printDocument(jsonInvoice, repDocObj, repStyleObj) {
var param = initParam();
var savedParam = Banana.document.getScriptSettings();
if (savedParam.length > 0) {
param = JSON.parse(savedParam);
param = verifyParam(param);
}
printInvoice(jsonInvoice, repDocObj, repStyleObj, param);
}
Sharing the setting with other extensions
The function Banana.document.setScriptSettings(paramToString); will save the setting in the accounting file under the Id of the extension.
If you need to share the settings with other extensions, like in case of a series of packaged extensions you should use the Banana.document.setScriptSettings((id, value).
And to read the setting use Banana.document.getScriptSettings((id).
For more information siee Banana.document.
Example:
// Save script settings
var paramString = JSON.stringify(param);
var value = Banana.document.setScriptSettings('ch.banana.vat', paramString);