combo_auto_box 0.0.48 → 0.0.49
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/lib/combo_auto_box/version.rb +1 -1
- data/vendor/assets/javascripts/combo-auto-box.js +154 -138
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 450b0baa2ff62c8da0071dd9f79823cc0395ed95
|
4
|
+
data.tar.gz: b801e1f5c9d05df1d33f03fef12125335abf8aec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64d9ede45079dc427ea67402d0ff050024faa151f60d6cc71f5be8e9d6f3d4ac2489a7b1f333d445a84065b15f399b61891e77132f0f2852d34c99a238fe0d5e
|
7
|
+
data.tar.gz: 21155fe070b5a61bf5ca699e23006a2b186ff13771b841f5c3fc612603e6839b4e5afadda8965ae2ccc7975dc02e1d672a213c476104d821b472845e99480284
|
@@ -7,20 +7,37 @@ var ComboAutoBox = {
|
|
7
7
|
while ($('input[name*="[' + prefix +"-" + now + ']"]').length != 0) {
|
8
8
|
now++;
|
9
9
|
}
|
10
|
-
|
10
|
+
|
11
11
|
return prefix + "-" + now;
|
12
12
|
};
|
13
13
|
|
14
|
+
var htmlSafe = function(html) {
|
15
|
+
html = html.toString();
|
16
|
+
html = html.replace(/\&/g, '&');
|
17
|
+
html = html.replace(/\</g, '<');
|
18
|
+
html = html.replace(/\>/g, '>');
|
19
|
+
html = html.replace(/\"/g, '"');
|
20
|
+
html = html.replace(/\'/g, ''');
|
21
|
+
html = html.replace(/\//g, '/');
|
22
|
+
|
23
|
+
return html;
|
24
|
+
}
|
25
|
+
|
26
|
+
$.each(options.source, function( index, value ){
|
27
|
+
options.source[index]['id'] = htmlSafe(options.source[index]['id']);
|
28
|
+
options.source[index]['label'] = htmlSafe(options.source[index]['label']);
|
29
|
+
});
|
30
|
+
|
14
31
|
// generatea an ID based on current time
|
15
32
|
var generateAnId = function(prefix) {
|
16
33
|
var now = new Date().getTime();
|
17
34
|
while ($("#" + prefix +"-" + now).length != 0) {
|
18
35
|
now++;
|
19
36
|
}
|
20
|
-
|
37
|
+
|
21
38
|
return prefix + "-" + now;
|
22
39
|
};
|
23
|
-
|
40
|
+
|
24
41
|
var splitValidEmails = function (inputId, inputValue) {
|
25
42
|
if ((options.type != 'multiple') || (!options.email)) {
|
26
43
|
return false;
|
@@ -46,7 +63,7 @@ var ComboAutoBox = {
|
|
46
63
|
|
47
64
|
return true;
|
48
65
|
}
|
49
|
-
|
66
|
+
|
50
67
|
// binds autocomplete to text field
|
51
68
|
var bindAutoComplete = function (inputId) {
|
52
69
|
var previuosValue = '';
|
@@ -62,7 +79,7 @@ var ComboAutoBox = {
|
|
62
79
|
if (!options.not_found_accepted) {
|
63
80
|
$('#' + inputId).val('');
|
64
81
|
}
|
65
|
-
selectData($('#' + inputId).val(), $('#' + inputId).val());
|
82
|
+
selectData($('#' + inputId).val(), $('#' + inputId).val());
|
66
83
|
return true;
|
67
84
|
} else if ((e.keyCode == 9) && (inputVal != '') && (options.source_not_found) && (options.type == 'multiple')) {
|
68
85
|
$('#' + inputId).autocomplete( "close");
|
@@ -76,9 +93,9 @@ var ComboAutoBox = {
|
|
76
93
|
$('#' + inputId).val('');
|
77
94
|
return true;
|
78
95
|
}
|
79
|
-
|
96
|
+
|
80
97
|
});
|
81
|
-
|
98
|
+
|
82
99
|
// CTRL+V or CMD+V
|
83
100
|
$('#' + inputId).bind('paste', function() {
|
84
101
|
var $this = $(this);
|
@@ -86,8 +103,8 @@ var ComboAutoBox = {
|
|
86
103
|
splitValidEmails(inputId, $this.val());
|
87
104
|
}, 20); //just break the callstack to let the event finish
|
88
105
|
|
89
|
-
});
|
90
|
-
|
106
|
+
});
|
107
|
+
|
91
108
|
$('#' + inputId).keypress(function(e) {
|
92
109
|
// 44 is "," - 32 is SPACE - 59 is ";"
|
93
110
|
if (((e.which === 32) || (e.which === 44) || (e.which === 59)) && (options.type == 'multiple') && (options.email) && ($('#' + inputId).val().match(/[^@\s]+@([^@\s]+\.)+[^@\s]+/))) {
|
@@ -102,7 +119,7 @@ var ComboAutoBox = {
|
|
102
119
|
setTimeout(function(){
|
103
120
|
$('#' + inputId).val('');
|
104
121
|
}, 20);
|
105
|
-
|
122
|
+
|
106
123
|
} else if ((e.which === 13) && ($('#' + inputId).val() != '')) {
|
107
124
|
if (options.type == 'full') {
|
108
125
|
$('#' + inputId).autocomplete( "close" );
|
@@ -130,16 +147,16 @@ var ComboAutoBox = {
|
|
130
147
|
selectData(item.id, item.label);
|
131
148
|
$('#' + inputId).val('');
|
132
149
|
} catch (error) {
|
133
|
-
|
150
|
+
|
134
151
|
}
|
135
152
|
}
|
136
|
-
|
153
|
+
|
137
154
|
return false;
|
138
155
|
} else if ((e.which === 13) && ($('#' + inputId).val() == '')) {
|
139
|
-
return false;
|
156
|
+
return false;
|
140
157
|
}
|
141
158
|
});
|
142
|
-
|
159
|
+
|
143
160
|
$('#' + inputId).autocomplete({
|
144
161
|
source: setAutoCompleteSource(inputId),
|
145
162
|
select: function(event, ui) {
|
@@ -177,7 +194,7 @@ var ComboAutoBox = {
|
|
177
194
|
},
|
178
195
|
search: function(event, ui) {
|
179
196
|
if (options.type == 'searchable') {
|
180
|
-
$('#' + inputId).autocomplete("option", { source: setAutoCompleteSource(inputId) });
|
197
|
+
$('#' + inputId).autocomplete("option", { source: setAutoCompleteSource(inputId) });
|
181
198
|
}
|
182
199
|
},
|
183
200
|
change: function (event, ui) {
|
@@ -191,7 +208,7 @@ var ComboAutoBox = {
|
|
191
208
|
},
|
192
209
|
});
|
193
210
|
};
|
194
|
-
|
211
|
+
|
195
212
|
// set autocomplete source
|
196
213
|
var setAutoCompleteSource = function (inputId) {
|
197
214
|
if (options.type == 'searchable') {
|
@@ -238,7 +255,7 @@ var ComboAutoBox = {
|
|
238
255
|
options.source_not_found = true;
|
239
256
|
return [ { id: $('#' + inputId).val(), label: '"' + $('#' + inputId).val() + '" ' + options.not_found_message } ];
|
240
257
|
}
|
241
|
-
|
258
|
+
|
242
259
|
// source items for searchable
|
243
260
|
var sourceForSearchable = function (inputId) {
|
244
261
|
var new_source = new Array();
|
@@ -251,9 +268,9 @@ var ComboAutoBox = {
|
|
251
268
|
}
|
252
269
|
});
|
253
270
|
});
|
254
|
-
return new_source;
|
271
|
+
return new_source;
|
255
272
|
}
|
256
|
-
|
273
|
+
|
257
274
|
// get i18n math comparisons
|
258
275
|
var i18nMath = function (language) {
|
259
276
|
var operators = new Array();
|
@@ -325,7 +342,7 @@ var ComboAutoBox = {
|
|
325
342
|
}
|
326
343
|
return title;
|
327
344
|
};
|
328
|
-
|
345
|
+
|
329
346
|
var i18nSelectAll = function (language) {
|
330
347
|
var title = 'Select All';
|
331
348
|
switch(language.toLowerCase()) {
|
@@ -347,7 +364,7 @@ var ComboAutoBox = {
|
|
347
364
|
}
|
348
365
|
return title;
|
349
366
|
};
|
350
|
-
|
367
|
+
|
351
368
|
// generates text field with html options
|
352
369
|
var generateInputTag = function () {
|
353
370
|
var html = 'input type="text"';
|
@@ -359,18 +376,18 @@ var ComboAutoBox = {
|
|
359
376
|
html = html + ' '+ key +'="' + value + '"';
|
360
377
|
});
|
361
378
|
}
|
362
|
-
|
379
|
+
|
363
380
|
if ((options.html == null) || (options.html.id == null)) {
|
364
381
|
html = html + ' id="' + generateAnId('combo-auto-box') + '"';
|
365
382
|
}
|
366
|
-
|
383
|
+
|
367
384
|
if ((options.bootstrap) && (options.type == "simple")) {
|
368
385
|
html = html + ' class="form-control" '
|
369
386
|
}
|
370
|
-
|
387
|
+
|
371
388
|
return '<' + html + '>';
|
372
389
|
};
|
373
|
-
|
390
|
+
|
374
391
|
// On click opens modal image tag inside "i" tag through css
|
375
392
|
var generateExpander = function () {
|
376
393
|
if (options.type == 'simple') {
|
@@ -381,21 +398,21 @@ var ComboAutoBox = {
|
|
381
398
|
}
|
382
399
|
} else if (options.type == 'multiple') {
|
383
400
|
if (options.style == "mail") {
|
384
|
-
return '<span class="multiple">' + options.label + '</span>';
|
401
|
+
return '<span class="multiple">' + options.label + '</span>';
|
385
402
|
} else {
|
386
|
-
return '<span class="multiple-icon"><button class="btn btn-default" type="button"><i class="fa fa-bars"></i></button></span>';
|
403
|
+
return '<span class="multiple-icon"><button class="btn btn-default" type="button"><i class="fa fa-bars"></i></button></span>';
|
387
404
|
}
|
388
405
|
}
|
389
406
|
};
|
390
|
-
|
407
|
+
|
391
408
|
var adjustExpanderImage = function() {
|
392
409
|
if ((options.bootstrap) && (options.type == "simple")) {
|
393
410
|
return true;
|
394
411
|
}
|
395
|
-
|
412
|
+
|
396
413
|
if (options.type == 'simple') {
|
397
414
|
spanTag = $('#' + container + ' > div.container-combo-auto-box > span.simple');
|
398
|
-
|
415
|
+
|
399
416
|
inputWidth = getTextFieldWidth(textField);
|
400
417
|
inputHeight = getTextFieldHeight(textField);
|
401
418
|
|
@@ -405,18 +422,18 @@ var ComboAutoBox = {
|
|
405
422
|
if (inputHeight % 2 != 0) {
|
406
423
|
inputBorderTop = inputBorderTop + 2;
|
407
424
|
}
|
408
|
-
|
425
|
+
|
409
426
|
iWidth = 20;
|
410
427
|
if (inputWidth < 20) {
|
411
428
|
iWidth = 10;
|
412
429
|
}
|
413
|
-
|
430
|
+
|
414
431
|
spanTag.css('margin-top', inputBorderTop.toString() + 'px');
|
415
432
|
spanTag.css('margin-left', (inputWidth - iWidth + 4).toString() + 'px');
|
416
433
|
|
417
434
|
spanTag.children(':first').css('width', iWidth.toString() + 'px');
|
418
435
|
spanTag.children(':first').css('height', inputHeight.toString() + 'px');
|
419
|
-
|
436
|
+
|
420
437
|
return true;
|
421
438
|
} else if (options.type == 'multiple') {
|
422
439
|
inputTop = 0;
|
@@ -436,7 +453,7 @@ var ComboAutoBox = {
|
|
436
453
|
|
437
454
|
var getTextFieldWidth = function (textField) {
|
438
455
|
var widthTotal = 0;
|
439
|
-
|
456
|
+
|
440
457
|
if (textField.width() != null) {
|
441
458
|
widthTotal = widthTotal + textField.width();
|
442
459
|
}
|
@@ -445,10 +462,10 @@ var ComboAutoBox = {
|
|
445
462
|
padding_right = textField.css('padding-right').toString().replace(/[a-zA-Z]+/g, '');
|
446
463
|
widthTotal = widthTotal + parseInt(padding_right);
|
447
464
|
}
|
448
|
-
|
465
|
+
|
449
466
|
return widthTotal;
|
450
467
|
}
|
451
|
-
|
468
|
+
|
452
469
|
var getTextFieldBorder = function (textField, side) {
|
453
470
|
var heightTotal = 0;
|
454
471
|
|
@@ -460,10 +477,10 @@ var ComboAutoBox = {
|
|
460
477
|
|
461
478
|
return heightTotal;
|
462
479
|
}
|
463
|
-
|
480
|
+
|
464
481
|
var getTextFieldHeight = function (textField) {
|
465
482
|
var heightTotal = 0;
|
466
|
-
|
483
|
+
|
467
484
|
try {
|
468
485
|
if (textField.height() != null) {
|
469
486
|
heightTotal = heightTotal + textField.height();
|
@@ -476,17 +493,17 @@ var ComboAutoBox = {
|
|
476
493
|
heightTotal = heightTotal + parseInt(padding_top);
|
477
494
|
}
|
478
495
|
} catch (error) {}
|
479
|
-
|
496
|
+
|
480
497
|
try {
|
481
498
|
if (textField.css('padding-bottom') != null) {
|
482
499
|
padding_bottom = textField.css('padding-bottom').toString().replace(/[a-zA-Z]+/g, '');
|
483
500
|
heightTotal = heightTotal + parseInt(padding_bottom);
|
484
501
|
}
|
485
502
|
} catch (error) {}
|
486
|
-
|
503
|
+
|
487
504
|
return heightTotal;
|
488
505
|
}
|
489
|
-
|
506
|
+
|
490
507
|
// Global div for combo auto box
|
491
508
|
var generateDivTag = function () {
|
492
509
|
var klass = 'container-combo-auto-box'
|
@@ -496,11 +513,11 @@ var ComboAutoBox = {
|
|
496
513
|
}
|
497
514
|
klass = klass + ' multiple';
|
498
515
|
} else if (options.type == 'searchable') {
|
499
|
-
klass = klass + ' searchable'
|
516
|
+
klass = klass + ' searchable'
|
500
517
|
} else if ((options.type == 'simple') && (options.bootstrap)) {
|
501
|
-
klass = klass + '-bootstrap input-group'
|
518
|
+
klass = klass + '-bootstrap input-group'
|
502
519
|
}
|
503
|
-
|
520
|
+
|
504
521
|
return '<div class="' + klass + '">' + generateInputTag() + '</div>';
|
505
522
|
};
|
506
523
|
|
@@ -511,7 +528,7 @@ var ComboAutoBox = {
|
|
511
528
|
disableSelectionIfAlreadySelectedSimple();
|
512
529
|
}
|
513
530
|
}
|
514
|
-
|
531
|
+
|
515
532
|
var disableSelectionIfAlreadySelectedBootstrap = function() {
|
516
533
|
var selecteds = $("div#" + container + " > div.container-combo-auto-box-bootstrap > div.item > input[type='hidden']").map(function(k, v) { return $(this).val() });
|
517
534
|
|
@@ -521,42 +538,42 @@ var ComboAutoBox = {
|
|
521
538
|
if ($.inArray(item, selecteds) >= 0) { // IF exists in array
|
522
539
|
$(this).addClass('selected');
|
523
540
|
} else {
|
524
|
-
}
|
525
|
-
});
|
541
|
+
}
|
542
|
+
});
|
526
543
|
}
|
527
544
|
|
528
545
|
var disableSelectionIfAlreadySelectedSimple = function() {
|
529
546
|
var selecteds = $("div#" + container + " > div.container-combo-auto-box > div.item > input[type='hidden']").map(function(k, v) { return $(this).val() });
|
530
|
-
|
547
|
+
|
531
548
|
$('#' + options.modalId + ' > div.list > ul > li').each(function(index) {
|
532
549
|
var item = $(this).children('span.combo-auto-box-item-id').text();
|
533
550
|
$(this).removeClass('selected');
|
534
551
|
if ($.inArray(item, selecteds) >= 0) { // IF exists in array
|
535
552
|
$(this).addClass('selected');
|
536
553
|
} else {
|
537
|
-
}
|
538
|
-
});
|
554
|
+
}
|
555
|
+
});
|
539
556
|
}
|
540
|
-
|
557
|
+
|
541
558
|
// dialog modal
|
542
559
|
var generateDivDialogModal = function (modalDialogId) {
|
543
|
-
$('<div id="'+ modalDialogId +'" class="dialog-modal">' +
|
544
|
-
'<div class="head">' +
|
560
|
+
$('<div id="'+ modalDialogId +'" class="dialog-modal">' +
|
561
|
+
'<div class="head">' +
|
545
562
|
'<span class="label">' + options.label + '</span>' +
|
546
563
|
'<span class="close" title="Close">X</span>' +
|
547
564
|
'</div>' +
|
548
565
|
'<div class="list">' +
|
549
|
-
'<ul></ul>' +
|
566
|
+
'<ul></ul>' +
|
550
567
|
'</div>' +
|
551
568
|
'<div class="footer">' +
|
552
|
-
'<a href="javascript:void(0)" class="selectAll">' + i18nSelectAll(options.lang) + '</a>' +
|
569
|
+
'<a href="javascript:void(0)" class="selectAll">' + i18nSelectAll(options.lang) + '</a>' +
|
553
570
|
'</div>' +
|
554
571
|
'</div>').appendTo('#' + container);
|
555
|
-
|
572
|
+
|
556
573
|
$('#' + modalDialogId + ' > div.head > span.close').click(function() {
|
557
574
|
$('#' + modalDialogId).dialog('close');
|
558
575
|
});
|
559
|
-
|
576
|
+
|
560
577
|
$('#' + modalDialogId).dialog({
|
561
578
|
width: 500,
|
562
579
|
height: 412,
|
@@ -566,26 +583,26 @@ var ComboAutoBox = {
|
|
566
583
|
margin: 0,
|
567
584
|
padding: 0,
|
568
585
|
});
|
569
|
-
|
586
|
+
|
570
587
|
getListForModalDialog(modalDialogId);
|
571
|
-
|
588
|
+
|
572
589
|
$("#" + modalDialogId).siblings('div.ui-dialog-titlebar').remove();
|
573
|
-
|
574
|
-
$('#' + container + ' > div.container-combo-auto-box > span.' + options.type).click(function() {
|
590
|
+
|
591
|
+
$('#' + container + ' > div.container-combo-auto-box > span.' + options.type).click(function() {
|
575
592
|
disableSelectionIfAlreadySelected();
|
576
593
|
|
577
|
-
openModalDialog(modalDialogId)
|
594
|
+
openModalDialog(modalDialogId)
|
578
595
|
});
|
579
596
|
|
580
597
|
$('a.selectAll').click(function() {
|
581
598
|
selectAllData(container, modalDialogId);
|
582
599
|
});
|
583
600
|
};
|
584
|
-
|
601
|
+
|
585
602
|
// dialog modal
|
586
603
|
var generateBootstrapDialogModal = function (modalDialogId) {
|
587
604
|
var targetObject = ('#' + container + ' > div.container-combo-auto-box-bootstrap > span');
|
588
|
-
|
605
|
+
|
589
606
|
if (options.type == "simple") {
|
590
607
|
targetObject = targetObject + ' > button';
|
591
608
|
}
|
@@ -610,12 +627,12 @@ var ComboAutoBox = {
|
|
610
627
|
} else {
|
611
628
|
$(modal).appendTo('#' + container);
|
612
629
|
}
|
613
|
-
|
630
|
+
|
614
631
|
getListForModalDialog(modalDialogId);
|
615
|
-
|
632
|
+
|
616
633
|
$(targetObject).click(function() {
|
617
634
|
disableSelectionIfAlreadySelected();
|
618
|
-
|
635
|
+
|
619
636
|
$('#' + modalDialogId).modal('show');
|
620
637
|
|
621
638
|
// fix to allways show back-shadow
|
@@ -626,11 +643,11 @@ var ComboAutoBox = {
|
|
626
643
|
// alert($('.modal-backdrop').css('z-index'));
|
627
644
|
// alert($('.modal').css('z-index'));
|
628
645
|
});
|
629
|
-
|
646
|
+
|
630
647
|
$('div#' + modalDialogId + ' > div.modal-dialog > div.modal-content > div.modal-footer > button.selectAll').click(function() {
|
631
648
|
selectAllData(container, modalDialogId);
|
632
649
|
});
|
633
|
-
|
650
|
+
|
634
651
|
$('#' + modalDialogId).on('hide.bs.modal', function (e) {
|
635
652
|
if (options.onHideModal != null) {
|
636
653
|
options.onHideModal();
|
@@ -643,19 +660,19 @@ var ComboAutoBox = {
|
|
643
660
|
}
|
644
661
|
});
|
645
662
|
};
|
646
|
-
|
663
|
+
|
647
664
|
// Selects an item form modal dialog when clicked on
|
648
665
|
var selectValueFromModalDialog = function (value) {
|
649
666
|
$('#' + container + ' > div.container-combo-auto-box > input').val(value);
|
650
667
|
selectData(value);
|
651
668
|
};
|
652
|
-
|
669
|
+
|
653
670
|
// generates list for modal dialog
|
654
671
|
var getListForModalDialog = function (modalDialogId) {
|
655
672
|
if (typeof options.source == 'string') {
|
656
673
|
var term = 'term=';
|
657
674
|
var params = (options.data == null) ? term : options.data + '&' + term;
|
658
|
-
|
675
|
+
|
659
676
|
$.getJSON(options.source + '?' + params, function(data) {
|
660
677
|
setListForModalDialog(modalDialogId, data);
|
661
678
|
});
|
@@ -663,7 +680,7 @@ var ComboAutoBox = {
|
|
663
680
|
setListForModalDialog(modalDialogId, options.source);
|
664
681
|
}
|
665
682
|
};
|
666
|
-
|
683
|
+
|
667
684
|
// set list for modal dialog
|
668
685
|
var setListForModalDialog = function (modalDialogId, data) {
|
669
686
|
if (options.bootstrap) {
|
@@ -675,7 +692,7 @@ var ComboAutoBox = {
|
|
675
692
|
|
676
693
|
var setListForSimpleModalDialog = function (modalDialogId, data) {
|
677
694
|
var items = [];
|
678
|
-
|
695
|
+
|
679
696
|
$.each(data, function(index){
|
680
697
|
items.push('<li><span class="combo-auto-box-item-id">' + data[index].id +'</span><span class="combo-auto-box-item-label">'+ data[index].label + '</span></li>');
|
681
698
|
});
|
@@ -689,9 +706,9 @@ var ComboAutoBox = {
|
|
689
706
|
|
690
707
|
var thisId = $(this).children('span.combo-auto-box-item-id').text();
|
691
708
|
var thisLabel = $(this).children('span.combo-auto-box-item-label').text();
|
692
|
-
|
709
|
+
|
693
710
|
$('#' + modalDialogId).dialog('close');
|
694
|
-
|
711
|
+
|
695
712
|
if (options.type == 'simple') {
|
696
713
|
$('#' + container + ' > div.container-combo-auto-box > input').val(thisLabel);
|
697
714
|
selectData(thisId, thisLabel);
|
@@ -701,14 +718,14 @@ var ComboAutoBox = {
|
|
701
718
|
$('#' + container + ' > div.container-combo-auto-box > input[type="text"]').focus();
|
702
719
|
selectData(thisId, thisLabel);
|
703
720
|
}
|
704
|
-
});
|
721
|
+
});
|
705
722
|
};
|
706
723
|
|
707
|
-
var setListForBootstrapModalDialog = function (modalDialogId, data) {
|
724
|
+
var setListForBootstrapModalDialog = function (modalDialogId, data) {
|
708
725
|
var items = [];
|
709
|
-
|
726
|
+
|
710
727
|
$.each(data, function(index){
|
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>');
|
728
|
+
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>');
|
712
729
|
});
|
713
730
|
|
714
731
|
$('#' + modalDialogId + ' > div.modal-dialog > div.modal-content > div.modal-body > div.list-group').html(items.join(''));
|
@@ -716,10 +733,10 @@ var ComboAutoBox = {
|
|
716
733
|
if ($(this).hasClass('selected')) {
|
717
734
|
return false;
|
718
735
|
}
|
719
|
-
|
736
|
+
|
720
737
|
var thisId = $(this).children('span.combo-auto-box-item-id').text();
|
721
738
|
var thisLabel = $(this).children('span.combo-auto-box-item-label').text();
|
722
|
-
|
739
|
+
|
723
740
|
if (options.type == 'simple') {
|
724
741
|
$('#' + container + ' > div.container-combo-auto-box-bootstrap > input').val(thisLabel);
|
725
742
|
selectData(thisId, thisLabel);
|
@@ -729,49 +746,49 @@ var ComboAutoBox = {
|
|
729
746
|
$('#' + container + ' > div.container-combo-auto-box-bootstrap > input[type="text"]').focus();
|
730
747
|
selectData(thisId, thisLabel);
|
731
748
|
}
|
732
|
-
|
749
|
+
|
733
750
|
$('#' + modalDialogId).modal('hide');
|
734
|
-
|
735
|
-
});
|
751
|
+
|
752
|
+
});
|
736
753
|
};
|
737
|
-
|
754
|
+
|
738
755
|
// opens modal dialog
|
739
756
|
var openModalDialog = function (modalDialogId) {
|
740
757
|
$('#' + modalDialogId).dialog("open");
|
741
758
|
};
|
742
|
-
|
759
|
+
|
743
760
|
// starting generate modial dialog
|
744
761
|
var generateModalDialog = function (textField) {
|
745
762
|
options['modalId'] = generateAnId('model-dialog')
|
746
763
|
if (options.bootstrap) {
|
747
764
|
if (options.type == 'simple') {
|
748
|
-
$(generateExpander()).appendTo('#' + container + ' > div.container-combo-auto-box-bootstrap');
|
765
|
+
$(generateExpander()).appendTo('#' + container + ' > div.container-combo-auto-box-bootstrap');
|
749
766
|
} else {
|
750
|
-
$(generateExpander()).prependTo('#' + container + ' > div.container-combo-auto-box-bootstrap');
|
767
|
+
$(generateExpander()).prependTo('#' + container + ' > div.container-combo-auto-box-bootstrap');
|
751
768
|
}
|
752
769
|
generateBootstrapDialogModal(options['modalId']);
|
753
770
|
} else {
|
754
771
|
$(generateExpander()).prependTo('#' + container + ' > div.container-combo-auto-box');
|
755
|
-
adjustExpanderImage();
|
772
|
+
adjustExpanderImage();
|
756
773
|
generateDivDialogModal(options['modalId']);
|
757
774
|
}
|
758
|
-
|
775
|
+
|
759
776
|
};
|
760
|
-
|
777
|
+
|
761
778
|
// add multiple item
|
762
779
|
var addMultipleItem = function (inputId, selectedId, selectedData) {
|
763
780
|
var targetId = (options.html.name + selectedId).replace(/[^A-Za-z0-9]/g, '_');
|
764
781
|
if ((selectedData != '') && ($('#' + targetId).length == 0)) {
|
765
782
|
var id = generateAnId('item');
|
766
783
|
$('#' + inputId).before('<div class="item" id="' + id + '">'+ htmlSafe(selectedData) +'<span class="remove_item" title="Remove Item">x</span><input type="hidden" name="'+ options.html.name +'[]" value="'+ htmlSafe(selectedId.toString()) +'" id=' + targetId + '></div>');
|
767
|
-
|
784
|
+
|
768
785
|
$('#' + id + ' > span').click(function() {
|
769
786
|
$(this).parent().remove();
|
770
787
|
unselectData(selectedId, selectedData);
|
771
788
|
});
|
772
789
|
}
|
773
790
|
};
|
774
|
-
|
791
|
+
|
775
792
|
// remove multiple item
|
776
793
|
var removeLastMultipleItem = function () {
|
777
794
|
if ($('#' + container + ' > div.multiple > div.item').length > 0) {
|
@@ -781,7 +798,7 @@ var ComboAutoBox = {
|
|
781
798
|
unselectData(value, label);
|
782
799
|
}
|
783
800
|
};
|
784
|
-
|
801
|
+
|
785
802
|
// add searchable item for ransack
|
786
803
|
var addSearchableItemForRansack = function (inputId, selectedId, selectedData) {
|
787
804
|
if (selectedData != '') {
|
@@ -795,14 +812,14 @@ var ComboAutoBox = {
|
|
795
812
|
fieldValue = '<input type="hidden" name="q[g]['+ predicate['attribute'] +'][c]['+ ransackId +'][v][0][value]" value="'+ htmlSafe(getSearchableValue(selectedData)) +'">';
|
796
813
|
var id = generateAnId('item');
|
797
814
|
$('#' + inputId).before('<div class="item" id="' + id + '">'+ htmlSafe(selectedData) +'<span class="remove_item" title="Remove Item">x</span>'+ fieldAttribute + fieldCondition + fieldValue +'</div>');
|
798
|
-
|
815
|
+
|
799
816
|
$('#' + id + ' > span').click(function() {
|
800
817
|
$(this).parent().remove();
|
801
818
|
unselectData(selectedId, selectedData);
|
802
819
|
});
|
803
820
|
}
|
804
821
|
};
|
805
|
-
|
822
|
+
|
806
823
|
var removeLastSearchableItemForRansack = function() {
|
807
824
|
if ($('#' + container + ' > div.searchable > div.item').length > 0) {
|
808
825
|
var label = $('#' + container + ' > div.searchable > div.item:last > input[name*="value"]').val();
|
@@ -810,23 +827,23 @@ var ComboAutoBox = {
|
|
810
827
|
var condition = $('#' + container + ' > div.searchable > div.item:last > input[name*="p"]').val();
|
811
828
|
$('#' + container + ' > div.searchable > div.item:last').remove();
|
812
829
|
unselectData(attribute + "_" + condition, label);
|
813
|
-
}
|
830
|
+
}
|
814
831
|
}
|
815
|
-
|
832
|
+
|
816
833
|
// add searchable item
|
817
|
-
var addSearchableItem = function (inputId, selectedId, selectedData) {
|
834
|
+
var addSearchableItem = function (inputId, selectedId, selectedData) {
|
818
835
|
if (selectedData != '') {
|
819
836
|
var id = generateAnId('item');
|
820
837
|
$('#' + inputId).before('<div class="item" id="' + id + '">'+ htmlSafe(selectedData) +'<span title="Remove Item">x</span><input type="hidden" name="'+ options.html.name +'['+ htmlSafe(selectedId.toString()) +'][]" value="'+ htmlSafe(getSearchableValue(selectedData)) +'"></div>');
|
821
|
-
|
838
|
+
|
822
839
|
$('#' + id + ' > span').click(function() {
|
823
840
|
$(this).parent().remove();
|
824
841
|
unselectData(selectedId, selectedData);
|
825
842
|
});
|
826
|
-
|
843
|
+
|
827
844
|
}
|
828
845
|
};
|
829
|
-
|
846
|
+
|
830
847
|
// return json with attribute and condition
|
831
848
|
var getSearchablePredicate = function (selectedId) {
|
832
849
|
var fields = $.map(options.source, function(val, i) { return val['id']}).join('|');
|
@@ -836,7 +853,7 @@ var ComboAutoBox = {
|
|
836
853
|
var full = getSearchableLabelForAttributeId(matched[1]) + ' ' + getSearchableLabelForConditionId(matched[2]);
|
837
854
|
return { attribute: matched[1], condition: matched[2], full: full };
|
838
855
|
}
|
839
|
-
|
856
|
+
|
840
857
|
// get only the value from selected Data
|
841
858
|
var getSearchableValue = function (selectedData) {
|
842
859
|
var fields = $.map(options.source, function(val, i) { return val['label']}).join('|');
|
@@ -848,7 +865,7 @@ var ComboAutoBox = {
|
|
848
865
|
return null;
|
849
866
|
}
|
850
867
|
}
|
851
|
-
|
868
|
+
|
852
869
|
var getSearchableLabelForAttributeId = function (attibuteId) {
|
853
870
|
for(var i=0; i<options.source.length;i++) {
|
854
871
|
if (options.source[i]['id'] == attibuteId) {
|
@@ -865,7 +882,7 @@ var ComboAutoBox = {
|
|
865
882
|
}
|
866
883
|
}
|
867
884
|
}
|
868
|
-
|
885
|
+
|
869
886
|
var htmlSafe = function(html) {
|
870
887
|
html = html.replace(/\&/g, '&');
|
871
888
|
html = html.replace(/\</g, '<');
|
@@ -873,26 +890,26 @@ var ComboAutoBox = {
|
|
873
890
|
html = html.replace(/\"/g, '"');
|
874
891
|
html = html.replace(/\'/g, ''');
|
875
892
|
html = html.replace(/\//g, '/');
|
876
|
-
|
893
|
+
|
877
894
|
return html;
|
878
895
|
}
|
879
|
-
|
896
|
+
|
880
897
|
// Bind click on div for multiple or searchble
|
881
898
|
var bindContainerClick = function(inputId) {
|
882
899
|
$('#' + container + ' > div.multiple').click(function() {
|
883
900
|
$('#' + inputId).focus();
|
884
|
-
});
|
885
|
-
|
901
|
+
});
|
902
|
+
|
886
903
|
$('#' + container + ' > div.searchable').click(function() {
|
887
904
|
$('#' + inputId).focus();
|
888
|
-
});
|
905
|
+
});
|
889
906
|
};
|
890
|
-
|
907
|
+
|
891
908
|
var normalizeStyles = function(inputId) {
|
892
909
|
$('#' + container).css('background-color', $('#' + inputId).css('background-color'));
|
893
910
|
$('#' + inputId).css('border', '0px');
|
894
911
|
}
|
895
|
-
|
912
|
+
|
896
913
|
// on select data
|
897
914
|
var selectData = function (selectedId, selectedLabel) {
|
898
915
|
if (options.complete != null) {
|
@@ -902,14 +919,14 @@ var ComboAutoBox = {
|
|
902
919
|
}
|
903
920
|
|
904
921
|
};
|
905
|
-
|
922
|
+
|
906
923
|
// on unselect data
|
907
924
|
var unselectData = function (selectedId, selectedLabel) {
|
908
925
|
if (options.unselect != null) {
|
909
926
|
options.unselect(selectedId, selectedLabel);
|
910
927
|
}
|
911
928
|
};
|
912
|
-
|
929
|
+
|
913
930
|
// valid language or set 'en' as default
|
914
931
|
var validLanguage = function () {
|
915
932
|
var langs = ['math', 'en', 'pt-br', 'pt', 'es', 'fr', 'it'];
|
@@ -919,14 +936,14 @@ var ComboAutoBox = {
|
|
919
936
|
return true;
|
920
937
|
}
|
921
938
|
} catch (error) {
|
922
|
-
|
939
|
+
|
923
940
|
}
|
924
941
|
}
|
925
|
-
|
942
|
+
|
926
943
|
options.lang = 'en';
|
927
944
|
return true;
|
928
945
|
};
|
929
|
-
|
946
|
+
|
930
947
|
// valid language or set 'en' as default
|
931
948
|
var validType = function () {
|
932
949
|
var types = ['simple', 'full', 'multiple', 'searchable'];
|
@@ -935,16 +952,16 @@ var ComboAutoBox = {
|
|
935
952
|
return true;
|
936
953
|
}
|
937
954
|
}
|
938
|
-
|
955
|
+
|
939
956
|
options.type = 'simple';
|
940
957
|
return true;
|
941
958
|
};
|
942
|
-
|
959
|
+
|
943
960
|
// valid sources for only and except
|
944
961
|
var validSource = function (source) {
|
945
962
|
operators = i18nMath('math');
|
946
963
|
validIndexes = new Array();
|
947
|
-
|
964
|
+
|
948
965
|
if (((source['only'] != null) && (source['except'] != null)) || ((source['only'] == null) && (source['except'] == null))) {
|
949
966
|
for(var i=0; i<operators.length;i++) {
|
950
967
|
validIndexes.push(i);
|
@@ -954,7 +971,7 @@ var ComboAutoBox = {
|
|
954
971
|
if ((source['only'].indexOf(operators[i]['id']) + source['only'].indexOf(operators[i]['label'])) >= -1) {
|
955
972
|
validIndexes.push(i);
|
956
973
|
}
|
957
|
-
}
|
974
|
+
}
|
958
975
|
} else if (source['except'] != null) {
|
959
976
|
for(var i=0; i<operators.length;i++) {
|
960
977
|
if ((source['except'].indexOf(operators[i]['id']) + source['except'].indexOf(operators[i]['label'])) == -2) {
|
@@ -962,10 +979,10 @@ var ComboAutoBox = {
|
|
962
979
|
}
|
963
980
|
}
|
964
981
|
}
|
965
|
-
|
982
|
+
|
966
983
|
return validIndexes;
|
967
984
|
}
|
968
|
-
|
985
|
+
|
969
986
|
var handleMultipleInitials = function() {
|
970
987
|
if (options.initials != null) {
|
971
988
|
$.each(options.initials, function(index) {
|
@@ -981,13 +998,13 @@ var ComboAutoBox = {
|
|
981
998
|
});
|
982
999
|
}
|
983
1000
|
}
|
984
|
-
|
1001
|
+
|
985
1002
|
var getSourceNotFound = function(value) {
|
986
1003
|
var pattern = new RegExp('^"(' + value + ')"', 'i');
|
987
1004
|
var matched = value.match(pattern);
|
988
1005
|
return matched[1];
|
989
1006
|
}
|
990
|
-
|
1007
|
+
|
991
1008
|
var selectAllData = function(container, modalDialogId) {
|
992
1009
|
var inputId = $('#' + container + ' > div.container-combo-auto-box > input').attr('id');
|
993
1010
|
if (options.bootstrap) {
|
@@ -996,7 +1013,7 @@ var ComboAutoBox = {
|
|
996
1013
|
} else {
|
997
1014
|
$('#' + modalDialogId).dialog('close');
|
998
1015
|
}
|
999
|
-
|
1016
|
+
|
1000
1017
|
$.each(options.source, function( index, value ){
|
1001
1018
|
selectData(value.id, value.label);
|
1002
1019
|
addMultipleItem(inputId, value.id, value.label);
|
@@ -1004,12 +1021,12 @@ var ComboAutoBox = {
|
|
1004
1021
|
}
|
1005
1022
|
|
1006
1023
|
validLanguage();
|
1007
|
-
|
1024
|
+
|
1008
1025
|
// main
|
1009
1026
|
if (options == null) {
|
1010
1027
|
options = {};
|
1011
1028
|
}
|
1012
|
-
|
1029
|
+
|
1013
1030
|
options.source_not_found = false;
|
1014
1031
|
|
1015
1032
|
if (options.not_found_message == null) {
|
@@ -1019,34 +1036,34 @@ var ComboAutoBox = {
|
|
1019
1036
|
if (options.not_found_accepted == null) {
|
1020
1037
|
options.not_found_accepted = false;
|
1021
1038
|
}
|
1022
|
-
|
1039
|
+
|
1023
1040
|
if (options.bootstrap == null) {
|
1024
1041
|
options.bootstrap = false;
|
1025
1042
|
}
|
1026
|
-
|
1043
|
+
|
1027
1044
|
if (options.style == null) {
|
1028
1045
|
options.style = "mail";
|
1029
1046
|
}
|
1030
|
-
|
1047
|
+
|
1031
1048
|
if (options.email == null) {
|
1032
1049
|
options.email = false
|
1033
1050
|
}
|
1034
|
-
|
1051
|
+
|
1035
1052
|
validType();
|
1036
|
-
|
1053
|
+
|
1037
1054
|
$('#' + container).html(generateDivTag());
|
1038
|
-
|
1055
|
+
|
1039
1056
|
if (options.bootstrap) {
|
1040
1057
|
textField = $('#' + container + ' > div.container-combo-auto-box-bootstrap > input');
|
1041
1058
|
} else {
|
1042
1059
|
textField = $('#' + container + ' > div.container-combo-auto-box > input');
|
1043
1060
|
}
|
1044
1061
|
bindAutoComplete(textField.attr('id'));
|
1045
|
-
|
1062
|
+
|
1046
1063
|
if (options.type == 'simple') {
|
1047
1064
|
generateModalDialog(textField);
|
1048
1065
|
}
|
1049
|
-
|
1066
|
+
|
1050
1067
|
if (options.type == 'multiple') {
|
1051
1068
|
generateModalDialog(textField);
|
1052
1069
|
bindContainerClick(textField.attr('id'));
|
@@ -1062,4 +1079,3 @@ var ComboAutoBox = {
|
|
1062
1079
|
|
1063
1080
|
}
|
1064
1081
|
}
|
1065
|
-
|
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.
|
4
|
+
version: 0.0.49
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adilson Chacon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|