[html-formfu] Re: Multiple inheritence with FormFu Catalyst Controllers

Mario Minati mario.minati at googlemail.com
Sun Apr 5 22:40:32 GMT 2009


Hello Moritz,

Am Sonntag 05 April 2009 22:36:37 schrieb Moritz Onken:
> Sounds reasonable!
>
> I uploaded the code to
> https://html-formfu.googlecode.com/svn/trunk/CatalystX-Controller-ExtJS/ .

Thanks a lot.

> You can patch it there.

I'll do so tomorrow. 
I found some more bugs which I corrected in the code you posted on the list.

> I was thinking about writing a custom serializer which "serializes" to
> a extjs form or an extjs grid resp. What do you think?
> The form could have buttons for create, delete and update.

Currently I'm useing a quite complex logic on the ExtJS side, which is 
inspired by tine  (tine20.org). Forms can be shown in separate browser popup 
windows or in ExtJS Windows.

I'm planning also the use of a specific store, that tries to hold all shown 
data in sync, when the same data is shown on multiple tabs. Therefore I'm 
integrating Saki's BindManager. And as last step I want to add support for 
the timeline in forms to provide some undo functionallity, when filling 
forms.

With all that in mind I rather lean on the TT method for now, as there is 
quite a bit javascript around in every form.
Later on it would be a good idea to move all that into a custom ExtJS class. 
Then I could make more use of a custom serializer.


My inherited ExtJS controller looks like this at the moment:

sub load_form : Chained('/') NSFormPathPart CaptureArgs(0) {
    my ( $self, $c ) = @_;

    # Check form existence
    $c->log->debug( "Loading form config from '" . $self->base_file . "'." )
        if ($c->debug);
    croak $self->base_file." cannot be found"
        unless (-e $self->base_file);

    # Get unique form name
    $c->stash->{form_name} = $self->_build_form_name;

    # Create form and load config
    my $form = $self->get_form( $c );
    $form->load_config_file( $self->base_file );

    # Build action from current path
    my $action = $self->action_namespace;
    $form->action( "/".$action );

    # Process empty form
    # NOTE:
    # the form's query method is not populated with the Catalyst request
    # object, which is ok for us as we don't take care of the request object
    $form->process;

    # Store form on stash
    $c->stash->{form} = $form;
}

sub edit_record :Chained('load_form') PathPart() Args(0) 
ActionClass('RenderView') {
    my ( $self, $c ) = @_;

    # Prepare template
    $c->stash->{template} = 'ext/forms/edit_record.tt2.js';

    # The form will be rendered while processing the template
    return;
}

sub _parse_NSFormPathPart_attr {
    my ( $self, $c ) = @_;

    # Split path and add form path
    my @path = split( /\//, $self->action_namespace );
    push @path, 'form';

    return ( PathPart => join('/', @path) );
}

sub _build_form_name {
    my ( $self, $c ) = @_;

    my @parts = split (/::/, ref $self);
    my $name = join ('', @parts[2 .. $#parts]);

    return $name;
}

The TT processing is quite slow, but for now peak performance is not the 
design goal.


Greets,

Mario Minati
 
>
>
>
> moritz
>
> Am 05.04.2009 um 21:57 schrieb Mario Minati:
> > Hello Moritz,
> >
> > the end method has a problem.
> > If it is a file upload it overwrites the output no matter what.
> > Usually
> > Serialize only writes output/body if it has no length.
> >
> > Would you mind if we use the following in line 55:
> >
> >    if ( $self->is_extjs_upload($c) and not length( $c->response-
> >
> > >body )) {
> >
> > I need this for my custom extension which needs a TT renderer in a
> > inherited
> > class of CatalystX::Controller::ExtJS::REST.
> >
> >
> > Greets,
> >
> > Mario Minati
> >
> > ----------  Weitergeleitete Nachricht  ----------
> >
> > Betreff: Re: [html-formfu] Re: Multiple inheritence with FormFu
> > Catalyst
> > Controllers
> > Datum: Samstag 04 April 2009
> > Von: Mario Minati <mario.minati at googlemail.com>
> > An: "HTML Form Creation, Rendering and Validation Framework"
> > <html-formfu at lists.scsys.co.uk>
> >
> > Hi Moritz,
> >
> > I was also on the go since thursday, so not much time yet.
> >
> > Am Mittwoch 01 April 2009 07:43:08 schrieb Moritz Onken:
> >> Am 01.04.2009 um 00:50 schrieb Mario Minati:
> >>> Hi Moritz,
> >>>
> >>> I like your Controller very much.
> >>>
> >>> Just some questions:
> >>>
> >>> Do you know if it can handle uploads with the Ext ux SwfUpload?
> >>> Probably no as the code of handle_uploads suggests.
> >>
> >> I have no Idea how SwfUpload works. AFAIK it allows to upload
> >> multiple files. Does it submit the form data as well? If not,
> >> this uploading thing should be an extra controller.
> >>
> >> As I did with ImageChooser I would suggest
> >> CatalystX::Controller::ExtJS::SwfUpload
> >
> > Forget about SwfUpload, I found out that it has unsolved problems
> > with firefox
> > on linux, so not a way I will follow any longer. There are other
> > Upload
> > controllers, which can upload files via a POST request, but not
> > integrated
> > with a more complex form.
> >
> > I'll look at this later on, may be extending one of those solutions.
> >
> >>> Line 134 is:
> >>>      $object = $object->$self->config->{default_rs_method};
> >>> Is that correct? It looks a bit to perlish, but I'm not sure.
> >>
> >> Yes, that line is totally wrong, shold look like:
> >>
> >>        my $rs = $self->config->{default_rs_method}
> >>        $object = $object->$rs;
> >>
> >>> How do you handle the usual controller logic, do you put it into the
> >>> model and
> >>> let the update die on problems or do you overwrite the PUT/PUSH
> >>> methods?
> >>
> >> What kind of logic are we talking about? I put A LOT of logic in the
> >> model.
> >> This helps me with testing and I have currently a daemon process who
> >> needs
> >> to access the model. So I have everything there. Most of the logic is
> >> handled by formfu.
> >
> > Model, ok.
> >
> >>> Do you plan to put that module into the formfu repository?
> >>
> >> Yes I do. Just wanted to write some more documentation and ask Carl
> >> if
> >> I can
> >> upload it there. I'm off until sunday and don't have internet access.
> >> But here is the latest and greatest latest version of this
> >> controller.
> >> I fixed the bug you mentioned and dropped the requirement for so many
> >> files.
> >> If one of the put/get/post/list files cannot be found it falls back
> >> to the base file root/forms/???.yml
> >>
> >> You are welcome to patch and write on. Or even upload it to the
> >> formfu
> >> repo. I already have my bags packed and will leave in a few minutes.
> >
> > As you changed the code, you better put the latest code into the
> > repo ;-)
> >
> >> One more thing, there are no tests yet. The module lives currently
> >> in my
> >> app's lib directory. So we need a module::install environment or
> >> something.
> >
> > I'm willing to help with tests, but am not (yet) familiar with that
> > module::install environment, so this may you can take care of that.
> >
> >> See you next monday!
> >
> > Have a nice weekend,
> >
> > Mario Minati
> >
> >> Am 01.04.2009 um 00:50 schrieb Mario Minati:
> >>> Hi Moritz,
> >>>
> >>> I like your Controller very much.
> >>>
> >>> Just some questions:
> >>>
> >>> Do you know if it can handle uploads with the Ext ux SwfUpload?
> >>> Probably no as the code of handle_uploads suggests.
> >>>
> >>> Line 134 is:
> >>>       $object = $object->$self->config->{default_rs_method};
> >>> Is that correct? It looks a bit to perlish, but I'm not sure.
> >>>
> >>> How do you handle the usual controller logic, do you put it into the
> >>> model and
> >>> let the update die on problems or do you overwrite the PUT/PUSH
> >>> methods?
> >>>
> >>> Do you plan to put that module into the formfu repository?
> >>>
> >>>
> >>> Greets,
> >>>
> >>> Mario Minati
> >>>
> >>> Am Dienstag 31 März 2009 13:13:09 schrieb Moritz Onken:
> >>>> Hi Mario,
> >>>>
> >>>> I wrote a Catalyst controller which might be worth looking at for
> >>>> you.
> >>>>
> >>>> It handles all kind of REST requests using formfu config files. For
> >>>> each kind of request there is an extra file.
> >>>>
> >>>> I added a few bits of documentation to it. It's currently in
> >>>> development for a new project I'm working on.
> >>>>
> >>>> My Controllers look currently something like this:
> >>>>
> >>>> package MyApp::Controller::User;
> >>>> use strict;
> >>>> use warnings;
> >>>>
> >>>> use base 'CatalystX::Controller::ExtJS::REST';
> >>>>
> >>>>
> >>>> 1;
> >>>>
> >>>>
> >>>> This will create two chained actions: /user and /users, where you
> >>>> can
> >>>> post,put, delete and get whatever you want.
> >>>>
> >>>> You can read the documentation I wrote and try it.
> >>>
> >>> _______________________________________________
> >>> HTML-FormFu mailing list
> >>> HTML-FormFu at lists.scsys.co.uk
> >>> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
> >>
> >> _______________________________________________
> >> HTML-FormFu mailing list
> >> HTML-FormFu at lists.scsys.co.uk
> >> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
> >
> > -------------------------------------------------------
> >
> > _______________________________________________
> > HTML-FormFu mailing list
> > HTML-FormFu at lists.scsys.co.uk
> > http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu





More information about the HTML-FormFu mailing list