72901: OFM Freeside Note Classes [v3 merge jquery/conf refactor]
authorJonathan Prykop <jonathan@freeside.biz>
Mon, 24 Oct 2016 08:51:26 +0000 (03:51 -0500)
committerJonathan Prykop <jonathan@freeside.biz>
Tue, 25 Oct 2016 04:31:27 +0000 (23:31 -0500)
FS/FS/Conf.pm
FS/FS/cust_main_note.pm
httemplate/edit/cust_main_note.cgi
httemplate/elements/menu.html
httemplate/view/cust_main/notes/notes.html

index 8e07c72..c31a1e1 100644 (file)
@@ -4179,6 +4179,13 @@ and customer address. Include units.',
   },
 
   {
+    'key'         => 'cust_main_note-require_class',
+    'section'     => 'customer_fields',
+    'description' => 'Require customer note classes for customer notes',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'cust_main-ticket_statuses',
     'section'     => 'UI',
     'description' => 'Show tickets with these statuses on the customer view page.',
@@ -5744,10 +5751,14 @@ and customer address. Include units.',
 
   {
     'key'         => 'note-classes',
-    'section'     => 'UI',
-    'description' => 'Use customer note classes',
+    'section'     => 'deprecated',
+    'description' => 'Use customer note classes (now automatically used if classes are defined)',
     'type'        => 'select',
-    'select_enum' => [ '', 'Enabled', 'Required' ],
+    'select_hash' => [
+                       0 => 'Disabled',
+                      1 => 'Enabled',
+                      2 => 'Enabled, with tabs',
+                    ],
   },
 
   {
index 1723951..f637c35 100644 (file)
@@ -121,8 +121,7 @@ sub check {
   if (!$self->classnum) {
     my $conf = new FS::Conf;
     return 'Note class is required'
-      if $conf->exists('note-classes')
-        and $conf->config('note-classes') eq 'Required';
+      if $conf->exists('cust_main_note-require_class');
   }
 
   $self->SUPER::check;
index 4cf5024..55bd97c 100755 (executable)
@@ -6,17 +6,17 @@
 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
 <INPUT TYPE="hidden" NAME="notenum" VALUE="<% $notenum %>">
 
-% if ($conf->exists('note-classes') && $conf->config('note-classes')) {
-%   my %includeopts = $conf->config('note-classes') eq 'Enabled'
-%                   ? ('empty_label' => '(unclassified)')
-%                   : ('disable_empty' => 1); # eq 'Required'
+% if (my @noteclasses = qsearch('cust_note_class',{ 'disabled' => '' })) {
+%   my %noteclassopts = $conf->exists('cust_main_note-require_class')
+%                     ? ('disable_empty' => 1)
+%                     : ('empty_label' => '(unclassified)');
     Class &nbsp;
        <% include( '/elements/select-table.html',
                  'table'       => 'cust_note_class',
+                 'records'     => \@noteclasses,
                  'name_col'    => 'classname',
                  'curr_value'  => $classnum,
-                 'hashref'     => { 'disabled' => '' },
-                 %includeopts,
+                 %noteclassopts,
          ) %>
     <BR>
 % }
index f8d727e..bd2464a 100644 (file)
@@ -659,8 +659,7 @@ tie my %config_cust, 'Tie::IxHash',
   'Contact types'    =>  [ $fsurl.'browse/contact_class.html', ''], #XXX useful description
 ;
   
-$config_cust{'Note classes'} = [ $fsurl.'browse/cust_note_class.html', 'Note classes define groups of customer notes for reporting.' ]
-    if ($conf->exists('note-classes') && $conf->config('note-classes'));
+$config_cust{'Note classes'} = [ $fsurl.'browse/cust_note_class.html', 'Note classes define groups of customer notes for reporting.' ];
 
 tie my %config_agent, 'Tie::IxHash',
   'Agent types' => [ $fsurl.'browse/agent_type.cgi', 'Agent types define groups of package definitions that you can then assign to particular agents' ],
index ee2dcc6..18a75f7 100644 (file)
@@ -2,60 +2,44 @@
 <SCRIPT TYPE="text/javascript">
 
 function display_notes_classnum (classnum) {
-
-  var bgcolor1 = '#eeeeee';
-  var bgcolor2 = '#ffffff';
-  var sticky_color = { '#eeeeee' : '#ffff66',
-                       '#ffffff' : '#ffffb8' };
-  var notes_bgcolor = '';
-
-  var trs = document.getElementsByTagName("TR");
-  for (var i=0; i < trs.length; i++) {
-    if (trs[i].id.length > 6 && trs[i].id.substring(0,6) == 'notes_') {
-      if (( classnum == '-1' ) || ( trs[i].getAttribute('data-classnum') == classnum )) {
-        trs[i].style.display = 'table-row';
-        if ( notes_bgcolor == bgcolor1 ) {
-          notes_bgcolor = bgcolor2;
-        } else {
-          notes_bgcolor = bgcolor1;
-        }
-        trs[i].style.backgroundColor = (trs[i].getAttribute('data-sticky') == '1') ? sticky_color[notes_bgcolor] : notes_bgcolor;
-      } else {
-        trs[i].style.display = 'none';
-      }
-    }
-  }
-%   if ($note_classes_conf) {
-
-  var as = document.getElementsByTagName("a");
-  for (var i=0; i < as.length; i++) {
-    if(as[i].id.length > 14 && as[i].id.substring(0,14) == 'notes_tablink_') {
-      if(as[i].id == 'notes_tablink_'+classnum) {
-        as[i].style.fontWeight = 'bold';
-      } else {
-        as[i].style.fontWeight = 'normal';
-      }
-    }
+  // hide/show
+  var $custnote = $('.custnote');
+  if (classnum >= 0) {
+    $custnote.hide();
+    $('tr[data-classnum=' + classnum + ']').show();
+  } else {
+    $custnote.show();
   }
-%   } # if note_classes_conf
-
+  // restripe
+  var $shownote = $custnote.filter(':visible');
+  var $shownote_even = $shownote.filter(':even');
+  var $shownote_odd = $shownote.filter(':odd');
+  $shownote_even.css('background-color','#eeeeee');
+  $shownote_even.filter('.stickynote').css('background-color','#ffff66');
+  $shownote_odd.css('background-color','#ffffff');
+  $shownote_odd.filter('.stickynote').css('background-color','#ffffb8');
+%   if ($use_class_tabs) {
+  // update links
+  var $tablink = $('.notes_tablink');
+  $tablink.css('font-weight','normal');
+  $tablink.filter('a[data-classnum=' + classnum + ']').css('font-weight','bold');
+%   }
 }
-
 </SCRIPT>
 
   <& /elements/init_overlib.html &>
 
-% if ( $note_classes_conf ) {
+%   if ( $use_class_tabs ) {
 <% mt('Show notes of class:') |h %> &nbsp; 
 %   # list unclassified last
-%      foreach my $classnum ( (grep { $_ != 0} sort { $a <=> $b } (keys %classes)), '0' ) {
-           <A  id="notes_tablink_<% $classnum %>"
+%        foreach my $classnum ( (grep { $_ != 0} sort { $a <=> $b } (keys %classes)), '0' ) {
+           <A CLASS="notes_tablink"
+        data-classnum="<% $classnum %>"
                HREF="javascript:display_notes_classnum(<% $classnum %>)"
-               style="font-weight: <% $classnum == -1 ? 'bold' : 'normal' %>"
            ><% $classes{$classnum} %></A>
-%      }
+%        }
     <BR>
-% }
+%   }
 
 <& /elements/table-grid.html &>
   <TR>
@@ -64,7 +48,7 @@ function display_notes_classnum (classnum) {
     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Time') |h %></TH>
 %   }
     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Person') |h %></TH>
-%   if ($note_classes_conf) {
+%   if ($use_classes) {
     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Class') |h %></TH>
 %   }
     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Note') |h %></TH>
@@ -100,15 +84,14 @@ function display_notes_classnum (classnum) {
 %             '('.emt('delete').')</A>';
 %   }
 %
-    <TR ID="notes_<% $note->notenum %>"
-        data-sticky="<% $note->sticky ? 1 : 0 %>"
-        <% $note_classes_conf ? ' data-classnum="'.($note->classnum || 0).'"' : '' %>>
+    <TR CLASS="grid custnote<% $note->sticky ? ' stickynote' : '' %>"
+        <% $use_class_tabs ? ' data-classnum="'.($note->classnum || 0).'"' : '' %>>
 
       <% note_datestr($note,$conf) %>
       <TD CLASS="grid">
         &nbsp;<% $note->usernum ? $note->access_user->name : $note->otaker %>
       </TD>
-%   if ($note_classes_conf) {
+%   if ($use_classes) {
       <TD CLASS="grid">
        <% $note->classname %>   
       </TD>
@@ -122,9 +105,13 @@ function display_notes_classnum (classnum) {
     </TR>
 % } #end foreach note
 
+% if (@notes) {
 </TABLE>
 
 <SCRIPT>display_notes_classnum('-1')</SCRIPT>
+% } else {
+<P><I><% emt('No notes for this customer') %></I></P>
+% }
 
 <%init>
 
@@ -138,11 +125,11 @@ my(%opt) = @_;
 my $cust_main = $opt{'cust_main'};
 my $custnum = $cust_main->custnum;
 
-my $note_classes_conf = $conf->exists('note-classes') ? $conf->config('note-classes') : '';
-
 my (@notes) = $cust_main->notes();
 
 my %classes = map { ($_->classnum || 0) => ( $_->classname ne '' ? $_->classname : '('.emt('unclassified').')' ) } @notes;
+my $use_classes = grep { $_ > 0 } keys %classes;  # show class column
+my $use_class_tabs = (keys %classes > 1) ? 1 : 0; # use class tabs
 $classes{'-1'} = 'All';
 
 #subroutines