sortablelabel-js 1.8 → 1.9

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: dd140d8c78c8c5ec6b07643731ea9db19fd509f7
4
- data.tar.gz: 58ac02c4f8aab9fdb91655100b02cf180133b5d7
3
+ metadata.gz: 1bb7a7fa39fff37569ea2e00f4d8eab9b31ae988
4
+ data.tar.gz: 9fc7830ed4c3c48415abd28df2d3724a5acd375a
5
5
  SHA512:
6
- metadata.gz: 78556bfef0d2378e61b9e78582b2a69d2b3851cd078fb1e73af3182fc5637c3d21181628b454107f7b915228b564a289769dbc72a0ecd7a243e7fd1a62214cd0
7
- data.tar.gz: f05e5ec98f37ef761f5c559b288688730d8346d677f6a0bcdb9a1e5bff047f96bf6bc6fb2f97e53fa275886d79c93f083456abba7996e5e064e51557941fdcc0
6
+ metadata.gz: 8b76e80d344d19730065c1c09a90c74c9e1685954c7c951132f1bad54d22963ae93ca82ffc8a08f65d7e1c74398c468d94f37434d43b291652260a2d7c9d4a6b
7
+ data.tar.gz: db512355f3e989e8ca0ed142e182f77957f28f32f6ebfbcd76575108b5d834629b93f9aa0055c427c961a5711fcb5302ac1bf85aa936c5cfaee95a88a3cbec51
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sortablelabel-js (1.8)
4
+ sortablelabel-js (1.9)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,5 +1,5 @@
1
1
  module Sortablelabel
2
2
  module Js
3
- VERSION = "1.8"
3
+ VERSION = "1.9"
4
4
  end
5
5
  end
@@ -11,12 +11,12 @@ 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()
18
18
  @calInitStepLable()
19
- if $(".sortable-label-#{@targetId}").size == 0
19
+ if $(".sortable-label-#{@targetId}").size() == 0
20
20
  $(document).on("nested:fieldAdded:#{@targetId}", (event) =>
21
21
  @calStepLable()
22
22
  if @options['nestedTarget']
@@ -57,85 +57,83 @@ 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
- @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
- )
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
+ )
77
76
 
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
- )
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
+ )
85
84
 
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
- })
107
- )
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
+ )
108
107
 
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
- )
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
123
+ )
125
124
 
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
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
129
128
 
130
- _target = $(sub_target)
131
- all_remain_fields_info.forEach((item, index) ->
132
- _target.append(item.j_element)
133
- )
129
+ _target = @target
130
+ all_remain_fields_info.forEach((item, index) ->
131
+ _target.append(item.j_element)
132
+ )
134
133
 
135
- all_removed_fields_info.forEach((item, index) ->
136
- _target.append(item.j_element)
137
- )
138
- )
134
+ all_removed_fields_info.forEach((item, index) ->
135
+ _target.append(item.j_element)
136
+ )
139
137
 
140
138
  calInitStepLable: ->
141
139
  this.calLabel(this.options['removeField']+'[value=false]')
@@ -149,35 +147,33 @@ class @SortableLabel
149
147
 
150
148
  calLabel: (target) ->
151
149
  _this = this
152
- $(@target).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();
158
- else
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')}")
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)
174
162
  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
- )
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
181
177
  )
182
178
  if typeof(@stop_callback) == 'function'
183
179
  @stop_callback();
@@ -186,33 +182,31 @@ class @SortableLabel
186
182
  calWeekGroupLabel: (target) ->
187
183
  _this = this
188
184
  week_group_label_list = []
189
- $(@target).each(->
190
- $(this).find(target).each(->
191
- tempLabel = $(this).closest('.fields').find('.workout_workout_weeks_workout_week_group_id select').find(":selected").text()
192
- if $(this).closest('.fields').find('.workout_workout_weeks_workout_week_group_id select').find(":selected").val() != ""
193
- _index = _this.isIncludeWeekGroup(tempLabel, week_group_label_list)
194
- if _index is -1
195
- week_group_label_list.push(
196
- name: tempLabel,
197
- count: 1
198
- )
199
- if typeof _this.options['subPositionTarget'] == 'string'
200
- $(this).closest('.fields').find(_this.options['subPositionTarget']).val(1)
201
- if typeof _this.options['groupLabel'] == 'string'
202
- $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel + " " + _this.options['groupLabel'] + " 1")
203
- else
204
- $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel)
205
- else if _index > -1
206
- week_group_label_list[_index].count += 1
207
- if typeof _this.options['subPositionTarget'] == 'string'
208
- $(this).closest('.fields').find(_this.options['subPositionTarget']).val(week_group_label_list[_index].count)
209
- if typeof _this.options['groupLabel'] == 'string'
210
- $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel + " " + _this.options['groupLabel'] + " " + week_group_label_list[_index].count)
211
- else
212
- $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel)
213
- else
214
- $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>")
215
- )
185
+ @target.find(target).each(->
186
+ tempLabel = $(this).closest('.fields').find('.workout_workout_weeks_workout_week_group_id select').find(":selected").text()
187
+ if $(this).closest('.fields').find('.workout_workout_weeks_workout_week_group_id select').find(":selected").val() != ""
188
+ _index = _this.isIncludeWeekGroup(tempLabel, week_group_label_list)
189
+ if _index is -1
190
+ week_group_label_list.push(
191
+ name: tempLabel,
192
+ count: 1
193
+ )
194
+ if typeof _this.options['subPositionTarget'] == 'string'
195
+ $(this).closest('.fields').find(_this.options['subPositionTarget']).val(1)
196
+ if typeof _this.options['groupLabel'] == 'string'
197
+ $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel + " " + _this.options['groupLabel'] + " 1")
198
+ else
199
+ $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel)
200
+ else if _index > -1
201
+ week_group_label_list[_index].count += 1
202
+ if typeof _this.options['subPositionTarget'] == 'string'
203
+ $(this).closest('.fields').find(_this.options['subPositionTarget']).val(week_group_label_list[_index].count)
204
+ if typeof _this.options['groupLabel'] == 'string'
205
+ $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel + " " + _this.options['groupLabel'] + " " + week_group_label_list[_index].count)
206
+ else
207
+ $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>" + tempLabel)
208
+ else
209
+ $(this).html("<i class='fa fa-trophy fa-fw small-opacity-30'></i>")
216
210
  )
217
211
 
218
212
  isIncludeWeekGroup: (item, arr)->
@@ -224,5 +218,6 @@ class @SortableLabel
224
218
 
225
219
  (($) ->
226
220
  $.fn.sortableLabel = (options) ->
227
- new SortableLabel(this, options)
221
+ this.each ->
222
+ new SortableLabel(this, options)
228
223
  )(jQuery)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sortablelabel-js
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.8'
4
+ version: '1.9'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-02 00:00:00.000000000 Z
11
+ date: 2018-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler