blib/lib/HTML/EditableTable/Javascript.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 9 | 84 | 10.7 |
branch | 0 | 12 | 0.0 |
condition | 0 | 3 | 0.0 |
subroutine | 3 | 13 | 23.0 |
pod | 0 | 10 | 0.0 |
total | 12 | 122 | 9.8 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package HTML::EditableTable::Javascript; | ||||||
2 | |||||||
3 | 1 | 1 | 8 | use strict; | |||
1 | 2 | ||||||
1 | 50 | ||||||
4 | 1 | 1 | 6 | use warnings; | |||
1 | 2 | ||||||
1 | 39 | ||||||
5 | |||||||
6 | 1 | 1 | 7 | use Carp qw(confess); | |||
1 | 2 | ||||||
1 | 1491 | ||||||
7 | |||||||
8 | =head1 NAME | ||||||
9 | |||||||
10 | HTML::EditableTable::Javascript | ||||||
11 | |||||||
12 | =head1 VERSION | ||||||
13 | |||||||
14 | Version 0.21 | ||||||
15 | |||||||
16 | =cut | ||||||
17 | |||||||
18 | our $Version = '0.21'; | ||||||
19 | |||||||
20 | my $javascriptDisplayCount = 0; | ||||||
21 | |||||||
22 | my %fieldParamJavascriptMap = ( | ||||||
23 | 'tooltip' => \&jsToolTip, | ||||||
24 | 'drillDownTruncate' => \&jsExpandText, | ||||||
25 | 'jsClearColumnOnEdit' => \&jsClearColumnOnEdit, | ||||||
26 | ); | ||||||
27 | |||||||
28 | my %tableParamJavascriptMap = ( | ||||||
29 | 'jsSortHeader' => \&jsSortHeader, | ||||||
30 | ); | ||||||
31 | |||||||
32 | my %formElementTypeJavascriptMap = ( | ||||||
33 | 'calendar' => \&jsCalendar10Setup, | ||||||
34 | ); | ||||||
35 | |||||||
36 | =head1 SYNOPSIS | ||||||
37 | |||||||
38 | This class provides all of the javascript functionality supported in EditableTable. It is designed so that the javascript code used can be easily overridden with local .js files See the documetation in L |
||||||
39 | |||||||
40 | =cut | ||||||
41 | |||||||
42 | $|=1; | ||||||
43 | |||||||
44 | sub new { | ||||||
45 | |||||||
46 | 0 | 0 | 0 | my $class = shift; | |||
47 | 0 | my $parent = shift; # reference to parent EditableTable | |||||
48 | |||||||
49 | 0 | 0 | if (!$parent->isa('HTML::EditableTable')) { confess "parent is not an HTML::EditableTable"; } | ||||
0 | |||||||
50 | |||||||
51 | 0 | my $self= {}; | |||||
52 | 0 | $self->{parent} = $parent; | |||||
53 | 0 | $self->{methods} = []; | |||||
54 | |||||||
55 | 0 | bless $self, $class; | |||||
56 | |||||||
57 | 0 | return $self; | |||||
58 | } | ||||||
59 | |||||||
60 | sub setUid { | ||||||
61 | 0 | 0 | 0 | my $uid = shift; | |||
62 | } | ||||||
63 | |||||||
64 | sub htmlDisplay { | ||||||
65 | |||||||
66 | 0 | 0 | 0 | my $self = shift; | |||
67 | |||||||
68 | # for multiple table case, only print these once | ||||||
69 | |||||||
70 | 0 | print "debug displayCount = $javascriptDisplayCount "; |
|||||
71 | |||||||
72 | 0 | 0 | if (!$javascriptDisplayCount) { | ||||
73 | |||||||
74 | # table field-level javascript support | ||||||
75 | |||||||
76 | 0 | my @potentialJSSupportParams = keys %fieldParamJavascriptMap; | |||||
77 | 0 | my @potentialJSSupportFormElementTypes = keys %formElementTypeJavascriptMap; | |||||
78 | 0 | my @potentialJSSupportTableParams = keys %tableParamJavascriptMap; | |||||
79 | |||||||
80 | # table-param-level javascript | ||||||
81 | |||||||
82 | 0 | foreach my $param (keys %{$self->{parent}}) { | |||||
0 | |||||||
83 | 0 | foreach my $potentialJSSupportTableParam (@potentialJSSupportTableParams) { | |||||
84 | |||||||
85 | 0 | 0 | if (my $mp = $tableParamJavascriptMap{$param}) { | ||||
86 | 0 | print $self->$mp(); | |||||
87 | } | ||||||
88 | } | ||||||
89 | } | ||||||
90 | |||||||
91 | 0 | foreach my $tableField (@{$self->{parent}->{tableFields}}) { | |||||
0 | |||||||
92 | |||||||
93 | # form-element-based javascript | ||||||
94 | 0 | my @remainingJSSupportFormElementTypes = (); | |||||
95 | |||||||
96 | 0 | foreach my $potentialFieldFormElementType (@potentialJSSupportFormElementTypes) { | |||||
97 | |||||||
98 | 0 | 0 | 0 | if ($tableField->{formElement} && $formElementTypeJavascriptMap{$tableField->{formElement}}) { | |||
99 | |||||||
100 | 0 | my $mp = $formElementTypeJavascriptMap{$tableField->{formElement}}; | |||||
101 | 0 | print $self->$mp(); | |||||
102 | } | ||||||
103 | else { | ||||||
104 | 0 | push @remainingJSSupportFormElementTypes, $potentialFieldFormElementType; | |||||
105 | } | ||||||
106 | } | ||||||
107 | 0 | @potentialJSSupportFormElementTypes = @remainingJSSupportFormElementTypes; | |||||
108 | |||||||
109 | |||||||
110 | # param-based javascript | ||||||
111 | |||||||
112 | 0 | my @remainingJSSupportParams = (); | |||||
113 | |||||||
114 | 0 | foreach my $potentialFieldParam (@potentialJSSupportParams) { | |||||
115 | |||||||
116 | 0 | 0 | if ($tableField->{$potentialFieldParam}) { | ||||
117 | 0 | my $mp = $fieldParamJavascriptMap{$potentialFieldParam}; | |||||
118 | 0 | print $self->$mp(); | |||||
119 | } | ||||||
120 | else { | ||||||
121 | 0 | push @remainingJSSupportParams, $potentialFieldParam; | |||||
122 | } | ||||||
123 | } | ||||||
124 | 0 | @potentialJSSupportParams = @remainingJSSupportParams; | |||||
125 | } | ||||||
126 | } | ||||||
127 | |||||||
128 | 0 | $javascriptDisplayCount = 1; | |||||
129 | |||||||
130 | # this method is unique to each table | ||||||
131 | |||||||
132 | 0 | 0 | if ($self->{parent}->isParamSet('jsAddData')) { | ||||
133 | 0 | print $self->jsAddData(); | |||||
134 | } | ||||||
135 | } | ||||||
136 | |||||||
137 | sub resetJavascriptDisplayCount { | ||||||
138 | 0 | 0 | 0 | my $self = shift; | |||
139 | |||||||
140 | 0 | print "reseting display count "; |
|||||
141 | 0 | $javascriptDisplayCount = 0; | |||||
142 | } | ||||||
143 | |||||||
144 | sub jsExpandText { | ||||||
145 | |||||||
146 | 0 | 0 | 0 | my $self = shift; | |||
147 | |||||||
148 | 0 | my $javascript = ""; | |||||
167 | 0 | return $javascript; | |||||
168 | } | ||||||
169 | |||||||
170 | sub jsClearColumnOnEdit { | ||||||
171 | |||||||
172 | 0 | 0 | 0 | my $self = shift; | |||
173 | |||||||
174 | 0 | my $javascript = ""; | |||||
195 | |||||||
196 | 0 | return $javascript; | |||||
197 | } | ||||||
198 | |||||||
199 | sub jsSortHeader { | ||||||
200 | |||||||
201 | 0 | 0 | 0 | my $javascript = ""; | |||
703 | |||||||
704 | 0 | return $javascript; | |||||
705 | } | ||||||
706 | |||||||
707 | sub jsAddData { | ||||||
708 | |||||||
709 | 0 | 0 | 0 | my $self = shift; | |||
710 | |||||||
711 | 0 | my $tableId = $self->{parent}->getTableId(); | |||||
712 | |||||||
713 | 0 | my $javascript = ""; | |||||
779 | 0 | return $javascript; | |||||
780 | } | ||||||
781 | |||||||
782 | sub jsCalendar10Setup { | ||||||
783 | |||||||
784 | 0 | 0 | 0 | my $self = shift; | |||
785 | 0 | my $calendarDir = $self->{parent}->getCalendarDir(); | |||||
786 | |||||||
787 | 0 | my $javascript = "\n"; | |||||
788 | 0 | $javascript .= "\n"; | |||||
789 | 0 | $javascript .= "\n"; | |||||
790 | 0 | $javascript .= "\n"; | |||||
791 | |||||||
792 | 0 | return $javascript; | |||||
793 | } | ||||||
794 | |||||||
795 | sub jsToolTip { | ||||||
796 | |||||||
797 | 0 | 0 | 0 | my $self = shift; | |||
798 | |||||||
799 | 0 | my $javascript = ""; | |||||
942 | |||||||
943 | 0 | return $javascript; | |||||
944 | } | ||||||
945 | |||||||
946 | =head1 COPYRIGHT & LICENSE | ||||||
947 | |||||||
948 | Copyright 2010 Freescale Semiconductor, all rights reserved. | ||||||
949 | |||||||
950 | This program is free software; you can redistribute it and/or modify it | ||||||
951 | under the same terms as Perl itself. | ||||||
952 | |||||||
953 | |||||||
954 | =cut | ||||||
955 | |||||||
956 | 1; # End of HTML::EditableTable::JavaScript |