Re: [Catalyst] Catalyst and ExtJS : Using Table Relationships

2009-05-25 Thread Peter Karman
jagdish eashwar wrote on 5/24/09 10:11 AM:
 Hi,
 
 I am trying my hand at using Catalyst and the ExtJS Grid (instead of TT). I
 am able to fetch data from a single table and display them in the grid. But
 I am not able to figure out how I can use the table relationships to fetch,
 say, the corresponding item_name for a given item_code and display that in
 the grid instead of the item_code.
 
 If I use TT, I use the following to fetch the item_name from another table
 in the schema:
 
 [% FOREACH item IN item_stash  %]
 [% item.belongs_to_relationship.item_name %]
 [% END %]
 
 How is this to be done when one is using the ExtJS Grid? I'm following
 mainly Jason Kohles' tutorial which is available at
 http://www.catalystframework.org/calendar/2007/9.
 

Presumably when you serialize your data into JSON, just use the foreign table
value you want instead of the foreign key.

CatalystX::CRUD::YUI implements this with the ExtJS livegrid extension, using
Rose::HTMLx::Form::Related.

Basically, each Controller corresponds to one table, and each table has one ORM
(DBIC or RDBO) class and one Form (RHTMLO) class. The Form class builds an
internal metadata structure for serializing a table row using unique values from
foreign (related) tables instead of the foreign key value.

So for example, if you had a db like:

 create table persons (
 id   serial primary key,
 name varchar(255) not null
 );
 create unique index person_name on persons(name);

 create table users (
 username   varchar(16),
 person_id  int not null references persons(id)
 );
 create unique index user_username on users(username);

where each Person can have one or more related User records, every time the User
Form is serialized it displays the person.name instead of the users.person_id.

The unique value is defined in each ORM class (DBIx::Class::RDBOHelpers for DBIC
and Rose::DBx::Object::MoreHelpers for RDBO) with the unique_value() method,
which by default looks for the first single-column unique column in the table.


-- 
Peter Karman  .  http://peknet.com/  .  pe...@peknet.com

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Catalyst and ExtJS

2009-03-16 Thread Adam Witney


On 14 Mar 2009, at 20:26, Moritz Onken wrote:





Hi Scott,

thanks for the info, do you use any particular module or have you  
built it yourself? I have found so far:


HTML::FormFu::ExtJS
Catalyst-Controller-HTML-FormFu-ExtJS

any you'd recommend taking a look at?

thanks again

adam



Hi Adam,

I'm the author of the above mentioned modules.  
C::C::HTML::FormFu::ExtJS was just a proof of concept. You can use  
it though. It's simply a subclass of C::C::HTML::FormFu and replaces  
new HTML::FormFu with new HTML::FormFu::ExtJS.


HTML::FormFu::ExtJS is actively developed. The version on CPAN is  
not very recent because I'm waiting for the maintainer of  
HTML::FormFu to release a new version. The most recent version is at http://html-formfu.googlecode.com/svn/trunk/HTML-FormFu-ExtJS/ 
 (requires the svn version of HTML::FromFu).


Try it, look at the tests, see me at IRC #formfu or email me. I'd be  
glad if someone is using this module so we can find bugs and add  
features to it.


Thanks for the link Moritz,

I'm working my way through your examples from

http://html-formfu.googlecode.com/svn/trunk/HTML-FormFu-ExtJS/lib/HTML/FormFu/ExtJS.pm

Should javascript.tt2 contain this:

script type=text/javascript
Ext.onReady(function(){
 var submitForm = function() {
   form.getForm().submit({ success: function(rst, req) {
  // submission was successful and valid } })
}
   });
 };

var form = [% form.render %];
 form.render(document.body);
});
/script

I needed to make these changes to get it to display.

thanks again for your help?

adam


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Catalyst and ExtJS

2009-03-16 Thread Moritz Onken




Thanks for the link Moritz,

I'm working my way through your examples from

http://html-formfu.googlecode.com/svn/trunk/HTML-FormFu-ExtJS/lib/HTML/FormFu/ExtJS.pm

Should javascript.tt2 contain this:

script type=text/javascript
Ext.onReady(function(){
var submitForm = function() {
  form.getForm().submit({ success: function(rst, req) {
 // submission was successful and valid } })
   }
  });
};

var form = [% form.render %];
form.render(document.body);
});
/script

I needed to make these changes to get it to display.


Yes that's correct. HTML::FormFu::ExtJS helps you with creating the  
form only.

The whole logic is up to you.

There are many ways to display a form. I usually put them in an  
Ext.Window.

But you can still render them directly to your html body.

moritz


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


RE: [Catalyst] Catalyst and ExtJS

2009-03-16 Thread Scott Pham (scpham)

 -Original Message-
 From: Adam Witney [mailto:awit...@sgul.ac.uk]
 Sent: Saturday, March 14, 2009 2:05 PM
 To: The elegant MVC web framework
 Subject: Re: [Catalyst] Catalyst and ExtJS
 
 
 On 14 Mar 2009, at 15:19, Scott Pham (scpham) wrote:
 
  -Original Message-
  From: Adam Witney [mailto:awit...@sgul.ac.uk]
  Sent: Saturday, March 14, 2009 10:36 AM
  To: The elegant MVC web framework
  Subject: [Catalyst] Catalyst and ExtJS
 
 
  Hi,
 
  I was thinking about using Catalyst and ExtJS, does anyone have any
  experience or know if they will play nicely together? Doing some
  googling implies that this is not a popular combination due to the
  limited information
 
  thanks for any help
 
  adam
 
 
  Yes I currently have a couple of apps that use ExtJS + Catalyst,
 works
  great for me!
 
 Hi Scott,
 
 thanks for the info, do you use any particular module or have you
 built it yourself? I have found so far:
 
 HTML::FormFu::ExtJS
 Catalyst-Controller-HTML-FormFu-ExtJS
 
 any you'd recommend taking a look at?
 
 thanks again
 
 adam
 

I built it myself using Catalyst::View::JSON and TT. It's actually
pretty easy when you get the hang out it.


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Catalyst and ExtJS

2009-03-16 Thread Adam Witney



Hi Scott,

thanks for the info, do you use any particular module or have you
built it yourself? I have found so far:

HTML::FormFu::ExtJS
Catalyst-Controller-HTML-FormFu-ExtJS

any you'd recommend taking a look at?

thanks again

adam



I built it myself using Catalyst::View::JSON and TT. It's actually
pretty easy when you get the hang out it.



Hi Scott,

thank for your reply, in having a go at using Catalyst::View::JSON i  
keep running into the


... encountered object 'MyApp::Model::DB::Experiment=HASH(0xe8ac4c)',  
but neither allow_blessed nor convert_blessed settings ... 


error. I'm getting data from DBIC but can't figure out how to get that  
into Catalyst::View::JSON. The hello world example works fine, but  
when trying to adapt this i run into trouble


sub hello : Local {
  my($self, $c) = @_;
#  $c-stash-{message} = 'Hello World!';

  $c-stash-{books} = [$c-model('DB::Books')-all];  ### this  
doesn't work


  $c-forward('MyApp::View::JSON');
}

any pointers into the right syntax/approach here would be greatly  
appreciated. I presume i have to write some kind of JSON encoder for  
the data coming out of $c-model('DB::Books')-all?


thanks again for your help

adam

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Catalyst and ExtJS

2009-03-16 Thread Moritz Onken


Hi Scott,

thank for your reply, in having a go at using Catalyst::View::JSON i  
keep running into the


... encountered object  
'MyApp::Model::DB::Experiment=HASH(0xe8ac4c)', but neither  
allow_blessed nor convert_blessed settings ... 


error. I'm getting data from DBIC but can't figure out how to get  
that into Catalyst::View::JSON. The hello world example works  
fine, but when trying to adapt this i run into trouble


sub hello : Local {
 my($self, $c) = @_;
#  $c-stash-{message} = 'Hello World!';

 $c-stash-{books} = [$c-model('DB::Books')-all];  ### this  
doesn't work


 $c-forward('MyApp::View::JSON');
}

any pointers into the right syntax/approach here would be greatly  
appreciated. I presume i have to write some kind of JSON encoder for  
the data coming out of $c-model('DB::Books')-all?


thanks again for your help



Hi,


You can access the raw data through $row-{_column_data}. But this is  
not recommended because it doesn't call any inflators.


try

$c-stash-{books} = [map { $_-{_column_data} } $c- 
model('DB::Books')-all];




Moritz

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Catalyst and ExtJS

2009-03-16 Thread J. Shirley
On Mon, Mar 16, 2009 at 10:53 AM, Moritz Onken on...@houseofdesign.dewrote:


 Hi Scott,

 thank for your reply, in having a go at using Catalyst::View::JSON i keep
 running into the

 ... encountered object 'MyApp::Model::DB::Experiment=HASH(0xe8ac4c)', but
 neither allow_blessed nor convert_blessed settings ... 

 error. I'm getting data from DBIC but can't figure out how to get that
 into Catalyst::View::JSON. The hello world example works fine, but when
 trying to adapt this i run into trouble

 sub hello : Local {
 my($self, $c) = @_;
 #  $c-stash-{message} = 'Hello World!';

 $c-stash-{books} = [$c-model('DB::Books')-all];  ### this doesn't
 work

 $c-forward('MyApp::View::JSON');
 }

 any pointers into the right syntax/approach here would be greatly
 appreciated. I presume i have to write some kind of JSON encoder for the
 data coming out of $c-model('DB::Books')-all?

 thanks again for your help



 Hi,


 You can access the raw data through $row-{_column_data}. But this is not
 recommended because it doesn't call any inflators.

 try

  $c-stash-{books} = [map { $_-{_column_data} }
 $c-model('DB::Books')-all];




 Moritz



No, don't do that!

Use $row-get_columns which returns a hash of the column data!  Accessing
internal methods is bad, accessing internal hash keys is doubleplusungood.
If you find yourself doing that, go read some documentation.  If you haven't
figured it out without doing that, submit a patch for a proper method!

Here's the pod:
http://search.cpan.org/~ribasushi/DBIx-Class-0.08012/lib/DBIx/Class/Row.pm#get_columns

Also, you can use the HashRefInflator which works -fantastic- for JSON
views:

The code is very simple:

my $rs = $c-model('DB::Books');
$rs-resultclass('DBIx::Class::HashRefInflator');
$c-stash-{books} = [ $rs-all ];

You can read about that here:
http://search.cpan.org/~ash/DBIx-Class-0.08010/lib/DBIx/Class/ResultClass/HashRefInflator.pm

-Jay

-- 
J. Shirley :: jshir...@gmail.com :: Killing two stones with one bird...
http://www.toeat.com
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Catalyst and ExtJS

2009-03-16 Thread Adam Witney


No, don't do that!

Use $row-get_columns which returns a hash of the column data!   
Accessing internal methods is bad, accessing internal hash keys is  
doubleplusungood.  If you find yourself doing that, go read some  
documentation.  If you haven't figured it out without doing that,  
submit a patch for a proper method!


Here's the pod:
http://search.cpan.org/~ribasushi/DBIx-Class-0.08012/lib/DBIx/Class/Row.pm#get_columns

Also, you can use the HashRefInflator which works -fantastic- for  
JSON views:


The code is very simple:

my $rs = $c-model('DB::Books');
$rs-resultclass('DBIx::Class::HashRefInflator');
$c-stash-{books} = [ $rs-all ];

You can read about that here:
http://search.cpan.org/~ash/DBIx-Class-0.08010/lib/DBIx/Class/ResultClass/HashRefInflator.pm


excellent, thanks guys, with minor modifications both those approaches  
work:


$c-stash-{books} = [map { $_-get_columns } $c- 
model('DB::Books')-all];


OR:

my $rs = $c-model('DB::Books');
$rs-result_class('DBIx::Class::ResultClass::HashRefInflator');
$c-stash-{books} = [ $rs-all ];

thanks again for your help

adam



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


RE: [Catalyst] Catalyst and ExtJS

2009-03-16 Thread Scott Pham (scpham)


 -Original Message-
 From: Adam Witney [mailto:awit...@sgul.ac.uk]
 Sent: Monday, March 16, 2009 3:00 PM
 To: The elegant MVC web framework
 Subject: Re: [Catalyst] Catalyst and ExtJS
 
 
  No, don't do that!
 
  Use $row-get_columns which returns a hash of the column data!
  Accessing internal methods is bad, accessing internal hash keys is
  doubleplusungood.  If you find yourself doing that, go read some
  documentation.  If you haven't figured it out without doing that,
  submit a patch for a proper method!
 
  Here's the pod:
  http://search.cpan.org/~ribasushi/DBIx-Class-
 0.08012/lib/DBIx/Class/Row.pm#get_columns
 
  Also, you can use the HashRefInflator which works -fantastic- for
  JSON views:
 
  The code is very simple:
 
  my $rs = $c-model('DB::Books');
  $rs-resultclass('DBIx::Class::HashRefInflator');
  $c-stash-{books} = [ $rs-all ];
 
  You can read about that here:
  http://search.cpan.org/~ash/DBIx-Class-
 0.08010/lib/DBIx/Class/ResultClass/HashRefInflator.pm
 
 excellent, thanks guys, with minor modifications both those approaches
 work:
 
  $c-stash-{books} = [map { $_-get_columns } $c-
  model('DB::Books')-all];
 
 OR:
 
  my $rs = $c-model('DB::Books');
  $rs-result_class('DBIx::Class::ResultClass::HashRefInflator');
  $c-stash-{books} = [ $rs-all ];
 
 thanks again for your help
 
 adam

You only want to present the data you need to ExtJS, you were stuffing
the whole dbic resultset object into the JSON ;).



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Catalyst and ExtJS

2009-03-15 Thread Peter Edwards
 Adam Witney wrote on 3/14/09 9:36 AM:
  I was thinking about using Catalyst and ExtJS, does anyone have any
  experience or know if they will play nicely together? Doing some
  googling implies that this is not a popular combination due to the
  limited information


It's really pretty straightforward and I've written a number of commercial
apps using it.
ExtJS lets you set up data sources, you hook these up to Catalyst REST JSON
providers.
You can use HTML::FormFu or your own templates to build the forms.

I wrote a getting started Advent calendar entry:
http://www.catalystframework.org/calendar/2007/1

Its example app is in the Catalyst repo
$ svn co
http://dev.catalystframework.org/repos/Catalyst/trunk/examples/ExtJS

It is out of date (uses ExtJS 1.1) but should be enough to give you the
general idea.

Cheers,
Peter
http://perl.dragonstaff.co.uk
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


RE: [Catalyst] Catalyst and ExtJS

2009-03-14 Thread Scott Pham (scpham)
 -Original Message-
 From: Adam Witney [mailto:awit...@sgul.ac.uk]
 Sent: Saturday, March 14, 2009 10:36 AM
 To: The elegant MVC web framework
 Subject: [Catalyst] Catalyst and ExtJS
 
 
 Hi,
 
 I was thinking about using Catalyst and ExtJS, does anyone have any
 experience or know if they will play nicely together? Doing some
 googling implies that this is not a popular combination due to the
 limited information
 
 thanks for any help
 
 adam


Yes I currently have a couple of apps that use ExtJS + Catalyst, works
great for me!

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Catalyst and ExtJS

2009-03-14 Thread Adam Witney


On 14 Mar 2009, at 15:19, Scott Pham (scpham) wrote:


-Original Message-
From: Adam Witney [mailto:awit...@sgul.ac.uk]
Sent: Saturday, March 14, 2009 10:36 AM
To: The elegant MVC web framework
Subject: [Catalyst] Catalyst and ExtJS


Hi,

I was thinking about using Catalyst and ExtJS, does anyone have any
experience or know if they will play nicely together? Doing some
googling implies that this is not a popular combination due to the
limited information

thanks for any help

adam



Yes I currently have a couple of apps that use ExtJS + Catalyst, works
great for me!


Hi Scott,

thanks for the info, do you use any particular module or have you  
built it yourself? I have found so far:


HTML::FormFu::ExtJS
Catalyst-Controller-HTML-FormFu-ExtJS

any you'd recommend taking a look at?

thanks again

adam

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Catalyst and ExtJS

2009-03-14 Thread Moritz Onken




Hi Scott,

thanks for the info, do you use any particular module or have you  
built it yourself? I have found so far:


HTML::FormFu::ExtJS
Catalyst-Controller-HTML-FormFu-ExtJS

any you'd recommend taking a look at?

thanks again

adam



Hi Adam,

I'm the author of the above mentioned modules.  
C::C::HTML::FormFu::ExtJS was just a proof of concept. You can use it  
though. It's simply a subclass of C::C::HTML::FormFu and replaces new  
HTML::FormFu with new HTML::FormFu::ExtJS.


HTML::FormFu::ExtJS is actively developed. The version on CPAN is not  
very recent because I'm waiting for the maintainer of HTML::FormFu to  
release a new version. The most recent version is at http://html-formfu.googlecode.com/svn/trunk/HTML-FormFu-ExtJS/ 
 (requires the svn version of HTML::FromFu).


Try it, look at the tests, see me at IRC #formfu or email me. I'd be  
glad if someone is using this module so we can find bugs and add  
features to it.


moritz

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Catalyst and ExtJS

2009-03-14 Thread Peter Karman
Adam Witney wrote on 3/14/09 9:36 AM:
 
 Hi,
 
 I was thinking about using Catalyst and ExtJS, does anyone have any
 experience or know if they will play nicely together? Doing some
 googling implies that this is not a popular combination due to the
 limited information

CatalystX::CRUD::YUI uses the ExtJS LiveGrid feature.

IME, picking a JS lib is orthogonal to the form manager (if you use one) or
Catalyst classes you pick. They can make some things easier in the simple cases,
but in the more complex cases I end up handcrafting the forms and JS myself.

-- 
Peter Karman  .  http://peknet.com/  .  pe...@peknet.com

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/