X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=rt%2Fhtml%2FREST%2F1.0%2FForms%2Fticket%2Fdefault;h=2bfc43d9abeab5c71ae8bfeeaaa5ea05f9786699;hp=1b3142b861926c592ae25e288295839795a2c43f;hb=8103c1fc1b2c27a6855feadf26f91b980a54bc52;hpb=c582e92888b4a5553e1b4e5214cf35217e4a0cf0 diff --git a/rt/html/REST/1.0/Forms/ticket/default b/rt/html/REST/1.0/Forms/ticket/default index 1b3142b86..2bfc43d9a 100644 --- a/rt/html/REST/1.0/Forms/ticket/default +++ b/rt/html/REST/1.0/Forms/ticket/default @@ -1,18 +1,66 @@ +%# BEGIN BPS TAGGED BLOCK {{{ +%# +%# COPYRIGHT: +%# +%# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC +%# +%# +%# (Except where explicitly superseded by other copyright notices) +%# +%# +%# LICENSE: +%# +%# 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. +%# +%# You should have received a copy of the GNU General Public License +%# along with this program; if not, write to the Free Software +%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +%# 02110-1301 or visit their web page on the internet at +%# http://www.gnu.org/copyleft/gpl.html. +%# +%# +%# CONTRIBUTION SUBMISSION POLICY: +%# +%# (The following paragraph is not intended to limit the rights granted +%# to you to modify and distribute this software under the terms of +%# the GNU General Public License and is only of importance to you if +%# you choose to contribute your changes and enhancements to the +%# community by submitting them to Best Practical Solutions, LLC.) +%# +%# By intentionally submitting any modifications, corrections or +%# derivatives to this work, or any other work intended for use with +%# Request Tracker, to Best Practical Solutions, LLC, you confirm that +%# you are the copyright holder for those contributions and you grant +%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +%# royalty-free, perpetual, license to use, copy, create derivative +%# works based on those contributions, and sublicense and distribute +%# those contributions and any derivatives thereof. +%# +%# END BPS TAGGED BLOCK }}} %# REST/1.0/Forms/ticket/default %# <%ARGS> $id $changes => {} $fields => undef +$args => undef -<%perl> +<%INIT> use MIME::Entity; my @comments; my ($c, $o, $k, $e) = ("", [], {}, 0); my %data = %$changes; my $ticket = new RT::Ticket $session{CurrentUser}; -my @dates = qw(Created Starts Started Due Resolved Told); +my @dates = qw(Created Starts Started Due Resolved Told LastUpdated); my @people = qw(Requestors Cc AdminCc); my @create = qw(Queue Requestor Subject Cc AdminCc Owner Status Priority InitialPriority FinalPriority TimeEstimated TimeWorked @@ -38,7 +86,7 @@ if ($id ne 'new') { } } else { - if (%data == 0) { + if (!keys(%data)) { # GET ticket/new: Return a suitable default form. # We get defaults from queue/1 (XXX: What if it isn't there?). my $due = new RT::Date $session{CurrentUser}; @@ -50,7 +98,7 @@ else { $starts->SetToNow; return [ - "# Required: Queue, Requestor, Subject", + "# Required: id, Queue", [ qw(id Queue Requestor Subject Cc AdminCc Owner Status Priority InitialPriority FinalPriority TimeEstimated Starts Due Text) ], { @@ -82,11 +130,26 @@ else { if (exists $create{lc $k}) { $v{$create{lc $k}} = delete $data{$k}; } + # Set custom field + elsif ($k =~ /^CF-/i) { + my $cf = RT::CustomField->new( $RT::SystemUser ); + my $cfk = $k; + $cfk =~ s/^CF-//i; + unless($cf->LoadByName( Name => $cfk )) { + push @comments, "# Invalid custom field name ($cfk)"; + delete $data{$k}; + next; + } + $v{"CustomField-".$cf->Id()} = delete $data{$k}; + } elsif (lc $k eq 'text') { $text = delete $data{$k}; } } + # people fields allow multiple values + $v{$_} = vsplit($v{$_}) foreach ( grep $create{lc $_}, @people ); + if ($text) { $v{MIMEObj} = MIME::Entity->build( @@ -96,20 +159,23 @@ else { ); } - $ticket->Create(%v); - unless ($ticket->Id) { - return [ "# Could not create ticket.", [], {}, 1 ]; + my($tid,$trid,$terr) = $ticket->Create(%v); + unless ($tid) { + push(@comments, "# Could not create ticket."); + push(@comments, "# " . $terr); + goto DONE; } delete $data{id}; $id = $ticket->Id; push(@comments, "# Ticket $id created."); - goto DONE if %data == 0; + # see if the hash is empty + goto DONE if ! keys(%data); } } # Now we know we're dealing with an existing ticket. -if (%data == 0) { +if (!keys(%data)) { my ($time, $key, $val, @data); push @data, [ id => "ticket/".$ticket->Id ]; @@ -126,7 +192,7 @@ if (%data == 0) { } foreach $key (@people) { - next unless (!%$fields || (exists $fields->{lc $key})); + next unless (!%$fields || (exists $fields->{lc $key})); push @data, [ $key => [ $ticket->$key->MemberEmailAddresses ] ]; } @@ -141,10 +207,22 @@ if (%data == 0) { foreach $key (qw(TimeEstimated TimeWorked TimeLeft)) { next unless (!%$fields || (exists $fields->{lc $key})); $val = $ticket->$key || 0; - $val = $time->DurationAsString($val*60) if $val; + $val = "$val minutes" if $val; push @data, [ $key => $val ]; } + # Display custom fields + my $CustomFields = $ticket->QueueObj->TicketCustomFields(); + while (my $cf = $CustomFields->Next()) { + next unless (!%$fields || (exists $fields->{"cf-".lc $cf->Name})); + my $vals = $ticket->CustomFieldValues($cf->Id()); + my @out = (); + while (my $v = $vals->Next()) { + push @out, $v->Content; + } + push @data, [ 'CF-' . $cf->Name => join ',', @out ]; + } + my %k = map {@$_} @data; $o = [ map {$_->[0]} @data ]; $k = \%k; @@ -226,6 +304,20 @@ else { $s =~ s/^# //; } } + # Set custom field + elsif ($key =~ /^CF-/i) { + my $cf = RT::CustomField->new( $RT::SystemUser ); + $key =~ s/^CF-//i; + if (not $cf->LoadByName( Name => $key )) { + $n = 0; + $s = "Unknown custom field."; + } + else { + ($n, $s) = $ticket->AddCustomFieldValue( + Field => $cf, Value => $val ); + $s =~ s/^# // if defined $s; + } + } elsif ($key ne 'id' && $key ne 'type' && $key ne 'creator') { $n = 0; $s = "Unknown field."; @@ -250,4 +342,4 @@ DONE: $c ||= join("\n", @comments) if @comments; return [$c, $o, $k, $e]; - +