cm-admin 1.3.2 → 1.3.4
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/Gemfile.lock +1 -1
- data/app/assets/javascripts/cm_admin/form_validation.js +4 -5
- data/app/views/cm_admin/main/_associated_table.html.slim +1 -1
- data/app/views/cm_admin/main/new.html.slim +1 -1
- data/lib/cm_admin/models/form_field.rb +2 -2
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/form_field_helper.rb +50 -13
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 8d8b59bb29b63e28e9f7477b9dd9dda0b2fead59924bf27bae4a6a524310a99f
         | 
| 4 | 
            +
              data.tar.gz: 31ad3672cf1f5811e0db81ea7937728b07c4cec6471e3bebb027559c78d08266
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: b0952b765aef635678377f3a6bdb7bdd973aa4bd9cd57be2a52522240fce40dac39f55138b04c0f25c220fc9a1f1848704184456cedc3e76742f7aad1b436c7f
         | 
| 7 | 
            +
              data.tar.gz: f37b2418e744562c062ac520ef51b3deda72718c41d4459598fe89ea9b59a1dfaa76971b04f2cd4a41395e04ba6e3017bba7e4cedc8a22e3c25bb499d90e2f92
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
| @@ -1,20 +1,19 @@ | |
| 1 1 | 
             
            $(document).on('click', '.form_submit', function(e) {
         | 
| 2 | 
            -
              console.log('Came here')
         | 
| 3 2 | 
             
              e.preventDefault();
         | 
| 4 3 | 
             
              var submit = [];
         | 
| 5 4 | 
             
              var form_class = $(this).data('form-class');
         | 
| 6 5 | 
             
              $("." + form_class + " input.required, ." + form_class + " textarea.required").each(function() {
         | 
| 7 | 
            -
                $(this).removeClass(' | 
| 6 | 
            +
                $(this).removeClass('is-invalid');
         | 
| 8 7 | 
             
                if ($(this).val().trim().length === 0) {
         | 
| 9 | 
            -
                  $(this).addClass(' | 
| 8 | 
            +
                  $(this).addClass('is-invalid');
         | 
| 10 9 | 
             
                  $(this)[0].scrollIntoView(true);
         | 
| 11 10 | 
             
                  submit.push(true);
         | 
| 12 11 | 
             
                }
         | 
| 13 12 | 
             
              });
         | 
| 14 13 | 
             
              $("." + form_class + " select.required").each(function() {
         | 
| 15 | 
            -
                $(this).removeClass(' | 
| 14 | 
            +
                $(this).removeClass('is-invalid');
         | 
| 16 15 | 
             
                if ($(this).val().trim().length === 0) {
         | 
| 17 | 
            -
                  $(this).parent().find('.select2').addClass(' | 
| 16 | 
            +
                  $(this).parent().find('.select2').addClass('is-invalid');
         | 
| 18 17 | 
             
                  $(this)[0].scrollIntoView(true);
         | 
| 19 18 | 
             
                  submit.push(true);
         | 
| 20 19 | 
             
                }
         | 
| @@ -60,4 +60,4 @@ | |
| 60 60 | 
             
              .pagination-bar
         | 
| 61 61 | 
             
                p.count-text.m-0 Showing #{@associated_ar_object.pagy.from} to #{@associated_ar_object.pagy.to} out of #{@associated_ar_object.pagy.count}
         | 
| 62 62 | 
             
                == render partial: 'cm_admin/main/cm_pagy_nav', locals: { pagy: @associated_ar_object.pagy }
         | 
| 63 | 
            -
            = render partial: 'cm_admin/main/member_custom_action_modal', locals: { cm_model: @associated_model, ar_collection: @associated_ar_object }
         | 
| 63 | 
            +
            / = render partial: 'cm_admin/main/member_custom_action_modal', locals: { cm_model: @associated_model, ar_collection: @associated_ar_object }
         | 
| @@ -10,7 +10,7 @@ module CmAdmin | |
| 10 10 |  | 
| 11 11 | 
             
                  VALID_INPUT_TYPES = %i[
         | 
| 12 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
         | 
| 13 | 
            +
                    single_file_upload multi_file_upload hidden rich_text check_box radio_button custom_string custom_date custom_single_select
         | 
| 14 14 | 
             
                  ].freeze
         | 
| 15 15 |  | 
| 16 16 | 
             
                  def initialize(field_name, input_type, attributes = {})
         | 
| @@ -25,7 +25,7 @@ module CmAdmin | |
| 25 25 | 
             
                  end
         | 
| 26 26 |  | 
| 27 27 | 
             
                  def set_default_values
         | 
| 28 | 
            -
                    self.disabled = false
         | 
| 28 | 
            +
                    self.disabled = lambda { |arg| return false } if display_if.nil?
         | 
| 29 29 | 
             
                    self.label = self.field_name.to_s.titleize
         | 
| 30 30 | 
             
                    self.input_type = :string
         | 
| 31 31 | 
             
                    self.html_attr = {}
         | 
    
        data/lib/cm_admin/version.rb
    CHANGED
    
    
| @@ -3,8 +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 | 
            -
             | 
| 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
         | 
| 13 | 
            +
                    # 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)
         | 
| 8 14 | 
             
                    is_required = form_obj.object._validators[cm_field.field_name].map(&:kind).include?(:presence)
         | 
| 9 15 | 
             
                    required_class = is_required ? 'required' : ''
         | 
| 10 16 | 
             
                    target_action = @model.available_actions.select { |x| x.name == cm_field.target[:action_name].to_s }.first if cm_field.target.present?
         | 
| @@ -14,7 +20,7 @@ module CmAdmin | |
| 14 20 | 
             
                  def cm_integer_field(form_obj, cm_field, value, required_class, _target_action)
         | 
| 15 21 | 
             
                    form_obj.text_field cm_field.field_name,
         | 
| 16 22 | 
             
                                        class: "field-control #{required_class}",
         | 
| 17 | 
            -
                                        disabled: cm_field.disabled,
         | 
| 23 | 
            +
                                        disabled: cm_field.disabled.call(form_obj.object),
         | 
| 18 24 | 
             
                                        value: value,
         | 
| 19 25 | 
             
                                        placeholder: cm_field.placeholder,
         | 
| 20 26 | 
             
                                        data: { behaviour: 'integer-only' }
         | 
| @@ -23,7 +29,7 @@ module CmAdmin | |
| 23 29 | 
             
                  def cm_decimal_field(form_obj, cm_field, value, required_class, _target_action)
         | 
| 24 30 | 
             
                    form_obj.number_field cm_field.field_name,
         | 
| 25 31 | 
             
                                          class: "field-control #{required_class}",
         | 
| 26 | 
            -
                                          disabled: cm_field.disabled,
         | 
| 32 | 
            +
                                          disabled: cm_field.disabled.call(form_obj.object),
         | 
| 27 33 | 
             
                                          value: value,
         | 
| 28 34 | 
             
                                          placeholder: cm_field.placeholder,
         | 
| 29 35 | 
             
                                          data: { behaviour: 'decimal-only' }
         | 
| @@ -32,16 +38,23 @@ module CmAdmin | |
| 32 38 | 
             
                  def cm_string_field(form_obj, cm_field, value, required_class, _target_action)
         | 
| 33 39 | 
             
                    form_obj.text_field cm_field.field_name,
         | 
| 34 40 | 
             
                                        class: "field-control #{required_class}",
         | 
| 35 | 
            -
                                        disabled: cm_field.disabled,
         | 
| 41 | 
            +
                                        disabled: cm_field.disabled.call(form_obj.object),
         | 
| 36 42 | 
             
                                        value: value,
         | 
| 37 43 | 
             
                                        placeholder: cm_field.placeholder
         | 
| 38 44 | 
             
                  end
         | 
| 39 45 |  | 
| 46 | 
            +
                  def cm_custom_string_field(form_obj, cm_field, value, required_class, _target_action)
         | 
| 47 | 
            +
                    text_field_tag cm_field.html_attr[:name] || cm_field.field_name,
         | 
| 48 | 
            +
                                    value, class: "field-control #{required_class}",
         | 
| 49 | 
            +
                                    disabled: cm_field.disabled.call(form_obj.object),
         | 
| 50 | 
            +
                                    placeholder: cm_field.placeholder
         | 
| 51 | 
            +
                  end
         | 
| 52 | 
            +
             | 
| 40 53 | 
             
                  def cm_single_select_field(form_obj, cm_field, value, required_class, target_action)
         | 
| 41 54 | 
             
                    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)),
         | 
| 42 55 | 
             
                                    { include_blank: cm_field.placeholder },
         | 
| 43 56 | 
             
                                    class: "field-control #{required_class} select-2",
         | 
| 44 | 
            -
                                    disabled: cm_field.disabled,
         | 
| 57 | 
            +
                                    disabled: cm_field.disabled.call(form_obj.object),
         | 
| 45 58 | 
             
                                    data: {
         | 
| 46 59 | 
             
                                      field_name: cm_field.field_name,
         | 
| 47 60 | 
             
                                      field_type: 'linked-field',
         | 
| @@ -50,18 +63,42 @@ module CmAdmin | |
| 50 63 | 
             
                                    }
         | 
| 51 64 | 
             
                  end
         | 
| 52 65 |  | 
| 66 | 
            +
                  def cm_custom_single_select_field(form_obj, cm_field, value, required_class, target_action)
         | 
| 67 | 
            +
                    select_tag cm_field.html_attr[:name] || cm_field.field_name,
         | 
| 68 | 
            +
                                options_for_select(select_collection_value(form_obj.object, cm_field)),
         | 
| 69 | 
            +
                                {
         | 
| 70 | 
            +
                                  include_blank: cm_field.placeholder,
         | 
| 71 | 
            +
                                  class: "field-control #{required_class} select-2",
         | 
| 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 | 
            +
                                  }
         | 
| 79 | 
            +
                                }
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
             | 
| 53 82 | 
             
                  def cm_multi_select_field(form_obj, cm_field, value, required_class, target_action)
         | 
| 54 83 | 
             
                    form_obj.select cm_field.field_name,
         | 
| 55 84 | 
             
                                    options_for_select(select_collection_value(form_obj.object, cm_field), form_obj.object.send(cm_field.field_name)),
         | 
| 56 85 | 
             
                                    { include_blank: cm_field.placeholder },
         | 
| 57 86 | 
             
                                    class: "field-control #{required_class} select-2",
         | 
| 58 | 
            -
                                    disabled: cm_field.disabled, multiple: true
         | 
| 87 | 
            +
                                    disabled: cm_field.disabled.call(form_obj.object), multiple: true
         | 
| 59 88 | 
             
                  end
         | 
| 60 89 |  | 
| 61 90 | 
             
                  def cm_date_field(form_obj, cm_field, value, required_class, _target_action)
         | 
| 62 91 | 
             
                    form_obj.text_field cm_field.field_name,
         | 
| 63 92 | 
             
                                        class: "field-control #{required_class}",
         | 
| 64 | 
            -
                                        disabled: cm_field.disabled,
         | 
| 93 | 
            +
                                        disabled: cm_field.disabled.call(form_obj.object),
         | 
| 94 | 
            +
                                        placeholder: cm_field.placeholder,
         | 
| 95 | 
            +
                                        data: { behaviour: 'date-only' }
         | 
| 96 | 
            +
                  end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                  def cm_custom_date_field(form_obj, cm_field, value, required_class, _target_action)
         | 
| 99 | 
            +
                    text_field_tag cm_field.html_attr[:name] || cm_field.field_name, value&.strftime('%d-%m-%Y'),
         | 
| 100 | 
            +
                                        class: "field-control #{required_class}",
         | 
| 101 | 
            +
                                        disabled: cm_field.disabled.call(form_obj.object),
         | 
| 65 102 | 
             
                                        value: value&.strftime('%d-%m-%Y'),
         | 
| 66 103 | 
             
                                        placeholder: cm_field.placeholder,
         | 
| 67 104 | 
             
                                        data: { behaviour: 'date-only' }
         | 
| @@ -70,7 +107,7 @@ module CmAdmin | |
| 70 107 | 
             
                  def cm_date_time_field(form_obj, cm_field, value, required_class, _target_action)
         | 
| 71 108 | 
             
                    form_obj.text_field cm_field.field_name,
         | 
| 72 109 | 
             
                                        class: "field-control #{required_class}",
         | 
| 73 | 
            -
                                        disabled: cm_field.disabled,
         | 
| 110 | 
            +
                                        disabled: cm_field.disabled.call(form_obj.object),
         | 
| 74 111 | 
             
                                        value: value,
         | 
| 75 112 | 
             
                                        placeholder: cm_field.placeholder,
         | 
| 76 113 | 
             
                                        data: { behaviour: 'date-time' }
         | 
| @@ -90,14 +127,14 @@ module CmAdmin | |
| 90 127 |  | 
| 91 128 | 
             
                  def cm_single_file_upload_field(form_obj, cm_field, _value, required_class, _target_action)
         | 
| 92 129 | 
             
                    content_tag(:div) do
         | 
| 93 | 
            -
                      concat form_obj.file_field cm_field.field_name, class: " | 
| 130 | 
            +
                      concat form_obj.file_field cm_field.field_name, class: "field-control #{required_class}", disabled: cm_field.disabled.call(form_obj.object)
         | 
| 94 131 | 
             
                      concat attachment_list(form_obj, cm_field, _value, required_class, _target_action)
         | 
| 95 132 | 
             
                    end
         | 
| 96 133 | 
             
                  end
         | 
| 97 134 |  | 
| 98 135 | 
             
                  def cm_multi_file_upload_field(form_obj, cm_field, _value, required_class, _target_action)
         | 
| 99 136 | 
             
                    content_tag(:div) do
         | 
| 100 | 
            -
                      concat form_obj.file_field cm_field.field_name, multiple: true, class: " | 
| 137 | 
            +
                      concat form_obj.file_field cm_field.field_name, multiple: true, class: "field-control #{required_class}", disabled: cm_field.disabled.call(form_obj.object)
         | 
| 101 138 | 
             
                      concat attachment_list(form_obj, cm_field, _value, required_class, _target_action)
         | 
| 102 139 | 
             
                    end
         | 
| 103 140 | 
             
                  end
         | 
| @@ -159,7 +196,7 @@ module CmAdmin | |
| 159 196 | 
             
                      form_obj.check_box cm_field.field_name,
         | 
| 160 197 | 
             
                                         {
         | 
| 161 198 | 
             
                                           class: "field-control cm-checkbox #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
         | 
| 162 | 
            -
                                           disabled: cm_field.disabled,
         | 
| 199 | 
            +
                                           disabled: cm_field.disabled.call(form_obj.object),
         | 
| 163 200 | 
             
                                           data: {
         | 
| 164 201 | 
             
                                             field_name: cm_field.field_name,
         | 
| 165 202 | 
             
                                             target_action: target_action&.name,
         | 
| @@ -189,7 +226,7 @@ module CmAdmin | |
| 189 226 | 
             
                      concat form_obj.check_box cm_field.field_name,
         | 
| 190 227 | 
             
                                                {
         | 
| 191 228 | 
             
                                                  class: "field-control cm-checkbox #{required_class} #{target_action.present? ? 'linked-field-request' : ''}",
         | 
| 192 | 
            -
                                                  disabled: cm_field.disabled,
         | 
| 229 | 
            +
                                                  disabled: cm_field.disabled.call(form_obj.object),
         | 
| 193 230 | 
             
                                                  name: "#{@model.name.underscore}[#{cm_field.field_name}][]",
         | 
| 194 231 | 
             
                                                  data: {
         | 
| 195 232 | 
             
                                                    target_action: target_action&.name,
         | 
    
        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.3. | 
| 4 | 
            +
              version: 1.3.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - sajinmp
         | 
| @@ -10,7 +10,7 @@ authors: | |
| 10 10 | 
             
            autorequire:
         | 
| 11 11 | 
             
            bindir: exe
         | 
| 12 12 | 
             
            cert_chain: []
         | 
| 13 | 
            -
            date: 2023-11- | 
| 13 | 
            +
            date: 2023-11-08 00:00:00.000000000 Z
         | 
| 14 14 | 
             
            dependencies:
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 16 16 | 
             
              name: rails
         |