simple_form_extension 1.1.2 → 1.1.3
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/lib/generators/simple_form_extension/templates/config/locales/simple_form_extension.en.yml +1 -0
- data/lib/generators/simple_form_extension/templates/config/locales/simple_form_extension.fr.yml +1 -0
- data/lib/simple_form_extension/inputs/file_input.rb +67 -14
- data/lib/simple_form_extension/inputs/image_input.rb +47 -16
- data/lib/simple_form_extension/version.rb +1 -1
- data/vendor/assets/javascripts/simple_form_extension/fileinput.coffee +39 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41f086cd052a4b616fbcd9329c43f943baf45da0
|
4
|
+
data.tar.gz: 121454242d3c9e3e9c80454e0e34e13de660c09b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55d81b2f320d89a4a8dfc9c99e502c2609a68aa255997378e576e7e5724639eb9b80d42cf98f419039da57acb99398104b4b6a831f2dd69cb70a09bd4af3aabd
|
7
|
+
data.tar.gz: 2990f089af56a6811445738d9e6954f7bb880e4c77463d21c6606c7c97d6be3b485aaa243d19d05c3adff269207ca449a782dd4667af70921d309896c174527c
|
@@ -3,23 +3,76 @@ module SimpleFormExtension
|
|
3
3
|
class FileInput < SimpleForm::Inputs::Base
|
4
4
|
include SimpleFormExtension::Translations
|
5
5
|
|
6
|
+
delegate :content_tag, to: :template
|
7
|
+
|
6
8
|
def input(wrapper_options = nil)
|
7
9
|
input_html_options[:class] << "file-upload"
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
input_markup
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def input_markup
|
17
|
+
content_tag(:div, class: 'fileinput fileinput-new input-group', data: { provides: 'fileinput' }) do
|
18
|
+
content_tag(:div, class: 'form-control uneditable-input', data: { trigger: 'fileinput' }) do
|
19
|
+
content_tag(:i, '', class: 'fa fa-file fileinput-exists') +
|
20
|
+
content_tag(:span, '', class: 'fileinput-filename')
|
21
|
+
end +
|
22
|
+
|
23
|
+
content_tag(:div, class: 'input-group-btn') do
|
24
|
+
content_tag(:div, class: 'btn btn-default btn-file') do
|
25
|
+
content_tag(:span, _translate('file.select'), class: 'fileinput-new') +
|
26
|
+
content_tag(:span, _translate('file.change'), class: 'fileinput-exists') +
|
27
|
+
@builder.file_field(attribute_name, input_html_options)
|
28
|
+
end +
|
29
|
+
|
30
|
+
content_tag(:button, class: 'btn btn-danger fileinput-exists', type: 'button', data: { dismiss: 'fileinput' }) do
|
31
|
+
content_tag(:i, '', class: 'fa fa-times')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end +
|
35
|
+
|
36
|
+
existing_file_tag
|
37
|
+
end
|
38
|
+
|
39
|
+
def existing_file_tag
|
40
|
+
return '' unless has_file?
|
41
|
+
|
42
|
+
url = object.send(attribute_name).url
|
43
|
+
|
44
|
+
content_tag(:div, class: 'input-group help-block existing-file', data: { provides: 'existing-file'}) do
|
45
|
+
content_tag(:span, class: 'input-group-addon') do
|
46
|
+
"#{ _translate('file.existing_file') } : ".html_safe
|
47
|
+
end +
|
48
|
+
|
49
|
+
content_tag(:div, class: 'btn-group') do
|
50
|
+
content_tag(:a, class: 'btn btn-default ', href: url, target: '_blank', data: { toggle: 'existing-file' }) do
|
51
|
+
content_tag(:i, '', class: 'fa fa-file') +
|
52
|
+
" ".html_safe +
|
53
|
+
object.send(:"#{ attribute_name }_file_name").html_safe
|
54
|
+
end +
|
55
|
+
|
56
|
+
remove_file_button
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def remove_file_button
|
62
|
+
return unless object.respond_to?(:"#{ remove_attachment_method }=")
|
63
|
+
|
64
|
+
content_tag(:button, class: 'btn btn-danger', type: 'button', data: { dismiss: 'existing-file' }) do
|
65
|
+
content_tag(:i, '', class: 'fa fa-remove', data: { :'removed-class' => 'fa fa-refresh' }) +
|
66
|
+
@builder.hidden_field(remove_attachment_method, class: 'remove-file-input', value: nil)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def remove_attachment_method
|
71
|
+
options[:remove_method] || :"remove_#{ attribute_name }"
|
72
|
+
end
|
73
|
+
|
74
|
+
def has_file?
|
75
|
+
@has_file ||= object.send(:"#{ attribute_name }?")
|
23
76
|
end
|
24
77
|
end
|
25
78
|
end
|
@@ -3,35 +3,66 @@ module SimpleFormExtension
|
|
3
3
|
class ImageInput < SimpleForm::Inputs::Base
|
4
4
|
include SimpleFormExtension::Translations
|
5
5
|
|
6
|
+
delegate :content_tag, :image_tag, to: :template
|
7
|
+
|
6
8
|
def input(wrapper_options = nil)
|
7
9
|
input_html_options[:class] << "image-upload"
|
8
10
|
|
9
|
-
|
10
|
-
<div class=\"\">
|
11
|
-
<div class=\"btn btn-default btn-file\" type=\"button\">
|
12
|
-
<span class=\"fileinput-new\">#{ _translate('image.select') }</span>
|
13
|
-
<span class=\"fileinput-exists\">#{ _translate('image.change') }</span>
|
14
|
-
#{@builder.file_field(attribute_name, input_html_options)}
|
15
|
-
</div>
|
16
|
-
<button class=\"btn btn-danger fileinput-exists\" data-dismiss=\"fileinput\" type=\"button\"><i class=\"fa fa-times\"></i></button>
|
17
|
-
</div>
|
18
|
-
<div class=\"fileinput-preview thumbnail\">
|
19
|
-
#{ image_tag }
|
20
|
-
</div>
|
21
|
-
</div>".html_safe
|
11
|
+
input_markup
|
22
12
|
end
|
23
13
|
|
24
14
|
private
|
25
15
|
|
26
|
-
def
|
16
|
+
def input_markup
|
17
|
+
content_tag(:div, class: 'fileinput fileinput-new', data: { provides: 'fileinput' }) do
|
18
|
+
content_tag(:div) do
|
19
|
+
content_tag(:div, class: 'btn btn-default btn-file') do
|
20
|
+
content_tag(:div, _translate('image.select'), class: 'fileinput-new') +
|
21
|
+
content_tag(:div, _translate('image.change'), class: 'fileinput-exists') +
|
22
|
+
@builder.file_field(attribute_name, input_html_options)
|
23
|
+
end +
|
24
|
+
|
25
|
+
content_tag(:button, class: 'btn btn-danger fileinput-exists', type: 'button', data: { dismiss: 'fileinput' }) do
|
26
|
+
content_tag(:i, '', class: 'fa fa-times')
|
27
|
+
end
|
28
|
+
end +
|
29
|
+
|
30
|
+
content_tag(:div, class: 'fileinput-preview thumbnail') do
|
31
|
+
existing_image_tag
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def existing_image_tag
|
27
37
|
if @builder.object.send(:"#{ attribute_name }?")
|
28
38
|
image_url = @builder.object.send(attribute_name).url(image_style)
|
29
|
-
|
39
|
+
|
40
|
+
container_style = 'position: relative; height: 100%; width: 100%; min-height: 50px;min-width: 58px; display: block;'
|
41
|
+
|
42
|
+
content_tag(:div, style: container_style, data: { provides: 'existing-file' }) do
|
43
|
+
image_tag(image_url, style: 'height: 100%; width: 100%; display: block;', data: { toggle: 'existing-file' }) +
|
44
|
+
remove_image_button
|
45
|
+
end
|
30
46
|
else
|
31
|
-
|
47
|
+
content_tag(:div, '', class: 'empty-thumbnail')
|
32
48
|
end
|
33
49
|
end
|
34
50
|
|
51
|
+
def remove_image_button
|
52
|
+
return unless object.respond_to?(:"#{ remove_attachment_method }=")
|
53
|
+
|
54
|
+
button_style = 'position: absolute; top: 10px; left: 10px;'
|
55
|
+
|
56
|
+
content_tag(:button, class: 'btn btn-danger', style: button_style, type: 'button', data: { dismiss: 'existing-file' }) do
|
57
|
+
content_tag(:i, '', class: 'fa fa-remove', data: { :'removed-class' => 'fa fa-refresh' }) +
|
58
|
+
@builder.hidden_field(remove_attachment_method, class: 'remove-file-input', value: nil)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def remove_attachment_method
|
63
|
+
options[:remove_method] || :"remove_#{ attribute_name }"
|
64
|
+
end
|
65
|
+
|
35
66
|
def image_style
|
36
67
|
styles = @builder.object.send(attribute_name).styles.map(&:first)
|
37
68
|
# Check if there's a :thumb or :thumbnail style in attachment definition
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class ExistingFileField
|
2
|
+
constructor: (@$field) ->
|
3
|
+
@$existingFile = @$field.find('[data-toggle="existing-file"]')
|
4
|
+
@$removeButton = @$field.find('[data-dismiss="existing-file"]')
|
5
|
+
@$removeInput = @$removeButton.find('input')
|
6
|
+
|
7
|
+
@$removeButtonIcon = @$removeButton.find('i')
|
8
|
+
@originalClass = @$removeButtonIcon.attr('class')
|
9
|
+
@removedClass = @$removeButtonIcon.attr('data-removed-class')
|
10
|
+
|
11
|
+
console.log('foo', @$removeButton, @$removeInput)
|
12
|
+
|
13
|
+
@$removeButton.on('click', $.proxy(@removeButtonClicked, this))
|
14
|
+
|
15
|
+
removeButtonClicked: ->
|
16
|
+
if @$removeInput.val()
|
17
|
+
@unsetRemoved()
|
18
|
+
else
|
19
|
+
@setRemoved()
|
20
|
+
|
21
|
+
setRemoved: ->
|
22
|
+
@$removeInput.val('1')
|
23
|
+
@$existingFile.hide(0)
|
24
|
+
@$removeButtonIcon.attr(class: @removedClass)
|
25
|
+
|
26
|
+
unsetRemoved: ->
|
27
|
+
@$removeInput.removeAttr('value')
|
28
|
+
@$existingFile.show(0)
|
29
|
+
@$removeButtonIcon.attr(class: @originalClass)
|
30
|
+
|
31
|
+
onPageReady ->
|
32
|
+
$('body').on 'click', '[data-dismiss="existing-file"]', (e) ->
|
33
|
+
$button = $(e.currentTarget)
|
34
|
+
$field = $button.closest('[data-provides="existing-file"]')
|
35
|
+
|
36
|
+
unless $field.data('simple-form:existing-file')
|
37
|
+
data = new ExistingFileField($field)
|
38
|
+
data.removeButtonClicked()
|
39
|
+
$field.data('simple-form:existing-file', data)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form_extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Vasseur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- vendor/assets/javascripts/simple_form_extension.coffee
|
139
139
|
- vendor/assets/javascripts/simple_form_extension/.DS_Store
|
140
140
|
- vendor/assets/javascripts/simple_form_extension/datetimepicker.coffee
|
141
|
+
- vendor/assets/javascripts/simple_form_extension/fileinput.coffee
|
141
142
|
- vendor/assets/javascripts/simple_form_extension/redactor.coffee
|
142
143
|
- vendor/assets/javascripts/simple_form_extension/selectize.coffee
|
143
144
|
- vendor/assets/javascripts/simple_form_extension/spinbox.coffee
|