cm-admin 2.3.2 → 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1090a3a388d95d97dd96bd211bcb03731e42fa5ebee07b0a6f276e5b9160d952
4
- data.tar.gz: 8a4417d459df6f2380890a9a89bf538fc7803c5d2ed5ff1c07858966c097e66a
3
+ metadata.gz: 2f85a062f8d926712d7817aeb392c0233208690eacbefeccdbcadb90ac6e85cf
4
+ data.tar.gz: eb59e86b5c40e9e592d8c1c488cbb5bf9ab2d7de5e66fbad97c0abb401449688
5
5
  SHA512:
6
- metadata.gz: d123a4ceacfe88f2d4e734fe5ed216333936dc5796da00f3f7c5e3cd2b57d5e83a941fef80266c3d318bafaa31ccba35182f8c6c49c2bfdfb5e9308c03aa40f4
7
- data.tar.gz: 2ee1bb8c761def45e410be1a064a48d298068618b041daa20da1a9eb3c56f4d628587ac6a0241fc4e8e1635327a0d6b6b60928b1c79f15d06d927e20ca9fbac5
6
+ metadata.gz: e4bf5998df379c42994928003eac0f18770c1650983520aae1fd2940f062d239f567066ea16469b1c7fa5135d9d77a0307be7df13c2a34342625b02da0ed2445
7
+ data.tar.gz: 0a7d326057c1a49aff2ef3db674ab7e21f1634634f1b527d4cb85bc535c49c0ef441b102bcb16b6d8077f33f5866d333b49c9ab6d096c9833bd7da019c43e961
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-admin (2.3.2)
4
+ cm-admin (2.3.3)
5
5
  caxlsx_rails
6
6
  cocoon (~> 1.2.15)
7
7
  csv-importer (~> 0.8.2)
@@ -40,6 +40,19 @@ document.addEventListener("turbo:load", function () {
40
40
  });
41
41
  jqueryJgrowl();
42
42
  setup_select_2_ajax();
43
+ var el = $("[data-section='nested-form-body']")
44
+ if(el[0]) {
45
+ Sortable.create(el[0],{
46
+ handle: '.drag-handle',
47
+ animation: 150,
48
+ onUpdate: function (evt) {
49
+ var itemEl = evt.item
50
+ $("[data-section='nested-form-body'] tr").each(function(index, el){
51
+ $(el).find('.hidden-position').val(index+1)
52
+ })
53
+ }
54
+ });
55
+ }
43
56
  });
44
57
 
45
58
  $(document).on(
@@ -1,7 +1,11 @@
1
1
  - if nested_table_field.display_type == :table
2
2
  tr.nested-fields
3
- td.item-delete-cell
4
- - if nested_table_field.is_deletable.call(f.object)
3
+ - if nested_table_field.is_positionable.call(f.object)
4
+ td
5
+ i class='fa-solid fa-arrows-up-down-left-right drag-handle'
6
+ = f.hidden_field :position, class: 'hidden-position'
7
+ - if nested_table_field.is_deletable.call(f.object)
8
+ td.item-delete-cell
5
9
  = link_to_remove_association "", f, class: 'fa-regular fa-trash-can btn-ghost'
6
10
  - nested_table_field.fields.each do |field|
7
11
  td data-field-type="#{field.input_type}"
@@ -8,13 +8,17 @@
8
8
  table.nested-form-table
9
9
  thead
10
10
  tr
11
- th
12
- |
13
- - nested_table_field.fields.each do |field|
11
+ - if nested_table_field.is_positionable.call(f.object)
12
+ th
13
+ |
14
+ - if nested_table_field.is_deletable.call(f.object)
15
+ th
16
+ |
17
+ - nested_table_field.fields.each do |field|
14
18
  th data-field-type="#{field.input_type}"
15
19
  - if field.label
16
20
  = field.label.to_s || field.field_name.to_s.titleize
17
- tbody class="insert-cocoon-position-#{uniq_no}"
21
+ tbody class="insert-cocoon-position-#{uniq_no}" data-section='nested-form-body'
18
22
  = f.fields_for table_name do |record|
19
23
  - if record.object.persisted? || @ar_object.errors.present?
20
24
  = render partial: '/cm_admin/main/nested_fields', locals: { f: record, assoc_name: assoc_name, nested_table_field: nested_table_field }
@@ -6,7 +6,8 @@ module CmAdmin
6
6
  include Utils::Helpers
7
7
 
8
8
  attr_accessor :field_name, :label, :header, :input_type, :collection, :disabled, :helper_method,
9
- :placeholder, :display_if, :html_attrs, :target, :col_size, :ajax_url, :helper_text
9
+ :placeholder, :display_if, :html_attrs, :target, :col_size, :ajax_url, :helper_text,
10
+ :image_preview
10
11
 
11
12
  VALID_INPUT_TYPES = %i[
12
13
  integer decimal string single_select multi_select date date_time text switch custom_single_select checkbox_group
@@ -32,6 +33,7 @@ module CmAdmin
32
33
  self.html_attrs = {}
33
34
  self.target = {}
34
35
  self.col_size = nil
36
+ self.image_preview = false
35
37
  end
36
38
 
37
39
  def set_default_placeholder
@@ -4,7 +4,8 @@ module CmAdmin
4
4
 
5
5
  # NestedField is like a container to hold Field and FormField object
6
6
 
7
- attr_accessor :field_name, :display_type, :fields, :associated_fields, :parent_field, :header, :label, :submit_text, :is_deletable, :is_creatable
7
+ attr_accessor :field_name, :display_type, :fields, :associated_fields, :parent_field,
8
+ :header, :label, :submit_text, :is_deletable, :is_creatable, :is_positionable
8
9
 
9
10
  def initialize(field_name, attributes={})
10
11
  @field_name = field_name
@@ -21,6 +22,7 @@ module CmAdmin
21
22
  self.submit_text = "+ Add #{@field_name.to_s.titleize}"
22
23
  self.is_deletable = lambda { |arg| return true }
23
24
  self.is_creatable = lambda { |arg| return true }
25
+ self.is_positionable = lambda { |arg| return false }
24
26
  end
25
27
 
26
28
  end
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = '2.3.2'
2
+ VERSION = '2.3.3'
3
3
  end
@@ -222,20 +222,25 @@ module CmAdmin
222
222
  content_tag(:div) do
223
223
  if attached.class == ActiveStorage::Attached::Many
224
224
  attached.each do |attachment|
225
- concat attachment_with_icon(attachment, attachment_name:)
225
+ concat attachment_with_icon(cm_field, attachment, attachment_name:)
226
226
  end
227
227
  elsif attached.attached?
228
- concat attachment_with_icon(attached, attachment_name:)
228
+ concat attachment_with_icon(cm_field, attached, attachment_name:)
229
229
  end
230
230
  end
231
231
  end
232
232
 
233
- def attachment_with_icon(attachment, attachment_name:)
233
+ def attachment_with_icon(cm_field, attachment, attachment_name:)
234
234
  content_tag(:div, class: 'destroy-attachment', data: { ar_id: attachment.id, attachment_name: }) do
235
235
  concat(content_tag(:button, '', class: 'btn-ghost') do
236
236
  concat tag.i(class: 'fa-regular fa-trash-can')
237
237
  end)
238
238
  concat content_tag(:span, attachment.filename.to_s, class: 'btn-link')
239
+ concat(content_tag(:a, href: attachment.url, target: '_blank') do
240
+ if attachment.content_type.include?('image')
241
+ image_tag(attachment.url, height: 50, width: 50, class: "rounded")
242
+ end
243
+ end) if cm_field.image_preview
239
244
  end
240
245
  end
241
246
 
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: 2.3.2
4
+ version: 2.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael