<div class="contextual">
  <%= link_to l(:label_cms_preview), preview_cms_part_path(@part), :class => 'icon icon-preview'  %>
  <%= link_to l(:label_cms_preview_page), preview_cms_page_path(@part.page), :class => 'icon icon-preview'  %>
  <%= link_to l(:label_history), cms_object_history_path(@part, :object_type => @part.class.name.underscore), :class => 'icon icon-history' %>
  <%= link_to l(:button_duplicate), new_cms_part_path(:copy_from => @part), :class => 'icon icon-duplicate' %>
  <%= delete_link cms_part_path(@part) if User.current.admin? %>
</div>


<h2><%= link_to l(:label_cms_page_plural), cms_pages_path %>
  <% @page.ancestors.each do |page| %>
    &#187; <%= link_to page.slug, edit_cms_page_url(page) %>
  <% end %>
    &#187; <%= @page.slug %>
</h2>

<div class="tabs part-tabs">
  <ul>
    <li><%= link_to(l(:label_cms_page), edit_cms_page_path(@part.page), :class => "page") %></li>
    <% @part.page.parts.active.order(:position).each do |part| %>
      <li><%= link_to(part.title, edit_cms_part_path(part), :class => "#{(@part.id == part.id ? 'selected' : nil)} #{'locked' unless part.active?}") %></li>
    <% end %>
    <li><%= link_to "+", new_cms_part_path(:page_id => @part.page.id) %></li>
  </ul>
  <div class="tabs-buttons" style="display:none;">
    <button class="tab-left" type="button" onclick="moveTabLeft(this);"></button>
    <button class="tab-right" type="button" onclick="moveTabRight(this);"></button>
  </div>
</div>

<%= labelled_form_for :part, @part, :url => { :action => 'update', :id => @part},
  :html => { :id => 'part_form', :multipart => true, :method => :put } do |f| %>

<%= render :partial => 'form', :locals => { :f => f } %>
<% if @page.attachments.any? %>
    <fieldset><legend><%= l(:label_attachment_plural) %></legend>
      <%= link_to_cms_attachments @page, :thumbnails => true  %>
    </fieldset>
    <br/>
  <% end %>

<!-- <fieldset><legend><%= l(:label_attachment_plural) %></legend>
  <%= link_to_cms_attachments @part, :thumbnails => true  %>
</fieldset><br/> -->

<% content_for :sidebar do %>
  <% render :partial => 'cms_settings/menu' %>
<% end %>

<%= submit_tag l(:button_save) %>
<%= link_to l(:label_cms_apply), "#", :style => "margin-left:10px;", :remote => true, :onclick => "editor.save(); $.ajax({url: '#{escape_javascript cms_part_path(@part)}', type: \'post\', dataType: \'script\', data: $(\'#part_form\').serialize()}); $('textarea').removeData('changed'); return false;"%>
<% end %>

<% content_for :header_tags do %>
  <div class="contextual page-edit" id="float_buttons">
    <%= link_to l(:label_cms_apply), "#", :remote => true, :onclick => "editor.save(); $.ajax({url: '#{escape_javascript cms_part_path(@part)}', type: \'post\', dataType: \'script\', data: $(\'#part_form\').serialize()}); $('textarea').removeData('changed'); return false;"%>
  </div>
<% end %>
<%= javascript_tag "$('.contextual.page-edit').draggable();" %>

<% html_title(@part.title + " " + @part.page.name) -%>