add ability to remove suffix-ed config items, RT#5218
[freeside.git] / httemplate / config / config-view.cgi
index 534de02..9b5b132 100644 (file)
@@ -59,14 +59,20 @@ Click on a configuration value to change it.
 %   }
 %
 %   my @agents = ();
+%   my @add_agents = ();
 %   if ( $page_agent ) {
 %     @agents = ( $page_agent );
 %   } else {
-%     @agents = (
-%       '',
-%       grep { defined( _config_agentonly($conf, $i->key, $_->agentnum) ) }
-%            @all_agents
-%     );
+%     @agents = ( '' );
+%     if ( $i->per_agent ) {
+%       foreach my $agent (@all_agents) {
+%         if ( defined(_config_agentonly($conf, $i->key, $agent->agentnum)) ) {
+%           push @agents, $agent;
+%         } else {
+%           push @add_agents, $agent;
+%         }
+%       }
+%     }
 %   }
 %
 %   foreach my $agent ( @agents ) {
@@ -90,6 +96,19 @@ Click on a configuration value to change it.
                                                  # if $cgi->param('showagent')?
                     )
           %>: <% $i->description %>
+%       if ( $agent && $cgi->param('showagent') ) {
+%         my $confnum =
+%           _config_agentonly($conf, $i->key, $agent->agentnum)->confnum;
+          (<A HREF="javascript:areyousure('delete this agent override', 'config-delete.cgi?confnum=<% $confnum %>;redirect=config_view_showagent')">delete agent override</A>)
+%       } elsif ( $i->base_key ) {
+%         my $confnum =
+%           $agent
+%             ? _config_agentonly($conf, $i->key, $agent->agentnum)->confnum
+%             : $conf->_config( $i->key )->confnum;
+%         my $showagent = $cgi->param('showagent') ? '_showagent' : '';
+          (<A HREF="javascript:areyousure('delete this configuration item', 'config-delete.cgi?confnum=<% $confnum %>;redirect=config_view<%$showagent%>')">delete configuration item</A>)
+%       }
+
       </td>
       <td><table border=0>
 
@@ -199,12 +218,70 @@ Click on a configuration value to change it.
 
 % } # foreach my $agentnum
 
+% if ( @add_agents ) {
+
+  <tr>
+    <td>
+      <FORM>
+      Add <b><% $i->key %></b> override for
+        <% include('/elements/select-agent.html',
+                     'agents'      => \@add_agents,
+                     'empty_label' => 'Select agent',
+                     'onchange'    => "agent_changed",
+                     'id'          => 'agent_'. $i->key,
+                  )
+        %>
+      agent
+
+%     my $agent_el = "document.getElementById('agent_". $i->key. "')";
+      <INPUT TYPE    = "button"
+             VALUE   = "Add"
+             ID      = "add_<% $i->key %>"
+             DISABLED
+             onClick = "<%
+               include('/elements/popup_link_onclick.html',
+                         'action'      =>
+                           'config.cgi?key='.      $i->key.
+                           ";agentnum=' + ".
+                             "$agent_el.options[$agent_el.selectedIndex].value".
+                             " + '",
+                         'width'       => $width,
+                         'height'      => $height,
+                         'actionlabel' => 'Enter configuration value',
+                      )
+             %>"
+      >
+      </FORM>
+    </td>
+  </tr>
+
+% } #if @add_agents
+
 % } # foreach my $i
 
   </table><br><br>
 
 % } # foreach my $nav_section
 
+<SCRIPT TYPE="text/javascript">
+
+  function agent_changed(what) {
+    var key = what.id.substring(6); // trim agent_
+    var button = document.getElementById('add_'+key);
+    if ( what.selectedIndex > 0 ) {
+      button.disabled = false;
+    } else {
+      button.disabled = true;
+    }
+  }
+
+  function areyousure(what, href) {
+    if ( confirm("Are you sure you want to " + what + "?") == true )
+      window.location.href = href;
+  }
+
+</SCRIPT>
+
 </body></html>
 <%once>
 
@@ -240,7 +317,6 @@ if ($cgi->param('agentnum') =~ /^(\d+)$/) {
 my $conf = new FS::Conf;
  
 my @config_items = grep { $page_agent ? $_->per_agent : 1 }
-                   grep { $_->key != ~/^invoice_(html|latex|template)/ }
                         $conf->config_items; 
 
 my @sections = qw(required billing username password UI session shell BIND );