[freeside-commits] branch FREESIDE_3_BRANCH updated. 84919ed60de29dc4ccf42d7930c6178eedc51f36

Mark Wells mark at 420.am
Sat Nov 16 18:22:48 PST 2013


The branch, FREESIDE_3_BRANCH has been updated
       via  84919ed60de29dc4ccf42d7930c6178eedc51f36 (commit)
      from  7af50f45c514a0e9ae27c60b7aa6e9b3c8b48557 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 84919ed60de29dc4ccf42d7930c6178eedc51f36
Author: Mark Wells <mark at freeside.biz>
Date:   Sat Nov 16 18:22:29 2013 -0800

    UI to disable message templates, #26035

diff --git a/FS/FS/part_event/Action/letter.pm b/FS/FS/part_event/Action/letter.pm
index 57b7b77..835dec2 100644
--- a/FS/FS/part_event/Action/letter.pm
+++ b/FS/FS/part_event/Action/letter.pm
@@ -20,6 +20,7 @@ sub option_fields {
                   'type'     => 'select-table',
                   'table'    => 'msg_template',
                   'name_col' => 'msgname',
+                  'hashref'  => { disabled => '' },
                   'disable_empty' => 1,
                 },
   );
diff --git a/FS/FS/part_event/Action/notice.pm b/FS/FS/part_event/Action/notice.pm
index 8e22c68..7c8ed16 100644
--- a/FS/FS/part_event/Action/notice.pm
+++ b/FS/FS/part_event/Action/notice.pm
@@ -19,6 +19,7 @@ sub option_fields {
     'msgnum' => { 'label'    => 'Template',
                   'type'     => 'select-table',
                   'table'    => 'msg_template',
+                  'hashref'  => { disabled => '' },
                   'name_col' => 'msgname',
                   'disable_empty' => 1,
                 },
diff --git a/FS/FS/part_event/Action/notice_to.pm b/FS/FS/part_event/Action/notice_to.pm
index 194aeb8..d300e33 100644
--- a/FS/FS/part_event/Action/notice_to.pm
+++ b/FS/FS/part_event/Action/notice_to.pm
@@ -24,6 +24,7 @@ sub option_fields {
                   'type'     => 'select-table',
                   'table'    => 'msg_template',
                   'name_col' => 'msgname',
+                  'hashref'  => { disabled => '' },
                   'disable_empty' => 1,
                 },
   );
diff --git a/FS/FS/part_event/Action/svc_acct_notice.pm b/FS/FS/part_event/Action/svc_acct_notice.pm
index d71a137..97a4ad6 100644
--- a/FS/FS/part_event/Action/svc_acct_notice.pm
+++ b/FS/FS/part_event/Action/svc_acct_notice.pm
@@ -18,6 +18,7 @@ sub option_fields {
                   'type'     => 'select-table',
                   'table'    => 'msg_template',
                   'name_col' => 'msgname',
+                  'hashref'  => { disabled => '' },
                   'disable_empty' => 1,
                 },
   );
diff --git a/FS/FS/part_export/rt_ticket.pm b/FS/FS/part_export/rt_ticket.pm
index 7ae6105..72e387c 100644
--- a/FS/FS/part_export/rt_ticket.pm
+++ b/FS/FS/part_export/rt_ticket.pm
@@ -21,7 +21,7 @@ my %template_select = (
     %templates = (0 => '',
       map { $_->msgnum, $_->msgname } 
       qsearch({ table => 'msg_template',
-                hashref => {},
+                hashref => { disabled => '' },
                 order_by => 'ORDER BY msgnum ASC'
               })
     );
diff --git a/FS/FS/part_export/send_email.pm b/FS/FS/part_export/send_email.pm
index 6ba131f..1fcb828 100644
--- a/FS/FS/part_export/send_email.pm
+++ b/FS/FS/part_export/send_email.pm
@@ -21,7 +21,7 @@ my %template_select = (
     %templates = (0 => '',
       map { $_->msgnum, $_->msgname } 
       qsearch({ table => 'msg_template',
-                hashref => {},
+                hashref => { disabled => 1 },
                 order_by => 'ORDER BY msgnum ASC'
               })
     );
diff --git a/httemplate/browse/msg_template.html b/httemplate/browse/msg_template.html
index bb5ac94..ef0b2da 100644
--- a/httemplate/browse/msg_template.html
+++ b/httemplate/browse/msg_template.html
@@ -5,14 +5,15 @@
               'query'         => { 'table' => 'msg_template', },
               'count_query'   => 'SELECT COUNT(*) FROM msg_template',
               'disableable'   => 1,
-              'disabled_statuspos' => 2,
+              'disabled_statuspos' => (scalar(@locales) + 3),
               'agent_virt'         => 1,
               'agent_null_right'   => ['View global templates','Edit global templates'],
               'agent_pos'          => 1,
-              'header'     => [ 'Name', '', map '', @locales ],
-              'fields'     => [ 'msgname', @locales ],
-              'links'      => [ $link, @locale_links ],
-              'cell_style' => [ '', '', map $locale_style, @locales ],
+              'header'      => [ 'Name', '', map ('', @locales), '' ],
+              'fields'      => [ 'msgname', @locales, $disable_link_label ],
+              'links'       => [ $link, @locale_links, '' ],
+              'link_onclicks' => [ '', map('', @locale_links), $disable_link ],
+              'cell_style'    => [ '', '', map ($locale_style, @locales), $locale_style ],
           )
 %>
 <%init>
@@ -30,7 +31,7 @@ if ( $curuser->access_right(['Edit templates', 'Edit global templates']) ) {
 
 my $link = [ "${p}edit/msg_template.html?msgnum=", 'msgnum' ];
 
-my $locale_style = 'font-size:0.8em; padding:3px; background-color:';
+my $locale_style = 'font-size:0.8em; padding:3px';
 
 my (@locales, @locale_links);
 foreach my $l ( FS::Locales->locales ) {
@@ -44,6 +45,20 @@ foreach my $l ( FS::Locales->locales ) {
     [ "${p}edit/msg_template.html?locale=$l;msgnum=", 'msgnum' ];
   };
 }
-    
+
+my $disable_link = sub {
+  my $template = shift;
+  include('/elements/popup_link_onclick.html',
+    action      => $p.'misc/disable-msg_template.cgi?msgnum=' .
+                     $template->msgnum .
+                     ($template->disabled ? ';enable=1' : ''),
+    actionlabel => 'Disable lemplate',
+  );
+};
+
+my $disable_link_label = sub {
+  my $template = shift;
+  $template->disabled ? '(enable)' : '(disable)' ;
+};
 
 </%init>
diff --git a/httemplate/misc/disable-msg_template.cgi b/httemplate/misc/disable-msg_template.cgi
new file mode 100644
index 0000000..1eb4d25
--- /dev/null
+++ b/httemplate/misc/disable-msg_template.cgi
@@ -0,0 +1,77 @@
+% if ( @error ) {
+<& /elements/errorpage-popup.html, @error &>
+% } else {
+<& /elements/header-popup.html, "Template ${actioned}" &>
+  <SCRIPT TYPE="text/javascript">
+    window.top.location.reload();
+  </SCRIPT>
+</BODY>
+</HTML>
+% }
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+my $conf = FS::Conf->new;
+my @error;
+my $actioned;
+
+die "access denied"
+  unless $curuser->access_right([ 'Edit templates', 'Edit global templates' ]);
+
+my $msgnum = $cgi->param('msgnum');
+$msgnum =~ /^\d+$/ or die "bad msgnum '$msgnum'";
+my $msg_template = qsearchs({
+  table     => 'msg_template',
+  hashref   => { msgnum => $msgnum },
+  extra_sql => ' AND '.
+    $curuser->agentnums_sql(null_right => 'Edit global templates'),
+});
+die "unknown msgnum $msgnum" unless $msg_template;
+
+if ( $cgi->param('enable') ) {
+  $actioned = 'enabled';
+  $msg_template->set('disabled' => '');
+} else {
+  $actioned = 'disabled';
+  # make sure it's not in use anywhere
+  my @inuse;
+
+  # notice, letter, notice_to events (if they're enabled)
+  my @events = qsearch({
+    table     => 'part_event_option',
+    addl_from => ' JOIN part_event USING (eventpart)',
+    hashref   => {
+      optionname => 'msgnum',
+      optionvalue => $msgnum,
+    },
+    extra_sql => ' AND disabled IS NULL',
+  });
+  push @inuse, map {"Billing event #".$_->eventpart} @events;
+
+  # send_email and rt_ticket exports
+  my @exports = qsearch( 'part_export_option', {
+    optionname => { op => 'LIKE', value => '%_template' },
+    optionvalue => $msgnum,
+  });
+  push @inuse, map {"Export #".$_->exportnum} @exports;
+
+  # payment_receipt_msgnum, decline_msgnum, etc.
+  my @confs = qsearch( 'conf', {
+    name => { op => 'LIKE', value => '%_msgnum' },
+    value => $msgnum,
+  });
+  push @inuse, map {"Configuration setting ".$_->name} @confs;
+  # XXX pending queue jobs?
+  if (@inuse) {
+    @error = ("This template is in use.  Check the following settings:",
+              @inuse);
+  }
+
+  # good to go
+  $msg_template->set(disabled => 'Y');
+}
+if (!@error) {
+  my $error = $msg_template->replace;
+  push @error, $error if $error;
+}
+</%init>
diff --git a/httemplate/misc/email-customers.html b/httemplate/misc/email-customers.html
index ad67b8d..3b2ac3c5 100644
--- a/httemplate/misc/email-customers.html
+++ b/httemplate/misc/email-customers.html
@@ -98,6 +98,7 @@ Template:
     <% include('/elements/select-table.html',
                   'label'         => 'Template:',
                   'table'         => 'msg_template',
+                  'hashref'       => { disabled => '' },
                   'name_col'      => 'msgname',
                   'empty_label'   => '(none)',
                   'onchange'      => 'toggle(this)',

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/part_event/Action/letter.pm          |    1 +
 FS/FS/part_event/Action/notice.pm          |    1 +
 FS/FS/part_event/Action/notice_to.pm       |    1 +
 FS/FS/part_event/Action/svc_acct_notice.pm |    1 +
 FS/FS/part_export/rt_ticket.pm             |    2 +-
 FS/FS/part_export/send_email.pm            |    2 +-
 httemplate/browse/msg_template.html        |   29 ++++++++---
 httemplate/misc/disable-msg_template.cgi   |   77 ++++++++++++++++++++++++++++
 httemplate/misc/email-customers.html       |    1 +
 9 files changed, 106 insertions(+), 9 deletions(-)
 create mode 100644 httemplate/misc/disable-msg_template.cgi




More information about the freeside-commits mailing list