[Jifty-commit] r2746 - in jifty: .
branches/virtual-models/lib/Jifty/Model
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Jan 31 17:34:16 EST 2007
Author: sterling
Date: Wed Jan 31 17:34:16 2007
New Revision: 2746
Modified:
jifty/ (props changed)
jifty/branches/virtual-models/lib/Jifty/Model/ModelClassColumn.pm
jifty/branches/virtual-models/plugins/ModelBuilder/share/web/templates/__jifty/builder/model/fragments/column/list
jifty/branches/virtual-models/plugins/ModelBuilder/share/web/templates/__jifty/builder/model/fragments/column/new
jifty/branches/virtual-models/plugins/ModelBuilder/share/web/templates/__jifty/builder/model/fragments/column/update
Log:
Added an autocompleter for storage_type and render_as.
Modified: jifty/branches/virtual-models/lib/Jifty/Model/ModelClassColumn.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Model/ModelClassColumn.pm (original)
+++ jifty/branches/virtual-models/lib/Jifty/Model/ModelClassColumn.pm Wed Jan 31 17:34:16 2007
@@ -22,6 +22,7 @@
use Jifty::DBI::Schema;
use Jifty::Model::ModelClass;
+use Module::Pluggable search_path => [ 'Jifty::Web::Form::Field' ];
use Scalar::Defer;
use Jifty::Record schema {
@@ -48,7 +49,8 @@
column storage_type =>
type is 'text',
label is 'Storage type',
- hints is 'The kind of data that is being stored. Use "text" if you are not sure.';
+ hints is 'The kind of data that is being stored. Use "text" if you are not sure.',
+ is autocompleted;
column max_length =>
type is 'int',
@@ -93,7 +95,8 @@
column render_as =>
type is 'text',
label is 'Render as',
- hints is 'The kind of widget to use to edit the information.';
+ hints is 'The kind of widget to use to edit the information.',
+ is autocompleted;
# FIXME should actually be a reference to a list
column filters =>
@@ -176,4 +179,51 @@
sub since {'0.70127'}
+=head2 autocomplete_storage_type
+
+This attempts to discover the available column types from the DBI handle using C<type_info>.
+
+=cut
+
+# XXX Should this information be cached?
+sub autocomplete_storage_type {
+ my ($self, $string) = @_;
+
+ # Generic defaults
+ # TODO These should be loaded from somewhere or a constant somewhere else?
+ # TODO Add more default choices.
+ my @choices = qw/
+ text
+ int
+ timestamp
+ /;
+
+ if (Jifty->handle && Jifty->handle->dbh) {
+ my @type_info = Jifty->handle->dbh->type_info;
+ if (@type_info) {
+ @choices = map { $_->{TYPE_NAME} } @type_info;
+ }
+ }
+
+ my $qstring = $string ? quotemeta $string : '.*';
+ my @matches = grep /$qstring/, @choices;
+
+ return @matches;
+}
+
+=head2 autocomplete_render_as
+
+Searches the list of Jifty form widgets to suggest options.
+
+=cut
+
+sub autocomplete_render_as {
+ my ($self, $string) = @_;
+
+ my $qstring = $string ? quotemeta $string : '.*';
+ my @widgets = grep /$qstring/, map { /(\w+)$/ } $self->plugins;
+
+ return @widgets;
+}
+
1;
Modified: jifty/branches/virtual-models/plugins/ModelBuilder/share/web/templates/__jifty/builder/model/fragments/column/list
==============================================================================
--- jifty/branches/virtual-models/plugins/ModelBuilder/share/web/templates/__jifty/builder/model/fragments/column/list (original)
+++ jifty/branches/virtual-models/plugins/ModelBuilder/share/web/templates/__jifty/builder/model/fragments/column/list Wed Jan 31 17:34:16 2007
@@ -78,6 +78,7 @@
$per_page => 25
$collapsed => 1
$new_slot => 1
+$region
</%args>
<%init>
my $model_columns = Jifty::Model::ModelClassColumnCollection->new;
Modified: jifty/branches/virtual-models/plugins/ModelBuilder/share/web/templates/__jifty/builder/model/fragments/column/new
==============================================================================
--- jifty/branches/virtual-models/plugins/ModelBuilder/share/web/templates/__jifty/builder/model/fragments/column/new (original)
+++ jifty/branches/virtual-models/plugins/ModelBuilder/share/web/templates/__jifty/builder/model/fragments/column/new Wed Jan 31 17:34:16 2007
@@ -7,7 +7,7 @@
<% $create->form_field('name') %>
<% $create->form_field('label') %>
-<% $create->form_field('storage_type') %>
+<% $create->form_field('storage_type', mandatory => 1) %>
<% $create->form_field('default_value') %>
<% $create->form_field('mandatory') %>
<% $create->form_field('distinct_value') %>
Modified: jifty/branches/virtual-models/plugins/ModelBuilder/share/web/templates/__jifty/builder/model/fragments/column/update
==============================================================================
--- jifty/branches/virtual-models/plugins/ModelBuilder/share/web/templates/__jifty/builder/model/fragments/column/update (original)
+++ jifty/branches/virtual-models/plugins/ModelBuilder/share/web/templates/__jifty/builder/model/fragments/column/update Wed Jan 31 17:34:16 2007
@@ -23,7 +23,7 @@
<% $update->form_value('name') %>
<% $update->form_field('label') %>
-<% $update->form_field('storage_type') %>
+<% $update->form_field('storage_type', mandatory => 1) %>
<% $update->form_field('default_value') %>
<% $update->form_field('mandatory') %>
<% $update->form_field('distinct_value') %>
More information about the Jifty-commit
mailing list