added a user form field type

This commit is contained in:
JT Smith 2006-04-23 23:50:40 +00:00
parent d71171cc26
commit dc1a0c7703
7 changed files with 173 additions and 37 deletions

View file

@ -44,6 +44,7 @@
- Converted WebGUI to use a new object oriented session system. More details - Converted WebGUI to use a new object oriented session system. More details
in migation.txt. in migation.txt.
- Added a sort alphabetically option to the folder asset. - 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 - Added a symbol next to items in the asset manager to indicate if they have
children or not. children or not.
- Added more templating options to the Paginator thanks to Jukka Raimovaara. - Added more templating options to the Paginator thanks to Jukka Raimovaara.

View file

@ -221,7 +221,7 @@ sub definition {
defaultValue=>'7' defaultValue=>'7'
}, },
ownerUserId=>{ ownerUserId=>{
fieldType=>'selectBox', fieldType=>'user',
defaultValue=>'3' defaultValue=>'3'
}, },
status=>{ status=>{
@ -605,22 +605,11 @@ sub getEditForm {
} else { } else {
$subtext = ""; $subtext = "";
} }
my $clause; $tabform->getTab("security")->user(
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(
-name=>"ownerUserId", -name=>"ownerUserId",
-options=>$users,
-label=>$i18n->get(108), -label=>$i18n->get(108),
-hoverHelp=>$i18n->get('108 description'), -hoverHelp=>$i18n->get('108 description'),
-value=>[$self->get("ownerUserId")], -value=>$self->get("ownerUserId"),
-subtext=>$subtext, -subtext=>$subtext,
-uiLevel=>6 -uiLevel=>6
); );

View file

@ -576,8 +576,7 @@ sub www_editListing {
-label=>$i18n->get('description'), -label=>$i18n->get('description'),
); );
if ($self->canEdit) { if ($self->canEdit) {
$f->selectBox( $f->user(
options=>$self->session->db->buildHashRef("select userId,username from users order by username"),
name=>"maintainerId", name=>"maintainerId",
value=>$listing->{maintainerId}, value=>$listing->{maintainerId},
label=>$i18n->get('listing maintainer'), label=>$i18n->get('listing maintainer'),

111
lib/WebGUI/Form/User.pm Normal file
View file

@ -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;

View file

@ -265,6 +265,7 @@ sub getOperations {
'editUserSave' => 'WebGUI::Operation::User', 'editUserSave' => 'WebGUI::Operation::User',
'editUserKarma' => 'WebGUI::Operation::User', 'editUserKarma' => 'WebGUI::Operation::User',
'editUserKarmaSave' => 'WebGUI::Operation::User', 'editUserKarmaSave' => 'WebGUI::Operation::User',
'formUsers' => 'WebGUI::Operation::User',
'listUsers' => 'WebGUI::Operation::User', 'listUsers' => 'WebGUI::Operation::User',
'approveVersionTag' => 'WebGUI::Operation::VersionTag', 'approveVersionTag' => 'WebGUI::Operation::VersionTag',

View file

@ -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. 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. 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 =cut
#-------------------------------------------------------------------
sub getUserSearchForm { sub getUserSearchForm {
my $session = shift; my $session = shift;
my $op = shift; my $op = shift;
my $params = shift; my $params = shift;
my $noStatus = shift;
$session->scratch->set("userSearchKeyword",$session->form->process("keyword")); $session->scratch->set("userSearchKeyword",$session->form->process("keyword"));
$session->scratch->set("userSearchStatus",$session->form->process("status")); $session->scratch->set("userSearchStatus",$session->form->process("status"));
$session->scratch->set("userSearchModifier",$session->form->process("modifier")); $session->scratch->set("userSearchModifier",$session->form->process("modifier"));
@ -195,18 +201,25 @@ sub getUserSearchForm {
-name=>"keyword", -name=>"keyword",
-value=>$session->scratch->get("userSearchKeyword"), -value=>$session->scratch->get("userSearchKeyword"),
-size=>15 -size=>15
) );
.WebGUI::Form::selectBox($session, if ($noStatus) {
-name => "status", $output .= WebGUI::Form::hidden($session,
-value => ($session->scratch->get("userSearchStatus") || "users.status like '%'"), name => "status",
-options=> { value => "Active"
"" => $i18n->get(821), );
Active => $i18n->get(817), } else {
Deactivated => $i18n->get(818), $output .= WebGUI::Form::selectBox($session,
Selfdestructed => $i18n->get(819) -name => "status",
} -value => ($session->scratch->get("userSearchStatus") || "users.status like '%'"),
) -options=> {
.WebGUI::Form::submit($session,value=>$i18n->get(170)) "" => $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,); .WebGUI::Form::formFooter($session,);
$output .= '</div>'; $output .= '</div>';
return $output; return $output;
@ -511,6 +524,33 @@ sub www_editUserKarmaSave {
return www_editUser(); 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 .= '<ul>';
my $p = doUserSearch($session,"formUsers",1);
foreach my $data (@{$p->getPageData}) {
$output .= '<li><a href="#" onclick="window.opener.document.getElementById(\''.$session->form->process("formId").'\').value=\''.$data->{userId}.'\';window.opener.document.getElementById(\''.$session->form->process("formId").'_display\').value=\''.$data->{username}.'\';window.close();">'.$data->{username}.'</a></li>';
}
$output .= '</ul>';
$output .= $p->getBarTraditional;
return $output;
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub www_listUsers { sub www_listUsers {
my $session = shift; my $session = shift;

View file

@ -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. 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. 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 =cut
sub create { sub create {
my $class = shift; my $class = shift;
my $session = shift; my $session = shift;
my $properties = shift; my $properties = shift;
my $id = shift;
my ($isSingleton) = $session->db->quickArray("select isSingleton from Workflow where workflowId=?",[$properties->{workflowId}]); 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 $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]); my ($count) = $session->db->quickArray("select count(*) from WorkflowInstance where workflowId=? and parameters=?",[$properties->{workflowId},$params]);
return undef if ($isSingleton && $count); 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); my $self = $class->new($session, $instanceId);
$properties->{notifySpectre} = 1 unless ($properties->{notifySpectre} eq "0"); $properties->{notifySpectre} = 1 unless ($properties->{notifySpectre} eq "0");
$self->set($properties); $self->set($properties);