activeadmin_addons 1.10.0 → 2.0.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -17
  3. data/app/inputs/active_admin/inputs/select_input.rb +9 -5
  4. data/app/inputs/nested_level_input.rb +13 -7
  5. data/app/inputs/nested_select_input.rb +19 -13
  6. data/app/inputs/search_select_filter_input.rb +15 -1
  7. data/app/inputs/search_select_input.rb +6 -5
  8. data/app/inputs/tags_input.rb +5 -34
  9. data/app/javascript/activeadmin_addons/addons/slim-select-interactive-tag.js +78 -0
  10. data/app/javascript/activeadmin_addons/all.js +2 -7
  11. data/app/javascript/activeadmin_addons/config.js +8 -5
  12. data/app/javascript/activeadmin_addons/inputs/slim-select-nested.js +95 -0
  13. data/app/javascript/activeadmin_addons/inputs/slim-select-search.js +37 -0
  14. data/app/javascript/activeadmin_addons/inputs/slim-select-selected-list.js +103 -0
  15. data/app/javascript/activeadmin_addons/inputs/slim-select-simple-tags.js +22 -0
  16. data/app/javascript/activeadmin_addons/inputs/slim-select-tags.js +28 -0
  17. data/app/javascript/activeadmin_addons/inputs/slim-select-utils.js +70 -0
  18. data/app/javascript/activeadmin_addons/inputs/slim-select.js +93 -0
  19. data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/all.scss +4 -10
  20. data/app/javascript/activeadmin_addons/stylesheets/imports/slimselect.css +1 -0
  21. data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/inputs/selected-list.scss +0 -1
  22. data/app/javascript/activeadmin_addons/stylesheets/inputs/slim-select.scss +9 -0
  23. data/lib/activeadmin_addons/addons/image_builder.rb +2 -9
  24. data/lib/activeadmin_addons/addons/state_builder.rb +1 -0
  25. data/lib/activeadmin_addons/addons/tag_builder.rb +3 -22
  26. data/lib/activeadmin_addons/engine.rb +1 -6
  27. data/lib/activeadmin_addons/support/custom_builder.rb +1 -1
  28. data/lib/activeadmin_addons/support/input_base.rb +0 -42
  29. data/lib/activeadmin_addons/support/input_helpers/filter_input_methods.rb +1 -0
  30. data/lib/activeadmin_addons/support/input_helpers/input_html_helpers.rb +42 -0
  31. data/lib/activeadmin_addons/support/input_helpers/select_helpers.rb +10 -12
  32. data/lib/activeadmin_addons/support/select_filter_input_extension.rb +1 -3
  33. data/lib/activeadmin_addons/support/select_input_base.rb +11 -0
  34. data/lib/activeadmin_addons/version.rb +1 -1
  35. data/lib/activeadmin_addons.rb +4 -1
  36. data/lib/generators/activeadmin_addons/install/install_generator.rb +2 -1
  37. data/lib/generators/activeadmin_addons/install/templates/initializer.rb +2 -2
  38. data/lib/generators/activeadmin_addons/webpacker/webpacker_generator.rb +3 -6
  39. metadata +82 -196
  40. data/app/assets/images/fileicons/file_extension_3gp.png +0 -0
  41. data/app/assets/images/fileicons/file_extension_7z.png +0 -0
  42. data/app/assets/images/fileicons/file_extension_ace.png +0 -0
  43. data/app/assets/images/fileicons/file_extension_ai.png +0 -0
  44. data/app/assets/images/fileicons/file_extension_aif.png +0 -0
  45. data/app/assets/images/fileicons/file_extension_aiff.png +0 -0
  46. data/app/assets/images/fileicons/file_extension_amr.png +0 -0
  47. data/app/assets/images/fileicons/file_extension_asf.png +0 -0
  48. data/app/assets/images/fileicons/file_extension_asx.png +0 -0
  49. data/app/assets/images/fileicons/file_extension_bat.png +0 -0
  50. data/app/assets/images/fileicons/file_extension_bin.png +0 -0
  51. data/app/assets/images/fileicons/file_extension_bmp.png +0 -0
  52. data/app/assets/images/fileicons/file_extension_bup.png +0 -0
  53. data/app/assets/images/fileicons/file_extension_cab.png +0 -0
  54. data/app/assets/images/fileicons/file_extension_cbr.png +0 -0
  55. data/app/assets/images/fileicons/file_extension_cda.png +0 -0
  56. data/app/assets/images/fileicons/file_extension_cdl.png +0 -0
  57. data/app/assets/images/fileicons/file_extension_cdr.png +0 -0
  58. data/app/assets/images/fileicons/file_extension_chm.png +0 -0
  59. data/app/assets/images/fileicons/file_extension_dat.png +0 -0
  60. data/app/assets/images/fileicons/file_extension_divx.png +0 -0
  61. data/app/assets/images/fileicons/file_extension_dll.png +0 -0
  62. data/app/assets/images/fileicons/file_extension_dmg.png +0 -0
  63. data/app/assets/images/fileicons/file_extension_doc.png +0 -0
  64. data/app/assets/images/fileicons/file_extension_docx.png +0 -0
  65. data/app/assets/images/fileicons/file_extension_dss.png +0 -0
  66. data/app/assets/images/fileicons/file_extension_dvf.png +0 -0
  67. data/app/assets/images/fileicons/file_extension_dwg.png +0 -0
  68. data/app/assets/images/fileicons/file_extension_eml.png +0 -0
  69. data/app/assets/images/fileicons/file_extension_eps.png +0 -0
  70. data/app/assets/images/fileicons/file_extension_exe.png +0 -0
  71. data/app/assets/images/fileicons/file_extension_fla.png +0 -0
  72. data/app/assets/images/fileicons/file_extension_flv.png +0 -0
  73. data/app/assets/images/fileicons/file_extension_gif.png +0 -0
  74. data/app/assets/images/fileicons/file_extension_gz.png +0 -0
  75. data/app/assets/images/fileicons/file_extension_hqx.png +0 -0
  76. data/app/assets/images/fileicons/file_extension_htm.png +0 -0
  77. data/app/assets/images/fileicons/file_extension_html.png +0 -0
  78. data/app/assets/images/fileicons/file_extension_ifo.png +0 -0
  79. data/app/assets/images/fileicons/file_extension_indd.png +0 -0
  80. data/app/assets/images/fileicons/file_extension_iso.png +0 -0
  81. data/app/assets/images/fileicons/file_extension_jar.png +0 -0
  82. data/app/assets/images/fileicons/file_extension_jpeg.png +0 -0
  83. data/app/assets/images/fileicons/file_extension_jpg.png +0 -0
  84. data/app/assets/images/fileicons/file_extension_lnk.png +0 -0
  85. data/app/assets/images/fileicons/file_extension_log.png +0 -0
  86. data/app/assets/images/fileicons/file_extension_m4a.png +0 -0
  87. data/app/assets/images/fileicons/file_extension_m4b.png +0 -0
  88. data/app/assets/images/fileicons/file_extension_m4p.png +0 -0
  89. data/app/assets/images/fileicons/file_extension_m4v.png +0 -0
  90. data/app/assets/images/fileicons/file_extension_mcd.png +0 -0
  91. data/app/assets/images/fileicons/file_extension_mdb.png +0 -0
  92. data/app/assets/images/fileicons/file_extension_mid.png +0 -0
  93. data/app/assets/images/fileicons/file_extension_mov.png +0 -0
  94. data/app/assets/images/fileicons/file_extension_mp2.png +0 -0
  95. data/app/assets/images/fileicons/file_extension_mp3.png +0 -0
  96. data/app/assets/images/fileicons/file_extension_mp4.png +0 -0
  97. data/app/assets/images/fileicons/file_extension_mpeg.png +0 -0
  98. data/app/assets/images/fileicons/file_extension_mpg.png +0 -0
  99. data/app/assets/images/fileicons/file_extension_msi.png +0 -0
  100. data/app/assets/images/fileicons/file_extension_mswmm.png +0 -0
  101. data/app/assets/images/fileicons/file_extension_ogg.png +0 -0
  102. data/app/assets/images/fileicons/file_extension_pdf.png +0 -0
  103. data/app/assets/images/fileicons/file_extension_png.png +0 -0
  104. data/app/assets/images/fileicons/file_extension_pps.png +0 -0
  105. data/app/assets/images/fileicons/file_extension_ppt.png +0 -0
  106. data/app/assets/images/fileicons/file_extension_pptx.png +0 -0
  107. data/app/assets/images/fileicons/file_extension_ps.png +0 -0
  108. data/app/assets/images/fileicons/file_extension_psd.png +0 -0
  109. data/app/assets/images/fileicons/file_extension_pst.png +0 -0
  110. data/app/assets/images/fileicons/file_extension_ptb.png +0 -0
  111. data/app/assets/images/fileicons/file_extension_pub.png +0 -0
  112. data/app/assets/images/fileicons/file_extension_qbb.png +0 -0
  113. data/app/assets/images/fileicons/file_extension_qbw.png +0 -0
  114. data/app/assets/images/fileicons/file_extension_qxd.png +0 -0
  115. data/app/assets/images/fileicons/file_extension_ram.png +0 -0
  116. data/app/assets/images/fileicons/file_extension_rar.png +0 -0
  117. data/app/assets/images/fileicons/file_extension_rm.png +0 -0
  118. data/app/assets/images/fileicons/file_extension_rmvb.png +0 -0
  119. data/app/assets/images/fileicons/file_extension_rtf.png +0 -0
  120. data/app/assets/images/fileicons/file_extension_sea.png +0 -0
  121. data/app/assets/images/fileicons/file_extension_ses.png +0 -0
  122. data/app/assets/images/fileicons/file_extension_sit.png +0 -0
  123. data/app/assets/images/fileicons/file_extension_sitx.png +0 -0
  124. data/app/assets/images/fileicons/file_extension_ss.png +0 -0
  125. data/app/assets/images/fileicons/file_extension_swf.png +0 -0
  126. data/app/assets/images/fileicons/file_extension_tgz.png +0 -0
  127. data/app/assets/images/fileicons/file_extension_thm.png +0 -0
  128. data/app/assets/images/fileicons/file_extension_tif.png +0 -0
  129. data/app/assets/images/fileicons/file_extension_tmp.png +0 -0
  130. data/app/assets/images/fileicons/file_extension_torrent.png +0 -0
  131. data/app/assets/images/fileicons/file_extension_ttf.png +0 -0
  132. data/app/assets/images/fileicons/file_extension_txt.png +0 -0
  133. data/app/assets/images/fileicons/file_extension_unknown.png +0 -0
  134. data/app/assets/images/fileicons/file_extension_vcd.png +0 -0
  135. data/app/assets/images/fileicons/file_extension_vob.png +0 -0
  136. data/app/assets/images/fileicons/file_extension_wav.png +0 -0
  137. data/app/assets/images/fileicons/file_extension_wma.png +0 -0
  138. data/app/assets/images/fileicons/file_extension_wmv.png +0 -0
  139. data/app/assets/images/fileicons/file_extension_wps.png +0 -0
  140. data/app/assets/images/fileicons/file_extension_xls.png +0 -0
  141. data/app/assets/images/fileicons/file_extension_xlsx.png +0 -0
  142. data/app/assets/images/fileicons/file_extension_xpi.png +0 -0
  143. data/app/assets/images/fileicons/file_extension_zip.png +0 -0
  144. data/app/assets/images/material/icons/keyboard_arrow_down.svg +0 -4
  145. data/app/assets/images/material/icons/keyboard_arrow_left.svg +0 -4
  146. data/app/assets/images/material/icons/keyboard_arrow_right.svg +0 -4
  147. data/app/assets/images/material/icons/keyboard_arrow_up.svg +0 -4
  148. data/app/assets/images/material/icons/today.svg +0 -4
  149. data/app/assets/javascripts/activeadmin_addons/all.js +0 -753
  150. data/app/assets/stylesheets/activeadmin_addons/addons/material-datepicker.scss +0 -173
  151. data/app/assets/stylesheets/activeadmin_addons/addons/material-toggle_bool.scss +0 -52
  152. data/app/assets/stylesheets/activeadmin_addons/inputs/select2.scss +0 -3
  153. data/app/assets/stylesheets/activeadmin_addons/material.scss +0 -53
  154. data/app/javascript/activeadmin_addons/addons/interactive_select_tag.js +0 -95
  155. data/app/javascript/activeadmin_addons/inputs/nested-select.js +0 -170
  156. data/app/javascript/activeadmin_addons/inputs/search-select.js +0 -76
  157. data/app/javascript/activeadmin_addons/inputs/select2.js +0 -52
  158. data/app/javascript/activeadmin_addons/inputs/selected-list.js +0 -107
  159. data/app/javascript/activeadmin_addons/inputs/tags.js +0 -76
  160. data/lib/activeadmin_addons/addons/attachment_builder.rb +0 -60
  161. data/lib/activeadmin_addons/support/enumerize_formtastic_support.rb +0 -18
  162. data/lib/generators/activeadmin_addons/assets/assets_generator.rb +0 -53
  163. data/vendor/assets/select2/select2.css +0 -481
  164. data/vendor/assets/select2/select2.full.js +0 -6820
  165. /data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/addons/interactive_select_tag.scss +0 -0
  166. /data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/addons/toggle_bool.scss +0 -0
  167. /data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/imports/jquery-datepicker.scss +0 -0
  168. /data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/inputs/color-picker.scss +0 -0
  169. /data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/inputs/date-time-picker-filter.scss +0 -0
  170. /data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/inputs/date-time-picker.scss +0 -0
  171. /data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/inputs/numeric-range-filter.scss +0 -0
  172. /data/app/{assets/stylesheets/activeadmin_addons → javascript/activeadmin_addons/stylesheets}/vendor/palette-color-picker.scss +0 -0
@@ -1,753 +0,0 @@
1
- /* eslint-disable */
2
- /**
3
- * Warning: This file is auto-generated, do not modify. Instead, make your changes in 'app/javascript/activeadmin_addons/' and run `yarn build`
4
- */
5
- //= require select2.full
6
- //= require jquery.xdan.datetimepicker.full
7
-
8
- (function(factory) {
9
- typeof define === "function" && define.amd ? define([ "select2", "jquery-datetimepicker" ], factory) : factory();
10
- })(function() {
11
- "use strict";
12
- (function($) {
13
- $.paletteColorPicker = function(el, options) {
14
- var ns = "palette-color-picker", $el = $(el), plugin = this, current_value = $el.val(), target = $el.attr("name"), $button = $("<div>").addClass(ns + "-button").attr("data-target", target), $bubble = $("<div>").addClass(ns + "-bubble"), defaults = {
15
- custom_class: null,
16
- colors: null,
17
- position: "upside",
18
- insert: "before",
19
- clear_btn: "first",
20
- timeout: 2e3,
21
- set_background: false,
22
- close_all_but_this: false
23
- }, click_handler = "ontouchstart" in document.documentElement ? "touchstart click" : "click";
24
- plugin.init = function() {
25
- plugin.settings = $.extend({}, defaults, options);
26
- var val = $el.attr("value");
27
- if (typeof val === typeof undefined || val === false) {
28
- val = "";
29
- $el.attr("value", val);
30
- }
31
- $el.attr("data-initialvalue", $el.attr("value"));
32
- if (plugin.settings.colors === null) {
33
- plugin.settings.colors = $el.data("palette");
34
- }
35
- if (typeof plugin.settings.colors[0] === "string") {
36
- plugin.settings.colors = $.map(plugin.settings.colors, function(el, idx) {
37
- var b = {};
38
- b[el] = el;
39
- return b;
40
- });
41
- }
42
- plugin.settings.insert = plugin.settings.insert.charAt(0).toUpperCase() + plugin.settings.insert.slice(1);
43
- if (plugin.settings.custom_class) {
44
- $bubble.addClass(plugin.settings.custom_class);
45
- }
46
- $.each(plugin.settings.colors, function(idx, obj) {
47
- var key = Object.keys(obj)[0], col = obj[key], $sw = $("<span>").addClass("swatch").attr({
48
- title: key,
49
- "data-color": col,
50
- "data-name": key
51
- }).css("background-color", col);
52
- if (key === current_value) {
53
- $sw.addClass("active");
54
- $button.css("background", col);
55
- }
56
- $sw.appendTo($bubble);
57
- });
58
- if (plugin.settings.clear_btn !== null) {
59
- var $clear_btn = $("<span>").addClass("swatch clear").attr("title", "Clear selection");
60
- if (plugin.settings.clear_btn === "last") {
61
- $clear_btn.addClass("last").appendTo($bubble);
62
- } else {
63
- $clear_btn.prependTo($bubble);
64
- }
65
- }
66
- plugin.destroy = function() {
67
- $button.remove();
68
- $.removeData($el[0]);
69
- };
70
- plugin.clear = function() {
71
- $bubble.find(".active").removeClass("active");
72
- $button.removeAttr("style");
73
- $el.val("");
74
- };
75
- plugin.reset = function() {
76
- if ($el.attr("data-initialvalue") === "") {
77
- plugin.clear();
78
- } else {
79
- var iv = $el.attr("data-initialvalue");
80
- $bubble.find('[data-name="' + iv + '"]').trigger("click");
81
- }
82
- };
83
- plugin.reload = function() {
84
- var newVal = $el.val();
85
- if (newVal === "" || typeof newVal === typeof undefined || newVal === false) {
86
- plugin.reset();
87
- } else {
88
- if ($bubble.find('[data-name="' + newVal + '"]').length) {
89
- $bubble.find('[data-name="' + newVal + '"]').trigger("click");
90
- } else {
91
- plugin.reset();
92
- }
93
- }
94
- };
95
- $button.append($bubble).on(click_handler, function(e) {
96
- e.preventDefault();
97
- e.stopPropagation();
98
- var $b = $(this);
99
- if (!$(e.target).hasClass(ns + "-bubble")) {
100
- if (typeof plugin.settings.onbeforeshow_callback === "function") {
101
- plugin.settings.onbeforeshow_callback(this);
102
- }
103
- $b.toggleClass("active");
104
- var $current_bubble = $b.find("." + ns + "-bubble");
105
- if (plugin.settings.close_all_but_this) {
106
- $("." + ns + "-bubble").not($current_bubble).fadeOut();
107
- }
108
- $current_bubble.fadeToggle();
109
- if ($b.hasClass("active")) {
110
- clearTimeout(plugin.timer);
111
- plugin.timer = setTimeout(function() {
112
- $b.trigger("pcp.fadeout");
113
- }, plugin.settings.timeout);
114
- }
115
- }
116
- }).on("pcp.fadeout", function() {
117
- $(this).removeClass("active").find("." + ns + "-bubble").fadeOut();
118
- }).on("mouseenter", "." + ns + "-bubble", function() {
119
- clearTimeout(plugin.timer);
120
- }).on("mouseleave", "." + ns + "-bubble", function() {
121
- plugin.timer = setTimeout(function() {
122
- $button.trigger("pcp.fadeout");
123
- }, plugin.settings.timeout);
124
- }).on(click_handler, "." + ns + "-bubble span.swatch", function(e) {
125
- e.preventDefault();
126
- e.stopPropagation();
127
- var col = $(this).attr("data-color"), name = $(this).attr("data-name"), $button = $("." + ns + '-button[data-target="' + $(this).closest("." + ns + "-button").attr("data-target") + '"]'), $bubble = $(this).closest("." + ns + "-bubble");
128
- $bubble.find(".active").removeClass("active");
129
- if ($(e.target).is(".clear")) {
130
- $button.removeAttr("style");
131
- col = "";
132
- } else {
133
- $(this).addClass("active");
134
- $button.css("background", col);
135
- }
136
- if (typeof plugin.settings.onchange_callback === "function") {
137
- plugin.settings.onchange_callback(col);
138
- }
139
- if (plugin.settings.set_background === false) {
140
- $('[name="' + $button.attr("data-target") + '"]').val(name);
141
- } else {
142
- $('[name="' + $button.attr("data-target") + '"]').css({
143
- "background-color": col
144
- });
145
- }
146
- })["insert" + plugin.settings.insert]($el);
147
- if (plugin.settings.position === "downside" || $el.offset().top + 20 < $bubble.outerHeight()) {
148
- $bubble.addClass("downside");
149
- }
150
- };
151
- $("body").on(click_handler, function(event) {
152
- if (!$(event.target).hasClass(ns + "-button")) {
153
- $($button).removeClass("active").find("." + ns + "-bubble").fadeOut();
154
- }
155
- });
156
- plugin.init();
157
- };
158
- $.fn.paletteColorPicker = function(options) {
159
- return this.each(function() {
160
- if (typeof $(this).data("paletteColorPickerPlugin") === "undefined") {
161
- $(this).data("paletteColorPickerPlugin", new $.paletteColorPicker(this, options));
162
- }
163
- });
164
- };
165
- })(jQuery);
166
- var initializer$9 = function() {
167
- window.ActiveadminAddons = {
168
- config: {
169
- defaultSelect: $("body").data("default-select")
170
- }
171
- };
172
- };
173
- $(initializer$9);
174
- $(document).on("turbolinks:load turbo:load", initializer$9);
175
- var initializer$8 = function() {
176
- configureSelect2(document);
177
- $(document).on("has_many_add:after", function(event, container) {
178
- configureSelect2(container);
179
- });
180
- function configureSelect2(container) {
181
- if (window.ActiveadminAddons.config.defaultSelect == "select2") {
182
- $("select:not(.default-select)", container).each(function(i, el) {
183
- setupSelect2(el);
184
- });
185
- }
186
- $("select.select2", container).each(function(i, el) {
187
- setupSelect2(el);
188
- });
189
- function setupSelect2(select) {
190
- var selectConfig = {
191
- placeholder: "",
192
- width: "80%",
193
- allowClear: true
194
- };
195
- function isFilter(path) {
196
- return $(select).closest(path).length > 0;
197
- }
198
- if (isFilter(".select_and_search")) {
199
- selectConfig.width = "resolve";
200
- selectConfig.allowClear = false;
201
- } else if (isFilter(".filter_select")) {
202
- selectConfig.width = "resolve";
203
- }
204
- $(select).select2(selectConfig);
205
- $(select).on("select2:unselecting", function() {
206
- $(this).data("unselecting", true);
207
- }).on("select2:open", function() {
208
- if ($(this).data("unselecting")) {
209
- $(this).select2("close").removeData("unselecting");
210
- }
211
- });
212
- }
213
- }
214
- };
215
- $(initializer$8);
216
- $(document).on("turbolinks:load turbo:load", initializer$8);
217
- var initializer$7 = function() {
218
- setupSearchSelect(document);
219
- $(document).on("has_many_add:after", function(event, container) {
220
- setupSearchSelect(container);
221
- });
222
- function setupSearchSelect(container) {
223
- $(".search-select-input, .search-select-filter-input, ajax-filter-input", container).each(function(i, el) {
224
- var element = $(el);
225
- var url = element.data("url");
226
- var fields = element.data("fields");
227
- var predicate = element.data("predicate");
228
- var displayName = element.data("display-name");
229
- var width = element.data("width");
230
- var responseRoot = element.data("response-root");
231
- var minimumInputLength = element.data("minimum-input-length");
232
- var order = element.data("order");
233
- var selectOptions = {
234
- width: width,
235
- minimumInputLength: minimumInputLength,
236
- placeholder: "",
237
- allowClear: true,
238
- ajax: {
239
- url: url,
240
- dataType: "json",
241
- delay: 250,
242
- cache: true,
243
- data: function(params) {
244
- var textQuery = {
245
- m: "or"
246
- };
247
- fields.forEach(function(field) {
248
- if (field == "id") {
249
- textQuery[field + "_eq"] = params.term;
250
- } else {
251
- textQuery[field + "_" + predicate] = params.term;
252
- }
253
- });
254
- var query = {
255
- order: order,
256
- q: {
257
- groupings: [ textQuery ],
258
- combinator: "and"
259
- }
260
- };
261
- return query;
262
- },
263
- processResults: function(data) {
264
- if (data.constructor == Object) {
265
- data = data[responseRoot];
266
- }
267
- return {
268
- results: jQuery.map(data, function(resource) {
269
- if (!resource[displayName]) {
270
- resource[displayName] = "No display name for id #" + resource.id.toString();
271
- }
272
- return {
273
- id: resource.id,
274
- text: resource[displayName].toString()
275
- };
276
- })
277
- };
278
- }
279
- }
280
- };
281
- $(el).select2(selectOptions);
282
- });
283
- }
284
- };
285
- $(initializer$7);
286
- $(document).on("turbolinks:load turbo:load", initializer$7);
287
- $.fn.select2.amd.define("select2/data/nestedCustomAdapter", [ "select2/data/array", "select2/utils" ], function(ArrayData, Utils) {
288
- function CustomData($element, options) {
289
- CustomData.__super__.constructor.call(this, $element, options);
290
- }
291
- Utils.Extend(CustomData, ArrayData);
292
- CustomData.prototype.query = function(params, callback) {
293
- var data = {
294
- results: []
295
- };
296
- var element = this.$element;
297
- var collection = element.data("collection");
298
- var parent = element.data("parent");
299
- var parentId = element.data("parent-id");
300
- collection.forEach(function(record) {
301
- var regex = new RegExp(params.term, "i");
302
- var matched = !!record.text.match(regex);
303
- if ((!parent || record[parent] == parentId) && matched) {
304
- data.results.push(record);
305
- }
306
- });
307
- callback(data);
308
- };
309
- CustomData.prototype.current = function(callback) {
310
- var currentOption = null;
311
- var element = this.$element;
312
- var selectedOption = element.data("selected");
313
- var collection = element.data("collection");
314
- var data = [];
315
- $.each(collection, function(index, option) {
316
- if (!!selectedOption && option.id == selectedOption.id) {
317
- currentOption = option;
318
- element.data("selected", null);
319
- return;
320
- }
321
- if (element.val() == option.id) {
322
- currentOption = option;
323
- return;
324
- }
325
- });
326
- if (currentOption) {
327
- data.push(currentOption);
328
- }
329
- callback(data);
330
- };
331
- return CustomData;
332
- });
333
- var initializer$6 = function() {
334
- configureSelect2(document);
335
- $(document).on("has_many_add:after", function(event, container) {
336
- configureSelect2(container);
337
- });
338
- function configureSelect2(container) {
339
- var INVALID_PARENT_ID = -1;
340
- $(".nested-level-input", container).each(function(i, el) {
341
- var element = $(el);
342
- var url = element.data("url");
343
- var fields = element.data("fields");
344
- var predicate = element.data("predicate");
345
- var filters = element.data("filters");
346
- var displayName = element.data("display-name");
347
- var parent = element.data("parent");
348
- var width = element.data("width");
349
- var model = element.data("model");
350
- var responseRoot = element.data("response-root");
351
- var collection = element.data("collection");
352
- var minimumInputLength = element.data("minimum-input-length");
353
- var order = element.data("order");
354
- var parentId = element.data("parent-id");
355
- var selectInstance;
356
- var select2Config = {
357
- width: width,
358
- minimumInputLength: minimumInputLength,
359
- placeholder: "",
360
- allowClear: true
361
- };
362
- if (collection) {
363
- select2Config.dataAdapter = $.fn.select2.amd.require("select2/data/nestedCustomAdapter");
364
- } else {
365
- var ajaxConfig = {
366
- url: url,
367
- dataType: "json",
368
- delay: 250,
369
- cache: true,
370
- data: function(params) {
371
- var textQuery = {
372
- m: "or"
373
- };
374
- fields.forEach(function(field) {
375
- if (field == "id") {
376
- textQuery[field + "_eq"] = params.term;
377
- } else {
378
- textQuery[field + "_" + predicate] = params.term;
379
- }
380
- });
381
- var query = {
382
- order: order,
383
- q: {
384
- groupings: [ textQuery ],
385
- combinator: "and"
386
- }
387
- };
388
- if (!!parent) {
389
- query.q[parent + "_eq"] = parentId;
390
- }
391
- Object.assign(query.q, filters);
392
- return query;
393
- },
394
- processResults: function(data) {
395
- if (data.constructor == Object) {
396
- data = data[responseRoot];
397
- }
398
- return {
399
- results: jQuery.map(data, function(resource) {
400
- if (!resource[displayName]) {
401
- resource[displayName] = "No display name for id #" + resource.id.toString();
402
- }
403
- return {
404
- id: resource.id,
405
- text: resource[displayName].toString()
406
- };
407
- })
408
- };
409
- }
410
- };
411
- select2Config.ajax = ajaxConfig;
412
- }
413
- selectInstance = element.select2(select2Config);
414
- function setParentValue(e) {
415
- selectInstance.val(null).trigger("select2:select").trigger("change");
416
- parentId = e.params && e.params.data.id ? e.params.data.id : INVALID_PARENT_ID;
417
- element.data("parent-id", parentId);
418
- }
419
- if (!!parent) {
420
- var parentSelectorId = "#" + model + "_" + parent;
421
- if (!$(parentSelectorId).length) {
422
- parentSelectorId = $(container).find("*[id*=" + parent + "]")[0];
423
- }
424
- var parentSelector = $(parentSelectorId)[0];
425
- $(parentSelector).on("select2:select", setParentValue);
426
- $(parentSelector).on("select2:unselect", setParentValue);
427
- }
428
- });
429
- }
430
- };
431
- $(initializer$6);
432
- $(document).on("turbolinks:load turbo:load", initializer$6);
433
- var initializer$5 = function() {
434
- setupTags(document);
435
- $(document).on("has_many_add:after", function(event, container) {
436
- setupTags(container);
437
- });
438
- function setupTags(container) {
439
- $(".tags-input", container).each(function(i, el) {
440
- var model = $(el).data("model");
441
- var method = $(el).data("method");
442
- var prefix = model + "_" + method;
443
- var isRelation = !!$(el).data("relation");
444
- var collection = $(el).data("collection");
445
- var width = $(el).data("width");
446
- var selectOptions = {
447
- width: width,
448
- multiple: true,
449
- tags: true,
450
- data: collection
451
- };
452
- if (!!isRelation) {
453
- selectOptions.createTag = function() {
454
- return undefined;
455
- };
456
- }
457
- $(el).on("select2:select", onItemAdded);
458
- $(el).on("select2:unselect", onItemRemoved);
459
- $(el).select2(selectOptions);
460
- function getSelectedItems() {
461
- var choices = $(el).parent("li.input").find(".select2-selection__choice");
462
- return $.map(choices, function(item) {
463
- return $(item).attr("title");
464
- });
465
- }
466
- function fillHiddenInput() {
467
- var hiddenInput = $("#" + prefix);
468
- hiddenInput.val(getSelectedItems().join());
469
- }
470
- function onItemRemoved(event) {
471
- if (isRelation) {
472
- var itemId = "[id='" + prefix + "_" + event.params.data.id + "']";
473
- $(itemId).remove();
474
- } else {
475
- fillHiddenInput();
476
- }
477
- }
478
- function onItemAdded(event) {
479
- if (isRelation) {
480
- var value = event.params.data.id;
481
- var selectedItemsContainer = $("[id='" + prefix + "_selected_values']");
482
- var itemName = model + "[" + method + "][]";
483
- var itemId = prefix + "_" + value;
484
- $("<input>").attr({
485
- id: itemId,
486
- name: itemName,
487
- type: "hidden",
488
- value: value
489
- }).appendTo(selectedItemsContainer);
490
- } else {
491
- fillHiddenInput();
492
- }
493
- }
494
- });
495
- }
496
- };
497
- $(initializer$5);
498
- $(document).on("turbolinks:load turbo:load", initializer$5);
499
- var initializer$4 = function() {
500
- setupSelectedList(document);
501
- $(document).on("has_many_add:after", function(event, container) {
502
- setupSelectedList(container);
503
- });
504
- function setupSelectedList(container) {
505
- $(".selected-list-container").click(function(event) {
506
- var item = $(event.target);
507
- if (item.hasClass("selected-item")) {
508
- item.remove();
509
- }
510
- });
511
- $(".selected-list-input", container).each(function(i, el) {
512
- var element = $(el);
513
- var url = element.data("url");
514
- var fields = element.data("fields");
515
- var predicate = element.data("predicate");
516
- var displayName = element.data("display-name");
517
- var method = element.data("method");
518
- var model = element.data("model");
519
- var prefix = model + "_" + method;
520
- var responseRoot = element.data("response-root");
521
- var minimumInputLength = element.data("minimum-input-length");
522
- var order = element.data("order");
523
- var selectOptions = {
524
- minimumInputLength: minimumInputLength,
525
- allowClear: true,
526
- ajax: {
527
- url: url,
528
- dataType: "json",
529
- delay: 250,
530
- cache: true,
531
- data: function(params) {
532
- var textQuery = {
533
- m: "or"
534
- };
535
- fields.forEach(function(field) {
536
- textQuery[field + "_" + predicate] = params.term;
537
- });
538
- var query = {
539
- order: order,
540
- q: {
541
- groupings: [ textQuery ],
542
- combinator: "and"
543
- }
544
- };
545
- return query;
546
- },
547
- processResults: function(data) {
548
- if (data.constructor == Object) {
549
- data = data[responseRoot];
550
- }
551
- return {
552
- results: jQuery.map(data, function(resource) {
553
- return {
554
- id: resource.id,
555
- text: resource[displayName].toString()
556
- };
557
- })
558
- };
559
- }
560
- }
561
- };
562
- $(el).on("select2:select", onItemSelected);
563
- $(el).on("select2:close", onSelectClosed);
564
- $(el).select2(selectOptions);
565
- function onItemSelected(event) {
566
- var data = event.params.data;
567
- var selectedItemsContainer = $("[id='" + prefix + "_selected_values']");
568
- var itemName = model + "[" + method + "][]";
569
- var itemId = prefix + "_" + data.id;
570
- if ($("#" + itemId).length > 0) {
571
- return;
572
- }
573
- var item = $("<div>" + data.text + "</div>").attr({
574
- class: "selected-item",
575
- id: itemId
576
- });
577
- var hiddenInput = $("<input>").attr({
578
- name: itemName,
579
- type: "hidden",
580
- value: data.id
581
- });
582
- item.appendTo(selectedItemsContainer);
583
- hiddenInput.appendTo(item);
584
- }
585
- function onSelectClosed() {
586
- $(el).val(null).trigger("change");
587
- }
588
- });
589
- }
590
- };
591
- $(initializer$4);
592
- $(document).on("turbolinks:load turbo:load", initializer$4);
593
- var initializer$3 = function() {
594
- setupDateTimePicker(document);
595
- $(document).on("has_many_add:after", ".has_many_container", function(event, fieldset) {
596
- return setupDateTimePicker(fieldset);
597
- });
598
- function setupDateTimePicker(container) {
599
- var defaults = {
600
- formatDate: "y-m-d",
601
- format: "Y-m-d H:i",
602
- allowBlank: true,
603
- defaultSelect: false,
604
- validateOnBlur: false,
605
- scrollInput: false
606
- };
607
- var entries = $(container).find("input.date-time-picker-input");
608
- return entries.each(function(index, entry) {
609
- var options = $(entry).data("picker-options");
610
- var mixedOptions = $.extend(defaults, options);
611
- return $(entry).datetimepicker(mixedOptions);
612
- });
613
- }
614
- };
615
- $(initializer$3);
616
- $(document).on("turbolinks:load turbo:load", initializer$3);
617
- var initializer$2 = function() {
618
- setupColorPicker();
619
- $(document).on("has_many_add:after", setupColorPicker);
620
- function setupColorPicker() {
621
- $(".color-picker-input").each(function(i, el) {
622
- $(el).paletteColorPicker({
623
- clear_btn: "last"
624
- });
625
- });
626
- }
627
- };
628
- $(initializer$2);
629
- $(document).on("turbolinks:load turbo:load", initializer$2);
630
- var initializer$1 = function() {
631
- $(".toggle-bool-switch").click(function(e) {
632
- var boolSwitch = $(e.target);
633
- var objectId = boolSwitch.data("object_id");
634
- var model = boolSwitch.data("model");
635
- var field = boolSwitch.data("field");
636
- var url = boolSwitch.data("url");
637
- var value = boolSwitch.data("value");
638
- var successMessage = boolSwitch.data("success_message");
639
- var data = {
640
- id: objectId
641
- };
642
- data[model] = {};
643
- data[model][field] = !value;
644
- $.ajax({
645
- url: url,
646
- data: data,
647
- dataType: "json",
648
- headers: {
649
- "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
650
- },
651
- error: function() {
652
- var errorMsg = "Error: Update Unsuccessful";
653
- alert(errorMsg);
654
- },
655
- success: function() {
656
- boolSwitch.data("value", !value);
657
- boolSwitch.toggleClass("on");
658
- if (!boolSwitch.hasClass("notify-success")) return;
659
- $(function() {
660
- setTimeout(alert(successMessage), 500);
661
- });
662
- },
663
- type: "PATCH"
664
- });
665
- });
666
- };
667
- $(initializer$1);
668
- $(document).on("turbolinks:load turbo:load", initializer$1);
669
- var initializer = function() {
670
- configureInteractiveSelect(document);
671
- $(document).on("has_many_add:after", function(event, container) {
672
- configureInteractiveSelect(container);
673
- });
674
- function configureInteractiveSelect(container) {
675
- $(".interactive-tag-select select", container).each(function(i, el) {
676
- setupSelect2(el);
677
- });
678
- function setupSelect2(select) {
679
- var selectConfig = {
680
- placeholder: "",
681
- allowClear: false,
682
- width: "125px"
683
- };
684
- $(select).select2(selectConfig);
685
- $(select).on("select2:unselecting", function() {
686
- $(this).data("unselecting", true);
687
- }).on("select2:open", function() {
688
- if ($(this).data("unselecting")) {
689
- $(this).select2("close").removeData("unselecting");
690
- }
691
- });
692
- }
693
- }
694
- $(".interactive-tag").click(function(e) {
695
- var tag = $(e.target).parent();
696
- var model = tag.data("model");
697
- var objectId = tag.data("object_id");
698
- var field = tag.data("field");
699
- var selectTag = $("." + model + "-" + field + "-" + objectId + "-select");
700
- selectTag.removeClass("select-container-hidden");
701
- tag.addClass("interactive-tag-hidden");
702
- selectTag.find("select").select2("open");
703
- });
704
- $(".interactive-tag-select").on("select2:close", function(e) {
705
- var selectTag = $(e.target).parent();
706
- var model = selectTag.data("model");
707
- var objectId = selectTag.data("object_id");
708
- var field = selectTag.data("field");
709
- var tagContainer = $("." + model + "-" + field + "-" + objectId + "-tag");
710
- var statusTag = tagContainer.find(".status_tag");
711
- var newValue = e.target.value;
712
- var newText = e.target.selectedOptions[0].text;
713
- var oldValue = selectTag.data("value");
714
- if (newValue === oldValue) {
715
- selectTag.addClass("select-container-hidden");
716
- tagContainer.removeClass("interactive-tag-hidden");
717
- } else {
718
- var url = tagContainer.data("url");
719
- var data = {
720
- id: objectId
721
- };
722
- data[model] = {};
723
- data[model][field] = newValue;
724
- $.ajax({
725
- url: url,
726
- data: data,
727
- dataType: "json",
728
- headers: {
729
- "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
730
- },
731
- error: function() {
732
- var errorMsg = "Error: Update Unsuccessful";
733
- console.log(errorMsg);
734
- },
735
- success: function() {
736
- statusTag.text(newText);
737
- statusTag.removeClass(oldValue);
738
- statusTag.addClass(newValue);
739
- tagContainer.data("value", newValue);
740
- selectTag.data("value", newValue);
741
- },
742
- complete: function() {
743
- selectTag.addClass("select-container-hidden");
744
- tagContainer.removeClass("interactive-tag-hidden");
745
- },
746
- type: "PATCH"
747
- });
748
- }
749
- });
750
- };
751
- $(initializer);
752
- $(document).on("turbolinks:load turbo:load", initializer);
753
- });