combo_auto_box 0.0.46 → 0.0.47

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: 5af9caeb5d78d81019092949042011a646faf5c5
4
- data.tar.gz: 7031b14882d8f883ec02e1c204b4a0cd5647c28d
3
+ metadata.gz: 4a7ba4f09b36010bff6315cf2ac481b9b508fd4d
4
+ data.tar.gz: a11a890140331919ebc7e3ef2c8807a2de9548ed
5
5
  SHA512:
6
- metadata.gz: a52f191f98febc10cb8e80e62510ff333a1c476c3ceb9034f5b001f2dbc30e2a67970aba2a5d60d3df36e8b63e0093dd2f07915f4dffb85d34e8ba96c1fa7421
7
- data.tar.gz: 63eef0bde0f95eff096a0b6512697bd8251c09c7e81d321f2ec9fce847017146f6f05905106dd307894385a643a086a63fe0093cb5361bf73d59dc7ed86e6e8e
6
+ metadata.gz: 07fe55149157d253a0a38ad7af403cac8fe1a8ab108601ac5e2e7d79a56addae147e1a0c3dcba99090f4e140bb9da1b0bb8e72d11c4da528b20f7622ac6dd791
7
+ data.tar.gz: c292b9a2c684367c73b9ecb23e0c1f878795c139cc275014c480d02464b48833a6568083a34b4230f519457904e4b66b7afd7dde5481f769dc018742e860d835
@@ -1,3 +1,3 @@
1
1
  module ComboAutoBox
2
- VERSION = '0.0.46'
2
+ VERSION = '0.0.47'
3
3
  end
@@ -20,6 +20,32 @@ var ComboAutoBox = {
20
20
 
21
21
  return prefix + "-" + now;
22
22
  };
23
+
24
+ var splitValidEmails = function (inputId, inputValue) {
25
+ if ((options.type != 'multiple') || (!options.email)) {
26
+ return false;
27
+ }
28
+
29
+ var emails = inputValue.split(/[\,\s\;]+/);
30
+ for (var i = 0; i < emails.length; i++) {
31
+ if (!emails[i].match(/[^@\s]+@([^@\s]+\.)+[^@\s]+/)) {
32
+ return false;
33
+ }
34
+ }
35
+
36
+ $('#' + inputId).autocomplete( "close" );
37
+ if ((options.source_not_found) && (!options.not_found_accepted)) {
38
+ selectData('', '');
39
+ } else {
40
+ for (var i = 0; i < emails.length; i++) {
41
+ addMultipleItem(inputId, emails[i], emails[i]);
42
+ selectData(emails[i], emails[i]);
43
+ }
44
+ }
45
+ $('#' + inputId).val('');
46
+
47
+ return true;
48
+ }
23
49
 
24
50
  // binds autocomplete to text field
25
51
  var bindAutoComplete = function (inputId) {
@@ -52,9 +78,32 @@ var ComboAutoBox = {
52
78
  }
53
79
 
54
80
  });
55
-
81
+
82
+ // CTRL+V or CMD+V
83
+ $('#' + inputId).bind('paste', function() {
84
+ var $this = $(this);
85
+ setTimeout(function(){
86
+ splitValidEmails(inputId, $this.val());
87
+ }, 20); //just break the callstack to let the event finish
88
+
89
+ });
90
+
56
91
  $('#' + inputId).keypress(function(e) {
57
- if ((e.which === 13) && ($('#' + inputId).val() != '')) {
92
+ // 44 is "," - 32 is SPACE - 59 is ";"
93
+ if (((e.which === 32) || (e.which === 44) || (e.which === 59)) && (options.type == 'multiple') && (options.email) && ($('#' + inputId).val().match(/[^@\s]+@([^@\s]+\.)+[^@\s]+/))) {
94
+ $('#' + inputId).autocomplete( "close" );
95
+ if ((options.source_not_found) && (!options.not_found_accepted)) {
96
+ $('#' + inputId).val('');
97
+ } else {
98
+ addMultipleItem(inputId, $('#' + inputId).val(), $('#' + inputId).val());
99
+ }
100
+ selectData($('#' + inputId).val(), $('#' + inputId).val());
101
+
102
+ setTimeout(function(){
103
+ $('#' + inputId).val('');
104
+ }, 20);
105
+
106
+ } else if ((e.which === 13) && ($('#' + inputId).val() != '')) {
58
107
  if (options.type == 'full') {
59
108
  $('#' + inputId).autocomplete( "close" );
60
109
  selectData($('#' + inputId).val(), $('#' + inputId).val());
@@ -67,9 +116,9 @@ var ComboAutoBox = {
67
116
  } else if (options.type == 'multiple') {
68
117
  $('#' + inputId).autocomplete( "close" );
69
118
  if ((options.source_not_found) && (!options.not_found_accepted)) {
70
- $('#' + inputId).val('');
119
+ $('#' + inputId).val('');
71
120
  } else {
72
- addMultipleItem(inputId, $('#' + inputId).val(), $('#' + inputId).val());
121
+ addMultipleItem(inputId, $('#' + inputId).val(), $('#' + inputId).val());
73
122
  }
74
123
  selectData($('#' + inputId).val(), $('#' + inputId).val());
75
124
  $('#' + inputId).val('');
@@ -454,6 +503,40 @@ var ComboAutoBox = {
454
503
 
455
504
  return '<div class="' + klass + '">' + generateInputTag() + '</div>';
456
505
  };
506
+
507
+ var disableSelectionIfAlreadySelected = function() {
508
+ if (options.bootstrap) {
509
+ disableSelectionIfAlreadySelectedBootstrap();
510
+ } else {
511
+ disableSelectionIfAlreadySelectedSimple();
512
+ }
513
+ }
514
+
515
+ var disableSelectionIfAlreadySelectedBootstrap = function() {
516
+ var selecteds = $("div#" + container + " > div.container-combo-auto-box-bootstrap > div.item > input[type='hidden']").map(function(k, v) { return $(this).val() });
517
+
518
+ $("div#" + container + " > div.modal > div.modal-dialog > div.modal-content > div.modal-body > div.list-group > a").each(function(index) {
519
+ var item = $(this).children('span.combo-auto-box-item-id').text();
520
+ $(this).removeClass('selected');
521
+ if ($.inArray(item, selecteds) >= 0) { // IF exists in array
522
+ $(this).addClass('selected');
523
+ } else {
524
+ }
525
+ });
526
+ }
527
+
528
+ var disableSelectionIfAlreadySelectedSimple = function() {
529
+ var selecteds = $("div#" + container + " > div.container-combo-auto-box > div.item > input[type='hidden']").map(function(k, v) { return $(this).val() });
530
+
531
+ $('#' + options.modalId + ' > div.list > ul > li').each(function(index) {
532
+ var item = $(this).children('span.combo-auto-box-item-id').text();
533
+ $(this).removeClass('selected');
534
+ if ($.inArray(item, selecteds) >= 0) { // IF exists in array
535
+ $(this).addClass('selected');
536
+ } else {
537
+ }
538
+ });
539
+ }
457
540
 
458
541
  // dialog modal
459
542
  var generateDivDialogModal = function (modalDialogId) {
@@ -489,6 +572,8 @@ var ComboAutoBox = {
489
572
  $("#" + modalDialogId).siblings('div.ui-dialog-titlebar').remove();
490
573
 
491
574
  $('#' + container + ' > div.container-combo-auto-box > span.' + options.type).click(function() {
575
+ disableSelectionIfAlreadySelected();
576
+
492
577
  openModalDialog(modalDialogId)
493
578
  });
494
579
 
@@ -529,6 +614,8 @@ var ComboAutoBox = {
529
614
  getListForModalDialog(modalDialogId);
530
615
 
531
616
  $(targetObject).click(function() {
617
+ disableSelectionIfAlreadySelected();
618
+
532
619
  $('#' + modalDialogId).modal('show');
533
620
 
534
621
  // fix to allways show back-shadow
@@ -596,6 +683,10 @@ var ComboAutoBox = {
596
683
  $('#' + modalDialogId + ' > div.list').css('height', ($('#' + modalDialogId).dialog("option", "height") - 90) + 'px');
597
684
  $('#' + modalDialogId + ' > div.list > ul').html(items.join(''));
598
685
  $('#' + modalDialogId + ' > div.list > ul > li').click(function() {
686
+ if ($(this).hasClass('selected')) {
687
+ return false;
688
+ }
689
+
599
690
  var thisId = $(this).children('span.combo-auto-box-item-id').text();
600
691
  var thisLabel = $(this).children('span.combo-auto-box-item-label').text();
601
692
 
@@ -617,11 +708,15 @@ var ComboAutoBox = {
617
708
  var items = [];
618
709
 
619
710
  $.each(data, function(index){
620
- items.push('<a href="javascript:void(0);" class="list-group-item"><span class="combo-auto-box-item-id" style="display:none;">' + data[index].id +'</span><span class="combo-auto-box-item-label">'+ data[index].label + '</span></a>');
711
+ items.push('<a href="javascript:void(0);" class="list-group-item"><span class="combo-auto-box-item-id" style="display:none;">' + data[index].id +'</span><span class="combo-auto-box-item-label">'+ data[index].label + '</span></a>');
621
712
  });
622
713
 
623
714
  $('#' + modalDialogId + ' > div.modal-dialog > div.modal-content > div.modal-body > div.list-group').html(items.join(''));
624
715
  $('#' + modalDialogId + ' > div.modal-dialog > div.modal-content > div.modal-body > div.list-group > a').click(function() {
716
+ if ($(this).hasClass('selected')) {
717
+ return false;
718
+ }
719
+
625
720
  var thisId = $(this).children('span.combo-auto-box-item-id').text();
626
721
  var thisLabel = $(this).children('span.combo-auto-box-item-label').text();
627
722
 
@@ -647,24 +742,24 @@ var ComboAutoBox = {
647
742
 
648
743
  // starting generate modial dialog
649
744
  var generateModalDialog = function (textField) {
745
+ options['modalId'] = generateAnId('model-dialog')
650
746
  if (options.bootstrap) {
651
747
  if (options.type == 'simple') {
652
748
  $(generateExpander()).appendTo('#' + container + ' > div.container-combo-auto-box-bootstrap');
653
749
  } else {
654
750
  $(generateExpander()).prependTo('#' + container + ' > div.container-combo-auto-box-bootstrap');
655
751
  }
656
- generateBootstrapDialogModal(generateAnId('model-dialog'));
752
+ generateBootstrapDialogModal(options['modalId']);
657
753
  } else {
658
754
  $(generateExpander()).prependTo('#' + container + ' > div.container-combo-auto-box');
659
755
  adjustExpanderImage();
660
- generateDivDialogModal(generateAnId('model-dialog'));
756
+ generateDivDialogModal(options['modalId']);
661
757
  }
662
758
 
663
759
  };
664
760
 
665
761
  // add multiple item
666
762
  var addMultipleItem = function (inputId, selectedId, selectedData) {
667
- console.log(selectedId);
668
763
  var targetId = (options.html.name + selectedId).replace(/[^A-Za-z0-9]/g, '_');
669
764
  if ((selectedData != '') && ($('#' + targetId).length == 0)) {
670
765
  var id = generateAnId('item');
@@ -931,6 +1026,10 @@ var ComboAutoBox = {
931
1026
  options.style = "mail";
932
1027
  }
933
1028
 
1029
+ if (options.email == null) {
1030
+ options.email = false
1031
+ }
1032
+
934
1033
  validLanguage();
935
1034
  validType();
936
1035
 
@@ -1,24 +1,26 @@
1
1
  span.combo-auto-box-item-id { display:none; }
2
+ div.modal > div.modal-dialog > div.modal-content > div.modal-body > div.list-group > a.selected { color:#CDCDCD; }
3
+ div.modal > div.modal-dialog > div.modal-content > div.modal-body > div.list-group > a.selected:hover { color:#CDCDCD; cursor:default; }
2
4
 
3
- div.multiple { border: 1px solid #CDCDCD; display:table; width:100%; padding: 2px 6px; }
4
- div.multiple:hover {cursor:text}
5
- div.multiple span.multiple-icon { float:right; }
5
+ div.multiple { border: 1px solid #CDCDCD; display:table; width:100%; padding: 0px; }
6
+ div.multiple:hover { cursor:text }
7
+ div.multiple span.multiple-icon { float:right; border-radius: 0em;}
6
8
  div.multiple span.multiple-icon:hover { cursor:pointer; }
7
9
  div.multiple span.multiple { font-family: inherit; float:left; font-size: 18px; color:#9A9A9A; margin: 1px 2px 2px 2px; padding:2px 10px 2px 10px; vertical-align: middle; }
8
10
  div.multiple span.multiple:hover { cursor:pointer; }
9
- div.multiple input { border: 0px; float:left; min-height:22px; font-size:15px; margin-top:2px; }
10
- div.multiple input:focus { outline:none; }
11
- div.multiple div.item { font-family: arial,sans-serif; float:left; font-size: 15px; color:#000000; background-color:#EDEDED; margin: 2px 10px 2px 2px; padding:2px 10px 2px 10px; border-radius: .25em; vertical-align: baseline; display:inline; white-space: nowrap; }
11
+ div.multiple div.item { font-family: arial,sans-serif; float:left; font-size: 15px; color:#000000; background-color:#EDEDED; margin: 3px 10px 2px 2px; padding:2px 10px 2px 10px; border-radius: .25em; vertical-align: baseline; display:inline; white-space: nowrap; }
12
12
  div.multiple div.item:hover { cursor:default; }
13
13
  div.multiple div.item span { margin-left:10px; color:#CCCCCC; }
14
- div.multiple div.item span.remove_item { font-weight:none; color:#ADADAD;}
15
- div.multiple div.item span:hover { color:#6D6D6D; cursor:pointer;}
16
-
14
+ div.multiple div.item span.remove_item { font-weight:none; color:#ADADAD; }
15
+ div.multiple div.item span:hover { color:#6D6D6D; cursor:pointer; }
16
+ div.multiple input { border: 0px; float:left; min-height:22px; font-size:13px; margin-top:5px; margin-left:11px; }
17
+ div.multiple input:focus { outline:none; }
18
+
17
19
  div.searchable { border: 1px solid #CDCDCD; display:table; width:100%; padding: 2px 6px; }
18
20
  div.searchable:hover {cursor:text}
19
21
  div.searchable input { border: 0px; float:left; min-height:22px; font-size:15px; margin-top:2px; }
20
22
  div.searchable input:focus { outline:none; }
21
- div.searchable div.item { font-family: inherit; float:left; font-size: 15px; color:#FFFFFF; background-color:#008000; margin: 2px 10px 2px 2px; padding:2px 10px 2px 10px; border-radius: .25em; vertical-align: baseline; display:inline; white-space: nowrap; font-weight:bold; }
23
+ div.searchable div.item { font-family: inherit; float:left; font-size: 15px; color:#FFFFFF; background-color:#008000; margin: 2px 8px 3px 4px; padding:2px 10px 2px 10px; border-radius: .25em; vertical-align: baseline; display:inline; white-space: nowrap; font-weight:bold; }
22
24
  div.searchable div.item:hover { cursor:default; }
23
25
  div.searchable div.item span { margin-left:10px; color:#CCCCCC; }
24
26
  div.searchable div.item span.remove_item { font-weight:none; color:#AAAAAA;}
@@ -7,12 +7,12 @@ div.multiple { border: 1px solid #CDCDCD; display:table; width:100%; }
7
7
  div.multiple:hover {cursor:text}
8
8
  div.multiple span.multiple { font-family: arial,sans-serif; float:left; font-size: 13px; color:#9A9A9A; margin: 2px 2px 2px 2px; padding:2px 10px 2px 10px; }
9
9
  div.multiple span.multiple:hover { cursor:pointer; }
10
- div.multiple input { border: 0px; float:left; height:22px; }
11
10
  div.multiple div.item { font-family: arial,sans-serif; float:left; font-size: 13px; color:#000000; background-color:#EDEDED; margin: 2px 10px 2px 2px; padding:2px 10px 2px 10px; -moz-border-radius:4px;-webkit-border-radius:4px; border:1px solid #CECECE; }
12
11
  div.multiple div.item:hover { cursor:default; }
13
12
  div.multiple div.item span { margin-left:10px; color:#CCCCCC; }
14
13
  div.multiple div.item span:hover { color:#9A9A9A; cursor:pointer;}
15
- div.multiple input:focus {outline:none; }
14
+ div.multiple input { border: 0px; float:left; height:22px; }
15
+ div.multiple input:focus { outline:none; }
16
16
 
17
17
  div.searchable { border: 1px solid #CDCDCD; display:table; width:100%; }
18
18
  div.searchable:hover {cursor:text}
@@ -35,6 +35,9 @@ div.dialog-modal div.list ul { list-style:none; width:100%; height:100px; float:
35
35
  div.dialog-modal div.list ul li { padding: 5px 0 5px 3px; margin-left:0px; width:100%; border-bottom:1px solid #DCDCDC; font-size:12px; }
36
36
  div.dialog-modal div.list ul li:hover { cursor:pointer; text-decoration:underline; background-color:#F9F9F9; }
37
37
 
38
+ div.dialog-modal div.list ul li.selected { padding: 5px 0 5px 3px; margin-left:0px; width:100%; border-bottom:1px solid #DCDCDC; font-size:12px; color:#CDCDCD;}
39
+ div.dialog-modal div.list ul li.selected:hover { cursor:default; }
40
+
38
41
  div.dialog-modal div.footer { display:table; width:99%; float:left; margin-top:12px; text-align: right;}
39
42
 
40
43
  /*div.dialog-modal div.head { display:block; width:99%; position:absolute; z-index:2002; top:0px; left:0px; border: 1px solid #000; background-color:#CECECE; height:30px; -moz-border-radius:4px;-webkit-border-radius:4px;}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: combo_auto_box
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.46
4
+ version: 0.0.47
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adilson Chacon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-17 00:00:00.000000000 Z
11
+ date: 2016-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec