« [Tip] Trapping for incorrectly entered dates | Main | [Tip] Choosing one record from a list »
December 25, 2005
[Tip] Dynamic buttons management
by Riccardo Albieri
Morninger Soluzioni
Sometimes, you may find yourself in the need of building a reusable buttons management system: Servoy's toolbox provides you various ways to accomplish this task.
My current favourite one is placing a relationless tab (containing all the buttons of the solution you normally place in the header) and a couple of methods that hide and show the buttons depending on the form you're moving in. One of my most welcome new features is the ability to retrieve all the elements name of a form and place them in an array: this way becomes very easy to enable (or disable) all the elements at once. After placing the buttons in the form to be shown in the relationless tab (remember to fill in the name property), create a form method named hideShow, that will take care of setting up the group of button chosen for the current form. The code is something like:
var buttonsOff = arguments[0]
var buttonsOn = arguments[1]
var buttonsAll = elements.allnames
if (buttonsOff[0] == "all")
{
for ( var i = 0 ; i < buttonsAll.length; i++ )
{
var theButton = buttonsAll[i]
elements[theButton].visible = false
}
for ( var i = 0 ; i < buttonsOn.length; i++ )
{
var theButton = buttonsOn[i]
elements[theButton].visible = true
}
}
else if (buttonsOn[0] == "all")
{
for ( var i = 0 ; i < buttonsAll.length; i++ )
{
var theButton = buttonsAll[i]
elements[theButton].visible = true
}
for ( var i = 0 ; i < buttonsOff.length; i++ )
{
var theButton = buttonsOff[i]
elements[theButton].visible = false
}
}
else
{
for ( var i = 0 ; i < buttonsOff.length; i++ )
{
var theButton = buttonsOff[i]
elements[theButton].visible = false
}
for ( var i = 0 ; i < buttonsOn.length; i++ )
{
var theButton = buttonsOn[i]
elements[theButton].visible = true
}
}
As you can see, two parameters are passed to the method: they indicate the buttons to hide (var buttonsOff) and the buttons to show (var buttonsOn). In certain situations, you may find more agile to programmatically hide all the buttons and then to show only the desired set: in this case, you can skip the last loop.
To call this function from a navigation method, all you have to do is add these instructions:
var toHide = new Array('all')
var toShow = new Array('nav_bar','btn_new','lbl_new'); //names of the object to show
forms.buttons.hideShow(toHide, toShow);
Here you are: you can place all the buttons of the solution into a single form, making them appear when moving from a form to another. This way you'll have more spare time for your Christmas shopping.
Buon natale, Ric.
| Posted by Riccardo Albieri on December 25, 2005 at 01:23 PM in Tips | Permalink
