sortablelabel-js 1.8 → 1.9
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/sortablelabel/js/version.rb +1 -1
- data/vendor/assets/javascripts/sortable_label.coffee +126 -131
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bb7a7fa39fff37569ea2e00f4d8eab9b31ae988
|
4
|
+
data.tar.gz: 9fc7830ed4c3c48415abd28df2d3724a5acd375a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b76e80d344d19730065c1c09a90c74c9e1685954c7c951132f1bad54d22963ae93ca82ffc8a08f65d7e1c74398c468d94f37434d43b291652260a2d7c9d4a6b
|
7
|
+
data.tar.gz: db512355f3e989e8ca0ed142e182f77957f28f32f6ebfbcd76575108b5d834629b93f9aa0055c427c961a5711fcb5302ac1bf85aa936c5cfaee95a88a3cbec51
|
data/Gemfile.lock
CHANGED
@@ -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.
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
127
|
-
|
128
|
-
|
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
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
129
|
+
_target = @target
|
130
|
+
all_remain_fields_info.forEach((item, index) ->
|
131
|
+
_target.append(item.j_element)
|
132
|
+
)
|
134
133
|
|
135
|
-
|
136
|
-
|
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
|
-
|
153
|
-
|
154
|
-
$(this).find(
|
155
|
-
if
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
if
|
162
|
-
if _this.options['fieldName']
|
163
|
-
|
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
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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
|
-
|
190
|
-
$(this).find(
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2018-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|