summaryrefslogtreecommitdiff
path: root/httemplate/elements/tr-select-agent.html
blob: 04600fa8d9461290eebe1daa567c9644e15f1276 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<%doc>

Example:

  include( '/elements/tr-select-agent.html',

    #recommended to keep things "sticky" on errors
    'curr_value'    => $curr_value,

    ##
    # optional
    ##

    'label'         => 'Agent for this thing',
    'empty_label'   => 'Select agent', #override default 
    'disable_empty' => 1,

    #set to 'None' or something to override default of showing all agents
    #for employees w/ 'View customers of all agents' right
    viewall_right   => 'None',

  );

</%doc>
% if ( scalar(@agents) == 1 || $opt{'fixed'} ) { 

  <INPUT TYPE  = "hidden"
         NAME  = "<% $opt{'field'} || 'agentnum' %>"
         ID    = "<% $opt{'field'} || 'agentnum' %>"
         VALUE = "<% $agents[0]->agentnum %>"
  >

%   if ( scalar(@agents) != 1 ) {
      <TR>
        <TH ALIGN="right"><% $opt{'label'} || emt('Agent') %></TD>
        <TD BGCOLOR="#dddddd" <% $colspan %>>
%         my $agent = qsearchs('agent', { 'agentnum' => $agentnum });
          <% $agent ? $agent->agent : '(all)' |h %>
        </TD>
      </TR>

%   } else { # YUCK.  empty row so we don't throw g_row in edit.html off :/
      <TR>
      </TR>
%   }
%
% } else { 

  <TR>
    <TH ALIGN="right"><% $opt{'label'} || emt('Agent') %></TD>
    <TD <% $colspan %>>
      <& /elements/select-agent.html,
                     'curr_value' => $agentnum,
                     'agents'     => \@agents,
                     %opt,
      &>
    </TD>
  </TR>

% } 

<%init>

my %opt = @_;
my $agentnum = $opt{'curr_value'} || $opt{'value'};

my @agents =
  $opt{'agents'}
    ? @{ $opt{'agents'} }
    : $FS::CurrentUser::CurrentUser->agents(
        'viewall_right' => $opt{'viewall_right'},
      );

my $colspan = $opt{'colspan'} ? 'COLSPAN="'.$opt{'colspan'}.'"' : '';

</%init>