From: Teemu A. <te...@io...> - 2004-01-12 03:18:08
|
Hello, for a while we have been developing a nice object oriented toolkit for making application development on OpenInteract easy. The main idea is that when creating applications, you don't have to creaty _any_ templates for your project. Dicole core just provides generic templates for different content and an object oriented interface to hide all dirty template parameter details. That way you may build sites completely out of widgets. Site layout is controlled completely through CSS and the page sources are based on XHTML. I have extended the toolkit with a system called Dicole::Generictool. Most applications that work with some sort of data objects usually are satisfactory when they provide at least functionality to add, list, remove, show and edit objects. Generictool addresses just those, adds a couple of nice features and makes everything easy to extend. For example, here is sample code of my current "list" handler method that features browsing, sorting, searching and listing of objects and some fields: sub list { my ( $class, $p ) = @_; my ( $R, $tool, $gentool ) = $class->_common_init( params => $p ); $tool->Path->add( name => 'List users' ); # Modify tool object to contain our form in a single legend box $tool->Container->box_at( 0, 0 )->set_name( 'List of users' ); $tool->Container->box_at( 0, 0 )->add_content( $gentool->get_list( 'list' ) ); return $R->template->handler( $tool->get_template_handler_structure ); } Not too many lines of code =). _common_init basically only defines the object fields with some added meta-data. Generictool also takes care of input validation. Here is my add method, for example: sub add { my ( $class, $p ) = @_; my ( $R, $tool, $gentool ) = $class->_common_init( params => $p ); $tool->Path->add( name => 'Add new user' ); if ( $R->apache->param( 'save' ) ) { ( $p->{return_code}, $p->{return} ) = $gentool->validate_input( $gentool->visible_fields('add'), { clear_output => 1 } ); if ( $p->{return_code} ) { $p->{return} = "User has been saved."; } else { $p->{return} = sprintf( "Failed adding user: %s", $p->{return} ); } $tool->set_return( $p->{return_code}, $p->{return} ); } # Modify tool object to contain our form in a single legend box $tool->Container->box_at( 0, 0 )->set_name( 'New user details' ); $tool->Container->box_at( 0, 0 )->add_content( $gentool->get_add( 'add' ) ); return $R->template->handler( $tool->get_template_handler_structure ); } No single template needed for that handler, either. Dicole is going to be the total rewrite (sequel) of MimerDesk (www.mimerdesk.org), a groupware I created during the years. This time I'm going to make the sources a little bit more maintainable. I try to keep the documentation if the source code complete so using it shouldn't be a problem in anyone is interested to try it so early in the development. Links: The current unstable CVS is browsable here: http://www.mimerdesk.org/cgi-bin/cvsweb.cgi/dicole/ Dicole documentation (draft, partly incomplete): http://inf.dicole.fi/dicole_docs/ Generictool documentation: http://inf.dicole.fi/dicole_docs/Dicole/Generictool.html Example handler code: http://www.mimerdesk.org/cgi-bin/cvsweb.cgi/dicole/pkg/user_manager/OpenInteract/Handler/UserManager.pm?rev=1.50&content-type=text/x-cvsweb-markup Example application for trying the results out (Mozilla recommended): http://dev1.dicole.fi/Usermanager/ Latest CVS checkout: cvs -d :pserver:ano...@mi...:/opt/cvs login Login with blank password (Just press enter). cvs -d :pserver:ano...@mi...:/opt/cvs checkout dicole -- Sincerely, Teemu Arina mimerdesk.org |