diff options
| author | Matteo Pasotti <matteo.pasotti@gmail.com> | 2014-01-26 12:35:06 +0100 |
|---|---|---|
| committer | Matteo Pasotti <matteo.pasotti@gmail.com> | 2014-01-26 12:35:06 +0100 |
| commit | 267ce4f56d85f1fd618d9c03daa0f3e0514dd8c6 (patch) | |
| tree | 49bb28a50b1b759bf10cc98acb111bd912f3d87c /AdminPanel/Shared.pm | |
| parent | e320a003f4d87921272c67d89acddd33c2602b0d (diff) | |
| parent | fec5ef4ddfa4a2772c6bd96f6b72b88a7c0bf57d (diff) | |
| download | colin-keep-267ce4f56d85f1fd618d9c03daa0f3e0514dd8c6.tar colin-keep-267ce4f56d85f1fd618d9c03daa0f3e0514dd8c6.tar.gz colin-keep-267ce4f56d85f1fd618d9c03daa0f3e0514dd8c6.tar.bz2 colin-keep-267ce4f56d85f1fd618d9c03daa0f3e0514dd8c6.tar.xz colin-keep-267ce4f56d85f1fd618d9c03daa0f3e0514dd8c6.zip | |
Merge branch 'master' of ssh://git.mageia.org/software/adminpanel
Diffstat (limited to 'AdminPanel/Shared.pm')
| -rw-r--r-- | AdminPanel/Shared.pm | 113 |
1 files changed, 103 insertions, 10 deletions
diff --git a/AdminPanel/Shared.pm b/AdminPanel/Shared.pm index 5d052e0..583b214 100644 --- a/AdminPanel/Shared.pm +++ b/AdminPanel/Shared.pm @@ -85,14 +85,17 @@ use yui; use base qw(Exporter); # TODO move GUI dialogs to Shared::GUI -our @EXPORT = qw(warningMsgBox - msgBox - infoMsgBox - ask_YesOrNo - ask_OkCancel - AboutDialog - trim - member); +our @EXPORT = qw( + warningMsgBox + msgBox + infoMsgBox + ask_YesOrNo + ask_OkCancel + ask_fromList + AboutDialog + trim + member +); =head1 VERSION @@ -284,8 +287,8 @@ sub ask_OkCancel { =head3 DESCRIPTION -This function create a Yes-No dialog with a 'title' and a question 'text' -passed as parameters. +This function create a Yes-No dialog with a 'title' and a +question 'text' passed as parameters. =cut @@ -325,6 +328,96 @@ sub ask_YesOrNo { return $retVal; } + +#============================================================= + +=head2 ask_fromList + +=head3 INPUT + + $title: dialog title + $text: combobox heading + $list: item list + +=head3 OUTPUT + + undef: if Cancel button has been pressed + selected item: if Ok button has been pressed + +=head3 DESCRIPTION + +This function create a dialog with a combobox in which to +choose an item from a given list. + +=cut + +#============================================================= + +sub ask_fromList { + my ($title, $text, $list) = @_; + + die "Title is mandatory" if (! $title); + die "Heading is mandatory" if (! $text); + die "List is mandatory" if (! $list ); + die "At least one element is mandatory into list" if (scalar(@$list) < 1); + + my $choice = undef; + my $factory = yui::YUI::widgetFactory; + + ## push application title + my $appTitle = yui::YUI::app()->applicationTitle(); + ## set new title to get it in dialog + yui::YUI::app()->setApplicationTitle($title); + + my $dlg = $factory->createPopupDialog($yui::YDialogNormalColor); + my $layout = $factory->createVBox($dlg); + + my $combo = $factory->createComboBox($layout, $text, 0); + my $itemColl = new yui::YItemCollection; + foreach (@$list) { + my $item = new yui::YItem ($_, 0); + $itemColl->push($item); + $item->DISOWN(); + } + $combo->addItems($itemColl); + + my $align = $factory->createRight($layout); + my $hbox = $factory->createHBox($align); + my $okButton = $factory->createPushButton($hbox, N("Ok")); + my $cancelButton = $factory->createPushButton($hbox, N("Cancel")); + + while (1) { + my $event = $dlg->waitForEvent(); + + my $eventType = $event->eventType(); + #event type checking + if ($eventType == $yui::YEvent::CancelEvent) { + last; + } + elsif ($eventType == $yui::YEvent::WidgetEvent) { + # widget selected + my $widget = $event->widget(); + + if ($widget == $cancelButton) { + last; + } + elsif ($widget == $okButton) { + my $item = $combo->selectedItem(); + $choice = $item->label() if ($item); + last; + } + } + } + + destroy $dlg; + + #restore old application title + yui::YUI::app()->setApplicationTitle($appTitle); + + return $choice; +} + + #============================================================= =head2 AboutDialog |
