<p>
  <label><%= l(:field_visible) %></label>
  <label class="block radio">
    <%= radio_button_tag 'custom_field[visible]', 1, @custom_field.visible?, :id => 'custom_field_visible_on',
      :data => {:disables => '.custom_field_role input'} %>
      <%= l(:label_visibility_public) %>
  </label>
  <label class="block radio">
    <%= radio_button_tag 'custom_field[visible]', 0, !@custom_field.visible?, :id => 'custom_field_visible_off',
      :data => {:enables => '.custom_field_role input'} %>
    <%= l(:label_visibility_roles) %>:
  </label>
  <% Role.givable.sorted.each do |role| %>
    <label class="block checkbox custom_field_role" style="padding-left:2em;">
      <%= check_box_tag 'custom_field[role_ids][]', role.id, @custom_field.roles.include?(role), :id => nil %>
      <%= role.name %>
    </label>
  <% end %>
  <%= hidden_field_tag 'custom_field[role_ids][]', '' %>
</p>

<script type="text/javascript">
  function disableMailNotifications() {
      var notifications = $('#custom_field_mail_notification');
      if ($('#custom_field_visible_on').is(':checked')) {
          notifications.prop('disabled', false);
      }
      else {
          notifications.prop('disabled', true);
          notifications.prop('checked', false);
      }
  }

  $('#custom_field_visible_on, #custom_field_visible_off').change(disableMailNotifications);
  $(document).ready(disableMailNotifications);
</script>
