trestle icon indicating copy to clipboard operation
trestle copied to clipboard

How to make the New action in Index view open in new page?

Open basharabdullah opened this issue 3 years ago • 3 comments

Thanks for the great work!

Basically on my Jobs Admin page, I customized New action from the controller side. And I also need the New action to open in a blank window. How can I do that?

basharabdullah avatar Sep 02 '21 11:09 basharabdullah

@basharabdullah Adding target: '_blank' works toolbar.link 'Open action in new Window', some_url, icon: 'fa fa-check', target: '_blank'

PadawanBreslau avatar Sep 02 '21 12:09 PadawanBreslau

@basharabdullah Adding target: '_blank' works toolbar.link 'Open action in new Window', some_url, icon: 'fa fa-check', target: '_blank'

Thanks. But I meant the large + icon above the table view.

basharabdullah avatar Sep 02 '21 15:09 basharabdullah

Currently to do this you will need to copy and override the template from https://github.com/TrestleAdmin/trestle/blob/master/app/views/trestle/resource/index.html.erb for your admin.

e.g. within app/views/admin/jobs/index.html.erb:

<% content_for(:title, admin.t("titles.index", default: "Listing %{pluralized_model_name}")) %>

<% toolbar(:primary) do |t| %>
  <%= t.link(admin.t("buttons.new", default: "New %{model_name}"), action: :new, style: :light, icon: "fa fa-plus", class: "btn-new-resource", target: "_blank") %>
<% end %>

<% content_for(:utilities) do %>
  <%= render "scopes" %>
<% end if admin.scopes.any? %>

<%= render layout: "layout" do %>
  <% if hook?("resource.index.header") %>
    <header class="main-content-header">
      <%= hook("resource.index.header") %>
    </header>
  <% end %>

  <%= render "trestle/table/table", table: admin.table, collection: collection %>

  <footer class="main-content-footer">
    <%= hook("resource.index.footer") %>

    <%= pagination collection: collection, entry_name: admin.model_name, remote: admin.pagination_options[:ajax] %>
  </footer>
<% end %>

Cleaner ways to do this will be coming in future however.

spohlenz avatar Sep 07 '21 04:09 spohlenz