sortablelabel-js 1.1 → 1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c8988a5febbb6a36eef8f2abb7147e41b128e89
4
- data.tar.gz: eaba667569867cd97aeeee6f232c8b7191825f5f
3
+ metadata.gz: b7deccf7a6fdb6dd6a39a7d32c168b48aae562b2
4
+ data.tar.gz: 849222eeb0d982cdf5bcd50a199d16f2b941209e
5
5
  SHA512:
6
- metadata.gz: 4e1dd6a2b5f72f3687c0d872d2d7c9d73f71440e70dad22c6c598fc81ea781dc0d074579538e1d4d1622a81a47af2c4aedce3f7735aa0e2512d4399f6ca0f65e
7
- data.tar.gz: c5c8ad24134d2620a74f15bb678b099d110dbbb368ed81b4bd5028e2eaa799a3092e41c00fb41c5fe99976919e9b2b2fd2412c6f65eb53ebc1eba16ce2ad08d4
6
+ metadata.gz: 5500f3041bbb7d4aa87ac3d2972caeb5308f66df4e18468451626f8a4bdfcb04970114687bc5113d310c9ba0a4bff96d55938f14028f23809cc5bef8ade7fbae
7
+ data.tar.gz: 719a82ab093534fc6ca30216c04eaff27aa2957a2e8b9dedf0df7516664aec5e56b49f35cc0e30fcbf9bbfcf89a2b8fd1c60e2a97d760e5a99929e2a870a5652
@@ -1,5 +1,5 @@
1
1
  module Sortablelabel
2
2
  module Js
3
- VERSION = "1.1"
3
+ VERSION = "1.2"
4
4
  end
5
5
  end
@@ -14,6 +14,7 @@ class @SortableLabel
14
14
  @target = scope
15
15
  @targetId = @options['fieldName'] || @target.attr('id')
16
16
  @stop_callback = @options["stop"]
17
+ @initSortByPosition()
17
18
  @calInitStepLable()
18
19
 
19
20
  $(document).on("nested:fieldAdded:#{@targetId}", (event) =>
@@ -41,12 +42,50 @@ class @SortableLabel
41
42
  $(this).find('.ui-state-highlight').css('height', $(ui.item).css('height'))
42
43
  stop: =>
43
44
  @calStepLable()
45
+ if typeof(@stop_callback) == 'function'
46
+ @stop_callback()
44
47
  )
45
48
 
46
49
  @target.on('sortableLabel:disable', =>
47
50
  @target.sortable('disable')
48
51
  )
49
52
 
53
+ # 1. ascending sort if all position fields are not provided
54
+ # 2. ascending sort field elements which part of them are no provided position
55
+ initSortByPosition: () ->
56
+ all_fields = $(@target).find(@options['sortableItem'])
57
+ _positionTarget = @options['positionTarget']
58
+ all_fields_info = []
59
+ maxium_position = 1
60
+
61
+ if all_fields.length > 0
62
+ all_fields.each((index, field_item) ->
63
+ _position = $(field_item).find(_positionTarget).val()
64
+ if _position && _position != '' && typeof _position != 'undefined'
65
+ _position = parseInt(_position, 10)
66
+ if _position >= maxium_position
67
+ maxium_position = _position
68
+ )
69
+ all_fields.each((index, field_item) ->
70
+ _position = parseInt($(field_item).find(_positionTarget).val(), 10)
71
+ if typeof(_position) == 'undefined'
72
+ _position = maxium_position
73
+ maxium_position += 1
74
+ all_fields_info.push({
75
+ position: _position,
76
+ j_element: field_item
77
+ })
78
+ )
79
+
80
+ if all_fields_info.length > 0
81
+ all_fields_info.sort((a, b) ->
82
+ return a.position - b.position
83
+ )
84
+ _target = @target
85
+ all_fields_info.forEach((item, index) ->
86
+ _target.append(item.j_element)
87
+ )
88
+
50
89
  calInitStepLable: ->
51
90
  this.calLabel(this.options['removeField']+'[value=false]')
52
91
  if this.options['weekGroupLabelTarget']
@@ -85,6 +124,7 @@ class @SortableLabel
85
124
  if typeof(@stop_callback) == 'function'
86
125
  @stop_callback();
87
126
 
127
+
88
128
  calWeekGroupLabel: (target) ->
89
129
  _this = this
90
130
  week_group_label_list = []
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.1'
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-19 00:00:00.000000000 Z
11
+ date: 2018-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler