cm-admin 2.4.3 → 2.4.4

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: 1811b7dc704a66a4f26ec20ee3ff1a72c1cd369d19cc968d60fcfb135eab8ded
4
- data.tar.gz: d2b62571d0a3f3205615a604bcfdaa046590621478be3aebd37be2025dac130b
3
+ metadata.gz: d0637794147d28cbeb2b09c9162104aabb3c5b7f52e3fb9e42c6a291e89b8e5e
4
+ data.tar.gz: 7971b87140570d9a486c65522fa762a960b5d5bc1e2cb392abcb36beec867003
5
5
  SHA512:
6
- metadata.gz: ee0549268bffe487c3eeabea14b127ea036b71ffbf18fbcdca944832c42558fb121f11cb4b4e7f5eb1baa9153614e588e92c21b295efce2511c06c7cfcd414a8
7
- data.tar.gz: da4a8ab490c02decefe6597d8937da700762e91171af8859ee246e8cf769dab48356c292c750e26f111891496cf4100b865dd728cb750f7e979d0d90c10e9676
6
+ metadata.gz: 5e61028998a91e7279541570fd4e881cdc9263f3bd89f03db97e0b057c6667e32f69481164cf294bd6c517a55ec34de5c744b50e98340192c56861325eb9a7bb
7
+ data.tar.gz: 2cacfa59737f253733fe9b362464515f944e876e4e67b5e21f0895bd5691c6888c7a9d4013432d80b0ad24b04b4e9f52712786e445826ab539aef4d490a6a1cc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-admin (2.4.3)
4
+ cm-admin (2.4.4)
5
5
  caxlsx_rails
6
6
  cocoon (~> 1.2.15)
7
7
  csv-importer (~> 0.8.2)
@@ -23,14 +23,16 @@ function setBulkActionParams() {
23
23
  $('[data-behaviour="bulk-action-checkbox"]:checked').each(function(){ selected_ids.push($(this).data('ar-object-id')) })
24
24
  var bulk_action_form = '[data-section="bulk-action"] form'
25
25
  if ($(bulk_action_form)) {
26
- if ($(bulk_action_form + ' [name="selected_ids"]').length == 0) {
27
- $('<input>').attr({
28
- type: 'hidden',
29
- name: 'selected_ids'
30
- }).appendTo(bulk_action_form);
31
- }
26
+ $(bulk_action_form).each(function( i ) {
27
+ if ($(this).find('[name="selected_ids"]').length == 0) {
28
+ $('<input>').attr({
29
+ type: 'hidden',
30
+ name: 'selected_ids'
31
+ }).appendTo(this);
32
+ }
33
+ })
32
34
  }
33
35
  $('[data-section="bulk-action"] [name="selected_ids"]').each(function( i ) {
34
36
  $(this).val(selected_ids)
35
37
  })
36
- }
38
+ }
@@ -118,3 +118,37 @@
118
118
  .discard-form {
119
119
  margin-left: 16px;
120
120
  }
121
+
122
+ // Bulk Actions Dropdown
123
+ .bulk-action-item {
124
+
125
+ form {
126
+ width: 100%;
127
+ }
128
+
129
+ .bulk-action-icon {
130
+ width: 20px;
131
+ height: 20px;
132
+
133
+ svg {
134
+ width: 100%;
135
+ height: 100%;
136
+ object-fit: contain;
137
+ }
138
+ }
139
+
140
+ .bulk-action-button {
141
+ @extend .d-flex, .align-items-center, .gap-2;
142
+
143
+ &:hover {
144
+ color: inherit;
145
+ text-decoration: none;
146
+ }
147
+ }
148
+
149
+ a {
150
+ display: flex;
151
+ gap: 8px;
152
+ }
153
+ }
154
+
@@ -20,8 +20,7 @@
20
20
  - bulk_actions = actions_filter(@model, @ar_object, :bulk_action)
21
21
  - if bulk_actions.present?
22
22
  .table-top.hidden data-section="bulk-action"
23
- - bulk_actions.each do |action|
24
- = custom_action_items(action, 'index')
23
+ = bulk_action_items(bulk_actions, 'index')
25
24
  .table-wrapper
26
25
  table.index-table data-bulk-actions=(bulk_actions.present? && "present")
27
26
  thead
@@ -7,11 +7,7 @@ module CmAdmin
7
7
 
8
8
  def initialize(attributes = {}, &block)
9
9
  super
10
- override_default_values
11
- end
12
-
13
- def override_default_values
14
- self.icon_name = 'fa fa-layer-group'
10
+ self.icon_name ||= 'fa fa-layer-group'
15
11
  self.verb = :post
16
12
  end
17
13
  end
@@ -282,7 +282,7 @@ module CmAdmin
282
282
  # @param redirection_url [String] the redirection url of action
283
283
  # @param icon_name [String] the icon name of action, follow font-awesome icon name
284
284
  # @param verb [String] the verb of action, +get+, +post+, +put+, +patch+ or +delete+
285
- # @param display_type [Symbol] the display type of action, +:page+, +:modal+
285
+ # @param display_type [Symbol] the display type of action, +:page+, +:modal+, +:button+, +:icon_only+[deprecated]
286
286
  # @param modal_configuration [Hash] the configuration of modal
287
287
  # @param route_type [String] the route type of action, +member+, +collection+
288
288
  # @param partial [String] the partial path of action
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = '2.4.3'
2
+ VERSION = '2.4.4'
3
3
  end
@@ -86,6 +86,76 @@ module CmAdmin
86
86
  end
87
87
  end
88
88
 
89
+ def bulk_action_items(bulk_items, current_action_name)
90
+ content_tag :div, class: 'dropdown' do
91
+ concat(link_to('Bulk Actions', '#', class: 'dropdown-toggle', role: 'button', id: 'dropdownMenuLink', data: { bs_toggle: 'dropdown' }, aria: { expanded: false }))
92
+
93
+ concat(
94
+ content_tag(:ul, class: 'dropdown-menu', aria: { labelledby: 'dropdownMenuLink' }) do
95
+ bulk_action_dropdown_items(bulk_items, current_action_name)
96
+ end
97
+ )
98
+ end
99
+ end
100
+
101
+ def bulk_action_dropdown_items(bulk_items, current_action_name)
102
+ bulk_items.each do |bulk_action|
103
+ next unless bulk_action.name.present? && policy([:cm_admin, @model.name.classify.constantize]).send(:"#{bulk_action.name}?")
104
+
105
+ scoped_model = bulk_action.name.present? && policy([:cm_admin, @model.name.classify.constantize]).send(:"#{bulk_action.name}?")
106
+
107
+ has_scoped_record = if current_action_name == 'index'
108
+ scoped_model.present?
109
+ else
110
+ scoped_model.find_by(id: ar_object.id).present?
111
+ end
112
+
113
+ next unless bulk_action.display_if.call(@ar_object) && has_scoped_record
114
+
115
+ case bulk_action.display_type
116
+ when :button
117
+ bulk_action_button(bulk_action)
118
+ when :modal
119
+ bulk_action_modal(bulk_action)
120
+ when :page
121
+ bulk_action_page(bulk_action)
122
+ end
123
+ end
124
+ end
125
+
126
+ def bulk_action_button(bulk_action)
127
+ concat(content_tag(:li, class: 'bulk-action-item', data: { action: bulk_action.name }) do
128
+ button_to cm_admin.send("#{@model.name.underscore}_#{bulk_action.name}_path"), method: :post, params: { selected_ids: '' }, class: 'bulk-action-button dropdown-item' do
129
+ concat(content_tag(:div, class: 'bulk-action-icon') do
130
+ concat(content_tag(:i, '', class: bulk_action.icon_name))
131
+ end)
132
+ concat(content_tag(:span, custom_action_title(bulk_action)))
133
+ end
134
+ end)
135
+ end
136
+
137
+ def bulk_action_modal(bulk_action)
138
+ concat(content_tag(:li, class: 'bulk-action-item', data: { action: bulk_action.name }) do
139
+ link_to '#', data: { bs_toggle: 'modal', bs_target: "##{bulk_action.name.classify}Modal-#{@ar_object.id}" }, class: 'dropdown-item' do
140
+ concat(content_tag(:div, class: 'bulk-action-icon') do
141
+ concat(content_tag(:i, '', class: bulk_action.icon_name))
142
+ end)
143
+ concat(content_tag(:span, bulk_action.display_name))
144
+ end
145
+ end)
146
+ end
147
+
148
+ def bulk_action_page(bulk_action)
149
+ concat(content_tag(:li, class: 'bulk-action-item', data: { action: bulk_action.name }) do
150
+ link_to cm_admin.send("#{@model.name.underscore}_#{bulk_action.name}_path", @ar_object, bulk_action.url_params), class: 'dropdown-item' do
151
+ concat(content_tag(:div, class: 'bulk-action-icon') do
152
+ concat(content_tag(:i, '', class: bulk_action.icon_name))
153
+ end)
154
+ concat(content_tag(:span, bulk_action.display_name))
155
+ end
156
+ end)
157
+ end
158
+
89
159
  def custom_action_title(custom_action)
90
160
  custom_action.display_name.to_s.presence || custom_action.name.to_s.titleize
91
161
  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: 2.4.3
4
+ version: 2.4.4
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-10-17 00:00:00.000000000 Z
17
+ date: 2024-10-18 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: caxlsx_rails