f36d7d8789d521fb175a3be89346a257204b3bd1
[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
6   var bgcolor1 = '#eeeeee';
7   var bgcolor2 = '#ffffff';
8   var sticky_color = { '#eeeeee' : '#ffff66',
9                        '#ffffff' : '#ffffb8' };
10   var notes_bgcolor = '';
11
12   var trs = document.getElementsByTagName("TR");
13   for (var i=0; i < trs.length; i++) {
14     if (trs[i].id.length > 6 && trs[i].id.substring(0,6) == 'notes_') {
15       if (( classnum == '-1' ) || ( trs[i].getAttribute('data-classnum') == classnum )) {
16         trs[i].style.display = 'table-row';
17         if ( notes_bgcolor == bgcolor1 ) {
18           notes_bgcolor = bgcolor2;
19         } else {
20           notes_bgcolor = bgcolor1;
21         }
22         trs[i].style.backgroundColor = (trs[i].getAttribute('data-sticky') == '1') ? sticky_color[notes_bgcolor] : notes_bgcolor;
23       } else {
24         trs[i].style.display = 'none';
25       }
26     }
27   }
28 %   if ($note_classes_conf) {
29
30   var as = document.getElementsByTagName("a");
31   for (var i=0; i < as.length; i++) {
32     if(as[i].id.length > 14 && as[i].id.substring(0,14) == 'notes_tablink_') {
33       if(as[i].id == 'notes_tablink_'+classnum) {
34         as[i].style.fontWeight = 'bold';
35       } else {
36         as[i].style.fontWeight = 'normal';
37       }
38     }
39   }
40 %   } # if note_classes_conf
41
42 }
43
44 </SCRIPT>
45
46   <& /elements/init_overlib.html &>
47
48 % if ( $note_classes_conf ) {
49 <% mt('Show notes of class:') |h %> &nbsp; 
50 %   # list unclassified last
51 %       foreach my $classnum ( (grep { $_ != 0} sort { $a <=> $b } (keys %classes)), '0' ) {
52             <A  id="notes_tablink_<% $classnum %>"
53                 HREF="javascript:display_notes_classnum(<% $classnum %>)"
54                 style="font-weight: <% $classnum == -1 ? 'bold' : 'normal' %>"
55             ><% $classes{$classnum} %></A>
56 %       }
57     <BR>
58 % }
59
60 <& /elements/table-grid.html &>
61   <TR>
62     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Date') |h %></TH>
63 %   if ( $conf->exists('cust_main_note-display_times') ) {
64     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Time') |h %></TH>
65 %   }
66     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Employee') |h %></TH>
67 %   if ($note_classes_conf) {
68     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Class') |h %></TH>
69 %   }
70     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Note') |h %></TH>
71 %   if ($curuser->access_right('Edit customer note') ) {
72     <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em">&nbsp;</TH>
73 %   }
74   </TR>
75
76 % } # end if @notes
77
78 % foreach my $note (@notes) {
79 %
80 %   my $pop = popurl(3);
81 %   my $notenum = $note->notenum;
82 %   my $onclick = include( '/elements/popup_link_onclick.html',
83 %                            'action'      => popurl(2).
84 %                                             'edit/cust_main_note.cgi'.
85 %                                             "?custnum=$custnum".
86 %                                             ";notenum=$notenum",
87 %                            'actionlabel' => emt('Edit customer note'),
88 %                            'width'       => 616,
89 %                            'height'      => 575,
90 %                            'frame'       => 'top',
91 %                        );
92 %   my $clickjs = qq!onclick="$onclick"!;
93 %
94 %   my $edit = '';
95 %   if ($curuser->access_right('Edit customer note') ) {
96 %     my $delete_url = $fsurl.'misc/delete-note.html?'.$notenum;
97 %     $edit = qq! <A HREF="javascript:void(0);" $clickjs>(!.emt('edit').')</A>'.
98 %             qq! <A HREF="$delete_url" !.
99 %             qq! onclick="return confirm('Delete this note?')">!.
100 %             '('.emt('delete').')</A>';
101 %   }
102 %
103     <TR ID="notes_<% $note->notenum %>"
104         data-sticky="<% $note->sticky ? 1 : 0 %>"
105         <% $note_classes_conf ? ' data-classnum="'.($note->classnum || 0).'"' : '' %>>
106
107       <% note_datestr($note,$conf) %>
108       <TD CLASS="grid">
109         &nbsp;<% $note->usernum ? $note->access_user->name : $note->otaker %>
110       </TD>
111 %   if ($note_classes_conf) {
112       <TD CLASS="grid">
113         <% $note->classname %>   
114       </TD>
115 %   }
116       <TD CLASS="grid">
117         <% $note->comments | defang %>
118       </TD>
119 %   if ($edit) {
120       <TD CLASS="grid"><% $edit %></TD>
121 %   }
122     </TR>
123 % } #end foreach note
124
125 </TABLE>
126
127 <SCRIPT>display_notes_classnum('-1')</SCRIPT>
128
129 <%init>
130
131 use HTML::Defang;
132
133 my $conf = new FS::Conf;
134 my $curuser = $FS::CurrentUser::CurrentUser;
135
136 my(%opt) = @_;
137
138 my $cust_main = $opt{'cust_main'};
139 my $custnum = $cust_main->custnum;
140
141 my $note_classes_conf = $conf->exists('note-classes') ? $conf->config('note-classes') : '';
142
143 my (@notes) = $cust_main->notes();
144
145 my %classes = map { ($_->classnum || 0) => ( $_->classname ne '' ? $_->classname : '('.emt('unclassified').')' ) } @notes;
146 $classes{'-1'} = 'All';
147
148 #subroutines
149
150 sub note_datestr {
151   my($note, $conf) = @_ or return '';
152   my $td = qq{<TD CLASS="grid" ALIGN="right">};
153   my $format = "$td%b&nbsp;%o,&nbsp;%Y</TD>";
154   $format .= "$td%l:%M%P</TD>"
155     if $conf->exists('cust_main_note-display_times');
156   ( my $strip = time2str($format, $note->_date) ) =~ s/ (\d)/$1/g;
157   $strip;
158 }
159
160 </%init>