cm-admin 3.0.7 → 3.0.9
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/scaffolds.js +56 -3
- data/app/assets/stylesheets/cm_admin/base/form.scss +15 -1
- data/app/assets/stylesheets/cm_admin/base/table.scss +13 -10
- data/app/views/cm_admin/main/_nested_fields.html.slim +3 -3
- data/app/views/cm_admin/main/_nested_table_form.html.slim +11 -7
- data/app/views/cm_admin/roles/permissions.html.slim +35 -34
- data/lib/cm_admin/version.rb +1 -1
- data/lib/cm_admin/view_helpers/form_field_helper.rb +12 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7470565c394ee297e76878ead64578e8fcb5cc7458b69516fc397f2577374d76
|
4
|
+
data.tar.gz: bf8f4e1694b6e8b4f5095f05eb9df1919a1fb4ce49d588d1fe576346cc76dd46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e3de3b4dd2892626348a9feab18726c4cc370cca3d9a98625cb7e0a228f21b760413adb5f0e55607cfb4c02fb11625833f0dbd601e134d3dd14eb7aae733945
|
7
|
+
data.tar.gz: 9624eb827a4a5459f4f254e8f57f771afe8f9f6109493e136def8d1e9a0012aa76676fab59fbcd0851b8fcc6c9c9ef073c6a909e5b36bd393de269ec63b3ec82
|
data/Gemfile.lock
CHANGED
@@ -79,15 +79,68 @@ $(document).on("click", function (e) {
|
|
79
79
|
}
|
80
80
|
});
|
81
81
|
|
82
|
-
$(document).on("click", "
|
82
|
+
$(document).on("click", '[data-section="destroy-attachment"] button', function (e) {
|
83
83
|
e.preventDefault();
|
84
|
-
var ar_id = $(this).parent("
|
85
|
-
$(this).parent("
|
84
|
+
var ar_id = $(this).parent('[data-section="destroy-attachment"]').data("ar-id");
|
85
|
+
$(this).parent('[data-section="destroy-attachment"]').addClass("hidden");
|
86
|
+
$(this).closest('[data-field-type="single_file_upload"]').find('input').removeClass('hidden')
|
86
87
|
$(this).append(
|
87
88
|
'<input type="text" name="attachment_destroy_ids[]" value="' + ar_id + '"/>'
|
88
89
|
);
|
89
90
|
});
|
90
91
|
|
92
|
+
$(document).on('change', '[data-field-type="single_file_upload"] input', function(e) {
|
93
|
+
console.log("File changed")
|
94
|
+
const [file] = $(this)[0].files
|
95
|
+
if (file) {
|
96
|
+
// blah.src = URL.createObjectURL(file)
|
97
|
+
const upload_div = $(this).closest('[data-field-type="single_file_upload"]')
|
98
|
+
$(upload_div).find('input').addClass('hidden')
|
99
|
+
$(upload_div).find('[data-section="destroy-attachment"]').removeClass("hidden")
|
100
|
+
$(upload_div).find('[data-section="image-preview"]').html(`<div data-section="destroy-attachment" data-attachment-name="listing[media_items_attributes][0]_attachment_attachments">\
|
101
|
+
<span class="btn-link">${file.name}</span>\
|
102
|
+
<button class="btn-ghost">\
|
103
|
+
<i class="fa-regular fa-trash-can"></i>\
|
104
|
+
</button>\
|
105
|
+
</div>`
|
106
|
+
)
|
107
|
+
var allowExtention = ".jpg,.bmp,.gif,.png";
|
108
|
+
var extention = file.name.substring(file.name.lastIndexOf(".") + 1).toLowerCase();
|
109
|
+
|
110
|
+
if (allowExtention.indexOf(extention) > -1) {
|
111
|
+
var img = $('<img height="50" width="50" class="rounded"/>');
|
112
|
+
img.attr("src", URL.createObjectURL(file));
|
113
|
+
$(upload_div).find('[data-section="image-preview"]').find('[data-section="destroy-attachment"]').prepend(img);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
})
|
117
|
+
|
118
|
+
$(document).on('change', '[data-field-type="multi_file_upload"] input', function(e) {
|
119
|
+
console.log("File changed")
|
120
|
+
const files = $(this)[0].files
|
121
|
+
const element_id = $(this).attr('id')
|
122
|
+
const upload_div = $(this).closest('[data-field-type="multi_file_upload"]')
|
123
|
+
$(upload_div).find('[data-section="image-preview"]').html('')
|
124
|
+
if (files) {
|
125
|
+
$.each(files, function(index, file) {
|
126
|
+
$(upload_div).find('[data-section="destroy-attachment"]').removeClass("hidden");
|
127
|
+
$(upload_div).find('[data-section="image-preview"]').append(`<div data-section="destroy-attachment" data-index="${index}" data-attachment-name="${element_id}_attachments">\
|
128
|
+
<span class="btn-link">${file.name}</span>\
|
129
|
+
</div>`
|
130
|
+
)
|
131
|
+
var allowExtention = ".jpg,.bmp,.gif,.png";
|
132
|
+
var extention = file.name.substring(file.name.lastIndexOf(".") + 1).toLowerCase();
|
133
|
+
|
134
|
+
if (allowExtention.indexOf(extention) > -1) {
|
135
|
+
var img = $('<img height="50" width="50" class="rounded"/>');
|
136
|
+
img.attr("src", URL.createObjectURL(file));
|
137
|
+
$(upload_div).find('[data-section="image-preview"]').find(`[data-index="${index}"]`).prepend(img);
|
138
|
+
}
|
139
|
+
})
|
140
|
+
|
141
|
+
}
|
142
|
+
})
|
143
|
+
|
91
144
|
$(document).on(
|
92
145
|
"click",
|
93
146
|
'[data-behaviour="permission-check-box"]',
|
@@ -61,9 +61,23 @@
|
|
61
61
|
}
|
62
62
|
|
63
63
|
//upload attachment style
|
64
|
-
|
64
|
+
[data-section="destroy-attachment"] {
|
65
65
|
margin-top: 4px;
|
66
66
|
}
|
67
|
+
[data-section="image-preview"] {
|
68
|
+
[data-section="destroy-attachment"] {
|
69
|
+
background-color: $grey-lightest-clr;
|
70
|
+
mix-blend-mode: multiply;
|
71
|
+
padding: 8px;
|
72
|
+
margin-bottom: 5px;
|
73
|
+
.btn-ghost {
|
74
|
+
float: right;
|
75
|
+
margin-top: 12px;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
|
67
81
|
|
68
82
|
//Form card UI
|
69
83
|
.form-card {
|
@@ -290,19 +290,22 @@
|
|
290
290
|
.nested-form-table {
|
291
291
|
@extend .table, .table-light, .table-hover, .table-bordered, .m-0;
|
292
292
|
width: max-content;
|
293
|
-
.item-delete-cell {
|
294
|
-
vertical-align: middle;
|
295
|
-
text-align: center;
|
296
|
-
}
|
297
293
|
}
|
298
|
-
|
299
|
-
min-width:
|
300
|
-
max-width:
|
294
|
+
[data-behaviour="action-icons"] {
|
295
|
+
min-width: 48px;
|
296
|
+
max-width: 48px;
|
297
|
+
text-align: center;
|
298
|
+
}
|
299
|
+
[data-section="action-icon-header"] {
|
300
|
+
min-width: 48px;
|
301
|
+
max-width: 48px;
|
301
302
|
}
|
302
|
-
|
303
|
-
|
304
|
-
max-width: 47px;
|
303
|
+
[data-action-title-pad="2"] {
|
304
|
+
padding-left: 53px !important;
|
305
305
|
}
|
306
|
+
[data-action-title-pad="3"] {
|
307
|
+
padding-left: 101px !important;
|
308
|
+
}
|
306
309
|
th,
|
307
310
|
td {
|
308
311
|
min-width: 120px;
|
@@ -1,11 +1,11 @@
|
|
1
1
|
- if nested_table_field.display_type == :table
|
2
2
|
tr.nested-fields
|
3
3
|
- if nested_table_field.is_positionable.call(f.object)
|
4
|
-
td
|
5
|
-
i class='fa-solid fa-
|
4
|
+
td data-behaviour='action-icons'
|
5
|
+
i class='fa-solid fa-grip-dots-vertical drag-handle pointer'
|
6
6
|
= f.hidden_field :position, class: 'hidden-position'
|
7
7
|
- if nested_table_field.is_deletable.call(f.object)
|
8
|
-
td.item-delete-cell
|
8
|
+
td.item-delete-cell data-behaviour='action-icons'
|
9
9
|
= link_to_remove_association "", f, class: 'fa-regular fa-trash-can btn-ghost'
|
10
10
|
- nested_table_field.fields.each do |field|
|
11
11
|
td data-field-type="#{field.input_type}"
|
@@ -4,19 +4,23 @@
|
|
4
4
|
.nested-field-wrapper data-table-name=assoc_name data-model-name=assoc_name.to_s.classify
|
5
5
|
/ label.field-label = nested_table_field.label.to_s.titleize
|
6
6
|
- uniq_no = Random.rand(10000)
|
7
|
+
- colspan_count = 1
|
7
8
|
.nested-form-table-wrapper
|
8
9
|
table.nested-form-table
|
9
10
|
thead
|
10
11
|
tr
|
11
12
|
- if nested_table_field.is_positionable.call(f.object)
|
12
|
-
|
13
|
-
|
|
13
|
+
- colspan_count +=1
|
14
14
|
- if nested_table_field.is_deletable.call(f.object)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
- colspan_count +=1
|
16
|
+
- nested_table_field.fields.each_with_index do |field, index|
|
17
|
+
- if index.zero?
|
18
|
+
th data-field-type="#{field.input_type}" data-action-title-pad="#{colspan_count}" colspan="#{colspan_count}"
|
19
|
+
- if field.label
|
20
|
+
= field.label.to_s || field.field_name.to_s.titleize
|
21
|
+
- else
|
22
|
+
th data-field-type="#{field.input_type}"
|
23
|
+
- if field.label
|
20
24
|
= field.label.to_s || field.field_name.to_s.titleize
|
21
25
|
tbody class="insert-cocoon-position-#{uniq_no}" data-section='nested-form-body'
|
22
26
|
= f.fields_for table_name do |record|
|
@@ -1,38 +1,39 @@
|
|
1
|
-
.form-page.permission-form
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
.permission-form__checkbox-wrapper
|
18
|
-
- saved_permission = @ar_object.cm_permissions.where(ar_model_name: model.name)
|
19
|
-
- available_actions = model.available_actions.reject {|x| ['custom_action_modal', 'custom_action', 'create', 'update'].include?(x.name)}
|
20
|
-
- is_checked = (saved_permission.count >= available_actions.count)
|
21
|
-
input.form-check-input[type="checkbox" value="" data-behaviour="permission-check-all" checked=is_checked]
|
22
|
-
.cm-checkbox-label
|
23
|
-
span.action-name
|
24
|
-
| All
|
25
|
-
- model.available_actions.each do |action|
|
26
|
-
- permission = @ar_object.cm_permissions.where(ar_model_name: model.name, action_name: action.name).first
|
27
|
-
- unless ['custom_action_modal', 'custom_action', 'create', 'update'].include?(action.name)
|
1
|
+
.form-page.permission-form
|
2
|
+
.form-page__body
|
3
|
+
.form-container
|
4
|
+
= form_for CmPermission.new, url: cm_admin.send('cm_create_role_permission_cm_role_path', @ar_object), method: :post do |f|
|
5
|
+
- cm_models = CmAdmin.config.cm_admin_models.sort_by{|k, v| k.display_name}
|
6
|
+
.form-section-container
|
7
|
+
- cm_models.each do |model|
|
8
|
+
- next if model.override_policy == true
|
9
|
+
.row
|
10
|
+
.col.form-container
|
11
|
+
p.form-title
|
12
|
+
= model.model_name
|
13
|
+
.form-container__inner
|
14
|
+
.row
|
15
|
+
.col
|
16
|
+
.form-field.disabled
|
28
17
|
.form-check
|
29
18
|
.permission-form__checkbox-wrapper
|
30
|
-
|
19
|
+
- saved_permission = @ar_object.cm_permissions.where(ar_model_name: model.name)
|
20
|
+
- available_actions = model.available_actions.reject {|x| ['custom_action_modal', 'custom_action', 'create', 'update'].include?(x.name)}
|
21
|
+
- is_checked = (saved_permission.count >= available_actions.count)
|
22
|
+
input.form-check-input[type="checkbox" value="" data-behaviour="permission-check-all" checked=is_checked]
|
31
23
|
.cm-checkbox-label
|
32
24
|
span.action-name
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
25
|
+
| All
|
26
|
+
- model.available_actions.each do |action|
|
27
|
+
- permission = @ar_object.cm_permissions.where(ar_model_name: model.name, action_name: action.name).first
|
28
|
+
- unless ['custom_action_modal', 'custom_action', 'create', 'update'].include?(action.name)
|
29
|
+
.form-check
|
30
|
+
.permission-form__checkbox-wrapper
|
31
|
+
input.form-check-input[type="checkbox" value="#{action.name}" checked=permission.present? name="role_permission[#{model.name}][#{action.name}][is_checked]" data-behaviour="permission-check-box"]
|
32
|
+
.cm-checkbox-label
|
33
|
+
span.action-name
|
34
|
+
= action.display_name || action.name.titleize
|
35
|
+
.cm-select-tag class="#{permission.present? ? '' : 'hidden'}"
|
36
|
+
= select_tag(:policy_scope_name, options_for_select(model.policy_scopes.map{|policy_hash| [policy_hash[:display_name], policy_hash[:scope_name]]}, permission&.scope_name), {name: "role_permission[#{model.name}][#{action.name}][scope_name]", class: 'select-2', id: "policy-scope-#{model.name}-#{action.name}"})
|
37
|
+
.form-submit-button-container
|
38
|
+
= f.submit 'Save Changes', class: "btn-cta"
|
39
|
+
= link_to 'Discard', cm_admin.send('cm_index_cm_role_path'), class: "btn-secondary ml-10"
|
data/lib/cm_admin/version.rb
CHANGED
@@ -189,28 +189,28 @@ module CmAdmin
|
|
189
189
|
end
|
190
190
|
|
191
191
|
def cm_single_file_upload_field(form_obj, cm_field, _value, required_class, _target_action, _ajax_url)
|
192
|
-
content_tag(:div) do
|
192
|
+
content_tag(:div, data: { 'field-type': 'single_file_upload' }) do
|
193
|
+
concat attachment_list(form_obj, cm_field, _value, required_class, _target_action)
|
193
194
|
concat form_obj.file_field cm_field.field_name,
|
194
195
|
merge_wrapper_options(
|
195
196
|
{
|
196
|
-
class: "field-control #{required_class}",
|
197
|
+
class: "field-control #{required_class} #{form_obj.object.send(cm_field.field_name).attached? ? 'hidden' : ''}",
|
197
198
|
disabled: cm_field.disabled.call(form_obj.object)
|
198
199
|
}, cm_field.html_attrs
|
199
200
|
)
|
200
|
-
concat attachment_list(form_obj, cm_field, _value, required_class, _target_action)
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
204
204
|
def cm_multi_file_upload_field(form_obj, cm_field, _value, required_class, _target_action, _ajax_url)
|
205
|
-
content_tag(:div) do
|
205
|
+
content_tag(:div, data: { 'field-type': 'multi_file_upload' }) do
|
206
|
+
concat attachment_list(form_obj, cm_field, _value, required_class, _target_action)
|
206
207
|
concat form_obj.file_field cm_field.field_name,
|
207
208
|
merge_wrapper_options(
|
208
209
|
{
|
209
|
-
multiple: true, class: "field-control #{required_class}",
|
210
|
+
multiple: true, class: "field-control #{required_class}}",
|
210
211
|
disabled: cm_field.disabled.call(form_obj.object)
|
211
212
|
}, cm_field.html_attrs
|
212
213
|
)
|
213
|
-
concat attachment_list(form_obj, cm_field, _value, required_class, _target_action)
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
@@ -219,7 +219,7 @@ module CmAdmin
|
|
219
219
|
attachment_name = "#{form_obj.object_name}_#{cm_field.field_name}_attachments"
|
220
220
|
return if defined?(::Paperclip) && attached.instance_of?(::Paperclip::Attachment)
|
221
221
|
|
222
|
-
content_tag(:div) do
|
222
|
+
content_tag(:div, data: { section: 'image-preview'}) do
|
223
223
|
if attached.class == ActiveStorage::Attached::Many
|
224
224
|
attached.each do |attachment|
|
225
225
|
concat attachment_with_icon(cm_field, attachment, attachment_name:)
|
@@ -231,16 +231,16 @@ module CmAdmin
|
|
231
231
|
end
|
232
232
|
|
233
233
|
def attachment_with_icon(cm_field, attachment, attachment_name:)
|
234
|
-
content_tag(:div,
|
235
|
-
concat(content_tag(:button, '', class: 'btn-ghost') do
|
236
|
-
concat tag.i(class: 'fa-regular fa-trash-can')
|
237
|
-
end)
|
238
|
-
concat content_tag(:span, attachment.filename.to_s, class: 'btn-link')
|
234
|
+
content_tag(:div, data: { section: 'destroy-attachment', ar_id: attachment.id, attachment_name: }) do
|
239
235
|
concat(content_tag(:a, href: attachment.url, target: '_blank') do
|
240
236
|
if attachment.content_type.include?('image')
|
241
237
|
image_tag(attachment.url, height: 50, width: 50, class: "rounded")
|
242
238
|
end
|
243
239
|
end) if cm_field.image_preview
|
240
|
+
concat content_tag(:span, attachment.filename.to_s, class: 'btn-link')
|
241
|
+
concat(content_tag(:button, '', class: 'btn-ghost') do
|
242
|
+
concat tag.i(class: 'fa-regular fa-trash-can')
|
243
|
+
end) if cm_field.input_type == :single_file_upload
|
244
244
|
end
|
245
245
|
end
|
246
246
|
|