Commit d194e75a authored by Audrey Tang's avatar Audrey Tang
Browse files

CF editing (at least for Freeform-1) for User/Group done.

add new, dispatch-oriented customfield editing widgets
refactor lookup paths to _CustomFieldComposites.
warn on deprecated Queue->CustomFields per request from obra.
  (it should now be Queue->TicketCustomFields)
re-rationalise lookup into "LookupType".

git-svn-id: svn+ssh://svn.bestpractical.com/svn/bps-public/rt/branches/autrijus-3.1@478 e417ac7c-1bcc-0310-8ffa-8f5827389a85
parent f8b1925b
......@@ -383,10 +383,7 @@ CREATE TABLE CustomFields (
Repeated int2 NOT NULL DEFAULT 0 , # New -- repeated table entry
Description varchar(255) NULL ,
SortOrder integer NOT NULL DEFAULT 0 ,
ObjectType varchar(255) NOT NULL,
IntermediateType varchar(255) NOT NULL,
ParentType varchar(255) NOT NULL,
LookupType varchar(255) NOT NULL,
Creator integer NOT NULL DEFAULT 0 ,
Created DATETIME NULL ,
......@@ -403,7 +400,7 @@ CREATE TABLE CustomFields (
CREATE TABLE ObjectCustomFields (
id INTEGER NOT NULL AUTO_INCREMENT,
CustomField int NOT NULL ,
ParentId integer NOT NULL,
ObjectId integer NOT NULL,
SortOrder integer NOT NULL DEFAULT 0 ,
Creator integer NOT NULL DEFAULT 0 ,
......
......@@ -25,9 +25,9 @@ Title => $title &>
</tr>
<tr>
<td class="label"><&|/l&>Applies to</&></td>
<td><& /Admin/Elements/SelectCustomFieldObjectType,
Name => "ObjectTypeComposite",
Default => $CustomFieldObj->ObjectTypeComposite, &>
<td><& /Admin/Elements/SelectCustomFieldLookupType,
Name => "LookupType",
Default => $CustomFieldObj->LookupType, &>
</td>
</tr>
<tr>
......@@ -67,7 +67,7 @@ else {
if ( $id eq 'new' ) {
my ( $val, $msg ) = $CustomFieldObj->Create(Name => $Name,
TypeComposite => $TypeComposite,
ObjectTypeComposite => $ObjectTypeComposite,
LookupType => $LookupType,
Description => $Description,);
$m->comp("/Elements/Error", Why => loc( "Could not create CustomField", $msg ) ) unless ($val);
push @results, $msg;
......@@ -77,7 +77,7 @@ else {
$CustomFieldObj->Load($id) || $m->comp("/Elements/Error", Why => loc('No CustomField') );
$title = loc( 'Editing CustomField [_1]', $CustomFieldObj->Name() );
my @attribs = qw( Name TypeComposite ObjectTypeComposite Description);
my @attribs = qw( Name TypeComposite LookupType Description);
my @aresults = UpdateRecordObject( AttributesRef => \@attribs,
Object => $CustomFieldObj,
ARGSRef => \%ARGS );
......@@ -155,7 +155,7 @@ if ($ARGS{'Create'}){
<%ARGS>
$id => undef
$TypeComposite => undef
$ObjectTypeComposite => undef
$LookupType => undef
$MaxValues => undef
$SortOrder => undef
$Description => undef
......
......@@ -60,9 +60,9 @@ my @results;
my (@GlobalCFs, @AssociatedCFs, @UnassociatedCFs);
# XXX - exception: by "RT::Queue" fields on UI we really mean "RT::Ticket" fields.
my $composite = "$ObjectType--";
$composite = 'RT::Ticket--RT::Queue' if $composite eq 'RT::Queue--';
$CustomFields->LimitToComposite($composite);
my $lookup = $ObjectType;
$lookup = 'RT::Queue-RT::Ticket' if $lookup eq 'RT::Queue';
$CustomFields->LimitToLookupType($lookup);
if ($FindDisabledCustomFields) {
$caption = loc("All Custom Fields");
......@@ -115,11 +115,13 @@ if ($CustomField and $Move) {
my $id = $Object->Id;
my ($GlobalCFs, $ObjectCFs);
$ObjectCFs = RT::ObjectCustomFields->new($session{'CurrentUser'});
$ObjectCFs->LimitToParentAndComposite(Parent => $Object, Composite => $composite);
$ObjectCFs->LimitToObjectId($Object->Id);
$ObjectCFs->LimitToLookupType($lookup);
if ($id) {
$GlobalCFs = RT::ObjectCustomFields->new($session{'CurrentUser'});
$GlobalCFs->LimitToParentAndComposite(ParentType => ref($Object), Composite => $composite);
$GlobalCFs->LimitToObjectId(0);
$GlobalCFs->LimitToLookupType($lookup);
}
while (my $cf = $CustomFields->Next) {
......@@ -137,7 +139,7 @@ while (my $cf = $CustomFields->Next) {
if ($ARGS{$key}) {
push @AssociatedCFs, $cf;
if (!$ObjectCFs->HasEntryForCustomField($cf_id)) {
my ($val, $msg) = $cf->AddToParent($Object, $composite);
my ($val, $msg) = $cf->AddToObject($Object);
push (@results, $msg);
}
# my ($val, $msg) = $cf->SetSortOrderForObject(Object => $Object, SortOrder => $ARGS{"Object-$id-CF-$cf_id-SortOrder"});
......@@ -145,7 +147,7 @@ while (my $cf = $CustomFields->Next) {
else {
push @UnassociatedCFs, $cf;
if ($ObjectCFs->HasEntryForCustomField($cf_id)) {
my ($val, $msg) = $cf->RemoveFromParent($Object, $composite);
my ($val, $msg) = $cf->RemoveFromParent($Object);
push (@results, $msg);
}
}
......
%# BEGIN LICENSE BLOCK
%#
%# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
%#
%# (Except where explictly superceded by other copyright notices)
%#
%# This work is made available to you under the terms of Version 2 of
%# the GNU General Public License. A copy of that license should have
%# been provided with this software, but in any event can be snarfed
%# from www.gnu.org.
%#
%# This work is distributed in the hope that it will be useful, but
%# WITHOUT ANY WARRANTY; without even the implied warranty of
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%# General Public License for more details.
%#
%# Unless otherwise specified, all modifications, corrections or
%# extensions to this work which alter its source code become the
%# property of Best Practical Solutions, LLC when submitted for
%# inclusion in the work.
%#
%#
%# END LICENSE BLOCK
% if (@CustomFields == 0) {
<P><i><&|/l&>(No custom fields)</&></i></P>
% } else {
<TABLE cellspacing=0 cellpadding=2>
% my $count;
% foreach my $CustomFieldObj (@CustomFields) {
<TR>
<TD valign="TOP">
<input type="checkbox"
name="Object-<%$id%>-CF-<%$CustomFieldObj->Id%>"
value="1"
<% $Checked && 'CHECKED' %>
>
</TD>
<TD valign="TOP">
% if ($CustomFieldObj->Name) {
<A HREF="/Admin/CustomFields/Modify.html?id=<%$CustomFieldObj->id()%>"><b><%$CustomFieldObj->Name%></b></a><br>
% } else {
<A HREF="/Admin/CustomFields/Modify.html?id=<%$CustomFieldObj->id()%>"><i>(<%loc("no name")%>)</i></a><br>
% }
<%$CustomFieldObj->Description%>
</TD>
<TD valign="TOP">
<i><% $CustomFieldObj->FriendlyTypeComposite %></i>
</TD>
% # show 'move up' unless it's the first item
% if ($count++ and !$ReadOnly) {
<TD valign="TOP">
<a href="CustomFields.html?id=<%$id%>&CustomField=<%$CustomFieldObj->id%>&Move=-1"><&|/l&>Move up</&></a>
% } else {
<TD valign="TOP" ALIGN=RIGHT>
% }
% # show 'move down' unless it's the last item
% if ($count != @CustomFields and !$ReadOnly) {
% $m->print(' | ') if $count > 1;
<a href="CustomFields.html?id=<%$id%>&CustomField=<%$CustomFieldObj->id%>&Move=1"><&|/l&>Move down</&></a>
% }
</TD>
</TR>
% }
</TABLE>
% }
<%ARGS>
@CustomFields
$id
$ReadOnly => 0
$Checked => 0
</%ARGS>
......@@ -22,8 +22,8 @@
%#
%# END LICENSE BLOCK
<SELECT NAME ="<%$Name%>">
%for my $option ($cf->ObjectTypeComposites) {
<OPTION VALUE="<%$option%>" <%$option eq $Default && "SELECTED"%>><% $cf->FriendlyObjectTypeComposite($option) %></OPTION>
%for my $option ($cf->LookupTypes) {
<OPTION VALUE="<%$option%>" <%$option eq $Default && "SELECTED"%>><% $cf->FriendlyLookupType($option) %></OPTION>
%}
</SELECT>
<%INIT>
......@@ -32,5 +32,5 @@ my $cf = RT::CustomField->new($session{'CurrentUser'});
</%INIT>
<%ARGS>
$Default=>undef
$Name => 'ObjectTypeComposite'
$Name => 'LookupType'
</%ARGS>
......@@ -24,7 +24,7 @@
<& /Admin/Elements/Tabs,
subtabs => $tabs,
current_tab => 'Admin/Users/',
current_subtab => $current_subtab,
current_subtab => $current_tab,
Title => $Title &>
<%INIT>
my $tabs;
......@@ -37,6 +37,9 @@ subtabs => {
Basics => { title => loc('Basics'),
path => "Admin/Users/Modify.html?id=".$id
},
Memberships => { title => loc('Memberships'),
path => "Admin/Users/Memberships.html?id=".$id
},
History => { title => loc('History'),
path => "Admin/Users/History.html?id=".$id
},
......@@ -63,11 +66,19 @@ if ($session{'CurrentUser'}->HasRight( Object => $RT::System, Right => 'AdminUse
# Now let callbacks add their extra tabs
$m->comp('/Elements/Callback', tabs => $tabs, %ARGS);
foreach my $tab ( sort keys %{$tabs} ) {
if ( $tabs->{$tab}->{'path'} eq $current_subtab ) {
$tabs->{$tab}->{"current_subtab"} = $current_subtab;
#foreach my $tab ( sort keys %{$tabs} ) {
# if ( $tabs->{$tab}->{'path'} eq $current_subtab ) {
# $tabs->{$tab}->{"current_subtab"} = $current_subtab;
# }
#}
foreach my $tab ( sort keys %{$tabs->{'this'}->{'subtabs'}} ) {
if ( $tabs->{'this'}->{'subtabs'}->{$tab}->{'path'} eq $current_tab ) {
$tabs->{'this'}->{'subtabs'}->{$tab}->{"subtabs"} = $subtabs;
$tabs->{'this'}->{'subtabs'}->{$tab}->{"current_subtab"} = $current_subtab;
}
}
}
$tabs->{'this'}->{"current_subtab"} = $current_tab;
$current_tab = "Admin/Users/Modify.html?id=".$id if $id;
</%INIT>
......
%# BEGIN LICENSE BLOCK
%#
%# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
%#
%# (Except where explictly superceded by other copyright notices)
%#
%# This work is made available to you under the terms of Version 2 of
%# the GNU General Public License. A copy of that license should have
%# been provided with this software, but in any event can be snarfed
%# from www.gnu.org.
%#
%# This work is distributed in the hope that it will be useful, but
%# WITHOUT ANY WARRANTY; without even the implied warranty of
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%# General Public License for more details.
%#
%# Unless otherwise specified, all modifications, corrections or
%# extensions to this work which alter its source code become the
%# property of Best Practical Solutions, LLC when submitted for
%# inclusion in the work.
%#
%#
%# END LICENSE BLOCK
<& /Admin/Elements/ObjectCustomFields, %ARGS, ObjectType => 'RT::Group' &>
......@@ -25,7 +25,7 @@
<& /Admin/Elements/UserTabs,
id => $id,
UserObj => $UserObj,
current_subtab => $current_tab,
current_tab => $current_tab,
Title => $title &>
<& /Ticket/Elements/ShowHistory,
......
%# BEGIN LICENSE BLOCK
%#
%# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
%#
%# (Except where explictly superceded by other copyright notices)
%#
%# This work is made available to you under the terms of Version 2 of
%# the GNU General Public License. A copy of that license should have
%# been provided with this software, but in any event can be snarfed
%# from www.gnu.org.
%#
%# This work is distributed in the hope that it will be useful, but
%# WITHOUT ANY WARRANTY; without even the implied warranty of
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%# General Public License for more details.
%#
%# Unless otherwise specified, all modifications, corrections or
%# extensions to this work which alter its source code become the
%# property of Best Practical Solutions, LLC when submitted for
%# inclusion in the work.
%#
%#
%# END LICENSE BLOCK
<& /Admin/Elements/Header, Title => $title &>
<& /Admin/Elements/UserTabs,
id => $id,
UserObj => $UserObj,
current_tab => $current_tab,
Title => $title &>
<h2><&|/l&>Groups</&></h2>
<ul>
% while ( my $GroupMember = $GroupMembers->Next ) {
% my $Group = RT::Group->new($session{'CurrentUser'});
% $Group->Load($GroupMember->GroupId) or next;
% if ($Group->Domain eq 'UserDefined') {
<li><a href="/Admin/Groups/Modify.html?id=<% $Group->Id %>"><% $Group->Name %></a></li>
% } elsif ($Group->Domain eq 'SystemInternal') {
<li><em><% loc($Group->Type) %></em></li>
% }
% }
</ul>
<%INIT>
my $current_tab = 'Admin/Users/Memberships.html?id='.$id;
my $UserObj = new RT::User($session{'CurrentUser'});
$UserObj->Load($id) || Abort("Couldn't load user '$id'");
my $title = loc("Memberships of the user [_1]", $UserObj->Name);
my $GroupMembers = RT::GroupMembers->new($session{'CurrentUser'});
$GroupMembers->Limit( FIELD => 'MemberId', VALUE => $UserObj->Id );
my $alias = $GroupMembers->Join(
TYPE => 'left',
ALIAS1 => 'main',
FIELD1 => 'GroupId',
TABLE2 => 'Groups',
FIELD2 => 'id'
);
$GroupMembers->Limit(
ALIAS => $alias,
FIELD => 'Domain',
OPERATOR => '=',
VALUE => 'SystemInternal',
);
$GroupMembers->Limit(
ALIAS => $alias,
FIELD => 'Domain',
OPERATOR => '=',
VALUE => 'UserDefined',
);
$GroupMembers->OrderByCols(
{ ALIAS => $alias, FIELD => 'Domain' },
{ ALIAS => $alias, FIELD => 'Name' },
);
</%INIT>
<%ARGS>
$id => undef
</%ARGS>
......@@ -25,7 +25,7 @@
<& /Admin/Elements/UserTabs,
id => $id,
UserObj => $UserObj,
current_subtab => $current_tab,
current_tab => $current_tab,
Title => $title &>
<& /Elements/ListActions, actions => \@results &>
......@@ -179,14 +179,15 @@
<TR>
</TR>
</TABLE>
<BR>
<& /Elements/TitleBoxStart, title => loc('Custom Fields') &>
<TABLE>
% my $CFs = $UserObj->CustomFields;
% while (my $CF = $CFs->Next) {
<TR><TD ALIGN="RIGHT">
<% $CF->Name %>
<% $CF->Name %>:
</TD><TD>
<& /Ticket/Elements/EditCustomField, CustomField => $CF &>
<& /Elements/EditCustomField, %ARGS, Object => $UserObj, CustomField => $CF &>
</TD></TR>
% }
<TR>
......@@ -278,6 +279,7 @@ if ($UserObj->Id) {
Object => $UserObj,
ARGSRef => \%ARGS );
push (@results,@fieldresults);
push @results, ProcessObjectCustomFieldUpdates( ARGSRef => \%ARGS );
# {{{ Deal with special fields: Privileged, Enabled and Password
......
%# BEGIN LICENSE BLOCK
%#
%# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
%#
%# (Except where explictly superceded by other copyright notices)
%#
%# This work is made available to you under the terms of Version 2 of
%# the GNU General Public License. A copy of that license should have
%# been provided with this software, but in any event can be snarfed
%# from www.gnu.org.
%#
%# This work is distributed in the hope that it will be useful, but
%# WITHOUT ANY WARRANTY; without even the implied warranty of
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%# General Public License for more details.
%#
%# Unless otherwise specified, all modifications, corrections or
%# extensions to this work which alter its source code become the
%# property of Best Practical Solutions, LLC when submitted for
%# inclusion in the work.
%#
%#
%# END LICENSE BLOCK
<input name="<%$NamePrefix%><%$CustomField->Id%>-Value" size="<%$Cols%>" value="<%$Default ? $Default : ''%>">
<%ARGS>
$Object => undef
$CustomField => undef
$NamePrefix => undef
$Default => undef
$Cols
</%ARGS>
%# BEGIN LICENSE BLOCK
%#
%# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
%#
%# (Except where explictly superceded by other copyright notices)
%#
%# This work is made available to you under the terms of Version 2 of
%# the GNU General Public License. A copy of that license should have
%# been provided with this software, but in any event can be snarfed
%# from www.gnu.org.
%#
%# This work is distributed in the hope that it will be useful, but
%# WITHOUT ANY WARRANTY; without even the implied warranty of
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%# General Public License for more details.
%#
%# Unless otherwise specified, all modifications, corrections or
%# extensions to this work which alter its source code become the
%# property of Best Practical Solutions, LLC when submitted for
%# inclusion in the work.
%#
%#
%# END LICENSE BLOCK
% if ($CustomField->Type eq 'FreeformSingle') {
<input name="<%$NamePrefix%><%$CustomField->Id%>-Value"
size="<%$Cols%>"
% if ($Object) {
value="<%$Values->Count ? $Values->First->Content : ''%>"
% } elsif ($Default) {
value="<%$Default ? $Default : ''%>"
% }
>
% } elsif ($CustomField->Type eq 'FreeformMultiple') {
% my $content;
% if ($Object) {
% while (my $value = $Values->Next ) {
% $content .= $value->Content;
% }
% } elsif ($Default) {
value="<%$Default ? $Default : ''%>"
% }
<input type="hidden" name="<%$NamePrefix%><%$CustomField->Id%>-Values-Magic" value="1">
<textarea cols=<%$Cols%> rows=<%$Rows%> name="<%$NamePrefix%><%$CustomField->Id%>-Values"><%$content%></textarea>
% } elsif ($CustomField->Type =~ /^Select/) {
<input type="hidden" name="<%$NamePrefix%><%$CustomField->Id%>-Values-Magic" value="1">
<select name="<%$NamePrefix%><%$CustomField->Id%>-Values"
size="<%$Rows%>"
<%$CustomField->Type eq 'SelectMultiple' && 'MULTIPLE'%>>
% my $CustomFieldValues = $CustomField->Values();
% my $selected;
% while (my $value = $CustomFieldValues->Next) {
<option value="<% $value->Name %>"
% if ($Object) {
<% $Values->HasEntry($value->Name) && ($selected = 1) && 'SELECTED' %>
% } elsif ($Default) {
<% ($Default eq $value->Name) && ($selected = 1) && 'SELECTED' %>
% }
><% $value->Name%></option>
% }
<option value="" <% !$selected && 'SELECTED' %>><&|/l&>(no value)</&></option>
</select>
% }
<%INIT>
my $Values;
if ($Object) {
$Values = $Object->CustomFieldValues($CustomField->id);
$NamePrefix ||= join('-', 'Object', ref($Object), $Object->Id, 'CustomField', '');
}
my $Type = $CustomField->Type;
my $MaxValues = $CustomField->MaxValues;
$Type .= ($MaxValues > 1) ? 'Some' : $MaxValues ? 'Single' : 'Multiple';
if ($MaxValues == 1 and $Object and $Values) {
$Default = ($Values->Count ? $Values->First->Content : '');
}
return $m->comp(
"/Elements/CustomField/$Type",
%ARGS,
Rows => $Rows,
Cols => $Cols,
Default => $Default,
Object => $Object,
NamePrefix => $NamePrefix,
CustomField => $CustomField,
);
</%INIT>
<%ARGS>
$Object => undef
$CustomField => undef
$NamePrefix => undef
$Rows => 5
$Cols => 15
$Default => undef
</%ARGS>
......@@ -73,9 +73,7 @@ Create takes a hash of values and creates a row in the database:
smallint(6) 'Repeated'.
varchar(255) 'Description'.
int(11) 'SortOrder'.
varchar(255) 'ObjectType'.
varchar(255) 'IntermediateType'.
varchar(255) 'ParentType'.
varchar(255) 'LookupType'.
smallint(6) 'Disabled'.
=cut
......@@ -93,9 +91,7 @@ sub Create {
Repeated => '0',
Description => '',
SortOrder => '0',
ObjectType => '',
IntermediateType => '',
ParentType => '',
LookupType => '',
Disabled => '0',
@_);
......@@ -107,9 +103,7 @@ sub Create {
Repeated => $args{'Repeated'},
Description => $args{'Description'},
SortOrder => $args{'SortOrder'},
ObjectType => $args{'ObjectType'},
IntermediateType => $args{'IntermediateType'},
ParentType => $args{'ParentType'},
LookupType => $args{'LookupType'},
Disabled => $args{'Disabled'},
);
......@@ -252,55 +246,19 @@ Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
=cut
=head2 ObjectType
=head2 LookupType
Returns the current value of ObjectType.
(In the database, ObjectType is stored as varchar(255).)
Returns the current value of LookupType.
(In the database, LookupType is stored as varchar(255).)
=head2 SetObjectType VALUE
=head2 SetLookupType VALUE
Set ObjectType to VALUE.
Set LookupType to VALUE.
Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
(In the database, ObjectType will be stored as a varchar(255).)
=cut
=head2 IntermediateType
Returns the current value of IntermediateType.
(In the database, IntermediateType is stored as varchar(255).)
=head2 SetIntermediateType VALUE
Set IntermediateType to VALUE.
Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
(In the database, IntermediateType will be stored as a varchar(255).)
=cut
=head2 ParentType
Returns the current value of ParentType.
(In the database, ParentType is stored as varchar(255).)
=head2 SetParentType VALUE
Set ParentType to VALUE.
Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
(In the database, ParentType will be stored as a varchar(255).)
(In the database, LookupType will be stored as a varchar(255).)
=cut
......@@ -380,11 +338,7 @@ sub _CoreAccessible {
{read => 1, write => 1, type => 'varchar(255)', default => ''},
SortOrder =>
{read => 1, write => 1, type => 'int(11)', default => '0'},
ObjectType =>
{read => 1, write => 1, type => 'varchar(255)', default => ''},
IntermediateType =>
{read => 1, write => 1, type => 'varchar(255)', default => ''},
ParentType =>
LookupType =>
{read => 1, write => 1, type => 'varchar(255)', default => ''},
Creator =>
{read => 1, auto => 1, type => 'int(11)', default => '0'},
......
......@@ -95,11 +95,8 @@ sub Create {
MaxValues => '0',
Pattern => '',
Description => '',
SortOrder => '0',
Disabled => '0',
ObjectType => '',
IntermediateType => '',
ParentType => '',
LookupType => '',
Repeated => '0',
@_);
......@@ -107,10 +104,6 @@ sub Create {