Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Move blueprints from DOM to memory - gives much better performance #338

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/nested_form/builder_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ def link_to_add(*args, &block)

@fields ||= {}
@template.after_nested_form(fields_blueprint_id) do
blueprint = {:id => fields_blueprint_id, :style => 'display: none'}
block, options = @fields[fields_blueprint_id].values_at(:block, :options)
options[:child_index] = "new_#{association}"
blueprint[:"data-blueprint"] = fields_for(association, model_object, options, &block).to_str
@template.content_tag(:div, nil, blueprint)
blueprint_string_code = URI.encode(fields_for(association, model_object, options, &block).to_str)
blueprint_code = <<JS
if (typeof nestedFormBlueprints === 'undefined')
window.nestedFormBlueprints = {};
nestedFormBlueprints["#{fields_blueprint_id}"] = "#{blueprint_string_code}";
JS
@template.content_tag(:script, blueprint_code.html_safe, {:type => 'text/javascript'})
end
@template.link_to(*args, &block)
end
Expand Down
3 changes: 1 addition & 2 deletions vendor/assets/javascripts/jquery_nested_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
// Setup
var link = e.currentTarget;
var assoc = $(link).data('association'); // Name of child
var blueprint = $('#' + $(link).data('blueprint-id'));
var content = blueprint.data('blueprint'); // Fields template
var content = decodeURIComponent(nestedFormBlueprints[$(link).data('blueprint-id')]); // Fields template

// Make the context correct by replacing <parents> with the generated ID
// of each of the parent objects
Expand Down
3 changes: 1 addition & 2 deletions vendor/assets/javascripts/prototype_nested_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ document.observe('click', function(e, el) {
// Setup
var assoc = el.readAttribute('data-association'); // Name of child
var target = el.readAttribute('data-target');
var blueprint = $(el.readAttribute('data-blueprint-id'));
var content = blueprint.readAttribute('data-blueprint'); // Fields template
var content = decodeURIComponent(nestedFormBlueprints[$(el.readAttribute('data-blueprint-id'))]); // Fields template

// Make the context correct by replacing <parents> with the generated ID
// of each of the parent objects
Expand Down