simple_form_extension 1.1.2 → 1.1.3

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
  SHA1:
3
- metadata.gz: c376f924f219d09cb3f166bc1e66f63a08625ae7
4
- data.tar.gz: 603f99ab5b7be3b18bbfc76da761f8416dcc2cd4
3
+ metadata.gz: 41f086cd052a4b616fbcd9329c43f943baf45da0
4
+ data.tar.gz: 121454242d3c9e3e9c80454e0e34e13de660c09b
5
5
  SHA512:
6
- metadata.gz: 5fe558bb91419b112cfdc8d225f9176e30ed7377cc57db007ef6a8a7fd76059972446cae9b1bd5777bae78ea5ee359abdffe2a8aef001bb72d0d44762f286687
7
- data.tar.gz: 3a1bce244ca45ebe71526999b193bc9c7b4ffa5dc370973a6ecdec2d82f2251be73c54a63f8e23aee07a53a0b8391882c71ffbce7a35e84b8f9fcb10c311da3e
6
+ metadata.gz: 55d81b2f320d89a4a8dfc9c99e502c2609a68aa255997378e576e7e5724639eb9b80d42cf98f419039da57acb99398104b4b6a831f2dd69cb70a09bd4af3aabd
7
+ data.tar.gz: 2990f089af56a6811445738d9e6954f7bb880e4c77463d21c6606c7c97d6be3b485aaa243d19d05c3adff269207ca449a782dd4667af70921d309896c174527c
@@ -4,6 +4,7 @@ en:
4
4
  file:
5
5
  select: "Select file"
6
6
  change: "Change file"
7
+ existing_file: "Existing file"
7
8
  image:
8
9
  select: "Select image"
9
10
  change: "Change image"
@@ -4,6 +4,7 @@ fr:
4
4
  file:
5
5
  select: "Sélectionnez un fichier"
6
6
  change: "Changer"
7
+ existing_file: "Fichier actuel"
7
8
  image:
8
9
  select: "Sélectionnez une image"
9
10
  change: "Changer"
@@ -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
- "<div class=\"fileinput fileinput-new input-group\" data-provides=\"fileinput\">
10
- <div class=\"form-control uneditable-input\" data-trigger=\"fileinput\">
11
- <i class=\"fa fa-file fileinput-exists\"></i>
12
- <span class=\"fileinput-filename\"></span>
13
- </div>
14
- <div class=\"input-group-btn\">
15
- <div class=\"btn btn-default btn-file\" type=\"button\">
16
- <span class=\"fileinput-new\">#{ _translate('file.select') }</span>
17
- <span class=\"fileinput-exists\">#{ _translate('file.change') }</span>
18
- #{@builder.file_field(attribute_name, input_html_options)}
19
- </div>
20
- <button class=\"btn btn-danger fileinput-exists\" data-dismiss=\"fileinput\" type=\"button\"><i class=\"fa fa-times\"></i></button>
21
- </div>
22
- </div>".html_safe
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
+ "&nbsp;".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
- "<div class=\"fileinput fileinput-new\" data-provides=\"fileinput\">
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 image_tag
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
- "<img src=\"#{ image_url }\" style=\"height: 100%; width: 100%; display: block;\">"
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
- "<div class=\"empty-thumbnail\"></div>"
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
@@ -1,3 +1,3 @@
1
1
  module SimpleFormExtension
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
@@ -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.2
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-06 00:00:00.000000000 Z
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