dynamic_scaffold 0.5.0 → 0.6.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36be61464a2924a1255e1aaec3f3b24b934bbd1a159a17b93d064104c0cb95f7
|
4
|
+
data.tar.gz: 57daaef6f45e18ef51211bef4490891f5470b0c0fcb2c7c6285e7040c7aa1057
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ffa3ab65caccdb85647404e046d7c8e6d57d419c673c5f0e8389b4cfe6ae5ef9dc6a28fbe23210f1cc33b576e20384d58c9340c7827ee880c17419fd701e1e4
|
7
|
+
data.tar.gz: 6a092523f5ad7b097d03b96b039d34afe49ae27f774aeee17c649338b3d9bb10c93c49f43dc1d4ade87b6bcfc281afa4387bd0b2b947c2e6e99288bc7e041d27
|
data/README.md
CHANGED
@@ -233,7 +233,12 @@ class ShopController < ApplicationController
|
|
233
233
|
# class Shop < ApplicationRecord
|
234
234
|
# mount_uploader :thumb, ShopThumbUploader
|
235
235
|
#
|
236
|
-
config.form.item(
|
236
|
+
config.form.item(
|
237
|
+
:carrierwave_image,
|
238
|
+
:thumb,
|
239
|
+
preview_max_size: {width: '300px', height: '300px'},
|
240
|
+
removable: false # If you want to require image, please set removable to false. the default is true.
|
241
|
+
)
|
237
242
|
|
238
243
|
# If you want to display more free form field, use block.
|
239
244
|
# The block is executed in the context of view, so you can call the method of view.
|
@@ -16,12 +16,16 @@ document.addEventListener('dynamic_scaffold:load', function (){
|
|
16
16
|
|
17
17
|
// delete event
|
18
18
|
const button = preview.querySelector('.dynamicScaffoldJs-image-remove')
|
19
|
-
|
20
|
-
button
|
21
|
-
|
22
|
-
flag
|
23
|
-
|
24
|
-
|
19
|
+
let flag
|
20
|
+
if(button)
|
21
|
+
{
|
22
|
+
flag = wrapper.querySelector('.dynamicScaffoldJs-image-remove-flag')
|
23
|
+
button.addEventListener('click', function(e){
|
24
|
+
preview.style.display = 'none'
|
25
|
+
flag.disabled = false
|
26
|
+
input.value = ''
|
27
|
+
})
|
28
|
+
}
|
25
29
|
|
26
30
|
// change event
|
27
31
|
input.addEventListener('change', function(e){
|
@@ -29,7 +33,7 @@ document.addEventListener('dynamic_scaffold:load', function (){
|
|
29
33
|
reader.onload = function (e) {
|
30
34
|
img.src = e.target.result
|
31
35
|
preview.style.display = 'inline-block'
|
32
|
-
flag.disabled = true
|
36
|
+
if(flag) flag.disabled = true
|
33
37
|
}
|
34
38
|
|
35
39
|
if(input.files.length){
|
@@ -31,16 +31,20 @@
|
|
31
31
|
<%- image = form.object.public_send(elem.name) -%>
|
32
32
|
<div class="dynamicScaffoldJs-image-wrapper">
|
33
33
|
<div class="dynamicScaffoldJs-image-preview panel panel-default card mb-1">
|
34
|
+
<% if elem.options[:removable] %>
|
34
35
|
<div class="text-right panel-heading card-header">
|
35
36
|
<button type="button" class="btn btn-outline-danger btn-danger btn-sm dynamicScaffoldJs-image-remove">
|
36
37
|
<%= dynamic_scaffold_icon :times %>
|
37
38
|
</button>
|
38
39
|
</div>
|
39
|
-
|
40
|
-
|
40
|
+
<% end %>
|
41
|
+
<div class="panel-body card-body">
|
42
|
+
<div style="<%= elem.preview_image_style %>">
|
43
|
+
<img src="<%= image.url if image.file.present? %>" alt="" class="img-responsive img-fluid">
|
44
|
+
</div>
|
41
45
|
</div>
|
42
46
|
</div>
|
43
|
-
<%= form.hidden_field "remove_#{elem.name}", value: "1", disabled:"disabled", class: 'dynamicScaffoldJs-image-remove-flag'%>
|
47
|
+
<%= form.hidden_field "remove_#{elem.name}", value: "1", disabled:"disabled", class: 'dynamicScaffoldJs-image-remove-flag' if elem.options[:removable]%>
|
44
48
|
<%= elem.render(self, form, 'form-control-file dynamicScaffoldJs-image') do |attr|%>
|
45
49
|
<%= form.file_field(elem.name, attr) %>
|
46
50
|
<%end%>
|
@@ -2,9 +2,11 @@ module DynamicScaffold
|
|
2
2
|
module Form
|
3
3
|
module Item
|
4
4
|
class CarrierWaveImage < Base
|
5
|
+
attr_reader :options
|
5
6
|
def initialize(config, type, name, options = {})
|
6
7
|
super(config, type, name, {})
|
7
8
|
@options = options
|
9
|
+
@options[:removable] = true if @options[:removable].nil?
|
8
10
|
end
|
9
11
|
|
10
12
|
def preview_image_style
|
@@ -23,7 +25,7 @@ module DynamicScaffold
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def strong_parameter
|
26
|
-
[@name, "remove_#{@name}"]
|
28
|
+
@options[:removable] ? [@name, "remove_#{@name}"] : @name
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|