cm-admin 1.5.37 → 1.5.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop-https---raw-githubusercontent-com-commutatus-cm-linters-main-rubocop-yml +7 -7
- data/Gemfile.lock +1 -1
- data/app/assets/javascripts/cm_admin/form_validation.js +31 -13
- data/app/assets/javascripts/cm_admin/scaffolds.js +51 -44
- data/app/assets/stylesheets/cm_admin/base/form.scss +13 -0
- data/app/assets/stylesheets/cm_admin/cm_admin.css.scss +2 -0
- data/app/assets/stylesheets/cm_admin/dependency/bootstrap/scss/_variables.scss +1 -0
- data/app/views/cm_admin/main/_nested_table_section.html.slim +1 -1
- data/config/importmap.rb +2 -1
- data/lib/cm_admin/models/form_field.rb +2 -2
- data/lib/cm_admin/models/section.rb +11 -1
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/form_field_helper.rb +182 -148
- data/lib/cm_admin/view_helpers/form_helper.rb +15 -2
- data/lib/generators/cm_admin/install_generator.rb +2 -3
- data/lib/generators/cm_admin/templates/custom.css +0 -1
- metadata +3 -3
- /data/{lib/generators/cm_admin/templates → app/assets/stylesheets/cm_admin}/actiontext.scss +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c40bfc75e34962bd8f06fdf048ab26a15bf28f6c12bcee4d610798c5039051fd
|
4
|
+
data.tar.gz: 9fd1bc8df6119bfdd081f54273e214a52c5a5f48f1ede629f2871f25c3ce29e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 489cb6075a78d061f8faf54bd785634bdfe0034b071e32f2b23e825861784052e82acdd74bfa10248f31ac15f582d0722d2cc94180de6765a9a6863270d16f99
|
7
|
+
data.tar.gz: 31da01d615e7f0af26d79dcd82d8f3737c832ee9c34962ab1d9dcb9ebea1b291dcb29c2dcc60cadf6c90b376f2f04456d1a55e78a5b4c879dbbca7ebbbc95268
|
@@ -1,20 +1,20 @@
|
|
1
1
|
AllCops:
|
2
|
-
|
2
|
+
DisabledByDefault: false
|
3
3
|
|
4
4
|
Style/FrozenStringLiteralComment:
|
5
|
-
|
5
|
+
Enabled: false
|
6
6
|
|
7
7
|
Style/Documentation:
|
8
|
-
|
8
|
+
Enabled: false
|
9
9
|
|
10
10
|
Layout/IndentationStyle:
|
11
|
-
|
11
|
+
Enabled: false
|
12
12
|
|
13
13
|
Layout/LineLength:
|
14
|
-
|
14
|
+
Enabled: false
|
15
15
|
|
16
16
|
Metrics/MethodLength:
|
17
|
-
|
17
|
+
Enabled: false
|
18
18
|
|
19
19
|
Metrics/AbcSize:
|
20
|
-
|
20
|
+
Enabled: false
|
data/Gemfile.lock
CHANGED
@@ -1,35 +1,53 @@
|
|
1
|
-
$(document).on(
|
1
|
+
$(document).on("click", '[data-behaviour="form_submit"]', function (e) {
|
2
2
|
e.preventDefault();
|
3
3
|
var submit = [];
|
4
|
-
var form_class = $(this).data(
|
5
|
-
$(
|
6
|
-
|
4
|
+
var form_class = $(this).data("form-class");
|
5
|
+
$(
|
6
|
+
"." + form_class + " input.required, ." + form_class + " textarea.required"
|
7
|
+
).each(function () {
|
8
|
+
$(this).removeClass("is-invalid");
|
7
9
|
if ($(this).val().trim().length === 0) {
|
8
|
-
$(this).addClass(
|
10
|
+
$(this).addClass("is-invalid");
|
9
11
|
$(this)[0].scrollIntoView(true);
|
10
12
|
submit.push(true);
|
11
13
|
}
|
12
14
|
});
|
13
15
|
$("." + form_class + " select.required").each(function () {
|
14
|
-
$(this).removeClass(
|
16
|
+
$(this).removeClass("is-invalid");
|
15
17
|
if ($(this).val().trim().length === 0) {
|
16
|
-
$(this).parent().find(
|
18
|
+
$(this).parent().find("select").addClass("is-invalid");
|
17
19
|
$(this)[0].scrollIntoView(true);
|
18
20
|
submit.push(true);
|
19
21
|
}
|
20
22
|
});
|
21
|
-
$(
|
23
|
+
$(".nested_input_validation").each(function () {
|
22
24
|
var class_name;
|
23
|
-
class_name = $(this).data(
|
24
|
-
$(this)
|
25
|
+
class_name = $(this).data("class-name");
|
26
|
+
$(this)
|
27
|
+
.parents(":nth(1)")
|
28
|
+
.find("." + class_name)
|
29
|
+
.addClass("hidden");
|
25
30
|
if ($(this).val().trim().length === 0) {
|
26
|
-
$(this)
|
31
|
+
$(this)
|
32
|
+
.parents(":nth(1)")
|
33
|
+
.find("." + class_name)
|
34
|
+
.removeClass("hidden");
|
27
35
|
$(this)[0].scrollIntoView(true);
|
28
36
|
submit.push(true);
|
29
37
|
}
|
30
38
|
});
|
31
39
|
if (submit.length === 0) {
|
32
|
-
$(
|
33
|
-
return $('[data-behaviour="form_submit"]').button(
|
40
|
+
$("." + form_class).submit();
|
41
|
+
return $('[data-behaviour="form_submit"]').button("loading");
|
42
|
+
}
|
43
|
+
});
|
44
|
+
|
45
|
+
$(document).on("change", '[data-behaviour="multiple-checkbox"]', function (e) {
|
46
|
+
const inputField = e.target.previousElementSibling;
|
47
|
+
|
48
|
+
if (e.target.checked) {
|
49
|
+
inputField.setAttribute("disabled", "disabled");
|
50
|
+
} else {
|
51
|
+
inputField.removeAttribute("disabled");
|
34
52
|
}
|
35
53
|
});
|
@@ -1,81 +1,88 @@
|
|
1
|
-
import jQuery from
|
2
|
-
window.jQuery = jQuery // <- "select2" will check this
|
3
|
-
window.$ = jQuery
|
1
|
+
import jQuery from "jquery";
|
2
|
+
window.jQuery = jQuery; // <- "select2" will check this
|
3
|
+
window.$ = jQuery;
|
4
4
|
|
5
5
|
// This is a hack to fix 'process is not defined'
|
6
6
|
// Ref article: https://adambien.blog/roller/abien/entry/uncaught_referenceerror_process_is_not
|
7
7
|
// Based on this filter dropdown works.
|
8
8
|
window.process = {
|
9
9
|
env: {
|
10
|
-
|
11
|
-
}
|
12
|
-
}
|
10
|
+
NODE_ENV: "development",
|
11
|
+
},
|
12
|
+
};
|
13
13
|
|
14
|
-
import
|
15
|
-
import
|
16
|
-
import
|
17
|
-
import
|
18
|
-
import
|
19
|
-
import
|
20
|
-
|
14
|
+
import "moment";
|
15
|
+
import "bootstrap";
|
16
|
+
import "@popperjs/core";
|
17
|
+
import "flatpickr";
|
18
|
+
import "jgrowl";
|
19
|
+
import "trix";
|
20
|
+
import "@rails/actiontext";
|
21
|
+
import Select2 from "select2";
|
22
|
+
Select2();
|
21
23
|
|
22
24
|
// import '@nathanvda/cocoon'
|
23
|
-
import
|
24
|
-
import
|
25
|
-
import jqueryJgrowl from
|
26
|
-
|
25
|
+
import "daterangepicker";
|
26
|
+
import "@fortawesome/fontawesome-free";
|
27
|
+
import jqueryJgrowl from "jgrowl";
|
27
28
|
|
28
29
|
document.addEventListener("turbo:load", function () {
|
29
30
|
flatpickr("[data-behaviour='date-only']", {
|
30
|
-
dateFormat: "d-m-Y"
|
31
|
-
})
|
31
|
+
dateFormat: "d-m-Y",
|
32
|
+
});
|
32
33
|
flatpickr("[data-behaviour='date-time']", {
|
33
|
-
enableTime: true
|
34
|
-
})
|
34
|
+
enableTime: true,
|
35
|
+
});
|
35
36
|
flatpickr("[data-behaviour='filter'][data-filter-type='date']", {
|
36
|
-
mode:
|
37
|
-
})
|
38
|
-
$(
|
37
|
+
mode: "range",
|
38
|
+
});
|
39
|
+
$(".select-2").select2({
|
39
40
|
theme: "bootstrap-5",
|
40
41
|
});
|
41
|
-
jqueryJgrowl()
|
42
|
+
jqueryJgrowl();
|
42
43
|
setup_select_2_ajax();
|
43
44
|
});
|
44
45
|
|
45
|
-
$(document).on(
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
$(document).on(
|
47
|
+
"click",
|
48
|
+
'[data-behaviour="toggle-profile-popup"]',
|
49
|
+
function (e) {
|
50
|
+
e.stopPropagation();
|
51
|
+
$('[data-behaviour="profile-popup"]').toggleClass("hidden");
|
52
|
+
}
|
53
|
+
);
|
49
54
|
|
50
|
-
$(document).on(
|
55
|
+
$(document).on("click", function (e) {
|
51
56
|
var popup = $('[data-behaviour="profile-popup"]');
|
52
57
|
if (!popup.is(e.target) && popup.has(e.target).length === 0) {
|
53
|
-
popup.addClass(
|
58
|
+
popup.addClass("hidden");
|
54
59
|
}
|
55
60
|
});
|
56
61
|
|
57
|
-
$(document).on(
|
62
|
+
$(document).on("click", ".destroy-attachment button", function (e) {
|
58
63
|
e.preventDefault();
|
59
|
-
var ar_id = $(this).parent(
|
60
|
-
$(this).parent(
|
61
|
-
$(this).append(
|
62
|
-
|
64
|
+
var ar_id = $(this).parent(".destroy-attachment").data("ar-id");
|
65
|
+
$(this).parent(".destroy-attachment").addClass("hidden");
|
66
|
+
$(this).append(
|
67
|
+
'<input type="text" name="attachment_destroy_ids[]" value="' + ar_id + '"/>'
|
68
|
+
);
|
69
|
+
});
|
63
70
|
|
64
|
-
window.addEventListener(
|
71
|
+
window.addEventListener("popstate", (e) => window.location.reload());
|
65
72
|
|
66
|
-
function setup_select_2_ajax(){
|
67
|
-
$(".select-2-ajax").each(function(index, element){
|
73
|
+
function setup_select_2_ajax() {
|
74
|
+
$(".select-2-ajax").each(function (index, element) {
|
68
75
|
$(element).select2({
|
69
76
|
ajax: {
|
70
|
-
url: $(element)[0][
|
71
|
-
dataType:
|
77
|
+
url: $(element)[0]["dataset"].ajaxUrl,
|
78
|
+
dataType: "json",
|
72
79
|
processResults: (data, params) => {
|
73
80
|
return {
|
74
81
|
results: data.results,
|
75
|
-
}
|
82
|
+
};
|
76
83
|
},
|
77
84
|
},
|
78
|
-
minimumInputLength: 0
|
85
|
+
minimumInputLength: 0,
|
79
86
|
});
|
80
87
|
});
|
81
|
-
}
|
88
|
+
}
|
@@ -21,9 +21,16 @@
|
|
21
21
|
@extend .h6, .fw-semibold;
|
22
22
|
color: $primary-text-clr;
|
23
23
|
}
|
24
|
+
.nested-form-title {
|
25
|
+
color: $nested-form-section-color;
|
26
|
+
margin-bottom: 16px;
|
27
|
+
}
|
24
28
|
&__inner {
|
25
29
|
@extend .card, .p-4;
|
26
30
|
background-color: var(--bs-gray-100);
|
31
|
+
&.nested_section {
|
32
|
+
padding: 1rem !important;
|
33
|
+
}
|
27
34
|
}
|
28
35
|
}
|
29
36
|
}
|
@@ -97,3 +104,9 @@
|
|
97
104
|
@extend .form-control;
|
98
105
|
}
|
99
106
|
}
|
107
|
+
|
108
|
+
.nested-section {
|
109
|
+
padding: 1.5rem;
|
110
|
+
border: 1px solid $gray-300;
|
111
|
+
background-color: $gray-100;
|
112
|
+
}
|
@@ -1422,6 +1422,7 @@ $form-feedback-tooltip-font-size: $tooltip-font-size !default;
|
|
1422
1422
|
$form-feedback-tooltip-line-height: null !default;
|
1423
1423
|
$form-feedback-tooltip-opacity: $tooltip-opacity !default;
|
1424
1424
|
$form-feedback-tooltip-border-radius: $tooltip-border-radius !default;
|
1425
|
+
$nested-form-section-color: #21252980;
|
1425
1426
|
// scss-docs-end tooltip-feedback-variables
|
1426
1427
|
|
1427
1428
|
|
@@ -28,4 +28,4 @@
|
|
28
28
|
|
29
29
|
- if nested_field.associated_fields.present?
|
30
30
|
- nested_field.associated_fields.each do |associated_nested_field|
|
31
|
-
= render partial: 'cm_admin/main/nested_table_section', locals: { nested_field: associated_nested_field, ar_object: record }
|
31
|
+
= render partial: 'cm_admin/main/nested_table_section', locals: { nested_field: associated_nested_field, ar_object: record }
|
data/config/importmap.rb
CHANGED
@@ -5,7 +5,8 @@ pin '@popperjs/core', to: 'https://ga.jspm.io/npm:@popperjs/core@2.11.5/lib/inde
|
|
5
5
|
pin 'flatpickr', to: 'https://ga.jspm.io/npm:flatpickr@4.6.13/dist/esm/index.js'
|
6
6
|
pin 'jgrowl', to: 'https://ga.jspm.io/npm:jgrowl@1.4.8/jquery.jgrowl.js'
|
7
7
|
pin 'moment', to: 'https://ga.jspm.io/npm:moment@2.29.4/moment.js'
|
8
|
-
pin 'trix', to: 'https://ga.jspm.io/npm:trix@2.
|
8
|
+
pin 'trix', to: 'https://ga.jspm.io/npm:trix@2.1.3/dist/trix.esm.min.js'
|
9
|
+
pin '@rails/actiontext', to: 'https://ga.jspm.io/npm:@rails/actiontext@7.1.3-4/app/assets/javascripts/actiontext.esm.js'
|
9
10
|
pin '@fortawesome/fontawesome-free', to: 'https://ga.jspm.io/npm:@fortawesome/fontawesome-free@6.1.1/js/all.js'
|
10
11
|
pin 'daterangepicker', to: 'https://ga.jspm.io/npm:daterangepicker@3.1.0/daterangepicker.js'
|
11
12
|
pin '@nathanvda/cocoon', to: 'https://ga.jspm.io/npm:@nathanvda/cocoon@1.2.14/cocoon.js'
|
@@ -9,8 +9,8 @@ module CmAdmin
|
|
9
9
|
:placeholder, :display_if, :html_attrs, :target, :col_size, :ajax_url, :helper_text
|
10
10
|
|
11
11
|
VALID_INPUT_TYPES = %i[
|
12
|
-
integer decimal string single_select multi_select date date_time text
|
13
|
-
single_file_upload multi_file_upload hidden rich_text check_box radio_button custom_string custom_date
|
12
|
+
integer decimal string single_select multi_select date date_time text switch custom_single_select
|
13
|
+
single_file_upload multi_file_upload hidden rich_text check_box radio_button custom_string custom_date
|
14
14
|
].freeze
|
15
15
|
|
16
16
|
def initialize(field_name, input_type, attributes = {})
|
@@ -6,7 +6,8 @@ module CmAdmin
|
|
6
6
|
# These list of fields are iterated and displayed on show/new/edit page.
|
7
7
|
# It also contains rows, which contains sections and fields.
|
8
8
|
|
9
|
-
attr_accessor :section_name, :section_fields, :display_if, :current_action, :cm_model, :
|
9
|
+
attr_accessor :section_name, :section_fields, :display_if, :current_action, :cm_model, :parent_section,
|
10
|
+
:nested_table_fields, :rows, :col_size, :current_nested_field, :nested_sections, :html_attrs
|
10
11
|
|
11
12
|
def initialize(section_name, current_action, cm_model, display_if, html_attrs, col_size, &block)
|
12
13
|
@section_fields = []
|
@@ -19,6 +20,8 @@ module CmAdmin
|
|
19
20
|
@html_attrs = html_attrs || {}
|
20
21
|
@display_if = display_if || ->(arg) { true }
|
21
22
|
@current_nested_field = nil
|
23
|
+
@nested_sections = []
|
24
|
+
@parent_section = nil
|
22
25
|
instance_eval(&block)
|
23
26
|
end
|
24
27
|
|
@@ -55,6 +58,13 @@ module CmAdmin
|
|
55
58
|
@rows ||= []
|
56
59
|
@rows << CmAdmin::Models::Row.new(@current_action, @model, display_if, html_attrs, &block)
|
57
60
|
end
|
61
|
+
|
62
|
+
def nested_form_section(section_name, display_if: nil, col_size: nil, html_attrs: nil, &block)
|
63
|
+
nested_section = CmAdmin::Models::Section.new(section_name, @current_action, @cm_model, display_if, html_attrs, col_size, &block)
|
64
|
+
nested_section.parent_section = self
|
65
|
+
@nested_sections ||= []
|
66
|
+
@nested_sections << nested_section
|
67
|
+
end
|
58
68
|
end
|
59
69
|
end
|
60
70
|
end
|
data/lib/cm_admin/version.rb
CHANGED
@@ -3,13 +3,14 @@ module CmAdmin
|
|
3
3
|
module FormFieldHelper
|
4
4
|
def input_field_for_column(form_obj, cm_field)
|
5
5
|
return unless cm_field.display_if.call(form_obj.object)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
|
7
|
+
value = if cm_field.helper_method
|
8
|
+
send(cm_field.helper_method, form_obj.object, cm_field.field_name)
|
9
|
+
elsif cm_field.input_type.to_s.include?('custom')
|
10
|
+
nil
|
11
|
+
else
|
12
|
+
form_obj.object.send(cm_field.field_name)
|
13
|
+
end
|
13
14
|
# value = cm_field.helper_method ? send(cm_field.helper_method, form_obj.object, cm_field.field_name) : form_obj.object.send(cm_field.field_name)
|
14
15
|
is_required = form_obj.object._validators[cm_field.field_name].map(&:kind).include?(:presence)
|
15
16
|
required_class = is_required ? 'required' : ''
|
@@ -20,156 +21,182 @@ module CmAdmin
|
|
20
21
|
def cm_integer_field(form_obj, cm_field, value, required_class, _target_action, _ajax_url)
|
21
22
|
form_obj.text_field cm_field.field_name,
|
22
23
|
merge_wrapper_options(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
{
|
25
|
+
class: "field-control #{required_class}",
|
26
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
27
|
+
value:,
|
28
|
+
placeholder: cm_field.placeholder,
|
29
|
+
data: { behaviour: 'integer-only' }
|
30
|
+
}, cm_field.html_attrs
|
31
|
+
)
|
30
32
|
end
|
31
33
|
|
32
34
|
def cm_decimal_field(form_obj, cm_field, value, required_class, _target_action, _ajax_url)
|
33
35
|
form_obj.text_field cm_field.field_name,
|
34
36
|
merge_wrapper_options({
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
class: "field-control #{required_class}",
|
38
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
39
|
+
value:,
|
40
|
+
placeholder: cm_field.placeholder,
|
41
|
+
data: { behaviour: 'decimal-only' }
|
42
|
+
}, cm_field.html_attrs)
|
41
43
|
end
|
42
44
|
|
43
45
|
def cm_string_field(form_obj, cm_field, value, required_class, _target_action, _ajax_url)
|
44
46
|
form_obj.text_field cm_field.field_name,
|
45
47
|
merge_wrapper_options(
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
{
|
49
|
+
class: "field-control #{required_class}",
|
50
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
51
|
+
value:,
|
52
|
+
placeholder: cm_field.placeholder
|
53
|
+
}, cm_field.html_attrs
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def cm_switch_field(form_obj, cm_field, value, required_class, _target_action, _ajax_url)\
|
58
|
+
content_tag :div, class: 'form-check form-switch' do
|
59
|
+
form_obj.check_box cm_field.field_name,
|
60
|
+
merge_wrapper_options(
|
61
|
+
{
|
62
|
+
class: "field-control form-check-input #{required_class}",
|
63
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
64
|
+
value:,
|
65
|
+
role: 'switch'
|
66
|
+
}, cm_field.html_attrs
|
67
|
+
)
|
68
|
+
end
|
52
69
|
end
|
53
70
|
|
54
71
|
def cm_custom_string_field(form_obj, cm_field, value, required_class, _target_action_ajax_url)
|
55
72
|
text_field_tag cm_field.html_attrs[:name] || cm_field.field_name,
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
73
|
+
merge_wrapper_options(
|
74
|
+
{
|
75
|
+
value:,
|
76
|
+
class: "field-control #{required_class}",
|
77
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
78
|
+
placeholder: cm_field.placeholder
|
79
|
+
}, cm_field.html_attrs
|
80
|
+
)
|
63
81
|
end
|
64
82
|
|
65
|
-
def cm_single_select_field(form_obj, cm_field,
|
83
|
+
def cm_single_select_field(form_obj, cm_field, _value, required_class, target_action, ajax_url)
|
66
84
|
class_name = ajax_url.present? ? 'select-2-ajax' : 'select-2'
|
67
85
|
form_obj.select cm_field.field_name, options_for_select(select_collection_value(form_obj.object, cm_field), form_obj.object.send(cm_field.field_name)),
|
68
|
-
{include_blank: cm_field.placeholder},
|
86
|
+
{ include_blank: cm_field.placeholder },
|
69
87
|
merge_wrapper_options(
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
88
|
+
{
|
89
|
+
class: "field-control #{required_class} #{class_name}",
|
90
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
91
|
+
data: {
|
92
|
+
field_name: cm_field.field_name,
|
93
|
+
field_type: 'linked-field',
|
94
|
+
target_action: target_action&.name,
|
95
|
+
target_url: target_action&.name ? cm_admin.send("#{@model.name.underscore}_#{target_action&.name}_path") : '',
|
96
|
+
ajax_url:
|
97
|
+
}
|
98
|
+
}, cm_field.html_attrs
|
99
|
+
)
|
81
100
|
end
|
82
101
|
|
83
|
-
def cm_custom_single_select_field(form_obj, cm_field,
|
102
|
+
def cm_custom_single_select_field(form_obj, cm_field, _value, required_class, target_action, _ajax_url)
|
84
103
|
select_tag cm_field.html_attrs[:name] || cm_field.field_name,
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
104
|
+
options_for_select(select_collection_value(form_obj.object, cm_field)),
|
105
|
+
{ include_blank: cm_field.placeholder },
|
106
|
+
merge_wrapper_options(
|
107
|
+
{
|
108
|
+
class: "field-control #{required_class} select-2",
|
109
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
110
|
+
data: {
|
111
|
+
field_name: cm_field.field_name,
|
112
|
+
field_type: 'linked-field',
|
113
|
+
target_action: target_action&.name,
|
114
|
+
target_url: target_action&.name ? cm_admin.send("#{@model.name.underscore}_#{target_action&.name}_path") : ''
|
115
|
+
}
|
116
|
+
}, cm_field.html_attrs
|
117
|
+
)
|
98
118
|
end
|
99
119
|
|
100
|
-
def cm_multi_select_field(form_obj, cm_field,
|
120
|
+
def cm_multi_select_field(form_obj, cm_field, _value, required_class, _target_action, _ajax_url)
|
101
121
|
form_obj.select cm_field.field_name,
|
102
122
|
options_for_select(select_collection_value(form_obj.object, cm_field), form_obj.object.send(cm_field.field_name)),
|
103
123
|
{ include_blank: cm_field.placeholder },
|
104
124
|
merge_wrapper_options(
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
125
|
+
{
|
126
|
+
class: "field-control #{required_class} select-2",
|
127
|
+
disabled: cm_field.disabled.call(form_obj.object), multiple: true
|
128
|
+
}, cm_field.html_attrs
|
129
|
+
)
|
109
130
|
end
|
110
131
|
|
111
132
|
def cm_date_field(form_obj, cm_field, value, required_class, _target_action, _ajax_url)
|
112
133
|
form_obj.text_field cm_field.field_name,
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
134
|
+
merge_wrapper_options(
|
135
|
+
{
|
136
|
+
class: "field-control #{required_class}",
|
137
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
138
|
+
value: value&.strftime('%d-%m-%Y'),
|
139
|
+
placeholder: cm_field.placeholder,
|
140
|
+
data: { behaviour: 'date-only' }
|
141
|
+
}, cm_field.html_attrs
|
142
|
+
)
|
121
143
|
end
|
122
144
|
|
123
145
|
def cm_custom_date_field(form_obj, cm_field, value, required_class, _target_action, _ajax_url)
|
124
146
|
text_field_tag cm_field.html_attrs[:name] || cm_field.field_name, value&.strftime('%d-%m-%Y'),
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
147
|
+
merge_wrapper_options(
|
148
|
+
{
|
149
|
+
class: "field-control #{required_class}",
|
150
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
151
|
+
value: value&.strftime('%d-%m-%Y'),
|
152
|
+
placeholder: cm_field.placeholder,
|
153
|
+
data: { behaviour: 'date-only' }
|
154
|
+
}, cm_field.html_attrs
|
155
|
+
)
|
133
156
|
end
|
134
157
|
|
135
158
|
def cm_date_time_field(form_obj, cm_field, value, required_class, _target_action, _ajax_url)
|
136
159
|
form_obj.text_field cm_field.field_name,
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
160
|
+
merge_wrapper_options(
|
161
|
+
{
|
162
|
+
class: "field-control #{required_class}",
|
163
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
164
|
+
value:,
|
165
|
+
placeholder: cm_field.placeholder,
|
166
|
+
data: { behaviour: 'date-time' }
|
167
|
+
}, cm_field.html_attrs
|
168
|
+
)
|
145
169
|
end
|
146
170
|
|
147
|
-
def cm_text_field(form_obj, cm_field,
|
171
|
+
def cm_text_field(form_obj, cm_field, _value, required_class, _target_action, _ajax_url)
|
148
172
|
form_obj.text_area cm_field.field_name,
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
173
|
+
merge_wrapper_options(
|
174
|
+
{
|
175
|
+
class: "field-control #{required_class}",
|
176
|
+
placeholder: cm_field.placeholder
|
177
|
+
}, cm_field.html_attrs
|
178
|
+
)
|
154
179
|
end
|
155
180
|
|
156
|
-
def cm_rich_text_field(form_obj, cm_field,
|
181
|
+
def cm_rich_text_field(form_obj, cm_field, _value, required_class, _target_action, _ajax_url)
|
157
182
|
form_obj.rich_text_area cm_field.field_name,
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
183
|
+
merge_wrapper_options(
|
184
|
+
{
|
185
|
+
class: "field-control #{required_class}",
|
186
|
+
placeholder: cm_field.placeholder
|
187
|
+
}, cm_field.html_attrs
|
188
|
+
)
|
163
189
|
end
|
164
190
|
|
165
191
|
def cm_single_file_upload_field(form_obj, cm_field, _value, required_class, _target_action, _ajax_url)
|
166
192
|
content_tag(:div) do
|
167
193
|
concat form_obj.file_field cm_field.field_name,
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
194
|
+
merge_wrapper_options(
|
195
|
+
{
|
196
|
+
class: "field-control #{required_class}",
|
197
|
+
disabled: cm_field.disabled.call(form_obj.object)
|
198
|
+
}, cm_field.html_attrs
|
199
|
+
)
|
173
200
|
concat attachment_list(form_obj, cm_field, _value, required_class, _target_action)
|
174
201
|
end
|
175
202
|
end
|
@@ -177,16 +204,17 @@ module CmAdmin
|
|
177
204
|
def cm_multi_file_upload_field(form_obj, cm_field, _value, required_class, _target_action, _ajax_url)
|
178
205
|
content_tag(:div) do
|
179
206
|
concat form_obj.file_field cm_field.field_name,
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
207
|
+
merge_wrapper_options(
|
208
|
+
{
|
209
|
+
multiple: true, class: "field-control #{required_class}",
|
210
|
+
disabled: cm_field.disabled.call(form_obj.object)
|
211
|
+
}, cm_field.html_attrs
|
212
|
+
)
|
185
213
|
concat attachment_list(form_obj, cm_field, _value, required_class, _target_action)
|
186
214
|
end
|
187
215
|
end
|
188
216
|
|
189
|
-
def attachment_list(form_obj, cm_field, _value,
|
217
|
+
def attachment_list(form_obj, cm_field, _value, _required_class, _target_action)
|
190
218
|
attached = form_obj.object.send(cm_field.field_name)
|
191
219
|
return if defined?(::Paperclip) && attached.instance_of?(::Paperclip::Attachment)
|
192
220
|
|
@@ -195,14 +223,14 @@ module CmAdmin
|
|
195
223
|
attached.each do |attachment|
|
196
224
|
concat attachment_with_icon(attachment)
|
197
225
|
end
|
198
|
-
|
199
|
-
concat attachment_with_icon(attached)
|
226
|
+
elsif attached.attached?
|
227
|
+
concat attachment_with_icon(attached)
|
200
228
|
end
|
201
229
|
end
|
202
230
|
end
|
203
231
|
|
204
232
|
def attachment_with_icon(attachment)
|
205
|
-
content_tag(:div, class: 'destroy-attachment', data: { ar_id: attachment.id}) do
|
233
|
+
content_tag(:div, class: 'destroy-attachment', data: { ar_id: attachment.id }) do
|
206
234
|
concat(content_tag(:button, '', class: 'btn-ghost') do
|
207
235
|
concat tag.i(class: 'fa-regular fa-trash-can')
|
208
236
|
end)
|
@@ -214,17 +242,18 @@ module CmAdmin
|
|
214
242
|
format_check_box_options(value, form_obj, cm_field, required_class, target_action)
|
215
243
|
end
|
216
244
|
|
217
|
-
def cm_radio_button_field(form_obj,
|
245
|
+
def cm_radio_button_field(form_obj, _cm_field, value, _required_class, _target_action, _ajax_url)
|
218
246
|
format_radio_button_options(value, form_obj)
|
219
247
|
end
|
220
248
|
|
221
|
-
def cm_hidden_field(form_obj, cm_field, value,
|
249
|
+
def cm_hidden_field(form_obj, cm_field, value, _required_class, _target_action, _ajax_url)
|
222
250
|
form_obj.hidden_field cm_field.field_name,
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
251
|
+
merge_wrapper_options(
|
252
|
+
{
|
253
|
+
value:,
|
254
|
+
name: cm_field.html_attrs[:name] || "#{form_obj.object_name}[#{cm_field.field_name}]"
|
255
|
+
}, cm_field.html_attrs
|
256
|
+
)
|
228
257
|
end
|
229
258
|
|
230
259
|
# Refactor: Collection argument can be removed.
|
@@ -244,16 +273,17 @@ module CmAdmin
|
|
244
273
|
format_check_box_array(value, form_obj, cm_field, required_class, target_action)
|
245
274
|
else
|
246
275
|
form_obj.check_box cm_field.field_name,
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
276
|
+
merge_wrapper_options(
|
277
|
+
{
|
278
|
+
class: "cm-checkbox #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
|
279
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
280
|
+
data: {
|
281
|
+
field_name: cm_field.field_name,
|
282
|
+
target_action: target_action&.name,
|
283
|
+
target_url: target_action&.name ? cm_admin.send("#{@model.name.underscore}_#{target_action&.name}_path") : ''
|
284
|
+
}
|
285
|
+
}, cm_field.html_attrs
|
286
|
+
)
|
257
287
|
end
|
258
288
|
end
|
259
289
|
|
@@ -274,18 +304,23 @@ module CmAdmin
|
|
274
304
|
|
275
305
|
def format_check_box_tag(val, form_obj, cm_field, required_class, target_action)
|
276
306
|
content_tag :div, class: 'cm-radio-tag' do
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
307
|
+
if val.present?
|
308
|
+
concat form_obj.text_field cm_field.field_name, name: "#{@model.name.underscore}[#{cm_field.field_name}][]", value: '0', hidden: true, disabled: 'disabled'
|
309
|
+
else
|
310
|
+
concat form_obj.text_field cm_field.field_name, name: "#{@model.name.underscore}[#{cm_field.field_name}][]", value: '0', hidden: true
|
311
|
+
end
|
312
|
+
concat check_box_tag "#{@model.name.underscore}[#{cm_field.field_name}][]", '1', val,
|
313
|
+
merge_wrapper_options(
|
314
|
+
{
|
315
|
+
class: "cm-checkbox multiple-checkbox #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
|
316
|
+
disabled: cm_field.disabled.call(form_obj.object),
|
317
|
+
data: {
|
318
|
+
behaviour: 'multiple-checkbox',
|
319
|
+
target_action: target_action&.name,
|
320
|
+
target_url: target_action&.name ? cm_admin.send("#{@model.name.underscore}_#{target_action&.name}_path", ':param_1') : ''
|
321
|
+
}
|
322
|
+
}, cm_field.html_attrs
|
323
|
+
)
|
289
324
|
end
|
290
325
|
end
|
291
326
|
|
@@ -314,9 +349,9 @@ module CmAdmin
|
|
314
349
|
if html_attrs
|
315
350
|
options.merge(html_attrs) do |key, oldval, newval|
|
316
351
|
case key.to_s
|
317
|
-
when
|
318
|
-
oldval +
|
319
|
-
when
|
352
|
+
when 'class'
|
353
|
+
oldval + ' ' + newval
|
354
|
+
when 'data', 'aria'
|
320
355
|
oldval.merge(newval)
|
321
356
|
else
|
322
357
|
newval
|
@@ -326,7 +361,6 @@ module CmAdmin
|
|
326
361
|
options
|
327
362
|
end
|
328
363
|
end
|
329
|
-
|
330
364
|
end
|
331
365
|
end
|
332
366
|
end
|
@@ -65,7 +65,7 @@ module CmAdmin
|
|
65
65
|
|
66
66
|
def create_sections(resource, form_obj, section)
|
67
67
|
content_tag :div, class: 'col form-container' do
|
68
|
-
concat content_tag(:p, section.section_name, class: 'form-title')
|
68
|
+
concat content_tag(:p, section.section_name, class: 'form-title') unless section.parent_section.present?
|
69
69
|
concat set_form_for_fields(resource, form_obj, section)
|
70
70
|
end
|
71
71
|
end
|
@@ -82,9 +82,11 @@ module CmAdmin
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def set_form_for_fields(resource, form_obj, section)
|
85
|
-
content_tag(:div, class:
|
85
|
+
content_tag(:div, class: "form-container__inner #{section.parent_section.present? ? 'nested_section' : ''}") do
|
86
|
+
concat content_tag(:h6, section.section_name, class: 'nested-form-title') if section.parent_section.present?
|
86
87
|
concat create_row_inside_section(resource, form_obj, section.rows) if section.rows.present?
|
87
88
|
concat set_form_fields(resource, form_obj, section.section_fields)
|
89
|
+
concat set_nested_section_form_fields(resource, form_obj, section.nested_sections)
|
88
90
|
concat set_nested_form_fields(form_obj, section)
|
89
91
|
end
|
90
92
|
end
|
@@ -118,6 +120,17 @@ module CmAdmin
|
|
118
120
|
end
|
119
121
|
end
|
120
122
|
|
123
|
+
def set_nested_section_form_fields(resource, form_obj, nested_sections)
|
124
|
+
return if nested_sections.blank?
|
125
|
+
|
126
|
+
nested_sections.each do |nested_section|
|
127
|
+
next unless nested_section.display_if.call(form_obj.object)
|
128
|
+
|
129
|
+
concat create_sections(resource, form_obj, nested_section)
|
130
|
+
end
|
131
|
+
nil
|
132
|
+
end
|
133
|
+
|
121
134
|
def set_nested_form_fields(form_obj, section)
|
122
135
|
content_tag(:div) do
|
123
136
|
section.nested_table_fields.each do |nested_table_field|
|
@@ -10,8 +10,7 @@ module CmAdmin
|
|
10
10
|
copy_file 'cm_admin_initializer.rb', 'config/initializers/zcm_admin.rb'
|
11
11
|
copy_file 'custom.js', 'app/assets/javascripts/cm_admin/custom.js'
|
12
12
|
copy_file 'custom.css', 'app/assets/stylesheets/cm_admin/custom.css'
|
13
|
-
|
14
|
-
remove_file 'app/assets/stylesheets/actiontext.scss'
|
13
|
+
remove_file 'app/assets/stylesheets/actiontext.css'
|
15
14
|
copy_file 'application_policy.rb', 'app/policies/application_policy.rb'
|
16
15
|
route 'mount CmAdmin::Engine => "/admin"'
|
17
16
|
generate 'migration', 'CreateFileImport associated_model_name:string added_by:references{polymorphic} error_report:jsonb completed_at:datetime status:integer'
|
@@ -19,4 +18,4 @@ module CmAdmin
|
|
19
18
|
end
|
20
19
|
end
|
21
20
|
end
|
22
|
-
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cm-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.38
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: exe
|
16
16
|
cert_chain: []
|
17
|
-
date: 2024-07-
|
17
|
+
date: 2024-07-19 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: caxlsx_rails
|
@@ -212,6 +212,7 @@ files:
|
|
212
212
|
- app/assets/javascripts/cm_admin/quick_search.js
|
213
213
|
- app/assets/javascripts/cm_admin/scaffolds.js
|
214
214
|
- app/assets/javascripts/cm_admin/shared_scaffolds.js
|
215
|
+
- app/assets/stylesheets/cm_admin/actiontext.scss
|
215
216
|
- app/assets/stylesheets/cm_admin/base/auth.scss
|
216
217
|
- app/assets/stylesheets/cm_admin/base/cardView.scss
|
217
218
|
- app/assets/stylesheets/cm_admin/base/comments.scss
|
@@ -454,7 +455,6 @@ files:
|
|
454
455
|
- lib/generators/cm_admin/add_graphql_generator.rb
|
455
456
|
- lib/generators/cm_admin/install_generator.rb
|
456
457
|
- lib/generators/cm_admin/policy_generator.rb
|
457
|
-
- lib/generators/cm_admin/templates/actiontext.scss
|
458
458
|
- lib/generators/cm_admin/templates/application_controller.rb
|
459
459
|
- lib/generators/cm_admin/templates/application_policy.rb
|
460
460
|
- lib/generators/cm_admin/templates/authentication.rb
|
File without changes
|