Subject: | Representing database enums using a drop-down box |
I was missing a comfortable way to enter values into an enum column
within my DBIx/MySQL database, so I added some code to make it work for
me, at least.
I attached a small patch that adds support for it.
I provide an array-ref called list (which contains the enum's possible
values) within the extra-attribute of the column. I think this is what
the automatic scheme generation tool was doing some time ago.
The changes to the Model/Metadata/DBIC.pm file include the
extra-attribute within the column description available to the View and
change the extjs_type to 'combo' for an enum column. The changes to the
template consider the new extjs_type case. You probably want to take a
slightly different and cleaner approach, if you would like to implement
this feature yourself. In particular, AutoCRUD will still report that
everything is okay even if the user provided an invalid string in an
enum field.
By the way, AutoCRUD is written in a great and comprehendible way! Keep
up the great work!
Subject: | enum_support.patch |
Plugin/AutoCRUD/Model/Metadata/DBIC.pm
54a55,56
> $xtype_for{'enum'} = 'combo';
>
279a282,284
>
> $ti->{cols}->{$col}->{extra} = $info->{extra}
> if (exists $info->{extra});
Plugin/AutoCRUD/templates/full-fat/javascript/update/tabs.tt
104a105,115
> [% CASE 'combo' %]
> ,store: new Ext.data.SimpleStore({
> fields: [ '[% field %]' ],
> data: [
> [% FOREACH option IN info.cols.$field.extra.list %]
> ['[% option %]'],
> [% END %]
> ]})
> ,displayField: '[% field %]'
> ,mode: 'local'
> ,triggerAction: 'all'