Permalink
Browse files

Major refactoring of the batch actions UI code. More to come.

  • Loading branch information...
1 parent 6cbe3a1 commit 1538d080718aadabcb09166aaf51c6934deac9d0 @gregbell gregbell committed May 3, 2012
Showing with 497 additions and 462 deletions.
  1. +0 −8 Guardfile
  2. +0 −292 app/assets/javascripts/active_admin/application.js
  3. +4 −1 app/assets/javascripts/active_admin/base.js
  4. +0 −4 app/assets/javascripts/active_admin/coffeescripts/application.js
  5. +0 −45 app/assets/javascripts/active_admin/coffeescripts/pages/batch_actions.js.coffee
  6. 0 ...ssets/javascripts/active_admin/{coffeescripts → }/components/jquery.aa.checkbox-toggler.js.coffee
  7. +107 −0 app/assets/javascripts/active_admin/components/jquery.aa.dropdown-menu.js.coffee
  8. +17 −12 app/assets/javascripts/active_admin/{coffeescripts → }/components/jquery.aa.popover.js.coffee
  9. +0 −2 ...javascripts/active_admin/{coffeescripts → }/components/jquery.aa.table-checkbox-toggler.js.coffee
  10. 0 app/assets/javascripts/active_admin/{coffeescripts → }/lib/namespace.js.coffee
  11. +2 −1 app/assets/javascripts/active_admin/{coffeescripts → }/pages/application.js.coffee
  12. +26 −0 app/assets/javascripts/active_admin/pages/batch_actions.js.coffee
  13. +1 −0 app/assets/stylesheets/active_admin/_base.css.scss
  14. +1 −2 app/assets/stylesheets/active_admin/components/_buttons.scss
  15. +151 −0 app/assets/stylesheets/active_admin/components/_dropdown_menu.scss
  16. +3 −31 app/assets/stylesheets/active_admin/components/_table_tools.css.scss
  17. +2 −2 features/index/batch_actions.feature
  18. +10 −6 features/step_definitions/batch_action_steps.rb
  19. +2 −1 lib/active_admin/batch_actions.rb
  20. +11 −10 lib/active_admin/batch_actions/views/batch_action_form.rb
  21. +63 −0 lib/active_admin/batch_actions/views/batch_action_selector.rb
  22. +73 −0 lib/active_admin/views/components/dropdown_menu.rb
  23. +12 −19 lib/active_admin/views/components/popover.rb
  24. +0 −5 lib/active_admin/views/pages/base.rb
  25. +11 −20 lib/active_admin/views/pages/index.rb
  26. +1 −1 spec/javascripts/coffeescripts/jquery.aa.checkbox-toggler-spec.js.coffee
View
@@ -5,11 +5,3 @@ guard 'rspec', :all_on_start => false, :version => 2 do
watch(%r{^lib/active_admin/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec/" }
end
-
-guard 'coffeescript', :output => 'spec/javascripts/compiled', :all_on_start => true do
- watch(%r{spec/javascripts/coffeescripts/(.*)\.coffee})
-end
-
-guard 'sprockets', :destination => "app/assets/javascripts/active_admin/", :asset_paths => ['app/assets/javascripts/active_admin/coffeescripts/'] do
- watch(%r{^app/assets/javascripts/active_admin/coffeescripts/.+$})
-end
@@ -1,292 +0,0 @@
-(function() {
-
- window.AA = {};
-
-}).call(this);
-(function() {
-
- window.AA.CheckboxToggler = AA.CheckboxToggler = (function() {
-
- function CheckboxToggler(options, container) {
- var defaults;
- this.options = options;
- this.container = container;
- defaults = {};
- this.options = $.extend({}, defaults, options);
- this._init();
- this._bind();
- }
-
- CheckboxToggler.prototype._init = function() {
- if (!this.container) {
- throw new Error("Container element not found");
- } else {
- this.$container = $(this.container);
- }
- if (!this.$container.find(".toggle_all").length) {
- throw new Error("'toggle all' checkbox not found");
- } else {
- this.toggle_all_checkbox = this.$container.find(".toggle_all");
- }
- return this.checkboxes = this.$container.find(":checkbox").not(this.toggle_all_checkbox);
- };
-
- CheckboxToggler.prototype._bind = function() {
- var _this = this;
- this.checkboxes.bind("change", function(e) {
- return _this._didChangeCheckbox(e.target);
- });
- return this.toggle_all_checkbox.bind("change", function(e) {
- return _this._didChangeToggleAllCheckbox();
- });
- };
-
- CheckboxToggler.prototype._didChangeCheckbox = function(checkbox) {
- if (this.checkboxes.filter(":checked").length === this.checkboxes.length - 1) {
- return this._uncheckToggleAllCheckbox();
- } else if (this.checkboxes.filter(":checked").length === this.checkboxes.length) {
- return this._checkToggleAllCheckbox();
- }
- };
-
- CheckboxToggler.prototype._didChangeToggleAllCheckbox = function() {
- if (this.toggle_all_checkbox.attr("checked") === "checked") {
- return this._checkAllCheckboxes();
- } else {
- return this._uncheckAllCheckboxes();
- }
- };
-
- CheckboxToggler.prototype._uncheckToggleAllCheckbox = function() {
- return this.toggle_all_checkbox.removeAttr("checked");
- };
-
- CheckboxToggler.prototype._checkToggleAllCheckbox = function() {
- return this.toggle_all_checkbox.attr("checked", "checked");
- };
-
- CheckboxToggler.prototype._uncheckAllCheckboxes = function() {
- var _this = this;
- return this.checkboxes.each(function(index, el) {
- $(el).removeAttr("checked");
- return _this._didChangeCheckbox(el);
- });
- };
-
- CheckboxToggler.prototype._checkAllCheckboxes = function() {
- var _this = this;
- return this.checkboxes.each(function(index, el) {
- $(el).attr("checked", "checked");
- return _this._didChangeCheckbox(el);
- });
- };
-
- return CheckboxToggler;
-
- })();
-
- (function($) {
- return $.widget.bridge('checkboxToggler', AA.CheckboxToggler);
- })(jQuery);
-
-}).call(this);
-(function() {
-
- window.AA.Popover = AA.Popover = (function() {
-
- function Popover(options, element) {
- var defaults;
- this.options = options;
- this.element = element;
- this.$element = $(this.element);
- defaults = {
- fadeInDuration: 20,
- fadeOutDuration: 100,
- autoOpen: true,
- pageWrapperElement: "#wrapper",
- onClickActionItemCallback: null
- };
- this.options = $.extend({}, defaults, options);
- this.$popover = null;
- this.isOpen = false;
- if ($(this.$element.attr("href")).length > 0) {
- this.$popover = $(this.$element.attr("href"));
- }
- this._buildPopover();
- this._bind();
- return this;
- }
-
- Popover.prototype.open = function() {
- this.isOpen = true;
- this.$popover.fadeIn(this.options.fadeInDuration);
- this._positionPopover();
- this._positionNipple();
- return this;
- };
-
- Popover.prototype.close = function() {
- this.isOpen = false;
- this.$popover.fadeOut(this.options.fadeOutDuration);
- return this;
- };
-
- Popover.prototype.destroy = function() {
- this.$element.removeData('popover');
- this.$element.unbind();
- this.$element = null;
- return this;
- };
-
- Popover.prototype.option = function() {};
-
- Popover.prototype._buildPopover = function() {
- this.$popover.prepend("<div class=\"popover_nipple\"></div>");
- this.$popover.hide();
- return this.$popover.addClass("popover");
- };
-
- Popover.prototype._bind = function() {
- var _this = this;
- $(this.options.pageWrapperElement).bind('click', function(e) {
- if (_this.isOpen === true) return _this.close();
- });
- if (this.options.autoOpen === true) {
- return this.$element.bind('click', function() {
- _this.open();
- return false;
- });
- }
- };
-
- Popover.prototype._positionPopover = function() {
- var centerOfButtonFromLeft, centerOfPopoverFromLeft, popoverLeftPos;
- centerOfButtonFromLeft = this.$element.offset().left + this.$element.outerWidth() / 2;
- centerOfPopoverFromLeft = this.$popover.outerWidth() / 2;
- popoverLeftPos = centerOfButtonFromLeft - centerOfPopoverFromLeft;
- return this.$popover.css("left", popoverLeftPos);
- };
-
- Popover.prototype._positionNipple = function() {
- var $nipple, bottomOfButtonFromTop, centerOfPopoverFromLeft, centerOfnippleFromLeft, nippleLeftPos;
- centerOfPopoverFromLeft = this.$popover.outerWidth() / 2;
- bottomOfButtonFromTop = this.$element.offset().top + this.$element.outerHeight() + 10;
- this.$popover.css("top", bottomOfButtonFromTop);
- $nipple = this.$popover.find(".popover_nipple");
- centerOfnippleFromLeft = $nipple.outerWidth() / 2;
- nippleLeftPos = centerOfPopoverFromLeft - centerOfnippleFromLeft;
- return $nipple.css("left", nippleLeftPos);
- };
-
- return Popover;
-
- })();
-
- (function($) {
- return $.widget.bridge('popover', AA.Popover);
- })(jQuery);
-
-}).call(this);
-(function() {
- var __hasProp = Object.prototype.hasOwnProperty,
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
-
- window.AA.TableCheckboxToggler = AA.TableCheckboxToggler = (function(_super) {
-
- __extends(TableCheckboxToggler, _super);
-
- function TableCheckboxToggler() {
- TableCheckboxToggler.__super__.constructor.apply(this, arguments);
- }
-
- TableCheckboxToggler.prototype._init = function() {
- return TableCheckboxToggler.__super__._init.apply(this, arguments);
- };
-
- TableCheckboxToggler.prototype._bind = function() {
- var _this = this;
- TableCheckboxToggler.__super__._bind.apply(this, arguments);
- return this.$container.find("tbody").find("td").bind("click", function(e) {
- if (e.target.type !== 'checkbox') return _this._didClickCell(e.target);
- });
- };
-
- TableCheckboxToggler.prototype._didChangeCheckbox = function(checkbox) {
- var $row;
- TableCheckboxToggler.__super__._didChangeCheckbox.apply(this, arguments);
- $row = $(checkbox).parents("tr");
- if (checkbox.checked) {
- return $row.addClass("selected");
- } else {
- return $row.removeClass("selected");
- }
- };
-
- TableCheckboxToggler.prototype._didClickCell = function(cell) {
- return $(cell).parent("tr").find(':checkbox').click();
- };
-
- return TableCheckboxToggler;
-
- })(AA.CheckboxToggler);
-
- (function($) {
- return $.widget.bridge('tableCheckboxToggler', AA.TableCheckboxToggler);
- })(jQuery);
-
-}).call(this);
-(function() {
-
- $(function() {
- $(".datepicker").datepicker({
- dateFormat: "yy-mm-dd"
- });
- return $(".clear_filters_btn").click(function() {
- window.location.search = "";
- return false;
- });
- });
-
-}).call(this);
-(function() {
-
- jQuery(function($) {
- $("#batch_actions_button").popover({
- autoOpen: false
- });
- $(document).delegate("#batch_actions_popover li a", "click.rails", function() {
- $("#batch_action").val($(this).attr("data-action"));
- return $("#collection_selection").submit();
- });
- $("#batch_actions_button").click(function() {
- if (!$(this).hasClass("disabled")) {
- if ($("#batch_actions_popover").is(":hidden")) {
- $(this).popover("open");
- return false;
- } else {
- $(this).popover("close");
- return false;
- }
- }
- });
- if ($("#batch_actions_button").length && $(":checkbox.toggle_all").length) {
- if ($(".paginated_collection").find("table").length) {
- $(".paginated_collection table").tableCheckboxToggler();
- } else {
- $(".paginated_collection").checkboxToggler();
- }
- return $(".paginated_collection").find(":checkbox").bind("change", function() {
- if ($(".paginated_collection").find(":checkbox").filter(":checked").length > 0) {
- return $("#batch_actions_button").removeClass("disabled");
- } else {
- return $("#batch_actions_button").addClass("disabled");
- }
- });
- }
- });
-
-}).call(this);
-
-
-
-
@@ -1,5 +1,8 @@
//= require jquery
//= require jquery-ui
//= require jquery_ujs
-//= require active_admin/application
+//= require_tree ./lib/
+//= require_tree ./components/
+//= require_tree ./pages/
+//= require_directory ./
@@ -1,4 +0,0 @@
-//= require_tree ./lib/
-//= require_tree ./components/
-//= require_tree ./pages/
-//= require_directory ./
@@ -1,45 +0,0 @@
-jQuery ($) ->
-
- #
- # Init batch action popover
- #
-
- $("#batch_actions_button").popover autoOpen: false
-
- #
- # Use Rails.js click handler to allow for Rails' confirm dialogs
- #
-
- $(document).delegate "#batch_actions_popover li a", "click.rails", ->
- $("#batch_action").val $(this).attr("data-action")
- $("#collection_selection").submit()
-
- #
- # Toggle showing / hiding the batch actions popover
- #
-
- $("#batch_actions_button").click ->
- unless $(this).hasClass("disabled")
- if $("#batch_actions_popover").is(":hidden")
- $(this).popover "open"
- return false
- else
- $(this).popover "close"
- return false
-
- #
- # Add checkbox selection to resource tables and lists if batch actions are enabled
- #
-
- if $("#batch_actions_button").length && $(":checkbox.toggle_all").length
-
- if $(".paginated_collection").find("table").length
- $(".paginated_collection table").tableCheckboxToggler()
- else
- $(".paginated_collection").checkboxToggler()
-
- $(".paginated_collection").find(":checkbox").bind "change", ->
- if $(".paginated_collection").find(":checkbox").filter(":checked").length > 0
- $("#batch_actions_button").removeClass("disabled")
- else
- $("#batch_actions_button").addClass("disabled")
Oops, something went wrong.

0 comments on commit 1538d08

Please sign in to comment.