Repository navigation
Expand file tree
/
Copy pathAjax.pm
More file actions
131 lines (92 loc) · 2.59 KB
/
Copy pathAjax.pm
File metadata and controls
131 lines (92 loc) · 2.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
package WebComponent::Ajax;
# Ajax - component for ajax support
use strict;
use warnings;
use base qw( WebComponent );
use CGI;
use WebApplication;
use Conf;
$CGI::LIST_CONTEXT_WARN = 0;
$CGI::Application::LIST_CONTEXT_WARN = 0;
1;
=pod
=head1 NAME
Ajax - component for ajax support
=head1 DESCRIPTION
WebComponent for a ajax support
=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->{singleton} = 1;
return $self;
}
=item * B<output> ()
Returns the html output of the component.
=cut
sub output {
my ($self) = @_;
if ($self->{output_called}) {
return "";
}
$self->{output_called} = 1;
my $application = $self->application();
my $cgi = $application->cgi();
#my $cgi_url = "$Conf::cgi_url/ajax.cgi";
my $cgi_url;
if ($Conf::nmpdr_site_url or $Conf::force_ajax_to_cgi_url) {
$cgi_url = "$Conf::cgi_url/ajax.cgi";
} else {
$cgi_url = $cgi->url( -rewrite => 0 );
$cgi_url =~ /(.+)\//;
$cgi_url = $1."/ajax.cgi";
$cgi_url =~ s/(http\:\/\/[^\/]+)\:\d+/$1/;
}
# Get the cookie string.
my $cookies = $self->cookie_call() || '0';
# Build the ajax params.
my $html = "<input type='hidden' id='ajax_url' value='" . $cgi_url . "'>\n";
$html .= "<input type='hidden' id='ajax_params' value='page=".$application->page->name()."&app=" . $application->backend->name() . "&url=" . $application->url . "&cookies=" . $cookies . "' />\n";
return $html;
}
sub render {
my ($app, $page, $sub_to_call, $cgi) = @_;
my $application = WebApplication->new( { id => $app, cgi => $cgi } );
$application->check_for_silent_login();
$application->check_for_anonymous_login();
unless (ref($application)) {
return "Could not initialize application";
}
$application->url($cgi->param("url"));
my $page_object = $page->new($application);
$application->page($page_object);
$page_object->init();
my $html = "";
if ($cgi->param('component')) {
my ($component, $id) = split(/\|/, $cgi->param('component'));
my $c = $application->{component_index}->{$id};
eval { $html = $c->$sub_to_call(); };
if ($@) {
print STDERR $@."\n";
}
} else {
$html = $page_object->$sub_to_call();
}
return $html;
}
=item * B<cookie_call> ()
Gets or sets the name of the method to call for setting cookies in the response header.
=cut
sub cookie_call {
my ($self, $name) = @_;
if (defined $name) {
$self->{cookie_call} = $name;
}
return $self->{cookie_call};
}
sub require_javascript {
return ["$Conf::cgi_url/Html/Ajax.js"];
}