o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1386700262.3127906: @value"3 {I" class:EFI"ProcessedAsset;FI"logical_path;FI"prototype_nested_form.js;TI" pathname;FI":$root/app/assets/javascripts/prototype_nested_form.js;TI"content_type;FI"application/javascript;FI" mtime;FI"2013-12-02T11:00:44-05:00;FI" length;Fic I" digest;F"%21f07dea88439370bdee97c025c04a22I" source;FI"c document.observe('click', function(e, el) { if (el = e.findElement('form a.add_nested_fields')) { // 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 // Make the context correct by replacing with the generated ID // of each of the parent objects var context = (el.getOffsetParent('.fields').firstDescendant().readAttribute('name') || '').replace(/\[[a-z_]+\]$/, ''); // If the parent has no inputs we need to strip off the last pair var current = content.match(new RegExp('\\[([a-z_]+)\\]\\[new_' + assoc + '\\]')); if (current) { context = context.replace(new RegExp('\\[' + current[1] + '\\]\\[(new_)?\\d+\\]$'), ''); } // context will be something like this for a brand new form: // project[tasks_attributes][1255929127459][assignments_attributes][1255929128105] // or for an edit form: // project[tasks_attributes][0][assignments_attributes][1] if(context) { var parent_names = context.match(/[a-z_]+_attributes(?=\]\[(new_)?\d+\])/g) || []; var parent_ids = context.match(/[0-9]+/g) || []; for(i = 0; i < parent_names.length; i++) { if(parent_ids[i]) { content = content.replace( new RegExp('(_' + parent_names[i] + ')_.+?_', 'g'), '$1_' + parent_ids[i] + '_'); content = content.replace( new RegExp('(\\[' + parent_names[i] + '\\])\\[.+?\\]', 'g'), '$1[' + parent_ids[i] + ']'); } } } // Make a unique ID for the new child var regexp = new RegExp('new_' + assoc, 'g'); var new_id = new Date().getTime(); content = content.replace(regexp, new_id); var field; if (target) { field = $$(target)[0].insert(content); } else { field = el.insert({ before: content }); } field.fire('nested:fieldAdded', {field: field}); field.fire('nested:fieldAdded:' + assoc, {field: field}); return false; } }); document.observe('click', function(e, el) { if (el = e.findElement('form a.remove_nested_fields')) { var hidden_field = el.previous(0), assoc = el.readAttribute('data-association'); // Name of child to be removed if(hidden_field) { hidden_field.value = '1'; } var field = el.up('.fields').hide(); field.fire('nested:fieldRemoved', {field: field}); field.fire('nested:fieldRemoved:' + assoc, {field: field}); return false; } }); ;FI"dependency_digest;F"%b199fccde31f6c4d1c596410f2d6a749I"required_paths;F[I":$root/app/assets/javascripts/prototype_nested_form.js;TI"dependency_paths;F[{I" path;FI":$root/app/assets/javascripts/prototype_nested_form.js;TI" mtime;FI"2013-12-02T11:00:44-05:00;FI" digest;F"%21f07dea88439370bdee97c025c04a22I" _version;F"%2d1b8610f49bfd9877b6ca91714f2834