(function() {
  var $el = $('#element_<%= @element.id %>');
  $('.content_editor', $el).removeClass('validation_failed');

<%- if @element_validated -%>

  $('.element_head', $el).replaceWith('<%= j render("element_head", element: @element) %>');
  Alchemy.ElementEditors.reinit($el);
  $("#element_<%= @element.id %>_errors").hide();
  Alchemy.setElementSaved($el);
  Alchemy.growl('<%= _t(:element_saved) %>');
  Alchemy.PreviewWindow.refresh(function() {
    Alchemy.ElementEditors.selectElementInPreview(<%= @element.id %>);
  });
  <%= update_essence_select_elements(@page, @element) -%>

<%- else -%>

  Alchemy.growl('<%= j @notice %>', 'warn');
  $('#element_<%= @element.id %>_errors').html('<%= j @error_message %><ul><li><%== j @element.essence_error_messages.join("</li><li>") %></li></ul>');
  $("#element_<%= @element.id %>_errors").show();
  $('<%= @element.contents_with_errors.map { |content| "#" + content.dom_id }.join(", ") %>').addClass('validation_failed');
  Alchemy.ElementEditors.scrollToElement('#element_<%= @element.id %>');
  Alchemy.Buttons.enable($el);

<%- end -%>

})();

(function() {
  var $el = $('#element_<%= @element.id %>');
  $('.content_editor', $el).removeClass('validation_failed');

<%- if @element_validated -%>

  $el.replaceWith('<%= j render("element", element: @element) %>');
  Alchemy.ElementEditors.reinit($el);
  $("#element_<%= @element.id %>_errors").hide();
  Alchemy.setElementSaved($el);
  Alchemy.growl('<%= _t(:element_saved) %>');
  Alchemy.PreviewWindow.refresh(function() {
    Alchemy.ElementEditors.selectElementInPreview(<%= @element.id %>);
  });
  <%= update_essence_select_elements(@page, @element) -%>

<%- else -%>

  Alchemy.growl('<%= j @notice %>', 'warn');
  $('#element_<%= @element.id %>_errors').html('<%= j @error_message %><ul><li><%== j @element.essence_error_messages.join("</li><li>") %></li></ul>');
  $("#element_<%= @element.id %>_errors").show();
  $('<%= @element.contents_with_errors.map { |content| "#" + content.dom_id }.join(", ") %>').addClass('validation_failed');
  Alchemy.ElementEditors.scrollToElement('#element_<%= @element.id %>');
  Alchemy.Buttons.enable($el);

<%- end -%>

})();

Update whole element upon save in editor
Update whole element upon save in editor

Before, only the element editor's head was replaced. This may lead to
problems when the editor body or one of it's essences' editors doesn't
just display inputs. We had one problem where we displayed an image of
a referenced model. This was never updated. Now it gets updated since
the whole editor block will be regenerated.
