Repository navigation
Expand file tree
/
Copy pathCustomAlert.pm
More file actions
188 lines (134 loc) · 3.59 KB
/
Copy pathCustomAlert.pm
File metadata and controls
188 lines (134 loc) · 3.59 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package WebComponent::CustomAlert;
use strict;
use warnings;
use base qw( WebComponent );
1;
=pod
=head1 NAME
TabView - component for a tabular view
=head1 DESCRIPTION
WebComponent for a tabular view
=head1 METHODS
=over 4
=item * B<new> ()
Called when the object is initialized. Expands SUPER::new.
=cut
sub new {
my $self = shift->SUPER::new(@_);
$self->{name} = '';
$self->{title} = '';
$self->{content} = '';
$self->{width} = 300;
$self->{type} = 'alert';
$self->{buttons} = ['Ok', 'Cancel'];
$self->{form} = '';
$self->{onclick} = ['', ''];
return $self;
}
=item * B<output> ()
Returns the html output of the TabView component.
=cut
sub output {
my ($self) = @_;
# must have name
if ($self->name() eq '') {
die "CustomAlert component must have a name";
}
my $html;
$html .= "<div style='width:" . $self->width() . "px; text-align: center;'>";
unless ($self->title() eq '0') {
$html .= "<h2>" . $self->title() . "</h2>";
}
# add content
my $content = $self->content();
$html .= "<div style='margin: 0px 14px;'>$content</div>";
# customize the buttons
my $remove = "removeCustomAlert(); ";
my $type = $self->type();
my $buttons = "<div style='margin: 14px;'>";
if ($type eq 'alert') {
my $onclick = $self->onclick()->[0];
$onclick .= (substr($onclick, -1) eq ";") ? ' ' : '; ' if ($onclick ne '');
$onclick .= $remove;
$buttons .= "<button onclick='$onclick'>" . $self->buttons()->[0] . "</button>";
} elsif ($type eq 'confirm') {
my $form = ($self->form() ne '') ? ("document." . $self->form() . ".submit(); ") : "";
my $onclick1 = $self->onclick()->[0];
$onclick1 .= (substr($onclick1, -1) eq ";") ? ' ' : '; ' if ($onclick1 ne '');
$onclick1 .= $form . $remove;
my $onclick2 = $self->onclick()->[1];
$onclick2 .= (substr($onclick2, -1) eq ";") ? ' ' : '; ' if ($onclick2 ne '');
$onclick2 .= $remove;
my $button1 = "<button onclick='$onclick1'>" . $self->buttons()->[0] . "</button>";
my $button2 = "<button onclick='$onclick2'>" . $self->buttons()->[1] . "</button>";
$buttons .= "$button1 $button2";
} else {
die "Unknown CustomAlert type: $type.";
}
$buttons .= "</div>";
# add buttons
$html .= $buttons;
$html .= "</div>";
# escape quotes
$html =~ s/"/~!/g; #"
return "<img src=\"./Html/clear.gif\" onload=\"CustomAlert['".$self->name()."'] = "$html";\" />";
}
sub title {
my ($self, $title) = @_;
if (defined($title)) {
$self->{title} = $title;
}
return $self->{title};
}
sub content {
my ($self, $content) = @_;
if (defined($content)) {
$self->{content} = $content;
}
return $self->{content};
}
sub width {
my ($self, $width) = @_;
if (defined($width)) {
$self->{width} = $width;
}
return $self->{width};
}
sub type {
my ($self, $type) = @_;
if (defined($type)) {
$self->{type} = $type;
}
return $self->{type};
}
sub buttons {
my ($self, $buttons) = @_;
if (defined($buttons)) {
$self->{buttons} = $buttons;
}
return $self->{buttons};
}
sub form {
my ($self, $form) = @_;
if (defined($form)) {
$self->{form} = $form;
}
return $self->{form};
}
sub onclick {
my ($self, $onclick) = @_;
if (defined($onclick)) {
$self->{onclick} = $onclick;
}
return $self->{onclick};
}
sub name {
my ($self, $name) = @_;
if (defined($name)) {
$self->{name} = $name;
}
return $self->{name};
}
sub require_javascript {
return ["$Conf::cgi_url/Html/CustomAlert.js","$Conf::cgi_url/Html/fade.js"];
}