1 ###########################################################################
3 # Copyright (C) Daniel Guermeur - 1999-2001
4 # Copyright (C) Metadot Corporation - 2001-2005
6 # This file is part of Metadot Portal Server software $Name: Release_6_4_5_4 $
8 # Metadot Portal Server software is free software; you can
9 # redistribute it and/or modify it under the terms of the GNU General Public
10 # License as published by the Free Software Foundation; either version 2 of
11 # the License, or (at your option) any later version.
13 # Metadot Portal Server software is distributed in the hope that it
14 # will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16 # Public License for more details.
18 # You should have received a copy of the GNU General Public License along with
19 # Metadot Portal Server; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # For more information, please contact info@metadot.com.
26 ############################################################################
27 package JavascriptHTML;
32 use CGI qw/escapeHTML unescapeHTML/;
40 use Metadot qw($USER %FORM $SESSION $HTTP_HEADER_SENT $PARAMS);
42 use constant NOTE=>
'<ul><li><b><i>Name</i></b> and <b><i>description</i></b> fields will not appear in normal viewing mode</li>'
43 .
'<li>The script code will only be executed in normal viewing mode, or by clicking on the "Run" button,<br />'
44 .
'and not in editing mode, therefore, you must disable editing to see the result of the code</li></ul>';
46 use constant SAMPLE=>
'<b>The following example code displays an alert box when the page loads:<br /><br /></b>'
47 .
'<script language="JavaScript"><br /> alert("I am alive!");<br />'
48 .
'</script><br />';
50 @ISA=qw(GizmoBuilder);
53 sub customize_permissions {
57 $class->SUPER::customize_permissions($AC);
59 $AC->add_op(
'MOD',
'run_it');
64 return "HTML/Javascript";
67 sub gizmo_list_decorator {
68 return 'HTML::Decorator::NullDecorator';
73 my $args = Utility->coerce_hashref(@_);
74 $self->SUPER::initialize(@_);
76 $self->set_field_info (
77 'name', NOTE.
'<br /><b>Name</b>', 1,
78 'description',
'<b>Description</b>', 0,
79 't1', SAMPLE.
'<br /><b>Code</b>', 1,
82 $self->set_field_type(
't1',
'variabletext', {rows=>35, cols=>120, html_only=>1} );
88 return $self->get_t1();
93 my $iid = $self->get_iid();
94 my $name = $self->get_name();
95 my $description = $self->get_description();
96 my $script = $self->get_script_code();
97 my $buttons = $self->get_buttons();
98 my $run_it = $FORM{
'run_it'};
101 ## Only show name and description when in edit mode
102 if ($USER->is_logged_in() && ($SESSION->admin_mode()) && $self->is_allowed_to_do(
'run_it', $USER)) {
103 $html =
"<p><b>$buttons <b><font size=\"3\">< ></font></b> $name</b>\n";
104 $html .=
"<br />$description\n" if ($description);
108 my $script_size = length $script;
110 $script = escapeHTML($script);
112 if( $script_size > 100 ){
113 $script = substr($script,0,100);
114 $script .=
"<br />...\n";
117 $script =~ s/\n/<br \/>/g;
121 $html .=
"<pre><i><font face=\"courier\">$script</font></i></pre>";
126 $html .=
"$script\n";
138 return $self->show();
141 sub exec_show_summary {
144 return $self->show_summary();
148 # add a 'run code' button.
151 my $id = $self->get_id();
155 $buttons .= $self->SUPER::get_buttons( {add_panel=>$self->get_run_button()});
157 $buttons = $self->SUPER::get_buttons();
164 my $parent = $self->get_navigation_parent();
165 return unless defined($parent);
167 my $parent_id = $parent->get_id();
168 my $parent_isa = $parent->get_is_a();
170 my $id = $self->get_id();
171 my $isa = $self->get_is_a();
174 my $run_it = $FORM{
'run_it'};
176 my $image =
"run.jpg";
181 $href =
"?id=$parent_id&isa=$parent_isa&op=show&run_it=$flag";
182 $win =
"target=\"_blank\"";
188 if ($SESSION->admin_mode()) {
190 my $img_src =
"$PARAMS->{'imageslocation'}/obj/$image";
191 $result =
"<a href=\"$href\" $win><img src=\"$img_src\" class=\"icon\" border=\"0\" /></a>";