(function() {
  var page = document.querySelector('#page_<%= @page.id %>');

<% if @while_page_edit -%>

  Alchemy.reloadPreview();
  document.querySelector('#page_<%= @page.id %>_status').outerHTML = '<%= j render("current_page", current_page: @page) %>';
  Alchemy.growl("<%= j @notice %>");
  Alchemy.closeCurrentDialog();

<% elsif @page.parent_id != @old_parent_id -%>

  Alchemy.closeCurrentDialog(function() {
    Alchemy.growl("<%= j @notice %>");
    Alchemy.currentSitemap.load(<%= @page.get_language_root.id %>);
  });

<% else -%>

  if (page) {
    var page_html = "<%= j render('page', page: @page) %>";
    var compiler = Handlebars.compile(page_html);
    var tree = <%== @tree.to_json %>;
    page.outerHTML = compiler(tree.pages[0]);
    Alchemy.growl("<%= j @notice %>");
    Alchemy.closeCurrentDialog();
  } else {
    document.addEventListener('turbolinks:load', function () {
      Alchemy.growl("<%= j @notice %>");
    }, { once: true })
    Alchemy.closeCurrentDialog(function() {
      Turbolinks.visit(location.toString(), { action: "replace" });
    });
  }

<% end -%>
})()

(function() {
  var page = document.querySelector('#page_<%= @page.id %>');

<% if @while_page_edit -%>

  Alchemy.reloadPreview();
  document.querySelector('#page_<%= @page.id %>_status').outerHTML = '<%= j render("current_page", current_page: @page) %>';
  Alchemy.growl("<%= j @notice %>");
  Alchemy.closeCurrentDialog();

<% elsif @page.parent_id != @old_parent_id -%>

  Alchemy.closeCurrentDialog(function() {
    Alchemy.growl("<%= j @notice %>");
    Alchemy.currentSitemap.load(<%= @page.get_language_root.id %>);
  });

<% else -%>

  if (page) {
    var page_html = "<%= j render('page', page: @page) %>".replace(/__ID__/g, "<%= @page.id %>");;
    var compiler = Handlebars.compile(page_html);
    var tree = <%== @tree.to_json %>;
    page.outerHTML = compiler(tree.pages[0]);
    Alchemy.growl("<%= j @notice %>");
    Alchemy.closeCurrentDialog();
  } else {
    document.addEventListener('turbolinks:load', function () {
      Alchemy.growl("<%= j @notice %>");
    }, { once: true })
    Alchemy.closeCurrentDialog(function() {
      Turbolinks.visit(location.toString(), { action: "replace" });
    });
  }

<% end -%>
})()

Fix admin page tree links after update
Fix admin page tree links after update

Closes #2347
