logo       

Re: Templates and AJAX: msg#00040

Subject: Re: Templates and AJAX

On Sun, 19 Nov 2006, Buddy Burden wrote:

We use OpenThought (http://www.openthought.net/) with TT2.
[snip]
I understand that CGI::Application works well with TT2, but I don't know how difficult it would be to convince the OT code to do that.

I have an app built with TT2 and CGI::Application, and found it _very_ easy to plug in AJAX functionality using OpenThought.

For example I have a login page where you can type in your username and request your password hint, something like this (stripped down):

   <!-- this is where hint gets pasted in -->
   <p id="password_hint">&nbsp;</p>

   <form method="POST" action="login">
      Username: <input type="text" name="username" /><br />
      <a href="#" onclick="showHint();return false">Show Hint</a>
   </form>

   <script>
      // Pass the current value of "username" form field
      // to the CGI::Application runmode "show_pw_hint":
      function showHint {
         OpenThought.CallUrl('[% self_url %]/show_pw_hint', 'username');
      }
   </script>

Then my CGI::Application runmode looks like this (error handling stripped out):

   sub show_pw_hint
   {
      my $self     = shift;
      my $username = $self->query->param('username');
      my $hint     = ... DB lookup of hint for $username ... ;

      # Replace content of "password_hint" HTML element,
      # and set focus to "username" form field:
      return $self->_do_OT({
         html        => {password_hint => "Your hint is: $hint"},
         focus       => 'username',
         error       => $any_error_msg,
         #fields     => {},
         #javascript => '',
      });
   }

   # Helper function to do OpenThought stuff:
   #
   sub _do_OT
   {
      my ($self, $args) = @_;
      my $error = delete $args->{error};

      my $OT = OpenThought2->new();

      if ($error) {
         my $url =  $self->param('self_url') .
                          '/error_runmode?msg=' . uri_escape($error);
         return $OT->parse_and_output({url => $url});
      }
      else {
         return $OT->parse_and_output($args);
      }
   }



Larry


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe