(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 -%>

})();

(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.Tinymce.init(<%= @element.richtext_contents_ids.to_json %>);
  Alchemy.PreviewWindow.refresh(function() {
    Alchemy.ElementEditors.selectElementInPreview(<%= @element.id %>);
  });
  <%= update_essence_select_elements(@page, @element) -%>
  Alchemy.GUI.initElement('#element_<%= @element.id %>');

<%- 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 -%>

})();

Fix enhanced elements when updating whole elements
Fix enhanced elements when updating whole elements

Completes 1aecd1530f67d5414f0a21a0a17703b715dbd44a
