rt 4.2.16
[freeside.git] / rt / share / html / Elements / SelectOwnerDropdown
index 5dd6429..ce38159 100644 (file)
@@ -2,7 +2,7 @@
 %#
 %# COPYRIGHT:
 %#
-%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2019 Best Practical Solutions, LLC
 %#                                          <sales@bestpractical.com>
 %#
 %# (Except where explicitly superseded by other copyright notices)
 %if ($DefaultValue) {
 <option value=""<% !$Default ? qq[ selected="selected"] : '' |n %>><%$DefaultLabel |n%></option>
 %}
-% $Default = 0 unless defined $Default && $Default =~ /^\d+$/;
-% my @formatednames = sort {lc $a->[1] cmp lc $b->[1]} map {[$_, $m->scomp('/Elements/ShowUser', User => $_)]} grep { $_->id != RT->Nobody->id } @users;
-% my $nobody = [RT->Nobody, $m->scomp('/Elements/ShowUser', User => RT->Nobody)];
-% unshift @formatednames, $nobody;
 %foreach my $UserRef ( @formatednames)  {
 %my $User = $UserRef->[0];
 <option <% ( $User->Id == $Default) ? qq[ selected="selected"] : '' |n %>
@@ -61,7 +57,7 @@
 %} elsif ($ValueAttribute eq 'Name') {
     value="<%$User->Name%>"
 %}
-><% $UserRef->[1] |n %></option>
+><% $UserRef->[1] %></option>
 %}
 </select>
 <%INIT>
@@ -71,6 +67,7 @@ my $isSU = $session{CurrentUser}
     ->HasRight( Right => 'SuperUser', Object => $RT::System );
 foreach my $object (@$Objects) {
     my $Users = RT::Users->new( $session{CurrentUser} );
+    $Users->LimitToPrivileged;
     $Users->WhoHaveRight(
         Right               => 'OwnTicket',
         Object              => $object,
@@ -81,12 +78,35 @@ foreach my $object (@$Objects) {
         $user_uniq_hash{ $User->Id() } = $User;
     }
 }
+
+my $dropdown_limit = 50;
+$m->callback( CallbackName => 'ModifyDropdownLimit', DropdownLimit => \$dropdown_limit );
+
+if (keys(%user_uniq_hash) > $dropdown_limit ) {
+    if ($Objects->[0]->id) {
+        my $desc = $Objects->[0]->RecordType." ".$Objects->[0]->id;
+        RT->Logger->notice("More than $dropdown_limit possible Owners found for $desc; switching to autocompleter.  See the \$AutocompleteOwners configuration option");
+    }
+    $m->comp("/Elements/SelectOwnerAutocomplete", %ARGS);
+    return;
+}
+
 if ($Default && $Default != RT->Nobody->id && !$user_uniq_hash{$Default}) {
     $user_uniq_hash{$Default} = RT::User->new($session{CurrentUser});
     $user_uniq_hash{$Default}->Load($Default);
 }
+$Default = 0 unless defined $Default && $Default =~ /^\d+$/;
+
+my @formatednames = sort {lc $a->[1] cmp lc $b->[1]}
+                     map {[$_, $_->Format]}
+                    grep { $_->id != RT->Nobody->id }
+                  values %user_uniq_hash;
+
+my $nobody_user = RT::User->new( $session{CurrentUser} );
+$nobody_user->Load( RT->Nobody->id );
+my $nobody = [$nobody_user, $nobody_user->Format];
+unshift @formatednames, $nobody;
 
-my @users = values %user_uniq_hash;
 </%INIT>
 
 <%ARGS>