simple_form_extension 1.0.3 → 1.1.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
  SHA1:
3
- metadata.gz: 9a5c463531e99823ad37182cd382b6d65f64d0df
4
- data.tar.gz: 7ad5632119bc4b6335aae64fd987862b400a6630
3
+ metadata.gz: 946b7d8265779451e32f1032aa3b9ace6d8f02c4
4
+ data.tar.gz: 0bd6a400862b4f5fdea0b5fab2fd476c64ab0d27
5
5
  SHA512:
6
- metadata.gz: fb013f0c9983ecf7e3585aeb78eb398b833dc178a3356d0f7c4bf2db70335ffe5bbc0f4c0a634a44964663c1e9c9e1b881502ea3046fec3cb2732323ca0623d2
7
- data.tar.gz: d8d639aa61cb707142a8e78912b16d5646f85c4d032f877073b41aaf10916471a06850002f5d63a886de4810b82de4381a100c9dbea05f8a9f59ec79e52cdbcf
6
+ metadata.gz: aee6e469e6e1fec674d2aae34dd90cf4b8f5a7337b7f1e479b504573082de14bd1ca43fe2990b99da422524accf9066ed96cb3d1274af8dd2d9dd051bb69f84c
7
+ data.tar.gz: 1e5f4de04288e9789a897d2cd4e338a9fcaf4fa7b8854b68bd2f8b3cb6314d6a602d60d550539b9b0c36e603d5c3e4f20ef402db74b8ab13d14aced69de85514
@@ -13,3 +13,5 @@ en:
13
13
  format: 'm/d/Y H:i'
14
14
  shared:
15
15
  week_start_day: 0
16
+ selectize:
17
+ add: "Add"
@@ -13,3 +13,5 @@ fr:
13
13
  format: 'd/m/Y H:i'
14
14
  shared:
15
15
  week_start_day: 1
16
+ selectize:
17
+ add: "Ajouter"
@@ -11,5 +11,7 @@ module SimpleFormExtension
11
11
  autoload :FileInput
12
12
  autoload :ImageInput
13
13
  autoload :RedactorInput
14
+ autoload :AirRedactorInput
15
+ autoload :SelectizeInput
14
16
  end
15
17
  end
@@ -0,0 +1,15 @@
1
+ module SimpleFormExtension
2
+ module Inputs
3
+ class AirRedactorInput < SimpleForm::Inputs::TextInput
4
+ def input(wrapper_options = nil)
5
+ @additional_classes ||= additional_classes
6
+ @additional_classes -= [input_type]
7
+
8
+
9
+ input_html_options[:"data-air-redactor"] = true
10
+
11
+ super
12
+ end
13
+ end
14
+ end
15
+ end
@@ -16,10 +16,29 @@ module SimpleFormExtension
16
16
  <button class=\"btn btn-danger fileinput-exists pull-right\" data-dismiss=\"fileinput\" type=\"button\"><i class=\"fa fa-times\"></i></button>
17
17
  </div>
18
18
  <div class=\"fileinput-preview thumbnail\">
19
- <img data-src='holder.js/100%x100%' alt=\"100%x100%\" src=\"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxOTAiIGhlaWdodD0iMTQwIj48cmVjdCB3aWR0aD0iMTkwIiBoZWlnaHQ9IjE0MCIgZmlsbD0iI2VlZSI+PC9yZWN0Pjx0ZXh0IHRleHQtYW5jaG9yPSJtaWRkbGUiIHg9Ijk1IiB5PSI3MCIgc3R5bGU9ImZpbGw6I2FhYTtmb250LXdlaWdodDpib2xkO2ZvbnQtc2l6ZToxMnB4O2ZvbnQtZmFtaWx5OkFyaWFsLEhlbHZldGljYSxzYW5zLXNlcmlmO2RvbWluYW50LWJhc2VsaW5lOmNlbnRyYWwiPjE5MHgxNDA8L3RleHQ+PC9zdmc+\" style=\"height: 100%; width: 100%; display: block;\">
19
+ #{ image_tag }
20
20
  </div>
21
21
  </div>".html_safe
22
22
  end
23
+
24
+ private
25
+
26
+ def image_tag
27
+ if @builder.object.send(:"#{ attribute_name }?")
28
+ image_url = @builder.object.send(attribute_name).url(image_style)
29
+ "<img src=\"#{ image_url }\" style=\"height: 100%; width: 100%; display: block;\">"
30
+ else
31
+ "<div class=\"empty-thumbnail\"></div>"
32
+ end
33
+ end
34
+
35
+ def image_style
36
+ styles = @builder.object.send(attribute_name).styles.map(&:first)
37
+ # Check if there's a :thumb or :thumbnail style in attachment definition
38
+ thumb = styles.find { |s| %w(thumb thumbnail).include?(s.to_s) }
39
+ # Return the potentially smallest size !
40
+ thumb || styles.first || :original
41
+ end
23
42
  end
24
43
  end
25
44
  end
@@ -0,0 +1,88 @@
1
+ module SimpleFormExtension
2
+ module Inputs
3
+ class SelectizeInput < SimpleForm::Inputs::Base
4
+ include SimpleFormExtension::Translations
5
+
6
+ # This field only allows local select options (serialized into JSON)
7
+ # Searching for remote ones will be implemented later.
8
+ #
9
+ # Data attributes that may be useful :
10
+ #
11
+ # :'search-url' => search_url,
12
+ # :'search-param' => search_param,
13
+ # :'preload' => preload,
14
+ #
15
+ def input(wrapper_options = {})
16
+ input_html_options[:data] ||= {}
17
+
18
+ input_html_options[:data].merge!(
19
+ :'selectize' => true,
20
+ :'value' => serialized_value,
21
+ :'creatable' => creatable?,
22
+ :'multi' => multi?,
23
+ :'add-translation' => _translate('selectize.add'),
24
+ :'collection' => collection
25
+ )
26
+
27
+ @builder.hidden_field attribute_name, input_html_options
28
+ end
29
+
30
+ def creatable?
31
+ !!options[:creatable]
32
+ end
33
+
34
+ def multi?
35
+ (options.key?(:multi) && !!options[:multi]) ||
36
+ value.class.include?(Enumerable)
37
+ end
38
+
39
+ def collection
40
+ if (collection = options[:collection])
41
+ if collection.class.include?(Enumerable)
42
+ collection.map(&method(:serialize_option))
43
+ else
44
+ (object.send(collection) || []).map(&method(:serialize_option))
45
+ end
46
+ else
47
+ []
48
+ end
49
+ end
50
+
51
+ def serialized_value
52
+ if multi?
53
+ value.map do |item|
54
+ { text: item, value: item }
55
+ end
56
+ else
57
+ value && { text: value, value: value }
58
+ end
59
+ end
60
+
61
+ def value
62
+ @value ||= options_fetch(:value) { object.send(attribute_name) }
63
+ end
64
+
65
+ private
66
+
67
+ def serialize_option(option)
68
+ if option.kind_of?(Hash) && options.key?(:text) && option.key?(:value)
69
+ option
70
+ elsif !option.kind_of?(Hash)
71
+ { text: option.to_s, value: option }
72
+ else
73
+ raise ArgumentError.new "The individual collection items should " \
74
+ "either be single items or a hash with :text and :value fields"
75
+ end
76
+ end
77
+
78
+ def options_fetch(key, &block)
79
+ [options, input_html_options].each do |hash|
80
+ return hash[key] if hash.key?(key)
81
+ end
82
+
83
+ # Return default block value or nil if no block was given
84
+ block ? block.call : nil
85
+ end
86
+ end
87
+ end
88
+ end
@@ -1,3 +1,3 @@
1
1
  module SimpleFormExtension
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency 'rails', '>= 3.1'
23
23
  spec.add_dependency 'simple_form'
24
24
  spec.add_dependency 'redactor-rails'
25
+ spec.add_dependency 'selectize-rails'
25
26
 
26
27
  spec.add_development_dependency 'bundler', '~> 1.5'
27
28
  spec.add_development_dependency 'rake'
@@ -1,4 +1,7 @@
1
1
  #= require redactor-rails/redactor.min
2
+ #= require redactor-rails/langs/fr
3
+ #= require redactor-rails/plugins
4
+ #= require selectize
2
5
  #= require jquery.datetimepicker
3
6
  #= require_self
4
7
  #= require_tree ./simple_form_extension
@@ -10,8 +10,43 @@ onPageReady ->
10
10
  # Avoid double initialization
11
11
  unless $textArea.data('initialized.redactor')
12
12
  $textArea.redactor
13
+ buttons: ['html', 'formatting', 'bold', 'italic', 'underline', 'deleted',
14
+ 'unorderedlist', 'orderedlist', 'outdent', 'indent',
15
+ 'image', 'video', 'file', 'table', 'link', 'alignment', 'horizontalrule']
16
+ minHeight: 400
13
17
  imageUpload: ["/redactor_rails/pictures", params].join('?')
14
18
  imageGetJson: "/redactor_rails/pictures"
19
+ fileUpload: ["/redactor_rails/documents", params].join('?')
20
+ fileGetJson: "/redactor_rails/documents"
21
+ plugins: [
22
+ "fontcolor"
23
+ "fontsize"
24
+ ]
15
25
  path: "/assets/redactor-rails"
16
26
  css: "style.css"
27
+ lang: "fr"
17
28
  $textArea.data('initialized.redactor', true)
29
+
30
+ $('[data-air-redactor]').each (i, el) ->
31
+ $textArea = $(el)
32
+ # Avoid double initialization
33
+ unless $textArea.data('initialized.redactor')
34
+ $textArea.redactor
35
+ air: true
36
+ plugins: [
37
+ "fontcolor"
38
+ "fontsize"
39
+ ]
40
+ airButtons: [
41
+ "bold"
42
+ "italic"
43
+ "fontcolor"
44
+ "fontsize"
45
+ "underline"
46
+ "deleted"
47
+ "link"
48
+ ]
49
+ lang: "fr"
50
+
51
+ $textArea.data('initialized.redactor', true)
52
+
@@ -0,0 +1,55 @@
1
+ class Selectize
2
+ constructor: (@$el) ->
3
+ @single = @$el.data('multi') is false
4
+ @el = @$el[0]
5
+
6
+ creatable = @$el.data('creatable')
7
+ addTranslation = @$el.data('add-translation')
8
+
9
+ @$el.val('')
10
+
11
+ @$el.selectize(
12
+ mode: if @single then 'single' else 'multi'
13
+ sortField: 'text'
14
+ plugins: ['remove_button']
15
+ create: creatable
16
+ render: @renderOptions()
17
+ options: @$el.data('collection')
18
+ )
19
+
20
+ if (value = @$el.data('value'))
21
+ @initializeValue(value)
22
+
23
+ initializeValue: (data) ->
24
+ if @single
25
+ @el.selectize.addOption(data)
26
+ else
27
+ $.each data, (i, item) => @el.selectize.addOption(item)
28
+
29
+ if @single
30
+ @el.selectize.addItem(data.value)
31
+ else
32
+ $.each data, (i, item) => @el.selectize.addItem(item.value)
33
+
34
+ addAndSelect: (data) ->
35
+ @el.selectize.addOption(data)
36
+ @el.selectize.addItem(data.value)
37
+
38
+ renderOptions: ->
39
+ option_create: (data) ->
40
+ """
41
+ <div class="create" data-selectable="">
42
+ #{ @addTranslation } <strong>#{ data.input }</strong> ...
43
+ </div>
44
+ """
45
+
46
+ onPageReady ->
47
+ $selectizes = $('[data-selectize]')
48
+
49
+ return unless $selectizes.length
50
+
51
+ $('[data-selectize]').each (i, el) ->
52
+ $select = $(el)
53
+ return if $select.data('simple-form:selectize')
54
+ instance = new Selectize($select)
55
+ $select.data('simple-form:selectize', instance)
@@ -1,2 +1,4 @@
1
1
  //= require redactor-rails
2
+ //= require selectize
3
+ //= require selectize.bootstrap3
2
4
  //= require jquery.datetimepicker
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.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Vasseur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-03 00:00:00.000000000 Z
11
+ date: 2014-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: selectize-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -104,6 +118,7 @@ files:
104
118
  - lib/simple_form_extension/components/popovers.rb
105
119
  - lib/simple_form_extension/ext/form_builder.rb
106
120
  - lib/simple_form_extension/inputs.rb
121
+ - lib/simple_form_extension/inputs/air_redactor_input.rb
107
122
  - lib/simple_form_extension/inputs/boolean_input.rb
108
123
  - lib/simple_form_extension/inputs/collection_check_boxes_input.rb
109
124
  - lib/simple_form_extension/inputs/collection_radio_buttons_input.rb
@@ -113,6 +128,7 @@ files:
113
128
  - lib/simple_form_extension/inputs/image_input.rb
114
129
  - lib/simple_form_extension/inputs/numeric_input.rb
115
130
  - lib/simple_form_extension/inputs/redactor_input.rb
131
+ - lib/simple_form_extension/inputs/selectize_input.rb
116
132
  - lib/simple_form_extension/railtie.rb
117
133
  - lib/simple_form_extension/translations.rb
118
134
  - lib/simple_form_extension/version.rb
@@ -123,6 +139,7 @@ files:
123
139
  - vendor/assets/javascripts/simple_form_extension/.DS_Store
124
140
  - vendor/assets/javascripts/simple_form_extension/datetimepicker.coffee
125
141
  - vendor/assets/javascripts/simple_form_extension/redactor.coffee
142
+ - vendor/assets/javascripts/simple_form_extension/selectize.coffee
126
143
  - vendor/assets/stylesheets/jquery.datetimepicker.css
127
144
  - vendor/assets/stylesheets/simple_form_extension.sass
128
145
  homepage: http://www.glyph.fr