combo_auto_box 0.0.7 → 0.0.8
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.
| 
         @@ -4,7 +4,7 @@ var ComboAutoBox = { 
     | 
|
| 
       4 
4 
     | 
    
         
             
            		// generatea an ID based on current time
         
     | 
| 
       5 
5 
     | 
    
         
             
            		var generateShortId = function(prefix) {
         
     | 
| 
       6 
6 
     | 
    
         
             
            			var now = 0;
         
     | 
| 
       7 
     | 
    
         
            -
            			while ($(" 
     | 
| 
      
 7 
     | 
    
         
            +
            			while ($('input[name*="[' + prefix +"-" + now + ']"]').length != 0) {
         
     | 
| 
       8 
8 
     | 
    
         
             
            				now++;
         
     | 
| 
       9 
9 
     | 
    
         
             
            			}
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
         @@ -46,7 +46,17 @@ var ComboAutoBox = { 
     | 
|
| 
       46 
46 
     | 
    
         
             
            						addItem(inputId, $('#' + inputId).val(), $('#' + inputId).val());
         
     | 
| 
       47 
47 
     | 
    
         
             
            						selectData($('#' + inputId).val());
         
     | 
| 
       48 
48 
     | 
    
         
             
            						$('#' + inputId).val('');
         
     | 
| 
       49 
     | 
    
         
            -
            					} 
         
     | 
| 
      
 49 
     | 
    
         
            +
            					} else if ((options.type == 'searchable') && ($('#' + inputId).val()) != '') {
         
     | 
| 
      
 50 
     | 
    
         
            +
            						try {
         
     | 
| 
      
 51 
     | 
    
         
            +
            							var item = sourceForSearchable(inputId)[0];
         
     | 
| 
      
 52 
     | 
    
         
            +
            							addSearchableItemForRansack(inputId, item.id, item.label);
         
     | 
| 
      
 53 
     | 
    
         
            +
            							selectData(item.id);
         
     | 
| 
      
 54 
     | 
    
         
            +
            							$('#' + inputId).val('');
         
     | 
| 
      
 55 
     | 
    
         
            +
            							$('#' + inputId).autocomplete('close');
         
     | 
| 
      
 56 
     | 
    
         
            +
            						} catch (error) {
         
     | 
| 
      
 57 
     | 
    
         
            +
            							
         
     | 
| 
      
 58 
     | 
    
         
            +
            						}
         
     | 
| 
      
 59 
     | 
    
         
            +
            					}
         
     | 
| 
       50 
60 
     | 
    
         
             
            					return false;
         
     | 
| 
       51 
61 
     | 
    
         
             
            				}
         
     | 
| 
       52 
62 
     | 
    
         
             
            			});
         
     | 
| 
         @@ -89,17 +99,7 @@ var ComboAutoBox = { 
     | 
|
| 
       89 
99 
     | 
    
         
             
            		// set autocomplete source
         
     | 
| 
       90 
100 
     | 
    
         
             
            		var setAutoCompleteSource = function (inputId) {
         
     | 
| 
       91 
101 
     | 
    
         
             
            			if (options.type == 'searchable') {
         
     | 
| 
       92 
     | 
    
         
            -
            				 
     | 
| 
       93 
     | 
    
         
            -
            				var operators = i18nMath(options.lang);
         
     | 
| 
       94 
     | 
    
         
            -
            				$.each(options.source, function(i){
         
     | 
| 
       95 
     | 
    
         
            -
            					validIndexes = validSource(options.source[i]);
         
     | 
| 
       96 
     | 
    
         
            -
            					$.each(operators, function(j){
         
     | 
| 
       97 
     | 
    
         
            -
            						if (validIndexes.indexOf(j) >= 0) {
         
     | 
| 
       98 
     | 
    
         
            -
            							new_source.push( { id: options.source[i]['id'] + '_' + operators[j]['id'], label: options.source[i]['label'] + ' ' + operators[j]['label'] + ' ' + $('#' + inputId).val()} );
         
     | 
| 
       99 
     | 
    
         
            -
            						}
         
     | 
| 
       100 
     | 
    
         
            -
            					});
         
     | 
| 
       101 
     | 
    
         
            -
            				});
         
     | 
| 
       102 
     | 
    
         
            -
            				return new_source;
         
     | 
| 
      
 102 
     | 
    
         
            +
            				return sourceForSearchable(inputId);
         
     | 
| 
       103 
103 
     | 
    
         
             
            			} else if (typeof options.source == 'string') {
         
     | 
| 
       104 
104 
     | 
    
         
             
            				return function(request, response) {
         
     | 
| 
       105 
105 
     | 
    
         
             
            					var term = 'term=' + $('#' + inputId).val();
         
     | 
| 
         @@ -110,6 +110,21 @@ var ComboAutoBox = { 
     | 
|
| 
       110 
110 
     | 
    
         
             
            				return options.source;
         
     | 
| 
       111 
111 
     | 
    
         
             
            			}
         
     | 
| 
       112 
112 
     | 
    
         
             
            		};
         
     | 
| 
      
 113 
     | 
    
         
            +
            		
         
     | 
| 
      
 114 
     | 
    
         
            +
            		// source items for searchable
         
     | 
| 
      
 115 
     | 
    
         
            +
            		var sourceForSearchable = function (inputId) {
         
     | 
| 
      
 116 
     | 
    
         
            +
            			var new_source = new Array();
         
     | 
| 
      
 117 
     | 
    
         
            +
            			var operators = i18nMath(options.lang);
         
     | 
| 
      
 118 
     | 
    
         
            +
            			$.each(options.source, function(i){
         
     | 
| 
      
 119 
     | 
    
         
            +
            				validIndexes = validSource(options.source[i]);
         
     | 
| 
      
 120 
     | 
    
         
            +
            				$.each(operators, function(j){
         
     | 
| 
      
 121 
     | 
    
         
            +
            					if (validIndexes.indexOf(j) >= 0) {
         
     | 
| 
      
 122 
     | 
    
         
            +
            						new_source.push( { id: options.source[i]['id'] + '_' + operators[j]['id'], label: options.source[i]['label'] + ' ' + operators[j]['label'] + ' ' + $('#' + inputId).val()} );
         
     | 
| 
      
 123 
     | 
    
         
            +
            					}
         
     | 
| 
      
 124 
     | 
    
         
            +
            				});
         
     | 
| 
      
 125 
     | 
    
         
            +
            			});
         
     | 
| 
      
 126 
     | 
    
         
            +
            			return new_source;			
         
     | 
| 
      
 127 
     | 
    
         
            +
            		}
         
     | 
| 
       113 
128 
     | 
    
         | 
| 
       114 
129 
     | 
    
         
             
            		// get i18n math comparisons
         
     | 
| 
       115 
130 
     | 
    
         
             
            		var i18nMath = function (language) {
         
     | 
| 
         @@ -283,7 +298,7 @@ var ComboAutoBox = { 
     | 
|
| 
       283 
298 
     | 
    
         
             
            		var addItem = function (inputId, selectedId, selectedData) {
         
     | 
| 
       284 
299 
     | 
    
         
             
            			if (selectedData != '') {
         
     | 
| 
       285 
300 
     | 
    
         
             
            				var id = generateAnId('item');
         
     | 
| 
       286 
     | 
    
         
            -
            				$('#' + inputId).before('<div class="item"  
     | 
| 
      
 301 
     | 
    
         
            +
            				$('#' + inputId).before('<div class="item" id="' + id + '">'+ selectedData +'<span title="Remove Item">x</span><input type="hidden" name="'+ options.html.name +'[]" value="'+ selectedId +'"></div>');
         
     | 
| 
       287 
302 
     | 
    
         | 
| 
       288 
303 
     | 
    
         
             
            				$('#' + id + ' > span').click(function() {
         
     | 
| 
       289 
304 
     | 
    
         
             
            					$(this).parent().remove();
         
     | 
| 
         @@ -304,7 +319,7 @@ var ComboAutoBox = { 
     | 
|
| 
       304 
319 
     | 
    
         
             
            				fieldCondition = '<input type="hidden" name="q[g]['+ predicate['attribute'] +'][c]['+ ransackId +'][p]"           value="'+ predicate['condition'] +'">';
         
     | 
| 
       305 
320 
     | 
    
         
             
            				fieldValue =     '<input type="hidden" name="q[g]['+ predicate['attribute'] +'][c]['+ ransackId +'][v][0][value]" value="'+ getSearchableValue(selectedData) +'">';
         
     | 
| 
       306 
321 
     | 
    
         
             
            				var id = generateAnId('item');
         
     | 
| 
       307 
     | 
    
         
            -
            				$('#' + inputId).before('<div class="item"  
     | 
| 
      
 322 
     | 
    
         
            +
            				$('#' + inputId).before('<div class="item" id="' + id + '">'+ selectedData +'<span title="Remove Item">x</span>'+ fieldAttribute + fieldCondition + fieldValue +'</div>');
         
     | 
| 
       308 
323 
     | 
    
         | 
| 
       309 
324 
     | 
    
         
             
            				$('#' + id + ' > span').click(function() {
         
     | 
| 
       310 
325 
     | 
    
         
             
            					$(this).parent().remove();
         
     | 
| 
         @@ -317,7 +332,7 @@ var ComboAutoBox = { 
     | 
|
| 
       317 
332 
     | 
    
         
             
            		var addSearchableItem = function (inputId, selectedId, selectedData) {			
         
     | 
| 
       318 
333 
     | 
    
         
             
            			if (selectedData != '') {
         
     | 
| 
       319 
334 
     | 
    
         
             
            				var id = generateAnId('item');
         
     | 
| 
       320 
     | 
    
         
            -
            				$('#' + inputId).before('<div class="item"  
     | 
| 
      
 335 
     | 
    
         
            +
            				$('#' + inputId).before('<div class="item" id="' + id + '">'+ selectedData +'<span title="Remove Item">x</span><input type="hidden" name="'+ options.html.name +'['+ selectedId +'][]" value="'+ getSearchableValue(selectedData) +'"></div>');
         
     | 
| 
       321 
336 
     | 
    
         | 
| 
       322 
337 
     | 
    
         
             
            				$('#' + id + ' > span').click(function() {
         
     | 
| 
       323 
338 
     | 
    
         
             
            					$(this).parent().remove();
         
     | 
| 
         @@ -376,6 +391,11 @@ var ComboAutoBox = { 
     | 
|
| 
       376 
391 
     | 
    
         
             
            				$('#' + inputId).focus();
         
     | 
| 
       377 
392 
     | 
    
         
             
            			});			
         
     | 
| 
       378 
393 
     | 
    
         
             
            		};
         
     | 
| 
      
 394 
     | 
    
         
            +
            		
         
     | 
| 
      
 395 
     | 
    
         
            +
            		var normalizeStyles = function(inputId) {
         
     | 
| 
      
 396 
     | 
    
         
            +
            			$('#' + container).css('background-color', $('#' + inputId).css('background-color'));
         
     | 
| 
      
 397 
     | 
    
         
            +
            			$('#' + inputId).css('border', '0px');
         
     | 
| 
      
 398 
     | 
    
         
            +
            		}
         
     | 
| 
       379 
399 
     | 
    
         | 
| 
       380 
400 
     | 
    
         
             
            		// on select data
         
     | 
| 
       381 
401 
     | 
    
         
             
            		var selectData = function (selectedData) {
         
     | 
| 
         @@ -455,6 +475,7 @@ var ComboAutoBox = { 
     | 
|
| 
       455 
475 
     | 
    
         | 
| 
       456 
476 
     | 
    
         
             
            		if ((options.type == 'multiple') || (options.type == 'searchable')) {
         
     | 
| 
       457 
477 
     | 
    
         
             
            			bindContainerClick(textField.attr('id'));
         
     | 
| 
      
 478 
     | 
    
         
            +
            			normalizeStyles(textField.attr('id'));
         
     | 
| 
       458 
479 
     | 
    
         
             
            		}
         
     | 
| 
       459 
480 
     | 
    
         | 
| 
       460 
481 
     | 
    
         
             
            		if ((options.type == 'multiple') && (options.initials != null)) {
         
     | 
| 
         @@ -2,17 +2,21 @@ span.combo-auto-box-item-id { display:none; } 
     | 
|
| 
       2 
2 
     | 
    
         
             
            div.container-combo-auto-box span.simple { position:absolute;cursor:pointer;display:block;margin:0px 0px 0px 0px; width:20px; }
         
     | 
| 
       3 
3 
     | 
    
         
             
            div.container-combo-auto-box span.simple i{ background-image:url(/assets/combo_auto_box_expand.png);width:19px;height:19px;display:block;font-size:0; }
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
            div.multiple { border: 1px solid #CDCDCD; display:table; }
         
     | 
| 
      
 5 
     | 
    
         
            +
            div.multiple { border: 1px solid #CDCDCD; display:table; width:100%; }
         
     | 
| 
      
 6 
     | 
    
         
            +
            div.multiple:hover {cursor:text}
         
     | 
| 
       6 
7 
     | 
    
         
             
            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; }
         
     | 
| 
       7 
8 
     | 
    
         
             
            div.multiple input { border: 0px; float:left; height:22px; }
         
     | 
| 
       8 
9 
     | 
    
         
             
            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; }
         
     | 
| 
      
 10 
     | 
    
         
            +
            div.multiple div.item:hover { cursor:default; }
         
     | 
| 
       9 
11 
     | 
    
         
             
            div.multiple div.item span { margin-left:10px; color:#CCCCCC; }
         
     | 
| 
       10 
12 
     | 
    
         
             
            div.multiple div.item span:hover { color:#9A9A9A; cursor:pointer;}
         
     | 
| 
       11 
13 
     | 
    
         
             
            div.multiple input:focus {outline:none; }
         
     | 
| 
       12 
14 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
            div.searchable { border: 1px solid #CDCDCD; display:table; }
         
     | 
| 
      
 15 
     | 
    
         
            +
            div.searchable { border: 1px solid #CDCDCD; display:table; width:100%; }
         
     | 
| 
      
 16 
     | 
    
         
            +
            div.searchable:hover {cursor:text}
         
     | 
| 
       14 
17 
     | 
    
         
             
            div.searchable input { border: 0px; float:left; height:22px; }
         
     | 
| 
       15 
18 
     | 
    
         
             
            div.searchable div.item { font-family: arial,sans-serif; float:left; font-size: 13px; color:#FFFFFF; background-color:#008000; margin: 2px 10px 2px 2px; padding:2px 10px 2px 10px; -moz-border-radius:4px;-webkit-border-radius:4px; border:1px solid #ECECEC; }
         
     | 
| 
      
 19 
     | 
    
         
            +
            div.searchable div.item:hover { cursor:default; }
         
     | 
| 
       16 
20 
     | 
    
         
             
            div.searchable div.item span { margin-left:10px; color:#CCCCCC; }
         
     | 
| 
       17 
21 
     | 
    
         
             
            div.searchable div.item span:hover { color:#FFFFFF; cursor:pointer;}
         
     | 
| 
       18 
22 
     | 
    
         
             
            div.searchable input:focus {outline:none; }
         
     | 
    
        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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.8
         
     | 
| 
       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-07- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2013-07-19 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: activesupport
         
     |