aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngelo Naselli <anaselli@linux.it>2014-06-25 17:24:33 +0200
committerAngelo Naselli <anaselli@linux.it>2014-06-25 17:24:33 +0200
commitb78632292cdea8259bc6493e6cfa5a5326c22d60 (patch)
tree60d56977d47cc7abeadb1796cad9dd1a04aac5d1
parentdb29547aacdb5d3899affe022c3f351a04a790a6 (diff)
downloadmanatools-b78632292cdea8259bc6493e6cfa5a5326c22d60.tar
manatools-b78632292cdea8259bc6493e6cfa5a5326c22d60.tar.gz
manatools-b78632292cdea8259bc6493e6cfa5a5326c22d60.tar.bz2
manatools-b78632292cdea8259bc6493e6cfa5a5326c22d60.tar.xz
manatools-b78632292cdea8259bc6493e6cfa5a5326c22d60.zip
added arrayListToYItemCollection and managed default item into
ask_fromList
-rw-r--r--lib/AdminPanel/Shared/GUI.pm58
-rw-r--r--t/03-Shared_GUI.t8
2 files changed, 56 insertions, 10 deletions
diff --git a/lib/AdminPanel/Shared/GUI.pm b/lib/AdminPanel/Shared/GUI.pm
index 7108bece..6d552ea7 100644
--- a/lib/AdminPanel/Shared/GUI.pm
+++ b/lib/AdminPanel/Shared/GUI.pm
@@ -326,6 +326,50 @@ sub ask_YesOrNo {
}
+#=============================================================
+
+=head2 arrayListToYItemCollection
+
+=head3 INPUT
+
+ $listInfo: HASH reference containing
+ default_item => Selected item (if any)
+ itemList => ARRAY reference containing the item list
+
+=head3 OUTPUT
+
+ $itemList: YItemCollection containing the item list passed
+
+=head3 DESCRIPTION
+
+ This method returns a YItemCollection containing the item list passed with default item
+ the "default_item"
+
+=cut
+
+#=============================================================
+
+sub arrayListToYItemCollection {
+ my ($self, $listInfo) = @_;
+
+ die "Item list is mandatory" if !($listInfo->{itemList});
+ # TODO check type
+ die "Not empty item list is mandatory" if (scalar @{$listInfo->{itemList}} < 1);
+
+
+ my $itemColl = new yui::YItemCollection;
+ foreach (@{$listInfo->{itemList}}) {
+ my $item = new yui::YItem ($_, 0);
+ $itemColl->push($item);
+ $item->DISOWN();
+ if ($listInfo->{default_item} && $listInfo->{default_item} eq $item->label()) {
+ $item->setSelected(1);
+ }
+ }
+
+ return $itemColl;
+}
+
#=============================================================
@@ -336,6 +380,7 @@ sub ask_YesOrNo {
$info: HASH, information to be passed to the dialog.
title => dialog title
header => combobox header
+ default_item => selected item if any
list => item list
default_button => (optional) 1: Select (any other values Cancel)
@@ -375,12 +420,11 @@ sub ask_fromList {
my $layout = $factory->createVBox($dlg);
my $combo = $factory->createComboBox($layout, $info->{header}, 0);
- my $itemColl = new yui::YItemCollection;
- foreach (@$list) {
- my $item = new yui::YItem ($_, 0);
- $itemColl->push($item);
- $item->DISOWN();
- }
+
+ my $listInfo;
+ $listInfo->{default_item} = $info->{default_item} if $info->{default_item};
+ $listInfo->{itemList} = $info->{list};
+ my $itemColl = $self->arrayListToYItemCollection($listInfo);
$combo->addItems($itemColl);
my $align = $factory->createRight($layout);
@@ -637,7 +681,7 @@ sub ask_fromTreeList {
yui::YUI::app()->setApplicationTitle($info->{title});
my $minWidth = 80;
my $minHeight = 25;
-
+
if (exists $info->{min_size}) {
$minWidth = $info->{min_size}->{width} if $info->{min_size}->{width};
$minHeight = $info->{min_size}->{height} if $info->{min_size}->{height};
diff --git a/t/03-Shared_GUI.t b/t/03-Shared_GUI.t
index 01a5772d..65777983 100644
--- a/t/03-Shared_GUI.t
+++ b/t/03-Shared_GUI.t
@@ -37,12 +37,14 @@ BEGIN {
diag "ask_YesOrNo got: < " . ($btn == 1 ? "Yes": "No"). " >";
#TODO cancel makes this test failing
- ok(my $item = $gui->ask_fromList({title => "Choose from list", header => "Which one do you select?", default_button => 1,
- list => ['item 1', 'item 2', 'item 3', 'item 4']}), 'ask_fromList');
+ ok(my $item = $gui->ask_fromList({title => "Choose from list", header => "Which one do you select? [default is item 3]", default_button => 1,
+ list => ['item 1', 'item 2', 'item 3', 'item 4'],
+ default_item => 'item 3'
+ }), 'ask_fromList');
diag "ask_fromList got: < " . ($item ? $item : "none") . " >";
#TODO cancel makes this test failing
- ok($item = $gui->ask_fromTreeList({title => "Choose from list", header => "Which one do you select?", default_button => 1,
+ ok($item = $gui->ask_fromTreeList({title => "Choose from list", header => "Which one do you select? [default is leaf 2]", default_button => 1,
default_item => 'leaf 2',
list => ['item 1/item 2/item 3', 'item 1/item 2/leaf 1', 'item 1/item 2/leaf 2', 'item 4/leaf 3', 'item 5']}),
'ask_fromTreeList');