18a75f7322a5ad4b39abdddcdd6adeb72a34a025
[freeside.git] / httemplate / view / cust_main / notes / notes.html
1 % if ( scalar(@notes) ) {
2 <SCRIPT TYPE="text/javascript">
3
4 function display_notes_classnum (classnum) {
5   // hide/show
6   var $custnote = $('.custnote');
7   if (classnum >= 0) {
8     $custnote.hide();
9     $('tr[data-classnum=' + classnum + ']').show();
10   } else {
11     $custnote.show();
12   }
13   // restripe
14   var $shownote = $custnote.filter(':visible');
15   var $shownote_even = $shownote.filter(':even');
16   var $shownote_odd = $shownote.filter(':odd');
17   $shownote_even.css('background-color','#eeeeee');
18   $shownote_even.filter('.stickynote').css('background-color','#ffff66');
19   $shownote_odd.css('background-color','#ffffff');
20   $shownote_odd.filter('.stickynote').css('background-color','#ffffb8');
21 %   if ($use_class_tabs) {
22   // update links
23   var $tablink = $('.notes_tablink');
24   $tablink.css('font-weight','normal');
25   $tablink.filter('a[data-classnum=' + classnum + ']').css('font-weight','bold');
26 %   }
27 }
28 </SCRIPT>
29
30   <& /elements/init_overlib.html &>
31
32 %   if ( $use_class_tabs ) {
33 <% mt('Show notes of class:') |h %> &nbsp; 
34 %   # list unclassified last
35 %         foreach my $classnum ( (grep { $_ != 0} sort { $a <=> $b } (keys %classes)), '0' ) {
36             <A CLASS="notes_tablink"
37         data-classnum="<% $classnum %>"
38                 HREF="javascript:display_notes_classnum(<% $classnum %>)"
39             ><% $classes{$classnum} %></A>
40 %         }
41     <BR>
42 %   }
43
44 <& /elements/table-grid.html &>
45   <TR>
46     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Date') |h %></TH>
47 %   if ( $conf->exists('cust_main_note-display_times') ) {
48     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Time') |h %></TH>
49 %   }
50     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Person') |h %></TH>
51 %   if ($use_classes) {
52     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Class') |h %></TH>
53 %   }
54     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Note') |h %></TH>
55 %   if ($curuser->access_right('Edit customer note') ) {
56     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em">&nbsp;</TH>
57 %   }
58   </TR>
59
60 % } # end if @notes
61
62 % foreach my $note (@notes) {
63 %
64 %   my $pop = popurl(3);
65 %   my $notenum = $note->notenum;
66 %   my $onclick = include( '/elements/popup_link_onclick.html',
67 %                            'action'      => popurl(2).
68 %                                             'edit/cust_main_note.cgi'.
69 %                                             "?custnum=$custnum".
70 %                                             ";notenum=$notenum",
71 %                            'actionlabel' => emt('Edit customer note'),
72 %                            'width'       => 616,
73 %                            'height'      => 575,
74 %                            'frame'       => 'top',
75 %                        );
76 %   my $clickjs = qq!onclick="$onclick"!;
77 %
78 %   my $edit = '';
79 %   if ($curuser->access_right('Edit customer note') ) {
80 %     my $delete_url = $fsurl.'misc/delete-note.html?'.$notenum;
81 %     $edit = qq! <A HREF="javascript:void(0);" $clickjs>(!.emt('edit').')</A>'.
82 %             qq! <A HREF="$delete_url" !.
83 %             qq! onclick="return confirm('Delete this note?')">!.
84 %             '('.emt('delete').')</A>';
85 %   }
86 %
87     <TR CLASS="grid custnote<% $note->sticky ? ' stickynote' : '' %>"
88         <% $use_class_tabs ? ' data-classnum="'.($note->classnum || 0).'"' : '' %>>
89
90       <% note_datestr($note,$conf) %>
91       <TD CLASS="grid">
92         &nbsp;<% $note->usernum ? $note->access_user->name : $note->otaker %>
93       </TD>
94 %   if ($use_classes) {
95       <TD CLASS="grid">
96         <% $note->classname %>   
97       </TD>
98 %   }
99       <TD CLASS="grid">
100         <% $note->comments | defang %>
101       </TD>
102 %   if ($edit) {
103       <TD CLASS="grid"><% $edit %></TD>
104 %   }
105     </TR>
106 % } #end foreach note
107
108 % if (@notes) {
109 </TABLE>
110
111 <SCRIPT>display_notes_classnum('-1')</SCRIPT>
112 % } else {
113 <P><I><% emt('No notes for this customer') %></I></P>
114 % }
115
116 <%init>
117
118 use HTML::Defang;
119
120 my $conf = new FS::Conf;
121 my $curuser = $FS::CurrentUser::CurrentUser;
122
123 my(%opt) = @_;
124
125 my $cust_main = $opt{'cust_main'};
126 my $custnum = $cust_main->custnum;
127
128 my (@notes) = $cust_main->notes();
129
130 my %classes = map { ($_->classnum || 0) => ( $_->classname ne '' ? $_->classname : '('.emt('unclassified').')' ) } @notes;
131 my $use_classes = grep { $_ > 0 } keys %classes;  # show class column
132 my $use_class_tabs = (keys %classes > 1) ? 1 : 0; # use class tabs
133 $classes{'-1'} = 'All';
134
135 #subroutines
136
137 sub note_datestr {
138   my($note, $conf) = @_ or return '';
139   my $td = qq{<TD CLASS="grid" ALIGN="right">};
140   my $format = "$td%b&nbsp;%o,&nbsp;%Y</TD>";
141   $format .= "$td%l:%M%P</TD>"
142     if $conf->exists('cust_main_note-display_times');
143   ( my $strip = time2str($format, $note->_date) ) =~ s/ (\d)/$1/g;
144   $strip;
145 }
146
147 </%init>