added a user form field type
This commit is contained in:
parent
d71171cc26
commit
dc1a0c7703
7 changed files with 173 additions and 37 deletions
|
|
@ -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
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
|
|
|
|||
111
lib/WebGUI/Form/User.pm
Normal file
111
lib/WebGUI/Form/User.pm
Normal 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;
|
||||
|
||||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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 .= '</div>';
|
||||
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 .= '<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 {
|
||||
my $session = shift;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue