$(document).ready(function() { setup_data(<%= hier %>); }); var is_hier = false; function setup_data(hier) { is_hier = hier; var data = "<%= data %>"; var lines = data.split('|'); var op = "" for (i=0; i"; var line = lines[i]; var items = line.split('~'); op += " Remove"; if (hier) { op += ""; } op += ""; } op += "
  • "; op += " "; op += "
  • "; $('#data').append(op); } function added_parent(id) { var op = ''; var new_id = id + 1; op += "
  • "; $('#parent_' + id).attr('onkeyup', ''); $('#parent_' + id).parent().append(op); if (is_hier) { $('#childrenof_' + id).append("
  • "); } show_warning(); } function added_child(parent_id, id) { var op = ''; var new_id = id + 1; op += "
  • "; $('#childrenof_' + parent_id).append(op); $('#childof_' + parent_id + "_" + id).attr('onkeyup', '').after(" Remove"); } function remove_parent(id) { $('#line_' + id).remove(); show_warning(); } function remove_child(parent_id, id) { $('#childof_' + parent_id + "_" + id).parent().remove(); show_warning(); } function complete() { var op = ''; var last_parent = null; $('#data li input').each(function(i, e) { var id = $(e).attr('id'); var splits = id.split('_'); var parent_id = splits[1]; var v = $(e).val(); if (v!=='undefined' && v!=='') { if (last_parent!==parent_id) { if (op!=='') { op += "|"; } last_parent = parent_id; op += v; } else { op += "~"; op += v; } } }); $('#form_field_type_options').val(op); $("#options_edit form").submit(); } function show_warning() { $(".warning").slideDown(); }