In questo articolo
This class Banana.Ui contains methods to interact with user interface.
Methods
createUi(uiFilePath)
Read the file uiFilepath and return an object representing the dialog. The uiFileName has to be in the same directory as the running script. You can also load a ui file from the table documents with the prefix 'documents:', ex.: 'documents:calculator.ui', For details and examples see Script dialogs or the tutorial JavaScript Tutorial 1.
Every widget defined in the ui file is exposed to the script environment and you can interact with them like in c++ code. You find further details under Banana.Ui.Widget.
If an error occurred undefined is returned.
Example:
@includejs = ch.banana.calculator.dialog.js; // Define the class Calculator // that control the .ui file ... var calculatorUi = Banana.Ui.createUi("ch.banana.calculator.dialog.ui"); var calcJs = new Calculator(calculatorUi); calclatorUi.exec(); //Show the dialog
getDouble(title, label [, value , min, max, decimals])
Show the user a dialog asking to insert a double. Return the inserted double or undefined if the user clicked cancel.
var a = Banana.Ui.getDouble("Title text", "Label text"); var b = Banana.Ui.getDouble("Title text", "Label text", "10.0");
getInt(title, label [, value, min, max, steps])
Show the user a dialog asking to insert an integer. Return the inserted integer or undefined if the user clicked cancel.
var a = Banana.Ui.getInt("Title text", "Label text"); var b = Banana.Ui.getInt("Title text", "Label text", "5", "1", "10","1");
getItem(title, label, items [, current, editable])
Show the user a combo box dialog asking to select an item from a list. Return the selected item or undefined if the user clicked cancel.
var value = Banana.Ui.getItem("Input", "Choose a value", ["a","b","c","d","e"], 2, false);
getItems(title, label, items [, selectedItems])
Show the user a list dialog asking to select one or more items from a list. Return the selected items or undefined if the user clicked cancel.
var value = Banana.Ui.getItems("Input", "Choose one or more values", ["a","b","c","d","e"], ["b","c"]);
Since: Banana Experimental 9.1.0
getPeriod(title, startDate, endDate [, selectionStartDate, selectionEndDate, selectionChecked])
Show the user a dialog asking to select a period like the tab Period. Return an object with the atributes 'startDate', 'endDate' and 'hasSelection' or undefined if the user clicked cancel. Date values are in the format "YYYY-MM-DD".
var period = Banana.Ui.getPeriod("Title text", "2016-01-01", "2016-12-31"); if (period) { var selectedStartDate = period.startDate; // return the start date of the selected period var selectedEndDate = period.endDate; // return the end date of the selected period }
getText(title, label [, text])
Show the user a dialog asking to insert a text. Return the inserted text or undefined if the user clicked cancel.
var text = Banana.Ui.getText("Title text","Label text");
openPropertyEditor(title, params, [dialogId])
Show the user a dialog asking to set given params. Return the modified params or undefined if the user clicked cancel.
Invoice Apps contains examples with this method (https://www.banana.ch/doc9/en/node/8381)
Param properties:
- name: param's key (unique id)
- title: param's title, which appears in the left column "property"
- parentObject (optional): parent's name if you define children
- type (optional): string, multilinestring, bool (default: string). if boolean a checkbox will appear, if multilinestring a textarea will appear
- value: the value, which appears in the right column "value". For type bool: true/false, for type string and multilinestring a text
- defaultvalue (optional): value used by Restore Defaults button. If the param has this property the button Restore Defaults will be available.
- collapse (optional): true/false. By default the dialog expand all items. If collapse is true the item will not be expanded.
- enabled (optional): true/false. If false the value will appears grey and the user cannot change the value (default: true)
- editable (optional): true/false. If false the user cannot change the value, available only for string and multilinestring types (default: true)
- tooltip (optional): text which appears over the item without clicking on the item
- errorId (optional): error id that identify an error. The error id is used to link the error to the corresponding help page
- errorMsg (optional): error string that describe an error. If a parameter has this property set, the label will be show in red and the error showed on the right of the name
var paramList = {}; paramList.version = '1.0'; paramList.data = []; var param = {}; param.name = 'print_header'; param.title = 'print header'; //type: bool, string, number param.type = 'bool'; param.value = true; param.readValue = function() { param.print_header = this.value; } paramList.data.push(param); var dialogTitle = 'Settings'; var pageAnchor = 'dlgSettings'; Banana.Ui.openPropertyEditor(dialogTitle, paramList, pageAnchor)) for (var i = 0; i < paramList.data.length; i++) { // Read values to param (through the readValue function) paramList.data[i].readValue(); }
showHelp(uiFileName)
Show the help of a dialog. The help is loaded from the Banana.ch web site.
showInformation(title, msg)
Show the user an information dialog.
Banana.Ui.showInformation("Information", 'Insert here the text of the information.');
showQuestion(title, question)
Show the user a question dialog with Yes and No buttons. Return true if the user clicked Yes, otherwise false.
var answer = Banana.Ui.showQuestion("Question title", "Insert here the text of the question");
showText(text)
Show the given text in a dialog. The text can be plain text of html and span over multiple lines. If the text is in html the title is taken form the html. The dialog enables the user to save the content in the formats html, pdf, odf and txt.
The use of pixels to set the font sizes is not supported, the text is not rendered properly.
// Normal text Banana.Ui.showText("Insert here the text."); // Html text Banana.Ui.showText('<html><header><title>This is title</title></header><body>Hello world</body></html>');
showText(title, text)
This is an overloaded function.
Show the given text in a dialog with the given title. The text can be plain text of html and span over multiple lines. The dialog enables the user to save the content in the formats html, pdf, odf and txt.
showText(title, text, options)
This is an overloaded function.
Show the given text in a dialog with the given title. The text can be plain text of html and span over multiple lines. The dialog enables the user to save the content in the formats html, pdf, odf and txt.
Through the object options it is possible to set the following additional parameters:
- codecName: the name of the codec to be used in case the content will be saved as txt file. Default is 'UTF-8'
- outputFileName: the file name without path to be used in case the content will be saved. The path is current open document path or the user's document path.
var options = { 'codecName' : "latin1", // Default is UTF-8 'outputFileName' : "prova.txt" } Banana.Ui.showText("Title", "some text...", options);