diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index df29dc191..9bc5f7475 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -44,6 +44,7 @@ - Converted WebGUI to use a new object oriented session system. More details in migation.txt. - Added a sort alphabetically option to the folder asset. + - Added a User form field type. - Added a symbol next to items in the asset manager to indicate if they have children or not. - Added more templating options to the Paginator thanks to Jukka Raimovaara. diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 48c02a6bb..56388ca79 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -221,7 +221,7 @@ sub definition { defaultValue=>'7' }, ownerUserId=>{ - fieldType=>'selectBox', + fieldType=>'user', defaultValue=>'3' }, status=>{ @@ -605,22 +605,11 @@ sub getEditForm { } else { $subtext = ""; } - my $clause; - if ($self->session->user->isInGroup(3)) { - my $group = WebGUI::Group->new($self->session,4); - my $contentManagers = $group->getAllUsers(); - push (@$contentManagers, $self->session->user->userId); - $clause = "userId in (".$self->session->db->quoteAndJoin($contentManagers).")"; - } else { - $clause = "userId=".$self->session->db->quote($self->get("ownerUserId")); - } - my $users = $self->session->db->buildHashRef("select userId,username from users where $clause order by username"); - $tabform->getTab("security")->selectBox( + $tabform->getTab("security")->user( -name=>"ownerUserId", - -options=>$users, -label=>$i18n->get(108), -hoverHelp=>$i18n->get('108 description'), - -value=>[$self->get("ownerUserId")], + -value=>$self->get("ownerUserId"), -subtext=>$subtext, -uiLevel=>6 ); diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index 6ad95012c..f8c50911e 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -576,8 +576,7 @@ sub www_editListing { -label=>$i18n->get('description'), ); if ($self->canEdit) { - $f->selectBox( - options=>$self->session->db->buildHashRef("select userId,username from users order by username"), + $f->user( name=>"maintainerId", value=>$listing->{maintainerId}, label=>$i18n->get('listing maintainer'), diff --git a/lib/WebGUI/Form/User.pm b/lib/WebGUI/Form/User.pm new file mode 100644 index 000000000..bea142cbd --- /dev/null +++ b/lib/WebGUI/Form/User.pm @@ -0,0 +1,111 @@ +package WebGUI::Form::User; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2006 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use base 'WebGUI::Form::Control'; +use WebGUI::User; +use WebGUI::Form::Button; +use WebGUI::Form::Hidden; +use WebGUI::Form::Text; + +=head1 NAME + +Package WebGUI::Form::User + +=head1 DESCRIPTION + +Creates a user selector field. + +=head1 SEE ALSO + +This is a subclass of WebGUI::Form::Control. + +=head1 METHODS + +The following methods are specifically available from this class. Check the superclass for additional methods. + +=cut + +#------------------------------------------------------------------- + +=head2 definition ( [ additionalTerms ] ) + +See the super class for additional details. + +=head3 additionalTerms + +The following additional parameters have been added via this sub class. + +=head4 name + +The name of the field. Defaults to "userId". + +=head4 label + +Defaults to "User". + +=cut + +sub definition { + my $class = shift; + my $session = shift; + my $definition = shift || []; + my $i18n = WebGUI::International->new($session, "WebGUI"); + push(@{$definition}, { + formName=>{ + defaultValue=>$i18n->get("user"), + }, + label=>{ + defaultValue=>$i18n->get("user"), + }, + name=>{ + defaultValue=>"userId", + }, + }); + return $class->SUPER::definition($session, $definition); +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a user selector. + +=cut + +sub toHtml { + my $self = shift; + my $user = WebGUI::User->new($self->session, $self->get("value")); + return WebGUI::Form::Hidden->new($self->session, + name=>$self->get("name"), + extras=>$self->get("extras"), + value=>$user->userId, + id=>$self->get("id"), + )->toHtml + .WebGUI::Form::Text->new($self->session, + name=>$self->get("name")."_display", + extras=>' readonly="1" ', + value=>$user->username, + id=>$self->get('id')."_display" + )->toHtml + .WebGUI::Form::Button->new($self->session, + value=>"...", + extras=>'onclick="window.open(\''.$self->session->url->page("op=formUsers;formId=".$self->get('id')).'\',\'userPicker\',\'toolbar=no, location=no, status=no, directories=no, width=400, height=400\');"' + )->toHtml; +} + +1; + diff --git a/lib/WebGUI/Operation.pm b/lib/WebGUI/Operation.pm index 14924f26e..ffc5f32c0 100644 --- a/lib/WebGUI/Operation.pm +++ b/lib/WebGUI/Operation.pm @@ -265,6 +265,7 @@ sub getOperations { 'editUserSave' => 'WebGUI::Operation::User', 'editUserKarma' => 'WebGUI::Operation::User', 'editUserKarmaSave' => 'WebGUI::Operation::User', + 'formUsers' => 'WebGUI::Operation::User', 'listUsers' => 'WebGUI::Operation::User', 'approveVersionTag' => 'WebGUI::Operation::VersionTag', diff --git a/lib/WebGUI/Operation/User.pm b/lib/WebGUI/Operation/User.pm index 3b1ae0eaa..063da60b0 100644 --- a/lib/WebGUI/Operation/User.pm +++ b/lib/WebGUI/Operation/User.pm @@ -143,7 +143,9 @@ sub doUserSearch { } } -=head2 doUserSearchForm ( $session, $op, $params ) +#------------------------------------------------------------------- + +=head2 doUserSearchForm ( session, op, params, noStatus ) Form front-end and display for searching for users. @@ -155,13 +157,17 @@ The name of the calling operation, passed so that pagination links work correctl Hashref. A set of key,value pairs that will be hidden in the user search form. +=head3 noStatus + +Don't display the status filter. + =cut -#------------------------------------------------------------------- sub getUserSearchForm { my $session = shift; my $op = shift; my $params = shift; + my $noStatus = shift; $session->scratch->set("userSearchKeyword",$session->form->process("keyword")); $session->scratch->set("userSearchStatus",$session->form->process("status")); $session->scratch->set("userSearchModifier",$session->form->process("modifier")); @@ -195,18 +201,25 @@ sub getUserSearchForm { -name=>"keyword", -value=>$session->scratch->get("userSearchKeyword"), -size=>15 - ) - .WebGUI::Form::selectBox($session, - -name => "status", - -value => ($session->scratch->get("userSearchStatus") || "users.status like '%'"), - -options=> { - "" => $i18n->get(821), - Active => $i18n->get(817), - Deactivated => $i18n->get(818), - Selfdestructed => $i18n->get(819) - } - ) - .WebGUI::Form::submit($session,value=>$i18n->get(170)) + ); + if ($noStatus) { + $output .= WebGUI::Form::hidden($session, + name => "status", + value => "Active" + ); + } else { + $output .= WebGUI::Form::selectBox($session, + -name => "status", + -value => ($session->scratch->get("userSearchStatus") || "users.status like '%'"), + -options=> { + "" => $i18n->get(821), + Active => $i18n->get(817), + Deactivated => $i18n->get(818), + Selfdestructed => $i18n->get(819) + } + ); + } + $output .= WebGUI::Form::submit($session,value=>$i18n->get(170)) .WebGUI::Form::formFooter($session,); $output .= ''; return $output; @@ -511,6 +524,33 @@ sub www_editUserKarmaSave { return www_editUser(); } +#------------------------------------------------------------------- + +=head2 www_formUsers ( $session ) + +Form helper to pick a user from the system. + +=cut + +sub www_formUsers { + my $session = shift; + $session->http->setCacheControl("none"); + return $session->privilege->insufficient() unless $session->user->isInGroup(12); + $session->style->useEmptyStyle("1"); + my $output = getUserSearchForm($session,"formUsers",undef,1); + my ($userCount) = $session->db->quickArray("select count(*) from users"); + return $output unless ($session->form->process("doit") || $userCount<250 || $session->form->process("pn") > 1); + $output .= ''; + $output .= $p->getBarTraditional; + return $output; +} + + #------------------------------------------------------------------- sub www_listUsers { my $session = shift; diff --git a/lib/WebGUI/Workflow/Instance.pm b/lib/WebGUI/Workflow/Instance.pm index 57a2aa37d..d257dafcd 100644 --- a/lib/WebGUI/Workflow/Instance.pm +++ b/lib/WebGUI/Workflow/Instance.pm @@ -40,7 +40,7 @@ These methods are available from this class: #------------------------------------------------------------------- -=head2 create ( session, properties [, id ] ) +=head2 create ( session, properties ) Creates a new workflow instance and returns a reference to the object. Will return undef if the workflow specified is serial and an instance of it already exists. @@ -52,22 +52,17 @@ A reference to the current session. The settable properties of the workflow instance. See the set() method for details. -=head3 id - -Normally an ID will be generated for you, but if you want to override this and provide your own 22 character id, then you can specify it here. - =cut sub create { my $class = shift; my $session = shift; my $properties = shift; - my $id = shift; my ($isSingleton) = $session->db->quickArray("select isSingleton from Workflow where workflowId=?",[$properties->{workflowId}]); my $params = (exists $properties->{parameters}) ? JSON::objToJson({parameters => $properties->{parameters}}) : undef; my ($count) = $session->db->quickArray("select count(*) from WorkflowInstance where workflowId=? and parameters=?",[$properties->{workflowId},$params]); return undef if ($isSingleton && $count); - my $instanceId = $session->db->setRow("WorkflowInstance","instanceId",{instanceId=>"new", runningSince=>time()}, $id); + my $instanceId = $session->db->setRow("WorkflowInstance","instanceId",{instanceId=>"new", runningSince=>time()}); my $self = $class->new($session, $instanceId); $properties->{notifySpectre} = 1 unless ($properties->{notifySpectre} eq "0"); $self->set($properties);