Author: spadkins
Date: Wed Sep  2 11:15:46 2009
New Revision: 13260

Added:
   p5ee/trunk/App-Widget-ExtJS/cgi-bin/
   p5ee/trunk/App-Widget-ExtJS/cgi-bin/App/
   p5ee/trunk/App-Widget-ExtJS/cgi-bin/App/app-ext-repository   (contents, 
props changed)

Log:
new

Added: p5ee/trunk/App-Widget-ExtJS/cgi-bin/App/app-ext-repository
==============================================================================
--- (empty file)
+++ p5ee/trunk/App-Widget-ExtJS/cgi-bin/App/app-ext-repository  Wed Sep  2 
11:15:46 2009
@@ -0,0 +1,102 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use App::Options;
+use App;
+
+{
+    my ($json_result_set);
+    eval {
+        my $context = App->context();
+        my $request = $context->request();
+        my $cgi     = $request->{cgi};
+
+        if ($App::options{verbose}) {
+            print STDERR "app-ext-repository: CGI=$cgi\n";
+            foreach my $p ($cgi->param()) {
+                print STDERR "   $p : ", $cgi->param($p), "\n";
+            }
+        }
+
+        my $rep     = $context->repository();
+        my $json    = $context->serializer("json", class => 
"App::Serializer::Json");
+
+        my %cgi_param_ignored = (
+            context  => 1,
+            table    => 1,
+            columns  => 1,
+            start    => 1,
+            limit    => 1,
+            sort     => 1,
+            dir      => 1,
+            order_by => 1,
+            rowtype  => 1,
+        );
+        my ($rows);
+
+        my @cgi_params  = $cgi->param();
+
+        my $table   = $cgi->param("table") || $App::options{table} || die 
"app-ext-repository: table param not set\n";
+
+        my $columns = $cgi->param("columns");
+        if ($columns) {
+            $columns = [ split(/,/, $columns) ] if (!ref($columns));
+        }
+        else {
+            $columns = $rep->_get_default_columns($table);
+        }
+
+        my $rowtype = $cgi->param("rowtype") || "array";
+
+        my $params  = {};
+        my ($value);
+        foreach my $cgi_param (@cgi_params) {
+            if (!$cgi_param_ignored{$cgi_param}) {
+                $value = $cgi->param($cgi_param);
+                $params->{$cgi_param} = $value if (defined $value && $value !~ 
/^\s*$/);
+            }
+        }
+
+        my $options = {};
+        my $startrow = ($cgi->param("start") || 0) + 1;
+        $startrow = 1 if ($startrow < 1);
+        my $limit = $cgi->param("limit");
+        my $endrow = $limit ? $startrow + $limit - 1: 0;
+        $options->{startrow} = $startrow if ($startrow > 1);
+        $options->{endrow} = $endrow if ($endrow > 0);
+        my $sort = $cgi->param("sort");
+        my $order_by = $cgi->param("order_by");
+        my $dir = $cgi->param("dir");
+        if ($sort || $order_by) {
+            my (@order_by);
+            @order_by = split(/,/, $order_by) if ($order_by);
+            if ($sort) {
+                $sort = $sort . "." . lc($dir) if ($dir);
+                unshift(@order_by, $sort);
+            }
+            $options->{order_by} = \...@order_by;
+        }
+
+        if ($rowtype eq "object") {
+            $rows   = $rep->get_hashes($table, $params, $columns, $options);
+        }
+        else {
+            $rows   = $rep->get_rows($table, $params, $columns, $options);
+        }
+        my $nrows = $rep->get($table, $params, "count(1)") + 0;
+
+        my $result_set = {
+            totalCount => $nrows,
+            data => $rows,
+        };
+        $json_result_set = $json->serialize($result_set);
+    };
+    if ($@) {
+        print "Context-type: text/plain\n\nERROR: ", $@;
+    }
+    else {
+        print "Context-type: text/plain\n\n", $json_result_set;
+    }
+}
+

Reply via email to