redmine_crm 0.0.35 → 0.0.36

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: 92635e6f0499ac5b1796630c2f6cbfad4e4e7155
4
- data.tar.gz: 0fc303aa0ea4ae0d62b5a309236f4c0a0fa08b98
3
+ metadata.gz: f2ae8872b72b3265c1ae6e6993a8b3e0ca78f920
4
+ data.tar.gz: c8364d112ed92618726af3ef54b16ffc23090abd
5
5
  SHA512:
6
- metadata.gz: 89f55f9402861d004b5ab7b552bea9fe5854f61f18797333364c66f8b9473bc7ce3c949c15fbc2a3ca27d4a54881092cca33894a5516a58c2ea93dcfa7f12740
7
- data.tar.gz: ada540ad5f9e398420e4c7d89fe66e4a21ff2fb238cd9cc0cf65b77c4dcf6565127efd54a80c54b46c89b1f8161ad8742495f775cdf25f3801b525634760a0f1
6
+ metadata.gz: 7a623433baaf7d77bf346e0a04e0a0052eeee082d063d13b073b20d487208bf1ac0183d03380b18e109d7ddfbc88405f5c8afde7d05c4b3a2c65241f50ff1b67
7
+ data.tar.gz: 4004698fa8ee608d219a319142708253de3dc0770bba5d856715ffb9c49d7753c0c41320321bf8a9a6296b87a2767249727d215077487972088a58889b07389c
data/doc/CHANGELOG CHANGED
@@ -4,6 +4,10 @@ Redmine crm gem - general functions for plugins (tags, vote, viewing, currency)
4
4
  Copyright (C) 2011-2018 RedmineUP
5
5
  https://www.redmineup.com/
6
6
 
7
+ == 2018-03-22 v0.0.36
8
+
9
+ * select2_tag improvements
10
+
7
11
  == 2018-03-05 v0.0.35
8
12
 
9
13
  * Added select2_tag helper
@@ -1,40 +1,92 @@
1
1
  module RedmineCrm
2
2
  module FormTagHelper
3
+ # Allows include select2 into your views.
4
+ #
5
+ # ==== Examples
6
+ # select2_tag 'city_id', '<option value="1">Lisbon</option>...'
7
+ # select2_tag 'city_id', options_for_select(...)
8
+ # select2_tag 'tag_list', nil, :multiple => true, :data => [{ id: 0, text: 'deal' }, ...], :tags => true, :include_hidden => false %>
9
+ # select2_tag 'tag_list', options_for_select(...), :multiple => true, :style => 'width: 100%;', :url => '/tags', :placeholder => '+ add tag', :tags => true %>
10
+ #
11
+ # You may use select_tag options and additional options.
12
+ #
13
+ # ==== Additional options
14
+ # * <tt>:url</tt> Allows searches for remote data using the ajax.
15
+ # * <tt>:data</tt> Load dropdown options from a local array if +url+ option not set.
16
+ # * <tt>:placeholder</tt> Supports displaying a placeholder value.
17
+ # * <tt>:include_hidden</tt> Adds hidden field after select when +multiple+ option true. Default value true.
18
+ #
19
+ # <b>Note:</b> The HTML specification says when +multiple+ parameter passed to select and all options got deselected
20
+ # web browsers do not send any value to server.
21
+ #
22
+ # In case if you don't want the helper to generate this hidden field you can specify
23
+ # <tt>include_hidden: false</tt> option.
24
+ #
25
+ # Also aliased as: select2
26
+ #
27
+ # select2 'city_id', options_for_select(...)
28
+ #
3
29
  def select2_tag(name, option_tags = nil, options = {})
4
30
  id = sanitize_to_id(name)
5
- url = options[:url].to_s
6
- data = options[:data] || []
7
31
  placeholder = options[:placeholder] || 'Select ...'
8
32
 
9
- data_source =
10
- if url.empty?
11
- "data: #{data.to_json}"
12
- else
13
- "ajax: {
14
- url: '#{url}',
15
- dataType: 'json',
16
- delay: 250,
17
- data: function (params) {
18
- return { q: params.term };
19
- },
20
- processResults: function (data, params) {
21
- return { results: data };
22
- },
23
- cache: true
24
- }"
25
- end
26
-
27
33
  content_for(:header_tags) { select2_assets }
28
34
  result = select_tag(name, option_tags, options)
35
+ if options[:multiple] && options.fetch(:include_hidden, true)
36
+ result << hidden_field_tag("#{name}[]", '')
37
+ end
38
+
29
39
  result << javascript_tag(<<-JS)
30
40
  $(function () {
31
41
  $('select#' + '#{id}').select2({
32
- #{data_source},
33
- tags: #{options[:tags] || false},
42
+ #{select2_data_source_options(options)},
43
+ #{select2_tags_options(options)},
34
44
  placeholder: '#{placeholder}'
35
45
  });
36
46
  });
37
47
  JS
38
48
  end
49
+
50
+ alias select2 select2_tag
51
+
52
+ private
53
+
54
+ def select2_data_source_options(options = {})
55
+ if options[:url].to_s.empty?
56
+ "data: #{options.fetch(:data, []).to_json}"
57
+ else
58
+ "ajax: {
59
+ url: '#{options[:url]}',
60
+ dataType: 'json',
61
+ delay: 250,
62
+ data: function (params) {
63
+ return { q: params.term };
64
+ },
65
+ processResults: function (data, params) {
66
+ return { results: data };
67
+ },
68
+ cache: true
69
+ }"
70
+ end
71
+ end
72
+
73
+ def select2_tags_options(options = {})
74
+ if options.fetch(:tags, false)
75
+ "tags: true,
76
+ tokenSeparators: [','],
77
+ createTag: function (params) {
78
+ var term = $.trim(params.term);
79
+ if (term === '' || term.indexOf(',') > -1) {
80
+ return null; // Return null to disable tag creation
81
+ }
82
+ return {
83
+ id: term,
84
+ text: term
85
+ }
86
+ }"
87
+ else
88
+ 'tags: false'
89
+ end
90
+ end
39
91
  end
40
92
  end
@@ -1,3 +1,3 @@
1
1
  module RedmineCrm
2
- VERSION = "0.0.35"
2
+ VERSION = "0.0.36"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine_crm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.35
4
+ version: 0.0.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - RedmineUP
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-05 00:00:00.000000000 Z
11
+ date: 2018-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid