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: 3510af104ad96b427d07fb37304e8ef027ac1304b44690eba6f4396765913dce
4
- data.tar.gz: 10d59ca97b95307e52f470ed9b9b4d7d54baa33488f9ffdb07a9f0403ff5cf87
3
+ metadata.gz: 36be61464a2924a1255e1aaec3f3b24b934bbd1a159a17b93d064104c0cb95f7
4
+ data.tar.gz: 57daaef6f45e18ef51211bef4490891f5470b0c0fcb2c7c6285e7040c7aa1057
5
5
  SHA512:
6
- metadata.gz: e54bbebed15b73ae7f90c3cfcf602e023bdcb6fc0a0aa7ea7594b12770c69db8132465180f51b7278d478e7d3ee91aeff5dcb341b63d8ef9724c5c5d5ac95962
7
- data.tar.gz: 65c53fd1541da71f1635fd0741da54148377c9c6566a062e5c5cc759db3da9c1f2979dc59f5d6450b75faeb6130626a13e18dac8bf3c6161fc001892f0f5015d
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(:carrierwave_image, :thumb, preview_max_size: {width: '300px', height: '300px'})
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
- const flag = wrapper.querySelector('.dynamicScaffoldJs-image-remove-flag')
20
- button.addEventListener('click', function(e){
21
- preview.style.display = 'none'
22
- flag.disabled = false
23
- input.value = ''
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
- <div style="<%= elem.preview_image_style %>">
40
- <img src="<%= image.url if image.file.present? %>" alt="" class="img-responsive img-fluid">
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
@@ -1,3 +1,3 @@
1
1
  module DynamicScaffold
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masamoto Miyata