activeadmin_addons_rails6 1.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +24 -0
- data/app/assets/images/fileicons/file_extension_3gp.png +0 -0
- data/app/assets/images/fileicons/file_extension_7z.png +0 -0
- data/app/assets/images/fileicons/file_extension_ace.png +0 -0
- data/app/assets/images/fileicons/file_extension_ai.png +0 -0
- data/app/assets/images/fileicons/file_extension_aif.png +0 -0
- data/app/assets/images/fileicons/file_extension_aiff.png +0 -0
- data/app/assets/images/fileicons/file_extension_amr.png +0 -0
- data/app/assets/images/fileicons/file_extension_asf.png +0 -0
- data/app/assets/images/fileicons/file_extension_asx.png +0 -0
- data/app/assets/images/fileicons/file_extension_bat.png +0 -0
- data/app/assets/images/fileicons/file_extension_bin.png +0 -0
- data/app/assets/images/fileicons/file_extension_bmp.png +0 -0
- data/app/assets/images/fileicons/file_extension_bup.png +0 -0
- data/app/assets/images/fileicons/file_extension_cab.png +0 -0
- data/app/assets/images/fileicons/file_extension_cbr.png +0 -0
- data/app/assets/images/fileicons/file_extension_cda.png +0 -0
- data/app/assets/images/fileicons/file_extension_cdl.png +0 -0
- data/app/assets/images/fileicons/file_extension_cdr.png +0 -0
- data/app/assets/images/fileicons/file_extension_chm.png +0 -0
- data/app/assets/images/fileicons/file_extension_dat.png +0 -0
- data/app/assets/images/fileicons/file_extension_divx.png +0 -0
- data/app/assets/images/fileicons/file_extension_dll.png +0 -0
- data/app/assets/images/fileicons/file_extension_dmg.png +0 -0
- data/app/assets/images/fileicons/file_extension_doc.png +0 -0
- data/app/assets/images/fileicons/file_extension_docx.png +0 -0
- data/app/assets/images/fileicons/file_extension_dss.png +0 -0
- data/app/assets/images/fileicons/file_extension_dvf.png +0 -0
- data/app/assets/images/fileicons/file_extension_dwg.png +0 -0
- data/app/assets/images/fileicons/file_extension_eml.png +0 -0
- data/app/assets/images/fileicons/file_extension_eps.png +0 -0
- data/app/assets/images/fileicons/file_extension_exe.png +0 -0
- data/app/assets/images/fileicons/file_extension_fla.png +0 -0
- data/app/assets/images/fileicons/file_extension_flv.png +0 -0
- data/app/assets/images/fileicons/file_extension_gif.png +0 -0
- data/app/assets/images/fileicons/file_extension_gz.png +0 -0
- data/app/assets/images/fileicons/file_extension_hqx.png +0 -0
- data/app/assets/images/fileicons/file_extension_htm.png +0 -0
- data/app/assets/images/fileicons/file_extension_html.png +0 -0
- data/app/assets/images/fileicons/file_extension_ifo.png +0 -0
- data/app/assets/images/fileicons/file_extension_indd.png +0 -0
- data/app/assets/images/fileicons/file_extension_iso.png +0 -0
- data/app/assets/images/fileicons/file_extension_jar.png +0 -0
- data/app/assets/images/fileicons/file_extension_jpeg.png +0 -0
- data/app/assets/images/fileicons/file_extension_jpg.png +0 -0
- data/app/assets/images/fileicons/file_extension_lnk.png +0 -0
- data/app/assets/images/fileicons/file_extension_log.png +0 -0
- data/app/assets/images/fileicons/file_extension_m4a.png +0 -0
- data/app/assets/images/fileicons/file_extension_m4b.png +0 -0
- data/app/assets/images/fileicons/file_extension_m4p.png +0 -0
- data/app/assets/images/fileicons/file_extension_m4v.png +0 -0
- data/app/assets/images/fileicons/file_extension_mcd.png +0 -0
- data/app/assets/images/fileicons/file_extension_mdb.png +0 -0
- data/app/assets/images/fileicons/file_extension_mid.png +0 -0
- data/app/assets/images/fileicons/file_extension_mov.png +0 -0
- data/app/assets/images/fileicons/file_extension_mp2.png +0 -0
- data/app/assets/images/fileicons/file_extension_mp3.png +0 -0
- data/app/assets/images/fileicons/file_extension_mp4.png +0 -0
- data/app/assets/images/fileicons/file_extension_mpeg.png +0 -0
- data/app/assets/images/fileicons/file_extension_mpg.png +0 -0
- data/app/assets/images/fileicons/file_extension_msi.png +0 -0
- data/app/assets/images/fileicons/file_extension_mswmm.png +0 -0
- data/app/assets/images/fileicons/file_extension_ogg.png +0 -0
- data/app/assets/images/fileicons/file_extension_pdf.png +0 -0
- data/app/assets/images/fileicons/file_extension_png.png +0 -0
- data/app/assets/images/fileicons/file_extension_pps.png +0 -0
- data/app/assets/images/fileicons/file_extension_ppt.png +0 -0
- data/app/assets/images/fileicons/file_extension_pptx.png +0 -0
- data/app/assets/images/fileicons/file_extension_ps.png +0 -0
- data/app/assets/images/fileicons/file_extension_psd.png +0 -0
- data/app/assets/images/fileicons/file_extension_pst.png +0 -0
- data/app/assets/images/fileicons/file_extension_ptb.png +0 -0
- data/app/assets/images/fileicons/file_extension_pub.png +0 -0
- data/app/assets/images/fileicons/file_extension_qbb.png +0 -0
- data/app/assets/images/fileicons/file_extension_qbw.png +0 -0
- data/app/assets/images/fileicons/file_extension_qxd.png +0 -0
- data/app/assets/images/fileicons/file_extension_ram.png +0 -0
- data/app/assets/images/fileicons/file_extension_rar.png +0 -0
- data/app/assets/images/fileicons/file_extension_rm.png +0 -0
- data/app/assets/images/fileicons/file_extension_rmvb.png +0 -0
- data/app/assets/images/fileicons/file_extension_rtf.png +0 -0
- data/app/assets/images/fileicons/file_extension_sea.png +0 -0
- data/app/assets/images/fileicons/file_extension_ses.png +0 -0
- data/app/assets/images/fileicons/file_extension_sit.png +0 -0
- data/app/assets/images/fileicons/file_extension_sitx.png +0 -0
- data/app/assets/images/fileicons/file_extension_ss.png +0 -0
- data/app/assets/images/fileicons/file_extension_swf.png +0 -0
- data/app/assets/images/fileicons/file_extension_tgz.png +0 -0
- data/app/assets/images/fileicons/file_extension_thm.png +0 -0
- data/app/assets/images/fileicons/file_extension_tif.png +0 -0
- data/app/assets/images/fileicons/file_extension_tmp.png +0 -0
- data/app/assets/images/fileicons/file_extension_torrent.png +0 -0
- data/app/assets/images/fileicons/file_extension_ttf.png +0 -0
- data/app/assets/images/fileicons/file_extension_txt.png +0 -0
- data/app/assets/images/fileicons/file_extension_unknown.png +0 -0
- data/app/assets/images/fileicons/file_extension_vcd.png +0 -0
- data/app/assets/images/fileicons/file_extension_vob.png +0 -0
- data/app/assets/images/fileicons/file_extension_wav.png +0 -0
- data/app/assets/images/fileicons/file_extension_wma.png +0 -0
- data/app/assets/images/fileicons/file_extension_wmv.png +0 -0
- data/app/assets/images/fileicons/file_extension_wps.png +0 -0
- data/app/assets/images/fileicons/file_extension_xls.png +0 -0
- data/app/assets/images/fileicons/file_extension_xlsx.png +0 -0
- data/app/assets/images/fileicons/file_extension_xpi.png +0 -0
- data/app/assets/images/fileicons/file_extension_zip.png +0 -0
- data/app/assets/images/material/icons/keyboard_arrow_down.svg +4 -0
- data/app/assets/images/material/icons/keyboard_arrow_left.svg +4 -0
- data/app/assets/images/material/icons/keyboard_arrow_right.svg +4 -0
- data/app/assets/images/material/icons/keyboard_arrow_up.svg +4 -0
- data/app/assets/images/material/icons/today.svg +4 -0
- data/app/assets/javascripts/activeadmin_addons/all.js +753 -0
- data/app/assets/stylesheets/activeadmin_addons/addons/interactive_select_tag.scss +30 -0
- data/app/assets/stylesheets/activeadmin_addons/addons/material-datepicker.scss +173 -0
- data/app/assets/stylesheets/activeadmin_addons/addons/material-toggle_bool.scss +52 -0
- data/app/assets/stylesheets/activeadmin_addons/addons/toggle_bool.scss +52 -0
- data/app/assets/stylesheets/activeadmin_addons/all.scss +19 -0
- data/app/assets/stylesheets/activeadmin_addons/imports/jquery-datepicker.scss +1 -0
- data/app/assets/stylesheets/activeadmin_addons/imports/webpack/jquery-datepicker.scss +1 -0
- data/app/assets/stylesheets/activeadmin_addons/inputs/color-picker.scss +4 -0
- data/app/assets/stylesheets/activeadmin_addons/inputs/date-time-picker.scss +5 -0
- data/app/assets/stylesheets/activeadmin_addons/inputs/numeric-range-filter.scss +12 -0
- data/app/assets/stylesheets/activeadmin_addons/inputs/select2.scss +3 -0
- data/app/assets/stylesheets/activeadmin_addons/inputs/selected-list.scss +27 -0
- data/app/assets/stylesheets/activeadmin_addons/material.scss +53 -0
- data/app/assets/stylesheets/activeadmin_addons/vendor/palette-color-picker.scss +155 -0
- data/app/inputs/active_admin/inputs/select_input.rb +11 -0
- data/app/inputs/ajax_filter_input.rb +6 -0
- data/app/inputs/color_picker_input.rb +37 -0
- data/app/inputs/date_range_input.rb +5 -0
- data/app/inputs/date_time_picker_input.rb +64 -0
- data/app/inputs/nested_level_input.rb +51 -0
- data/app/inputs/nested_select_input.rb +88 -0
- data/app/inputs/numeric_range_filter_input.rb +27 -0
- data/app/inputs/range_select_input.rb +6 -0
- data/app/inputs/search_select_filter_input.rb +12 -0
- data/app/inputs/search_select_input.rb +29 -0
- data/app/inputs/selected_list_input.rb +54 -0
- data/app/inputs/tags_input.rb +55 -0
- data/app/javascript/activeadmin_addons/addons/interactive_select_tag.js +95 -0
- data/app/javascript/activeadmin_addons/addons/toggle_bool.js +39 -0
- data/app/javascript/activeadmin_addons/all.js +14 -0
- data/app/javascript/activeadmin_addons/config.js +10 -0
- data/app/javascript/activeadmin_addons/inputs/color-picker.js +16 -0
- data/app/javascript/activeadmin_addons/inputs/date-time-picker.js +28 -0
- data/app/javascript/activeadmin_addons/inputs/nested-select.js +170 -0
- data/app/javascript/activeadmin_addons/inputs/search-select.js +76 -0
- data/app/javascript/activeadmin_addons/inputs/select2.js +52 -0
- data/app/javascript/activeadmin_addons/inputs/selected-list.js +107 -0
- data/app/javascript/activeadmin_addons/inputs/tags.js +76 -0
- data/app/javascript/activeadmin_addons/vendor/jquery_palette_color_picker/palette-color-picker.js +265 -0
- data/lib/activeadmin_addons.rb +27 -0
- data/lib/activeadmin_addons/active_admin_config.rb +9 -0
- data/lib/activeadmin_addons/addons/attachment_builder.rb +60 -0
- data/lib/activeadmin_addons/addons/bool_builder.rb +31 -0
- data/lib/activeadmin_addons/addons/image_builder.rb +12 -0
- data/lib/activeadmin_addons/addons/list_builder.rb +73 -0
- data/lib/activeadmin_addons/addons/number_builder.rb +25 -0
- data/lib/activeadmin_addons/addons/state_builder.rb +39 -0
- data/lib/activeadmin_addons/addons/tag_builder.rb +91 -0
- data/lib/activeadmin_addons/addons/toggle_bool_builder.rb +44 -0
- data/lib/activeadmin_addons/engine.rb +19 -0
- data/lib/activeadmin_addons/support/custom_builder.rb +91 -0
- data/lib/activeadmin_addons/support/enumerize_formtastic_support.rb +18 -0
- data/lib/activeadmin_addons/support/input_base.rb +53 -0
- data/lib/activeadmin_addons/support/input_helpers/filter_input.rb +8 -0
- data/lib/activeadmin_addons/support/input_helpers/filter_input_methods.rb +32 -0
- data/lib/activeadmin_addons/support/input_helpers/input_html_helpers.rb +43 -0
- data/lib/activeadmin_addons/support/input_helpers/input_methods.rb +67 -0
- data/lib/activeadmin_addons/support/input_helpers/input_options_handler.rb +90 -0
- data/lib/activeadmin_addons/support/input_helpers/select_helpers.rb +89 -0
- data/lib/activeadmin_addons/support/set_datepicker.rb +13 -0
- data/lib/activeadmin_addons/version.rb +3 -0
- data/lib/activeadmin_addons_rails_6.rb +5 -0
- data/lib/generators/activeadmin_addons/assets/assets_generator.rb +53 -0
- data/lib/generators/activeadmin_addons/install/install_generator.rb +19 -0
- data/lib/generators/activeadmin_addons/install/templates/initializer.rb +12 -0
- data/lib/generators/activeadmin_addons/webpacker/webpacker_generator.rb +35 -0
- data/lib/tasks/activeadmin_addons_tasks.rake +4 -0
- data/vendor/assets/select2/select2.css +481 -0
- data/vendor/assets/select2/select2.full.js +6820 -0
- metadata +544 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
var initializer = function() {
|
2
|
+
setupSearchSelect(document);
|
3
|
+
|
4
|
+
$(document).on('has_many_add:after', function(event, container) {
|
5
|
+
setupSearchSelect(container);
|
6
|
+
});
|
7
|
+
|
8
|
+
function setupSearchSelect(container) {
|
9
|
+
$('.search-select-input, .search-select-filter-input, ajax-filter-input', container).each(function(i, el) {
|
10
|
+
var element = $(el);
|
11
|
+
var url = element.data('url');
|
12
|
+
var fields = element.data('fields');
|
13
|
+
var predicate = element.data('predicate');
|
14
|
+
var displayName = element.data('display-name');
|
15
|
+
var width = element.data('width');
|
16
|
+
var responseRoot = element.data('response-root');
|
17
|
+
var minimumInputLength = element.data('minimum-input-length');
|
18
|
+
var order = element.data('order');
|
19
|
+
|
20
|
+
var selectOptions = {
|
21
|
+
width: width,
|
22
|
+
minimumInputLength: minimumInputLength,
|
23
|
+
placeholder: '',
|
24
|
+
allowClear: true,
|
25
|
+
ajax: {
|
26
|
+
url: url,
|
27
|
+
dataType: 'json',
|
28
|
+
delay: 250,
|
29
|
+
cache: true,
|
30
|
+
data: function(params) {
|
31
|
+
var textQuery = { m: 'or' };
|
32
|
+
fields.forEach(function(field) {
|
33
|
+
if (field == 'id') {
|
34
|
+
textQuery[field + '_eq'] = params.term;
|
35
|
+
} else {
|
36
|
+
textQuery[field + '_' + predicate] = params.term;
|
37
|
+
}
|
38
|
+
});
|
39
|
+
|
40
|
+
var query = {
|
41
|
+
order: order,
|
42
|
+
q: {
|
43
|
+
groupings: [textQuery],
|
44
|
+
combinator: 'and',
|
45
|
+
},
|
46
|
+
};
|
47
|
+
|
48
|
+
return query;
|
49
|
+
},
|
50
|
+
processResults: function(data) {
|
51
|
+
if (data.constructor == Object) {
|
52
|
+
data = data[responseRoot];
|
53
|
+
}
|
54
|
+
|
55
|
+
return {
|
56
|
+
results: jQuery.map(data, function(resource) {
|
57
|
+
if (!resource[displayName]) {
|
58
|
+
resource[displayName] = 'No display name for id #' + resource.id.toString();
|
59
|
+
}
|
60
|
+
return {
|
61
|
+
id: resource.id,
|
62
|
+
text: resource[displayName].toString(),
|
63
|
+
};
|
64
|
+
}),
|
65
|
+
};
|
66
|
+
},
|
67
|
+
},
|
68
|
+
};
|
69
|
+
|
70
|
+
$(el).select2(selectOptions);
|
71
|
+
});
|
72
|
+
}
|
73
|
+
};
|
74
|
+
|
75
|
+
$(initializer);
|
76
|
+
$(document).on('turbolinks:load', initializer);
|
@@ -0,0 +1,52 @@
|
|
1
|
+
var initializer = function() {
|
2
|
+
configureSelect2(document);
|
3
|
+
|
4
|
+
$(document).on('has_many_add:after', function(event, container) {
|
5
|
+
configureSelect2(container);
|
6
|
+
});
|
7
|
+
|
8
|
+
function configureSelect2(container) {
|
9
|
+
if (window.ActiveadminAddons.config.defaultSelect == 'select2') {
|
10
|
+
$('select:not(.default-select)', container).each(function(i, el) {
|
11
|
+
setupSelect2(el);
|
12
|
+
});
|
13
|
+
}
|
14
|
+
|
15
|
+
$('select.select2', container).each(function(i, el) {
|
16
|
+
setupSelect2(el);
|
17
|
+
});
|
18
|
+
|
19
|
+
function setupSelect2(select) {
|
20
|
+
var selectConfig = {
|
21
|
+
placeholder: '',
|
22
|
+
width: '80%',
|
23
|
+
allowClear: true,
|
24
|
+
};
|
25
|
+
|
26
|
+
function isFilter(path) {
|
27
|
+
return $(select).closest(path).length > 0;
|
28
|
+
}
|
29
|
+
|
30
|
+
if (isFilter('.select_and_search')) {
|
31
|
+
selectConfig.width = 'resolve';
|
32
|
+
selectConfig.allowClear = false;
|
33
|
+
} else if (isFilter('.filter_select')) {
|
34
|
+
selectConfig.width = 'resolve';
|
35
|
+
}
|
36
|
+
|
37
|
+
$(select).select2(selectConfig);
|
38
|
+
|
39
|
+
// Related with https://github.com/select2/select2/issues/3320
|
40
|
+
$(select).on('select2:unselecting', function() {
|
41
|
+
$(this).data('unselecting', true);
|
42
|
+
}).on('select2:open', function() {
|
43
|
+
if ($(this).data('unselecting')) {
|
44
|
+
$(this).select2('close').removeData('unselecting');
|
45
|
+
}
|
46
|
+
});
|
47
|
+
}
|
48
|
+
}
|
49
|
+
};
|
50
|
+
|
51
|
+
$(initializer);
|
52
|
+
$(document).on('turbolinks:load', initializer);
|
@@ -0,0 +1,107 @@
|
|
1
|
+
var initializer = function() {
|
2
|
+
setupSelectedList(document);
|
3
|
+
|
4
|
+
$(document).on('has_many_add:after', function(event, container) {
|
5
|
+
setupSelectedList(container);
|
6
|
+
});
|
7
|
+
|
8
|
+
function setupSelectedList(container) {
|
9
|
+
$('.selected-list-container').click(function(event) {
|
10
|
+
var item = $(event.target);
|
11
|
+
if (item.hasClass('selected-item')) {
|
12
|
+
item.remove();
|
13
|
+
}
|
14
|
+
});
|
15
|
+
|
16
|
+
$('.selected-list-input', container).each(function(i, el) {
|
17
|
+
var element = $(el);
|
18
|
+
var url = element.data('url');
|
19
|
+
var fields = element.data('fields');
|
20
|
+
var predicate = element.data('predicate');
|
21
|
+
var displayName = element.data('display-name');
|
22
|
+
var method = element.data('method');
|
23
|
+
var model = element.data('model');
|
24
|
+
var prefix = model + '_' + method;
|
25
|
+
var responseRoot = element.data('response-root');
|
26
|
+
var minimumInputLength = element.data('minimum-input-length');
|
27
|
+
var order = element.data('order');
|
28
|
+
|
29
|
+
var selectOptions = {
|
30
|
+
minimumInputLength: minimumInputLength,
|
31
|
+
allowClear: true,
|
32
|
+
ajax: {
|
33
|
+
url: url,
|
34
|
+
dataType: 'json',
|
35
|
+
delay: 250,
|
36
|
+
cache: true,
|
37
|
+
data: function(params) {
|
38
|
+
var textQuery = { m: 'or' };
|
39
|
+
fields.forEach(function(field) {
|
40
|
+
textQuery[field + '_' + predicate] = params.term;
|
41
|
+
});
|
42
|
+
|
43
|
+
var query = {
|
44
|
+
order: order,
|
45
|
+
q: {
|
46
|
+
groupings: [textQuery],
|
47
|
+
combinator: 'and',
|
48
|
+
},
|
49
|
+
};
|
50
|
+
|
51
|
+
return query;
|
52
|
+
},
|
53
|
+
processResults: function(data) {
|
54
|
+
if (data.constructor == Object) {
|
55
|
+
data = data[responseRoot];
|
56
|
+
}
|
57
|
+
|
58
|
+
return {
|
59
|
+
results: jQuery.map(data, function(resource) {
|
60
|
+
return {
|
61
|
+
id: resource.id,
|
62
|
+
text: resource[displayName].toString(),
|
63
|
+
};
|
64
|
+
}),
|
65
|
+
};
|
66
|
+
},
|
67
|
+
},
|
68
|
+
};
|
69
|
+
|
70
|
+
$(el).on('select2:select', onItemSelected);
|
71
|
+
$(el).on('select2:close', onSelectClosed);
|
72
|
+
$(el).select2(selectOptions);
|
73
|
+
|
74
|
+
function onItemSelected(event) {
|
75
|
+
var data = event.params.data;
|
76
|
+
var selectedItemsContainer = $("[id='" + prefix + "_selected_values']");
|
77
|
+
var itemName = model + '[' + method + '][]';
|
78
|
+
var itemId = prefix + '_' + data.id;
|
79
|
+
|
80
|
+
if ($('#' + itemId).length > 0) {
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
|
84
|
+
var item = $('<div>' + data.text + '</div>').attr({
|
85
|
+
class: 'selected-item',
|
86
|
+
id: itemId,
|
87
|
+
});
|
88
|
+
|
89
|
+
var hiddenInput = $('<input>').attr({
|
90
|
+
name: itemName,
|
91
|
+
type: 'hidden',
|
92
|
+
value: data.id,
|
93
|
+
});
|
94
|
+
|
95
|
+
item.appendTo(selectedItemsContainer);
|
96
|
+
hiddenInput.appendTo(item);
|
97
|
+
}
|
98
|
+
|
99
|
+
function onSelectClosed() {
|
100
|
+
$(el).val(null).trigger('change');
|
101
|
+
}
|
102
|
+
});
|
103
|
+
}
|
104
|
+
};
|
105
|
+
|
106
|
+
$(initializer);
|
107
|
+
$(document).on('turbolinks:load', initializer);
|
@@ -0,0 +1,76 @@
|
|
1
|
+
var initializer = function() {
|
2
|
+
setupTags(document);
|
3
|
+
|
4
|
+
$(document).on('has_many_add:after', function(event, container) {
|
5
|
+
setupTags(container);
|
6
|
+
});
|
7
|
+
|
8
|
+
function setupTags(container) {
|
9
|
+
$('.tags-input', container).each(function(i, el) {
|
10
|
+
var model = $(el).data('model');
|
11
|
+
var method = $(el).data('method');
|
12
|
+
var prefix = model + '_' + method;
|
13
|
+
var isRelation = !!$(el).data('relation');
|
14
|
+
var collection = $(el).data('collection');
|
15
|
+
var width = $(el).data('width');
|
16
|
+
var selectOptions = {
|
17
|
+
width: width,
|
18
|
+
multiple: true,
|
19
|
+
tags: true,
|
20
|
+
data: collection,
|
21
|
+
};
|
22
|
+
|
23
|
+
if (!!isRelation) {
|
24
|
+
selectOptions.createTag = function() {
|
25
|
+
return undefined;
|
26
|
+
};
|
27
|
+
}
|
28
|
+
|
29
|
+
$(el).on('select2:select', onItemAdded);
|
30
|
+
$(el).on('select2:unselect', onItemRemoved);
|
31
|
+
$(el).select2(selectOptions);
|
32
|
+
|
33
|
+
function getSelectedItems() {
|
34
|
+
var choices = $(el).parent('li.input').find('.select2-selection__choice');
|
35
|
+
return $.map(choices, function(item) {
|
36
|
+
return $(item).attr('title');
|
37
|
+
});
|
38
|
+
}
|
39
|
+
|
40
|
+
function fillHiddenInput() {
|
41
|
+
var hiddenInput = $('#' + prefix);
|
42
|
+
hiddenInput.val(getSelectedItems().join());
|
43
|
+
}
|
44
|
+
|
45
|
+
function onItemRemoved(event) {
|
46
|
+
if (isRelation) {
|
47
|
+
var itemId = '[id=\'' + prefix + '_' + event.params.data.id + '\']';
|
48
|
+
$(itemId).remove();
|
49
|
+
} else {
|
50
|
+
fillHiddenInput();
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
function onItemAdded(event) {
|
55
|
+
if (isRelation) {
|
56
|
+
var value = event.params.data.id;
|
57
|
+
var selectedItemsContainer = $("[id='" + prefix + "_selected_values']");
|
58
|
+
var itemName = model + '[' + method + '][]';
|
59
|
+
var itemId = prefix + '_' + value;
|
60
|
+
|
61
|
+
$('<input>').attr({
|
62
|
+
id: itemId,
|
63
|
+
name: itemName,
|
64
|
+
type: 'hidden',
|
65
|
+
value: value,
|
66
|
+
}).appendTo(selectedItemsContainer);
|
67
|
+
} else {
|
68
|
+
fillHiddenInput();
|
69
|
+
}
|
70
|
+
}
|
71
|
+
});
|
72
|
+
}
|
73
|
+
};
|
74
|
+
|
75
|
+
$(initializer);
|
76
|
+
$(document).on('turbolinks:load', initializer);
|
data/app/javascript/activeadmin_addons/vendor/jquery_palette_color_picker/palette-color-picker.js
ADDED
@@ -0,0 +1,265 @@
|
|
1
|
+
/*!
|
2
|
+
* JQuery Palette Color Picker v1.13 by Carlos Cabo ( @putuko )
|
3
|
+
* https://github.com/carloscabo/jquery-palette-color-picker
|
4
|
+
*/
|
5
|
+
(function($) {
|
6
|
+
// La magia aquí
|
7
|
+
'use strict';
|
8
|
+
|
9
|
+
// Public core
|
10
|
+
$.paletteColorPicker = function( el, options ) {
|
11
|
+
var
|
12
|
+
ns = 'palette-color-picker', // Base attr / class
|
13
|
+
$el = $(el),
|
14
|
+
plugin = this,
|
15
|
+
timer = null,
|
16
|
+
current_value = $el.val(),
|
17
|
+
target = $el.attr('name'),
|
18
|
+
$button = $('<div>')
|
19
|
+
.addClass(ns+'-button')
|
20
|
+
.attr('data-target', target),
|
21
|
+
$bubble = $('<div>')
|
22
|
+
.addClass(ns+'-bubble'),
|
23
|
+
|
24
|
+
// Final settings will be stored here
|
25
|
+
settings = {},
|
26
|
+
|
27
|
+
// Default settings
|
28
|
+
defaults = {
|
29
|
+
custom_class: null,
|
30
|
+
colors: null,
|
31
|
+
position: 'upside', // upside | downside
|
32
|
+
insert: 'before', // default
|
33
|
+
clear_btn: 'first', // default
|
34
|
+
timeout: 2000, // default
|
35
|
+
set_background: false, // default
|
36
|
+
close_all_but_this: false // default
|
37
|
+
},
|
38
|
+
|
39
|
+
click_handler = ('ontouchstart' in document.documentElement ? 'touchstart click' : 'click');
|
40
|
+
|
41
|
+
// Init
|
42
|
+
plugin.init = function() {
|
43
|
+
// Extand settings with user options
|
44
|
+
plugin.settings = $.extend({}, defaults, options);
|
45
|
+
|
46
|
+
// If input has not value add it
|
47
|
+
var
|
48
|
+
val = $el.attr('value');
|
49
|
+
if (typeof val === typeof undefined || val === false) {
|
50
|
+
val = '';
|
51
|
+
$el.attr('value', val);
|
52
|
+
}
|
53
|
+
|
54
|
+
// Backup initial value
|
55
|
+
$el.attr('data-initialvalue', $el.attr('value') );
|
56
|
+
|
57
|
+
// If color were not passed as options get them from data-palette attribute
|
58
|
+
if (plugin.settings.colors === null) {
|
59
|
+
plugin.settings.colors = $el.data('palette');
|
60
|
+
}
|
61
|
+
|
62
|
+
// If color is array of string, convert to obj
|
63
|
+
if (typeof plugin.settings.colors[0] === 'string') {
|
64
|
+
plugin.settings.colors = $.map(plugin.settings.colors, function(el, idx) {
|
65
|
+
var b = {}; b[el] = el; return b;
|
66
|
+
});
|
67
|
+
}
|
68
|
+
|
69
|
+
// Capitalize position
|
70
|
+
plugin.settings.insert = plugin.settings.insert.charAt(0).toUpperCase() + plugin.settings.insert.slice(1);
|
71
|
+
|
72
|
+
// Add custom_class
|
73
|
+
if (plugin.settings.custom_class) {
|
74
|
+
$bubble.addClass(plugin.settings.custom_class);
|
75
|
+
}
|
76
|
+
|
77
|
+
// Create color swatches
|
78
|
+
$.each( plugin.settings.colors, function( idx, obj ) {
|
79
|
+
var
|
80
|
+
key = Object.keys( obj )[0],
|
81
|
+
col = obj[key],
|
82
|
+
$sw = $('<span>').addClass('swatch')
|
83
|
+
.attr({
|
84
|
+
'title': key,
|
85
|
+
'data-color': col,
|
86
|
+
'data-name': key
|
87
|
+
}).css('background-color', col);
|
88
|
+
|
89
|
+
if ( key === current_value ) {
|
90
|
+
$sw.addClass('active');
|
91
|
+
$button.css('background', col);
|
92
|
+
}
|
93
|
+
|
94
|
+
$sw.appendTo( $bubble );
|
95
|
+
});
|
96
|
+
|
97
|
+
// Create clear button if not null
|
98
|
+
if (plugin.settings.clear_btn !== null) {
|
99
|
+
var
|
100
|
+
$clear_btn = $('<span>').addClass('swatch clear').attr('title', 'Clear selection');
|
101
|
+
if (plugin.settings.clear_btn === 'last') {
|
102
|
+
$clear_btn.addClass('last').appendTo( $bubble );
|
103
|
+
} else {
|
104
|
+
$clear_btn.prependTo( $bubble );
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
// Public
|
109
|
+
plugin.destroy = function() {
|
110
|
+
$button.remove();
|
111
|
+
$.removeData( $el[0] );
|
112
|
+
};
|
113
|
+
|
114
|
+
// Clears all
|
115
|
+
plugin.clear = function() {
|
116
|
+
$bubble.find('.active').removeClass('active');
|
117
|
+
$button.removeAttr('style');
|
118
|
+
$el.val('');
|
119
|
+
};
|
120
|
+
|
121
|
+
// Reset to initial value
|
122
|
+
plugin.reset = function() {
|
123
|
+
// Dont had initial value
|
124
|
+
if ( $el.attr('data-initialvalue') === '' ) {
|
125
|
+
plugin.clear();
|
126
|
+
} else {
|
127
|
+
// Had initial value
|
128
|
+
var iv = $el.attr('data-initialvalue');
|
129
|
+
$bubble.find('[data-name="'+iv+'"]').trigger('click');
|
130
|
+
}
|
131
|
+
};
|
132
|
+
|
133
|
+
// reload value after it has been changed programatically
|
134
|
+
plugin.reload = function() {
|
135
|
+
|
136
|
+
var newVal = $el.val();
|
137
|
+
if ( newVal === '' || typeof newVal === typeof undefined || newVal === false ) {
|
138
|
+
// Doesn't have the value to load so loading initial value
|
139
|
+
plugin.reset();
|
140
|
+
} else {
|
141
|
+
// setting the value to new value
|
142
|
+
if($bubble.find('[data-name="'+newVal+'"]').length) {
|
143
|
+
// value will only be set if the color exists in options
|
144
|
+
$bubble.find('[data-name="'+newVal+'"]').trigger('click');
|
145
|
+
} else {
|
146
|
+
// setting to the initial value if color does not exists
|
147
|
+
plugin.reset();
|
148
|
+
}
|
149
|
+
}
|
150
|
+
};
|
151
|
+
|
152
|
+
// Events
|
153
|
+
// Simple click
|
154
|
+
$button.append( $bubble ).on( click_handler, function(e){
|
155
|
+
e.preventDefault();
|
156
|
+
e.stopPropagation();
|
157
|
+
var $b = $( this );
|
158
|
+
|
159
|
+
// don't close on clicking the bubble
|
160
|
+
if (!$(e.target).hasClass(ns+'-bubble')) {
|
161
|
+
|
162
|
+
// Call the callback, if set
|
163
|
+
if (typeof plugin.settings.onbeforeshow_callback === 'function') {
|
164
|
+
plugin.settings.onbeforeshow_callback(this);
|
165
|
+
}
|
166
|
+
|
167
|
+
$b.toggleClass('active');
|
168
|
+
var $current_bubble = $b.find('.'+ns+'-bubble');
|
169
|
+
// Forces hiding other bubbles
|
170
|
+
if (plugin.settings.close_all_but_this) {
|
171
|
+
$('.'+ns+'-bubble').not($current_bubble).fadeOut();
|
172
|
+
}
|
173
|
+
$current_bubble.fadeToggle();
|
174
|
+
|
175
|
+
if ($b.hasClass('active')) {
|
176
|
+
clearTimeout(plugin.timer);
|
177
|
+
plugin.timer = setTimeout(function(){
|
178
|
+
$b.trigger('pcp.fadeout');
|
179
|
+
}, plugin.settings.timeout);
|
180
|
+
}
|
181
|
+
}
|
182
|
+
})
|
183
|
+
// Fade timer
|
184
|
+
.on('pcp.fadeout', function() {
|
185
|
+
$( this ).removeClass('active').find('.'+ns+'-bubble').fadeOut();
|
186
|
+
})
|
187
|
+
// Enter bubble
|
188
|
+
.on('mouseenter', '.'+ns+'-bubble', function() {
|
189
|
+
clearTimeout(plugin.timer);
|
190
|
+
})
|
191
|
+
// Leave bubble
|
192
|
+
.on('mouseleave', '.'+ns+'-bubble', function() {
|
193
|
+
plugin.timer = setTimeout(function(){
|
194
|
+
$button.trigger('pcp.fadeout');
|
195
|
+
}, plugin.settings.timeout);
|
196
|
+
})
|
197
|
+
// Click on swatches
|
198
|
+
.on(click_handler, '.'+ns+'-bubble span.swatch', function(e){
|
199
|
+
e.preventDefault();
|
200
|
+
e.stopPropagation();
|
201
|
+
var
|
202
|
+
col = $( this ).attr('data-color'),
|
203
|
+
name = $( this ).attr('data-name'),
|
204
|
+
// Select all button in document with same data target to keep them synconized
|
205
|
+
$button = $('.'+ns+'-button[data-target="' + $( this ).closest( '.'+ns+'-button' ).attr('data-target') + '"]'),
|
206
|
+
$bubble = $( this ).closest( '.'+ns+'-bubble' );
|
207
|
+
|
208
|
+
// console.log('.'+ns+'-button [data-target="' + $( this ).closest( '.'+ns+'-button' ).attr('data-target') + '"]');
|
209
|
+
$bubble.find('.active').removeClass('active');
|
210
|
+
|
211
|
+
// Set background on color
|
212
|
+
// User clicked in the clear swatch
|
213
|
+
if ( $(e.target).is('.clear') ) {
|
214
|
+
$button.removeAttr('style');
|
215
|
+
col = '';
|
216
|
+
} else {
|
217
|
+
$(this).addClass('active');
|
218
|
+
$button.css('background', col);
|
219
|
+
}
|
220
|
+
|
221
|
+
// Call the callback, if set
|
222
|
+
if (typeof plugin.settings.onchange_callback === "function") {
|
223
|
+
plugin.settings.onchange_callback(col);
|
224
|
+
}
|
225
|
+
|
226
|
+
if( plugin.settings.set_background === false ) {
|
227
|
+
$('[name="' + $button.attr('data-target') + '"]').val(name);
|
228
|
+
} else {
|
229
|
+
$('[name="' + $button.attr('data-target') + '"]').css({'background-color' : col});
|
230
|
+
}
|
231
|
+
})['insert'+plugin.settings.insert]( $el );
|
232
|
+
|
233
|
+
// Upside / downside, default is upside
|
234
|
+
if ( plugin.settings.position === 'downside' || ($el.offset().top) + 20 < $bubble.outerHeight() ) {
|
235
|
+
$bubble.addClass('downside');
|
236
|
+
}
|
237
|
+
|
238
|
+
};
|
239
|
+
|
240
|
+
// Close on clicking outside the palette
|
241
|
+
$('body').on(click_handler,function(event) {
|
242
|
+
if (!$(event.target).hasClass(ns+'-button')) {
|
243
|
+
$( $button ).removeClass('active').find('.'+ns+'-bubble').fadeOut();
|
244
|
+
}
|
245
|
+
});
|
246
|
+
|
247
|
+
// Start
|
248
|
+
plugin.init();
|
249
|
+
};
|
250
|
+
|
251
|
+
// add the plugin to the jQuery.fn object
|
252
|
+
$.fn.paletteColorPicker = function(options) {
|
253
|
+
return this.each(function() {
|
254
|
+
if (typeof $(this).data('paletteColorPickerPlugin') === 'undefined') {
|
255
|
+
$(this).data('paletteColorPickerPlugin', new $.paletteColorPicker(this, options));
|
256
|
+
}
|
257
|
+
});
|
258
|
+
};
|
259
|
+
|
260
|
+
})(jQuery);
|
261
|
+
|
262
|
+
// Sample usage
|
263
|
+
// $(function() {
|
264
|
+
// $('[data-palette-color-picker]').paletteColorPicker();
|
265
|
+
// });
|