cvs commit: p5ee/App-Widget-JSApp/lib/App/Widget/JSApp DualSelectWidget.pm

[email protected] (Stephen Adkins)
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
cvsuser     05/08/09 12:46:51

  Added:       App-Widget-JSApp CHANGES MANIFEST MANIFEST.SKIP Makefile.PL
                        README TODO
               App-Widget-JSApp/lib/App/Widget JSApp.pm
               App-Widget-JSApp/lib/App/Widget/JSApp DualSelectWidget.pm
  Log:
  new
  
  Revision  Changes    Path
  1.1                  p5ee/App-Widget-JSApp/CHANGES
  
  Index: CHANGES
  ===================================================================
  #########################################
  # CHANGE LOG
  #########################################
  
  VERSION 0.10
   x Initial release
  
  
  
  
  1.1                  p5ee/App-Widget-JSApp/MANIFEST
  
  Index: MANIFEST
  ===================================================================
  CHANGES
  Makefile.PL
  MANIFEST
  README
  TODO
  lib/App/Widget/JSApp.pm
  lib/App/Widget/JSApp/DualSelectWidget.pm
  
  
  
  1.1                  p5ee/App-Widget-JSApp/MANIFEST.SKIP
  
  Index: MANIFEST.SKIP
  ===================================================================
  ~$
  ^MANIFEST\.
  ^Makefile$
  ^blib/
  ^pm_to_blib$
  \.old$
  \.bak$
  \.cvsignore$
  \.tar\.gz$
  htdocs/.exists
  CVS/
  
  
  
  1.1                  p5ee/App-Widget-JSApp/Makefile.PL
  
  Index: Makefile.PL
  ===================================================================
  
  ######################################################################
  ## File: $Id: Makefile.PL,v 1.1 2005/08/09 19:46:51 spadkins Exp $
  ######################################################################
  
  use ExtUtils::MakeMaker;
  # See lib/ExtUtils/MakeMaker.pm for details of how to influence
  # the contents of the Makefile that is written.
  
  %opts = (
      'NAME'        => 'App-Widget-JSApp',
      'DISTNAME'    => 'App-Widget-JSApp',
      'VERSION'     => '0.10',
      'PREREQ_PM'   => {
                         'App::Widget'              => 0,
                       },
      'clean'       => { FILES => '$(EXE_FILES)' },
      'dist'        => {'COMPRESS'=>'gzip -9f', 'SUFFIX' => 'gz',
                        'ZIP'=>'/usr/bin/zip','ZIPFLAGS'=>'-rl'},
  );
  
  ######################################################################
  # MAKE THE MAKEFILE
  ######################################################################
  
  WriteMakefile(%opts);
  
  sub MY::postamble {
      return <<EOF;
  
  install ::
  	@\$(MOD_INSTALL) htdocs  "\$(PREFIX)/htdocs/App"
  
  EOF
  }
  
  
  
  
  1.1                  p5ee/App-Widget-JSApp/README
  
  Index: README
  ===================================================================
  ######################################################################
  ## File: $Id: README,v 1.1 2005/08/09 19:46:51 spadkins Exp $
  ######################################################################
  
  WHAT IS THIS?
  
  This is the App-Widget-JSApp distribution.
  It incorporates the JavaScripted js-app widgets
  
     http://js-app.sourceforge.net/
  
  into the App-Widget world of the App-Context framework.
  
     http://www.officevision.com/pub/App-Context
  
  HOW DO I INSTALL IT?
  
  To install this module, cd to the directory that contains this README
  file and type the following:
  
     perl Makefile.PL
     make
     make test
     make install
  
  
  
  
  1.1                  p5ee/App-Widget-JSApp/TODO
  
  Index: TODO
  ===================================================================
  ######################################################################
  ## File: $Id: TODO,v 1.1 2005/08/09 19:46:51 spadkins Exp $
  ######################################################################
  
  To get to Version 1.0
   o go over the documentation which has been completely neglected
   o create some tests
  
  
  
  
  1.1                  p5ee/App-Widget-JSApp/lib/App/Widget/JSApp.pm
  
  Index: JSApp.pm
  ===================================================================
  
  ######################################################################
  ## $Id: JSApp.pm,v 1.1 2005/08/09 19:46:51 spadkins Exp $
  ######################################################################
  
  package App::Widget::JSApp;
  $VERSION = do { my @r=(q$Revision: 1.1 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  
  use App::Widget;
  @ISA = ( "App::Widget" );
  
  use strict;
  
  =head1 NAME
  
  App::Widget::JSApp::DualListSelectWidget - An ordered multi-select widget made up of two HTML <select> tags and four buttons,
  enhanced by JavaScript
  
  =head1 SYNOPSIS
  
     use App::Widget::JSApp::DualListSelectWidget;
  
     ...
  
  =cut
  
  sub html {
      my $self = shift;
      my $name = $self->{name};
      my $context = $self->{context};
  
      $self->init_jsapp();
  
      my (@attrib);
      foreach my $key (keys %$self) {
          if ($key =~ /^jsapp_(.+)/) {
              push(@attrib, $1, $self->{$key});
          }
      }
      if (! defined $self->{jsapp_submittable}) {
          push(@attrib, "submittable", 1);
      }
      my $value = $context->so_get($name);
      $value = "" if (!defined $value);
      push(@attrib, "default", $value);
      my $js_conf = "";
      if ($#attrib > -1) {
          $js_conf = ", {";
          for (my $i = 0; $i < $#attrib; $i += 2) {
              $js_conf .= "," if ($i > 0);
              $js_conf .= " \"$attrib[$i]\" : \"$attrib[$i+1]\"";
          }
          $js_conf .= " }";
      }
  
      my $html = <<EOF;
  <script type="text/javascript">
    context.widget("$name"$js_conf).write();
  </script>
  EOF
  
      return($html);
  }
  
  sub init_jsapp {
      my ($self) = @_;
      my $context = $self->{context};
      my $response = $context->response();
      my $html_url_dir = $context->get_option("html_url_dir");
      my $js = "$html_url_dir/js-app/init.js";
      if (!$response->is_included($js)) {
          my $js_conf = $self->javascript_conf();
          $response->include("javascript", $js_conf);
          $response->include("javascript", $js);
      }
  }
  
  sub javascript_conf {
      my ($self) = @_;
      my $context = $self->{context};
      my $options = $context->options();
      my $html_url_dir     = $options->{html_url_dir};
      my $script_url_dir   = $options->{script_url_dir};
      my $js = $options->{jsapp_init};
      if (!$js) {
          $js = <<EOF;
  <script type="text/javascript" language="JavaScript">
    var appOptions = {
      urlDocRoot    : "$html_url_dir",
      urlScriptRoot : "$script_url_dir"
    };
  </script>
  EOF
      }
      return($js);
  }
  
  1;
  
  
  
  
  1.1                  p5ee/App-Widget-JSApp/lib/App/Widget/JSApp/DualSelectWidget.pm
  
  Index: DualSelectWidget.pm
  ===================================================================
  
  ######################################################################
  ## $Id: DualSelectWidget.pm,v 1.1 2005/08/09 19:46:51 spadkins Exp $
  ######################################################################
  
  package App::Widget::JSApp::DualSelectWidget;
  $VERSION = do { my @r=(q$Revision: 1.1 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  
  use App::Widget::JSApp;
  @ISA = ( "App::Widget::JSApp" );
  
  use strict;
  
  =head1 NAME
  
  App::Widget::JSApp::DualSelectWidget - An ordered multi-select widget made up of two HTML <select> tags and four buttons,
  enhanced by JavaScript
  
  =head1 SYNOPSIS
  
     use App::Widget::JSApp::DualSelectWidget;
  
     ...
  
  =cut
  
  sub html {
      my $self = shift;
      my $name = $self->{name};
  
      $self->init_jsapp();
  
      my $size = "";
      $size = ",\n    \"size\" : $self->{size}" if ($self->{size});
  
      my ($values, $labels) = $self->values_labels();
      my ($values_text, $i);
  
      my $labels_text = "";
  
      if ($#$values > -1) {
          $values_text = ",\n    \"values\" : [";
          for ($i = 0; $i <= $#$values; $i++) {
              $values_text .= "," if ($i > 0);
              $values_text .= "\n     " if ($i % 10 == 0);
              $values_text .= " \"$values->[$i]\"";
          }
          $values_text .= "\n    ]";
  
          if ($labels && %$labels) {
              $labels_text = ",\n    \"labels\" : {";
              for ($i = 0; $i <= $#$values; $i++) {
                  next if (! defined $labels->{$values->[$i]});
                  $labels_text .= "," if ($i > 0);
                  $labels_text .= "\n     " if ($i % 10 == 0);
                  $labels_text .= " \"$values->[$i]\" : \"$labels->{$values->[$i]}\"";
              }
              $labels_text .= "\n    }";
          }
      }
      else {
          $values_text = ",\n    values : [ ]";
      }
      my $context = $self->{context};
      my $value = $context->so_get($name);
      $value = "" if (!defined $value);
  
      my $html = <<EOF;
  <script type="text/javascript">
    context.widget("$name", {
      "serviceClass" : "DualSelectWidget",
      "submittable" : 1,
      "default" : "$value"$size$values_text$labels_text
    }).write();
  </script>
  EOF
  
      return($html);
  }
  
  1;
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.