[freeside-commits] freeside/httemplate/config config-view.cgi, 1.26, 1.27 config-process.cgi, 1.16, 1.17

Ivan,,, ivan at wavetail.420.am
Thu Apr 30 18:07:48 PDT 2009


Update of /home/cvs/cvsroot/freeside/httemplate/config
In directory wavetail.420.am:/tmp/cvs-serv1392

Modified Files:
	config-view.cgi config-process.cgi 
Log Message:
add ability to edit the agent overrides from the main config, RT#4218

Index: config-process.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/config/config-process.cgi,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- config-process.cgi	17 Apr 2009 08:02:29 -0000	1.16
+++ config-process.cgi	1 May 2009 01:07:45 -0000	1.17
@@ -65,7 +65,7 @@
   <SCRIPT TYPE="text/javascript">
 %   my $n = 0;
 %   foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
-    var configCell = window.top.document.getElementById('<% $i->key. $n %>');
+    var configCell = window.top.document.getElementById('<% $agentnum. $i->key. $n %>');
     //alert('found cell ' + configCell);
 %     if (    $type eq 'textarea'
 %          || $type eq 'editlist'

Index: config-view.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/config/config-view.cgi,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- config-view.cgi	17 Apr 2009 08:02:29 -0000	1.26
+++ config-view.cgi	1 May 2009 01:07:45 -0000	1.27
@@ -3,6 +3,21 @@
 Click on a configuration value to change it.
 <BR><BR>
 
+% unless ( $page_agent ) {
+%
+%   if ( $cgi->param('showagent') ) {
+%     $cgi->param('showagent', 0);
+      ( <a href="<% $cgi->self_url %>">hide agent overrides</a> )
+%     $cgi->param('showagent', 1);
+%   } else {
+%     $cgi->param('showagent', 1);
+      ( <a href="<% $cgi->self_url %>">show agent overrides</a> )
+%     $cgi->param('showagent', 0);
+%   }
+%
+% }
+<BR><BR>
+
 <% include('/elements/init_overlib.html') %>
 
 % if ($FS::UID::use_confcompat) {
@@ -42,6 +57,26 @@
 %     #$width =
 %     #$height = 
 %   }
+%
+%   my @agents = ();
+%   if ( $page_agent ) {
+%     @agents = ( $page_agent );
+%   } else {
+%     @agents = (
+%       '',
+%       grep { defined( _config_agentonly($conf, $i->key, $_->agentnum) ) }
+%            @all_agents
+%     );
+%   }
+%
+%   foreach my $agent ( @agents ) {
+%     my $agentnum = $agent ? $agent->agentnum : '';
+%
+%     my $label = $i->key;
+%     $label = '['. $agent->agent. "] $label"
+%       if $agent && $cgi->param('showagent');
+%
+%     #indentation :/
 
     <tr>
       <td><% include('/elements/popup_link.html',
@@ -50,8 +85,9 @@
                        'width'       => $width,
                        'height'      => $height,
                        'actionlabel' => 'Enter configuration value',
-                       'label'       => '<b>'. $i->key. '</b>',
-                       'aname'       => $i->key,
+                       'label'       => "<b>$label</b>",
+                       'aname'       => $i->key, #agentnum
+                                                 # if $cgi->param('showagent')?
                     )
           %>: <% $i->description %>
       </td>
@@ -102,21 +138,19 @@
 %             || $type eq 'selectmultiple' ) { 
 
             <tr>
-              <td id="<% $i->key.$n %>" bgcolor="#ffffff">
-<font size="-2"><pre>
-<% encode_entities(join("\n",
+              <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
+<font size="-2"><pre><% encode_entities(join("\n",
      map { length($_) > 88 ? substr($_,0,88).'...' : $_ }
          $conf->config($i->key, $agentnum)
    ) )
-%>
-</pre></font>
+%></pre></font>
               </td>
             </tr>
 
 %   } elsif ( $type eq 'checkbox' ) {
 
             <tr>
-              <td id="<% $i->key.$n %>" bgcolor="#<% $conf->exists($i->key, $agentnum) ? '00ff00">YES' : 'ff0000">NO' %></td>
+              <td id="<% $agentnum.$i->key.$n %>" bgcolor="#<% $conf->exists($i->key, $agentnum) ? '00ff00">YES' : 'ff0000">NO' %></td>
             </tr>
 
 %   } elsif ( $type eq 'select' && $i->select_hash ) {
@@ -129,7 +163,7 @@
 %     }
 
             <tr>
-              <td id="<% $i->key.$n %>" bgcolor="#ffffff">
+              <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
                 <% $conf->exists($i->key, $agentnum) ? $hash{ $conf->config($i->key, $agentnum) } : '' %>
               </td>
             </tr>
@@ -137,7 +171,7 @@
 %   } elsif ( $type eq 'text' || $type eq 'select' ) {
 
             <tr>
-              <td id="<% $i->key.$n %>" bgcolor="#ffffff">
+              <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
                 <% $conf->exists($i->key, $agentnum) ? $conf->config($i->key, $agentnum) : '' %>
               </td>
             </tr>
@@ -145,7 +179,7 @@
 %   } elsif ( $type eq 'select-sub' ) { 
 
             <tr>
-              <td id="<% $i->key.$n %>" bgcolor="#ffffff">
+              <td id="<% $agentnum.$i->key.$n %>" bgcolor="#ffffff">
                 <% $conf->config($i->key, $agentnum) %>: 
                 <% &{ $i->option_sub }( $conf->config($i->key, $agentnum) ) %>
               </td>
@@ -162,35 +196,50 @@
 
       </table></td>
     </tr>
-% } 
+
+% } # foreach my $agentnum
+
+% } # foreach my $i
 
   </table><br><br>
-% } 
 
+% } # foreach my $nav_section
 
 </body></html>
+<%once>
+
+#should probably be a Conf method.  what else would need to use it?
+sub _config_agentonly {
+  my($self,$name,$agentnum)=@_;
+  my $hashref = { 'name' => $name };
+  $hashref->{agentnum} = $agentnum;
+  local $FS::Record::conf = undef;  # XXX evil hack prevents recursion
+  FS::Record::qsearchs('conf', $hashref);
+}
+
+</%once>
 <%init>
 
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
 
-my $agentnum = '';
+my $page_agent = '';
 my $title;
 my @menubar = ();
 if ($cgi->param('agentnum') =~ /^(\d+)$/) {
-  $agentnum = $1;
-  my $agent = qsearchs('agent', { 'agentnum' => $agentnum } );
-  die "Agent $agentnum not found!" unless $agent;
+  my $page_agentnum = $1;
+  $page_agent = qsearchs('agent', { 'agentnum' => $page_agentnum } );
+  die "Agent $page_agentnum not found!" unless $page_agent;
 
   push @menubar, 'View all agents' => $p.'browse/agent.cgi';
-  $title = 'Agent Configuration for '. $agent->agent;
+  $title = 'Agent Configuration for '. $page_agent->agent;
 } else {
   $title = 'Global Configuration';
 }
 
 my $conf = new FS::Conf;
  
-my @config_items = grep { $agentnum ? $_->per_agent : 1 }
+my @config_items = grep { $page_agent ? $_->per_agent : 1 }
                    grep { $_->key != ~/^invoice_(html|latex|template)/ }
                         $conf->config_items; 
 
@@ -204,4 +253,10 @@
 
 @sections = grep scalar( @{ $section_items{$_} } ), @sections;
 
+my @all_agents = ();
+if ( $cgi->param('showagent') ) {
+  @all_agents = qsearch('agent', { 'disabled' => '' } );
+}
+warn 'all agents: '. join('-', @all_agents);
+
 </%init>



More information about the freeside-commits mailing list