[Rt-commit] r6235 - in rt/branches/3.7-EXPERIMENTAL:
html/Admin/CustomFields
ruz at bestpractical.com
ruz at bestpractical.com
Thu Oct 19 11:29:25 EDT 2006
Author: ruz
Date: Thu Oct 19 11:29:23 2006
New Revision: 6235
Modified:
rt/branches/3.7-EXPERIMENTAL/ (props changed)
rt/branches/3.7-EXPERIMENTAL/html/Admin/CustomFields/Modify.html
Log:
r3975 at cubic-pc: cubic | 2006-10-19 19:06:05 +0400
* add label to submit button: Create/Save Changes
* always highlight correct tab
* allow user to unset values
* update things only when we are not creating
and arg Update is defined
Modified: rt/branches/3.7-EXPERIMENTAL/html/Admin/CustomFields/Modify.html
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Admin/CustomFields/Modify.html (original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Admin/CustomFields/Modify.html Thu Oct 19 11:29:23 2006
@@ -125,81 +125,87 @@
</div>
% }
+<& /Elements/Submit, Name => 'Update', Label => $id eq 'new'? loc('Create'): loc('Save Changes') &>
+
+</form>
<%INIT>
+my ($title, @results, $Disabled);
my $CustomFieldObj = RT::CustomField->new( $session{'CurrentUser'} );
-my ( $title, @results, $EnabledChecked, $Disabled);
-$EnabledChecked = "checked";
+my $current_tab = 'Admin/CustomFields/Modify.html';
-if ( !$id ) {
+unless ( $id ) {
$title = loc("Create a CustomField");
$id = 'new';
+ $current_tab .= '?Create=1';
}
else {
-
if ( $id eq 'new' ) {
- my ( $val, $msg ) = $CustomFieldObj->Create(Name => $Name,
- TypeComposite => $TypeComposite,
- LookupType => $LookupType,
- Description => $Description,
- Pattern => $Pattern,);
- $m->comp("/Elements/Error", Why => loc( "Could not create CustomField", $msg ) ) unless ($val);
+ my ( $val, $msg ) = $CustomFieldObj->Create(
+ Name => $Name,
+ TypeComposite => $TypeComposite,
+ LookupType => $LookupType,
+ Description => $Description,
+ Pattern => $Pattern,
+ );
+ $m->comp( "/Elements/Error", Why => loc( "Could not create CustomField", $msg ) ) unless $val;
push @results, $msg;
$title = loc( 'Created CustomField [_1]', $CustomFieldObj->Name );
} else {
- $CustomFieldObj->Load($id) || $m->comp("/Elements/Error", Why => loc('No CustomField') );
+ $CustomFieldObj->Load( $id ) || $m->comp("/Elements/Error", Why => loc('No CustomField') );
$title = loc( 'Editing CustomField [_1]', $CustomFieldObj->Name );
}
+ $current_tab .= "?id=$id";
+}
- if( $ARGS{'Update'} ) {
+if ( $ARGS{'Update'} && $id ne 'new' ) {
- #we're asking about enabled on the web page but really care about disabled.
- $ARGS{'Disabled'} = $Disabled = $Enabled? 0 : 1;
+ #we're asking about enabled on the web page but really care about disabled.
+ $ARGS{'Disabled'} = $Disabled = $Enabled? 0 : 1;
- my @attribs = qw(Disabled Pattern Name TypeComposite LookupType Description LinkValueTo IncludeContentForValue);
- push @results, UpdateRecordObject( AttributesRef => \@attribs,
- Object => $CustomFieldObj,
- ARGSRef => \%ARGS );
+ my @attribs = qw(Disabled Pattern Name TypeComposite LookupType Description LinkValueTo IncludeContentForValue);
+ push @results, UpdateRecordObject(
+ AttributesRef => \@attribs,
+ Object => $CustomFieldObj,
+ ARGSRef => \%ARGS
+ );
+ $CustomFieldObj->SetValuesClass( $ValuesClass );
- $CustomFieldObj->SetValuesClass( $ValuesClass );
+ my $paramtag = "CustomField-". $CustomFieldObj->Id ."-Value";
+ # Delete any fields that want to be deleted
+ foreach my $key ( keys %ARGS ) {
+ next unless $key =~ /^Delete-$paramtag-(\d+)$/o;
+ my ($val, $msg) = $CustomFieldObj->DeleteValue( $1 );
+ push (@results, $msg);
}
- $id = $CustomFieldObj->id;
- $EnabledChecked = '' if $CustomFieldObj->Disabled;
-}
-
-my $paramtag = "CustomField-".$CustomFieldObj->Id."-Value-";
-# Delete any fields that want to be deleted
-foreach my $key (keys %ARGS) {
- next unless ($key =~ /^Delete-$paramtag(\d+)$/);
- my ($val, $msg) = $CustomFieldObj->DeleteValue($1);
- push (@results, $msg);
-}
+ # Update any existing values
+ my $values = $CustomFieldObj->ValuesObj;
+ while ( my $value = $values->Next ) {
+ foreach my $attr qw(Name Description SortOrder Category) {
+ my $param = "$paramtag-". $value->Id ."-". $attr;
+ next if ($value->$attr()||'') eq ($ARGS{$param}||'');
+
+ my $mutator = "Set$attr";
+ my ($id, $msg) = $value->$mutator( $ARGS{$param} );
+ push (@results, $msg);
+ }
+ }
-# Update any existing values
-my $values = $CustomFieldObj->ValuesObj;
-while (my $value = $values->Next) {
- foreach my $attr qw(Name Description SortOrder Category) {
- my $param = $paramtag.$value->Id."-".$attr;
-
- if ( $ARGS{$param} && ($value->$attr() ne $ARGS{$param})) {
- my $mutator = "Set$attr";
- my ($id, $msg) = $value->$mutator($ARGS{$param});
+ # Add any new values
+ if ( defined $ARGS{ $paramtag ."-new-Name" } && length $ARGS{ $paramtag ."-new-Name" } ) {
+ my ($id, $msg) = $CustomFieldObj->AddValue(
+ map { $_ => $ARGS{ $paramtag ."-new-$_" } }
+ qw( Name Description SortOrder Category )
+ );
push (@results, $msg);
- }
}
}
-# Add any new values
-if ($ARGS{$paramtag."new-Name"}) {
- my ($id, $msg) = $CustomFieldObj->AddValue(
- map { $_ => $ARGS{$paramtag."new-$_"} } qw( Name Description SortOrder Category )
- );
- push (@results, $msg);
-}
+$id = $CustomFieldObj->id;
-my $current_tab = 'Admin/CustomFields/Modify.html';
-$current_tab .= $ARGS{'Create'}? '?Create=1': "?id=$id";
+my $EnabledChecked = "checked";
+$EnabledChecked = '' if $CustomFieldObj->Disabled;
</%INIT>
<%ARGS>
More information about the Rt-commit
mailing list