<%  context = context_listing %>
<div id="<%= dom_id(context, "container") %>" class="list">
  <div id="<%= dom_id(context) %>" class="context sortable_row" style="display:'';">
    <div class="position">
      <span class="handle">DRAG</span>
    </div>
    <div class="data">
      <%= link_to_context( context ) %> <%= " (" + count_undone_todos_phrase(context,"actions") + ")" %>
    </div>

    <div class="buttons">
      <% if context.hide? %>
        <span class="grey">HIDDEN</span>
      <% else %>
        <span class="grey">VISIBLE</span>
      <% end %>
      <a class="delete_context_button" href="<%= formatted_context_path(context, :js) %>" title="delete the context '<%= context.name %>'"><%= image_tag( "blank.png", :title => "Delete context", :class=>"delete_item") %></a>
      <%= apply_behavior "a.delete_context_button:click", { :prevent_default => true, :external => true} do |page|
           page << "if (confirm('Are you sure that you want to ' + this.title + '?')) {"
           page << "  new Ajax.Request(this.href, {asynchronous:true,"
           page << "                               evalScripts:true, method:'delete'}); };"
         end -%>
      <a class="edit_context_button" href="#"><%= image_tag( "blank.png", :title => "Edit context", :class=>"edit_item") %></a>
      <%= apply_behavior 'a.edit_context_button:click', :prevent_default => true do |page, element|
           element.up('.context').toggle 
           editform = element.up('.list').down('.edit-form')
           editform.toggle 
           editform.visual_effect(:appear) 
           editform.down('input').focus
         end
      -%>
    </div>
  </div>
  <div id="<%= dom_id(context, 'edit') %>" class="edit-form" style="display:none;">
    <% form_tag context_path(context), { :id => dom_id(context, 'edit_form'), :class => "inline-form edit-context-form", :method => :put } do -%>
    <table style="table-layout: fixed;" width="450">
      <%= render :partial => 'context_form', :object => context %>
      <tr>
        <td width="150">&nbsp; <input type="hidden" name="wants_render" value="true" /> </td>
        <td width="300"><input type="submit" value="Update" />&nbsp;<a href="#" class="form_reset">Cancel</a></td>
      </tr>
    </table>
    <% end -%>
    <%= apply_behavior ".edit-context-form", make_remote_form(:complete => "Effect.Appear($(this).up('.list'));" ), :external => true %>
    <%= apply_behavior "a.form_reset:click", :prevent_default => true do |page, element|
         element.up('.list').down('.context').toggle
         element.up('.edit-form').toggle
         element.up('form').reset
       end %>
  </div>
</div>
<% if controller.action_name == 'create' %>
<script>
   new Effect.Appear('<%= dom_id(context) %>');
</script>
<% end %>
