[Jifty-commit] r923 - in jifty/trunk: lib/Jifty/Action
lib/Jifty/Web/Form share/web/static/js
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Mon Apr 24 21:20:38 EDT 2006
Author: alexmv
Date: Mon Apr 24 21:20:37 2006
New Revision: 923
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Action/Autocomplete.pm
jifty/trunk/lib/Jifty/Action/Record.pm
jifty/trunk/lib/Jifty/Web/Form/Field.pm
jifty/trunk/share/web/static/js/jifty.js
Log:
r12560 at zoq-fot-pik: chmrr | 2006-04-24 21:20:19 -0400
* Autocomplete serializes the whole action
* autocomplete_* on models get passed all of the columns
Modified: jifty/trunk/lib/Jifty/Action/Autocomplete.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Autocomplete.pm (original)
+++ jifty/trunk/lib/Jifty/Action/Autocomplete.pm Mon Apr 24 21:20:37 2006
@@ -43,7 +43,7 @@
sub arguments {
{
- action => {},
+ moniker => {},
argument => {}
}
}
@@ -59,14 +59,13 @@
sub take_action {
my $self = shift;
- my $moniker = $self->argument_value('action');
- # XXX TODO: we should just be getting the arg name, not the field name somehow
- my (undef, $arg_name, undef) = Jifty->web->request->parse_form_field_name($self->argument_value('argument'));
+ my $moniker = $self->argument_value('moniker');
+ my $argument = $self->argument_value('argument');
my $request_action = Jifty->web->request->action($moniker);
my $action = Jifty->web->new_action_from_request($request_action);
- my @completions = $action->_autocomplete_argument($arg_name);
+ my @completions = $action->_autocomplete_argument($argument);
$self->result->content->{completions} = \@completions;
return 1;
Modified: jifty/trunk/lib/Jifty/Action/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record.pm (original)
+++ jifty/trunk/lib/Jifty/Action/Record.pm Mon Apr 24 21:20:37 2006
@@ -204,7 +204,9 @@
if ( $self->record->can($autocomplete_method) ) {
$info->{'autocompleter'} ||= sub {
my ( $self, $value ) = @_;
- return $self->record->$autocomplete_method($value);
+ my %columns;
+ $columns{$_} = $self->argument_value($_) for grep {$_ ne $field} $self->possible_fields;
+ return $self->record->$autocomplete_method($value, %columns);
};
}
Modified: jifty/trunk/lib/Jifty/Web/Form/Field.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Field.pm (original)
+++ jifty/trunk/lib/Jifty/Web/Form/Field.pm Mon Apr 24 21:20:37 2006
@@ -465,7 +465,7 @@
Jifty->web->out(
qq!<div class="autocomplete" id="@{[$self->element_id]}-autocomplete" style="display:none;border:1px solid black;background-color:white;"></div>\n
<script type="text/javascript">
- new Jifty.Autocompleter('@{[$self->element_id]}', '@{[$self->element_id]}-autocomplete', '/__jifty/autocomplete.xml')
+ new Jifty.Autocompleter('@{[$self->element_id]}','@{[$self->element_id]}-autocomplete')
</script>
!
);
Modified: jifty/trunk/share/web/static/js/jifty.js
==============================================================================
--- jifty/trunk/share/web/static/js/jifty.js (original)
+++ jifty/trunk/share/web/static/js/jifty.js Mon Apr 24 21:20:37 2006
@@ -39,6 +39,15 @@
return elements;
},
+ getField: function(name) {
+ var elements = this.fields();
+ for (var i = 0; i < elements.length; i++) {
+ if (Form.Element.getField(elements[i]) == name)
+ return elements[i];
+ }
+ return null;
+ },
+
// Serialize and return all fields needed for this action
serialize: function() {
var fields = this.fields();
@@ -568,40 +577,36 @@
Jifty.Autocompleter = Class.create();
Object.extend(Object.extend(Jifty.Autocompleter.prototype, Ajax.Autocompleter.prototype), {
- initialize: function(element, update, url, options) {
- this.baseInitialize(element, update, options);
- this.options.asynchronous = true;
- this.options.method = 'get';
- this.options.onComplete = this.onComplete.bind(this);
- this.options.defaultParams = this.options.parameters || null;
- this.url = url;
+ initialize: function(field, div) {
+ this.field = $(field);
+ this.action = Form.Element.getAction(this.field);
+ this.url = '/__jifty/autocomplete.xml';
+
+
+ this.baseInitialize(this.field, $(div));
},
getUpdatedChoices: function() {
- entry = encodeURIComponent("J:A-autocomplete")
- + "=" +encodeURIComponent("Jifty::Action::Autocomplete");
-
- entry += '&' + encodeURIComponent("J:A:F-argument-autocomplete")
- + "=" + encodeURIComponent(this.options.paramName);
-
- entry += '&' + encodeURIComponent("J:A:F-action-autocomplete")
- + "=" + encodeURIComponent(
- Form.Element.getMoniker(this.element)
- );
-
- entry += '&'+ encodeURIComponent("J:ACTIONS") + '=' + encodeURIComponent("autocomplete");
-
-
- this.options.parameters = this.options.callback ?
- this.options.callback(this.element, entry) : entry;
-
- if(this.options.defaultParams)
- this.options.parameters += '&' + this.options.defaultParams;
-
- var action = Form.Element.getAction(this.element);
- this.options.parameters += '&' + action.serialize();
+ var request = { path: this.url, actions: {} };
- new Ajax.Request(this.url, this.options);
+ var a = {};
+ a['moniker'] = 'autocomplete';
+ a['class'] = 'Jifty::Action::Autocomplete';
+ a['fields'] = {};
+ a['fields']['moniker'] = this.action.moniker;
+ a['fields']['argument'] = Form.Element.getField(this.field);
+ request['actions']['autocomplete'] = a;
+ request['actions'][this.action.moniker] = this.action.data_structure();
+ request['actions'][this.action.moniker]['active'] = 0;
+
+ var options = { postBody: JSON.stringify(request),
+ onComplete: this.onComplete.bind(this),
+ requestHeaders: ['Content-Type', 'text/x-json']
+ };
+
+ new Ajax.Request(this.url,
+ options
+ );
}
More information about the Jifty-commit
mailing list