activeadmin 2.1.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activeadmin might be problematic. Click here for more details.

Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +112 -27
  3. data/CONTRIBUTING.md +50 -26
  4. data/README.md +8 -1
  5. data/app/assets/javascripts/active_admin/base.js +509 -0
  6. data/app/assets/stylesheets/active_admin/_base.scss +29 -29
  7. data/app/assets/stylesheets/active_admin/_header.scss +3 -5
  8. data/app/assets/stylesheets/active_admin/_mixins.scss +1 -1
  9. data/{vendor → app}/assets/stylesheets/active_admin/_normalize.scss +0 -0
  10. data/app/assets/stylesheets/active_admin/components/_tables.scss +1 -2
  11. data/app/assets/stylesheets/active_admin/mixins/_all.scss +8 -8
  12. data/app/assets/stylesheets/active_admin/mixins/_variables.scss +5 -0
  13. data/app/assets/stylesheets/active_admin/print.scss +2 -2
  14. data/app/assets/stylesheets/active_admin/structure/_main_structure.scss +1 -1
  15. data/app/javascript/active_admin/base.js +19 -0
  16. data/app/{assets/javascripts/active_admin/ext/jquery-ui.es6 → javascript/active_admin/ext/jquery-ui.js} +0 -0
  17. data/app/{assets/javascripts/active_admin/ext/jquery.es6 → javascript/active_admin/ext/jquery.js} +0 -0
  18. data/app/{assets/javascripts/active_admin/lib/batch_actions.es6 → javascript/active_admin/initializers/batch-actions.js} +9 -3
  19. data/app/javascript/active_admin/initializers/checkbox-toggler.js +3 -0
  20. data/app/{assets/javascripts/active_admin/initializers/datepicker.es6 → javascript/active_admin/initializers/datepicker.js} +0 -0
  21. data/app/javascript/active_admin/initializers/dropdown-menu.js +9 -0
  22. data/app/javascript/active_admin/initializers/filters.js +10 -0
  23. data/app/{assets/javascripts/active_admin/lib/has_many.es6 → javascript/active_admin/initializers/has-many.js} +0 -0
  24. data/app/javascript/active_admin/initializers/per-page.js +13 -0
  25. data/app/javascript/active_admin/initializers/table-checkbox-toggler.js +3 -0
  26. data/app/{assets/javascripts/active_admin/initializers/tabs.es6 → javascript/active_admin/initializers/tabs.js} +0 -0
  27. data/app/{assets/javascripts/active_admin/lib/checkbox-toggler.es6 → javascript/active_admin/lib/checkbox-toggler.js} +2 -2
  28. data/app/{assets/javascripts/active_admin/lib/dropdown-menu.es6 → javascript/active_admin/lib/dropdown-menu.js} +2 -9
  29. data/app/javascript/active_admin/lib/filters.js +39 -0
  30. data/app/{assets/javascripts/active_admin/lib/modal_dialog.es6 → javascript/active_admin/lib/modal-dialog.js} +3 -1
  31. data/app/javascript/active_admin/lib/per-page.js +38 -0
  32. data/app/{assets/javascripts/active_admin/lib/table-checkbox-toggler.es6 → javascript/active_admin/lib/table-checkbox-toggler.js} +4 -2
  33. data/app/javascript/active_admin/lib/utils.js +40 -0
  34. data/app/views/kaminari/active_admin_countless/_first_page.html.erb +11 -0
  35. data/app/views/kaminari/active_admin_countless/_gap.html.erb +8 -0
  36. data/app/views/kaminari/active_admin_countless/_next_page.html.erb +11 -0
  37. data/app/views/kaminari/active_admin_countless/_page.html.erb +12 -0
  38. data/app/views/kaminari/active_admin_countless/_paginator.html.erb +24 -0
  39. data/app/views/kaminari/active_admin_countless/_prev_page.html.erb +11 -0
  40. data/config/locales/ar.yml +3 -2
  41. data/config/locales/az.yml +138 -0
  42. data/config/locales/bg.yml +1 -0
  43. data/config/locales/bs.yml +1 -0
  44. data/config/locales/ca.yml +1 -1
  45. data/config/locales/cs.yml +1 -0
  46. data/config/locales/da.yml +1 -0
  47. data/config/locales/de-CH.yml +1 -0
  48. data/config/locales/de.yml +19 -0
  49. data/config/locales/el.yml +1 -0
  50. data/config/locales/en-CA.yml +1 -0
  51. data/config/locales/en-GB.yml +1 -0
  52. data/config/locales/en.yml +1 -0
  53. data/config/locales/eo.yml +1 -0
  54. data/config/locales/es-MX.yml +1 -0
  55. data/config/locales/es.yml +1 -0
  56. data/config/locales/fa.yml +1 -0
  57. data/config/locales/fi.yml +1 -0
  58. data/config/locales/fr.yml +2 -1
  59. data/config/locales/he.yml +1 -0
  60. data/config/locales/hr.yml +1 -0
  61. data/config/locales/hu.yml +1 -0
  62. data/config/locales/id.yml +1 -0
  63. data/config/locales/it.yml +1 -0
  64. data/config/locales/ja.yml +1 -0
  65. data/config/locales/ko.yml +1 -0
  66. data/config/locales/lt.yml +1 -0
  67. data/config/locales/lv.yml +1 -0
  68. data/config/locales/mk.yml +134 -0
  69. data/config/locales/nb.yml +1 -0
  70. data/config/locales/nl.yml +1 -0
  71. data/config/locales/pl.yml +1 -0
  72. data/config/locales/pt-BR.yml +1 -0
  73. data/config/locales/pt-PT.yml +1 -0
  74. data/config/locales/ro.yml +1 -0
  75. data/config/locales/ru.yml +1 -0
  76. data/config/locales/sk.yml +60 -0
  77. data/config/locales/sv-SE.yml +1 -0
  78. data/config/locales/tr.yml +1 -0
  79. data/config/locales/uk.yml +1 -0
  80. data/config/locales/vi.yml +1 -0
  81. data/config/locales/zh-CN.yml +1 -0
  82. data/config/locales/zh-TW.yml +1 -0
  83. data/docs/1-general-configuration.md +20 -0
  84. data/docs/12-arbre-components.md +13 -0
  85. data/docs/13-authorization-adapter.md +2 -2
  86. data/docs/2-resource-customization.md +1 -1
  87. data/docs/3-index-pages/index-as-table.md +7 -0
  88. data/docs/Gemfile +0 -1
  89. data/docs/Gemfile.lock +58 -58
  90. data/docs/_config.yml +2 -0
  91. data/docs/_includes/top-menu.html +2 -2
  92. data/docs/index.html +108 -7
  93. data/docs/stylesheets/main.css +29 -0
  94. data/lib/active_admin.rb +0 -1
  95. data/lib/active_admin/application.rb +12 -3
  96. data/lib/active_admin/batch_actions/resource_extension.rb +5 -1
  97. data/lib/active_admin/controller_action.rb +2 -1
  98. data/lib/active_admin/csv_builder.rb +3 -2
  99. data/lib/active_admin/dependency.rb +0 -4
  100. data/lib/active_admin/error.rb +3 -1
  101. data/lib/active_admin/filters/active_filter.rb +3 -4
  102. data/lib/active_admin/filters/resource_extension.rb +24 -0
  103. data/lib/active_admin/generators/boilerplate.rb +12 -4
  104. data/lib/active_admin/inputs/filters/date_range_input.rb +4 -4
  105. data/lib/active_admin/namespace_settings.rb +13 -0
  106. data/lib/active_admin/order_clause.rb +1 -1
  107. data/lib/active_admin/page_presenter.rb +2 -1
  108. data/lib/active_admin/pundit_adapter.rb +7 -3
  109. data/lib/active_admin/resource.rb +16 -2
  110. data/lib/active_admin/resource/belongs_to.rb +6 -1
  111. data/lib/active_admin/resource/model.rb +15 -0
  112. data/lib/active_admin/resource/routes.rb +11 -3
  113. data/lib/active_admin/resource_controller.rb +2 -0
  114. data/lib/active_admin/resource_controller/decorators.rb +2 -2
  115. data/lib/active_admin/resource_controller/polymorphic_routes.rb +37 -0
  116. data/lib/active_admin/router.rb +2 -1
  117. data/lib/active_admin/scope.rb +7 -3
  118. data/lib/active_admin/sidebar_section.rb +3 -1
  119. data/lib/active_admin/version.rb +1 -1
  120. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +2 -2
  121. data/lib/active_admin/view_helpers/display_helper.rb +3 -2
  122. data/lib/active_admin/views/components/paginated_collection.rb +3 -2
  123. data/lib/active_admin/views/components/status_tag.rb +5 -1
  124. data/lib/active_admin/views/components/table_for.rb +1 -0
  125. data/lib/active_admin/views/index_as_table.rb +7 -0
  126. data/lib/active_admin/views/pages/base.rb +1 -1
  127. data/lib/active_admin/views/pages/index.rb +1 -0
  128. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +14 -1
  129. data/lib/generators/active_admin/resource/templates/admin.rb.erb +40 -37
  130. data/lib/ransack_ext.rb +2 -2
  131. metadata +38 -45
  132. data/app/assets/images/active_admin/nested_menu_arrow.gif +0 -0
  133. data/app/assets/images/active_admin/nested_menu_arrow_dark.gif +0 -0
  134. data/app/assets/images/active_admin/orderable.png +0 -0
  135. data/app/assets/javascripts/active_admin/base.es6 +0 -23
  136. data/app/assets/javascripts/active_admin/initializers/filters.es6 +0 -45
  137. data/app/assets/javascripts/active_admin/lib/active_admin.es6 +0 -41
  138. data/app/assets/javascripts/active_admin/lib/per_page.es6 +0 -47
@@ -0,0 +1,509 @@
1
+ /**
2
+ * Warning: This file is auto-generated, do not modify. Instead, make your changes in 'app/javascript/active_admin/' and run `yarn build`
3
+ */
4
+ //= require jquery3
5
+ //= require jquery-ui/widgets/datepicker
6
+ //= require jquery-ui/widgets/dialog
7
+ //= require jquery-ui/widgets/sortable
8
+ //= require jquery-ui/widgets/tabs
9
+ //= require jquery-ui/widget
10
+ //= require jquery_ujs
11
+ //= require_self
12
+
13
+ (function(factory) {
14
+ typeof define === "function" && define.amd ? define([ "jquery", "jquery-ui/ui/widgets/datepicker", "jquery-ui/ui/widgets/dialog", "jquery-ui/ui/widgets/sortable", "jquery-ui/ui/widgets/tabs", "jquery-ui/ui/widget", "jquery-ujs" ], factory) : factory();
15
+ })(function() {
16
+ "use strict";
17
+ $.fn.serializeObject = function() {
18
+ return this.serializeArray().reduce(function(obj, item) {
19
+ obj[item.name] = item.value;
20
+ return obj;
21
+ }, {});
22
+ };
23
+ $.ui.dialog.prototype._focusTabbable = function() {
24
+ this.uiDialog.focus();
25
+ };
26
+ function ModalDialog(message, inputs, callback) {
27
+ var html = '<form id="dialog_confirm" title="' + message + '"><ul>';
28
+ for (var name in inputs) {
29
+ var elem, opts, wrapper;
30
+ var type = inputs[name];
31
+ if (/^(datepicker|checkbox|text|number)$/.test(type)) {
32
+ wrapper = "input";
33
+ } else if (type === "textarea") {
34
+ wrapper = "textarea";
35
+ } else if ($.isArray(type)) {
36
+ var _ref = [ "select", "option", type, "" ];
37
+ wrapper = _ref[0];
38
+ elem = _ref[1];
39
+ opts = _ref[2];
40
+ type = _ref[3];
41
+ } else {
42
+ throw new Error("Unsupported input type: {" + name + ": " + type + "}");
43
+ }
44
+ var klass = type === "datepicker" ? type : "";
45
+ html += "<li>\n <label>" + (name.charAt(0).toUpperCase() + name.slice(1)) + "</label>\n <" + wrapper + ' name="' + name + '" class="' + klass + '" type="' + type + '">' + (opts ? function() {
46
+ var result = [];
47
+ opts.forEach(function(v) {
48
+ var $elem = $("<" + elem + "/>");
49
+ if ($.isArray(v)) {
50
+ $elem.text(v[0]).val(v[1]);
51
+ } else {
52
+ $elem.text(v);
53
+ }
54
+ result.push($elem.wrap("<div>").parent().html());
55
+ });
56
+ return result;
57
+ }().join("") : "") + ("</" + wrapper + ">") + "</li>";
58
+ var _ref2 = [];
59
+ wrapper = _ref2[0];
60
+ elem = _ref2[1];
61
+ opts = _ref2[2];
62
+ type = _ref2[3];
63
+ klass = _ref2[4];
64
+ }
65
+ html += "</ul></form>";
66
+ var form = $(html).appendTo("body");
67
+ $("body").trigger("modal_dialog:before_open", [ form ]);
68
+ form.dialog({
69
+ modal: true,
70
+ open: function open(event, ui) {
71
+ $("body").trigger("modal_dialog:after_open", [ form ]);
72
+ },
73
+ dialogClass: "active_admin_dialog",
74
+ buttons: {
75
+ OK: function OK() {
76
+ callback($(this).serializeObject());
77
+ $(this).dialog("close");
78
+ },
79
+ Cancel: function Cancel() {
80
+ $(this).dialog("close").remove();
81
+ }
82
+ }
83
+ });
84
+ }
85
+ var onDOMReady = function onDOMReady() {
86
+ $(".batch_actions_selector li a").off("click confirm:complete");
87
+ $(".batch_actions_selector li a").on("click", function(event) {
88
+ var _this = this;
89
+ var message;
90
+ event.stopPropagation();
91
+ event.preventDefault();
92
+ if (message = $(this).data("confirm")) {
93
+ ModalDialog(message, $(this).data("inputs"), function(inputs) {
94
+ $(_this).trigger("confirm:complete", inputs);
95
+ });
96
+ } else {
97
+ $(this).trigger("confirm:complete");
98
+ }
99
+ });
100
+ $(".batch_actions_selector li a").on("confirm:complete", function(event, inputs) {
101
+ var val;
102
+ if (val = JSON.stringify(inputs)) {
103
+ $("#batch_action_inputs").removeAttr("disabled").val(val);
104
+ } else {
105
+ $("#batch_action_inputs").attr("disabled", "disabled");
106
+ }
107
+ $("#batch_action").val($(this).data("action"));
108
+ $("#collection_selection").submit();
109
+ });
110
+ if ($(".batch_actions_selector").length && $(":checkbox.toggle_all").length) {
111
+ if ($(".paginated_collection table.index_table").length) {
112
+ $(".paginated_collection table.index_table").tableCheckboxToggler();
113
+ } else {
114
+ $(".paginated_collection").checkboxToggler();
115
+ }
116
+ $(document).on("change", ".paginated_collection :checkbox", function() {
117
+ if ($(".paginated_collection :checkbox:checked").length && $(".dropdown_menu_list").children().length) {
118
+ $(".batch_actions_selector").each(function() {
119
+ $(this).aaDropdownMenu("enable");
120
+ });
121
+ } else {
122
+ $(".batch_actions_selector").each(function() {
123
+ $(this).aaDropdownMenu("disable");
124
+ });
125
+ }
126
+ });
127
+ }
128
+ };
129
+ $(document).ready(onDOMReady).on("page:load turbolinks:load", onDOMReady);
130
+ var CheckboxToggler = function() {
131
+ function CheckboxToggler(options, container) {
132
+ this.options = options;
133
+ this.container = container;
134
+ this._init();
135
+ this._bind();
136
+ }
137
+ var _proto = CheckboxToggler.prototype;
138
+ _proto.option = function option(key, value) {};
139
+ _proto._init = function _init() {
140
+ if (!this.container) {
141
+ throw new Error("Container element not found");
142
+ } else {
143
+ this.$container = $(this.container);
144
+ }
145
+ if (!this.$container.find(".toggle_all").length) {
146
+ throw new Error('"toggle all" checkbox not found');
147
+ } else {
148
+ this.toggle_all_checkbox = this.$container.find(".toggle_all");
149
+ }
150
+ this.checkboxes = this.$container.find(":checkbox").not(this.toggle_all_checkbox);
151
+ };
152
+ _proto._bind = function _bind() {
153
+ var _this = this;
154
+ this.checkboxes.change(function(event) {
155
+ return _this._didChangeCheckbox(event.target);
156
+ });
157
+ this.toggle_all_checkbox.change(function() {
158
+ return _this._didChangeToggleAllCheckbox();
159
+ });
160
+ };
161
+ _proto._didChangeCheckbox = function _didChangeCheckbox(checkbox) {
162
+ var numChecked = this.checkboxes.filter(":checked").length;
163
+ var allChecked = numChecked === this.checkboxes.length;
164
+ var someChecked = numChecked > 0 && numChecked < this.checkboxes.length;
165
+ this.toggle_all_checkbox.prop({
166
+ checked: allChecked,
167
+ indeterminate: someChecked
168
+ });
169
+ };
170
+ _proto._didChangeToggleAllCheckbox = function _didChangeToggleAllCheckbox() {
171
+ var setting = this.toggle_all_checkbox.prop("checked");
172
+ this.checkboxes.prop({
173
+ checked: setting
174
+ });
175
+ return setting;
176
+ };
177
+ return CheckboxToggler;
178
+ }();
179
+ $.widget.bridge("checkboxToggler", CheckboxToggler);
180
+ (function($) {
181
+ $(document).on("focus", "input.datepicker:not(.hasDatepicker)", function() {
182
+ var input = $(this);
183
+ if (input[0].type === "date") {
184
+ return;
185
+ }
186
+ var defaults = {
187
+ dateFormat: "yy-mm-dd"
188
+ };
189
+ var options = input.data("datepicker-options");
190
+ input.datepicker($.extend(defaults, options));
191
+ });
192
+ })(jQuery);
193
+ var DropdownMenu = function() {
194
+ function DropdownMenu(options, element) {
195
+ this.options = options;
196
+ this.element = element;
197
+ this.$element = $(this.element);
198
+ var defaults = {
199
+ fadeInDuration: 20,
200
+ fadeOutDuration: 100,
201
+ onClickActionItemCallback: null
202
+ };
203
+ this.options = $.extend(defaults, this.options);
204
+ this.isOpen = false;
205
+ this.$menuButton = this.$element.find(".dropdown_menu_button");
206
+ this.$menuList = this.$element.find(".dropdown_menu_list_wrapper");
207
+ this._buildMenuList();
208
+ this._bind();
209
+ }
210
+ var _proto = DropdownMenu.prototype;
211
+ _proto.open = function open() {
212
+ this.isOpen = true;
213
+ this.$menuList.fadeIn(this.options.fadeInDuration);
214
+ this._position();
215
+ return this;
216
+ };
217
+ _proto.close = function close() {
218
+ this.isOpen = false;
219
+ this.$menuList.fadeOut(this.options.fadeOutDuration);
220
+ return this;
221
+ };
222
+ _proto.destroy = function destroy() {
223
+ this.$element = null;
224
+ return this;
225
+ };
226
+ _proto.isDisabled = function isDisabled() {
227
+ return this.$menuButton.hasClass("disabled");
228
+ };
229
+ _proto.disable = function disable() {
230
+ this.$menuButton.addClass("disabled");
231
+ };
232
+ _proto.enable = function enable() {
233
+ this.$menuButton.removeClass("disabled");
234
+ };
235
+ _proto.option = function option(key, value) {
236
+ if ($.isPlainObject(key)) {
237
+ return this.options = $.extend(true, this.options, key);
238
+ } else if (key != null) {
239
+ return this.options[key];
240
+ } else {
241
+ return this.options[key] = value;
242
+ }
243
+ };
244
+ _proto._buildMenuList = function _buildMenuList() {
245
+ this.$nipple = $('<div class="dropdown_menu_nipple"></div>');
246
+ this.$menuList.prepend(this.$nipple);
247
+ this.$menuList.hide();
248
+ };
249
+ _proto._bind = function _bind() {
250
+ var _this = this;
251
+ $("body").click(function() {
252
+ if (_this.isOpen) {
253
+ _this.close();
254
+ }
255
+ });
256
+ this.$menuButton.click(function() {
257
+ if (!_this.isDisabled()) {
258
+ if (_this.isOpen) {
259
+ _this.close();
260
+ } else {
261
+ _this.open();
262
+ }
263
+ }
264
+ return false;
265
+ });
266
+ };
267
+ _proto._position = function _position() {
268
+ this.$menuList.css("top", this.$menuButton.position().top + this.$menuButton.outerHeight() + 10);
269
+ var button_left = this.$menuButton.position().left;
270
+ var button_center = this.$menuButton.outerWidth() / 2;
271
+ var button_right = button_left + button_center * 2;
272
+ var menu_center = this.$menuList.outerWidth() / 2;
273
+ var nipple_center = this.$nipple.outerWidth() / 2;
274
+ var window_right = $(window).width();
275
+ var centered_menu_left = button_left + button_center - menu_center;
276
+ var centered_menu_right = button_left + button_center + menu_center;
277
+ if (centered_menu_left < 0) {
278
+ this.$menuList.css("left", button_left);
279
+ this.$nipple.css("left", button_center - nipple_center);
280
+ } else if (centered_menu_right > window_right) {
281
+ this.$menuList.css("right", window_right - button_right);
282
+ this.$nipple.css("right", button_center - nipple_center);
283
+ } else {
284
+ this.$menuList.css("left", centered_menu_left);
285
+ this.$nipple.css("left", menu_center - nipple_center);
286
+ }
287
+ };
288
+ return DropdownMenu;
289
+ }();
290
+ $.widget.bridge("aaDropdownMenu", DropdownMenu);
291
+ var onDOMReady$1 = function onDOMReady() {
292
+ return $(".dropdown_menu").aaDropdownMenu();
293
+ };
294
+ $(document).ready(onDOMReady$1).on("page:load turbolinks:load", onDOMReady$1);
295
+ function hasTurbolinks() {
296
+ return typeof Turbolinks !== "undefined" && Turbolinks.supported;
297
+ }
298
+ function turbolinksVisit(params) {
299
+ var path = [ window.location.pathname, "?", toQueryString(params) ].join("");
300
+ Turbolinks.visit(path);
301
+ }
302
+ function queryString() {
303
+ return (window.location.search || "").replace(/^\?/, "");
304
+ }
305
+ function queryStringToParams() {
306
+ var decode = function decode(value) {
307
+ return decodeURIComponent((value || "").replace(/\+/g, "%20"));
308
+ };
309
+ return queryString().split("&").map(function(pair) {
310
+ return pair.split("=");
311
+ }).map(function(_ref) {
312
+ var key = _ref[0], value = _ref[1];
313
+ return {
314
+ name: decode(key),
315
+ value: decode(value)
316
+ };
317
+ });
318
+ }
319
+ function toQueryString(params) {
320
+ var encode = function encode(value) {
321
+ return encodeURIComponent(value || "");
322
+ };
323
+ return params.map(function(_ref2) {
324
+ var name = _ref2.name, value = _ref2.value;
325
+ return [ encode(name), encode(value) ];
326
+ }).map(function(pair) {
327
+ return pair.join("=");
328
+ }).join("&");
329
+ }
330
+ var Filters = function() {
331
+ function Filters() {}
332
+ Filters._clearForm = function _clearForm(event) {
333
+ var regex = /^(q\[|q%5B|q%5b|page|utf8|commit)/;
334
+ var params = queryStringToParams().filter(function(_ref) {
335
+ var name = _ref.name;
336
+ return !name.match(regex);
337
+ });
338
+ event.preventDefault();
339
+ if (hasTurbolinks()) {
340
+ turbolinksVisit(params);
341
+ } else {
342
+ window.location.search = toQueryString(params);
343
+ }
344
+ };
345
+ Filters._disableEmptyInputFields = function _disableEmptyInputFields(event) {
346
+ var params = $(this).find(":input").filter(function(i, input) {
347
+ return input.value === "";
348
+ }).prop({
349
+ disabled: true
350
+ }).end().serializeArray();
351
+ if (hasTurbolinks()) {
352
+ event.preventDefault();
353
+ turbolinksVisit(params);
354
+ }
355
+ };
356
+ Filters._setSearchType = function _setSearchType() {
357
+ $(this).siblings("input").prop({
358
+ name: "q[" + this.value + "]"
359
+ });
360
+ };
361
+ return Filters;
362
+ }();
363
+ (function($) {
364
+ $(document).on("click", ".clear_filters_btn", Filters._clearForm).on("submit", ".filter_form", Filters._disableEmptyInputFields).on("change", ".filter_form_field.select_and_search select", Filters._setSearchType);
365
+ })(jQuery);
366
+ $(function() {
367
+ $(document).on("click", "a.button.has_many_remove", function(event) {
368
+ event.preventDefault();
369
+ var parent = $(this).closest(".has_many_container");
370
+ var to_remove = $(this).closest("fieldset");
371
+ recompute_positions(parent);
372
+ parent.trigger("has_many_remove:before", [ to_remove, parent ]);
373
+ to_remove.remove();
374
+ return parent.trigger("has_many_remove:after", [ to_remove, parent ]);
375
+ });
376
+ $(document).on("click", "a.button.has_many_add", function(event) {
377
+ var before_add;
378
+ event.preventDefault();
379
+ var parent = $(this).closest(".has_many_container");
380
+ parent.trigger(before_add = $.Event("has_many_add:before"), [ parent ]);
381
+ if (!before_add.isDefaultPrevented()) {
382
+ var index = parent.data("has_many_index") || parent.children("fieldset").length - 1;
383
+ parent.data({
384
+ has_many_index: ++index
385
+ });
386
+ var regex = new RegExp($(this).data("placeholder"), "g");
387
+ var html = $(this).data("html").replace(regex, index);
388
+ var fieldset = $(html).insertBefore(this);
389
+ recompute_positions(parent);
390
+ return parent.trigger("has_many_add:after", [ fieldset, parent ]);
391
+ }
392
+ });
393
+ $(document).on("change", '.has_many_container[data-sortable] :input[name$="[_destroy]"]', function() {
394
+ recompute_positions($(this).closest(".has_many"));
395
+ });
396
+ init_sortable();
397
+ $(document).on("has_many_add:after", ".has_many_container", init_sortable);
398
+ });
399
+ var init_sortable = function init_sortable() {
400
+ var elems = $(".has_many_container[data-sortable]:not(.ui-sortable)");
401
+ elems.sortable({
402
+ items: "> fieldset",
403
+ handle: "> ol > .handle",
404
+ start: function start(ev, ui) {
405
+ ui.item.css({
406
+ opacity: .3
407
+ });
408
+ },
409
+ stop: function stop(ev, ui) {
410
+ ui.item.css({
411
+ opacity: 1
412
+ });
413
+ recompute_positions($(this));
414
+ }
415
+ });
416
+ elems.each(recompute_positions);
417
+ };
418
+ var recompute_positions = function recompute_positions(parent) {
419
+ parent = parent instanceof jQuery ? parent : $(this);
420
+ var input_name = parent.data("sortable");
421
+ var position = parseInt(parent.data("sortable-start") || 0, 10);
422
+ parent.children("fieldset").each(function() {
423
+ var destroy_input = $(this).find("> ol > .input > :input[name$='[_destroy]']");
424
+ var sortable_input = $(this).find("> ol > .input > :input[name$='[" + input_name + "]']");
425
+ if (sortable_input.length) {
426
+ sortable_input.val(destroy_input.is(":checked") ? "" : position++);
427
+ }
428
+ });
429
+ };
430
+ var PerPage = function() {
431
+ function PerPage(element) {
432
+ this.element = element;
433
+ }
434
+ var _proto = PerPage.prototype;
435
+ _proto.update = function update() {
436
+ var params = queryStringToParams().filter(function(_ref) {
437
+ var name = _ref.name;
438
+ return name != "per_page" || name != "page";
439
+ });
440
+ params.push({
441
+ name: "per_page",
442
+ value: this.element.value
443
+ });
444
+ if (hasTurbolinks()) {
445
+ turbolinksVisit(params);
446
+ } else {
447
+ window.location.search = toQueryString(params);
448
+ }
449
+ };
450
+ PerPage._jQueryInterface = function _jQueryInterface(config) {
451
+ return this.each(function() {
452
+ var $this = $(this);
453
+ var data = $this.data("perPage");
454
+ if (!data) {
455
+ data = new PerPage(this);
456
+ $this.data("perPage", data);
457
+ }
458
+ if (config === "update") {
459
+ data[config]();
460
+ }
461
+ });
462
+ };
463
+ return PerPage;
464
+ }();
465
+ (function($) {
466
+ $(document).on("change", ".pagination_per_page > select", function(event) {
467
+ PerPage._jQueryInterface.call($(this), "update");
468
+ });
469
+ $.fn["perPage"] = PerPage._jQueryInterface;
470
+ $.fn["perPage"].Constructor = PerPage;
471
+ })(jQuery);
472
+ function _inheritsLoose(subClass, superClass) {
473
+ subClass.prototype = Object.create(superClass.prototype);
474
+ subClass.prototype.constructor = subClass;
475
+ subClass.__proto__ = superClass;
476
+ }
477
+ var TableCheckboxToggler = function(_CheckboxToggler) {
478
+ _inheritsLoose(TableCheckboxToggler, _CheckboxToggler);
479
+ function TableCheckboxToggler() {
480
+ return _CheckboxToggler.apply(this, arguments) || this;
481
+ }
482
+ var _proto = TableCheckboxToggler.prototype;
483
+ _proto._bind = function _bind() {
484
+ var _this = this;
485
+ _CheckboxToggler.prototype._bind.apply(this, arguments);
486
+ this.$container.find("tbody td").click(function(event) {
487
+ if (event.target.type !== "checkbox") {
488
+ _this._didClickCell(event.target);
489
+ }
490
+ });
491
+ };
492
+ _proto._didChangeCheckbox = function _didChangeCheckbox(checkbox) {
493
+ _CheckboxToggler.prototype._didChangeCheckbox.apply(this, arguments);
494
+ $(checkbox).parents("tr").toggleClass("selected", checkbox.checked);
495
+ };
496
+ _proto._didChangeToggleAllCheckbox = function _didChangeToggleAllCheckbox() {
497
+ this.$container.find("tbody tr").toggleClass("selected", _CheckboxToggler.prototype._didChangeToggleAllCheckbox.apply(this, arguments));
498
+ };
499
+ _proto._didClickCell = function _didClickCell(cell) {
500
+ $(cell).parent("tr").find(":checkbox").click();
501
+ };
502
+ return TableCheckboxToggler;
503
+ }(CheckboxToggler);
504
+ $.widget.bridge("tableCheckboxToggler", TableCheckboxToggler);
505
+ var onDOMReady$2 = function onDOMReady() {
506
+ return $("#active_admin_content .tabs").tabs();
507
+ };
508
+ $(document).ready(onDOMReady$2).on("page:load turbolinks:load", onDOMReady$2);
509
+ });