Sha256: f3a61ca600fe7ac02af6616200c25a738f5ee5215816368987eb130117ca4b87

Contents?: true

Size: 1.54 KB

Versions: 22

Compression:

Stored size: 1.54 KB

Contents

function new_form_field(type) {
  if ($.inArray(type, ['text_field', 'select', 'multiselect', 'radio', 'check_box']) == -1) {
    alert('Unknown field type.');
  } else {
    // find an index for the new form field (largest index plus one)
    var new_index = 0;
    $("#form-fields input[name$='[_type]']").each(function(i, el) {
      num = parseInt(el.id.replace(/form_fields_(\d+)__type/i, "$1"));
      if (new_index < num) new_index = num;
    });

    $.get('/admin/fields/new/', {
      'type': type,
      'index': (new_index + 1)
    },
    function(data) {
      $('#form-fields table tbody').append(data);
      setup_tooltips();
    });
  }

  return false;
}

function delete_form_field(button) {
  if (confirm('Are you sure?')) {
    $(button).closest('tr').remove();
  }
  return false;
}

function move_form_field(event) {
  direction = $(this).text().toLowerCase();
  row = $(this).closest('tr');
  if (direction == 'up') {
    row.prev('tr').before(row);
  } else {
    row.next('tr').after(row);
  }
  // COrrect indexes
  $("#form-fields tbody tr").each(function(i, row) {
    $(row).find("input").each(function(ri, input) {
      $(input).attr('id',  $(input).attr('id').replace(/_\d+_/,"_"+i+"_"));
      $(input).attr('name',  $(input).attr('name').replace(/\[\d+\]/,"["+i+"]"));
    });
    $(row).find("label").each(function(li, label) {
      $(label).attr('for',  $(label).attr('for').replace(/_\d+_/,"_"+i+"_"));
    });
  });
}
$('#form-fields .page_up').live('click',move_form_field);
$('#form-fields .page_down').live('click',move_form_field);

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
noodall-form-builder-0.4.2 app/assets/javascripts/admin/formbuilder.js
noodall-form-builder-0.4.1 app/assets/javascripts/admin/formbuilder.js
noodall-form-builder-0.4.0 app/assets/javascripts/admin/formbuilder.js
noodall-form-builder-0.3.3 public/javascripts/admin/formbuilder.js
noodall-form-builder-0.2.11 public/javascripts/admin/formbuilder.js
noodall-form-builder-0.3.2 public/javascripts/admin/formbuilder.js
noodall-form-builder-0.3.1 public/javascripts/admin/formbuilder.js
noodall-form-builder-0.3.0 public/javascripts/admin/formbuilder.js
noodall-form-builder-0.2.10 public/javascripts/admin/formbuilder.js
noodall-form-builder-0.2.9 public/javascripts/admin/formbuilder.js
noodall-form-builder-0.2.8 public/javascripts/admin/formbuilder.js
noodall-form-builder-0.2.7 public/javascripts/admin/formbuilder.js
noodall-form-builder-0.2.5 public/javascripts/admin/formbuilder.js
noodall-form-builder-0.2.4 public/javascripts/admin/formbuilder.js
noodall-form-builder-0.2.3 public/javascripts/admin/formbuilder.js
noodall-form-builder-0.2.2 public/javascripts/admin/formbuilder.js
noodall-form-builder-0.2.1 public/javascripts/admin/formbuilder.js
noodall-form-builder-0.2.0 public/javascripts/admin/formbuilder.js
noodall-form-builder-0.1.3 public/javascripts/admin/formbuilder.js
noodall-form-builder-0.1.2 public/javascripts/admin/formbuilder.js