Skip to content

Commit 6c2dc9c

Browse files
committed
Merge pull request activeadmin#1815 from seanlinsley/1815-batch-action-forms
Batch Action forms
2 parents 56e93bb + cb95ebc commit 6c2dc9c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+265
-79
lines changed

app/assets/javascripts/active_admin/base.js.coffee

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#= require jquery
2-
#= require jquery.ui.widget
32
#= require jquery.ui.datepicker
3+
#= require jquery.ui.dialog
44
#= require jquery.ui.sortable
5+
#= require jquery.ui.widget
56
#= require jquery_ujs
67
#
78
#= require_self
8-
#= require_tree ./lib/
9+
#= require_tree ./lib
10+
#= require_tree ./ext
911
#= require ./application
1012

1113
window.ActiveAdmin = {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Short-circuits `_focusTabbable` to focus on the modal itself instead of
2+
# elements inside the modal. Without this, if a datepicker is the first input,
3+
# it'll immediately pop up when the modal opens.
4+
# See this ticket for more info: http://bugs.jqueryui.com/ticket/4731
5+
$.ui.dialog.prototype._focusTabbable = ->
6+
@uiDialog.focus()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# `serializeArray` generates => [{ name: 'foo', value: 'bar' }]
2+
# This function remaps it to => { foo: 'bar' }
3+
$.fn.serializeObject = ->
4+
obj = {}
5+
for o in @serializeArray()
6+
obj[o.name] = o.value
7+
obj

app/assets/javascripts/active_admin/lib/batch_actions.js.coffee

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
$ ->
22

33
#
4-
# Use Rails.js click handler to allow for Rails' confirm dialogs
4+
# Use ActiveAdmin.modal_dialog to prompt user if confirmation is required for current Batch Action
55
#
6+
$('#batch_actions_selector li a').click (e)->
7+
e.stopPropagation() # prevent Rails UJS click event
8+
if message = $(@).data 'confirm'
9+
ActiveAdmin.modal_dialog message, $(@).data('inputs'), (inputs)=>
10+
$(@).trigger 'confirm:complete', inputs
11+
else
12+
$(@).trigger 'confirm:complete'
13+
14+
$('#batch_actions_selector li a').on 'confirm:complete', (e, inputs)->
15+
if val = JSON.stringify inputs
16+
$('#batch_action_inputs').val val
17+
else
18+
$('#batch_action_inputs').attr 'disabled', 'disabled'
619

7-
$(document).delegate "#batch_actions_selector li a", "click.rails", ->
8-
$("#batch_action").val $(@).attr("data-action")
9-
$("#collection_selection").submit()
20+
$('#batch_action').val $(@).data 'action'
21+
$('#collection_selection').submit()
1022

1123
#
1224
# Add checkbox selection to resource tables and lists if batch actions are enabled
@@ -20,7 +32,7 @@ $ ->
2032
$(".paginated_collection").checkboxToggler()
2133

2234
$(".paginated_collection :checkbox").change ->
23-
if $(".paginated_collection :checkbox:checked").length > 0
35+
if $(".paginated_collection :checkbox:checked").length
2436
$("#batch_actions_selector").aaDropdownMenu("enable")
2537
else
2638
$("#batch_actions_selector").aaDropdownMenu("disable")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
ActiveAdmin.modal_dialog = (message, inputs, callback)->
2+
html = """<form id="dialog_confirm" title="#{message}"><ul>"""
3+
for name, type of inputs
4+
if /^(datepicker|checkbox|text)$/.test type
5+
wrapper = 'input'
6+
else if type is 'textarea'
7+
wrapper = 'textarea'
8+
else if $.isArray type
9+
[wrapper, elem, opts, type] = ['select', 'option', type, '']
10+
else
11+
throw new Error "Unsupported input type: {#{name}: #{type}}"
12+
13+
klass = if type is 'datepicker' then type else ''
14+
html += """<li>
15+
<label>#{name.charAt(0).toUpperCase() + name.slice(1)}</label>
16+
<#{wrapper} name="#{name}" class="#{klass}" type="#{type}">""" +
17+
(if opts then ("<#{elem}>#{v}</#{elem}>" for v in opts).join '' else '') +
18+
"</#{wrapper}>" +
19+
"</li>"
20+
[wrapper, elem, opts, type, klass] = [] # unset any temporary variables
21+
22+
html += "</ul></form>"
23+
$(html).appendTo('body').dialog
24+
modal: true
25+
buttons:
26+
OK: ->
27+
callback $(@).serializeObject()
28+
$(@).dialog('close')
29+
Cancel: ->
30+
$(@).dialog('close').remove()

app/assets/stylesheets/active_admin/_base.css.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@import "active_admin/components/popovers";
1313
@import "active_admin/components/tables";
1414
@import "active_admin/components/batch_actions";
15+
@import "active_admin/components/modal_dialog";
1516
@import "active_admin/components/blank_slates";
1617
@import "active_admin/components/breadcrumbs";
1718
@import "active_admin/components/dropdown_menu";
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.ui-widget-overlay {
2+
position: fixed;
3+
background: rgba(0,0,0,.2);
4+
top: 0; left: 0; right: 0; bottom: 0;
5+
z-index: 1001;
6+
}
7+
8+
.ui-dialog {
9+
position: fixed;
10+
z-index: 1002;
11+
@include section-background;
12+
@include box-shadow(rgba(0,0,0,0.5) 0 0 10px);
13+
14+
.ui-dialog-titlebar {
15+
@include section-header;
16+
span { font-size: 1.1em }
17+
}
18+
.ui-dialog-titlebar-close { display: none }
19+
20+
ul { list-style-type: none }
21+
li { margin: 10px 0 }
22+
label { margin-right: 10px }
23+
24+
.ui-dialog-buttonpane, form {
25+
padding: 7px 15px 13px
26+
}
27+
.ui-dialog-buttonpane button {
28+
&:first-child { @include dark-button } // OK
29+
&:last-child { @include light-button } // Cancel
30+
}
31+
}

config/locales/bg.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ bg:
5353
link: "Създаване"
5454
batch_actions:
5555
button_label: "Масови действия"
56-
delete_confirmation: "Сигурни ли сте, че искате да изтриете тези %{plural_model}? Това действие не може да бъде върнато назад."
56+
default_confirmation: "Наистина ли искате да направите това?"
57+
delete_confirmation: "Сигурни ли сте, че искате да изтриете тези %{plural_model}?"
5758
succesfully_destroyed:
5859
one: "Успешно изтриване на 1 %{model}"
5960
other: "Успешно изтриване на %{count} %{plural_model}"

config/locales/ca.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ ca:
5252
link: "Crea'n un/a"
5353
batch_actions:
5454
button_label: "les accions per lots"
55-
delete_confirmation: "¿Està segur que desitja eliminar aquests %{plural_model}? Vostè no serà capaç de desfer això."
55+
default_confirmation: "¿Esteu segur que voleu fer-ho?"
56+
delete_confirmation: "¿Està segur que desitja eliminar aquests %{plural_model}?"
5657
succesfully_destroyed:
5758
one: "Va destruir amb èxit 1 %{model}"
5859
other: "Va destruir amb èxit %{count} %{plural_model}"

config/locales/cs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ cs:
5454
link: "Vytvořit"
5555
batch_actions:
5656
button_label: "Hromadné akce"
57+
default_confirmation: "Jste si jisti, že chcete provést?"
5758
delete_confirmation: "Jste si jisti, že chcete smazat tyto %{plural_model}?"
5859
succesfully_destroyed:
5960
zero: "Nebyl smazán žádný %{model}"

0 commit comments

Comments
 (0)