sortablelabel-js 1.9.1 → 2.0
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 -2
- data/lib/sortablelabel/js/version.rb +1 -1
- data/sortablelabel-js.gemspec +2 -3
- data/vendor/assets/javascripts/sortable_label.coffee +130 -125
- metadata +4 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 076c2fc366c4647abbd5651a889adbcc9056f12b
|
4
|
+
data.tar.gz: 707d95a4fe9752e837a30b385c9e79ec2821fc85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 (
|
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!
|
data/sortablelabel-js.gemspec
CHANGED
@@ -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 = ["
|
10
|
-
spec.email = ["
|
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 =
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
_position
|
73
|
-
|
74
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
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
|
-
#
|
126
|
-
|
127
|
-
|
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
|
-
|
130
|
-
|
131
|
-
|
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
|
-
|
135
|
-
|
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
|
-
|
151
|
-
|
152
|
-
|
153
|
-
if _this.options['
|
154
|
-
|
155
|
-
|
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
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
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.
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
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
|
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:
|
4
|
+
version: '2.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- BenZhang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
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
|
-
-
|
43
|
+
- bzbnhang@gmail.com
|
58
44
|
executables: []
|
59
45
|
extensions: []
|
60
46
|
extra_rdoc_files: []
|