combo_auto_box 0.0.15 → 0.0.16

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,3 +1,3 @@
1
1
  module ComboAutoBox
2
- VERSION = '0.0.15'
2
+ VERSION = '0.0.16'
3
3
  end
@@ -25,46 +25,38 @@ var ComboAutoBox = {
25
25
  var bindAutoComplete = function (inputId) {
26
26
  var previuosValue = '';
27
27
  $('#' + inputId).keydown(function(e) {
28
- if ((e.keyCode == 8) && (options.type == 'multiple') && ($('#' + inputId).val() == '')) {
29
- var value = $('#' + container + ' > div.multiple > div.item:last > input').val();
30
- var label = $('#' + container + ' > div.multiple > div.item:last').text();
31
- $('#' + container + ' > div.multiple > div.item:last').remove();
32
- unselectData(value, label);
33
- }
34
-
35
- if ((e.keyCode == 8) && (options.type == 'searchable') && ($('#' + inputId).val() == '')) {
36
- var label = $('#' + container + ' > div.searchable > div.item:last > input[name*="value"]').val();
37
- var attribute = $('#' + container + ' > div.searchable > div.item:last > input[name*="name"]').val();
38
- var condition = $('#' + container + ' > div.searchable > div.item:last > input[name*="p"]').val();
39
- $('#' + container + ' > div.searchable > div.item:last').remove();
40
- unselectData(attribute + "_" +condition, label);
28
+ if ((e.keyCode == 8) && ($('#' + inputId).val() == '')) {
29
+ if (options.type == 'multiple') {
30
+ removeLastMultipleItem();
31
+ } else if (options.type == 'searchable') {
32
+ removeLastSearchableItemForRansack();
33
+ }
41
34
  }
42
-
43
35
  });
44
36
 
45
37
  $('#' + inputId).keypress(function(e) {
46
- if (e.which === 13) {
38
+ if ((e.which === 13) && ($('#' + inputId).val() != '')) {
47
39
  if (options.type == 'full') {
48
40
  $('#' + inputId).autocomplete( "close" );
49
41
  selectData($('#' + inputId).val(), $('#' + inputId).val());
50
42
  } else if (options.type == 'multiple') {
51
43
  $('#' + inputId).autocomplete( "close" );
52
- addItem(inputId, $('#' + inputId).val(), $('#' + inputId).val());
44
+ addMultipleItem(inputId, $('#' + inputId).val(), $('#' + inputId).val());
53
45
  selectData($('#' + inputId).val(), $('#' + inputId).val());
54
46
  $('#' + inputId).val('');
55
- } else if ((options.type == 'searchable') && ($('#' + inputId).val()) != '') {
47
+ } else if (options.type == 'searchable') {
56
48
  try {
49
+ $('#' + inputId).autocomplete('close');
57
50
  var item = sourceForSearchable(inputId)[0];
58
51
  addSearchableItemForRansack(inputId, item.id, item.label);
59
52
  selectData(item.id, item.label);
60
53
  $('#' + inputId).val('');
61
- $('#' + inputId).autocomplete('close');
62
54
  } catch (error) {
63
55
 
64
56
  }
65
57
  }
66
- return false;
67
58
  }
59
+ return false;
68
60
  });
69
61
 
70
62
  $('#' + inputId).autocomplete({
@@ -76,7 +68,7 @@ var ComboAutoBox = {
76
68
  return selectData($('#' + inputId).val(), $('#' + inputId).val());
77
69
  } else if (options.type == 'multiple') {
78
70
  $('#' + inputId).val('');
79
- addItem(inputId, ui.item.id, ui.item.label);
71
+ addMultipleItem(inputId, ui.item.id, ui.item.label);
80
72
  selectData(ui.item.id, ui.item.label);
81
73
  return false;
82
74
  } else if (options.type == 'searchable') {
@@ -280,7 +272,7 @@ var ComboAutoBox = {
280
272
  selectData(thisId, thisLabel);
281
273
  } else if (options.type == 'multiple') {
282
274
  $('#' + container + ' > div.container-combo-auto-box > input').val('');
283
- addItem($('#' + container + ' > div.container-combo-auto-box > input').attr('id'), thisId, thisLabel);
275
+ addMultipleItem($('#' + container + ' > div.container-combo-auto-box > input').attr('id'), thisId, thisLabel);
284
276
  $('#' + container + ' > div.container-combo-auto-box > input[type="text"]').focus();
285
277
  selectData(thisId, thisLabel);
286
278
  }
@@ -301,8 +293,8 @@ var ComboAutoBox = {
301
293
  generateDivDialogModal(generateAnId('model-dialog'));
302
294
  };
303
295
 
304
- // add item
305
- var addItem = function (inputId, selectedId, selectedData) {
296
+ // add multiple item
297
+ var addMultipleItem = function (inputId, selectedId, selectedData) {
306
298
  if (selectedData != '') {
307
299
  var id = generateAnId('item');
308
300
  $('#' + inputId).before('<div class="item" id="' + id + '">'+ htmlSafe(selectedData) +'<span title="Remove Item">x</span><input type="hidden" name="'+ options.html.name +'[]" value="'+ selectedId +'"></div>');
@@ -314,6 +306,16 @@ var ComboAutoBox = {
314
306
  }
315
307
  };
316
308
 
309
+ // remove multiple item
310
+ var removeLastMultipleItem = function () {
311
+ if ($('#' + container + ' > div.multiple > div.item').length > 0) {
312
+ var value = $('#' + container + ' > div.multiple > div.item:last > input').val();
313
+ var label = $('#' + container + ' > div.multiple > div.item:last').text();
314
+ $('#' + container + ' > div.multiple > div.item:last').remove();
315
+ unselectData(value, label);
316
+ }
317
+ };
318
+
317
319
  // add searchable item for ransack
318
320
  var addSearchableItemForRansack = function (inputId, selectedId, selectedData) {
319
321
  if (selectedData != '') {
@@ -334,6 +336,16 @@ var ComboAutoBox = {
334
336
  });
335
337
  }
336
338
  };
339
+
340
+ var removeLastSearchableItemForRansack = function() {
341
+ if ($('#' + container + ' > div.searchable > div.item').length > 0) {
342
+ var label = $('#' + container + ' > div.searchable > div.item:last > input[name*="value"]').val();
343
+ var attribute = $('#' + container + ' > div.searchable > div.item:last > input[name*="name"]').val();
344
+ var condition = $('#' + container + ' > div.searchable > div.item:last > input[name*="p"]').val();
345
+ $('#' + container + ' > div.searchable > div.item:last').remove();
346
+ unselectData(attribute + "_" + condition, label);
347
+ }
348
+ }
337
349
 
338
350
  // add searchable item
339
351
  var addSearchableItem = function (inputId, selectedId, selectedData) {
@@ -483,6 +495,22 @@ var ComboAutoBox = {
483
495
 
484
496
  return validIndexes;
485
497
  }
498
+
499
+ var handleMultipleInitials = function() {
500
+ if (options.initials != null) {
501
+ $.each(options.initials, function(index) {
502
+ addMultipleItem(textField.attr('id'), options.initials[index]['id'], options.initials[index]['label']);
503
+ });
504
+ }
505
+ }
506
+
507
+ var handleSearchbleInitials = function() {
508
+ if (options.initials != null) {
509
+ $.each(options.initials, function(index) {
510
+ addSearchableItemForRansack(textField.attr('id'), options.initials[index]['id'], options.initials[index]['label']);
511
+ });
512
+ }
513
+ }
486
514
 
487
515
  // main
488
516
  if (options == null) {
@@ -497,25 +525,21 @@ var ComboAutoBox = {
497
525
  textField = $('#' + container + ' > div.container-combo-auto-box > input');
498
526
  bindAutoComplete(textField.attr('id'));
499
527
 
500
- if ((options.type == 'simple') || (options.type == 'multiple')) {
528
+ if (options.type == 'simple') {
501
529
  generateModalDialog(textField);
502
530
  }
503
-
504
- if ((options.type == 'multiple') || (options.type == 'searchable')) {
531
+
532
+ if (options.type == 'multiple') {
533
+ generateModalDialog(textField);
505
534
  bindContainerClick(textField.attr('id'));
506
535
  normalizeStyles(textField.attr('id'));
507
- }
508
-
509
- if ((options.type == 'multiple') && (options.initials != null)) {
510
- $.each(options.initials, function(index){
511
- addItem(textField.attr('id'), options.initials[index]['id'], options.initials[index]['label']);
512
- });
536
+ handleMultipleInitials();
513
537
  }
514
538
 
515
- if ((options.type == 'searchable') && (options.initials != null)) {
516
- $.each(options.initials, function(index){
517
- addSearchableItemForRansack(textField.attr('id'), options.initials[index]['id'], options.initials[index]['label']);
518
- });
539
+ if (options.type == 'searchable') {
540
+ bindContainerClick(textField.attr('id'));
541
+ normalizeStyles(textField.attr('id'));
542
+ handleSearchbleInitials();
519
543
  }
520
544
 
521
545
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: combo_auto_box
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-03 00:00:00.000000000 Z
12
+ date: 2013-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport