Skip to content

Commit

Permalink
Patch batch actions
Browse files Browse the repository at this point in the history
  • Loading branch information
sineed committed May 18, 2017
1 parent 914314c commit 810f5df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 1 addition & 3 deletions lib/ex_admin/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,10 @@ defmodule ExAdmin.Index do

@doc false
def render_index_pages(conn, page, scope_counts, cell, page_opts) do
# require IEx
# IEx.pry
name = resource_model(conn) |> titleize |> Inflex.pluralize
defn = conn.assigns.defn
label = get_resource_label(conn) |> Inflex.pluralize
batch_actions = (not false in defn.batch_actions) and :delete in page_opts[:actions]
batch_actions = (not false in defn.batch_actions)
opts = %{
columns: Map.get(page_opts, :columns, 3),
column_list: Map.get(page_opts, :column_list),
Expand Down
11 changes: 6 additions & 5 deletions lib/ex_admin/themes/admin_lte2/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,20 @@ defmodule ExAdmin.Theme.AdminLte2.Index do
|> Enum.reverse
end

def batch_action_form(_conn, enabled?, scopes, name, _scope_counts, fun) do
msg = gettext "Are you sure you want to delete these %{name}? You wont be able to undo this.", name: name
def batch_action_form(conn, enabled?, scopes, name, _scope_counts, fun) do
scopes = unless Application.get_env(:ex_admin, :scopes_index_page, true), do: [], else: scopes
if enabled? or scopes != [] do
resource_model = resource_model(conn)
name = resource_model |> base_name |> Inflex.underscore |> pluralize
view_module = Module.concat(ExAdmin, resource_model <> "View")
form "#collection_selection", action: "/admin/#{name}/batch_action", method: :post, "accept-charset": "UTF-8" do
div style: "margin:0;padding:0;display:inline" do
csrf = Plug.CSRFProtection.get_csrf_token
input name: "utf8", type: :hidden, value: "✓"
input(type: :hidden, name: "_csrf_token", value: csrf)
end
input "#batch_action", name: "batch_action", type: :hidden
input "scope", name: "scope", type: :hidden, value: conn.params["scope"]
div ".box-header" do
div ".table_tools" do
if enabled? do
Expand All @@ -143,9 +146,7 @@ defmodule ExAdmin.Theme.AdminLte2.Index do
div ".dropdown_menu_list_wrapper", style: "display: none;" do
div ".dropdown_menu_nipple"
ul ".dropdown_menu_list" do
li do
a ".batch_action " <> (gettext "Delete Selected"), href: "#", "data-action": :destroy, "data-confirm": msg
end
raw Phoenix.View.render(view_module, "batch_actions.html", [conn: conn])
end
end
end
Expand Down

0 comments on commit 810f5df

Please sign in to comment.