@finqu/cool 1.2.8 → 1.2.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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Cool UI tooltip.js v1.2.7 (https://finqu.fi)
2
+ * Cool UI tooltip.js v1.2.8 (https://finqu.fi)
3
3
  * Copyright 2011-2020 Finqu Oy
4
4
  * Licensed under the ISC license - (http://opensource.org/licenses/ISC)
5
5
  */
package/js/src/select.js CHANGED
@@ -135,7 +135,7 @@ class Select extends AbstractUIComponent {
135
135
  this.preventClose = false;
136
136
 
137
137
  if (this.itemsToExclude.length > 0) {
138
- this.itemsToExclude = this.itemsToExclude.map(Number);
138
+ this.itemsToExclude = this.itemsToExclude.map(String);
139
139
  }
140
140
 
141
141
  if (this.opts.setData) {
@@ -146,17 +146,46 @@ class Select extends AbstractUIComponent {
146
146
  this.data = this.$el.data('setData');
147
147
  }
148
148
 
149
- if (this.data[this.name] !== 'undefined' && this.data[this.name].length > 0 && self.itemsToExclude) {
149
+ // Convert data to be array so filters doesn't fail
150
+ if (!Array.isArray(this.data[this.name]) && this.data[this.name] !== '' && this.data[this.name].length > 0) {
151
+
152
+ const arr = this.data[this.name].toString().trim().split(',');
153
+
154
+ this.data[this.name] = arr;
155
+ }
156
+
157
+ // Convert all values to string format to make filtering more simple
158
+ if (this.data[this.name].length > 0) {
159
+ this.data[this.name] = this.data[this.name].map(String);
160
+ }
161
+
162
+ if (this.data[this.name].length > 0 && this.itemsToExclude.length > 0) {
150
163
 
151
164
  this.data[this.name] = this.data[this.name].filter(function(item) {
152
- return self.itemsToExclude.indexOf(parseInt(item.id, 10)) === -1;
165
+
166
+ if (item[self.primaryKeyword]) {
167
+
168
+ return self.itemsToExclude.indexOf(item[self.primaryKeyword].toString()) === -1;
169
+
170
+ } else {
171
+
172
+ return self.itemsToExclude.indexOf(item.toString()) === -1;
173
+ }
153
174
  });
154
175
  }
155
176
 
156
- if (this.items !== 'undefined' && this.items.lengths > 0 && self.itemsToExclude) {
177
+ if (this.items.length > 0 && this.itemsToExclude.length > 0) {
157
178
 
158
179
  this.items = this.items.filter(function(item) {
159
- return self.itemsToExclude.indexOf(parseInt(item.id, 10)) === -1;
180
+
181
+ if (item[self.primaryKeyword]) {
182
+
183
+ return self.itemsToExclude.indexOf(item[self.primaryKeyword].toString()) === -1;
184
+
185
+ } else {
186
+
187
+ return self.itemsToExclude.indexOf(item.toString()) === -1;
188
+ }
160
189
  });
161
190
  }
162
191
 
@@ -199,6 +228,20 @@ class Select extends AbstractUIComponent {
199
228
 
200
229
  } else {
201
230
 
231
+ const selectItems = this.$select.find('.select-item');
232
+
233
+ if (selectItems.length > 0 && this.itemsToExclude.length > 0) {
234
+
235
+ $.each(selectItems, (i, el) => {
236
+
237
+ const val = $(el).find(':input').val();
238
+
239
+ if (self.itemsToExclude.indexOf(val) > -1) {
240
+ $(el).remove();
241
+ }
242
+ });
243
+ }
244
+
202
245
  secondaryResolve();
203
246
  }
204
247
 
@@ -423,7 +466,7 @@ class Select extends AbstractUIComponent {
423
466
 
424
467
  if (this.checked) {
425
468
 
426
- self.data[self.name] = val;
469
+ self.data[self.name] = [val];
427
470
  self.$select.find('input[type="radio"]').not($(this)).prop('checked', false);
428
471
  self.$select.find('input[type="radio"]').not($(this)).removeClass('checked');
429
472
 
@@ -579,12 +622,12 @@ class Select extends AbstractUIComponent {
579
622
  });
580
623
 
581
624
  let itemIds = items.map(item => {
582
- return parseInt(item.id, 10);
625
+ return item.id.toString()
583
626
  });
584
627
 
585
628
  // Remove value from data if it doesn't exist anymore
586
629
  self.data[self.name] = self.data[self.name].filter(function(value) {
587
- return itemIds.indexOf(parseInt(value, 10)) > -1;
630
+ return itemIds.indexOf(value.toString()) > -1;
588
631
  });
589
632
 
590
633
  if (self.data[self.name].length == 0) {
@@ -592,7 +635,7 @@ class Select extends AbstractUIComponent {
592
635
  }
593
636
 
594
637
  items = items.filter(function(item) {
595
- return self.data[self.name].indexOf(item.id) > -1 && self.itemsToExclude.indexOf(parseInt(item.id, 10)) === -1 && parseInt(item.id, 10) > 0;
638
+ return self.data[self.name].indexOf(item.id) > -1 && self.itemsToExclude.indexOf(item.id) === -1 && item.id != 0;
596
639
  });
597
640
 
598
641
  let result = self._renderItemList(items);
@@ -624,7 +667,9 @@ class Select extends AbstractUIComponent {
624
667
 
625
668
  self.data[self.name].forEach(function(value) {
626
669
 
627
- let $input = $inputs.filter(function() { return this.value == value });
670
+ let $input = $inputs.filter(function() {
671
+ return this.value == value;
672
+ });
628
673
 
629
674
  $input.prop('checked', true);
630
675
 
@@ -633,7 +678,9 @@ class Select extends AbstractUIComponent {
633
678
 
634
679
  } else if (self.type == 'radio') {
635
680
 
636
- let $input = $inputs.filter(function() { return this.value == self.data[self.name] });
681
+ let $input = $inputs.filter(function() {
682
+ return this.value == self.data[self.name][0];
683
+ });
637
684
 
638
685
  $input.prop('checked', true);
639
686
  $input.addClass('checked');
@@ -652,11 +699,11 @@ class Select extends AbstractUIComponent {
652
699
  // Remove value from data if it doesn't exist anymore
653
700
  let $inputs = this.$scrollableContent.find(':input');
654
701
  let inputValues = $inputs.length > 0 ? $inputs.map(function() {
655
- return parseInt(this.value, 10);
702
+ return this.value.toString();
656
703
  }).get() : [];
657
704
 
658
705
  this.data[this.name] = this.data[this.name].filter(function(value) {
659
- return inputValues.indexOf(parseInt(value, 10)) > -1;
706
+ return inputValues.indexOf(value.toString()) > -1;
660
707
  });
661
708
 
662
709
  if (this.data[this.name].length == 0) {
@@ -685,7 +732,7 @@ class Select extends AbstractUIComponent {
685
732
  } else if (this.type == 'radio') {
686
733
 
687
734
  let $input = $inputs.filter(function() {
688
- return this.value == self.data[self.name]
735
+ return this.value == self.data[self.name][0];
689
736
  });
690
737
 
691
738
  $input.prop('checked', true);
@@ -731,7 +778,7 @@ class Select extends AbstractUIComponent {
731
778
  });
732
779
 
733
780
  items = items.filter(function(item) {
734
- return self.data[self.name].indexOf(item.id) === -1 && self.itemsToExclude.indexOf(parseInt(item.id, 10)) === -1 && parseInt(item.id, 10) > 0;
781
+ return self.data[self.name].indexOf(item.id) === -1 && self.itemsToExclude.indexOf(item.id) === -1 && item.id != 0;
735
782
  });
736
783
 
737
784
  let result = self._renderItemList(items);
@@ -914,7 +961,7 @@ class Select extends AbstractUIComponent {
914
961
  }
915
962
 
916
963
  items = items.filter(function(item) {
917
- return self.itemsToExclude.indexOf(parseInt(item.id, 10)) === -1;
964
+ return self.itemsToExclude.indexOf(item[self.primaryKeyword].toString()) === -1;
918
965
  });
919
966
 
920
967
  items.forEach(item => {
@@ -942,7 +989,7 @@ class Select extends AbstractUIComponent {
942
989
  items.forEach(item => {
943
990
 
944
991
  let $input = this.$select.find(':input').filter(function() { return this.value == item.id });
945
- let val = parseInt($input.val(), 10);
992
+ let val = $input.val().toString();
946
993
 
947
994
  $input.prop('checked', true);
948
995
 
@@ -954,7 +1001,7 @@ class Select extends AbstractUIComponent {
954
1001
 
955
1002
  let item = items[0];
956
1003
  let $input = this.$select.find(':input').filter(function() { return this.value == item.id });
957
- let val = parseInt($input.val(), 10);
1004
+ let val = $input.val().toString();
958
1005
 
959
1006
  $input.prop('checked', true);
960
1007
  $input.addClass('checked');
@@ -1039,11 +1086,11 @@ class Select extends AbstractUIComponent {
1039
1086
  ids = data;
1040
1087
  }
1041
1088
 
1042
- ids = ids.map(Number);
1089
+ ids = ids.map(String);
1043
1090
 
1044
1091
  if (this.items.length > 0) {
1045
1092
 
1046
- result = $.grep(this.items, function(item) { return ids.indexOf(parseInt(item.id, 10)) > -1 });
1093
+ result = $.grep(this.items, function(item) { return ids.indexOf(item.id.toString()) > -1 });
1047
1094
 
1048
1095
  if (segment) {
1049
1096
 
@@ -1078,11 +1125,11 @@ class Select extends AbstractUIComponent {
1078
1125
  ids = data;
1079
1126
  }
1080
1127
 
1081
- ids = ids.map(Number);
1128
+ ids = ids.map(String);
1082
1129
 
1083
1130
  if (this.items.length > 0) {
1084
1131
 
1085
- result = $.grep(this.items, function(item) { return ids.indexOf(parseInt(item.id, 10)) > -1 });
1132
+ result = $.grep(this.items, function(item) { return ids.indexOf(item.id.toString()) > -1 });
1086
1133
 
1087
1134
  if (segment) {
1088
1135
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finqu/cool",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "description": "Finqu UI package",
5
5
  "main": "index.js",
6
6
  "scripts": {