From: mark Date: Wed, 1 Sep 2010 23:39:23 +0000 (+0000) Subject: RT mandatory custom fields, RT#9260 X-Git-Tag: TORRUS_1_0_9~330 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=8c5a780343e027058a51692d8b9b8140c88ce6c7 RT mandatory custom fields, RT#9260 --- diff --git a/rt/etc/schema.Pg b/rt/etc/schema.Pg index 48525c8d7..e3006d073 100755 --- a/rt/etc/schema.Pg +++ b/rt/etc/schema.Pg @@ -539,6 +539,7 @@ CREATE TABLE CustomFields ( LastUpdatedBy integer NOT NULL DEFAULT 0 , LastUpdated TIMESTAMP NULL , Disabled integer NOT NULL DEFAULT 0 , + Required integer NOT NULL DEFAULT 0 , PRIMARY KEY (id) ); diff --git a/rt/lib/RT/CustomField.pm b/rt/lib/RT/CustomField.pm index 995728f67..dc4108044 100644 --- a/rt/lib/RT/CustomField.pm +++ b/rt/lib/RT/CustomField.pm @@ -122,6 +122,7 @@ sub Create { Disabled => '0', LinkToValue => '', IncludeContentForValue => '', + Required => '0', @_); $self->SUPER::Create( @@ -381,6 +382,8 @@ sub _CoreAccessible { {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''}, Disabled => {read => 1, write => 1, sql_type => 5, length => 6, is_blob => 0, is_numeric => 1, type => 'smallint(6)', default => '0'}, + Required => + {read => 1, write => 1, sql_type => 5, length => 6, is_blob => 0, is_numeric => 1, type => 'smallint(6)', default => '0'}, } }; diff --git a/rt/share/html/Admin/CustomFields/Modify.html b/rt/share/html/Admin/CustomFields/Modify.html index f75607a8d..d2932d2d9 100644 --- a/rt/share/html/Admin/CustomFields/Modify.html +++ b/rt/share/html/Admin/CustomFields/Modify.html @@ -119,6 +119,11 @@ % }   + /> +<&|/l&>Required for ticket resolution + + +  /> <&|/l&>Enabled (Unchecking this box disables this custom field) @@ -171,11 +176,12 @@ else { } 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; + + $ARGS{'Required'} ||= 0; - my @attribs = qw(Disabled Pattern Name TypeComposite LookupType Description LinkValueTo IncludeContentForValue); + my @attribs = qw(Disabled Required Pattern Name TypeComposite LookupType Description LinkValueTo IncludeContentForValue); push @results, UpdateRecordObject( AttributesRef => \@attribs, Object => $CustomFieldObj, @@ -222,6 +228,9 @@ $id = $CustomFieldObj->id if $CustomFieldObj->id; my $EnabledChecked = qq[checked="checked"]; $EnabledChecked = '' if $CustomFieldObj->Disabled; +my $RequiredChecked = ''; +$RequiredChecked = qq[checked="checked"] if $CustomFieldObj->Required; + my @CFvalidations = ( '(?#Mandatory).', '(?#Digits)^[\d.]+$', diff --git a/rt/share/html/Callbacks/CheckMandatoryFields/Ticket/Elements/Tabs/Default b/rt/share/html/Callbacks/CheckMandatoryFields/Ticket/Elements/Tabs/Default new file mode 100644 index 000000000..2c0698ec2 --- /dev/null +++ b/rt/share/html/Callbacks/CheckMandatoryFields/Ticket/Elements/Tabs/Default @@ -0,0 +1,12 @@ +<%doc> +If mandatory fields aren't set yet, point the "Resolve" link back +to "Ticket Basics". + +<%init> +my $TicketObj = delete($ARGS{'Ticket'}); +my $actions = $ARGS{'actions'}; +if( $m->comp('/Ticket/Elements/CheckMandatoryFields', Ticket => $TicketObj) + ) { + $actions->{'G'}->{'path'} = 'Ticket/Modify.html?id='.$TicketObj->Id.'&resolve=1'; +} + diff --git a/rt/share/html/Callbacks/CheckMandatoryFields/Ticket/Modify.html/BeforeActionList b/rt/share/html/Callbacks/CheckMandatoryFields/Ticket/Modify.html/BeforeActionList new file mode 100644 index 000000000..4779411ce --- /dev/null +++ b/rt/share/html/Callbacks/CheckMandatoryFields/Ticket/Modify.html/BeforeActionList @@ -0,0 +1,15 @@ +<%init> +use Data::Dumper; +my $ARGSRef = $ARGS{'ARGSRef'}; +my $TicketObj = $ARGS{'Ticket'}; +my $results = $ARGS{'Actions'}; +if(defined($ARGSRef->{'resolve'})) { + my @errors = + $m->comp('/Ticket/Elements/CheckMandatoryFields', Ticket => $TicketObj); + return if !@errors; + my $msg = 'Missing required field'.(@errors > 1 ? 's' : '').': ' . + join(', ', map { $_->Name } @errors); + $m->notes( ('InvalidField-' . $_->Id) => 'Required' ) foreach @errors; + push @$results, $msg; +} + diff --git a/rt/share/html/Callbacks/CheckMandatoryFields/Ticket/Update.html/BeforeDisplay b/rt/share/html/Callbacks/CheckMandatoryFields/Ticket/Update.html/BeforeDisplay new file mode 100644 index 000000000..0d69bc27b --- /dev/null +++ b/rt/share/html/Callbacks/CheckMandatoryFields/Ticket/Update.html/BeforeDisplay @@ -0,0 +1,24 @@ +<%doc> +When the user tries to change a ticket's status to "resolved" through +the Update interface, check mandatory fields. If they aren't all set, +redirect to Ticket Basics instead of updating. Note that this will +lose any comments/time/other information the user has entered. + + +<%init> +my $TicketObj = $ARGS{'Ticket'}; +my $ARGSRef = $ARGS{'ARGSRef'}; +my $oldStatus = $TicketObj->Status(); +my $newStatus = $ARGSRef->{'Status'} || $ARGSRef->{'DefaultStatus'}; +if( $oldStatus ne 'resolved' and + $newStatus eq 'resolved' and + $m->comp('/Ticket/Elements/CheckMandatoryFields', + Ticket => $TicketObj + ) ) { + $m->clear_buffer; + RT::Interface::Web::Redirect( + RT->Config->Get('WebURL')."Ticket/Modify.html?id=".$TicketObj->Id."&resolve=1" + ); + $m->abort; +} + diff --git a/rt/share/html/Ticket/Elements/CheckMandatoryFields b/rt/share/html/Ticket/Elements/CheckMandatoryFields new file mode 100644 index 000000000..3d0324f98 --- /dev/null +++ b/rt/share/html/Ticket/Elements/CheckMandatoryFields @@ -0,0 +1,9 @@ +<%init> + +my $TicketObj = $ARGS{'Ticket'} or return (); +my $ARGSRef = $ARGS{'ARGSRef'}; +my @fields = grep { $_->Required } + @{ $TicketObj->CustomFields->ItemsArrayRef }; +return grep { !defined($TicketObj->FirstCustomFieldValue($_->id)) } @fields; + +