activeadmin_addons 0.9.3 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/activeadmin_addons/select2.js +20 -8
- data/app/inputs/ajax_filter_input.rb +37 -0
- data/app/inputs/search_select_input.rb +1 -0
- data/app/inputs/tags_input.rb +1 -0
- data/lib/activeadmin_addons/addons/paperclip_attachment.rb +22 -8
- data/lib/activeadmin_addons/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb0bc25f0bbd9f292d7bb1f157239838880e6301
|
4
|
+
data.tar.gz: ce91eb8f8aafd7a4f032eab9b9070593161cec47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6d569f553ac461d98943bfb89d300202c481e5aa69e3fbd377cfc1a64ad420586eaa910276563c7d47c8f2e517ffa788bd60e78a5399ecb0a1431d02bfe0aa1
|
7
|
+
data.tar.gz: 77bd61606672f16b76770538e0ba702d20467b3013fa28a791e92dd01876cde41c1826509ea996bad8ebab9452ff6b97199bf35ec4a461c52a9d1672ffcf7589
|
@@ -10,12 +10,14 @@ $(function() {
|
|
10
10
|
|
11
11
|
function setupSelect2(container) {
|
12
12
|
var INVALID_PARENT_ID = -1;
|
13
|
+
var DEFAULT_SELECT_WIDTH = '80%';
|
13
14
|
|
14
15
|
$('.select2-tags', container).each(function(i, el) {
|
15
16
|
var model = $(el).data('model'),
|
16
17
|
method = $(el).data('method'),
|
18
|
+
width = $(el).data('width'),
|
17
19
|
selectOptions = {
|
18
|
-
width:
|
20
|
+
width: width || DEFAULT_SELECT_WIDTH,
|
19
21
|
tags: $(el).data('collection')
|
20
22
|
};
|
21
23
|
|
@@ -29,14 +31,14 @@ $(function() {
|
|
29
31
|
$(el).select2(selectOptions);
|
30
32
|
|
31
33
|
function onItemRemoved(event) {
|
32
|
-
var itemId = '
|
34
|
+
var itemId = '[id=\'' + prefix + '_' + event.val + '\']';
|
33
35
|
$(itemId).remove();
|
34
36
|
}
|
35
37
|
|
36
38
|
function onItemAdded(event) {
|
37
|
-
var selectedItemsContainer = $('
|
38
|
-
|
39
|
-
|
39
|
+
var selectedItemsContainer = $("[id='" + prefix + "_selected_values']"),
|
40
|
+
itemName = model + '[' + method + '][]',
|
41
|
+
itemId = prefix + '_' + event.val;
|
40
42
|
|
41
43
|
$('<input>').attr({
|
42
44
|
id: itemId,
|
@@ -48,13 +50,22 @@ $(function() {
|
|
48
50
|
});
|
49
51
|
|
50
52
|
$('select:not(.default-select)', container).each(function(i, el) {
|
53
|
+
var firstOption = $('option', el).first(),
|
54
|
+
allowClear = false;
|
55
|
+
|
56
|
+
if (firstOption.val() === "" && firstOption.text() === "") {
|
57
|
+
allowClear = true;
|
58
|
+
}
|
59
|
+
|
51
60
|
if ($(el).closest('.filter_form').length > 0) {
|
52
61
|
$(el).select2({
|
53
|
-
width: 'resolve'
|
62
|
+
width: 'resolve',
|
63
|
+
allowClear: allowClear
|
54
64
|
});
|
55
65
|
} else {
|
56
66
|
$(el).select2({
|
57
|
-
width:
|
67
|
+
width: DEFAULT_SELECT_WIDTH,
|
68
|
+
allowClear: allowClear
|
58
69
|
});
|
59
70
|
}
|
60
71
|
});
|
@@ -64,6 +75,7 @@ $(function() {
|
|
64
75
|
var fields = $(el).data('fields');
|
65
76
|
var displayName = $(el).data('display_name');
|
66
77
|
var parent = $(el).data('parent');
|
78
|
+
var width = $(el).data('width') || DEFAULT_SELECT_WIDTH;
|
67
79
|
var model = $(el).data('model');
|
68
80
|
var responseRoot = $(el).data('response_root');
|
69
81
|
var collection = $(el).data('collection');
|
@@ -131,7 +143,7 @@ $(function() {
|
|
131
143
|
};
|
132
144
|
|
133
145
|
var select2Config = {
|
134
|
-
width:
|
146
|
+
width: width,
|
135
147
|
containerCssClass: 'nested-select-container',
|
136
148
|
minimumInputLength: minimumInputLength,
|
137
149
|
initSelection: function(element, callback) {
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class AjaxFilterInput < Formtastic::Inputs::StringInput
|
2
|
+
include ActiveAdmin::Inputs::Filters::Base
|
3
|
+
|
4
|
+
def to_html
|
5
|
+
input_wrapping do
|
6
|
+
[
|
7
|
+
label_html,
|
8
|
+
builder.text_field(eq_input_name, input_html_options)
|
9
|
+
].join("\n").html_safe
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def eq_input_name
|
14
|
+
"#{method}_eq"
|
15
|
+
end
|
16
|
+
|
17
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
18
|
+
def input_html_options
|
19
|
+
opts = {}
|
20
|
+
opts[:class] = ['select2-ajax'].concat([@options[:class]] || []).join(' ')
|
21
|
+
opts["data-fields"] = (@options[:fields] || []).to_json
|
22
|
+
opts["data-url"] = @options[:url] || ""
|
23
|
+
opts["data-response_root"] = @options[:response_root] || @options[:url].to_s.split('/').last
|
24
|
+
opts["data-display_name"] = @options[:display_name] || "name"
|
25
|
+
opts["data-minimum_input_length"] = @options[:minimum_input_length] || 1
|
26
|
+
opts["data-width"] = @options[:width] || "100%"
|
27
|
+
opts["data-selected"] = get_selected_value(opts["data-display_name"])
|
28
|
+
super.merge opts
|
29
|
+
end
|
30
|
+
|
31
|
+
# rubocop:disable Style/RescueModifier
|
32
|
+
def get_selected_value(display_name)
|
33
|
+
filter_class = method.to_s.chomp("_id").classify.constantize
|
34
|
+
selected_value = @object.conditions.first.values.first.value rescue nil
|
35
|
+
filter_class.find(selected_value).send(display_name) if !!selected_value
|
36
|
+
end
|
37
|
+
end
|
@@ -8,6 +8,7 @@ class SearchSelectInput < Formtastic::Inputs::StringInput
|
|
8
8
|
opts["data-response_root"] = @options[:response_root] || @options[:url].to_s.split('/').last
|
9
9
|
opts["data-display_name"] = @options[:display_name] || "name"
|
10
10
|
opts["data-minimum_input_length"] = @options[:minimum_input_length] || 1
|
11
|
+
opts["data-width"] = @options[:width] if @options[:width]
|
11
12
|
opts["data-selected"] = relation.try(opts["data-display_name"].to_sym)
|
12
13
|
super.merge opts
|
13
14
|
end
|
data/app/inputs/tags_input.rb
CHANGED
@@ -21,24 +21,38 @@ module ActiveAdminAddons
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def build_label
|
24
|
-
icon = icon_for_filename(
|
24
|
+
icon = icon_for_filename(file.original_filename)
|
25
25
|
style = { width: "20", height: "20", style: "margin-right: 5px; vertical-align: middle;" }
|
26
26
|
icon_img = context.image_tag(icon, style)
|
27
|
-
|
28
|
-
file_name = context.truncate(data.original_filename) if options[:truncate] == true
|
29
|
-
label_text = options.fetch(:label, file_name)
|
27
|
+
text = label_text
|
30
28
|
|
31
29
|
context.content_tag(:span) do
|
32
30
|
context.concat(icon_img)
|
33
|
-
context.safe_concat(
|
31
|
+
context.safe_concat(text)
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
35
|
+
def label_text
|
36
|
+
label =
|
37
|
+
if options[:label].nil?
|
38
|
+
file.original_filename
|
39
|
+
elsif options[:label].is_a? Proc
|
40
|
+
options[:label].call(model).to_s
|
41
|
+
else
|
42
|
+
options[:label].to_s
|
43
|
+
end
|
44
|
+
options[:truncate] ? context.truncate(label) : label
|
45
|
+
end
|
46
|
+
|
37
47
|
def render
|
38
|
-
raise 'you need to pass a paperclip attribute' unless
|
48
|
+
raise 'you need to pass a paperclip attribute' unless file.respond_to?(:url)
|
39
49
|
options[:truncate] = options.fetch(:truncate, true)
|
40
|
-
return nil unless
|
41
|
-
context.link_to(build_label,
|
50
|
+
return nil unless file.exists?
|
51
|
+
context.link_to(build_label, file.url, target: "_blank", class: "attachment-link")
|
52
|
+
end
|
53
|
+
|
54
|
+
def file
|
55
|
+
model.send(attribute)
|
42
56
|
end
|
43
57
|
end
|
44
58
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_addons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Platanus
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-
|
14
|
+
date: 2016-11-30 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: railties
|
@@ -375,6 +375,7 @@ files:
|
|
375
375
|
- app/assets/javascripts/palette-color-picker.js
|
376
376
|
- app/assets/stylesheets/activeadmin_addons/all.scss
|
377
377
|
- app/assets/stylesheets/palette-color-picker.scss
|
378
|
+
- app/inputs/ajax_filter_input.rb
|
378
379
|
- app/inputs/color_picker_input.rb
|
379
380
|
- app/inputs/date_time_picker_input.rb
|
380
381
|
- app/inputs/nested_select_input.rb
|