auto_select2 0.1.1

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.

Potentially problematic release.


This version of auto_select2 might be problematic. Click here for more details.

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 758183c5f2a42dbba45ee09816ac7e2a56cb2ea7
4
+ data.tar.gz: 4c2c87db7827c50a0448d9854e9cbbba5998fea5
5
+ SHA512:
6
+ metadata.gz: 651a632482e0a368881d3cbd7f026cf160f6c17698e8a113fa604911ba07296fa8c4b02b3b06a3f6a407a6a374c25a3a231c12d09956b7bdffe7c3aa9b85caac
7
+ data.tar.gz: eda426df8faff2353693e4aa5b89a9aae18c8bf1c6846c176515bc6344d16143dd9f1ad26719865ee5b1af9d9570127700ed4c1e4b44c721d64ccfd67138f7fa
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .idea/*
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "vendor/assets/javascripts/select2"]
2
+ path = vendor/assets/javascripts/select2
3
+ url = git@github.com:ivaynberg/select2.git
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ivan Zabrovskiy
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # AutoSelect2
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'auto-select2'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install auto-select2
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/Loriowar/auto_select2/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'auto_select2/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "auto_select2"
8
+ spec.version = AutoSelect2::VERSION
9
+ spec.authors = ["Dmitriy Lisichkin", "Ivan Zabrovskiy"]
10
+ spec.email = ["dima@sb42.ru", "lorowar@gmail.com"]
11
+ spec.summary = %q{Base methods for wrapping a Select2 and easy initialize it.}
12
+ spec.description = <<-DESC
13
+ Gem provide scripts and helpers for initialize different select2 elements:
14
+ static, ajax and multi-ajax. Moreover this gem is foundation for other gems.
15
+ For example for AutoSelect2Tab.
16
+ DESC
17
+ spec.homepage = "http://github.com/Loriowar/auto_select2/fork"
18
+ spec.license = "MIT"
19
+
20
+ spec.files = `git ls-files`.split($/)
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "railties", ">= 3.1"
26
+ spec.add_dependency 'select2-rails'
27
+ spec.add_dependency 'coffee-rails'
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.5"
30
+ spec.add_development_dependency "rake"
31
+ spec.add_development_dependency "rails", "~> 3.2.12"
32
+ end
@@ -0,0 +1,26 @@
1
+ module AutoSelect2
2
+ module Select2Helpers
3
+
4
+ def ajax_select2_init_header_tags
5
+ unless @select2_ajax_script_included
6
+ @select2_ajax_script_included = true
7
+ javascript_include_tag('auto_select2/ajax_select2')
8
+ end
9
+ end
10
+
11
+ def ajax_multi_select2_init_header_tags
12
+ unless @select2_multi_ajax_script_included
13
+ @select2_multi_ajax_script_included = true
14
+ javascript_include_tag('auto_select2/multi_ajax_select2_value_parser')
15
+ end
16
+ end
17
+
18
+ def static_select2_init_header_tags
19
+ unless @select2_static_script_included
20
+ @select2_static_script_included = true
21
+ javascript_include_tag('auto_select2/static_select2')
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ require 'auto_select2/helpers/select2_helpers.rb'
2
+
3
+ module AutoSelect2::Select2Helpers; end
4
+
5
+ ActionView::Base.send :include, AutoSelect2::Select2Helpers
@@ -0,0 +1,3 @@
1
+ module AutoSelect2
2
+ VERSION = '0.1.1'
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'auto_select2/version'
2
+ require 'auto_select2/helpers'
3
+
4
+ module AutoSelect2
5
+ class Engine < ::Rails::Engine
6
+ # Get rails to add app, lib, vendor to load path
7
+
8
+ initializer :javascripts do |app|
9
+ app.config.assets.precompile +=
10
+ %w(auto_select2/ajax_select2.js
11
+ auto_select2/multi_ajax_select2_value_parser.js
12
+ auto_select2/static_select2.js)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,87 @@
1
+ jQuery ($) ->
2
+ format = (item)->
3
+ result = item.text
4
+ if item.class_name != undefined
5
+ result = '<span class="'+item.class_name+'">'+item.text+'</span>'
6
+ result
7
+ window.initAutoAjaxSelect2 = ->
8
+ $inputs = $('input.auto-ajax-select2').not('.select2-offscreen')
9
+ $inputs.each ->
10
+ $input = $(this)
11
+ path = $input.data('href')
12
+ limit = $input.data('limit') || 25
13
+ s2DefaultOptions = {
14
+ allowClear: true
15
+ multiple: false
16
+ formatSelection: format
17
+ formatResult: format
18
+ ajax: {
19
+ url: path,
20
+ dataType: 'json',
21
+ data: (term, page) ->
22
+ ajaxData = { term: term, page: page }
23
+ $this = $(this.context)
24
+
25
+ additionalUserData = $this.data('s2options')
26
+ paramsCollection = {}
27
+ if additionalUserData isnt `undefined`
28
+ additionalAjaxData = additionalUserData['additional_ajax_data']
29
+ if additionalAjaxData isnt `undefined`
30
+ $(additionalAjaxData['selector']).each (index, el) ->
31
+ $el = $(el)
32
+ paramsCollection[$el.attr('name')] = $el.val()
33
+ return
34
+ delete paramsCollection[$this.attr('name')]
35
+
36
+ return $.extend({}, paramsCollection, ajaxData)
37
+ ,
38
+ results: (data, page) ->
39
+ more = (page * limit) < data.total
40
+ return { results: data.items, more: more }
41
+ },
42
+ initSelection : (element, callback) ->
43
+ $element = $(element)
44
+ id = $element.val()
45
+ initText = $element.data('init-text')
46
+ initClassName = $element.data('init-class-name')
47
+ if (id != '')
48
+ if initText != undefined
49
+ params = { id: id, text: initText }
50
+ if initClassName != undefined
51
+ params.class_name = initClassName
52
+ callback(params)
53
+ else
54
+ $.ajax(path, {
55
+ data: { init: true, item_ids: id },
56
+ dataType: "json"
57
+ }).done((data) ->
58
+ if(data != null)
59
+ callback(data)
60
+ else
61
+ $element.val('')
62
+ callback({ id: '', text: '' })
63
+ )
64
+ }
65
+
66
+ s2UserOptions = $input.data("s2options")
67
+
68
+ if s2UserOptions is `undefined`
69
+ s2FullOptions = $.extend({}, s2DefaultOptions)
70
+ else
71
+ s2FullOptions = $.extend({}, s2DefaultOptions, s2UserOptions)
72
+
73
+ $input.select2(s2FullOptions)
74
+
75
+ return
76
+ return
77
+ initAutoAjaxSelect2()
78
+
79
+ $body = $('body')
80
+ $body.on 'ajaxSuccess', ->
81
+ initAutoAjaxSelect2()
82
+ return
83
+
84
+ $body.on 'cocoon:after-insert', ->
85
+ initAutoAjaxSelect2()
86
+ return
87
+ return
@@ -0,0 +1,16 @@
1
+ jQuery ($) ->
2
+ # Tune input fields before submitting form, change csv values into input elements with array names
3
+ $('input.auto-ajax-select2.multiple').closest('form').submit ->
4
+ $form = $(@) # save a reference to the form for later usage
5
+ $('input.auto-ajax-select2.multiple').each ->
6
+ $multi = $(@)
7
+ data = $multi.select2('data')
8
+ name = $multi.attr('name')
9
+ $multi.remove()
10
+ # Create hidden fields with array like names
11
+ $form.append $.map(data, (obj)->
12
+ $('<input/>', type: 'hidden', name: "#{name}[]", value: obj.id)
13
+ )
14
+ return
15
+ return
16
+ return
@@ -0,0 +1,30 @@
1
+ jQuery ($) ->
2
+ window.initAutoStaticSelect2 = ->
3
+ $("select.auto-static-select2").not(".select2-offscreen").each (index, el) ->
4
+ $el = $(el)
5
+ s2UserOptions = $el.data("s2options")
6
+
7
+ s2DefaultOptions =
8
+ allowClear: true
9
+ width: "resolve"
10
+
11
+ if s2UserOptions is `undefined`
12
+ s2FullOptions = $.extend({}, s2DefaultOptions)
13
+ else
14
+ s2FullOptions = $.extend({}, s2DefaultOptions, s2UserOptions)
15
+
16
+ $el.select2(s2FullOptions)
17
+
18
+ return
19
+ return
20
+ initAutoStaticSelect2()
21
+
22
+ $body = $('body')
23
+ $body.on 'ajaxSuccess', ->
24
+ initAutoStaticSelect2()
25
+ return
26
+
27
+ $body.on 'cocoon:after-insert', ->
28
+ initAutoStaticSelect2()
29
+ return
30
+ return
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auto_select2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Dmitriy Lisichkin
8
+ - Ivan Zabrovskiy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-11-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '3.1'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '3.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: select2-rails
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: coffee-rails
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '1.5'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.5'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rails
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: 3.2.12
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: 3.2.12
98
+ description: |2
99
+ Gem provide scripts and helpers for initialize different select2 elements:
100
+ static, ajax and multi-ajax. Moreover this gem is foundation for other gems.
101
+ For example for AutoSelect2Tab.
102
+ email:
103
+ - dima@sb42.ru
104
+ - lorowar@gmail.com
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - .gitignore
110
+ - .gitmodules
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - auto_select2.gemspec
116
+ - lib/auto_select2.rb
117
+ - lib/auto_select2/helpers.rb
118
+ - lib/auto_select2/helpers/select2_helpers.rb
119
+ - lib/auto_select2/version.rb
120
+ - vendor/assets/javascripts/auto_select2/ajax_select2.js.coffee
121
+ - vendor/assets/javascripts/auto_select2/multi_ajax_select2_value_parser.js.coffee
122
+ - vendor/assets/javascripts/auto_select2/static_select2.js.coffee
123
+ homepage: http://github.com/Loriowar/auto_select2/fork
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.0.2
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Base methods for wrapping a Select2 and easy initialize it.
147
+ test_files: []
148
+ has_rdoc: