Skip to content

Commit

Permalink
adjust the defaults for ajax rendering to match hobo-jquery so we don…
Browse files Browse the repository at this point in the history
…'t have to send as many options over the wire for each request.
  • Loading branch information
bryanlarsen committed Aug 9, 2012
1 parent 167f54f commit 4eb0714
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion hobo/lib/hobo/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def ajax_update_response(render_specs, results={}, options={})

headers["Content-Type"] = options['content_type'] if options['content_type']

page = options[:preamble] || "var _update = typeof Hobo == 'undefined' ? Element.update : Hobo.updateElement;\n"
page = options[:preamble] || ""
for spec in render_specs
function = spec[:function] || "hjq.ajax.update"
dom_id = spec[:id]
Expand All @@ -97,6 +97,7 @@ def ajax_update_response(render_specs, results={}, options={})
end
end
if renderer
options[:contexts_function] ||= "hjq.ajax.updatePartContexts" unless options[:no_contexts_function]
if options[:contexts_function]
storage = renderer.part_contexts_storage_uncoded
page << "#{options[:contexts_function]}(#{storage.to_json});\n"
Expand Down
13 changes: 9 additions & 4 deletions hobo_jquery/vendor/assets/javascripts/hobo-jquery/hjq.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,13 @@

result.context = this;
result.type = o.type || 'GET';
result.data = {"render_options[preamble]": o.preamble || '',
"render_options[contexts_function]": 'hjq.ajax.updatePartContexts'
};
result.data = {};
/* These are now the defaults, so we don't need to send
them over the wire.
result.data = {"render_options[preamble]": o.preamble || '',
"render_options[contexts_function]": 'hjq.ajax.updatePartContexts'
}; */
if(o.preamble) result.data["render_options[preamble]"] = o.postamble;
if(o.postamble) result.data["render_options[postamble]"] = o.postamble;
if(o.content_type) result.data["render_options[content_type]"] = o.content_type;
if(o.attrs.errors_ok) result.data["render_options[errors_ok]"] = 1;
Expand All @@ -258,7 +262,8 @@
if(part_data) $("#"+ids[i]).data('hjq-ajax', part_data);
result.data["render["+i+"][part_context]"] = page_data.hobo_parts[ids[i]];
result.data["render["+i+"][id]"] = ids[i];
result.data["render["+i+"][function]"] = o['function'] || 'hjq.ajax.update';
// default for render[i][function] is hjq.ajax.update
if(o.function) result.data["render["+i+"][function]"] = o['function'];
}

return result;
Expand Down

0 comments on commit 4eb0714

Please sign in to comment.