Hi Everyone,
I am busy generating a script that reads the assigned models from a function object. I then have to sort the assigned models manually, to get the sequence in the report in the correct order.
I have created a Dialog, with arrows next to a ListBox. I want to change the sequence in the ListBox by selecting a value and then clicking either the up or down button.
My code to this point:
var nuserdlg = 0;
var userdialog = Dialogs.createNewDialogTemplate(0, 0, 680, 320, "Output sequence");
userdialog.Text(10, 10, 460, 15, "Select the output sequence.");
userdialog.Text(10, 25, 460, 15, "Click on \'OK\' to finish the selection.");
userdialog.OptionGroup("Options");
userdialog.OptionButton(20, 55, 360, 15, "Sort alphabetically", "Opt1");
userdialog.OptionButton(20, 70, 360, 15, "Sort manually", "Opt2");
userdialog.ListBox(20, 90, 586, 220, modNames, "list");
userdialog.PushButton(610, 90, 25, 25, "<SYMBOL_ARROWUP>", "MoveUp");
userdialog.PushButton(610, 280, 25, 25, "<SYMBOL_ARROWDN>", "MoveDwn");
userdialog.OKButton();
userdialog.CancelButton();
var dlg = Dialogs.createUserDialog(userdialog);
nuserdlg = Dialogs.show(dlg);
var test = dlg.getDlgSelection("list");
this.MoveUp_pressed = function()
Does anyone have any code on how to change the sequence when clicking on the MoveUp button?
Thanks,
Willem
var nLocale = Context.getSelectedLanguage(); //get the current locale var selModelList = ArisData.getSelectedModels(); //get the list of selected models var modNames = []; //an array for model names as strings selModelList.forEach(function(value){ //for each of the selected models modNames.push(value.Name(nLocale)); //put the name of the individual model in the list of model names as strings }); function myDialog(){ //function for a new dialog this.getPages = function(){ //describes how the dialog is supposed to be built var userdialog = Dialogs.createNewDialogTemplate(0, 0, 680, 320, "Output sequence"); //stole this from your question... userdialog.Text(10, 10, 460, 15, "Select the output sequence."); userdialog.Text(10, 25, 460, 15, "Click on \'OK\' to finish the selection."); userdialog.OptionGroup("Options"); userdialog.OptionButton(20, 55, 360, 15, "Sort alphabetically", "Opt1"); userdialog.OptionButton(20, 70, 360, 15, "Sort manually", "Opt2"); userdialog.ListBox(20, 90, 586, 220, modNames, "list"); userdialog.PushButton(610, 90, 25, 25, "<SYMBOL_ARROWUP>", "MoveUp"); userdialog.PushButton(610, 280, 25, 25, "<SYMBOL_ARROWDN>", "MoveDwn"); userdialog.OKButton(); userdialog.CancelButton(); //till here return [userdialog]; //return the single dialog template template } this.MoveUp_pressed = function(){ //the function that describes what the MoveUp button does var listBoxObject = this.dialog.getDialogElement("list"); //get the dialog element list (it's needed multiple times, don't want to call this.dialog.getDialogElement("list") again and again var futureOrder = listBoxObject.getItems(); //get the array of strings that currently populate the ListBox var currSelectionIndex = listBoxObject.getSelectedIndex(); //get the index of the currently selected element in the ListBox if(currSelectionIndex != 0){ //if the current selected element is not the topmost (wouldn't be able to move that) this.dialog.getDialogElement("Options").setSelection(1); //set the correct OptionButton (radio Button). I think this is just convenient. var tempSave = futureOrder[currSelectionIndex]; //save the string value of the current selection to a temp variable futureOrder[currSelectionIndex] = futureOrder[(currSelectionIndex-1)]; //make the text in the current selection the text that stood originally above the selected element futureOrder[(currSelectionIndex-1)] = tempSave; //make the text above the selection display the text of the original selection listBoxObject.setItems(futureOrder); //the array element order was changed sucessfully, now put it back into the dialog listBoxObject.setSelection((currSelectionIndex-1)) //move the selection one element up, allowing the user to click the button again and again to move the same element upwards } } this.getResult = function(){ //function that describes what should be returned return this.dialog.getDialogElement("list").getItems(); //return the current list of sting elements of the ListBox } } var result = Dialogs.showDialog(new myDialog(), Constants.DIALOG_TYPE_ACTION, "Output sequence"); //show the previously described dialog as a single-page-dialog
Code is commented, should describe the functionality.
I brought your dialog into the shape described in the ARIS script help (bundle all the methods of the dialog into a single method and use a single Dialogs.showDialog(...) method to display the dialog).
Edit: corrected small mistake in the code comments