[svn:p5ee] r8676 - p5ee/trunk/App-Widget-JSApp/lib/App/Widget

[email protected]
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
Author: spadkins
Date: Mon Jan 22 11:41:33 2007
New Revision: 8676

Modified:
   p5ee/trunk/App-Widget-JSApp/lib/App/Widget/JSApp.pm

Log:
add support for {jsapp_hidden}, necessary for stateVariable support in js-app. (needed to maintain state for Trees)

Modified: p5ee/trunk/App-Widget-JSApp/lib/App/Widget/JSApp.pm
==============================================================================
--- p5ee/trunk/App-Widget-JSApp/lib/App/Widget/JSApp.pm	(original)
+++ p5ee/trunk/App-Widget-JSApp/lib/App/Widget/JSApp.pm	Mon Jan 22 11:41:33 2007
@@ -41,7 +41,7 @@
 
     $self->init_jsapp();
 
-    my %jsapp_special = ( attrib => 1, include_value_domain => 1, value_domain => 1, domain => 1, conf => 1, values_labels => 1 );
+    my %jsapp_special = ( attrib => 1, hidden => 1, include_value_domain => 1, value_domain => 1, domain => 1, conf => 1, values_labels => 1 );
     my (@attrib);
     foreach my $key (keys %$self) {
         if ($key =~ /^jsapp_(.+)/) {
@@ -176,6 +176,24 @@
   context.widget("$name"$js_conf).write();
 </script>
 EOF
+    if ($self->{jsapp_hidden}) {
+        my ($vars, @vars);
+        $vars = $self->{jsapp_hidden};
+        if (ref($vars) eq "ARRAY") {
+            @vars = @$vars;
+        }
+        elsif ($vars =~ /,/) {
+            @vars = split(/,/, $vars);
+        }
+        else {
+            @vars = ($vars);
+        }
+        foreach my $var (@vars) {
+            $value = $self->escape_html_attribute_value($context->so_get($var));
+            my $hidden_input = "<input type=\"hidden\" name=\"${var}\" value=\"$value\" />\n";
+            $html = $hidden_input . $html;
+        }
+    }
 
     &App::sub_exit($html) if ($App::trace);
     return($html);
@@ -189,6 +207,22 @@
     return($value);
 }
 
+sub escape_html_attribute_value {
+    my ($self, $value) = @_;
+    if (!defined $value) {
+        $value = "";
+    }
+    # I'm not exactly sure that this is the right way to escape special characters
+    # *within* an HTML attribute value.
+    elsif ($value =~ /[\&<>"]/) {
+        $value =~ s/\&/\&amp;/g;
+        $value =~ s/</\&lt;/g;
+        $value =~ s/>/\&gt;/g;
+        $value =~ s/"/\&quot;/g;
+    }
+    return($value);
+}
+
 sub init_jsapp {
     &App::sub_entry if ($App::trace);
     my ($self) = @_;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.