[Bps-public-commit] r13851 - in pie/trunk: . doc lib/PIE/Lambda pieplate pieplate/PIE-Plate pieplate/PIE-Plate/bin pieplate/PIE-Plate/doc pieplate/PIE-Plate/etc pieplate/PIE-Plate/lib pieplate/PIE-Plate/lib/PIE pieplate/PIE-Plate/lib/PIE/Plate pieplate/PIE-Plate/lib/PIE/Plate/Action pieplate/PIE-Plate/lib/PIE/Plate/Model pieplate/PIE-Plate/log pieplate/PIE-Plate/share pieplate/PIE-Plate/share/po pieplate/PIE-Plate/share/web pieplate/PIE-Plate/share/web/static pieplate/PIE-Plate/share/web/static/css pieplate/PIE-Plate/share/web/static/js pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4 pieplate/PIE-Plate/share/web/templates pieplate/PIE-Plate/t pieplate/PIE-Plate/var pieplate/PIE-Plate/var/mason t

sartak at bestpractical.com sartak at bestpractical.com
Tue Jul 8 10:36:44 EDT 2008


Author: sartak
Date: Tue Jul  8 10:36:26 2008
New Revision: 13851

Added:
   pie/trunk/lib/PIE/Block.pm
   pie/trunk/pieplate/
   pie/trunk/pieplate/.notes.swp   (contents, props changed)
   pie/trunk/pieplate/PIE-Plate/
   pie/trunk/pieplate/PIE-Plate/Makefile.PL
   pie/trunk/pieplate/PIE-Plate/bin/
   pie/trunk/pieplate/PIE-Plate/bin/jifty   (contents, props changed)
   pie/trunk/pieplate/PIE-Plate/doc/
   pie/trunk/pieplate/PIE-Plate/etc/
   pie/trunk/pieplate/PIE-Plate/etc/config.yml
   pie/trunk/pieplate/PIE-Plate/lib/
   pie/trunk/pieplate/PIE-Plate/lib/PIE/
   pie/trunk/pieplate/PIE-Plate/lib/PIE/Plate/
   pie/trunk/pieplate/PIE-Plate/lib/PIE/Plate.pm
   pie/trunk/pieplate/PIE-Plate/lib/PIE/Plate/Action/
   pie/trunk/pieplate/PIE-Plate/lib/PIE/Plate/Action/RunL.pm
   pie/trunk/pieplate/PIE-Plate/lib/PIE/Plate/Model/
   pie/trunk/pieplate/PIE-Plate/lib/PIE/Plate/View.pm
   pie/trunk/pieplate/PIE-Plate/log/
   pie/trunk/pieplate/PIE-Plate/share/
   pie/trunk/pieplate/PIE-Plate/share/po/
   pie/trunk/pieplate/PIE-Plate/share/web/
   pie/trunk/pieplate/PIE-Plate/share/web/static/
   pie/trunk/pieplate/PIE-Plate/share/web/static/css/
   pie/trunk/pieplate/PIE-Plate/share/web/static/css/app.css
   pie/trunk/pieplate/PIE-Plate/share/web/static/js/
   pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.dimensions.js
   pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.jeditable.js
   pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.superflydom.js
   pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4/
   pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4/ui.core.js
   pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4/ui.draggable.js
   pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4/ui.droppable.js
   pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4/ui.selectable.js
   pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4/ui.sortable.js
   pie/trunk/pieplate/PIE-Plate/share/web/static/js/pieui.js
   pie/trunk/pieplate/PIE-Plate/share/web/templates/
   pie/trunk/pieplate/PIE-Plate/t/
   pie/trunk/pieplate/PIE-Plate/var/
   pie/trunk/pieplate/PIE-Plate/var/mason/
   pie/trunk/t/builder.t
   pie/trunk/t/introspection.t
   pie/trunk/t/leaky-lexicals.t
   pie/trunk/t/let.t
   pie/trunk/t/list.t
   pie/trunk/t/named-params.t
Modified:
   pie/trunk/   (props changed)
   pie/trunk/TODO
   pie/trunk/doc/yapperl.txt
   pie/trunk/lib/PIE/Builder.pm
   pie/trunk/lib/PIE/Evaluator.pm
   pie/trunk/lib/PIE/EvaluatorResult.pm
   pie/trunk/lib/PIE/Expression.pm
   pie/trunk/lib/PIE/FunctionArgument.pm
   pie/trunk/lib/PIE/Lambda.pm
   pie/trunk/lib/PIE/Lambda/Native.pm
   pie/trunk/t/01basic.t
   pie/trunk/t/hello_world.t

Log:
Merge named-params to trunk

Modified: pie/trunk/TODO
==============================================================================
--- pie/trunk/TODO	(original)
+++ pie/trunk/TODO	Tue Jul  8 10:36:26 2008
@@ -1,10 +1,10 @@
 Backend
 
-# is there a reason we shouldn't force _all_ arguments to _all_ functions to be named? 
+# is there a reason we shouldn't force _all_ arguments to _all_ functions to be global_symbols? 
 
-- define named functions with typed arguments
+- define global_symbols functions with typed arguments
   - builtins
-    - control op: named subexpression?
+    - control op: global_symbols subexpression?
     - 
 
 
@@ -15,7 +15,7 @@
   args => { value => 'defined-symbol' } }
   
 { op => 'orz',
-  args => { named1 => EXP2,
+  args => { global_symbols1 => EXP2,
             orz2   => EXP3 } }
 
 
@@ -60,7 +60,7 @@
 - let user add an expression as an argument to an existing expression
 - let user add expression to run sequentially "after" another expression
 - serialize and save the tree of expressions 
-- save a tree of expressions as a named thingy which can be referenced from other expressions.
+- save a tree of expressions as a global_symbols thingy which can be referenced from other expressions.
 
 Hooks
 

Modified: pie/trunk/doc/yapperl.txt
==============================================================================
--- pie/trunk/doc/yapperl.txt	(original)
+++ pie/trunk/doc/yapperl.txt	Tue Jul  8 10:36:26 2008
@@ -63,7 +63,7 @@
         does it return results or does it shove results in some input handed to it?
         
 
-    a block is essentially a named bricks built up of one or more blocks or bricks
+    a block is essentially a global_symbols bricks built up of one or more blocks or bricks
     
     
 
@@ -300,7 +300,7 @@
 # a class to describe an op tree
 # a class to run an optree
 # primitives for basic ops
-    # run a named optree like it's a primitive
+    # run a global_symbols optree like it's a primitive
     
 # primitives for variables
 # a way to store an optree as a variable

Added: pie/trunk/lib/PIE/Block.pm
==============================================================================
--- (empty file)
+++ pie/trunk/lib/PIE/Block.pm	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,54 @@
+package PIE::Block;
+use Moose::Role;
+
+our $BLOCK_IDS = 0;
+
+has block_id => (
+                 is => 'ro',
+                 isa => 'Num',
+                 default => sub { ++$BLOCK_IDS },
+);
+
+has outer_block => (
+                     is => 'rw',
+                     weak_ref => 1,
+                     default => sub { undef },
+);
+
+around 'new' => sub {
+    my $next = shift;
+    my $class = shift;
+    my $self = $class->$next(@_);
+    return $self if ref($self) eq 'PIE::Lambda::Native';
+    $self->_walk( $self,
+                  sub { my $block = shift;
+                        return unless $block->does('PIE::Block');
+                        $block->outer_block($self);
+                        return 1;
+                    } );
+
+    return $self;
+};
+
+sub _walk {
+    my ($self, $exp, $cb) = @_;
+
+    if ($exp->can('nodes')) {
+        for (@{$exp->nodes}) {
+            next unless ref($_);
+            $cb->($_) and next;
+            $self->_walk($_, $cb);
+        }
+    }
+    else {
+        for (keys %{$exp->signature}) {
+            next unless ref($exp->args->{$_});
+            $cb->($exp->args->{$_}) and next;
+            $self->_walk($exp->args->{$_}, $cb);
+        }
+    }
+
+}
+
+
+1;

Modified: pie/trunk/lib/PIE/Builder.pm
==============================================================================
--- pie/trunk/lib/PIE/Builder.pm	(original)
+++ pie/trunk/lib/PIE/Builder.pm	Tue Jul  8 10:36:26 2008
@@ -1,39 +1,51 @@
 
 package PIE::Builder;
 use Moose;
-
+use Params::Validate;
 use PIE::Lambda;
+
 use PIE::Expression;
+use UNIVERSAL::require;
 
 sub build_op_expression {
     my ($self, $name, $args) = @_;
-    my $class = "PIE::Expression::$name";
-    die unless $class->meta->does_role("PIE::Evaluatable");
-    
-    $class->new( map { $_ => $self->build_expression( $args->{$_} ) } keys %$args );
+    my $class = $name;
+    $class = "PIE::Expression::$name" unless ($name =~ /^PIE::Expression/);
+    if ($class->can('meta')) {
+        $name = $class;
+    }
+    else {
+        $class = "PIE::Expression";
+    }
+
+    # XXX: in case of primitive-ops, we should only bulid the args we
+    # know about
+
+    my @known_args = $class eq 'PIE::Expression' ? keys %$args : keys %{ $class->signature };
+    return $class->new( name => $name, builder => $self, builder_args => $args,
+                        args => { map { $_ => $self->build_expression( $args->{$_} ) } @known_args } );
+
 }
 
 sub build_expression {
     my ($self, $tree) = @_;
     if (!ref($tree)) {
-        return PIE::Expression::String->new(value => $tree );
-    }
-    elsif (ref($tree) eq 'ARRAY') {
-        my ($func, @rest) = @$tree;
-        return PIE::Expression->new( elements => [$func, map { $self->build_expression($_) } @rest]);
+        return PIE::Expression::String->new(args => { value => $tree} );
     }
     elsif (ref($tree) eq 'HASH') {
         return $self->build_op_expression($tree->{name}, $tree->{args});
+    } else {
+        Carp::confess("Don't know what to do with a tree that looksl ike ". YAML::Dump($tree));use YAML;
     }
 }
 
 
-sub build_expressions {
+sub defun {
     my $self = shift;
-    my $ops = shift;
-
-    return PIE::Lambda->new( nodes => [map { $self->build_expression($_) } @$ops ] );
+    my %args = validate( @_, { ops => 1, signature => 1 });
+    return PIE::Lambda->new( progn => PIE::Expression::ProgN->new(
+                                                                  nodes => [map { $self->build_expression($_) } @{$args{ops}} ]),
+                             signature => $args{signature} );
 }
 
-
 1;

Modified: pie/trunk/lib/PIE/Evaluator.pm
==============================================================================
--- pie/trunk/lib/PIE/Evaluator.pm	(original)
+++ pie/trunk/lib/PIE/Evaluator.pm	Tue Jul  8 10:36:26 2008
@@ -10,47 +10,180 @@
     isa => 'PIE::EvaluatorResult',
     default => sub { return PIE::EvaluatorResult->new()}
     );
-    
-has named => (
+
+has global_symbols => (
              metaclass => 'Collection::Hash',
              is        => 'rw',
              default   => sub { {} },
              isa => 'HashRef',
              provides  => {
-                 get       => 'get_named',
-                 set       => 'set_named',
+                 get       => 'get_global_symbol',
+                 set       => 'set_global_symbol',
              });
 
-sub run {
+has lex_block_map => (
+                     is => 'rw',
+                     isa => 'HashRef[ArrayRef[Num]]',
+                     default => sub { {} },
+);
+
+has stack_block => (
+    is => 'rw',
+    metaclass => 'Collection::Array',
+    isa       => 'ArrayRef[PIE::Block]',
+    default   => sub { [] },
+    provides  => {
+        'push' => 'push_stack_block',
+        'pop'  => 'pop_stack_block',
+    }
+);
+
+has stack_depth => ( 
+            is => 'rw',
+            isa => 'Int',
+            default => sub { 0}
+            );
+
+
+sub enter_stack_frame {
+    my $self = shift;
+    my %args = validate(@_, {args => 1, block => 1});
+
+    $self->stack_depth($self->stack_depth+1);
+    $self->push_stack_block($args{'block'});
+
+    # lex_block_map is a mapping from a block id to an array of stack indexes.
+    # if we're entereing block 3, we push the current stack frame  onto the lex_block_map entry for block 3
+    #   The last entry of the current block is where we can see its lexical context
+    push @{ $self->lex_block_map->{ $args{'block'}->block_id } ||= [] }, $args{'args'};
+}
+
+sub leave_stack_frame {
     my $self = shift;
+    die "Trying to leave stack frame 0. Too many returns. Something relaly bad happened" if ($self->stack_depth == 0);
+    my $block = $self->pop_stack_block();
+    $self->stack_depth($self->stack_depth-1);
+
+    pop @{ $self->lex_block_map->{ $block->block_id } };
+}
+
+sub run {
+    my $self       = shift;
     my $expression = shift;
-    eval { 
-    my $ret = $expression->evaluate($self);
-    $self->result->value($ret) ; # XXX TODO - we should be separating out success and value
-    $self->result->success(1);
+    eval {
+        Carp::confess unless ($expression && $expression->can('evaluate'));
+        my $ret = $expression->evaluate($self);
+
+
+        $self->result->value($ret);
+        $self->result->success(1);
     };
-    if (my $err = $@) {
-        die $err; # for now
-    
+    if ( my $err = $@ ) {
+        #        die $err; # for now
+
         $self->result->success(0);
+        $self->result->value(undef);
         $self->result->error($err);
     }
-
-    return 1;
+    return $self->result->success;
 }
 
-sub resolve_name {
+sub lookup_lex_name {
     my ($self, $name) = @_;
-    $self->get_named($name);
+
+
+    return unless @{ $self->stack_block };
+    # look at the current block on the stack
+    my $block = $self->stack_block->[-1];
+    do {
+        # grab the stack frame from the lexical block map pointer for the 'current' block (the one we're inspecting
+        my $stack =$self->lex_block_map->{ $block->block_id }[-1] ;
+        # if we find the variable, we can return it
+
+        return $stack->{$name} if exists $stack->{$name};
+    } while ($block = $block->outer_block);
+
+    return;
 }
 
+sub resolve_symbol_name {
+    my ($self, $name) = @_;
+    Carp::cluck if ref($name);
+    $self->lookup_lex_name($name) || $self->get_global_symbol($name)
+        || die "Could not find symbol $name in the current lexical context.";
+}
 
 sub apply_script {
-    # self, a lambda, any number of positional params. (to be replaced with a params object?)
-    my ($self, $lambda, @exp) = validate_pos(@_, { isa => 'PIE::Evaluator'}, { ISA => 'PIE::Lambda'}, (0) x (@_ - 2)  ) ;
-        # XXX: cleanup, unmask, etc
-        $lambda->evaluate($self, @exp);
+
+# self, a lambda, any number of positional params. (to be replaced with a params object?)
+    my ( $self, $lambda, $args ) = validate_pos(
+        @_,
+        { isa => 'PIE::Evaluator' },
+        { ISA => 'PIE::Lambda' },
+        { ISA => "HASHREF" }
+    );
+    Carp::confess unless($lambda);
+#    Carp::cluck Dumper($lambda); use Data::Dumper;
+    my $ret = $lambda->apply( $self => $args );
+    $self->result->value($ret);
+    $self->result->success(1);
+    return $self->result->value;
+}
+
+sub core_expression_signatures {
+    my $self = shift;
+    my %signatures;
+    foreach my $core_expression ( $self->_enumerate_core_expressions() ) {
+        my $sig = $self->_flatten_core_expression_signature($core_expression);
+        $signatures{$core_expression} =  $sig;
+    }
+
+    return \%signatures;
+}
+
+sub _enumerate_core_expressions {
+    my $self = shift;
+    no strict 'refs';
+    use PIE::Expression;
+    my @core_expressions
+        = grep { $_ && $_->isa('PIE::Expression') }
+        map { /^(.*)::$/ ? 'PIE::Expression::' . $1 : '' }
+        keys %{'PIE::Expression::'};
+    return @core_expressions;
+}
+
+
+sub _flatten_core_expression_signature {
+    my $self    = shift;
+    my $core_expression = shift;
+    my $signature = $core_expression->signature;
+    return { map { $_->name =>  {type => $_->type}}   values %$signature};
+
 }
 
+sub symbol_signatures {
+    my $self = shift;
+    my %signatures;
+    foreach my $symbol ($self->_enumerate_symbols()) {
+        $signatures{$symbol} = $self->_flatten_symbol_signature( $symbol)
+    }
+    return \%signatures;
+}
+
+sub _enumerate_symbols() {
+    my $self = shift;
+    return keys %{$self->global_symbols};
+}
+
+
+sub _flatten_symbol_signature {
+    my $self = shift;
+    my $sym = shift;
+
+    my $x = $self->resolve_symbol_name($sym);
+    my $signature = $x->signature;
+    return { map { $_->name =>  {type => $_->type}}   values %$signature};
+
+}
 
 1;

Modified: pie/trunk/lib/PIE/EvaluatorResult.pm
==============================================================================
--- pie/trunk/lib/PIE/EvaluatorResult.pm	(original)
+++ pie/trunk/lib/PIE/EvaluatorResult.pm	Tue Jul  8 10:36:26 2008
@@ -1,4 +1,3 @@
-
 package PIE::EvaluatorResult;
 use Moose;
 
@@ -15,7 +14,7 @@
 
 has value => ( 
     is => 'rw',
-    isa => 'Str | Undef',
+#    isa => 'Str | Undef | PIE::EvaluatorResult::RunTime',
     required => 0
     );
 

Modified: pie/trunk/lib/PIE/Expression.pm
==============================================================================
--- pie/trunk/lib/PIE/Expression.pm	(original)
+++ pie/trunk/lib/PIE/Expression.pm	Tue Jul  8 10:36:26 2008
@@ -1,33 +1,42 @@
 
 package PIE::Expression;
+use PIE::FunctionArgument;
 use Moose;
 
 with 'PIE::Evaluatable';    
 
+has name => (
+   is => 'ro',
+   isa => 'Str');
+
 has elements => (
    is => 'ro',
    isa => 'ArrayRef');
 
-# (foo bar (orz 1 ))
-# === (eval 'foo bar (orz 1))
-# === (apply foo ((bar (orz 1))
-
+has signature => ( 
+    is => 'rw',
+    default => sub { {}},
+    isa => 'HashRef[PIE::FunctionArgument]');
 
+has args => (
+    is => 'rw',
+    default => sub { {} },
+    isa => 'HashRef[PIE::Expression]');
 
 sub evaluate {
     my ($self, $ev) = @_;
-    my $func = $self->elements->[0];
-    my @exp = @{ $self->elements }[1..$#{ $self->elements }];
-    my $lambda = $ev->resolve_name($func);
-    return $ev->apply_script($lambda, @exp);
+    my $lambda = $ev->resolve_symbol_name($self->name);
+    $ev->apply_script( $lambda, $self->args );
+    return $ev->result->value;
 }
 
-
 package PIE::Expression::True;
 use Moose;
+use MooseX::ClassAttribute;
 
 extends 'PIE::Expression';
 
+class_has signature => ( is => 'ro', default => sub { { }});
 sub evaluate {1}
 
 package PIE::Expression::False;
@@ -40,83 +49,213 @@
 
 }
 
-package PIE::Expression::Loop;
+package PIE::Expression::IfThen;
 use Moose;
 extends 'PIE::Expression';
+use Params::Validate qw/validate_pos/;
+use MooseX::ClassAttribute;
 
-has items => ( is => 'rw', isa => 'ArrayRef[PIE::Evaluatable]');
-has block => ( is => 'rw', isa => 'PIE::Evaluatable');
+class_has signature => (
+    is      => 'ro',
+    default => sub {
+         {
+            condition => PIE::FunctionArgument->new(
+                name => 'condition',
+                type  => 'PIE::Evaluatable'),
+
+            if_true => PIE::FunctionArgument->new(
+                name => 'if_true',
+                type  => 'PIE::Evaluatable'),
+           if_false => PIE::FunctionArgument->new(
+                name => 'if_false',
+                type  => 'PIE::Evaluatable'
+                )
+            }
+    }
+);
 
 sub evaluate {
-    my $self = shift;
+    my ($self, $evaluator) = validate_pos(@_, { isa => 'PIE::Expression'}, { isa => 'PIE::Evaluator'}, );
 
+    my $truth= $self->args->{condition}->evaluate($evaluator);
+    if ($truth) {
+        return    $self->args->{if_true}->evaluate($evaluator);
+        }    else { 
+        return $self->args->{if_false}->evaluate($evaluator);
+    }
 }
 
-package PIE::Expression::IfThen;
+package PIE::Expression::String;
 use Moose;
 extends 'PIE::Expression';
+use Params::Validate qw/validate_pos/;
+use MooseX::ClassAttribute;
 
+class_has signature => (
+    is      => 'ro',
+    default => sub {
+        { value => PIE::FunctionArgument->new( name => 'value', type => 'Str' )
+        };
+    }
+);
 
-has condition => (
-    is => 'rw',
-    does => 'PIE::Evaluatable');
-    
-has if_true => (
-    is => 'rw',
-    does => 'PIE::Evaluatable');
-    
-has if_false => (
+has '+args' => (
+    isa => 'HashRef[Str]');
+
+
+sub evaluate {
+    my ( $self, $eval ) = validate_pos(
+        @_,
+        { isa => 'PIE::Expression' },
+        { isa => 'PIE::Evaluator' }
+    );
+
+
+    return $self->args->{'value'};
+
+}
+
+package PIE::Expression::ProgN;
+use MooseX::ClassAttribute;
+use Moose;
+extends 'PIE::Expression';
+class_has signature => ( is => 'ro', default => sub { { }});
+
+has nodes => (
     is => 'rw',
-    does => 'PIE::Evaluatable');
-    
+    isa => 'ArrayRef',
+);
+
+sub BUILD {
+    my ($self, $params) = @_;
 
-sub arguments { return qw(condition if_true if_false)} 
-    
+    return unless $params->{builder};
+    my $nodes = $params->{builder_args}{nodes};
+
+    $self->nodes( [ map { $params->{builder}->build_expression($_) } @$nodes ] );
+}
 
 sub evaluate {
-    my $self = shift;
-    my $evaluator = shift;
-    $evaluator->run($self->condition);
-    
-
-    if ($evaluator->result->value) {
-        
-        $evaluator->run($self->if_true);
-        return $evaluator->result->value;
-        }    else { 
-        $evaluator->run($self->if_false);
-        return $evaluator->result->value;
+    my ($self, $evaluator) = @_;
+    my $res;
+    Carp::cluck unless $self->nodes;
+    foreach my $node (@{$self->nodes}) {
+       $res =  $node->evaluate($evaluator);
     }
+    return $res;
 }
 
-package PIE::Expression::String;
+package PIE::Expression::Symbol;
 use Moose;
 extends 'PIE::Expression';
+use Params::Validate qw/validate_pos/;
+use MooseX::ClassAttribute;
+
+class_has signature => (
+    is => 'ro',
+    default => sub { { symbol => PIE::FunctionArgument->new( name => 'symbol', type => 'Str')}});
 
-has value => (
-    is => 'rw',
-    isa => 'Str | Undef');
-    
-    
 sub evaluate {
-    my $self = shift;
-    return $self->value;
+    my ($self, $eval) = validate_pos(@_, { isa => 'PIE::Expression'}, { isa => 'PIE::Evaluator'});
+    my $symbol = $self->{'args'}->{'symbol'}->evaluate($eval);
+    my $result = $eval->resolve_symbol_name($symbol);
+    return ref($result) && $result->meta->does_role('PIE::Evaluatable') ? $result->evaluate($eval): $result; # XXX: figure out evaluation order here
+}
+
+package PIE::Expression::List;
+use Moose;
+extends 'PIE::Expression::ProgN';
+
+sub evaluate {
+    my ($self, $evaluator) = @_;
+    return bless \$self->nodes, 'PIE::EvaluatorResult::RunTime';
+}
+
+package PIE::Expression::ForEach;
+use Moose;
+extends 'PIE::Expression';
+use MooseX::ClassAttribute;
+
+class_has signature => (
+    is => 'ro',
+    default => sub { { list => PIE::FunctionArgument->new( name => 'list'),
+                       binding => PIE::FunctionArgument->new( name => 'Str'),
+                       do => PIE::FunctionArgument->new( name => 'Str', type => 'PIE::Lambda'), # XXX: type for runtime?
+                   }});
+
+sub evaluate {
+    my ($self, $evaluator) = @_;
+    my $lambda = $self->args->{do}->evaluate($evaluator);
+    die unless $lambda->isa("PIE::Lambda");
+
+    my $binding = $self->args->{binding}->evaluate($evaluator);
+    my $list = $self->args->{list}->evaluate($evaluator);
+
+    die unless ref($list) eq 'PIE::EvaluatorResult::RunTime';
+    my $nodes = $$list;
+
+    foreach (@$nodes) {
+        $lambda->apply($evaluator, { $binding => $_ });
+    }
 
 }
 
 package PIE::Expression::Symbol;
 use Moose;
 extends 'PIE::Expression';
+use Params::Validate qw/validate_pos/;
+use MooseX::ClassAttribute;
+
+class_has signature => (
+    is => 'ro',
+    default => sub { { symbol => PIE::FunctionArgument->new( name => 'symbol', type => 'Str')}});
+
 
-has symbol => (
+package PIE::Expression::Let;
+use Moose;
+extends 'PIE::Expression::ProgN';
+with 'PIE::Block';
+
+has bindings => (
     is => 'rw',
-    isa => 'Str');
-    
-    
+    isa => 'HashRef',
+    default => sub { { } },
+);
+
+has lambda => (
+    is => 'ro',
+    isa => 'PIE::Lambda',
+    lazy => 1,
+    default => sub {
+        my $self = shift;
+        PIE::Lambda->new(
+            progn     => PIE::Expression::ProgN->new( nodes => $self->nodes ),
+            signature => $self->mk_signature,
+            block_id => $self->block_id,
+            outer_block => $self->outer_block,
+        );
+    },
+);
+
+sub BUILD {
+    my ($self, $params) = @_;
+
+    return unless $params->{builder};
+    my $bindings = $params->{builder_args}{bindings};
+
+    $self->bindings->{$_} = $params->{builder}->build_expression($bindings->{$_})
+        for keys %$bindings;
+
+}
+
+sub mk_signature {
+    my $self = shift;
+    return { map { $_ => PIE::FunctionArgument->new( name => $_, type => 'Str') } keys %{ $self->bindings } };
+}
+
 sub evaluate {
-    my ($self, $ev) = @_;
-    my $result = $ev->get_named($self->symbol);
-    return $result->isa('PIE::Expression') ? $ev->run($result) : $result; # XXX: figure out evaluation order here
+    my ($self, $evaluator) = @_;
+    $self->lambda->apply( $evaluator, $self->bindings );
 }
 
 1;

Modified: pie/trunk/lib/PIE/FunctionArgument.pm
==============================================================================
--- pie/trunk/lib/PIE/FunctionArgument.pm	(original)
+++ pie/trunk/lib/PIE/FunctionArgument.pm	Tue Jul  8 10:36:26 2008
@@ -1,6 +1,8 @@
 package PIE::FunctionArgument;
 use Moose;
 
+
+
 has name => (
     is => 'rw',
     isa => 'Str'    

Modified: pie/trunk/lib/PIE/Lambda.pm
==============================================================================
--- pie/trunk/lib/PIE/Lambda.pm	(original)
+++ pie/trunk/lib/PIE/Lambda.pm	Tue Jul  8 10:36:26 2008
@@ -1,46 +1,72 @@
 
 package PIE::Lambda;
 use Moose; use MooseX::Params::Validate;
-with 'PIE::Evaluatable';
 
-has nodes => (
-    is => 'rw',
-    isa => 'ArrayRef',
-);
+with 'PIE::Block';
 
-has bindings => (
-    is => 'rw',
-    isa => 'ArrayRef[Str]');
+has progn => (
+    is => 'ro',
+    isa => 'PIE::Expression::ProgN',
+    default => sub { PIE::Expression::ProgN->new },
+    handles => [qw(nodes)]
+);
 
-has arguments => (
+has signature => (
     is => 'rw',
-    isa => 'HashRef[PIE::Function::Argument]');
+    default => sub { {} },
+    isa => 'HashRef[PIE::FunctionArgument]');
 
-
-sub check_bindings {
+sub check_args {
     my $self = shift;
-    my $passed = shift;
-    my $bindings = $self->bindings;
-    Carp::croak "unmatched number of arguments. ".($#{$bindings}+1)." expected. Got ".($#{$passed}+1) unless $#{$bindings} == $#{$passed};
+    my $passed = shift; #reference to hash of provided args
+    my $expected = $self->signature; # expected args
+    
+    
+    my $missing = {};
+    my $unwanted = {};
+    
+    my $fail =0;
+    foreach my $arg (keys %$passed) {
+            if  (!$expected->{$arg}) {
+            $unwanted->{$arg} =  "The caller passed $arg which we were not expecting" ;
+            };
+    }
+    foreach my $arg (keys %$expected) {
+                 if  (!$passed->{$arg}) {
 
-}
+                $missing->{$arg} =  "The caller did not pass $arg which we require";
+                }
+    }
 
-sub bind_expressions {
-    my ($self, $ev, @exp) = @_;
-    $self->check_bindings(\@exp);
-    my $bindings = $self->bindings;
-    $ev->set_named( $bindings->[$_] => $exp[$_] ) for 0.. $#exp;
+    return $missing, $unwanted;
 }
 
-sub evaluate {
+sub validate_args_or_die {
     my $self = shift;
-    my $evaluator = shift;
+    my $args = shift;
+    my ( $missing, $unwanted ) = $self->check_args( $args);
 
-    $self->bind_expressions( $evaluator, @_ );
+    if ( keys %$missing || keys %$unwanted ) {
+        die "Function signature mismatch \n".
+        (keys %$missing? "The following arguments were missing: " . join(", ", keys %$missing) ."\n" : ''),
+        (keys %$unwanted? "The following arguments were unwanted: " . join(", ", keys %$unwanted)."\n" : '');
 
-    foreach my $node (@{$self->nodes}) {
-        $evaluator->run($node);
     }
+} 
+
+sub apply {
+    my ($self, $evaluator, $args) = @_;
+
+    $self->validate_args_or_die($args);
+
+    $evaluator->enter_stack_frame( args => $args, block => $self );
+    my $res = $self->progn->evaluate($evaluator);
+
+    $evaluator->leave_stack_frame(); 
+    return $res;
+    #return $evaluator->result->value; 
+
+    
 }
 
 1;

Modified: pie/trunk/lib/PIE/Lambda/Native.pm
==============================================================================
--- pie/trunk/lib/PIE/Lambda/Native.pm	(original)
+++ pie/trunk/lib/PIE/Lambda/Native.pm	Tue Jul  8 10:36:26 2008
@@ -1,6 +1,8 @@
 
 package PIE::Lambda::Native;
 use Moose; 
+use YAML;
+use Scalar::Defer;
 extends 'PIE::Lambda';
 
 has body => (
@@ -8,16 +10,15 @@
 #    isa => 'CODE',
 );
 
-sub bind_expressions {
-    my ($self, $evaluator, @exp) = @_;
-    return;
-}
 
-sub evaluate {
-    my $self = shift;
-    my $evaluator = shift;
-    $self->check_bindings(\@_);
-    $self->body->(map {$evaluator->run($_); $evaluator->result->value } @_);
+
+sub apply {
+    my ( $self, $evaluator, $args ) = @_;
+
+    $self->validate_args_or_die($args);
+    my $r = $self->body->( {map { $_ => $args->{$_}->evaluate($evaluator) } keys %$args });
+    return $r;
 }
 
+
 1;

Added: pie/trunk/pieplate/.notes.swp
==============================================================================
Binary file. No diff available.

Added: pie/trunk/pieplate/PIE-Plate/Makefile.PL
==============================================================================
--- (empty file)
+++ pie/trunk/pieplate/PIE-Plate/Makefile.PL	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,7 @@
+use inc::Module::Install;
+
+name        'PIE::Plate';
+version     '0.01';
+requires    'Jifty' => '0.80311';
+
+WriteAll;

Added: pie/trunk/pieplate/PIE-Plate/bin/jifty
==============================================================================
--- (empty file)
+++ pie/trunk/pieplate/PIE-Plate/bin/jifty	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,10 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+use UNIVERSAL::require;
+
+use Jifty;
+use Jifty::Script;
+
+local $SIG{INT} = sub { warn "Stopped\n"; exit; };
+Jifty::Script->dispatch();

Added: pie/trunk/pieplate/PIE-Plate/etc/config.yml
==============================================================================
--- (empty file)
+++ pie/trunk/pieplate/PIE-Plate/etc/config.yml	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,74 @@
+--- 
+framework: 
+  AdminMode: 1
+  ApplicationClass: PIE::Plate
+  ApplicationName: PIE::Plate
+  ApplicationUUID: 5DB8E502-2887-11DD-9E60-9ACD23E51681
+  ConfigFileVersion: 3
+  Database: 
+    AutoUpgrade: 1
+    CheckSchema: 1
+    Database: pie::plate
+    Driver: SQLite
+    Host: localhost
+    Password: ''
+    RecordBaseClass: Jifty::DBI::Record::Cachable
+    User: ''
+    Version: 0.0.1
+  DevelMode: 1
+  L10N: 
+    PoDir: share/po
+  LogLevel: INFO
+  Mailer: Sendmail
+  MailerArgs: []
+
+  Plugins: 
+    - 
+      LetMe: {}
+
+    - 
+      SkeletonApp: {}
+
+    - 
+      REST: {}
+
+    - 
+      Halo: {}
+
+    - 
+      ErrorTemplates: {}
+
+    - 
+      OnlineDocs: {}
+
+    - 
+      CompressedCSSandJS: {}
+
+    - 
+      AdminUI: {}
+
+  PubSub: 
+    Backend: Memcached
+    Enable: ~
+  SkipAccessControl: 0
+  TemplateClass: PIE::Plate::View
+  View: 
+    FallbackHandler: Jifty::View::Mason::Handler
+    Handlers: 
+      - Jifty::View::Static::Handler
+      - Jifty::View::Declare::Handler
+      - Jifty::View::Mason::Handler
+  Web: 
+    BaseURL: http://localhost
+    DataDir: var/mason
+    Globals: []
+
+    MasonConfig: 
+      autoflush: 0
+      default_escape_flags: h
+      error_format: text
+      error_mode: fatal
+    Port: 8888
+    ServeStaticFiles: 1
+    StaticRoot: share/web/static
+    TemplateRoot: share/web/templates

Added: pie/trunk/pieplate/PIE-Plate/lib/PIE/Plate.pm
==============================================================================
--- (empty file)
+++ pie/trunk/pieplate/PIE-Plate/lib/PIE/Plate.pm	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,16 @@
+package PIE::Plate;
+
+Jifty->web->add_javascript(
+    qw( jquery.superflydom.js
+        jquery.jeditable.js
+        jquery.dimensions.js
+        jquery.ui-1.5b4/ui.core.js
+        jquery.ui-1.5b4/ui.sortable.js
+        jquery.ui-1.5b4/ui.selectable.js
+        jquery.ui-1.5b4/ui.draggable.js
+        jquery.ui-1.5b4/ui.droppable.js
+        pieui.js ));
+
+
+1;
+

Added: pie/trunk/pieplate/PIE-Plate/lib/PIE/Plate/Action/RunL.pm
==============================================================================
--- (empty file)
+++ pie/trunk/pieplate/PIE-Plate/lib/PIE/Plate/Action/RunL.pm	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,52 @@
+package PIE::Plate::Action::RunL;
+use PIE::Lambda;
+use PIE::Lambda::Native;
+use PIE::Builder; use PIE::FunctionArgument;
+use PIE::Evaluator; use JSON;
+use Jifty::Param::Schema;
+use PIE::Plate::Action schema {
+    param struct => type is 'text';
+};
+
+
+sub take_action {
+    my $self = shift;
+    warn $self->argument_value('struct');
+    my $tree = JSON::from_json($self->argument_value('struct'));
+    my $builder = PIE::Builder->new();
+    my $eval = PIE::Evaluator->new();
+
+
+my $MATCH_REGEX = PIE::Lambda::Native->new(
+    body => sub {
+        my $args = shift;
+        my $arg = $args->{'tested-string'};
+        my $regex = $args->{'regexp'};
+
+        return $arg =~ m/$regex/;
+    },
+
+    signature => {
+           'tested-string' =>  PIE::FunctionArgument->new( name =>              'tested-string' =>  type => 'Str' ),
+           'regexp'=>  PIE::FunctionArgument->new( name =>      'regex', type => 'Str' )
+    }
+
+);
+$eval->set_global_symbol( 'match-regexp' => $MATCH_REGEX );
+
+
+    eval { 
+            my $script  = $builder->defun( ops => $tree, signature => {});
+
+            $eval->apply_script($script, {} )};
+    if (my $msg = $@) { 
+        $self->result->error($msg);
+    }else {
+    warn $eval->result->value, $eval->result->success ;
+
+    $self->result->message($eval->result->value);
+   $eval->result->success ||  $eval->result->error($eval->result->error);
+}
+}
+
+1;

Added: pie/trunk/pieplate/PIE-Plate/lib/PIE/Plate/View.pm
==============================================================================
--- (empty file)
+++ pie/trunk/pieplate/PIE-Plate/lib/PIE/Plate/View.pm	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,70 @@
+use warnings;
+use strict;
+package PIE::Plate::View;
+use Jifty::View::Declare -base;
+use JSON;
+
+template 'index.html' => page {'hey'};
+template 'lorzy' => page { 
+    div { { id is 'result' }};
+    div { { id is 'wrapper' } };
+    div { { class is 'library' } 
+    
+        h2 {  'Function library'};
+    
+    };
+ outs_raw('<style>#wrapper div { padding-left:1em;} </style>');
+my $ops = [
+            {   name => 'IfThen',
+                args => {
+                    'if_true'   =>  'hate',
+                    'if_false'  => 'love',
+                    'condition' => {
+                        name => 'match-regexp',
+                        args => {
+                            regexp           => 'software',
+                            'tested-string' => 'foo',
+                        }
+                    }
+                }
+            }
+        ];
+
+my $json_text   = JSON->new->encode($ops);
+
+my $evaluator = PIE::Evaluator->new();
+my $MATCH_REGEX = PIE::Lambda::Native->new(
+    body => sub {
+        my $args = shift;
+        my $arg    = $args->{'tested-string'};
+        my $regexp = $args->{'regexp'};
+        return ($arg =~ m/$regexp/ )? 1 : 0;
+    },
+
+    signature => {
+        'tested-string' => PIE::FunctionArgument->new( name => 'tested-string' => type => 'Str'),
+        'regexp' => PIE::FunctionArgument->new( name => 'regexp', type => 'Str' )
+        }
+
+);
+
+$evaluator->set_global_symbol( 'match-regexp' => $MATCH_REGEX );
+
+
+my $signatures_json = JSON->new->encode(    $evaluator->core_expression_signatures());
+my $symbol_sigs = JSON->new->encode($evaluator->symbol_signatures());
+
+outs_raw(qq{<script type="text/javascript">
+
+
+jQuery(lorzy_show($json_text));
+jQuery(lorzy_show_symbols($symbol_sigs));
+jQuery(lorzy_show_symbols($signatures_json));
+
+</script>});
+
+};
+
+
+1;
+

Added: pie/trunk/pieplate/PIE-Plate/share/web/static/css/app.css
==============================================================================
--- (empty file)
+++ pie/trunk/pieplate/PIE-Plate/share/web/static/css/app.css	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,194 @@
+*, body, p, div, span, a, h1, h2, h3 {
+    font-family: Helvetica, Arial, Sans-serif;
+}
+
+
+#lightbox {
+position: fixed; 
+height: 100%; 
+width: 100%; 
+top:0; 
+left: 0; 
+background-color: #ccc; 
+z-index: 999; 
+    filter:alpha(opacity=90);
+    -moz-opacity:0.9;
+    -khtml-opacity: 0.9;
+    opacity: 0.9;
+}
+
+#lightbox-docs {
+    position: fixed;
+    background: #fff;
+    padding: 0.25em;
+    text-align: center;
+    text-color: #000;
+    bottom: 0;
+    width: 100%;
+    z-index: 1001;
+    border-top: 2px solid #666;
+}
+
+
+#lightbox-content {
+    position: fixed; top: 5em; 
+    padding: 2em;
+    left: 5em; 
+    right: 5em; 
+    bottom: 5em; 
+    border: 5px solid yellow;
+    z-index: 1000;
+    background: #ffc;
+    overflow: auto;
+}
+
+
+#wrapper {
+    width: 20em; 
+
+}
+
+.lorzy-expression {
+    padding: 0.5em;
+     min-height: 1em;
+    border: 2px solid #ccc;
+}
+
+
+.lorzy-expression, .lorzy-target {
+    -moz-border-radius: 5px;
+     margin-top: 0.25em;
+     margin-bottom: 0.25em;
+    border: 2px solid #fff;
+}
+.lorzy-target { height: 1em; 
+}
+.lorzy-target.droppable-active { height: 1em; content: "Add an expression here!"; }
+
+
+
+.droppable-active {
+    border: 2px solid green;
+     background: #eee;
+}
+
+.droppable-hover{
+    background: yellow;
+}
+
+
+#wrapper {
+    position: relative;
+    left: 15em;
+
+}
+
+#wrapper div.lorzy-code>.name:before {
+    content: 'code: ';
+
+}
+    
+div.lorzy-code-arg {
+  color: green;
+}
+
+div.lorzy-code-arg>.name:before {
+    content: 'arg: ';
+}
+
+.lorzy-const {
+  color: black;
+}
+.lorzy-const:before {
+    content: "constant: ";
+}
+
+
+
+.lorzy-code {
+  color: blue;
+}
+
+/* .droppable-hover .lorzy-expression { color: #000; background-color: #fff; filter:alpha(opacity=20); -moz-opacity:0.2; -khtml-opacity: 0.2; opacity: 0.2; } */
+
+
+.library  {
+    position: fixed;
+    top: 5em;
+    left: 1em;
+    bottom: 5em;
+    width: 12em;
+}
+
+.library .lorzy-expression { 
+    border: 2px solid blue;
+    background-color: #ddd;
+    -moz-border-radius: 0.5em;
+    padding: 0.25em;
+
+
+}
+
+.library .lorzy-expression .lorzy-expression { 
+        display: none; 
+}
+
+.library .draggable-active {
+    position: absolute;
+}
+
+
+.lorzy-drop-targets {
+    position: fixed;
+    left: 35em;
+    bottom: 2em;
+    font-size: 1.2em;
+
+}
+
+.lorzy-tools {
+    position: fixed;
+    left: 35em;
+    top: 4em;
+    font-size: 1.2em;
+}
+.lorzy-tools div, .lorzy-drop-targets div {
+    padding: 1em;
+    width: 5em;
+    border: 3px solid #ccc;
+    -moz-border-radius: 0.5em;
+}
+
+#trashy {
+    background-color: red;
+    color: #fff;
+    border: 3px solid red;
+}
+
+
+#trashy.droppable-active {
+    border: 2px solid green;
+    background-color: #e33;
+}
+
+#trashy.droppable-hover {
+    border: 2px solid yellow;
+    background-color: #f11;
+}
+
+input.lorzy-const {
+    font-size: 100%;
+    background: #ffc;
+    display: block;
+    width: 12em;
+}
+
+
+.draggable-active {
+    color: #66f;
+    filter:alpha(opacity=60);
+    -moz-opacity:0.6;
+    -khtml-opacity: 0.6;
+    opacity: 0.6;
+}
+

Added: pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.dimensions.js
==============================================================================
--- (empty file)
+++ pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.dimensions.js	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,119 @@
+/* Copyright (c) 2007 Paul Bakaus (paul.bakaus at googlemail.com) and Brandon Aaron (brandon.aaron at gmail.com || http://brandonaaron.net)
+ * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
+ * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
+ *
+ * $LastChangedDate: 2007-12-20 08:46:55 -0600 (Thu, 20 Dec 2007) $
+ * $Rev: 4259 $
+ *
+ * Version: 1.2
+ *
+ * Requires: jQuery 1.2+
+ */
+
+(function($){
+	
+$.dimensions = {
+	version: '1.2'
+};
+
+// Create innerHeight, innerWidth, outerHeight and outerWidth methods
+$.each( [ 'Height', 'Width' ], function(i, name){
+	
+	// innerHeight and innerWidth
+	$.fn[ 'inner' + name ] = function() {
+		if (!this[0]) return;
+		
+		var torl = name == 'Height' ? 'Top'    : 'Left',  // top or left
+		    borr = name == 'Height' ? 'Bottom' : 'Right'; // bottom or right
+		
+		return this.is(':visible') ? this[0]['client' + name] : num( this, name.toLowerCase() ) + num(this, 'padding' + torl) + num(this, 'padding' + borr);
+	};
+	
+	// outerHeight and outerWidth
+	$.fn[ 'outer' + name ] = function(options) {
+		if (!this[0]) return;
+		
+		var torl = name == 'Height' ? 'Top'    : 'Left',  // top or left
+		    borr = name == 'Height' ? 'Bottom' : 'Right'; // bottom or right
+		
+		options = $.extend({ margin: false }, options || {});
+		
+		var val = this.is(':visible') ? 
+				this[0]['offset' + name] : 
+				num( this, name.toLowerCase() )
+					+ num(this, 'border' + torl + 'Width') + num(this, 'border' + borr + 'Width')
+					+ num(this, 'padding' + torl) + num(this, 'padding' + borr);
+		
+		return val + (options.margin ? (num(this, 'margin' + torl) + num(this, 'margin' + borr)) : 0);
+	};
+});
+
+// Create scrollLeft and scrollTop methods
+$.each( ['Left', 'Top'], function(i, name) {
+	$.fn[ 'scroll' + name ] = function(val) {
+		if (!this[0]) return;
+		
+		return val != undefined ?
+		
+			// Set the scroll offset
+			this.each(function() {
+				this == window || this == document ?
+					window.scrollTo( 
+						name == 'Left' ? val : $(window)[ 'scrollLeft' ](),
+						name == 'Top'  ? val : $(window)[ 'scrollTop'  ]()
+					) :
+					this[ 'scroll' + name ] = val;
+			}) :
+			
+			// Return the scroll offset
+			this[0] == window || this[0] == document ?
+				self[ (name == 'Left' ? 'pageXOffset' : 'pageYOffset') ] ||
+					$.boxModel && document.documentElement[ 'scroll' + name ] ||
+					document.body[ 'scroll' + name ] :
+				this[0][ 'scroll' + name ];
+	};
+});
+
+$.fn.extend({
+	position: function() {
+		var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results;
+		
+		if (elem) {
+			// Get *real* offsetParent
+			offsetParent = this.offsetParent();
+			
+			// Get correct offsets
+			offset       = this.offset();
+			parentOffset = offsetParent.offset();
+			
+			// Subtract element margins
+			offset.top  -= num(elem, 'marginTop');
+			offset.left -= num(elem, 'marginLeft');
+			
+			// Add offsetParent borders
+			parentOffset.top  += num(offsetParent, 'borderTopWidth');
+			parentOffset.left += num(offsetParent, 'borderLeftWidth');
+			
+			// Subtract the two offsets
+			results = {
+				top:  offset.top  - parentOffset.top,
+				left: offset.left - parentOffset.left
+			};
+		}
+		
+		return results;
+	},
+	
+	offsetParent: function() {
+		var offsetParent = this[0].offsetParent;
+		while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && $.css(offsetParent, 'position') == 'static') )
+			offsetParent = offsetParent.offsetParent;
+		return $(offsetParent);
+	}
+});
+
+function num(el, prop) {
+	return parseInt($.curCSS(el.jquery?el[0]:el,prop,true))||0;
+};
+
+})(jQuery);
\ No newline at end of file

Added: pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.jeditable.js
==============================================================================
--- (empty file)
+++ pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.jeditable.js	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,429 @@
+/*
+ * Jeditable - jQuery in place edit plugin
+ *
+ * Copyright (c) 2006-2008 Mika Tuupola, Dylan Verheul
+ *
+ * Licensed under the MIT license:
+ *   http://www.opensource.org/licenses/mit-license.php
+ *
+ * Project home:
+ *   http://www.appelsiini.net/projects/jeditable
+ *
+ * Based on editable by Dylan Verheul <dylan_at_dyve.net>:
+ *    http://www.dyve.net/jquery/?editable
+ *
+ * Revision: $Id: jquery.jeditable.js 344 2008-03-24 16:02:11Z tuupola $
+ *
+ */
+
+/**
+  * Version 1.5.7
+  *
+  * @name  Jeditable
+  * @type  jQuery
+  * @param String  target             POST URL or function name to send edited content
+  * @param Hash    options            additional options 
+  * @param Function options[callback] Function to run after submitting edited content
+  * @param String  options[name]      POST parameter name of edited content
+  * @param String  options[id]        POST parameter name of edited div id
+  * @param Hash    options[submitdata] Extra parameters to send when submitting edited content.
+  * @param String  options[type]      text, textarea or select
+  * @param Integer options[rows]      number of rows if using textarea
+  * @param Integer options[cols]      number of columns if using textarea
+  * @param Mixed   options[height]    'auto', 'none' or height in pixels
+  * @param Mixed   options[width]     'auto', 'none' or width in pixels 
+  * @param String  options[loadurl]   URL to fetch input content before editing
+  * @param String  options[loadtype]  Request type for load url. Should be GET or POST.
+  * @param String  options[loadtext]  Text to display while loading external content.
+  * @param Hash    options[loaddata]  Extra parameters to pass when fetching content before editing.
+  * @param String  options[data]      Or content given as paramameter.
+  * @param String  options[indicator] indicator html to show when saving
+  * @param String  options[tooltip]   optional tooltip text via title attribute
+  * @param String  options[event]     jQuery event such as 'click' of 'dblclick'
+  * @param String  options[onblur]    'cancel', 'submit' or 'ignore'
+  * @param String  options[submit]    submit button value, empty means no button
+  * @param String  options[cancel]    cancel button value, empty means no button
+  * @param String  options[cssclass]  CSS class to apply to input form. 'inherit' to copy from parent.
+  * @param String  options[style]     Style to apply to input form 'inherit' to copy from parent.
+  * @param String  options[select]    true or false, when true text is highlighted
+  * @param String  options[placeholder] Placeholder text or html to insert when element is empty.
+  *             
+  */
+
+(function($) {
+
+    $.fn.editable = function(target, options) {
+    
+        var settings = {
+            target     : target,
+            name       : 'value',
+            id         : 'id',
+            type       : 'text',
+            width      : 'auto',
+            height     : 'auto',
+            event      : 'click',
+            onblur     : 'cancel',
+            loadtype   : 'GET',
+            loadtext   : 'Loading...',
+            placeholder: 'Click to edit',
+            loaddata   : {},
+            submitdata : {}
+        };
+        
+        if(options) {
+            $.extend(settings, options);
+        }
+    
+        /* setup some functions */
+        var plugin   = $.editable.types[settings.type].plugin || function() { };
+        var submit   = $.editable.types[settings.type].submit || function() { };
+        var buttons  = $.editable.types[settings.type].buttons 
+                    || $.editable.types['defaults'].buttons;
+        var content  = $.editable.types[settings.type].content 
+                    || $.editable.types['defaults'].content;
+        var element  = $.editable.types[settings.type].element 
+                    || $.editable.types['defaults'].element;
+        var callback = settings.callback || function() { };
+        
+        /* add custom event if it does not exist */
+        if  (!$.isFunction($(this)[settings.event])) {
+            $.fn[settings.event] = function(fn){
+          		return fn ? this.bind(settings.event, fn) : this.trigger(settings.event);
+          	}
+        }
+          
+        $(this).attr('title', settings.tooltip);
+        
+        settings.autowidth  = 'auto' == settings.width;
+        settings.autoheight = 'auto' == settings.height;
+
+        return this.each(function() {
+            
+            /* if element is empty add something clickable (if requested) */
+            if (!$.trim($(this).html())) {
+                $(this).html(settings.placeholder);
+            }
+            
+            $(this)[settings.event](function(e) {
+
+                /* save this to self because this changes when scope changes */
+                var self = this;
+
+                /* prevent throwing an exeption if edit field is clicked again */
+                if (self.editing) {
+                    return;
+                }
+
+                /* figure out how wide and tall we are, visibility trick */
+                /* is workaround for http://dev.jquery.com/ticket/2190 */
+                $(self).css('visibility', 'hidden');                
+                if (settings.width != 'none') {
+                    settings.width = 
+                        settings.autowidth ? $(self).width()  : settings.width;
+                }
+                if (settings.height != 'none') {
+                    settings.height = 
+                        settings.autoheight ? $(self).height() : settings.height;
+                }
+                $(this).css('visibility', '');
+                
+                
+                /* remove placeholder text, replace is here because of IE */
+                if ($(this).html().toLowerCase().replace(/;/, '') == 
+                    settings.placeholder.toLowerCase().replace(/;/, '')) {
+                        $(this).html('');
+                }
+                                
+                self.editing    = true;
+                self.revert     = $(self).html();
+                $(self).html('');
+
+                /* create the form object */
+                var form = $('<form/>');
+                
+                /* apply css or style or both */
+                if (settings.cssclass) {
+                    if ('inherit' == settings.cssclass) {
+                        form.attr('class', $(self).attr('class'));
+                    } else {
+                        form.attr('class', settings.cssclass);
+                    }
+                }
+
+                if (settings.style) {
+                    if ('inherit' == settings.style) {
+                        form.attr('style', $(self).attr('style'));
+                        /* IE needs the second line or display wont be inherited */
+                        form.css('display', $(self).css('display'));                
+                    } else {
+                        form.attr('style', settings.style);
+                    }
+                }
+
+                /* add main input element to form and store it in input */
+                var input = element.apply(form, [settings, self]);
+
+                /* set input content via POST, GET, given data or existing value */
+                var input_content;
+                
+                if (settings.loadurl) {
+                    var t = setTimeout(function() {
+                        input.disabled = true;
+                        content.apply(form, [settings.loadtext, settings, self]);
+                    }, 100);
+
+                    var loaddata = {};
+                    loaddata[settings.id] = self.id;
+                    if ($.isFunction(settings.loaddata)) {
+                        $.extend(loaddata, settings.loaddata.apply(self, [self.revert, settings]));
+                    } else {
+                        $.extend(loaddata, settings.loaddata);
+                    }
+                    $.ajax({
+                       type : settings.loadtype,
+                       url  : settings.loadurl,
+                       data : loaddata,
+                       async : false,
+                       success: function(result) {
+                       	  window.clearTimeout(t);
+                       	  input_content = result;
+                          input.disabled = false;
+                       }
+                    });
+                } else if (settings.data) {
+                    input_content = settings.data;
+                    if ($.isFunction(settings.data)) {
+                        input_content = settings.data.apply(self, [self.revert, settings]);
+                    }
+                } else {
+                    input_content = self.revert; 
+                }
+                content.apply(form, [input_content, settings, self]);
+
+                input.attr('name', settings.name);
+        
+                /* add buttons to the form */
+                buttons.apply(form, [settings, self]);
+         
+                /* attach 3rd party plugin if requested */
+                plugin.apply(form, [settings, self]);
+                
+                /* add created form to self */
+                $(self).append(form);
+
+                /* focus to first visible form element */
+                $(':input:visible:enabled:first', form).focus();
+
+                /* highlight input contents when requested */
+                if (settings.select) {
+                    input.select();
+                }
+        
+                /* discard changes if pressing esc */
+                input.keydown(function(e) {
+                    if (e.keyCode == 27) {
+                        e.preventDefault();
+                        reset();
+                    }
+                });
+
+                /* discard, submit or nothing with changes when clicking outside */
+                /* do nothing is usable when navigating with tab */
+                var t;
+                if ('cancel' == settings.onblur) {
+                    input.blur(function(e) {
+                        t = setTimeout(reset, 500);
+                    });
+                } else if ('submit' == settings.onblur) {
+                    input.blur(function(e) {
+                        form.submit();
+                    });
+                } else if ($.isFunction(settings.onblur)) {
+                    input.blur(function(e) {
+                        settings.onblur.apply(self, [input.val(), settings]);
+                    });
+                } else {
+                    input.blur(function(e) {
+                      /* TODO: maybe something here */
+                    });
+                }
+
+                form.submit(function(e) {
+
+                    if (t) { 
+                        clearTimeout(t);
+                    }
+
+                    /* do no submit */
+                    e.preventDefault(); 
+            
+                    /* if this input type has a call before submit hook, call it */
+                    submit.apply(form, [settings, self]);
+
+                    /* check if given target is function */
+                    if ($.isFunction(settings.target)) {
+                        var str = settings.target.apply(self, [input.val(), settings]);
+                        $(self).html(str);
+                        self.editing = false;
+                        callback.apply(self, [self.innerHTML, settings]);
+                        /* TODO: this is not dry */                              
+                        if (!$.trim($(self).html())) {
+                            $(self).html(settings.placeholder);
+                        }
+                    } else {
+                        /* add edited content and id of edited element to POST */
+                        var submitdata = {};
+                        submitdata[settings.name] = input.val();
+                        submitdata[settings.id] = self.id;
+                        /* add extra data to be POST:ed */
+                        if ($.isFunction(settings.submitdata)) {
+                            $.extend(submitdata, settings.submitdata.apply(self, [self.revert, settings]));
+                        } else {
+                            $.extend(submitdata, settings.submitdata);
+                        }          
+
+                        /* show the saving indicator */
+                        $(self).html(settings.indicator);
+                        $.post(settings.target, submitdata, function(str) {
+                            $(self).html(str);
+                            self.editing = false;
+                            callback.apply(self, [self.innerHTML, settings]);
+                            /* TODO: this is not dry */                              
+                            if (!$.trim($(self).html())) {
+                                $(self).html(settings.placeholder);
+                            }
+                        });
+                    }
+                     
+                    return false;
+                });
+
+                function reset() {
+                    $(self).html(self.revert);
+                    self.editing   = false;
+                    if (!$.trim($(self).html())) {
+                        $(self).html(settings.placeholder);
+                    }
+                }
+
+            });
+        });
+
+    };
+
+
+    $.editable = {
+        types: {
+            defaults: {
+                element : function(settings, original) {
+                    var input = $('<input type="hidden">');                
+                    $(this).append(input);
+                    return(input);
+                },
+                content : function(string, settings, original) {
+                    $(':input:first', this).val(string);
+                },
+                buttons : function(settings, original) {
+                    var form = this;
+                    if (settings.submit) {
+                        /* if given html string use that */
+                        if (settings.submit.match(/>$/)) {
+                            var submit = $(settings.submit).click(function() {
+                                form.submit();
+                            });
+                        /* otherwise use button with given string as text */
+                        } else {
+                            var submit = $('<button type="submit">');
+                            submit.html(settings.submit);                            
+                        }
+                        $(this).append(submit);
+                    }
+                    if (settings.cancel) {
+                        /* if given html string use that */
+                        if (settings.cancel.match(/>$/)) {
+                            var cancel = $(settings.cancel);
+                        /* otherwise use button with given string as text */
+                        } else {
+                            var cancel = $('<button type="cancel">');
+                            cancel.html(settings.cancel);
+                        }
+                        $(this).append(cancel);
+
+                        $(cancel).click(function(event) {
+                            $(original).html(original.revert);
+                            original.editing = false;
+                            if (!$.trim($(original).html())) {
+                                $(original).html(settings.placeholder);
+                            }
+                            return false;
+                        });
+                    }
+                }
+            },
+            text: {
+                element : function(settings, original) {
+                    var input = $('<input>');
+                    if (settings.width  != 'none') { input.width(settings.width);  }
+                    if (settings.height != 'none') { input.height(settings.height); }
+                    /* https://bugzilla.mozilla.org/show_bug.cgi?id=236791 */
+                    //input[0].setAttribute('autocomplete','off');
+                    input.attr('autocomplete','off');
+                    $(this).append(input);
+                    return(input);
+                }
+            },
+            textarea: {
+                element : function(settings, original) {
+                    var textarea = $('<textarea>');
+                    if (settings.rows) {
+                        textarea.attr('rows', settings.rows);
+                    } else {
+                        textarea.height(settings.height);
+                    }
+                    if (settings.cols) {
+                        textarea.attr('cols', settings.cols);
+                    } else {
+                        textarea.width(settings.width);
+                    }
+                    $(this).append(textarea);
+                    return(textarea);
+                }
+            },
+            select: {
+                element : function(settings, original) {
+                    var select = $('<select>');
+                    $(this).append(select);
+                    return(select);
+                },
+                content : function(string, settings, original) {
+                    if (String == string.constructor) { 	 
+                        eval ('var json = ' + string);
+                        for (var key in json) {
+                            if (!json.hasOwnProperty(key)) {
+                                continue;
+                            }
+                            if ('selected' == key) {
+                                continue;
+                            } 
+                            var option = $('<option>').val(key).append(json[key]);
+                            $('select', this).append(option); 	 
+                        }
+                    }
+                    /* Loop option again to set selected. IE needed this... */ 
+                    $('select', this).children().each(function() {
+                        if ($(this).val() == json['selected'] || 
+                            $(this).text() == original.revert) {
+                                $(this).attr('selected', 'selected');
+                        };
+                    });
+                }
+            }
+        },
+
+        /* Add new input type */
+        addInputType: function(name, input) {
+            $.editable.types[name] = input;
+        }
+    };
+
+})(jQuery);

Added: pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.superflydom.js
==============================================================================
--- (empty file)
+++ pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.superflydom.js	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,163 @@
+/**
+ * jQuery Plugin SuperFlyDOM v0.9g
+ *
+ * Create DOM elements on the fly and automatically append or prepend them to another DOM object.
+ * There are also template functions (tplAppend and tplPrepend) that can take a JSON-formatted
+ * complex HTML structure, apply a dataset, and therefore add siblings way faster
+ * 
+ * This plugin is built off of FlyDom 3.0.8, by dohpaz
+ * [http://dohpaz.mine.nu/jquery/jquery.flydom.html], who was inspired by "Oslow"
+ * [http://mg.to/2006/02/27/easy-dom-creation-for-jquery-and-prototype#comment-176],
+ * and since I could not get dohpaz code to work with my template (and since dohpaz
+ * could not get Oslow's code to work), and neither Michael Geary's code nor Sean's
+ * [http://www.pinkblack.org/itblog/?page_id=22] code were jQuery style and chainable,
+ * and I wanted a ton of features anyway, while retaining a small code base, I decided
+ * to rip apart, clean up (JSLint),and add features to their plugins. My hope is that
+ * this version will be easier to understand, more forgiving and flexible, and maintain
+ * with future versions of the fantastic framework which is jQuery.
+ *
+ * Note: For event attaching using the liveQuery plugin is highly recommended.
+ *
+ * Copyright (c) 2007 Charles Phillips [charles at doublerebel dot com]
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
+ * and GPL (GPL-LICENSE.txt) licenses.
+ *
+ * @version	 $Id: jquery.superflydom-0.9g.js 9 2007-08-27 00:02:34 polyrhythmic $
+ *
+ * @author	  Charles Phillips [charles at doublerebel dot com]
+ * @copyright   (C) 2007. All rights reserved.
+ *
+ * @license	 http://www.opensource.org/licenses/mit-license.php
+ * @license	 http://www.opensource.org/licenses/gpl-license.php
+ *
+ * @package	 jQuery Plugins
+ * @subpackage  SuperFlyDOM
+ *
+ * @todo		 (dohpaz): Cache basic elements that are created, and if an already existing basic element is
+ *			 asked to be created an additional time, use a copy of the cached element to build from.
+ *			 (Charles): If dohpaz accomplishes this I will be happy to merge it with my code fork.
+ * 
+ */
+
+/**
+ * Create DOM elements on the fly and automatically append them to the current DOM obejct
+ *
+ * @uses	jQuery
+ *
+ * @param   string  element - The name of the DOM element to create (i.e., img, table, a, etc)
+ * @param   object  attrs   - An optional object of attributes to apply to the element
+ * @param   string  text    - An optional string for text node to prepend to element
+ * @param   array   content - An optional array of content (or element children) to append to element
+ *
+ * @return  jQuery  element - The jQuery object representing the new element
+ *
+ * @since   FlyDom 1.0
+ */
+
+( function($) {
+	var el;
+	if ($.elHash === undefined) { //If there is no jQuery global hash yet defined,
+		var elArray, elHash = {}; //Define hash table of HTML 4.01 DOM Elements, excluding deprecated elements.
+		elArray = "a|abbr|acronym|address|area|b|base|bdo|big|blockquote|body|br|button|caption|cite|code|col|colgroup|dd|del|dfn|div|dl|dt|em|fieldset|form|frame|frameset|h1-h6|head|hr|html|i|iframe|img|input|ins|kbd|label|legend|li|link|map|meta|noframes|noscript|object|ol|optgroup|option|p|param|pre|q|samp|script|select|small|span|strong|style|sub|sup|table|tbody|td|textarea|tfoot|th|thead|title|tr|tt|ul|var".split("|"); //packed hash
+		for (var i = 0; i < elArray.length; i++) { elHash[elArray[i]] = true; } //Process hash
+		$.elHash = elHash; //Set jQuery global hash
+	}
+	if ($.browser.msie) { //From Dean Edwards IE7 fixes [http://dean.edwards.name] I can't believe I have to do this, damn you IE
+		Array.prototype.unshift = function() {
+			var a = Array.prototype.concat.call(Array.prototype.slice.apply(arguments, [0]), this), i = a.length;
+			while (i--) { this[i] = a[i]; }
+			return this.length;
+		}
+	}
+	$.fn.extend({
+		createAppend: function() {
+			if (arguments.length === 0) { return this; } //If nothing to process, move along!
+			var ie, pEl, elH = $.elHash, arg1 = arguments[0], arg2 = arguments[1], a = 1;
+			pEl = this[0] || this; //Parent element may be either jQuery Object or DOM element
+			if (typeof arg1 === "number") { arg1 = String(arg1); } //Pure numbers cannot be made into textNodes, nor can you run RegExp's or .constructor against them.  I learned this the hard way.
+			if (typeof arg1 === "string") { //We should have a string by now, or the input JSON was improperly formatted.
+				if (arg1 in elH) { //If first argument is valid HTML Element
+					ie = $.browser.msie;
+					el = (ie && arg1 === 'input') ? '<input type="' + arg2.type + '" />': arg1; //Fix input for ie. REQUIRES attribute type.
+					el = document.createElement(el);
+					if (ie && pEl.nodeName.toLowerCase() === "table" && el.nodeName.toLowerCase() === "tr") { //Fix table/tbody for ie.
+						pEl = pEl.parentNode.getElementsByTagName('tbody')[0] || pEl.appendChild(document.createElement('tbody')); // Create a new tbody
+					}
+					el = pEl.appendChild(el); // Add the element directly to the parentElement
+					if (arg2.constructor === Object) { //if element's sibling is Attributes Object, process with jQuery
+						for (attr in arg2) { $.attr(el, attr, arg2[attr]); }
+						a++;
+					}
+					if (arguments.length > a) { //If element has more objects in arguments[] than we have processed
+						if (arguments[a].constructor === Array){ //and the next object is an array, it is element's children
+							el = $.fn.createAppend.apply($(el), arguments[a]); //recursively apply
+							a++;
+						}
+					}
+				} else if (arg1.match(/(<\S[^><]*>)|(&.+;)/g) !== null &&
+						 arg1.tagName.toUpperCase() !== 'TEXTAREA') { //Check to see if TextNode is actually mixed HTML, but not textarea
+						pEl.innerHTML += arg1; //Append HTML
+						el = pEl; //We have no information about what could be in that HTML, so return parent
+				} else { el = pEl.appendChild(document.createTextNode(arg1)); } //Otherwise just append simple TextNode
+			} else { } //There should be no else.  Todo: Add error catching with throw/catch on string instead of if - Instead of hashing?
+			if (arguments.length > a) { //If element has unprocessed siblings
+				el = $.fn.createAppend.apply($(pEl), Array.prototype.slice.call(arguments, a)); //Process siblings (sliced arguments array) and append to parent element
+			}
+			return $(el); //We like chaining
+		},
+		
+		createPrepend: function() {
+			var al = arguments.length;
+			if (al === 0) { return this; } //If nothing to process, move along!
+			var elH = $.elHash, ie, pEl, hCN = this[0].hasChildNodes(), arg_l, arg = [];
+			arg_l = arg.push(arguments[al-1]); //Start stacking our queue
+			pEl = this[0] || this; //Parent element may be either jQuery Object or DOM element
+			if (arg[0].constructor === Array) { //If element to prepend has children, add to bottom of queue
+				arg_l = arg.unshift(arguments[al - 1 - arg_l]);
+			}
+			if (arg[0].constructor === Object) { //if element to prepend has attributes, add to queue
+				arg_l = arg.unshift(arguments[al - 1 - arg_l]);
+			}
+			if (typeof arg[0] === "number") { arg[0] = String(arg[0]); } //Pure numbers cannot be made into textNodes, nor can you run RegExp's or .constructor against them.  I learned this the hard way.
+			if (typeof arg[0] === "string") { //We should have a string by now, or the input JSON was improperly formatted.
+				if (arg[0] in elH) { //If first argument is valid HTML Element
+					ie = $.browser.msie;
+					el = (ie && arg[0] === 'input') ? '<input type="' + arg[1].type + '" />': arg[0]; //Fix input for ie. REQUIRES attribute type.
+					arg.shift();
+					el = document.createElement(el);
+					if (ie && pEl.nodeName.toLowerCase() === "table" && el.nodeName.toLowerCase() === "tr") { //Fix table/tbody for ie.
+						pEl = pEl.parentNode.getElementsByTagName('tbody')[0] || pEl.appendChild(document.createElement('tbody')); // Create a new tbody
+					}
+					if (hCN) { el = pEl.insertBefore(el, pEl.firstChild); } //If parent already has child nodes, add new element before them
+					else { el = pEl.appendChild(el); } // Otherwise add the element directly to the parentElement
+					if (arg[0].constructor === Object) {  //if element's sibling is Attributes Object, process with jQuery
+						for (attr in arg[0]) { $.attr(el, attr, arg[0][attr]); }
+						arg.shift();
+					}
+					if (arg[0] !== undefined && arg[0].constructor === Array) { //If there are still elements in the queue, and it's an array
+						el = $.fn.createPrepend.apply($(el), arg[0]); //Then recursively prepend the children
+					}
+				} else if (arg[0].match(/(<\S[^><]*>)|(&.+;)/g) !== null &&
+						 arg[0].tagName.toUpperCase() !== 'TEXTAREA') { //Check to see if TextNode is actually mixed HTML, but not textarea
+						pEl.innerHTML = arg.pop() + pEl.innerHTML; //Prepend HTML
+						el = pEl; //We have no information about what could be in that HTML, so return parent
+				} else {
+					el = document.createTextNode(arg[0]); //Otherwise just create simple TextNode
+					el = (hCN) ? pEl.insertBefore(el, pEl.firstChild) : pEl.appendChild(el); //If parent already has child nodes, add new element before them
+				}
+			} else { } //There should be no else.  Todo: Add error catching with throw/catch on string instead of if - Instead of hashing?
+			if (al > arg_l) { //If element has unprocessed siblings
+				el = $.fn.createPrepend.apply($(pEl), Array.prototype.slice.call(arguments, 0, -arg_l)); //Process siblings (sliced arguments array) and prepend to parent element
+			}
+			return $(el);
+		},
+
+		tplAppend: function(json, tpl) {
+			return $.fn.createAppend.apply(this, tpl.call(json)); // Return ourself for chaining
+		},
+		
+		tplPrepend: function(json, tpl) {
+			return $.fn.createPrepend.apply(this, tpl.call(json)); // Return ourself for chaining
+		}
+	});
+})(jQuery);
\ No newline at end of file

Added: pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4/ui.core.js
==============================================================================
--- (empty file)
+++ pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4/ui.core.js	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,237 @@
+/*
+ * jQuery UI @VERSION
+ *
+ * Copyright (c) 2008 Paul Bakaus (ui.jquery.com)
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
+ * and GPL (GPL-LICENSE.txt) licenses.
+ *
+ * http://docs.jquery.com/UI
+ *
+ * $Date: 2008-05-04 16:52:15 +0200 (So, 04 Mai 2008) $
+ * $Rev: 5419 $
+ */
+;(function($) {
+	
+	$.ui = {
+		plugin: {
+			add: function(module, option, set) {
+				var proto = $.ui[module].prototype;
+				for(var i in set) {
+					proto.plugins[i] = proto.plugins[i] || [];
+					proto.plugins[i].push([option, set[i]]);
+				}
+			},
+			call: function(instance, name, args) {
+				var set = instance.plugins[name];
+				if(!set) { return; }
+				
+				for (var i = 0; i < set.length; i++) {
+					if (instance.options[set[i][0]]) {
+						set[i][1].apply(instance.element, args);
+					}
+				}
+			}	
+		},
+		cssCache: {},
+		css: function(name) {
+			if ($.ui.cssCache[name]) { return $.ui.cssCache[name]; }
+			var tmp = $('<div class="ui-resizable-gen">').addClass(name).css({position:'absolute', top:'-5000px', left:'-5000px', display:'block'}).appendTo('body');
+			
+			//if (!$.browser.safari)
+				//tmp.appendTo('body'); 
+			
+			//Opera and Safari set width and height to 0px instead of auto
+			//Safari returns rgba(0,0,0,0) when bgcolor is not set
+			$.ui.cssCache[name] = !!(
+				(!(/auto|default/).test(tmp.css('cursor')) || (/^[1-9]/).test(tmp.css('height')) || (/^[1-9]/).test(tmp.css('width')) || 
+				!(/none/).test(tmp.css('backgroundImage')) || !(/transparent|rgba\(0, 0, 0, 0\)/).test(tmp.css('backgroundColor')))
+			);
+			try { $('body').get(0).removeChild(tmp.get(0));	} catch(e){}
+			return $.ui.cssCache[name];
+		},
+		disableSelection: function(e) {
+			e.unselectable = "on";
+			e.onselectstart = function() { return false; };
+			if (e.style) { e.style.MozUserSelect = "none"; }
+		},
+		enableSelection: function(e) {
+			e.unselectable = "off";
+			e.onselectstart = function() { return true; };
+			if (e.style) { e.style.MozUserSelect = ""; }
+		},
+		hasScroll: function(e, a) {
+			var scroll = /top/.test(a||"top") ? 'scrollTop' : 'scrollLeft', has = false;
+			if (e[scroll] > 0) return true; e[scroll] = 1;
+			has = e[scroll] > 0 ? true : false; e[scroll] = 0;
+			return has;
+		}
+	};
+	
+	
+	/** jQuery core modifications and additions **/
+	
+	var _remove = $.fn.remove;
+	$.fn.remove = function() {
+		$("*", this).add(this).trigger("remove");
+		return _remove.apply(this, arguments );
+	};
+	
+	// $.widget is a factory to create jQuery plugins
+	// taking some boilerplate code out of the plugin code
+	// created by Scott González and Jörn Zaefferer
+	function getter(namespace, plugin, method) {
+		var methods = $[namespace][plugin].getter || [];
+		methods = (typeof methods == "string" ? methods.split(/,?\s+/) : methods);
+		return ($.inArray(method, methods) != -1);
+	};
+	
+	var widgetPrototype = {
+		init: function() {},
+		destroy: function() {},
+		
+		getData: function(e, key) {
+			return this.options[key];
+		},
+		setData: function(e, key, value) {
+			this.options[key] = value;
+		},
+		
+		enable: function() {
+			this.setData(null, 'disabled', false);
+		},
+		disable: function() {
+			this.setData(null, 'disabled', true);
+		}
+	};
+	
+	$.widget = function(name, prototype) {
+		var namespace = name.split(".")[0];
+		name = name.split(".")[1];
+		// create plugin method
+		$.fn[name] = function(options, data) {
+			var isMethodCall = (typeof options == 'string'),
+				args = arguments;
+			
+			if (isMethodCall && getter(namespace, name, options)) {
+				var instance = $.data(this[0], name);
+				return (instance ? instance[options](data) : undefined); 
+			}
+			
+			return this.each(function() {
+				var instance = $.data(this, name);
+				if (!instance) {
+					$.data(this, name, new $[namespace][name](this, options));
+				} else if (isMethodCall) {
+					instance[options].apply(instance, $.makeArray(args).slice(1));
+				}
+			});
+		};
+		
+		// create widget constructor
+		$[namespace][name] = function(element, options) {
+			var self = this;
+			
+			this.options = $.extend({}, $[namespace][name].defaults, options);
+			this.element = $(element)
+				.bind('setData.' + name, function(e, key, value) {
+					return self.setData(e, key, value);
+				})
+				.bind('getData.' + name, function(e, key) {
+					return self.getData(e, key);
+				})
+				.bind('remove', function() {
+					return self.destroy();
+				});
+			this.init();
+		};
+		
+		// add widget prototype
+		$[namespace][name].prototype = $.extend({}, widgetPrototype, prototype);
+	};
+	
+	
+	/** Mouse Interaction Plugin **/
+	
+	$.widget("ui.mouse", {
+		init: function() {
+			var self = this;
+			
+			this.element
+				.bind('mousedown.mouse', function() { return self.click.apply(self, arguments); })
+				.bind('mouseup.mouse', function() { (self.timer && clearInterval(self.timer)); })
+				.bind('click.mouse', function() { if(self.initialized) { self.initialized = false; return false; } });
+			//Prevent text selection in IE
+			if ($.browser.msie) {
+				this.unselectable = this.element.attr('unselectable');
+				this.element.attr('unselectable', 'on');
+			}
+		},
+		destroy: function() {
+			this.element.unbind('.mouse').removeData("mouse");
+			($.browser.msie && this.element.attr('unselectable', this.unselectable));
+		},
+		trigger: function() { return this.click.apply(this, arguments); },
+		click: function(e) {
+		
+			if(    e.which != 1 //only left click starts dragging
+				|| $.inArray(e.target.nodeName.toLowerCase(), this.options.dragPrevention || []) != -1 // Prevent execution on defined elements
+				|| (this.options.condition && !this.options.condition.apply(this.options.executor || this, [e, this.element])) //Prevent execution on condition
+			) { return true; }
+		
+			var self = this;
+			this.initialized = false;
+			var initialize = function() {
+				self._MP = { left: e.pageX, top: e.pageY }; // Store the click mouse position
+				$(document).bind('mouseup.mouse', function() { return self.stop.apply(self, arguments); });
+				$(document).bind('mousemove.mouse', function() { return self.drag.apply(self, arguments); });
+		
+				if(!self.initalized && Math.abs(self._MP.left-e.pageX) >= self.options.distance || Math.abs(self._MP.top-e.pageY) >= self.options.distance) {
+					(self.options.start && self.options.start.call(self.options.executor || self, e, self.element));
+					(self.options.drag && self.options.drag.call(self.options.executor || self, e, this.element)); //This is actually not correct, but expected
+					self.initialized = true;
+				}
+			};
+
+			if(this.options.delay) {
+				if(this.timer) { clearInterval(this.timer); }
+				this.timer = setTimeout(initialize, this.options.delay);
+			} else {
+				initialize();
+			}
+				
+			return false;
+			
+		},
+		stop: function(e) {
+			
+			if(!this.initialized) {
+				return $(document).unbind('mouseup.mouse').unbind('mousemove.mouse');
+			}
+
+			(this.options.stop && this.options.stop.call(this.options.executor || this, e, this.element));
+			
+			$(document).unbind('mouseup.mouse').unbind('mousemove.mouse');
+			return false;
+			
+		},
+		drag: function(e) {
+
+			var o = this.options;
+			if ($.browser.msie && !e.button) {
+				return this.stop.call(this, e); // IE mouseup check
+			}
+			
+			if(!this.initialized && (Math.abs(this._MP.left-e.pageX) >= o.distance || Math.abs(this._MP.top-e.pageY) >= o.distance)) {
+				(o.start && o.start.call(o.executor || this, e, this.element));
+				this.initialized = true;
+			} else {
+				if(!this.initialized) { return false; }
+			}
+
+			(o.drag && o.drag.call(this.options.executor || this, e, this.element));
+			return false;
+			
+		}
+	});
+	
+})(jQuery);

Added: pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4/ui.draggable.js
==============================================================================
--- (empty file)
+++ pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4/ui.draggable.js	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,533 @@
+/*
+ * jQuery UI Draggable
+ *
+ * Copyright (c) 2008 Paul Bakaus
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
+ * and GPL (GPL-LICENSE.txt) licenses.
+ * 
+ * http://docs.jquery.com/UI/Draggables
+ *
+ * Depends:
+ *	ui.core.js
+ *
+ * Revision: $Id: ui.draggable.js 5452 2008-05-05 16:42:08Z rdworth $
+ */
+
+;(function($) {
+	
+	$.widget("ui.draggable", {
+		init: function() {
+			
+			//Initialize needed constants
+			var o = this.options;
+
+			//Initialize mouse events for interaction
+			this.element.mouse({
+				executor: this,
+				delay: o.delay,
+				distance: o.distance,
+				dragPrevention: o.cancel,
+				start: this.start,
+				stop: this.stop,
+				drag: this.drag,
+				condition: function(e) {
+					var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false;
+					if(!handle) $(this.options.handle, this.element).each(function() { if(this == e.target) handle = true; });
+					return !(e.target.className.indexOf("ui-resizable-handle") != -1 || this.options.disabled) && handle;
+				}
+			});
+			
+			//Position the node
+			if(o.helper == 'original' && !(/(relative|absolute|fixed)/).test(this.element.css('position')))
+				this.element.css('position', 'relative');
+			
+		},
+		start: function(e) {
+
+			var o = this.options;
+			if($.ui.ddmanager) $.ui.ddmanager.current = this;
+			
+			//Create and append the visible helper
+			this.helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [e])) : (o.helper == 'clone' ? this.element.clone() : this.element);
+			if(!this.helper.parents('body').length) this.helper.appendTo((o.appendTo == 'parent' ? this.element[0].parentNode : o.appendTo));
+			if(!this.helper.css("position") || this.helper.css("position") == "static") this.helper.css("position", "absolute");
+
+			/*
+			 * - Position generation -
+			 * This block generates everything position related - it's the core of draggables.
+			 */
+			
+			this.margins = {																				//Cache the margins
+				left: (parseInt(this.element.css("marginLeft"),10) || 0),
+				top: (parseInt(this.element.css("marginTop"),10) || 0)
+			};		
+
+			this.cssPosition = this.helper.css("position");													//Store the helper's css position
+			this.offset = this.element.offset();															//The element's absolute position on the page
+			this.offset = {																					//Substract the margins from the element's absolute offset
+				top: this.offset.top - this.margins.top,
+				left: this.offset.left - this.margins.left
+			};
+
+			this.offset.click = {																			//Where the click happened, relative to the element
+				left: e.pageX - this.offset.left,
+				top: e.pageY - this.offset.top
+			};
+	
+			this.offsetParent = this.helper.offsetParent(); var po = this.offsetParent.offset();			//Get the offsetParent and cache its position
+			this.offset.parent = {																			//Store its position plus border
+				top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
+				left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
+			};
+	
+			var p = this.element.position();																//This is a relative to absolute position minus the actual position calculation - only used for relative positioned helpers
+			this.offset.relative = this.cssPosition == "relative" ? {
+				top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.offsetParent[0].scrollTop,
+				left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.offsetParent[0].scrollLeft
+			} : { top: 0, left: 0 };
+		
+			this.originalPosition = this.generatePosition(e);												//Generate the original position
+			this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Cache the helper size
+
+			if(o.cursorAt) {
+				if(o.cursorAt.left != undefined) this.offset.click.left = o.cursorAt.left;
+				if(o.cursorAt.right != undefined) this.offset.click.left = this.helperProportions.width - o.cursorAt.right;
+				if(o.cursorAt.top != undefined) this.offset.click.top = o.cursorAt.top;
+				if(o.cursorAt.bottom != undefined) this.offset.click.top = this.helperProportions.height - o.cursorAt.bottom;
+			}
+
+
+			/*
+			 * - Position constraining -
+			 * Here we prepare position constraining like grid and containment.
+			 */	
+			
+			if(o.containment) {
+				if(o.containment == 'parent') o.containment = this.helper[0].parentNode;
+				if(o.containment == 'document') this.containment = [0,0,$(document).width(), ($(document).height() || document.body.parentNode.scrollHeight)];
+				if(!(/^(document|window|parent)$/).test(o.containment)) {
+					var ce = $(o.containment)[0];
+					var co = $(o.containment).offset();
+
+					this.containment = [
+						co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.relative.left - this.offset.parent.left,
+						co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.relative.top - this.offset.parent.top,
+						co.left+Math.max(ce.scrollWidth,ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.relative.left - this.offset.parent.left - this.helperProportions.width - this.margins.left - (parseInt(this.element.css("marginRight"),10) || 0),
+						co.top+Math.max(ce.scrollHeight,ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.relative.top - this.offset.parent.top - this.helperProportions.height - this.margins.top - (parseInt(this.element.css("marginBottom"),10) || 0)
+					];
+				}
+			}
+
+
+			//Call plugins and callbacks
+			this.propagate("start", e);
+
+			this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Recache the helper size
+			if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e);
+
+			return false;
+
+		},
+		convertPositionTo: function(d, pos) {
+			if(!pos) pos = this.position;
+			var mod = d == "absolute" ? 1 : -1;
+			return {
+				top: (
+					pos.top																	// the calculated relative position
+					+ this.offset.relative.top	* mod										// Only for relative positioned nodes: Relative offset from element to offset parent
+					+ this.offset.parent.top * mod											// The offsetParent's offset without borders (offset + border)
+					- (this.cssPosition == "fixed" ? 0 : this.offsetParent[0].scrollTop) * mod	// The offsetParent's scroll position, not if the element is fixed
+					+ this.margins.top * mod												//Add the margin (you don't want the margin counting in intersection methods)
+				),
+				left: (
+					pos.left																// the calculated relative position
+					+ this.offset.relative.left	* mod										// Only for relative positioned nodes: Relative offset from element to offset parent
+					+ this.offset.parent.left * mod											// The offsetParent's offset without borders (offset + border)
+					- (this.cssPosition == "fixed" ? 0 : this.offsetParent[0].scrollLeft) * mod	// The offsetParent's scroll position, not if the element is fixed
+					+ this.margins.left * mod												//Add the margin (you don't want the margin counting in intersection methods)
+				)
+			};
+		},
+		generatePosition: function(e) {
+			
+			var o = this.options;
+			var position = {
+				top: (
+					e.pageY																	// The absolute mouse position
+					- this.offset.click.top													// Click offset (relative to the element)
+					- this.offset.relative.top												// Only for relative positioned nodes: Relative offset from element to offset parent
+					- this.offset.parent.top												// The offsetParent's offset without borders (offset + border)
+					+ (this.cssPosition == "fixed" ? 0 : this.offsetParent[0].scrollTop)	// The offsetParent's scroll position, not if the element is fixed
+				),
+				left: (
+					e.pageX																	// The absolute mouse position
+					- this.offset.click.left												// Click offset (relative to the element)
+					- this.offset.relative.left												// Only for relative positioned nodes: Relative offset from element to offset parent
+					- this.offset.parent.left												// The offsetParent's offset without borders (offset + border)
+					+ (this.cssPosition == "fixed" ? 0 : this.offsetParent[0].scrollLeft)	// The offsetParent's scroll position, not if the element is fixed
+				)
+			};
+
+			if(!this.originalPosition) return position;										//If we are not dragging yet, we won't check for options
+			
+			
+			/*
+			 * - Position constraining -
+			 * Constrain the position to a mix of grid, containment.
+			 */
+			if(this.containment) {
+				if(position.left < this.containment[0]) position.left = this.containment[0];
+				if(position.top < this.containment[1]) position.top = this.containment[1];
+				if(position.left > this.containment[2]) position.left = this.containment[2];
+				if(position.top > this.containment[3]) position.top = this.containment[3];
+			}
+			
+			if(o.grid) {
+				var top = this.originalPosition.top + Math.round((position.top - this.originalPosition.top) / o.grid[1]) * o.grid[1];
+				position.top = this.containment ? (!(top < this.containment[1] || top > this.containment[3]) ? top : (!(top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
+
+				var left = this.originalPosition.left + Math.round((position.left - this.originalPosition.left) / o.grid[0]) * o.grid[0];
+				position.left = this.containment ? (!(left < this.containment[0] || left > this.containment[2]) ? left : (!(left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
+			}
+			
+			return position;
+		},
+		drag: function(e) {
+
+			//Compute the helpers position
+			this.position = this.generatePosition(e);
+			this.positionAbs = this.convertPositionTo("absolute");
+
+			//Call plugins and callbacks and use the resulting position if something is returned		
+			this.position = this.propagate("drag", e) || this.position;
+			
+			if(!this.options.axis || this.options.axis == "x") this.helper[0].style.left = this.position.left+'px';
+			if(!this.options.axis || this.options.axis == "y") this.helper[0].style.top = this.position.top+'px';
+			if($.ui.ddmanager) $.ui.ddmanager.drag(this, e);
+			return false;
+
+		},
+		stop: function(e) {
+		
+			//If we are using droppables, inform the manager about the drop
+			if ($.ui.ddmanager && !this.options.dropBehaviour)
+				$.ui.ddmanager.drop(this, e);
+				
+			if(this.options.revert) {
+				var self = this;
+				$(this.helper).animate(this.originalPosition, parseInt(this.options.revert, 10) || 500, function() {
+					self.propagate("stop", e);
+					self.clear();
+				});
+			} else {
+				this.propagate("stop", e);
+				this.clear();
+			}
+
+			return false;
+			
+		},
+		clear: function() {
+			if(this.options.helper != 'original' && !this.cancelHelperRemoval) this.helper.remove();
+			if($.ui.ddmanager) $.ui.ddmanager.current = null;
+			this.helper = null;
+			this.cancelHelperRemoval = false;
+		},
+		
+		// From now on bulk stuff - mainly helpers
+		plugins: {},
+		ui: function(e) {
+			return {
+				helper: this.helper,
+				position: this.position,
+				absolutePosition: this.positionAbs,
+				options: this.options			
+			};
+		},
+		propagate: function(n,e) {
+			$.ui.plugin.call(this, n, [e, this.ui()]);
+			return this.element.triggerHandler(n == "drag" ? n : "drag"+n, [e, this.ui()], this.options[n]);
+		},
+		destroy: function() {
+			if(!this.element.data('draggable')) return;
+			this.element.removeData("draggable").unbind(".draggable").mouse("destroy");
+		},
+		enable: function() {
+			this.options.disabled = false;
+		},
+		disable: function() {
+			this.options.disabled = true;
+		}
+	});
+	
+	$.ui.draggable.defaults = {
+		helper: "original",
+		appendTo: "parent",
+		cancel: ['input','textarea','button','select','option'],
+		distance: 1,
+		delay: 0
+	};
+	
+	
+	$.ui.plugin.add("draggable", "cursor", {
+		start: function(e, ui) {
+			var t = $('body');
+			if (t.css("cursor")) ui.options._cursor = t.css("cursor");
+			t.css("cursor", ui.options.cursor);
+		},
+		stop: function(e, ui) {
+			if (ui.options._cursor) $('body').css("cursor", ui.options._cursor);
+		}
+	});
+
+	$.ui.plugin.add("draggable", "zIndex", {
+		start: function(e, ui) {
+			var t = $(ui.helper);
+			if(t.css("zIndex")) ui.options._zIndex = t.css("zIndex");
+			t.css('zIndex', ui.options.zIndex);
+		},
+		stop: function(e, ui) {
+			if(ui.options._zIndex) $(ui.helper).css('zIndex', ui.options._zIndex);
+		}
+	});
+
+	$.ui.plugin.add("draggable", "opacity", {
+		start: function(e, ui) {
+			var t = $(ui.helper);
+			if(t.css("opacity")) ui.options._opacity = t.css("opacity");
+			t.css('opacity', ui.options.opacity);
+		},
+		stop: function(e, ui) {
+			if(ui.options._opacity) $(ui.helper).css('opacity', ui.options._opacity);
+		}
+	});
+	
+	$.ui.plugin.add("draggable", "iframeFix", {
+		start: function(e, ui) {
+			$(ui.options.iframeFix === true ? "iframe" : ui.options.iframeFix).each(function() {					
+				$('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>')
+				.css({
+					width: this.offsetWidth+"px", height: this.offsetHeight+"px",
+					position: "absolute", opacity: "0.001", zIndex: 1000
+				})
+				.css($(this).offset())
+				.appendTo("body");
+			});
+		},
+		stop: function(e, ui) {
+			$("div.DragDropIframeFix").each(function() { this.parentNode.removeChild(this); }); //Remove frame helpers	
+		}
+	});
+	
+	$.ui.plugin.add("draggable", "scroll", {
+		start: function(e, ui) {
+			var o = ui.options;
+			var i = $(this).data("draggable");
+			o.scrollSensitivity	= o.scrollSensitivity || 20;
+			o.scrollSpeed		= o.scrollSpeed || 20;
+
+			i.overflowY = function(el) {
+				do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-y'))) return el; el = el.parent(); } while (el[0].parentNode);
+				return $(document);
+			}(this);
+			i.overflowX = function(el) {
+				do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-x'))) return el; el = el.parent(); } while (el[0].parentNode);
+				return $(document);
+			}(this);
+			
+			if(i.overflowY[0] != document && i.overflowY[0].tagName != 'HTML') i.overflowYOffset = i.overflowY.offset();
+			if(i.overflowX[0] != document && i.overflowX[0].tagName != 'HTML') i.overflowXOffset = i.overflowX.offset();
+			
+		},
+		drag: function(e, ui) {
+			
+			var o = ui.options;
+			var i = $(this).data("draggable");
+
+			if(i.overflowY[0] != document && i.overflowY[0].tagName != 'HTML') {
+				if((i.overflowYOffset.top + i.overflowY[0].offsetHeight) - e.pageY < o.scrollSensitivity)
+					i.overflowY[0].scrollTop = i.overflowY[0].scrollTop + o.scrollSpeed;
+				if(e.pageY - i.overflowYOffset.top < o.scrollSensitivity)
+					i.overflowY[0].scrollTop = i.overflowY[0].scrollTop - o.scrollSpeed;
+								
+			} else {
+				if(e.pageY - $(document).scrollTop() < o.scrollSensitivity)
+					$(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
+				if($(window).height() - (e.pageY - $(document).scrollTop()) < o.scrollSensitivity)
+					$(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
+			}
+			
+			if(i.overflowX[0] != document && i.overflowX[0].tagName != 'HTML') {
+				if((i.overflowXOffset.left + i.overflowX[0].offsetWidth) - e.pageX < o.scrollSensitivity)
+					i.overflowX[0].scrollLeft = i.overflowX[0].scrollLeft + o.scrollSpeed;
+				if(e.pageX - i.overflowXOffset.left < o.scrollSensitivity)
+					i.overflowX[0].scrollLeft = i.overflowX[0].scrollLeft - o.scrollSpeed;
+			} else {
+				if(e.pageX - $(document).scrollLeft() < o.scrollSensitivity)
+					$(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
+				if($(window).width() - (e.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
+					$(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
+			}
+
+		}
+	});
+	
+	$.ui.plugin.add("draggable", "snap", {
+		start: function(e, ui) {
+			
+			var inst = $(this).data("draggable");
+			inst.snapElements = [];
+			$(ui.options.snap === true ? '.ui-draggable' : ui.options.snap).each(function() {
+				var $t = $(this); var $o = $t.offset();
+				if(this != inst.element[0]) inst.snapElements.push({
+					item: this,
+					width: $t.outerWidth(), height: $t.outerHeight(),
+					top: $o.top, left: $o.left
+				});
+			});
+			
+		},
+		drag: function(e, ui) {
+
+			var inst = $(this).data("draggable");
+			var d = ui.options.snapTolerance || 20;
+			var x1 = ui.absolutePosition.left, x2 = x1 + inst.helperProportions.width,
+				y1 = ui.absolutePosition.top, y2 = y1 + inst.helperProportions.height;
+
+			for (var i = inst.snapElements.length - 1; i >= 0; i--){
+
+				var l = inst.snapElements[i].left, r = l + inst.snapElements[i].width, 
+					t = inst.snapElements[i].top, b = t + inst.snapElements[i].height;
+
+				//Yes, I know, this is insane ;)
+				if(!((l-d < x1 && x1 < r+d && t-d < y1 && y1 < b+d) || (l-d < x1 && x1 < r+d && t-d < y2 && y2 < b+d) || (l-d < x2 && x2 < r+d && t-d < y1 && y1 < b+d) || (l-d < x2 && x2 < r+d && t-d < y2 && y2 < b+d))) continue;
+
+				if(ui.options.snapMode != 'inner') {
+					var ts = Math.abs(t - y2) <= 20;
+					var bs = Math.abs(b - y1) <= 20;
+					var ls = Math.abs(l - x2) <= 20;
+					var rs = Math.abs(r - x1) <= 20;
+					if(ts) ui.position.top = inst.convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top;
+					if(bs) ui.position.top = inst.convertPositionTo("relative", { top: b, left: 0 }).top;
+					if(ls) ui.position.left = inst.convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left;
+					if(rs) ui.position.left = inst.convertPositionTo("relative", { top: 0, left: r }).left;
+				}
+				
+				if(ui.options.snapMode != 'outer') {
+					var ts = Math.abs(t - y1) <= 20;
+					var bs = Math.abs(b - y2) <= 20;
+					var ls = Math.abs(l - x1) <= 20;
+					var rs = Math.abs(r - x2) <= 20;
+					if(ts) ui.position.top = inst.convertPositionTo("relative", { top: t, left: 0 }).top;
+					if(bs) ui.position.top = inst.convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top;
+					if(ls) ui.position.left = inst.convertPositionTo("relative", { top: 0, left: l }).left;
+					if(rs) ui.position.left = inst.convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left;
+				}
+
+			};
+		}
+	});
+	
+	$.ui.plugin.add("draggable", "connectToSortable", {
+		start: function(e,ui) {
+			var inst = $(this).data("draggable");
+			inst.sortable = $.data($(ui.options.connectToSortable)[0], 'sortable');
+			inst.sortableOffset = inst.sortable.element.offset();
+			inst.sortableOuterWidth = inst.sortable.element.outerWidth();
+			inst.sortableOuterHeight = inst.sortable.element.outerHeight();
+			if(inst.sortable.options.revert) inst.sortable.shouldRevert = true;
+		},
+		stop: function(e,ui) {
+			//If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
+			var instDraggable = $(this).data("draggable");
+			var inst = instDraggable.sortable;
+			
+			if(inst.isOver) {
+				inst.isOver = 0;
+				instDraggable.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance
+				inst.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work)
+				if(inst.shouldRevert) inst.options.revert = true; //revert here
+				inst.stop(e);
+				inst.options.helper = "original";
+			}
+		},
+		drag: function(e,ui) {
+			//This is handy: We reuse the intersectsWith method for checking if the current draggable helper
+			//intersects with the sortable container
+			var instDraggable = $(this).data("draggable");
+			var inst = instDraggable.sortable;
+			instDraggable.position.absolute = ui.absolutePosition; //Sorry, this is an ugly API fix
+			
+			if(inst.intersectsWith.call(instDraggable, {
+				left: instDraggable.sortableOffset.left, top: instDraggable.sortableOffset.top,
+				width: instDraggable.sortableOuterWidth, height: instDraggable.sortableOuterHeight
+			})) {
+				//If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once
+				if(!inst.isOver) {
+					inst.isOver = 1;
+					
+					//Cache the width/height of the new helper
+					var height = inst.options.placeholderElement ? $(inst.options.placeholderElement, $(inst.options.items, inst.element)).innerHeight() : $(inst.options.items, inst.element).innerHeight();
+					var width = inst.options.placeholderElement ? $(inst.options.placeholderElement, $(inst.options.items, inst.element)).innerWidth() : $(inst.options.items, inst.element).innerWidth();
+
+					//Now we fake the start of dragging for the sortable instance,
+					//by cloning the list group item, appending it to the sortable and using it as inst.currentItem
+					//We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one)
+					inst.currentItem = $(this).clone().appendTo(inst.element);
+					inst.options.helper = function() { return ui.helper[0]; };
+					inst.start(e);
+					
+					//Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
+					inst.clickOffset.top = instDraggable.offset.click.top;
+					inst.clickOffset.left = instDraggable.offset.click.left;
+					inst.offset.left -= ui.absolutePosition.left - inst.position.absolute.left;
+					inst.offset.top -= ui.absolutePosition.top - inst.position.absolute.top;
+					
+					//Do a nifty little helper animation: Animate it to the portlet's size (just takes the first 'li' element in the sortable now)
+					inst.helperProportions = {width: width, height: height}; //We have to reset the helper proportions, because we are doing our animation there
+					ui.helper.animate({height: height, width: width}, 500);
+					instDraggable.propagate("toSortable", e);
+				
+				}
+
+				//Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable
+				if(inst.currentItem) inst.drag(e);
+				
+			} else {
+				
+				//If it doesn't intersect with the sortable, and it intersected before,
+				//we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval
+				if(inst.isOver) {
+					inst.isOver = 0;
+					inst.cancelHelperRemoval = true;
+					inst.options.revert = false; //No revert here
+					inst.stop(e);
+					inst.options.helper = "original";
+					
+					//Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
+					inst.currentItem.remove();
+					inst.placeholder.remove();
+					
+					ui.helper.animate({ height: this.innerHeight(), width: this.innerWidth() }, 500);
+					instDraggable.propagate("fromSortable", e);
+				}
+				
+			};
+		}
+	});
+	
+	$.ui.plugin.add("draggable", "stack", {
+		start: function(e,ui) {
+			var group = $.makeArray($(ui.options.stack.group)).sort(function(a,b) {
+				return (parseInt($(a).css("zIndex")) || ui.options.stack.min) - (parseInt($(b).css("zIndex")) || ui.options.stack.min);
+			});
+			
+			$(group).each(function(i) {
+				this.style.zIndex = ui.options.stack.min + i;
+			});
+			
+			this[0].style.zIndex = ui.options.stack.min + group.length;
+		}
+	});
+	
+})(jQuery);
\ No newline at end of file

Added: pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4/ui.droppable.js
==============================================================================
--- (empty file)
+++ pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4/ui.droppable.js	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,300 @@
+/*
+ * jQuery UI Droppable
+ *
+ * Copyright (c) 2008 Paul Bakaus
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
+ * and GPL (GPL-LICENSE.txt) licenses.
+ * 
+ * http://docs.jquery.com/UI/Droppables
+ *
+ * Depends:
+ *	ui.core.js
+ *	ui.draggable.js
+ *
+ * Revision: $Id: ui.droppable.js 5452 2008-05-05 16:42:08Z rdworth $
+ */
+
+;(function($) {
+
+	$.widget("ui.droppable", {
+		init: function() {
+	
+			this.element.addClass("ui-droppable");
+			this.isover = 0; this.isout = 1;
+			
+			//Prepare the passed options
+			var o = this.options, accept = o.accept;
+			o = $.extend(o, {
+				accept: o.accept && o.accept.constructor == Function ? o.accept : function(d) {
+					return $(d).is(accept);
+				}
+			});
+			
+			//Store the droppable's proportions
+			this.proportions = { width: this.element.outerWidth(), height: this.element.outerHeight() };
+			
+			// Add the reference and positions to the manager
+			$.ui.ddmanager.droppables.push(this);
+			
+		},
+		plugins: {},
+		ui: function(c) {
+			return {
+				instance: this,
+				draggable: (c.currentItem || c.element),
+				helper: c.helper,
+				position: c.position,
+				absolutePosition: c.positionAbs,
+				options: this.options,
+				element: this.element
+			};
+		},
+		destroy: function() {
+			var drop = $.ui.ddmanager.droppables;
+			for ( var i = 0; i < drop.length; i++ )
+				if ( drop[i] == this )
+					drop.splice(i, 1);
+			
+			this.element
+				.removeClass("ui-droppable ui-droppable-disabled")
+				.removeData("droppable")
+				.unbind(".droppable");
+		},
+		enable: function() {
+			this.element.removeClass("ui-droppable-disabled");
+			this.options.disabled = false;
+		},
+		disable: function() {
+			this.element.addClass("ui-droppable-disabled");
+			this.options.disabled = true;
+		},
+		over: function(e) {
+			
+			var draggable = $.ui.ddmanager.current;
+			if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
+			
+			if (this.options.accept.call(this.element,(draggable.currentItem || draggable.element))) {
+				$.ui.plugin.call(this, 'over', [e, this.ui(draggable)]);
+				this.element.triggerHandler("dropover", [e, this.ui(draggable)], this.options.over);
+			}
+			
+		},
+		out: function(e) {
+			
+			var draggable = $.ui.ddmanager.current;
+			if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
+			
+			if (this.options.accept.call(this.element,(draggable.currentItem || draggable.element))) {
+				$.ui.plugin.call(this, 'out', [e, this.ui(draggable)]);
+				this.element.triggerHandler("dropout", [e, this.ui(draggable)], this.options.out);
+			}
+			
+		},
+		drop: function(e,custom) {
+			
+			var draggable = custom || $.ui.ddmanager.current;
+			if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return false; // Bail if draggable and droppable are same element
+			
+			var childrenIntersection = false;
+			this.element.find(".ui-droppable").each(function() {
+				var inst = $.data(this, 'droppable');
+				if(inst.options.greedy && $.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance)) {
+					childrenIntersection = true; return false;
+				}
+			});
+			if(childrenIntersection) return false;
+			
+			if(this.options.accept.call(this.element,(draggable.currentItem || draggable.element))) {
+				$.ui.plugin.call(this, 'drop', [e, this.ui(draggable)]);
+				this.element.triggerHandler("drop", [e, this.ui(draggable)], this.options.drop);
+				return true;
+			}
+			
+			return false;
+			
+		},
+		activate: function(e) {
+			
+			var draggable = $.ui.ddmanager.current;
+			$.ui.plugin.call(this, 'activate', [e, this.ui(draggable)]);
+			if(draggable) this.element.triggerHandler("dropactivate", [e, this.ui(draggable)], this.options.activate);
+			
+		},
+		deactivate: function(e) {
+			
+			var draggable = $.ui.ddmanager.current;
+			$.ui.plugin.call(this, 'deactivate', [e, this.ui(draggable)]);
+			if(draggable) this.element.triggerHandler("dropdeactivate", [e, this.ui(draggable)], this.options.deactivate);
+			
+		}
+	});
+	
+	$.extend($.ui.droppable, {
+		defaults: {
+			disabled: false,
+			tolerance: 'intersect'
+		}
+	});
+	
+	$.ui.intersect = function(draggable, droppable, toleranceMode) {
+		
+		if (!droppable.offset) return false;
+		
+		var x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width,
+			y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height;
+		var l = droppable.offset.left, r = l + droppable.proportions.width,
+			t = droppable.offset.top, b = t + droppable.proportions.height;
+		
+		switch (toleranceMode) {
+			case 'fit':
+				
+				if(!((y2-(draggable.helperProportions.height/2) > t && y1 < t) || (y1 < b && y2 > b) || (x2 > l && x1 < l) || (x1 < r && x2 > r))) return false;
+				
+				if(y2-(draggable.helperProportions.height/2) > t && y1 < t) return 1; //Crosses top edge
+				if(y1 < b && y2 > b) return 2; //Crosses bottom edge
+				if(x2 > l && x1 < l) return 1; //Crosses left edge
+				if(x1 < r && x2 > r) return 2; //Crosses right edge
+				
+				//return (l < x1 && x2 < r
+				//	&& t < y1 && y2 < b);
+				break;
+			case 'intersect':
+				return (l < x1 + (draggable.helperProportions.width / 2) // Right Half
+					&& x2 - (draggable.helperProportions.width / 2) < r // Left Half
+					&& t < y1 + (draggable.helperProportions.height / 2) // Bottom Half
+					&& y2 - (draggable.helperProportions.height / 2) < b ); // Top Half
+				break;
+			case 'pointer':
+				return (l < ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left) && ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left) < r
+					&& t < ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top) && ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top) < b);
+				break;
+			case 'touch':
+				return (
+						(y1 >= t && y1 <= b) ||	// Top edge touching
+						(y2 >= t && y2 <= b) ||	// Bottom edge touching
+						(y1 < t && y2 > b)		// Surrounded vertically
+					) && (
+						(x1 >= l && x1 <= r) ||	// Left edge touching
+						(x2 >= l && x2 <= r) ||	// Right edge touching
+						(x1 < l && x2 > r)		// Surrounded horizontally
+					);
+				break;
+			default:
+				return false;
+				break;
+			}
+		
+	};
+	
+	/*
+		This manager tracks offsets of draggables and droppables
+	*/
+	$.ui.ddmanager = {
+		current: null,
+		droppables: [],
+		prepareOffsets: function(t, e) {
+			
+			var m = $.ui.ddmanager.droppables;
+			var type = e ? e.type : null; // workaround for #2317
+			for (var i = 0; i < m.length; i++) {
+				
+				if(m[i].options.disabled || (t && !m[i].options.accept.call(m[i].element,(t.currentItem || t.element)))) continue;
+				m[i].visible = m[i].element.is(":visible"); if(!m[i].visible) continue; //If the element is not visible, continue
+				m[i].offset = m[i].element.offset();
+				m[i].proportions = { width: m[i].element.outerWidth(), height: m[i].element.outerHeight() };
+				
+				if(type == "dragstart" || type == "sortactivate") m[i].activate.call(m[i], e); //Activate the droppable if used directly from draggables
+			}
+			
+		},
+		drop: function(draggable, e) {
+			
+			var dropped = false;
+			$.each($.ui.ddmanager.droppables, function() {
+				
+				if(!this.options) return;
+				if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance))
+					dropped = this.drop.call(this, e);
+				
+				if (!this.options.disabled && this.visible && this.options.accept.call(this.element,(draggable.currentItem || draggable.element))) {
+					this.isout = 1; this.isover = 0;
+					this.deactivate.call(this, e);
+				}
+				
+			});
+			return dropped;
+			
+		},
+		drag: function(draggable, e) {
+			
+			//If you have a highly dynamic page, you might try this option. It renders positions every time you move the mouse.
+			if(draggable.options.refreshPositions) $.ui.ddmanager.prepareOffsets(draggable, e);
+			
+			//Run through all droppables and check their positions based on specific tolerance options
+			$.each($.ui.ddmanager.droppables, function() {
+				
+				if(this.disabled || this.greedyChild || !this.visible) return;
+				var intersects = $.ui.intersect(draggable, this, this.options.tolerance);
+				
+				var c = !intersects && this.isover == 1 ? 'isout' : (intersects && this.isover == 0 ? 'isover' : null);
+				if(!c) return;
+				
+				var parentInstance;
+				if (this.options.greedy) {
+					var parent = this.element.parents('.ui-droppable:eq(0)');
+					if (parent.length) {
+						parentInstance = $.data(parent[0], 'droppable');
+						parentInstance.greedyChild = (c == 'isover' ? 1 : 0);
+					}
+				}
+				
+				// we just moved into a greedy child
+				if (parentInstance && c == 'isover') {
+					parentInstance['isover'] = 0;
+					parentInstance['isout'] = 1;
+					parentInstance.out.call(parentInstance, e);
+				}
+				
+				this[c] = 1; this[c == 'isout' ? 'isover' : 'isout'] = 0;
+				this[c == "isover" ? "over" : "out"].call(this, e);
+				
+				// we just moved out of a greedy child
+				if (parentInstance && c == 'isout') {
+					parentInstance['isout'] = 0;
+					parentInstance['isover'] = 1;
+					parentInstance.over.call(parentInstance, e);
+				}
+			});
+			
+		}
+	};
+	
+/*
+ * Droppable Extensions
+ */
+	
+	$.ui.plugin.add("droppable", "activeClass", {
+		activate: function(e, ui) {
+			$(this).addClass(ui.options.activeClass);
+		},
+		deactivate: function(e, ui) {
+			$(this).removeClass(ui.options.activeClass);
+		},
+		drop: function(e, ui) {
+			$(this).removeClass(ui.options.activeClass);
+		}
+	});
+	
+	$.ui.plugin.add("droppable", "hoverClass", {
+		over: function(e, ui) {
+			$(this).addClass(ui.options.hoverClass);
+		},
+		out: function(e, ui) {
+			$(this).removeClass(ui.options.hoverClass);
+		},
+		drop: function(e, ui) {
+			$(this).removeClass(ui.options.hoverClass);
+		}
+	});
+ 
+})(jQuery);

Added: pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4/ui.selectable.js
==============================================================================
--- (empty file)
+++ pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4/ui.selectable.js	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,278 @@
+/*
+ * jQuery UI Selectable
+ *
+ * Copyright (c) 2008 Richard D. Worth (rdworth.org)
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
+ * and GPL (GPL-LICENSE.txt) licenses.
+ * 
+ * http://docs.jquery.com/UI/Selectables
+ *
+ * Depends:
+ *	ui.core.js
+ *
+ * Revision: $Id: ui.selectable.js 5452 2008-05-05 16:42:08Z rdworth $
+ */
+;(function($) {
+
+	$.widget("ui.selectable", {
+		init: function() {
+			var instance = this;
+			
+			this.element.addClass("ui-selectable");
+			
+			this.element.bind("setData.selectable", function(event, key, value){
+				instance.options[key] = value;
+			}).bind("getData.selectable", function(event, key){
+				return instance.options[key];
+			});
+			
+			this.dragged = false;
+	
+			// cache selectee children based on filter
+			var selectees;
+			this.refresh = function() {
+				selectees = $(instance.options.filter, instance.element[0]);
+				selectees.each(function() {
+					var $this = $(this);
+					var pos = $this.offset();
+					$.data(this, "selectable-item", {
+						element: this,
+						$element: $this,
+						left: pos.left,
+						top: pos.top,
+						right: pos.left + $this.width(),
+						bottom: pos.top + $this.height(),
+						startselected: false,
+						selected: $this.hasClass('ui-selected'),
+						selecting: $this.hasClass('ui-selecting'),
+						unselecting: $this.hasClass('ui-unselecting')
+					});
+				});
+			};
+			this.refresh();
+	
+			this.selectees = selectees.addClass("ui-selectee");
+	
+			//Initialize mouse interaction
+			this.element.mouse({
+				executor: this,
+				appendTo: 'body',
+				delay: 0,
+				distance: 0,
+				dragPrevention: ['input','textarea','button','select','option'],
+				start: this.start,
+				stop: this.stop,
+				drag: this.drag,
+				condition: function(e) {
+					var isSelectee = false;
+					$(e.target).parents().andSelf().each(function() {
+						if($.data(this, "selectable-item")) isSelectee = true;
+					});
+					return this.options.keyboard ? !isSelectee : true;
+				}
+			});
+			
+			this.helper = $(document.createElement('div')).css({border:'1px dotted black'});
+		},
+		toggle: function() {
+			if(this.disabled){
+				this.enable();
+			} else {
+				this.disable();
+			}
+		},
+		destroy: function() {
+			this.element
+				.removeClass("ui-selectable ui-selectable-disabled")
+				.removeData("selectable")
+				.unbind(".selectable")
+				.mouse("destroy");
+		},
+		enable: function() {
+			this.element.removeClass("ui-selectable-disabled");
+			this.disabled = false;
+		},
+		disable: function() {
+			this.element.addClass("ui-selectable-disabled");
+			this.disabled = true;
+		},
+		start: function(ev, element) {
+			
+			this.opos = [ev.pageX, ev.pageY];
+			
+			if (this.disabled)
+				return;
+
+			var options = this.options;
+
+			this.selectees = $(options.filter, element);
+
+			// selectable START callback
+			this.element.triggerHandler("selectablestart", [ev, {
+				"selectable": element,
+				"options": options
+			}], options.start);
+
+			$('body').append(this.helper);
+			// position helper (lasso)
+			this.helper.css({
+				"z-index": 100,
+				"position": "absolute",
+				"left": ev.clientX,
+				"top": ev.clientY,
+				"width": 0,
+				"height": 0
+			});
+
+			if (options.autoRefresh) {
+				this.refresh();
+			}
+
+			this.selectees.filter('.ui-selected').each(function() {
+				var selectee = $.data(this, "selectable-item");
+				selectee.startselected = true;
+				if (!ev.ctrlKey) {
+					selectee.$element.removeClass('ui-selected');
+					selectee.selected = false;
+					selectee.$element.addClass('ui-unselecting');
+					selectee.unselecting = true;
+					// selectable UNSELECTING callback
+					$(this.element).triggerHandler("selectableunselecting", [ev, {
+						selectable: element,
+						unselecting: selectee.element,
+						options: options
+					}], options.unselecting);
+				}
+			});
+		},
+		drag: function(ev, element) {
+			this.dragged = true;
+			
+			if (this.disabled)
+				return;
+
+			var options = this.options;
+
+			var x1 = this.opos[0], y1 = this.opos[1], x2 = ev.pageX, y2 = ev.pageY;
+			if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; }
+			if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; }
+			this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1});
+
+			this.selectees.each(function() {
+				var selectee = $.data(this, "selectable-item");
+				//prevent helper from being selected if appendTo: selectable
+				if (!selectee || selectee.element == element)
+					return;
+				var hit = false;
+				if (options.tolerance == 'touch') {
+					hit = ( !(selectee.left > x2 || selectee.right < x1 || selectee.top > y2 || selectee.bottom < y1) );
+				} else if (options.tolerance == 'fit') {
+					hit = (selectee.left > x1 && selectee.right < x2 && selectee.top > y1 && selectee.bottom < y2);
+				}
+
+				if (hit) {
+					// SELECT
+					if (selectee.selected) {
+						selectee.$element.removeClass('ui-selected');
+						selectee.selected = false;
+					}
+					if (selectee.unselecting) {
+						selectee.$element.removeClass('ui-unselecting');
+						selectee.unselecting = false;
+					}
+					if (!selectee.selecting) {
+						selectee.$element.addClass('ui-selecting');
+						selectee.selecting = true;
+						// selectable SELECTING callback
+						$(this.element).triggerHandler("selectableselecting", [ev, {
+							selectable: element,
+							selecting: selectee.element,
+							options: options
+						}], options.selecting);
+					}
+				} else {
+					// UNSELECT
+					if (selectee.selecting) {
+						if (ev.ctrlKey && selectee.startselected) {
+							selectee.$element.removeClass('ui-selecting');
+							selectee.selecting = false;
+							selectee.$element.addClass('ui-selected');
+							selectee.selected = true;
+						} else {
+							selectee.$element.removeClass('ui-selecting');
+							selectee.selecting = false;
+							if (selectee.startselected) {
+								selectee.$element.addClass('ui-unselecting');
+								selectee.unselecting = true;
+							}
+							// selectable UNSELECTING callback
+							$(this.element).triggerHandler("selectableunselecting", [ev, {
+								selectable: element,
+								unselecting: selectee.element,
+								options: options
+							}], options.unselecting);
+						}
+					}
+					if (selectee.selected) {
+						if (!ev.ctrlKey && !selectee.startselected) {
+							selectee.$element.removeClass('ui-selected');
+							selectee.selected = false;
+
+							selectee.$element.addClass('ui-unselecting');
+							selectee.unselecting = true;
+							// selectable UNSELECTING callback
+							$(this.element).triggerHandler("selectableunselecting", [ev, {
+								selectable: element,
+								unselecting: selectee.element,
+								options: options
+							}], options.unselecting);
+						}
+					}
+				}
+			});
+		},
+		stop: function(ev, element) {
+			this.dragged = false;
+			
+			var options = this.options;
+
+			$('.ui-unselecting', this.element).each(function() {
+				var selectee = $.data(this, "selectable-item");
+				selectee.$element.removeClass('ui-unselecting');
+				selectee.unselecting = false;
+				selectee.startselected = false;
+				$(this.element).triggerHandler("selectableunselected", [ev, {
+					selectable: element,
+					unselected: selectee.element,
+					options: options
+				}], options.unselected);
+			});
+			$('.ui-selecting', this.element).each(function() {
+				var selectee = $.data(this, "selectable-item");
+				selectee.$element.removeClass('ui-selecting').addClass('ui-selected');
+				selectee.selecting = false;
+				selectee.selected = true;
+				selectee.startselected = true;
+				$(this.element).triggerHandler("selectableselected", [ev, {
+					selectable: element,
+					selected: selectee.element,
+					options: options
+				}], options.selected);
+			});
+			$(this.element).triggerHandler("selectablestop", [ev, {
+				selectable: element,
+				options: this.options
+			}], this.options.stop);
+			
+			this.helper.remove();
+		}
+	});
+	
+	$.ui.selectable.defaults = {
+		appendTo: 'body',
+		autoRefresh: true,
+		filter: '*',
+		tolerance: 'touch'
+	};
+	
+})(jQuery);

Added: pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4/ui.sortable.js
==============================================================================
--- (empty file)
+++ pie/trunk/pieplate/PIE-Plate/share/web/static/js/jquery.ui-1.5b4/ui.sortable.js	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,671 @@
+/*
+ * jQuery UI Sortable
+ *
+ * Copyright (c) 2008 Paul Bakaus
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
+ * and GPL (GPL-LICENSE.txt) licenses.
+ * 
+ * http://docs.jquery.com/UI/Sortables
+ *
+ * Depends:
+ *	ui.core.js
+ *
+ * Revision: $Id: ui.sortable.js 5452 2008-05-05 16:42:08Z rdworth $
+ */
+;(function($) {
+	
+	function contains(a, b) { 
+	    var safari2 = $.browser.safari && $.browser.version < 522; 
+	    if (a.contains && !safari2) { 
+	        return a.contains(b); 
+	    } 
+	    if (a.compareDocumentPosition) 
+	        return !!(a.compareDocumentPosition(b) & 16); 
+	    while (b = b.parentNode) 
+	          if (b == a) return true; 
+	    return false; 
+	};
+	
+	$.widget("ui.sortable", {
+		init: function() {
+
+			var o = this.options;
+			this.containerCache = {};
+			this.element.addClass("ui-sortable");
+		
+			//Get the items
+			this.refresh();
+	
+			//Let's determine if the items are floating
+			this.floating = this.items.length ? (/left|right/).test(this.items[0].item.css('float')) : false;
+			
+			//Let's determine the parent's offset
+			if(!(/(relative|absolute|fixed)/).test(this.element.css('position'))) this.element.css('position', 'relative');
+			this.offset = this.element.offset();
+	
+			//Initialize mouse events for interaction
+			this.element.mouse({
+				executor: this,
+				delay: o.delay,
+				distance: o.distance || 1,
+				dragPrevention: o.prevention ? o.prevention.toLowerCase().split(',') : ['input','textarea','button','select','option'],
+				start: this.start,
+				stop: this.stop,
+				drag: this.drag,
+				condition: function(e) {
+	
+					if(this.options.disabled || this.options.type == 'static') return false;
+	
+					//Find out if the clicked node (or one of its parents) is a actual item in this.items
+					var currentItem = null, nodes = $(e.target).parents().each(function() {	
+						if($.data(this, 'sortable-item')) {
+							currentItem = $(this);
+							return false;
+						}
+					});
+					if($.data(e.target, 'sortable-item')) currentItem = $(e.target);
+					
+					if(!currentItem) return false;	
+					if(this.options.handle) {
+						var validHandle = false;
+						$(this.options.handle, currentItem).each(function() { if(this == e.target) validHandle = true; });
+						if(!validHandle) return false;
+					}
+						
+					this.currentItem = currentItem;
+					return true;
+	
+				}
+			});
+			
+		},
+		plugins: {},
+		ui: function(inst) {
+			return {
+				helper: (inst || this)["helper"],
+				placeholder: (inst || this)["placeholder"] || $([]),
+				position: (inst || this)["position"].current,
+				absolutePosition: (inst || this)["position"].absolute,
+				instance: this,
+				options: this.options,
+				element: this.element,
+				item: (inst || this)["currentItem"],
+				sender: inst ? inst.element : null
+			};		
+		},
+		propagate: function(n,e,inst) {
+			$.ui.plugin.call(this, n, [e, this.ui(inst)]);
+			this.element.triggerHandler(n == "sort" ? n : "sort"+n, [e, this.ui(inst)], this.options[n]);
+		},
+		serialize: function(o) {
+			
+			var items = $(this.options.items, this.element).not('.ui-sortable-helper'); //Only the items of the sortable itself
+			var str = []; o = o || {};
+			
+			items.each(function() {
+				var res = ($(this).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
+				if(res) str.push((o.key || res[1])+'[]='+(o.key ? res[1] : res[2]));
+			});
+			
+			return str.join('&');
+			
+		},
+		toArray: function(attr) {
+			var items = $(this.options.items, this.element).not('.ui-sortable-helper'); //Only the items of the sortable itself
+			var ret = [];
+
+			items.each(function() { ret.push($(this).attr(attr || 'id')); });
+			return ret;
+		},
+		enable: function() {
+			this.element.removeClass("ui-sortable-disabled");
+			this.options.disabled = false;
+		},
+		disable: function() {
+			this.element.addClass("ui-sortable-disabled");
+			this.options.disabled = true;
+		},
+		/* Be careful with the following core functions */
+		intersectsWith: function(item) {
+			
+			var x1 = this.position.absolute.left, x2 = x1 + this.helperProportions.width,
+			y1 = this.position.absolute.top, y2 = y1 + this.helperProportions.height;
+			var l = item.left, r = l + item.width, 
+			t = item.top, b = t + item.height;
+
+			if(this.options.tolerance == "pointer") {
+				return (y1 + this.clickOffset.top > t && y1 + this.clickOffset.top < b && x1 + this.clickOffset.left > l && x1 + this.clickOffset.left < r);
+			} else {
+			
+				return (l < x1 + (this.helperProportions.width / 2) // Right Half
+					&& x2 - (this.helperProportions.width / 2) < r // Left Half
+					&& t < y1 + (this.helperProportions.height / 2) // Bottom Half
+					&& y2 - (this.helperProportions.height / 2) < b ); // Top Half
+			
+			}
+			
+		},
+		intersectsWithEdge: function(item) {	
+			var x1 = this.position.absolute.left, x2 = x1 + this.helperProportions.width,
+				y1 = this.position.absolute.top, y2 = y1 + this.helperProportions.height;
+			var l = item.left, r = l + item.width, 
+				t = item.top, b = t + item.height;
+
+			if(this.options.tolerance == "pointer") {
+
+				if(!(y1 + this.clickOffset.top > t && y1 + this.clickOffset.top < b && x1 + this.clickOffset.left > l && x1 + this.clickOffset.left < r)) return false;
+				
+				if(this.floating) {
+					if(x1 + this.clickOffset.left > l && x1 + this.clickOffset.left < l + item.width/2) return 2;
+					if(x1 + this.clickOffset.left > l+item.width/2 && x1 + this.clickOffset.left < r) return 1;
+				} else {
+					if(y1 + this.clickOffset.top > t && y1 + this.clickOffset.top < t + item.height/2) return 2;
+					if(y1 + this.clickOffset.top > t+item.height/2 && y1 + this.clickOffset.top < b) return 1;
+				}
+
+			} else {
+			
+				if (!(l < x1 + (this.helperProportions.width / 2) // Right Half
+					&& x2 - (this.helperProportions.width / 2) < r // Left Half
+					&& t < y1 + (this.helperProportions.height / 2) // Bottom Half
+					&& y2 - (this.helperProportions.height / 2) < b )) return false; // Top Half
+				
+				if(this.floating) {
+					if(x2 > l && x1 < l) return 2; //Crosses left edge
+					if(x1 < r && x2 > r) return 1; //Crosses right edge
+				} else {
+					if(y2 > t && y1 < t) return 1; //Crosses top edge
+					if(y1 < b && y2 > b) return 2; //Crosses bottom edge
+				}
+			
+			}
+			
+			return false;
+			
+		},
+		//This method checks approximately if the item is dragged in a container, but doesn't touch any items
+		inEmptyZone: function(container) {
+
+			if(!$(container.options.items, container.element).length) {
+				return container.options.dropOnEmpty ? true : false;
+			};
+
+			var last = $(container.options.items, container.element).not('.ui-sortable-helper'); last = $(last[last.length-1]);
+			var top = last.offset()[this.floating ? 'left' : 'top'] + last[0][this.floating ? 'offsetWidth' : 'offsetHeight'];
+			return (this.position.absolute[this.floating ? 'left' : 'top'] > top);
+		},
+		refresh: function() {
+			this.refreshItems();
+			this.refreshPositions();
+		},
+		refreshItems: function() {
+			
+			this.items = [];
+			this.containers = [this];
+			var items = this.items;
+			var queries = [$(this.options.items, this.element)];
+			
+			if(this.options.connectWith) {
+				for (var i = this.options.connectWith.length - 1; i >= 0; i--){
+					var cur = $(this.options.connectWith[i]);
+					for (var j = cur.length - 1; j >= 0; j--){
+						var inst = $.data(cur[j], 'sortable');
+						if(inst && !inst.options.disabled) {
+							queries.push($(inst.options.items, inst.element));
+							this.containers.push(inst);
+						}
+					};
+				};
+			}
+
+			for (var i = queries.length - 1; i >= 0; i--){
+				queries[i].each(function() {
+					$.data(this, 'sortable-item', true); // Data for target checking (mouse manager)
+					items.push({
+						item: $(this),
+						width: 0, height: 0,
+						left: 0, top: 0
+					});
+				});
+			};
+
+		},
+		refreshPositions: function(fast) {
+			for (var i = this.items.length - 1; i >= 0; i--){
+				var t = this.items[i].item;
+				if(!fast) this.items[i].width = (this.options.toleranceElement ? $(this.options.toleranceElement, t) : t).outerWidth();
+				if(!fast) this.items[i].height = (this.options.toleranceElement ? $(this.options.toleranceElement, t) : t).outerHeight();
+				var p = (this.options.toleranceElement ? $(this.options.toleranceElement, t) : t).offset();
+				this.items[i].left = p.left;
+				this.items[i].top = p.top;
+			};
+			for (var i = this.containers.length - 1; i >= 0; i--){
+				var p =this.containers[i].element.offset();
+				this.containers[i].containerCache.left = p.left;
+				this.containers[i].containerCache.top = p.top;
+				this.containers[i].containerCache.width	= this.containers[i].element.outerWidth();
+				this.containers[i].containerCache.height = this.containers[i].element.outerHeight();
+			};
+		},
+		destroy: function() {
+			this.element
+				.removeClass("ui-sortable ui-sortable-disabled")
+				.removeData("sortable")
+				.unbind(".sortable")
+				.mouse("destroy");
+			
+			for ( var i = this.items.length - 1; i >= 0; i-- )
+				this.items[i].item.removeData("sortable-item");
+		},
+		createPlaceholder: function(that) {
+			(that || this).placeholderElement = this.options.placeholderElement ? $(this.options.placeholderElement, (that || this).currentItem) : (that || this).currentItem;
+			(that || this).placeholder = $('<div></div>')
+				.addClass(this.options.placeholder)
+				.appendTo('body')
+				.css({ position: 'absolute' })
+				.css((that || this).placeholderElement.offset())
+				.css({ width: (that || this).placeholderElement.outerWidth(), height: (that || this).placeholderElement.outerHeight() })
+				;
+		},
+		contactContainers: function(e) {
+			for (var i = this.containers.length - 1; i >= 0; i--){
+
+				if(this.intersectsWith(this.containers[i].containerCache)) {
+					if(!this.containers[i].containerCache.over) {
+						
+
+						if(this.currentContainer != this.containers[i]) {
+							
+							//When entering a new container, we will find the item with the least distance and append our item near it
+							var dist = 10000; var itemWithLeastDistance = null; var base = this.position.absolute[this.containers[i].floating ? 'left' : 'top'];
+							for (var j = this.items.length - 1; j >= 0; j--) {
+								if(!contains(this.containers[i].element[0], this.items[j].item[0])) continue;
+								var cur = this.items[j][this.containers[i].floating ? 'left' : 'top'];
+								if(Math.abs(cur - base) < dist) {
+									dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j];
+								}
+							}
+							
+							//We also need to exchange the placeholder
+							if(this.placeholder) this.placeholder.remove();
+							if(this.containers[i].options.placeholder) {
+								this.containers[i].createPlaceholder(this);
+							} else {
+								this.placeholder = null; this.placeholderElement = null;
+							}
+							
+							
+							itemWithLeastDistance ? this.rearrange(e, itemWithLeastDistance) : this.rearrange(e, null, this.containers[i].element);
+							this.propagate("change", e); //Call plugins and callbacks
+							this.containers[i].propagate("change", e, this); //Call plugins and callbacks
+							this.currentContainer = this.containers[i];
+
+						}
+						
+						this.containers[i].propagate("over", e, this);
+						this.containers[i].containerCache.over = 1;
+					}
+				} else {
+					if(this.containers[i].containerCache.over) {
+						this.containers[i].propagate("out", e, this);
+						this.containers[i].containerCache.over = 0;
+					}
+				}
+				
+			};			
+		},
+		start: function(e,el) {
+		
+			var o = this.options;
+			this.currentContainer = this;
+			this.refresh();
+
+			//Create and append the visible helper
+			this.helper = typeof o.helper == 'function' ? $(o.helper.apply(this.element[0], [e, this.currentItem])) : this.currentItem.clone();
+			if(!this.helper.parents('body').length) this.helper.appendTo(o.appendTo || this.currentItem[0].parentNode); //Add the helper to the DOM if that didn't happen already
+			this.helper.css({ position: 'absolute', clear: 'both' }).addClass('ui-sortable-helper'); //Position it absolutely and add a helper class
+			
+			//Prepare variables for position generation
+			$.extend(this, {
+				offsetParent: this.helper.offsetParent(),
+				offsets: {
+					absolute: this.currentItem.offset()
+				},
+				mouse: {
+					start: { top: e.pageY, left: e.pageX }
+				},
+				margins: {
+					top: parseInt(this.currentItem.css("marginTop")) || 0,
+					left: parseInt(this.currentItem.css("marginLeft")) || 0
+				}
+			});
+			
+			//The relative click offset
+			this.offsets.parent = this.offsetParent.offset();
+			this.clickOffset = { left: e.pageX - this.offsets.absolute.left, top: e.pageY - this.offsets.absolute.top };
+			
+			this.originalPosition = {
+				left: this.offsets.absolute.left - this.offsets.parent.left - this.margins.left,
+				top: this.offsets.absolute.top - this.offsets.parent.top - this.margins.top
+			}
+			
+			//Generate a flexible offset that will later be subtracted from e.pageX/Y
+			//I hate margins - they need to be removed before positioning the element absolutely..
+			this.offset = {
+				left: e.pageX - this.originalPosition.left,
+				top: e.pageY - this.originalPosition.top
+			};
+
+			//Save the first time position
+			$.extend(this, {
+				position: {
+					current: { top: e.pageY - this.offset.top, left: e.pageX - this.offset.left },
+					absolute: { left: e.pageX - this.clickOffset.left, top: e.pageY - this.clickOffset.top },
+					dom: this.currentItem.prev()[0]
+				}
+			});
+
+			//If o.placeholder is used, create a new element at the given position with the class
+			if(o.placeholder) this.createPlaceholder();
+
+			this.propagate("start", e); //Call plugins and callbacks
+			this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() }; //Save and store the helper proportions
+
+			//If we have something in cursorAt, we'll use it
+			if(o.cursorAt) {
+				if(o.cursorAt.top != undefined || o.cursorAt.bottom != undefined) {
+					this.offset.top -= this.clickOffset.top - (o.cursorAt.top != undefined ? o.cursorAt.top : (this.helperProportions.height - o.cursorAt.bottom));
+					this.clickOffset.top = (o.cursorAt.top != undefined ? o.cursorAt.top : (this.helperProportions.height - o.cursorAt.bottom));
+				}
+				if(o.cursorAt.left != undefined || o.cursorAt.right != undefined) {
+					this.offset.left -= this.clickOffset.left - (o.cursorAt.left != undefined ? o.cursorAt.left : (this.helperProportions.width - o.cursorAt.right));
+					this.clickOffset.left = (o.cursorAt.left != undefined ? o.cursorAt.left : (this.helperProportions.width - o.cursorAt.right));
+				}
+			}
+
+			if(this.options.placeholder != 'clone') $(this.currentItem).css('visibility', 'hidden'); //Set the original element visibility to hidden to still fill out the white space
+			for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i].propagate("activate", e, this); } //Post 'activate' events to possible containers
+			
+			//Prepare possible droppables
+			if($.ui.ddmanager) $.ui.ddmanager.current = this;
+			if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e);
+
+			this.dragging = true;
+			return false;
+			
+		},
+		stop: function(e) {
+
+			this.propagate("stop", e); //Call plugins and trigger callbacks
+			if(this.position.dom != this.currentItem.prev()[0]) this.propagate("update", e); //Trigger update callback if the DOM position has changed
+			if(!contains(this.element[0], this.currentItem[0])) { //Node was moved out of the current element
+				this.propagate("remove", e);
+				for (var i = this.containers.length - 1; i >= 0; i--){
+					if(contains(this.containers[i].element[0], this.currentItem[0])) {
+						this.containers[i].propagate("update", e, this);
+						this.containers[i].propagate("receive", e, this);
+					}
+				};
+			};
+			
+			//Post events to containers
+			for (var i = this.containers.length - 1; i >= 0; i--){
+				this.containers[i].propagate("deactivate", e, this);
+				if(this.containers[i].containerCache.over) {
+					this.containers[i].propagate("out", e, this);
+					this.containers[i].containerCache.over = 0;
+				}
+			}
+			
+			//If we are using droppables, inform the manager about the drop
+			if ($.ui.ddmanager && !this.options.dropBehaviour) $.ui.ddmanager.drop(this, e);
+			
+			this.dragging = false;
+			if(this.cancelHelperRemoval) return false;
+			$(this.currentItem).css('visibility', '');
+			if(this.placeholder) this.placeholder.remove();
+			this.helper.remove();
+
+			return false;
+			
+		},
+		drag: function(e) {
+
+			//Compute the helpers position
+			this.position.current = { top: e.pageY - this.offset.top, left: e.pageX - this.offset.left };
+			this.position.absolute = { left: e.pageX - this.clickOffset.left, top: e.pageY - this.clickOffset.top };
+
+			//Rearrange
+			for (var i = this.items.length - 1; i >= 0; i--) {
+				var intersection = this.intersectsWithEdge(this.items[i]);
+				if(!intersection) continue;
+				
+				if(this.items[i].item[0] != this.currentItem[0] //cannot intersect with itself
+					&&	this.currentItem[intersection == 1 ? "next" : "prev"]()[0] != this.items[i].item[0] //no useless actions that have been done before
+					&&	!contains(this.currentItem[0], this.items[i].item[0]) //no action if the item moved is the parent of the item checked
+					&& (this.options.type == 'semi-dynamic' ? !contains(this.element[0], this.items[i].item[0]) : true)
+				) {
+					
+					this.direction = intersection == 1 ? "down" : "up";
+					this.rearrange(e, this.items[i]);
+					this.propagate("change", e); //Call plugins and callbacks
+					break;
+				}
+			}
+			
+			//Post events to containers
+			this.contactContainers(e);
+			
+			//Interconnect with droppables
+			if($.ui.ddmanager) $.ui.ddmanager.drag(this, e);
+
+			this.propagate("sort", e); //Call plugins and callbacks
+			this.helper.css({ left: this.position.current.left+'px', top: this.position.current.top+'px' }); // Stick the helper to the cursor
+			return false;
+			
+		},
+		rearrange: function(e, i, a) {
+			a ? a.append(this.currentItem) : i.item[this.direction == 'down' ? 'before' : 'after'](this.currentItem);
+			this.refreshPositions(true); //Precompute after each DOM insertion, NOT on mousemove
+			if(this.placeholderElement) this.placeholder.css(this.placeholderElement.offset());
+			if(this.placeholderElement && this.placeholderElement.is(":visible")) this.placeholder.css({ width: this.placeholderElement.outerWidth(), height: this.placeholderElement.outerHeight() });
+		}
+	});
+	
+	$.extend($.ui.sortable, {
+		getter: "serialize toArray",
+		defaults: {
+			items: '> *',
+			zIndex: 1000
+		}
+	});
+
+	
+/*
+ * Sortable Extensions
+ */
+
+	$.ui.plugin.add("sortable", "cursor", {
+		start: function(e, ui) {
+			var t = $('body');
+			if (t.css("cursor")) ui.options._cursor = t.css("cursor");
+			t.css("cursor", ui.options.cursor);
+		},
+		stop: function(e, ui) {
+			if (ui.options._cursor) $('body').css("cursor", ui.options._cursor);
+		}
+	});
+
+	$.ui.plugin.add("sortable", "zIndex", {
+		start: function(e, ui) {
+			var t = ui.helper;
+			if(t.css("zIndex")) ui.options._zIndex = t.css("zIndex");
+			t.css('zIndex', ui.options.zIndex);
+		},
+		stop: function(e, ui) {
+			if(ui.options._zIndex) $(ui.helper).css('zIndex', ui.options._zIndex);
+		}
+	});
+
+	$.ui.plugin.add("sortable", "opacity", {
+		start: function(e, ui) {
+			var t = ui.helper;
+			if(t.css("opacity")) ui.options._opacity = t.css("opacity");
+			t.css('opacity', ui.options.opacity);
+		},
+		stop: function(e, ui) {
+			if(ui.options._opacity) $(ui.helper).css('opacity', ui.options._opacity);
+		}
+	});
+
+
+	$.ui.plugin.add("sortable", "revert", {
+		stop: function(e, ui) {
+			var self = ui.instance;
+			self.cancelHelperRemoval = true;
+			var cur = self.currentItem.offset();
+			var op = self.helper.offsetParent().offset();
+			if(ui.instance.options.zIndex) ui.helper.css('zIndex', ui.instance.options.zIndex); //Do the zIndex again because it already was resetted by the plugin above on stop
+
+			//Also animate the placeholder if we have one
+			if(ui.instance.placeholder) ui.instance.placeholder.animate({ opacity: 'hide' }, parseInt(ui.options.revert, 10) || 500);
+			
+			
+			ui.helper.animate({
+				left: cur.left - op.left - self.margins.left,
+				top: cur.top - op.top - self.margins.top
+			}, parseInt(ui.options.revert, 10) || 500, function() {
+				self.currentItem.css('visibility', 'visible');
+				window.setTimeout(function() {
+					if(self.placeholder) self.placeholder.remove();
+					self.helper.remove();
+					if(ui.options._zIndex) ui.helper.css('zIndex', ui.options._zIndex);
+				}, 50);
+			});
+		}
+	});
+
+	
+	$.ui.plugin.add("sortable", "containment", {
+		start: function(e, ui) {
+
+			var o = ui.options;
+			if((o.containment.left != undefined || o.containment.constructor == Array) && !o._containment) return;
+			if(!o._containment) o._containment = o.containment;
+
+			if(o._containment == 'parent') o._containment = this[0].parentNode;
+			if(o._containment == 'sortable') o._containment = this[0];
+			if(o._containment == 'document') {
+				o.containment = [
+					0,
+					0,
+					$(document).width(),
+					($(document).height() || document.body.parentNode.scrollHeight)
+				];
+			} else { //I'm a node, so compute top/left/right/bottom
+
+				var ce = $(o._containment);
+				var co = ce.offset();
+
+				o.containment = [
+					co.left,
+					co.top,
+					co.left+(ce.outerWidth() || ce[0].scrollWidth),
+					co.top+(ce.outerHeight() || ce[0].scrollHeight)
+				];
+			}
+
+		},
+		sort: function(e, ui) {
+
+			var o = ui.options;
+			var h = ui.helper;
+			var c = o.containment;
+			var self = ui.instance;
+			var borderLeft = (parseInt(self.offsetParent.css("borderLeftWidth"), 10) || 0);
+			var borderRight = (parseInt(self.offsetParent.css("borderRightWidth"), 10) || 0);
+			var borderTop = (parseInt(self.offsetParent.css("borderTopWidth"), 10) || 0);
+			var borderBottom = (parseInt(self.offsetParent.css("borderBottomWidth"), 10) || 0);
+			
+			if(c.constructor == Array) {
+				if((self.position.absolute.left < c[0])) self.position.current.left = c[0] - self.offsets.parent.left - self.margins.left;
+				if((self.position.absolute.top < c[1])) self.position.current.top = c[1] - self.offsets.parent.top - self.margins.top;
+				if(self.position.absolute.left - c[2] + self.helperProportions.width >= 0) self.position.current.left = c[2] - self.offsets.parent.left - self.helperProportions.width - self.margins.left - borderLeft - borderRight;
+				if(self.position.absolute.top - c[3] + self.helperProportions.height >= 0) self.position.current.top = c[3] - self.offsets.parent.top - self.helperProportions.height - self.margins.top - borderTop - borderBottom;
+			} else {
+				if((ui.position.left < c.left)) self.position.current.left = c.left;
+				if((ui.position.top < c.top)) self.position.current.top = c.top;
+				if(ui.position.left - self.offsetParent.innerWidth() + self.helperProportions.width + c.right + borderLeft + borderRight >= 0) self.position.current.left = self.offsetParent.innerWidth() - self.helperProportions.width - c.right - borderLeft - borderRight;
+				if(ui.position.top - self.offsetParent.innerHeight() + self.helperProportions.height + c.bottom + borderTop + borderBottom >= 0) self.position.current.top = self.offsetParent.innerHeight() - self.helperProportions.height - c.bottom - borderTop - borderBottom;
+			}
+
+		}
+	});
+
+	$.ui.plugin.add("sortable", "axis", {
+		sort: function(e, ui) {
+			var o = ui.options;
+			if(o.constraint) o.axis = o.constraint; //Legacy check
+			o.axis == 'x' ? ui.instance.position.current.top = ui.instance.originalPosition.top : ui.instance.position.current.left = ui.instance.originalPosition.left;
+		}
+	});
+
+	$.ui.plugin.add("sortable", "scroll", {
+		start: function(e, ui) {
+			var o = ui.options;
+			o.scrollSensitivity	= o.scrollSensitivity || 20;
+			o.scrollSpeed		= o.scrollSpeed || 20;
+
+			ui.instance.overflowY = function(el) {
+				do { if((/auto|scroll/).test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-y'))) return el; el = el.parent(); } while (el[0].parentNode);
+				return $(document);
+			}(this);
+			ui.instance.overflowX = function(el) {
+				do { if((/auto|scroll/).test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-x'))) return el; el = el.parent(); } while (el[0].parentNode);
+				return $(document);
+			}(this);
+			
+			if(ui.instance.overflowY[0] != document && ui.instance.overflowY[0].tagName != 'HTML') ui.instance.overflowYstart = ui.instance.overflowY[0].scrollTop;
+			if(ui.instance.overflowX[0] != document && ui.instance.overflowX[0].tagName != 'HTML') ui.instance.overflowXstart = ui.instance.overflowX[0].scrollLeft;
+			
+		},
+		sort: function(e, ui) {
+			
+			var o = ui.options;
+			var i = ui.instance;
+
+			if(i.overflowY[0] != document && i.overflowY[0].tagName != 'HTML') {
+				if(i.overflowY[0].offsetHeight - (ui.position.top - i.overflowY[0].scrollTop + i.clickOffset.top) < o.scrollSensitivity)
+					i.overflowY[0].scrollTop = i.overflowY[0].scrollTop + o.scrollSpeed;
+				if((ui.position.top - i.overflowY[0].scrollTop + i.clickOffset.top) < o.scrollSensitivity)
+					i.overflowY[0].scrollTop = i.overflowY[0].scrollTop - o.scrollSpeed;				
+			} else {
+				//$(document.body).append('<p>'+(e.pageY - $(document).scrollTop())+'</p>');
+				if(e.pageY - $(document).scrollTop() < o.scrollSensitivity)
+					$(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
+				if($(window).height() - (e.pageY - $(document).scrollTop()) < o.scrollSensitivity)
+					$(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
+			}
+			
+			if(i.overflowX[0] != document && i.overflowX[0].tagName != 'HTML') {
+				if(i.overflowX[0].offsetWidth - (ui.position.left - i.overflowX[0].scrollLeft + i.clickOffset.left) < o.scrollSensitivity)
+					i.overflowX[0].scrollLeft = i.overflowX[0].scrollLeft + o.scrollSpeed;
+				if((ui.position.top - i.overflowX[0].scrollLeft + i.clickOffset.left) < o.scrollSensitivity)
+					i.overflowX[0].scrollLeft = i.overflowX[0].scrollLeft - o.scrollSpeed;				
+			} else {
+				if(e.pageX - $(document).scrollLeft() < o.scrollSensitivity)
+					$(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
+				if($(window).width() - (e.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
+					$(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
+			}
+			
+			//ui.instance.recallOffset(e);
+			i.offset = {
+				left: i.mouse.start.left - i.originalPosition.left + (i.overflowXstart !== undefined ? i.overflowXstart - i.overflowX[0].scrollLeft : 0),
+				top: i.mouse.start.top - i.originalPosition.top + (i.overflowYstart !== undefined ? i.overflowYstart - i.overflowX[0].scrollTop : 0)
+			};
+
+		}
+	});
+
+})(jQuery);

Added: pie/trunk/pieplate/PIE-Plate/share/web/static/js/pieui.js
==============================================================================
--- (empty file)
+++ pie/trunk/pieplate/PIE-Plate/share/web/static/js/pieui.js	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,350 @@
+function ghetto_lightbox (content) {
+	var background = jQuery('<div id="lightbox"></div>');
+	jQuery('body').append(background).fadeIn(750);
+	var baa = jQuery('<div id="lightbox-content">'+content+'</div>');
+	var boxdox = jQuery('<div id="lightbox-docs">(Double-click to close)</div>');
+	background.append(baa);
+	background.append(boxdox);
+	jQuery('body').bind('dblclick', function (x) {
+	jQuery('#lightbox').fadeOut(750);
+	jQuery('#lightbox').replaceWith('');
+	
+});
+
+}
+
+
+function lorzy_remove_ast_node(node) {
+                   var target_after =  jQuery(node).next('.lorzy-target')[0];
+                    if(target_after) {
+                        target_after.remove();
+                    }
+
+                    
+                   var target_before =  jQuery(node).prev('.lorzy-target')[0];
+                    if(target_before) {
+                        target_before.remove();
+                    }
+
+                    node.replaceWith(lorzy_make_empty_drop_target());
+}
+
+
+var lorzy_draggable_opts = { revert: true, activeClass: 'draggable-active', opacity: '0.6'};
+var lorzy_droppable_opts = {
+            accept: '.lorzy-expression, .lorzy-expression-proto',
+            greedy: 'true',
+            activeClass: 'droppable-active',
+            hoverClass: 'droppable-hover',
+            tolerance: 'pointer',
+            drop: function(ev, ui) { 
+                var orig = jQuery(ui.draggable); 
+                var newitem = jQuery(ui.draggable).clone();
+                newitem.removeClass('lorzy-expression-proto')
+                  .attr({style: 'display: block'})
+                  .draggable(lorzy_draggable_opts)
+                  .droppable(lorzy_droppable_opts)
+                  .insertAfter(this);
+
+                if (!orig.parent().hasClass('library')) {
+                    lorzy_remove_ast_node(orig);
+
+                    jQuery(this).replaceWith('');
+                }
+
+                lorzy_wrap_in_drop_targets(newitem);
+
+                // use livequery or something
+                jQuery('.lorzy-expression', newitem).droppable(lorzy_droppable_opts);
+                jQuery('.lorzy-target', newitem).droppable(lorzy_droppable_opts);
+	        make_elements_editable(jQuery('.lorzy-expression.lorzy-const.string', newitem));
+                return true;
+
+}};
+
+var trashable_args = {
+            accept: '#wrapper .lorzy-expression',
+            greedy: 'true',
+            hover: 'pointer',
+            activeClass: 'droppable-active',
+            hoverClass: 'droppable-hover',
+            tolerance: 'pointer',
+            drop: function(ev, ui) { 
+                      var orig = jQuery(ui.draggable); 
+                      if (!orig.parent().hasClass('library')) {
+                        lorzy_remove_ast_node(orig);
+                   } 
+                    }
+};
+
+
+
+
+
+
+
+function lorzy_make_empty_drop_target (){
+      var x =  jQuery('<div class="lorzy-target"></div>');
+      x.droppable(lorzy_droppable_opts);
+      return(x);
+}
+function lorzy_wrap_in_drop_targets(node) {
+   
+    var myNode = jQuery(node);
+
+    if(! myNode.prev().hasClass('lorzy-target')){
+        jQuery(lorzy_make_empty_drop_target()).insertBefore(node);
+        } 
+
+    if(!myNode.next().hasClass('lorzy-target')){
+         jQuery(lorzy_make_empty_drop_target()).insertAfter(node);
+    }
+}
+
+
+
+
+function lorzy_show_expression_str(str, parent) {
+    jQuery(parent).replaceWith(lorzy_make_expression_str(str));
+}
+
+function lorzy_make_expression_str(str) {
+    var string =  jQuery('<div class="lorzy-expression lorzy-const string">'+str+'</div>');
+    return string;
+
+}
+
+function lorzy_show_exression_progn(expr, parent) {
+        jQuery.each(expr.nodes, function () { lorzy_show_expression(parent) });
+
+}
+
+function lorzy_show_expression(parent, add_event) {
+    if( this.name == 'progn') {
+        lorzy_show_expression_progn(this, parent);
+        return;
+    }
+
+    var ret = parent.createAppend('div', { className: this.name });
+    ret.addClass('lorzy-expression')
+    ret.addClass('lorzy-code');
+    lorzy_wrap_in_drop_targets(ret);
+    var that = this;
+    jQuery(ret).createAppend('div', { className: 'name'} , [this.name]);
+
+
+    var codeargs = lorzy_show_expression_args(this.args);
+    jQuery(ret).append(codeargs);
+
+    };
+
+    function lorzy_show_expression_args(args) {
+        var codeargs = jQuery('<div class="lorzy-code-args">');
+        
+
+    jQuery.each(args, function(name, exp) {
+        var entry = codeargs.createAppend('div', { className: 'lorzy-code-arg' });
+        entry.createAppend('div', { className: 'name'}, [ name]);
+        var value = entry.createAppend('div', { className: 'value'});
+        
+        if (typeof(exp) == 'string') {
+            var valcontent= value.createAppend('div', { className: 'lorzy-expression'});
+            lorzy_wrap_in_drop_targets(valcontent);
+            lorzy_show_expression_str(exp, valcontent);
+        } else if (exp) {
+            lorzy_show_expression.apply(exp, [value]); //[entry]);
+        } 
+
+
+    });
+
+    return codeargs;
+}
+
+
+function lorzy_show_symbols(struct) {
+        jQuery.each(struct, function(item, arg_list) {
+
+        var expression = jQuery('.library').createAppend('div', {className: 'lorzy-code lorzy-expression lorzy-expression-proto'});
+        expression.createAppend('div',{className: 'name'},[item]);
+        if(arg_list) {
+        var args_hook = expression.createAppend('div',{className: 'lorzy-code-args'});
+
+
+        jQuery.each(arg_list, function(attr)  { 
+                    var arg = args_hook.createAppend('div', {className: 'lorzy-code-arg'});
+                    arg.createAppend('div', {className: 'name'}, [attr]);
+                    var value = arg.createAppend('div', {className: 'value'});
+                   if (arg_list[attr].type == 'PIE::Expression') {
+                        value.append( lorzy_make_empty_drop_target() );
+                    } if (arg_list[attr].type == 'Str') {
+                        value.append(lorzy_make_expression_str('(click me to edit)'));
+                    } else {
+                        value.append('What should I do with '+arg_list[attr].type);
+                    }
+                    //args_hook.createAppend('div', {className: 'type'}, [attr.type]);
+                 
+        
+        });
+
+        }
+    });
+    jQuery('.library .lorzy-expression').draggable(lorzy_draggable_opts);
+}
+
+function lorzy_show(ops) {
+    jQuery(ops).each(
+        function() {
+            lorzy_show_expression.apply(this, [jQuery('#wrapper'), true]);
+            
+        });
+
+
+    jQuery('.lorzy-expression .lorzy-expression').draggable(lorzy_draggable_opts);
+
+    var tools = jQuery('<div class="lorzy-tools"></div>');
+    jQuery('#wrapper').after(tools);
+
+
+
+
+    tools.createAppend('div', { id: 'clicky'}, ['Serialize']);
+    tools.createAppend('div', { id: 'testy'}, ['Run on server']);
+    jQuery('#wrapper .lorzy-expression').droppable(lorzy_droppable_opts);
+    jQuery('#wrapper .lorzy-target').droppable(lorzy_droppable_opts);
+
+
+    var drop_targets = jQuery('<div class="lorzy-drop-targets"></div>');
+    jQuery('#wrapper').after(drop_targets);
+    drop_targets.createAppend('div', { id: 'trashy'} , ['Trash']);
+    jQuery('#trashy').droppable(trashable_args);
+
+
+
+    jQuery('#testy').click(function () {
+        jQuery.ajax({
+    'url': '/=/action/Pie.Plate.Action.RunL.json',
+    'datatype': 'text/json',
+    'type': 'post',
+    'success': function(json) { 
+            json = json.split(",").join(",\n");
+            ghetto_lightbox('<pre>'+json+'</pre>');
+}, 
+    'data': 'struct='+lorzy_generate_struct('#wrapper').toJSON()
+})
+
+
+    });
+
+    jQuery('#clicky').click(function () { 
+        var x =  lorzy_generate_struct('#wrapper').toJSON().split(",").join(",\n");
+        ghetto_lightbox('<pre>'+x+'</pre>');
+   
+    });
+
+    make_elements_editable(jQuery('#wrapper .lorzy-expression.lorzy-const.string'));
+    return true;
+};
+
+function make_elements_editable (elements) {
+        elements.bind('dblclick', function (x) { make_editable.apply(x.target)});
+
+
+
+    
+    
+    function make_editable() {
+                var noneditable = this;
+                var content = jQuery(noneditable).html();
+                var editable =  jQuery('<input type="text" class="lorzy-const lorzy-expression editable" value="'+content+'"/>');
+                 function blur_edit () {
+                    jQuery(noneditable).text( this.value); 
+                    jQuery(noneditable).bind('dblclick', function(x) { make_editable.apply(x.target)});
+                    jQuery(this).replaceWith(noneditable);
+                    }
+
+                editable.bind('blur', blur_edit)
+                        
+                        .bind('keypress', 
+                    
+                                // xxx icky. code duplication
+                                function (event) { if(event.keyCode == '13') { 
+                    jQuery(noneditable).text( this.value); 
+                    jQuery(noneditable).bind('dblclick', function(x) { make_editable.apply(x.target)});
+                    jQuery(this).replaceWith(noneditable);
+                            event.stopPropagation (true);
+                        }
+
+                        }
+                        );
+                        
+                    
+                
+                jQuery(this).replaceWith( editable);
+                
+            };
+
+}
+
+
+
+function lorzy_generate_struct(parent) {
+    var ops = jQuery(parent).children();
+    var tree=   jQuery.grep( 
+        jQuery.map(ops, function (op) { return lorzy_generate_op(jQuery(op)); }),
+
+        function(element, index) {
+            return (element && !jQuery(element).hasClass('lorzy-target'))
+        }
+    );
+   
+    return tree;
+}
+
+
+function lorzy_generate_op (op) {
+            if(op.hasClass('lorzy-target')) {
+            // it's nothing. skip it
+                return '';
+
+                }
+            if (op.hasClass('lorzy-const')) {            
+               return op.text();
+            } 
+           else if( op.hasClass('lorzy-expression')) {
+                var codeargs =  op.children('.lorzy-code-args').children();
+                return { 'name': op.children('.name').text(), 'args': lorzy_generate_args_struct(codeargs)  };
+            } 
+            
+            else if (op.hasClass('lorzy-progn')) {    
+                return { 'progn':  lorzy_generate_progn(op)}; 
+            }else  { 
+            console.log("failed to find a class on " +op.attr('class'));
+            }
+}
+
+function lorzy_generate_progn(op) {
+        return lorzy_generate_struct(op);//.children('lorzy-expression'));
+
+}
+
+
+function lorzy_generate_args_struct(args) {
+
+    var myArray = {};
+     jQuery.map(args, function (op)  {  
+               var values =  lorzy_generate_struct(jQuery(op).children('.value'));
+               if (values.length < 1 ) {
+                    myArray[ jQuery(op).children('.name').text() ]= null;
+                }
+               else if (values.length == 1) {
+                myArray[ jQuery(op).children('.name').text() ] =   values[0] ;
+               } else {
+                myArray[ jQuery(op).children('.name').text() ] =  { 'progn': values} ;
+               }
+    });
+
+
+    return myArray;
+}
+

Modified: pie/trunk/t/01basic.t
==============================================================================
--- pie/trunk/t/01basic.t	(original)
+++ pie/trunk/t/01basic.t	Tue Jul  8 10:36:26 2008
@@ -1,158 +1,123 @@
 use Test::More qw'no_plan';
-
+use strict;
 use_ok('PIE::Expression');
 use_ok('PIE::Evaluator');
 use_ok('PIE::Lambda');
 use_ok('PIE::Lambda::Native');
 use_ok('PIE::Builder');
-
+use_ok('PIE::FunctionArgument');
 my $trivial = PIE::Expression::True->new;
 
 my $evaluator = PIE::Evaluator->new;
-ok ($evaluator->run($trivial));
-ok($evaluator->result->success);
-ok($evaluator->result->value);
-
+ok( $evaluator->run($trivial) );
+ok( $evaluator->result->success );
+ok( $evaluator->result->value );
 
 my $false = PIE::Expression::False->new();
 my $eval2 = PIE::Evaluator->new;
-ok($eval2->run($false));
-ok(!$eval2->result->value);
-ok($eval2->result->success);
-
+ok( $eval2->run($false) );
+ok( !$eval2->result->value );
+ok( $eval2->result->success );
+
+my $if_true = PIE::Expression::IfThen->new( args => {
+    condition => PIE::Expression::True->new(),
+    if_true   => PIE::Expression::True->new(),
+    if_false  => PIE::Expression::False->new()}
+);
 
-my $if_true = PIE::Expression::IfThen->new( condition => PIE::Expression::True->new(),                                           if_true => PIE::Expression::True->new(),if_false => PIE::Expression::False->new());
-                                            
 my $eval3 = PIE::Evaluator->new();
-ok($eval3->run($if_true));
-ok($eval3->result->value);
-ok($eval2->result->success);
+ok( $eval3->run($if_true) );
+ok( $eval3->result->value );
+ok( $eval3->result->success, $eval3->result->error );
+
+my $if_false = PIE::Expression::IfThen->new( args => {
+    condition => PIE::Expression::False->new(),
+    if_true   => PIE::Expression::True->new(),
+    if_false  => PIE::Expression::False->new()}
+);
 
-my $if_false = PIE::Expression::IfThen->new( condition => PIE::Expression::False->new(),                                           if_true => PIE::Expression::True->new(),if_false => PIE::Expression::False->new());
-                                            
 my $eval4 = PIE::Evaluator->new();
-ok($eval4->run($if_false));
-ok(!$eval4->result->value);
-ok($eval4->result->success);
-
-
-
-
-
-my $MATCH_REGEX =     PIE::Lambda::Native->new( body =>  sub { my ($arg, $regexp) = @_;
-                                    return $arg =~ m/$regexp/; },
-                            
-                            bindings => [ 'tested-string', 'regex' ],
-                            
-                            );
-
-
-
-my $eval5 = PIE::Evaluator->new;
-$eval5->set_named( 'match-regexp' => $MATCH_REGEX);
-    
-                                    
-
-my $match_p = PIE::Expression->new(elements => ['match-regexp',
-                                                PIE::Expression::String->new( value => 'I do love software'), 
-                                                PIE::Expression::String->new( value =>'software')]);
-
-$eval5->run($match_p);
-ok ($eval5->result->success);
-
-is($eval5->result->value, 1);
-
-
-
-my $eval6 = PIE::Evaluator->new();
-
-$eval6->set_named( 'match-regexp' => $MATCH_REGEX);
-
+ok( $eval4->run($if_false) );
+ok( !$eval4->result->value );
+ok( $eval4->result->success );
 
-
-my $match_fail_p = PIE::Expression->new(elements => ['match-regexp',
-                                                PIE::Expression::String->new( value => 'I do love hardware'), 
-                                                PIE::Expression::String->new( value =>'software')]);
-
-$eval6->run($match_fail_p);
-ok ($eval6->result->success);
-
-ok(!$eval6->result->value);
-
-
-my $script = PIE::Lambda->new(nodes => [ 
+my $script = PIE::Lambda->new(
+   progn => PIE::Expression::ProgN->new(
+    nodes => [
         PIE::Expression::True->new()
 
-],
+    ]),
 
 );
 
 my $eval7 = PIE::Evaluator->new();
-$eval7->apply_script($script);
-ok($eval7->result->success);
-ok($eval7->result->value);
-
-
+$eval7->apply_script($script, {} );
+ok( $eval7->result->success );
+ok( $eval7->result->value );
 
 my $script2 = PIE::Lambda->new(
-    nodes => [
-                $if_true ]);
+   progn => PIE::Expression::ProgN->new(
+ nodes => [$if_true] ) );
 
 my $eval8 = PIE::Evaluator->new();
-$eval8->apply_script($script2);
-ok($eval8->result->success);
-ok($eval8->result->value);
+$eval8->apply_script($script2, {});
+ok( $eval8->result->success );
+ok( $eval8->result->value );
 
 my $eval9 = PIE::Evaluator->new();
 
-$eval9->set_named( 'match-regexp' => $MATCH_REGEX);
-
-
+my $MATCH_REGEX = PIE::Lambda::Native->new(
+    body => sub {
+        my $args = shift;
+        my $arg    = $args->{'tested-string'};
+        my $regexp = $args->{'regexp'};
+        return ($arg =~ m/$regexp/ )? 1 : 0;
+    },
+
+    signature => {
+        'tested-string' => PIE::FunctionArgument->new( name => 'tested-string' => type => 'Str'),
+        'regexp' => PIE::FunctionArgument->new( name => 'regexp', type => 'Str' )
+        }
 
-my $match_script = PIE::Lambda->new(
-
-    nodes => [
-        PIE::Expression->new(
-            elements => [
-                'match-regexp',
-                PIE::Expression::Symbol->new( symbol => 'tested-string' ),
-                PIE::Expression::Symbol->new( symbol => 'regex' ),
-            ]
-        )
-    ],
-    bindings => [ 'tested-string', 'regex' ],
 );
 
+$eval9->set_global_symbol( 'match-regexp' => $MATCH_REGEX );
 
-$eval9->apply_script($match_script,                                                 PIE::Expression::String->new( value => 'I do love hardware'), 
-                                                PIE::Expression::String->new( value =>'software') );
-
-ok ($eval9->result->success);
-
-is($eval9->result->value, 1);
-my $tree = 
-[
-          {
-            name => 'IfThen',
-            args => {
-                          'if_true' => 'hate',
-                          'if_false' => 'love',
-                          'condition' => [ 'match-regexp', 'software', 'foo' ],
-                        }
-          }
-        ];
+$eval9->apply_script(
+    $MATCH_REGEX, 
+    {   'tested-string' => PIE::Expression::String->new( args => {value => 'I do love software'} ),
+        'regexp' => PIE::Expression::String->new( args => { value => 'software' })
+    }
+);
 
+ok( $eval9->result->success, $eval9->result->error );
+is( $eval9->result->value, 1 );
 
 my $builder = PIE::Builder->new();
-#use YAML;
-
 my $eval10 = PIE::Evaluator->new();
+$eval10->set_global_symbol( 'match-regexp' => $MATCH_REGEX );
 
-$eval10->set_named( 'match-regexp' => $MATCH_REGEX);
-
-
-$eval10->apply_script( $builder->build_expressions($tree) );
-ok($eval10->result->success);
-is($eval10->result->value,'love');
-
+$eval10->apply_script(
+    $builder->defun(
+        ops => [
+            {   name => 'IfThen',
+                args => {
+                    'if_true'   => 'hate',
+                    'if_false'  => 'love',
+                    'condition' => {
+                        name => 'match-regexp',
+                        args => {
+                            regexp           => 'software',
+                            'tested-string' => 'foo',
+                        }
+                    }
+                }
+            }
+        ],
+        signature => {},
+    ),
+    {},
+);
+ok( $eval10->result->success, " Did not get an error: ".$eval10->result->error );
+is( $eval10->result->value, 'love' );
 

Added: pie/trunk/t/builder.t
==============================================================================
--- (empty file)
+++ pie/trunk/t/builder.t	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,45 @@
+use Test::More qw'no_plan';
+use strict;
+use_ok('PIE::Expression');
+use_ok('PIE::Evaluator');
+use_ok('PIE::Builder');
+
+my $builder = PIE::Builder->new();
+my $eval = PIE::Evaluator->new();
+#$eval->set_global_symbol( 'match-regexp' => $MATCH_REGEX );
+
+my $script = $builder->defun(
+                             ops => [
+                                     { name => 'ProgN',
+                                       args => {
+                                                nodes => [
+                                                          { name => 'True', args => {} },
+                                                          { name => 'False', args => {} },
+                         ],
+                                               } } ],
+                            signature => {});
+
+#warn Dumper($script);use Data::Dumper;
+# XXX: ensure $script structure
+use Data::Dumper;
+is_deeply($script->progn->nodes, 
+        [ 
+          bless( {
+                   'signature' => {},
+                   'name' => 'ProgN',
+                   'args' => {},
+                   'nodes' => [
+                                bless( {
+                                         'signature' => {},
+                                         'name' => 'True',
+                                         'args' => {}
+                                       }, 'PIE::Expression::True' ),
+                                bless( {
+                                         'signature' => {},
+                                         'name' => 'False',
+                                         'args' => {}
+                                       }, 'PIE::Expression::False' )
+                              ]
+                 }, 'PIE::Expression::ProgN' )
+
+        ]                );

Modified: pie/trunk/t/hello_world.t
==============================================================================
--- pie/trunk/t/hello_world.t	(original)
+++ pie/trunk/t/hello_world.t	Tue Jul  8 10:36:26 2008
@@ -1,8 +1,8 @@
-use Test::More tests => 13;
-
+use Test::More tests => 14;
 
 use_ok('PIE::Evaluator');
 use_ok('PIE::Builder');
+use_ok('PIE::FunctionArgument');
 
 package Hello;
 
@@ -10,90 +10,104 @@
 use MooseX::AttributeHelpers;
 
 has 'evaluator' => (
-    is => 'rw',
-    isa => 'PIE::Evaluator',
-    lazy => 1,
-    default => sub { return PIE::Evaluator->new()},
+    is      => 'rw',
+    isa     => 'PIE::Evaluator',
+    lazy    => 1,
+    default => sub { return PIE::Evaluator->new() },
 );
 
 has 'rules' => (
-#    metaclass => 'Collection::Array',
-    is => 'rw',
-    isa => 'ArrayRef',
-#     provides  => {
-#                 push       => 'push_rules'
-#     },
-#    default   => sub { [] },
-    );
-
 
+    #    metaclass => 'Collection::Array',
+    is  => 'rw',
+    isa => 'ArrayRef',
 
+    #     provides  => {
+    #                 push       => 'push_rules'
+    #     },
+    #    default   => sub { [] },
+);
 
-sub run { 
+sub run {
     my $self = shift;
     my $name = shift;
 
-    for (@{$self->rules||[]}) {
-        $self->evaluator->apply_script($_, 
-                                       PIE::Expression::String->new( value => $name ));
-        last unless ($self->evaluator->result->success);
-        $name =  $self->evaluator->result->value;
-    }   
+     my $args = { name => PIE::Expression::String->new( args => { value => $name } ) };
+    for ( @{ $self->rules || [] } ) {
+        $self->evaluator->apply_script( $_, $args);
+
+        last unless ( $self->evaluator->result->success );
+        $name = $self->evaluator->result->value;
+    }
 
     return "Hello $name";
 }
 
-
-
-
 package main;
 
-is (Hello->new->run('jesse'),'Hello jesse');
+is( Hello->new->run('jesse'), 'Hello jesse' );
 
 my $hello = Hello->new;
-isa_ok($hello => 'Hello');
+isa_ok( $hello => 'Hello' );
 
 use PIE::Lambda::Native;
-$hello->evaluator->set_named('make-fred',
-                             PIE::Lambda::Native->new( body => sub { return 'fred'}));
-$hello->evaluator->set_named('make-bob', PIE::Lambda::Native->new( body => sub { my $name = shift; return 'bob'}));
-
-$hello->evaluator->set_named('make-whoever',
-                             PIE::Lambda::Native->new( body => sub { return $_[0] },
-                                                       bindings => ['name'] ));
+$hello->evaluator->set_global_symbol( 'make-fred',
+    PIE::Lambda::Native->new( body => sub { return 'fred' } ) );
+$hello->evaluator->set_global_symbol( 'make-bob',
+    PIE::Lambda::Native->new( body => sub { return 'bob' } ) );
+
+$hello->evaluator->set_global_symbol(
+    'make-whoever',
+    PIE::Lambda::Native->new(
+        body => sub { my $args = shift; return $args->{'name'} },
+        signature => {
+            name => PIE::FunctionArgument->new( name => 'name', type => 'Str' )
+            }
 
+    )
+);
 
-my $tree = [ [ 'make-fred'] ];
+my $tree    = [ { name => 'make-fred' } ];
 my $builder = PIE::Builder->new();
-my $script = $builder->build_expressions($tree);
-$script->bindings([ 'name' ]);
-
-$hello->rules([ $script]);
-can_ok($hello->rules->[0], 'evaluate');
-is ($hello->run('jesse'),'Hello fred');
-
-my $script2 = $builder->build_expressions([ ['make-bob'], ['make-fred'] ] );
-$script2->bindings([ 'name' ]);
-$hello->rules([ $script2 ]);
-can_ok($hello->rules->[0], 'evaluate');
-
-is ($hello->run('jesse'),'Hello fred');
-
-my $script3 = $builder->build_expressions([ ['make-bob'] ]);
-$script3->bindings([ 'name' ]);
-my $script4 = $builder->build_expressions([ ['make-fred'] ]);
-$script4->bindings([ 'name' ]);
+my $script  = $builder->defun(
+    ops => $tree,
+    signature =>
+        { name => PIE::FunctionArgument->new( name => 'name', type => 'Str' ) }
+);
 
-$hello->rules([ $script3, $script4 ]);
+$hello->rules( [$script] );
+isa_ok( $hello->rules->[0], 'PIE::Lambda' );
+is( $hello->run('jesse'), 'Hello fred' );
+
+my $script2 = $builder->defun(
+    ops => [ { name => 'make-bob' }, { name => 'make-fred' } ],
+    signature =>
+        { name => PIE::FunctionArgument->new( name => 'name', type => 'Str' ) }
+);
+$hello->rules( [$script2] );
+isa_ok( $hello->rules->[0], 'PIE::Lambda' );
 
-can_ok($hello->rules->[0], 'evaluate');
-can_ok($hello->rules->[1], 'evaluate');
-is ($hello->run('jesse'),'Hello fred');
+is( $hello->run('jesse'), 'Hello fred' );
 
+my $script3 = $builder->defun(
+    ops => [ { name => 'make-bob' } ],
+    signature =>
+        { name => PIE::FunctionArgument->new( name => 'name', type => 'Str' ) }
+);
+my $script4 = $builder->defun(
+    ops => [ { name => 'make-fred' } ],
+    signature =>
+        { name => PIE::FunctionArgument->new( name => 'name', type => 'Str' ) }
+);
 
-$hello->rules([ $hello->evaluator->get_named('make-whoever') ]);
-can_ok($hello->rules->[0], 'evaluate');
-is ($hello->run('jesse'),'Hello jesse');
+$hello->rules( [ $script3, $script4 ] );
 
+isa_ok( $hello->rules->[0], 'PIE::Lambda' );
+isa_ok( $hello->rules->[1], 'PIE::Lambda' );
+is( $hello->run('jesse'), 'Hello fred' );
+
+$hello->rules( [ $hello->evaluator->get_global_symbol('make-whoever') ] );
+isa_ok( $hello->rules->[0], 'PIE::Lambda' );
+is( $hello->run('jesse'), 'Hello jesse' );
 
 1;

Added: pie/trunk/t/introspection.t
==============================================================================
--- (empty file)
+++ pie/trunk/t/introspection.t	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+
+use Test::More qw/no_plan/;
+use_ok('PIE::Evaluator');
+use_ok('PIE::Lambda::Native');
+my $e = PIE::Evaluator->new();
+
+my $signatures =  $e->core_expression_signatures;
+is_deeply($signatures->{'PIE::Expression::True'} , {});
+is_deeply($signatures->{'PIE::Expression::IfThen'} , { if_true => { type => 'PIE::Evaluatable'},
+                                                    if_false => {type => 'PIE::Evaluatable'},
+                                                    condition => {type => 'PIE::Evaluatable'}
+    
+    
+    });
+my $symbols = $e->symbol_signatures();
+is_deeply($symbols, {});
+
+my $MATCH_REGEX = PIE::Lambda::Native->new(
+    body => sub {
+        my $args = shift;
+        my $arg    = $args->{'tested-string'};
+        my $regexp = $args->{'regexp'};
+        return ($arg =~ m/$regexp/ )? 1 : 0;
+    },
+
+    signature => {
+        'tested-string' => PIE::FunctionArgument->new( name => 'tested-string' => type => 'Str'),
+        'regexp' => PIE::FunctionArgument->new( name => 'regexp', type => 'Str' )
+        }
+
+);
+
+$e->set_global_symbol( 'match-regexp' => $MATCH_REGEX );
+
+$symbols = $e->symbol_signatures();
+is_deeply($e->symbol_signatures(),  { 'match-regexp' => { regexp => { type => 'Str'}, 'tested-string' => { type => 'Str'}}});
+
+

Added: pie/trunk/t/leaky-lexicals.t
==============================================================================
--- (empty file)
+++ pie/trunk/t/leaky-lexicals.t	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,37 @@
+use Test::More qw'no_plan';
+use strict;
+use_ok('PIE::Expression');
+use_ok('PIE::Evaluator');
+use_ok('PIE::Lambda');
+use_ok('PIE::Lambda::Native');
+use_ok('PIE::Builder');
+use_ok('PIE::FunctionArgument');
+
+
+my $eval = PIE::Evaluator->new;
+my $builder = PIE::Builder->new();
+
+my $A_SIDE = PIE::Builder->defun( 
+        ops => [ 
+        
+         { name => 'Symbol', args => { symbol => 'x'}},
+                    { name => 'Symbol', args => { symbol => 'y'} }
+                
+                
+                ],
+        signature => { x => PIE::FunctionArgument->new(name => 'x', type => 'Str')});
+
+
+$eval->set_global_symbol( 'a' => $A_SIDE );
+
+my $defined_b = $builder->defun(
+    ops => [{ name => 'a', args => { x => 'x456' }} ],
+    signature =>
+        { y => PIE::FunctionArgument->new( name => 'y', type => 'String' ) }
+);
+
+$eval->set_global_symbol( b=> $defined_b);
+
+$eval->run( $builder->build_expression( { name => 'b', args => { y => 'Y123' }}));
+ok (!$eval->result->success);
+like($eval->result->error,qr/Could not find symbol y in the current lexical context/);

Added: pie/trunk/t/let.t
==============================================================================
--- (empty file)
+++ pie/trunk/t/let.t	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,67 @@
+use Test::More tests => 13;
+use strict;
+use_ok('PIE::Expression');
+use_ok('PIE::Evaluator');
+use_ok('PIE::Builder');
+use_ok('PIE::Lambda::Native');
+use_ok('PIE::FunctionArgument');
+use Test::Exception;
+
+my $MATCH_REGEX = PIE::Lambda::Native->new(
+    body => sub {
+        my $args = shift;
+        my $arg    = $args->{'tested-string'};
+        my $regexp = $args->{'regexp'};
+        return ($arg =~ m/$regexp/ )? 1 : 0;
+    },
+
+    signature => {
+        'tested-string' => PIE::FunctionArgument->new( name => 'tested-string' => type => 'Str'),
+        'regexp' => PIE::FunctionArgument->new( name => 'regexp', type => 'Str' )
+        }
+
+);
+
+my $builder = PIE::Builder->new();
+my $eval = PIE::Evaluator->new();
+$eval->set_global_symbol( 'match-regexp' => $MATCH_REGEX );
+
+my $script =
+    $builder->defun( # outer block
+    ops => [
+        { name => 'Let', #inner block. each block has a lexical pad structure
+            args => {
+                bindings => { REGEXP => 'software' },
+                nodes => [
+                    { name => 'IfThen',
+                        args => {
+                            'if_true'   => 'hate',
+                            'if_false'  => 'love',
+                            'condition' => {
+                                name => 'match-regexp',
+                                args => {
+                                    regexp => { name => 'Symbol', args => { symbol => 'REGEXP' } },
+                                    'tested-string' => 
+                                         { name => 'Symbol', args => { symbol => 'tested-string' } }, # lookup to tested string needs to query the outer block's lexpad
+                                    }
+                                }
+                            }
+                    }
+                    ] } } ],
+    signature => { 'tested-string' => PIE::FunctionArgument->new( name => 'tested-string' => type => 'Str' ) },
+    );
+
+is(scalar @{$script->progn->nodes}, 1);
+isa_ok($script->progn->nodes->[0], 'PIE::Expression::Let');
+is(scalar @{$script->progn->nodes->[0]->nodes}, 1);
+
+ok(exists $script->progn->nodes->[0]->bindings->{REGEXP});
+isa_ok($script->progn->nodes->[0]->bindings->{REGEXP}, 'PIE::Expression');
+
+
+lives_ok {
+    $eval->apply_script( $script, { 'tested-string', 'you do love software' } );
+};
+ok( $eval->result->success, $eval->result->error );
+is( $eval->result->value, 'hate' );
+

Added: pie/trunk/t/list.t
==============================================================================
--- (empty file)
+++ pie/trunk/t/list.t	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,54 @@
+use Test::More tests => 6;
+use strict;
+use_ok('PIE::Expression');
+use_ok('PIE::Evaluator');
+use_ok('PIE::Builder');
+use_ok('PIE::Lambda::Native');
+use_ok('PIE::FunctionArgument');
+use Test::Exception;
+my $builder = PIE::Builder->new();
+my $eval = PIE::Evaluator->new();
+
+my $script =
+    $builder->defun(
+    ops => [
+        { name => 'List',
+            args => {
+                nodes => [
+                     "hate",
+                     "love",
+                     "hate"  ] } } ],
+    signature => { });
+
+$eval->set_global_symbol( 'get-list' => $script );
+
+my @remembered;
+$eval->set_global_symbol( 'remember' =>
+PIE::Lambda::Native->new(
+    body => sub {
+        my $args = shift;
+        push @remembered, $args->{what};
+        return 1;
+    },
+
+    signature => {
+        'what' => PIE::FunctionArgument->new( name => 'what' => type => 'Str'),
+        }
+
+) );
+
+
+$eval->apply_script(
+    $builder->defun(
+    ops => [
+        { name => 'ForEach',
+            args => {
+                list => { name => 'get-list', args => {} },
+                binding => 'what',
+                do => { name => 'Symbol', args => { symbol => 'remember'} }
+                    }
+        } ],
+    signature => { }),
+ {});
+
+is_deeply(\@remembered, ['hate', 'love', 'hate']);

Added: pie/trunk/t/named-params.t
==============================================================================
--- (empty file)
+++ pie/trunk/t/named-params.t	Tue Jul  8 10:36:26 2008
@@ -0,0 +1,68 @@
+use Test::More qw/no_plan/;
+use warnings;
+use strict;
+
+use_ok('PIE::Lambda');
+use_ok('PIE::Lambda::Native');
+use_ok('PIE::Expression');
+use_ok('PIE::Evaluator');
+use_ok('PIE::FunctionArgument');
+my $MATCH_REGEX = PIE::Lambda::Native->new(
+    body => sub {
+        my $args = shift;
+        my $arg = $args->{'tested-string'};
+        my $regex = $args->{'regex'};
+            
+        return $arg =~ m/$regex/;
+    },
+
+    signature => {
+           'tested-string' =>  PIE::FunctionArgument->new( name =>              'tested-string' =>  type => 'Str' ),
+           'regex'=>  PIE::FunctionArgument->new( name =>      'regex', type => 'Str' )
+    }
+
+);
+my $eval5 = PIE::Evaluator->new;
+$eval5->set_global_symbol( 'match-regex' => $MATCH_REGEX );
+
+my $match_p = PIE::Expression->new(
+        name => 'match-regex',
+        args => {
+            'tested-string' =>          PIE::Expression::String->new( args => {value => 'I do love software'} ),
+            'regex' =>                  PIE::Expression::String->new( args => { value => 'software' } )
+        }
+);
+
+$eval5->run($match_p);
+ok( $eval5->result->success );
+
+is( $eval5->result->value, 1 );
+
+my $eval6 = PIE::Evaluator->new();
+
+$eval6->set_global_symbol( 'match-regex' => $MATCH_REGEX );
+
+my $match_fail_p = PIE::Expression->new(
+        name => 'match-regex',
+        args => { 
+        'tested-string' => PIE::Expression::String->new( args => { value => 'I do love hardware' }),
+        'regex' => PIE::Expression::String->new( args => { value => 'software'} )
+}
+);
+
+$eval6->run($match_fail_p);
+ok( $eval6->result->success );
+ok( !$eval6->result->value );
+
+
+my $match_orz = PIE::Expression->new(
+        name => 'match-regex',
+        args => {
+            'tested-string' =>          PIE::Expression::String->new( args => { value => 'I do love software'} ),
+            'wrong-param-name' =>            PIE::Expression::String->new( args => {  value => 'software' }),
+        }
+);
+
+$eval6->run($match_orz);
+
+ok( !$eval6->result->success, "yay! it failed when we gave it a wrong argument name". $eval6->result->error );



More information about the Bps-public-commit mailing list