summaryrefslogtreecommitdiff
path: root/httemplate/view/cust_main/notes/notes.html
blob: f36d7d8789d521fb175a3be89346a257204b3bd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
% if ( scalar(@notes) ) {
<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';
      }
    }
  }
%   } # if note_classes_conf

}

</SCRIPT>

  <& /elements/init_overlib.html &>

% if ( $note_classes_conf ) {
<% 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 %>"
		HREF="javascript:display_notes_classnum(<% $classnum %>)"
		style="font-weight: <% $classnum == -1 ? 'bold' : 'normal' %>"
	    ><% $classes{$classnum} %></A>
% 	}
    <BR>
% }

<& /elements/table-grid.html &>
  <TR>
    <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Date') |h %></TH>
%   if ( $conf->exists('cust_main_note-display_times') ) {
    <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Time') |h %></TH>
%   }
    <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em"><% mt('Employee') |h %></TH>
%   if ($note_classes_conf) {
    <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>
%   if ($curuser->access_right('Edit customer note') ) {
    <TH CLASS="grid" BGCOLOR="#cccccc" STYLE="padding: 0 1em">&nbsp;</TH>
%   }
  </TR>

% } # end if @notes

% foreach my $note (@notes) {
%
%   my $pop = popurl(3);
%   my $notenum = $note->notenum;
%   my $onclick = include( '/elements/popup_link_onclick.html',
%                            'action'      => popurl(2).
%                                             'edit/cust_main_note.cgi'.
%                                             "?custnum=$custnum".
%                                             ";notenum=$notenum",
%                            'actionlabel' => emt('Edit customer note'),
%                            'width'       => 616,
%                            'height'      => 575,
%                            'frame'       => 'top',
%                        );
%   my $clickjs = qq!onclick="$onclick"!;
%
%   my $edit = '';
%   if ($curuser->access_right('Edit customer note') ) {
%     my $delete_url = $fsurl.'misc/delete-note.html?'.$notenum;
%     $edit = qq! <A HREF="javascript:void(0);" $clickjs>(!.emt('edit').')</A>'.
%             qq! <A HREF="$delete_url" !.
%             qq! onclick="return confirm('Delete this note?')">!.
%             '('.emt('delete').')</A>';
%   }
%
    <TR ID="notes_<% $note->notenum %>"
        data-sticky="<% $note->sticky ? 1 : 0 %>"
        <% $note_classes_conf ? ' 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) {
      <TD CLASS="grid">
	<% $note->classname %>   
      </TD>
%   }
      <TD CLASS="grid">
        <% $note->comments | defang %>
      </TD>
%   if ($edit) {
      <TD CLASS="grid"><% $edit %></TD>
%   }
    </TR>
% } #end foreach note

</TABLE>

<SCRIPT>display_notes_classnum('-1')</SCRIPT>

<%init>

use HTML::Defang;

my $conf = new FS::Conf;
my $curuser = $FS::CurrentUser::CurrentUser;

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;
$classes{'-1'} = 'All';

#subroutines

sub note_datestr {
  my($note, $conf) = @_ or return '';
  my $td = qq{<TD CLASS="grid" ALIGN="right">};
  my $format = "$td%b&nbsp;%o,&nbsp;%Y</TD>";
  $format .= "$td%l:%M%P</TD>"
    if $conf->exists('cust_main_note-display_times');
  ( my $strip = time2str($format, $note->_date) ) =~ s/ (\d)/$1/g;
  $strip;
}

</%init>