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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cce8e5c65aa77c43396097851a57db6c824476a31cbd7fee30b55743cca54518
4
- data.tar.gz: '0695bb415b0fb2440c9c61ff43fe856b11f146d53d84b80fa543ab74b4bc760a'
3
+ metadata.gz: c40bfc75e34962bd8f06fdf048ab26a15bf28f6c12bcee4d610798c5039051fd
4
+ data.tar.gz: 9fd1bc8df6119bfdd081f54273e214a52c5a5f48f1ede629f2871f25c3ce29e3
5
5
  SHA512:
6
- metadata.gz: 5a8af60842c7016aaa0826b17d289f36d247d38fcf909ec19979d8bc105d5dd18e1dff727c0823e24e84163560241779fd6b9e7b6b9c28956dedfa18effaec4e
7
- data.tar.gz: 194106cb9cc410a74ad20bf31be36acd3aadf92cb2132322a62a0988d4f8965a127d1f951c306721aef0ac020170c85d4a32df0c7850a634bca0a5f0ca81e8bd
6
+ metadata.gz: 489cb6075a78d061f8faf54bd785634bdfe0034b071e32f2b23e825861784052e82acdd74bfa10248f31ac15f582d0722d2cc94180de6765a9a6863270d16f99
7
+ data.tar.gz: 31da01d615e7f0af26d79dcd82d8f3737c832ee9c34962ab1d9dcb9ebea1b291dcb29c2dcc60cadf6c90b376f2f04456d1a55e78a5b4c879dbbca7ebbbc95268
@@ -1,20 +1,20 @@
1
1
  AllCops:
2
- DisabledByDefault: false
2
+ DisabledByDefault: false
3
3
 
4
4
  Style/FrozenStringLiteralComment:
5
- Enabled: false
5
+ Enabled: false
6
6
 
7
7
  Style/Documentation:
8
- Enabled: false
8
+ Enabled: false
9
9
 
10
10
  Layout/IndentationStyle:
11
- Enabled: false
11
+ Enabled: false
12
12
 
13
13
  Layout/LineLength:
14
- Enabled: false
14
+ Enabled: false
15
15
 
16
16
  Metrics/MethodLength:
17
- Enabled: false
17
+ Enabled: false
18
18
 
19
19
  Metrics/AbcSize:
20
- Enabled: false
20
+ Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-admin (1.5.37)
4
+ cm-admin (1.5.38)
5
5
  caxlsx_rails
6
6
  cocoon (~> 1.2.15)
7
7
  csv-importer (~> 0.8.2)
@@ -1,35 +1,53 @@
1
- $(document).on('click', '[data-behaviour="form_submit"]', function (e) {
1
+ $(document).on("click", '[data-behaviour="form_submit"]', function (e) {
2
2
  e.preventDefault();
3
3
  var submit = [];
4
- var form_class = $(this).data('form-class');
5
- $("." + form_class + " input.required, ." + form_class + " textarea.required").each(function () {
6
- $(this).removeClass('is-invalid');
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('is-invalid');
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('is-invalid');
16
+ $(this).removeClass("is-invalid");
15
17
  if ($(this).val().trim().length === 0) {
16
- $(this).parent().find('select').addClass('is-invalid');
18
+ $(this).parent().find("select").addClass("is-invalid");
17
19
  $(this)[0].scrollIntoView(true);
18
20
  submit.push(true);
19
21
  }
20
22
  });
21
- $('.nested_input_validation').each(function () {
23
+ $(".nested_input_validation").each(function () {
22
24
  var class_name;
23
- class_name = $(this).data('class-name');
24
- $(this).parents(':nth(1)').find('.' + class_name).addClass('hidden');
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).parents(':nth(1)').find('.' + class_name).removeClass('hidden');
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
- $('.' + form_class).submit();
33
- return $('[data-behaviour="form_submit"]').button('loading');
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 'jquery';
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
- NODE_ENV: 'development'
11
- }
12
- }
10
+ NODE_ENV: "development",
11
+ },
12
+ };
13
13
 
14
- import 'moment'
15
- import 'bootstrap'
16
- import '@popperjs/core'
17
- import 'flatpickr'
18
- import 'jgrowl'
19
- import Select2 from "select2"
20
- Select2()
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 'daterangepicker'
24
- import '@fortawesome/fontawesome-free'
25
- import jqueryJgrowl from 'jgrowl';
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: 'range'
37
- })
38
- $('.select-2').select2({
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('click', '[data-behaviour="toggle-profile-popup"]', function(e) {
46
- e.stopPropagation();
47
- $('[data-behaviour="profile-popup"]').toggleClass('hidden');
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('click', function(e) {
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('hidden');
58
+ popup.addClass("hidden");
54
59
  }
55
60
  });
56
61
 
57
- $(document).on('click', '.destroy-attachment button', function(e) {
62
+ $(document).on("click", ".destroy-attachment button", function (e) {
58
63
  e.preventDefault();
59
- var ar_id = $(this).parent('.destroy-attachment').data('ar-id')
60
- $(this).parent('.destroy-attachment').addClass('hidden')
61
- $(this).append('<input type="text" name="attachment_destroy_ids[]" value="' + ar_id + '"/>')
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('popstate', e => window.location.reload() );
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]['dataset'].ajaxUrl,
71
- dataType: 'json',
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
+ }
@@ -1,3 +1,5 @@
1
+ @import "./actiontext";
2
+ @import "trix";
1
3
  @import "./dependency/bootstrap/scss/bootstrap";
2
4
  @import "./helpers/index.scss";
3
5
  @import "./pages/import_page";
@@ -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.0.0-beta.0/dist/trix.js'
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 custom_single_select
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, :nested_table_fields, :rows, :col_size, :current_nested_field, :html_attrs
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
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = '1.5.37'
2
+ VERSION = '1.5.38'
3
3
  end
@@ -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
- if cm_field.helper_method
7
- value = send(cm_field.helper_method, form_obj.object, cm_field.field_name)
8
- elsif cm_field.input_type.to_s.include?('custom')
9
- value = nil
10
- else
11
- value = form_obj.object.send(cm_field.field_name)
12
- end
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
- class: "field-control #{required_class}",
25
- disabled: cm_field.disabled.call(form_obj.object),
26
- value: value,
27
- placeholder: cm_field.placeholder,
28
- data: { behaviour: 'integer-only' }
29
- }, cm_field.html_attrs )
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
- class: "field-control #{required_class}",
36
- disabled: cm_field.disabled.call(form_obj.object),
37
- value: value,
38
- placeholder: cm_field.placeholder,
39
- data: { behaviour: 'decimal-only' }
40
- }, cm_field.html_attrs )
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
- class: "field-control #{required_class}",
48
- disabled: cm_field.disabled.call(form_obj.object),
49
- value: value,
50
- placeholder: cm_field.placeholder
51
- }, cm_field.html_attrs )
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
- merge_wrapper_options(
57
- {
58
- value: value,
59
- class: "field-control #{required_class}",
60
- disabled: cm_field.disabled.call(form_obj.object),
61
- placeholder: cm_field.placeholder
62
- }, cm_field.html_attrs )
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, value, required_class, target_action, ajax_url)
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
- class: "field-control #{required_class} #{class_name}",
72
- disabled: cm_field.disabled.call(form_obj.object),
73
- data: {
74
- field_name: cm_field.field_name,
75
- field_type: 'linked-field',
76
- target_action: target_action&.name,
77
- target_url: target_action&.name ? cm_admin.send("#{@model.name.underscore}_#{target_action&.name}_path") : '',
78
- ajax_url: ajax_url
79
- }
80
- }, cm_field.html_attrs )
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, value, required_class, target_action, _ajax_url)
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
- options_for_select(select_collection_value(form_obj.object, cm_field)),
86
- { include_blank: cm_field.placeholder },
87
- merge_wrapper_options(
88
- {
89
- class: "field-control #{required_class} select-2",
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
- }
97
- }, cm_field.html_attrs )
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, value, required_class, target_action, _ajax_url)
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
- class: "field-control #{required_class} select-2",
107
- disabled: cm_field.disabled.call(form_obj.object), multiple: true
108
- }, cm_field.html_attrs )
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
- merge_wrapper_options(
114
- {
115
- class: "field-control #{required_class}",
116
- disabled: cm_field.disabled.call(form_obj.object),
117
- value: value&.strftime('%d-%m-%Y'),
118
- placeholder: cm_field.placeholder,
119
- data: { behaviour: 'date-only' }
120
- }, cm_field.html_attrs )
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
- merge_wrapper_options(
126
- {
127
- class: "field-control #{required_class}",
128
- disabled: cm_field.disabled.call(form_obj.object),
129
- value: value&.strftime('%d-%m-%Y'),
130
- placeholder: cm_field.placeholder,
131
- data: { behaviour: 'date-only' }
132
- }, cm_field.html_attrs )
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
- merge_wrapper_options(
138
- {
139
- class: "field-control #{required_class}",
140
- disabled: cm_field.disabled.call(form_obj.object),
141
- value: value,
142
- placeholder: cm_field.placeholder,
143
- data: { behaviour: 'date-time' }
144
- }, cm_field.html_attrs )
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, value, required_class, _target_action, _ajax_url)
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
- merge_wrapper_options(
150
- {
151
- class: "field-control #{required_class}",
152
- placeholder: cm_field.placeholder
153
- }, cm_field.html_attrs)
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, value, required_class, _target_action, _ajax_url)
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
- merge_wrapper_options(
159
- {
160
- class: "field-control #{required_class}",
161
- placeholder: cm_field.placeholder
162
- }, cm_field.html_attrs)
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
- merge_wrapper_options(
169
- {
170
- class: "field-control #{required_class}",
171
- disabled: cm_field.disabled.call(form_obj.object)
172
- }, cm_field.html_attrs )
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
- merge_wrapper_options(
181
- {
182
- multiple: true, class: "field-control #{required_class}",
183
- disabled: cm_field.disabled.call(form_obj.object)
184
- }, cm_field.html_attrs )
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, required_class, _target_action)
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
- else
199
- concat attachment_with_icon(attached) if attached.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, cm_field, value, required_class, _target_action, _ajax_url)
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, required_class, _target_action, _ajax_url)
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
- merge_wrapper_options(
224
- {
225
- value: value,
226
- name: cm_field.html_attrs[:name] || "#{form_obj.object_name}[#{cm_field.field_name}]"
227
- }, cm_field.html_attrs )
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
- merge_wrapper_options(
248
- {
249
- class: "cm-checkbox #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
250
- disabled: cm_field.disabled.call(form_obj.object),
251
- data: {
252
- field_name: cm_field.field_name,
253
- target_action: target_action&.name,
254
- target_url: target_action&.name ? cm_admin.send("#{@model.name.underscore}_#{target_action&.name}_path") : ''
255
- }
256
- }, cm_field.html_attrs )
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
- concat form_obj.check_box cm_field.field_name,
278
- merge_wrapper_options(
279
- {
280
- class: "cm-checkbox #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
281
- disabled: cm_field.disabled.call(form_obj.object),
282
- name: "#{@model.name.underscore}[#{cm_field.field_name}][]",
283
- data: {
284
- target_action: target_action&.name,
285
- target_url: target_action&.name ? cm_admin.send("#{@model.name.underscore}_#{target_action&.name}_path", ':param_1') : ''
286
- }
287
- }, cm_field.html_attrs ),
288
- val
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 "class"
318
- oldval + " " + newval
319
- when "data", "aria"
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: 'form-container__inner') do
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
- copy_file 'actiontext.scss', 'app/assets/stylesheets/cm_admin/actiontext.scss'
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
@@ -2,4 +2,3 @@
2
2
  *= require_tree .
3
3
  *= require_self
4
4
  */
5
- @import "./actiontext.scss";
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.37
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-18 00:00:00.000000000 Z
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