sortablelabel-js 1.9.1 → 2.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: d59b839aed6ea45e04d202bc610f95026daf7914
4
- data.tar.gz: af05203c5149ec2a2baee842b4db1906380a98ac
3
+ metadata.gz: 076c2fc366c4647abbd5651a889adbcc9056f12b
4
+ data.tar.gz: 707d95a4fe9752e837a30b385c9e79ec2821fc85
5
5
  SHA512:
6
- metadata.gz: b2e5633bffd0d1b2afa4dd2500d37ee943c289020682de882eecde715e75e09919bfde1b34cdeafade3f942505108335d1b0ddf238103e9058bdeadf7acc6648
7
- data.tar.gz: a3eaf6589830cccba59b655b54a6423a35ce4feabd1835f0e096f9efe804d1d44e6c372ebbba2b95d8c2b114f5a0da95a69aa9e3cdbb0ff6e4fbb461b5de7e07
6
+ metadata.gz: 2ec95c40738fd473d417b1817066787e367ec616fbb78d76c7978dae4a95307e145b072e6c546aa520816a38599befbb53801d3c3e209fb781c15cea9226fd3b
7
+ data.tar.gz: 9e90fba5c89dc1ac134dd3c3fa42be238152e73d27de5820d18a9afa5038c2c846b44d6de4df43fce2dd3c60731f647b1d70305c98371affb4a31038c9b32684
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sortablelabel-js (1.9.1)
4
+ sortablelabel-js (2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -26,7 +26,6 @@ PLATFORMS
26
26
  ruby
27
27
 
28
28
  DEPENDENCIES
29
- bundler (~> 1.15)
30
29
  rake (~> 10.0)
31
30
  rspec (~> 3.0)
32
31
  sortablelabel-js!
@@ -1,5 +1,5 @@
1
1
  module Sortablelabel
2
2
  module Js
3
- VERSION = "1.9.1"
3
+ VERSION = "2.0"
4
4
  end
5
5
  end
@@ -6,8 +6,8 @@ require "sortablelabel/js/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "sortablelabel-js"
8
8
  spec.version = Sortablelabel::Js::VERSION
9
- spec.authors = ["Joe"]
10
- spec.email = ["ashzhouyue@gmail.com"]
9
+ spec.authors = ["BenZhang"]
10
+ spec.email = ["bzbnhang@gmail.com"]
11
11
 
12
12
  spec.summary = "Sortable label plugin for the project"
13
13
  spec.description = "Sortable label plugin for the project"
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_development_dependency "bundler", "~> 1.15"
27
26
  spec.add_development_dependency "rake", "~> 10.0"
28
27
  spec.add_development_dependency "rspec", "~> 3.0"
29
28
  end
@@ -11,7 +11,7 @@ class @SortableLabel
11
11
 
12
12
  constructor: (scope, options) ->
13
13
  @options = $.extend({}, defaults, options)
14
- @target = $(scope)
14
+ @target = scope
15
15
  @targetId = @options['fieldName'] || @target.attr('id')
16
16
  @stop_callback = @options["stop"]
17
17
  @initSortByPosition()
@@ -57,83 +57,85 @@ class @SortableLabel
57
57
  # 2. ascending sort field elements which part of them are no provided position
58
58
  initSortByPosition: () ->
59
59
  _option = @options
60
- all_fields = @target.find(_option['sortableItem'])
61
- _positionTarget = _option['positionTarget']
62
- all_remain_fields_info = []
63
- all_removed_fields_info = []
64
- maxium_position = 1
65
-
66
- if all_fields.length > 0
67
-
68
- # get the maxinum_position
69
- all_fields.each((index, field_item) ->
70
- _position = $(field_item).find(_positionTarget).val()
71
- if _position && _position != '' && typeof _position != 'undefined'
72
- _position = parseInt(_position, 10)
73
- if _position >= maxium_position
74
- maxium_position = _position
75
- )
76
-
77
- # in case that new added field position value is initialized as null or '' or undefined
78
- all_fields.each((index, field_item) ->
79
- _position = $(field_item).find(_positionTarget).val()
80
- if !_position || _position == '' || typeof _position != 'undefined'
81
- maxium_position += 1
82
- $(field_item).find(_positionTarget).val(maxium_position)
83
- )
60
+ @target.each((i, sub_target) ->
61
+ all_fields = $(sub_target).find(_option['sortableItem'])
62
+ _positionTarget = _option['positionTarget']
63
+ all_remain_fields_info = []
64
+ all_removed_fields_info = []
65
+ maxium_position = 1
66
+
67
+ if all_fields.length > 0
68
+
69
+ # get the maxinum_position
70
+ all_fields.each((index, field_item) ->
71
+ _position = $(field_item).find(_positionTarget).val()
72
+ if _position && _position != '' && typeof _position != 'undefined'
73
+ _position = parseInt(_position, 10)
74
+ if _position >= maxium_position
75
+ maxium_position = _position
76
+ )
84
77
 
85
- # filter removed fields and remain fields
86
- all_fields.each((index, field_item) ->
87
- _position = $(field_item).find(_positionTarget).val()
88
- _is_removed = $(field_item).find(_option['removeField']).val()
89
- if _is_removed == "false" || _is_removed == false
90
- _is_removed = "false"
91
- else
92
- _is_removed = "true"
93
-
94
- # removed fields should be filtered
95
- # only unremoved fields will be sorted
96
- if _is_removed == 'true'
97
- all_removed_fields_info.push({
98
- position: _position,
99
- j_element: field_item
100
- })
101
- else
102
- all_remain_fields_info.push({
103
- position: _position,
104
- j_element: field_item
105
- })
106
- )
78
+ # in case that new added field position value is initialized as null or '' or undefined
79
+ all_fields.each((index, field_item) ->
80
+ _position = $(field_item).find(_positionTarget).val()
81
+ if !_position || _position == '' || typeof _position != 'undefined'
82
+ maxium_position += 1
83
+ $(field_item).find(_positionTarget).val(maxium_position)
84
+ )
107
85
 
108
- # 1. go through sorted array to check if a field is of same position as previous fields
109
- # 2. if so, update the position of later one as max position + 1
110
- if all_remain_fields_info.length > 0
111
-
112
- _tmp_remain_fields_info = all_remain_fields_info.slice()
113
- for field, key in _tmp_remain_fields_info
114
- current_position = field.position
115
- for previous_field, previous_key in _tmp_remain_fields_info
116
- tmp_position = previous_field.position
117
- if tmp_position == current_position && previous_key < key
118
- maxium_position += 1
119
- all_remain_fields_info[key].position = maxium_position
120
-
121
- all_remain_fields_info.sort((a, b) ->
122
- return a.position - b.position
86
+ # filter removed fields and remain fields
87
+ all_fields.each((index, field_item) ->
88
+ _position = $(field_item).find(_positionTarget).val()
89
+ _is_removed = $(field_item).find(_option['removeField']).val()
90
+ if _is_removed == "false" || _is_removed == false
91
+ _is_removed = "false"
92
+ else
93
+ _is_removed = "true"
94
+
95
+ # removed fields should be filtered
96
+ # only unremoved fields will be sorted
97
+ if _is_removed == 'true'
98
+ all_removed_fields_info.push({
99
+ position: _position,
100
+ j_element: field_item
101
+ })
102
+ else
103
+ all_remain_fields_info.push({
104
+ position: _position,
105
+ j_element: field_item
106
+ })
123
107
  )
124
108
 
125
- # set remain fields position value as the acutal position in html page
126
- for field, key in all_remain_fields_info
127
- all_remain_fields_info[key].position = key + 1
109
+ # 1. go through sorted array to check if a field is of same position as previous fields
110
+ # 2. if so, update the position of later one as max position + 1
111
+ if all_remain_fields_info.length > 0
112
+
113
+ _tmp_remain_fields_info = all_remain_fields_info.slice()
114
+ for field, key in _tmp_remain_fields_info
115
+ current_position = field.position
116
+ for previous_field, previous_key in _tmp_remain_fields_info
117
+ tmp_position = previous_field.position
118
+ if tmp_position == current_position && previous_key < key
119
+ maxium_position += 1
120
+ all_remain_fields_info[key].position = maxium_position
121
+
122
+ all_remain_fields_info.sort((a, b) ->
123
+ return a.position - b.position
124
+ )
128
125
 
129
- _target = @target
130
- all_remain_fields_info.forEach((item, index) ->
131
- _target.append(item.j_element)
132
- )
126
+ # set remain fields position value as the acutal position in html page
127
+ for field, key in all_remain_fields_info
128
+ all_remain_fields_info[key].position = key + 1
133
129
 
134
- all_removed_fields_info.forEach((item, index) ->
135
- _target.append(item.j_element)
136
- )
130
+ _target = $(sub_target)
131
+ all_remain_fields_info.forEach((item, index) ->
132
+ _target.append(item.j_element)
133
+ )
134
+
135
+ all_removed_fields_info.forEach((item, index) ->
136
+ _target.append(item.j_element)
137
+ )
138
+ )
137
139
 
138
140
  calInitStepLable: ->
139
141
  this.calLabel(this.options['removeField']+'[value=false]')
@@ -147,33 +149,35 @@ class @SortableLabel
147
149
 
148
150
  calLabel: (target) ->
149
151
  _this = this
150
- stepCount = 1
151
- @target.find(target).each( ->
152
- if($(this).closest('.fields').find('.remove_nested_fields').data('association') == _this.options['fieldName'])
153
- if _this.options['minimun'] >= stepCount
154
- $(this).closest('.fields').find('.remove_nested_fields').hide();
155
- else
156
- $(this).closest('.fields').find('.remove_nested_fields').show();
157
- $(this).closest('.fields').find(_this.options['positionTarget']).val(stepCount)
158
- if typeof(_this.options['label']) == 'string'
159
- if _this.options['fieldName']
160
- if $(this).parent().find('.remove_nested_fields').data('association') == _this.options['fieldName']
161
- $(this).closest('.fields').find(_this.options['labelTarget']).html(_this.options['label'] + stepCount)
152
+ $(@target.selector).each(->
153
+ stepCount = 1
154
+ $(this).find(target).each( ->
155
+ if($(this).closest('.fields').find('.remove_nested_fields').data('association') == _this.options['fieldName'])
156
+ if _this.options['minimun'] >= stepCount
157
+ $(this).closest('.fields').find('.remove_nested_fields').hide();
162
158
  else
163
- alert("Field name can't be empty!")
164
- else if typeof(_this.options['label']) == 'function'
165
- $(this).closest('.fields').find(_this.options['labelTarget']).html(_this.options['label'].call($(this).closest('.fields').find(_this.options['labelTarget']), stepCount))
166
- else if _this.options['label'] == false
167
- if !$(this).closest('.fields').find(_this.options['labelTarget']).data('label')
168
- labelContent = $(this).closest('.fields').find(_this.options['labelTarget']).text()
169
- $(this).closest('.fields').find(_this.options['labelTarget']).data('label', labelContent)
170
- $(this).closest('.fields').find(_this.options['labelTarget']).html("#{$(this).closest('.fields').find(_this.options['labelTarget']).data('label')}")
171
- else
172
- if !$(this).closest('.fields').find(_this.options['labelTarget']).data('label')
173
- labelContent = $(this).closest('.fields').find(_this.options['labelTarget']).text()
174
- $(this).closest('.fields').find(_this.options['labelTarget']).data('label', labelContent)
175
- $(this).closest('.fields').find(_this.options['labelTarget']).html("#{$(this).closest('.fields').find(_this.options['labelTarget']).data('label')} #{stepCount}")
176
- stepCount += 1
159
+ $(this).closest('.fields').find('.remove_nested_fields').show();
160
+ $(this).closest('.fields').find(_this.options['positionTarget']).val(stepCount)
161
+ if typeof(_this.options['label']) == 'string'
162
+ if _this.options['fieldName']
163
+ if $(this).parent().find('.remove_nested_fields').data('association') == _this.options['fieldName']
164
+ $(this).closest('.fields').find(_this.options['labelTarget']).html(_this.options['label'] + stepCount)
165
+ else
166
+ alert("Field name can't be empty!")
167
+ else if typeof(_this.options['label']) == 'function'
168
+ $(this).closest('.fields').find(_this.options['labelTarget']).html(_this.options['label'].call($(this).closest('.fields').find(_this.options['labelTarget']), stepCount))
169
+ else if _this.options['label'] == false
170
+ if !$(this).closest('.fields').find(_this.options['labelTarget']).data('label')
171
+ labelContent = $(this).closest('.fields').find(_this.options['labelTarget']).text()
172
+ $(this).closest('.fields').find(_this.options['labelTarget']).data('label', labelContent)
173
+ $(this).closest('.fields').find(_this.options['labelTarget']).html("#{$(this).closest('.fields').find(_this.options['labelTarget']).data('label')}")
174
+ else
175
+ if !$(this).closest('.fields').find(_this.options['labelTarget']).data('label')
176
+ labelContent = $(this).closest('.fields').find(_this.options['labelTarget']).text()
177
+ $(this).closest('.fields').find(_this.options['labelTarget']).data('label', labelContent)
178
+ $(this).closest('.fields').find(_this.options['labelTarget']).html("#{$(this).closest('.fields').find(_this.options['labelTarget']).data('label')} #{stepCount}")
179
+ stepCount += 1
180
+ )
177
181
  )
178
182
  if typeof(@stop_callback) == 'function'
179
183
  @stop_callback.call(@target)
@@ -181,31 +185,33 @@ class @SortableLabel
181
185
  calWeekGroupLabel: (target) ->
182
186
  _this = this
183
187
  week_group_label_list = []
184
- @target.find(target).each(->
185
- tempLabel = $(this).closest('.fields').find('.workout_workout_weeks_workout_week_group_id select').find(":selected").text()
186
- if $(this).closest('.fields').find('.workout_workout_weeks_workout_week_group_id select').find(":selected").val() != ""
187
- _index = _this.isIncludeWeekGroup(tempLabel, week_group_label_list)
188
- if _index is -1
189
- week_group_label_list.push(
190
- name: tempLabel,
191
- count: 1
192
- )
193
- if typeof _this.options['subPositionTarget'] == 'string'
194
- $(this).closest('.fields').find(_this.options['subPositionTarget']).val(1)
195
- if typeof _this.options['groupLabel'] == 'string'
196
- $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel + " " + _this.options['groupLabel'] + " 1")
197
- else
198
- $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel)
199
- else if _index > -1
200
- week_group_label_list[_index].count += 1
201
- if typeof _this.options['subPositionTarget'] == 'string'
202
- $(this).closest('.fields').find(_this.options['subPositionTarget']).val(week_group_label_list[_index].count)
203
- if typeof _this.options['groupLabel'] == 'string'
204
- $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel + " " + _this.options['groupLabel'] + " " + week_group_label_list[_index].count)
205
- else
206
- $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel)
207
- else
208
- $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>")
188
+ $(@target.selector).each(->
189
+ $(this).find(target).each(->
190
+ tempLabel = $(this).closest('.fields').find('.workout_workout_weeks_workout_week_group_id select').find(":selected").text()
191
+ if $(this).closest('.fields').find('.workout_workout_weeks_workout_week_group_id select').find(":selected").val() != ""
192
+ _index = _this.isIncludeWeekGroup(tempLabel, week_group_label_list)
193
+ if _index is -1
194
+ week_group_label_list.push(
195
+ name: tempLabel,
196
+ count: 1
197
+ )
198
+ if typeof _this.options['subPositionTarget'] == 'string'
199
+ $(this).closest('.fields').find(_this.options['subPositionTarget']).val(1)
200
+ if typeof _this.options['groupLabel'] == 'string'
201
+ $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel + " " + _this.options['groupLabel'] + " 1")
202
+ else
203
+ $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel)
204
+ else if _index > -1
205
+ week_group_label_list[_index].count += 1
206
+ if typeof _this.options['subPositionTarget'] == 'string'
207
+ $(this).closest('.fields').find(_this.options['subPositionTarget']).val(week_group_label_list[_index].count)
208
+ if typeof _this.options['groupLabel'] == 'string'
209
+ $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel + " " + _this.options['groupLabel'] + " " + week_group_label_list[_index].count)
210
+ else
211
+ $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel)
212
+ else
213
+ $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>")
214
+ )
209
215
  )
210
216
 
211
217
  isIncludeWeekGroup: (item, arr)->
@@ -217,6 +223,5 @@ class @SortableLabel
217
223
 
218
224
  (($) ->
219
225
  $.fn.sortableLabel = (options) ->
220
- this.each ->
221
- new SortableLabel(this, options)
226
+ new SortableLabel(this, options)
222
227
  )(jQuery)
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sortablelabel-js
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: '2.0'
5
5
  platform: ruby
6
6
  authors:
7
- - Joe
7
+ - BenZhang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-04 00:00:00.000000000 Z
11
+ date: 2018-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.15'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.15'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -54,7 +40,7 @@ dependencies:
54
40
  version: '3.0'
55
41
  description: Sortable label plugin for the project
56
42
  email:
57
- - ashzhouyue@gmail.com
43
+ - bzbnhang@gmail.com
58
44
  executables: []
59
45
  extensions: []
60
46
  extra_rdoc_files: []