Skip to content

Commit

Permalink
Fixed several issues after merging with the @gregbell master & refact…
Browse files Browse the repository at this point in the history
…ored the JS support for batch actions out into a separate JS file.
  • Loading branch information
Matthew Brewer authored and Matthew Brewer committed Dec 2, 2011
1 parent 5c62315 commit 5ee02e5
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 98 deletions.
93 changes: 1 addition & 92 deletions app/assets/javascripts/active_admin/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,4 @@
//= require jquery-ui
//= require jquery_ujs
//= require active_admin/application

/* Active Admin JS */

$(function(){
$(".datepicker").datepicker({dateFormat: 'yy-mm-dd'});

$(".clear_filters_btn").click(function(){
window.location.search = "";
return false;
});

// Batch actions stuff

$('#batch_actions_button').toggle(function() {
if (!$(this).hasClass("disabled")) {
$("#batch_actions_popover").fadeIn(50);
};
}, function() {
$("#batch_actions_popover").fadeOut(100);
});

$('#collection_selection_toggle_all').click(function() {

var $this = $(this);
var isTable = $this.closest(".index").hasClass("index_as_table");

if ($(this).attr('checked') == true) {
$('#batch_actions_button').removeClass("disabled");
$('#batch_actions_button').addClass("selected");
$('.collection_selection').attr('checked', 'checked');
if ( isTable ) {
$(this).parents(".index_table").find('tr').addClass("selected");
}
} else {
$('#batch_actions_button').addClass("disabled");
$('#batch_actions_button').removeClass("selected");
$('.collection_selection').attr('checked', '');
if ( isTable ) {
$(this).parents(".index_table").find('tr').removeClass("selected");
}
}
});

$('.collection_selection').click(function() {

var $this = $(this);
var isTable = $this.closest(".index").hasClass("index_as_table");

if ( $this.attr('checked') == true ) {

$('#batch_actions_button').removeClass("disabled");
$('#batch_actions_button').addClass("selected");
if ( isTable ) {
$this.parents('tr').addClass("selected");
}

} else {

if ( $this.closest(".index").find("input:checked").length == 0) {
$('#batch_actions_button').addClass("disabled");
$('#batch_actions_button').removeClass("selected");
}

if ( isTable ) {
$this.parents('tr').removeClass("selected");
}

$("#collection_selection_toggle_all").attr('checked', '');

}

});

// Attach a click hanlder to each of the batch action items
$('#batch_actions_popover a.batch_action').click(function(e) {

// Present optional confirmation prompt to user
var $target = $(e.target);
if ( $target.attr("data-request-confirm") ) {
if ( !confirm( $target.attr("data-request-confirm") ) ) {
$("#batch_actions_popover").fadeOut(100);
return false;
}
}

// Submit the form, sending the request
$('#batch_action').val( $target.attr("data-action") );
$('#collection_selection').submit();

});

});
//= require active_admin/batch_actions
83 changes: 83 additions & 0 deletions app/assets/javascripts/active_admin/batch_actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
jQuery(function($) {

// Batch actions stuff

$('#batch_actions_button').toggle(function() {
if (!$(this).hasClass("disabled")) {
$("#batch_actions_popover").fadeIn(50);
};
}, function() {
$("#batch_actions_popover").fadeOut(100);
});

$('#collection_selection_toggle_all').click(function() {

var $this = $(this);
var isTable = $this.closest(".index").hasClass("index_table");

if ($(this).attr('checked') == "checked") {
$('#batch_actions_button').removeClass("disabled");
$('#batch_actions_button').addClass("selected");
$('.collection_selection').attr('checked', 'checked');
if ( isTable ) {
$(this).parents(".index_table").find('tr').addClass("selected");
}
} else {
$('#batch_actions_button').addClass("disabled");
$('#batch_actions_button').removeClass("selected");
$('.collection_selection').attr('checked', false);
if ( isTable ) {
$(this).parents(".index_table").find('tr').removeClass("selected");
}
}
});

$('.collection_selection').click(function() {

var $this = $(this);
var isTable = $this.closest(".index").hasClass("index_table");

if ( $this.attr('checked') == "checked" ) {

$('#batch_actions_button').removeClass("disabled");
$('#batch_actions_button').addClass("selected");
if ( isTable ) {
$this.parents('tr').addClass("selected");
}

} else {

if ( $this.closest(".index").find("input:checked").length == 0) {
$('#batch_actions_button').addClass("disabled");
$('#batch_actions_button').removeClass("selected");
}

if ( isTable ) {
$this.parents('tr').removeClass("selected");
}

$("#collection_selection_toggle_all").attr('checked', false);

}

});

// Attach a click hanlder to each of the batch action items
$('#batch_actions_popover a.batch_action').click(function(e) {

// Present optional confirmation prompt to user
var $target = $(e.target);
if ( $target.attr("data-request-confirm") ) {
if ( !confirm( $target.attr("data-request-confirm") ) ) {
$("#batch_actions_popover").fadeOut(100);
return false;
}
}

// Submit the form, sending the request
$('#batch_action').val( $target.attr("data-action") );
$('#collection_selection').submit();

});

});
2 changes: 1 addition & 1 deletion lib/active_admin/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DSL
def run_registration_block(config, &block)
@config = config
instance_eval &block if block_given?
register_batch_action_handler
register_batch_action_handler unless self.is_a?(ActiveAdmin::PageDSL)
end

# Register the batch action path
Expand Down
4 changes: 2 additions & 2 deletions lib/active_admin/views/index_as_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def build(page_presenter, collection)
table_options = {
:id => active_admin_config.plural_underscored_resource_name,
:sortable => true,
:class => "index_table",
:class => "index_table index",
:i18n => active_admin_config.resource_class
}

Expand Down Expand Up @@ -140,7 +140,7 @@ def default_actions(options = {})
:name => ""
}.merge(options)
column options[:name] do |resource|
links = ''.html_safe
links = ''.html_safe
if controller.action_methods.include?('show')
links += link_to I18n.t('active_admin.view'), resource_path(resource), :class => "member_link view_link"
end
Expand Down
5 changes: 2 additions & 3 deletions lib/active_admin/views/pages/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,15 @@ def build_batch_action_popover

def build_scopes
if active_admin_config.scopes.any?
div :class => "table_tools" do
scopes_renderer active_admin_config.scopes
end
scopes_renderer active_admin_config.scopes
end
end

# Creates a default configuration for the resource class. This is a table
# with each column displayed as well as all the default actions
def default_index_config
@default_index_config ||= ::ActiveAdmin::PagePresenter.new(:as => :table) do |display|
selectable_column
id_column
resource_class.content_columns.each do |col|
column col.name.to_sym
Expand Down

0 comments on commit 5ee02e5

Please sign in to comment.