visual_condition_builder 2.1.3 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7bd746c4a51174047bd1f502175d0c7ec290d5f
4
- data.tar.gz: 085a8891eb6e9463723e88ada7acaee3237785d6
3
+ metadata.gz: e5d6d3d0c9810d4ef5e4be6dc926b789fea06d30
4
+ data.tar.gz: 5df8bfae621f5c89746721e936e5028059a11c39
5
5
  SHA512:
6
- metadata.gz: b1c8e5a9583dbd1b38763be95cf4af04e0bc3bb39cd63c1893893b726d05ca6f24dc633e6b2ff26153f0ba6a4cebb4e753610cf5b1103f4daeaef342c2a54d07
7
- data.tar.gz: 3b4fcdbf826ab6844ab500464cf23412f3a93fdf7f1d058734fc19207c928c9d602a2738b21dbe1befcbf10cef243f95d08269d2b01b5b018ecc8a252176e6dd
6
+ metadata.gz: 2c6c65c06247ac075cdbd6124d9749f285c247c60fdf90fedcda4a319237d6ae0d2cc08b0d597744b3523c3342bdbf979b4e485b47bd5c676773f43f38120753
7
+ data.tar.gz: f25e00e1db7d7d1da10accfec93a8ea85c634bc69e399f5233de4d48b45b022f4f560eeae3a400aa038b7bfc9d04ba2eb4f731358553cb418a63b68c5c58e3b8
@@ -39,41 +39,45 @@
39
39
  //~~~ PUBLIC
40
40
  plugin.add_condition = function (field_name) {
41
41
  var fieldObj = getFieldByName(field_name);
42
- if (typeof fieldObj !== 'object') {
43
- return;
44
- }
45
-
46
42
  var new_id = new Date().getTime();
43
+ var $elField, $elOperators, $elValues;
47
44
 
48
45
  //BLOCK ELEMENTS HTML
49
- var block = $('<div id="group_conditions_'+new_id+'" data-id="'+new_id+'" class="group-conditions clearfix"></div>');
46
+ var block = $('<div id="group_conditions_' + new_id + '" data-id="' + new_id + '" class="group-conditions clearfix"></div>');
50
47
  block.append('<span class="conditions-move"></span>');
51
- var field_label = fieldObj.label;
52
- if (!is_blank(fieldObj.group)) {
53
- field_label = Object.values(fieldObj.group)[0] + ' : ' + field_label;
54
- }
55
48
 
56
- block.append('<input id="field_'+new_id+'" data-group-id="'+new_id+'" type="hidden" class="field form-control" value="' + fieldObj.field + '" data-type="' + fieldObj.type + '" />');
57
- block.append('<span id="field_name_'+new_id+'" data-group-id="'+new_id+'" class="field_name label label-info">' + field_label + ' <a href="" id="remove_condition_'+new_id+'" data-group-id="'+new_id+'" class="remove-condition">&#10006;</a></span>');
58
- block.append('<select id="operators_'+new_id+'" data-group-id="'+new_id+'" class="operators hide form-control"></select>');
59
- block.append('<span id="fixed_operator_'+new_id+'" data-group-id="'+new_id+'" class="fixed_operator hide form-control"></span>');
60
- block.append('<select id="values_'+new_id+'" data-group-id="'+new_id+'" class="values hide form-control"></select>');
61
- block.append('<input id="fixed_value_'+new_id+'" data-group-id="'+new_id+'" class="fixed_value hide form-control" />');
62
- if (plugin.parameters.debug == true) {
63
- block.append('<p class="expression help-block"></p>');
64
- }
65
- $elField = block.find('#field_'+new_id);
66
- $elOperators = block.find('#operators_'+new_id);
67
- $elValues = block.find('#values_'+new_id+', #fixed_value_'+new_id);
49
+ if (typeof fieldObj !== 'object') {
50
+ block.append('<span id="field_name_' + new_id + '" data-group-id="' + new_id + '" class="field_name label label-danger">' + field_name + ' <a href="" id="remove_condition_' + new_id + '" data-group-id="' + new_id + '" class="remove-condition">&#10006;</a></span>');
51
+ } else {
52
+ var field_label = fieldObj.label;
53
+ if (!is_blank(fieldObj.group)) {
54
+ field_label = Object.values(fieldObj.group)[0] + ' : ' + field_label;
55
+ }
56
+
57
+ block.append('<input id="field_' + new_id + '" data-group-id="' + new_id + '" type="hidden" class="field form-control" value="' + fieldObj.field + '" data-type="' + fieldObj.type + '" />');
58
+ block.append('<span id="field_name_' + new_id + '" data-group-id="' + new_id + '" class="field_name label label-info">' + field_label + ' <a href="" id="remove_condition_' + new_id + '" data-group-id="' + new_id + '" class="remove-condition">&#10006;</a></span>');
59
+ block.append('<select id="operators_' + new_id + '" data-group-id="' + new_id + '" class="operators hide form-control"></select>');
60
+ block.append('<span id="fixed_operator_' + new_id + '" data-group-id="' + new_id + '" class="fixed_operator hide form-control"></span>');
61
+ block.append('<select id="values_' + new_id + '" data-group-id="' + new_id + '" class="values hide form-control"></select>');
62
+ block.append('<input id="fixed_value_' + new_id + '" data-group-id="' + new_id + '" class="fixed_value hide form-control" />');
63
+ if (plugin.parameters.debug == true) {
64
+ block.append('<p class="expression help-block"></p>');
65
+ }
66
+ $elField = block.find('#field_' + new_id);
67
+ $elOperators = block.find('#operators_' + new_id);
68
+ $elValues = block.find('#values_' + new_id + ', #fixed_value_' + new_id);
68
69
 
69
- //EVENTS
70
- block.find('#remove_condition_'+new_id).on('click', event_remove_condition);
71
- $elOperators.on('change', event_load_values);
70
+ //EVENTS
71
+ block.find('#remove_condition_' + new_id).on('click', event_remove_condition);
72
+ $elOperators.on('change', event_load_values);
73
+ }
72
74
 
73
75
  $element.append(block);
74
76
 
75
77
  //LOAD OPERATORS
76
- plugin.load_operators($elField);
78
+ if (typeof $elField != 'undefined') {
79
+ plugin.load_operators($elField);
80
+ }
77
81
 
78
82
  return block;
79
83
 
@@ -87,14 +91,17 @@
87
91
  };
88
92
 
89
93
  plugin.load_operators = function (fieldEl) {
94
+ if (typeof fieldEl == 'undefined') {
95
+ return;
96
+ }
90
97
  var $fieldElement = $(fieldEl);
91
98
  var groupConditionId = $fieldElement.attr('data-group-id');
92
99
  var field_name = getFieldValue($fieldElement);
93
100
  var field = getFieldByName(field_name);
94
- var $operators = $('#operators_'+groupConditionId);
95
- var $fixedOperator = $('#fixed_operator_'+groupConditionId);
96
- var $values = $('.values_'+groupConditionId);
97
- var $fixedValue = $('.fixed_value_'+groupConditionId);
101
+ var $operators = $('#operators_' + groupConditionId);
102
+ var $fixedOperator = $('#fixed_operator_' + groupConditionId);
103
+ var $values = $('.values_' + groupConditionId);
104
+ var $fixedValue = $('.fixed_value_' + groupConditionId);
98
105
  var operators = field.operators;
99
106
 
100
107
  remove_plugins_elements(groupConditionId);
@@ -119,13 +126,13 @@
119
126
  plugin.fill_condition = function (groupConditionId, data) {
120
127
  if (data != undefined && data.length > 0 && groupConditionId != undefined) {
121
128
  var groupConditions = getGroupConditionById(groupConditionId)
122
- $elOperators = getOperatorElement(groupConditions);
129
+ var $elOperators = getOperatorElement(groupConditions);
123
130
  $elOperators.val(data[1]).trigger('change');
124
131
 
125
- $elOperator = $elOperators.find('option:selected');
132
+ var $elOperator = $elOperators.find('option:selected');
126
133
  var multiple = $elOperator.attr('data-multiple');
127
134
 
128
- $elValues = getValueElement(groupConditions);
135
+ var $elValues = getValueElement(groupConditions);
129
136
  if ($elValues.length > 1) {
130
137
  var values = (typeof data[2] == 'string') ? [data[2]] : data[2];
131
138
  $.each($elValues, function (i, elValue) {
@@ -140,7 +147,7 @@
140
147
  }
141
148
  });
142
149
  $elValues.val(values).trigger('change');
143
- triggerEl = false;
150
+ // triggerEl = false;
144
151
  }
145
152
  } else {
146
153
  $elValues.val(data[2]);
@@ -153,14 +160,14 @@
153
160
  if (typeof values == 'string' && !is_blank(values)) {
154
161
  plugin.parameters.values = getJson(values);
155
162
  } else if (is_blank(values) && !is_blank(plugin.parameters.input)) {
156
- $elInput = $(plugin.parameters.input);
163
+ var $elInput = $(plugin.parameters.input);
157
164
  if ($elInput.length > 0 && !is_blank($elInput.val())) {
158
165
  plugin.parameters.values = JSON.parse($elInput.val());
159
166
  }
160
167
  } else {
161
168
  plugin.parameters.values = values;
162
169
  }
163
- if (plugin.parameters.show==true) {
170
+ if (plugin.parameters.show == true) {
164
171
  show_rows();
165
172
  } else {
166
173
  build_rows();
@@ -172,7 +179,7 @@
172
179
  if ($elInput.length > 0) {
173
180
  try {
174
181
  plugin.parameters.values = JSON.parse($elInput.val());
175
- } catch(e) {
182
+ } catch (e) {
176
183
  plugin.parameters.values = '';
177
184
  }
178
185
  }
@@ -200,7 +207,7 @@
200
207
 
201
208
  //~~~ PRIVATE
202
209
  var getGroupConditionById = function (groupConditionId) {
203
- return $('#group_conditions_'+groupConditionId);
210
+ return $('#group_conditions_' + groupConditionId);
204
211
  }; //END getFieldElement
205
212
 
206
213
  var getFieldByName = function (field_name) {
@@ -246,13 +253,18 @@
246
253
  }; //END getFieldElement
247
254
 
248
255
  var getFieldValue = function (element) {
256
+ if (typeof element == 'undefined') {
257
+ return;
258
+ }
249
259
  var value;
250
260
  var $el = $(element);
251
261
  if ($el.hasClass('field')) {
252
262
  value = $el.val();
253
263
  } else {
254
264
  var el = getFieldElement(element);
255
- value = !is_blank(el) ? getFieldValue(el) : '';
265
+ if (el.length > 0) {
266
+ value = !is_blank(el) ? getFieldValue(el) : '';
267
+ }
256
268
  }
257
269
  return value;
258
270
  }; //END getFieldValue
@@ -351,10 +363,10 @@
351
363
  $.each(plugin.parameters.values, function (i, data) {
352
364
  var fieldObj = getFieldByName(data[0]);
353
365
  var operatorObj = getOperatorFromField(data[1], fieldObj.operators);
354
- var $listItem = $('<li></li>');
355
- $listItem.append('<span class="pr-2">'+getLabel(fieldObj)+'</span>');
356
- $listItem.append('<span class="pr-2">'+getLabel(operatorObj)+'</span>');
357
- $listItem.append('<span class="">'+data[2]+'</span>');
366
+ var $listItem = $('<li></li>');
367
+ $listItem.append('<span class="pr-2">' + getLabel(fieldObj) + '</span>');
368
+ $listItem.append('<span class="pr-2">' + getLabel(operatorObj) + '</span>');
369
+ $listItem.append('<span class="">' + data[2] + '</span>');
358
370
  $listItem.appendTo($listUl);
359
371
  });
360
372
  $element.append($listUl);
@@ -367,8 +379,10 @@
367
379
  $.each(plugin.parameters.values, function (i, data) {
368
380
  var field = data[0];
369
381
  var groupConditions = plugin.add_condition(field);
370
- var groupConditionId = groupConditions.attr('data-id');
371
- plugin.fill_condition(groupConditionId, data);
382
+ if (typeof groupConditions != 'undefined') {
383
+ var groupConditionId = groupConditions.attr('data-id');
384
+ plugin.fill_condition(groupConditionId, data);
385
+ }
372
386
  });
373
387
  }
374
388
  };
@@ -423,7 +437,7 @@
423
437
  normalize_values_type(groupConditionId, list_with_item, multiple);
424
438
  }; //END build_values
425
439
 
426
- var validate_multiple_values = function(groupConditionId) {
440
+ var validate_multiple_values = function (groupConditionId) {
427
441
  var $groupConditions = getGroupConditionById(groupConditionId);
428
442
  var $operatorEl = getOperatorElement($groupConditions);
429
443
  var $valueEl = getValueElement($groupConditions);
@@ -447,7 +461,7 @@
447
461
  }; //END validate_multiple_values
448
462
 
449
463
  var remove_plugins_elements = function (groupConditionId) {
450
- $groupConditions = getGroupConditionById(groupConditionId);
464
+ var $groupConditions = getGroupConditionById(groupConditionId);
451
465
  $groupConditions.find('.fixed_value[class*="select2-"], .values[class*="select2-"]').select2('destroy');
452
466
  $groupConditions.find('.values.clone, .fixed_value.clone').remove();
453
467
  }; //END remove_plugins_elements
@@ -574,7 +588,7 @@
574
588
  var build_select2_element = function (el, tags) {
575
589
  if (tags == undefined) tags = true;
576
590
  var $el = $(el);
577
- var select2Config = $.extend({},plugin.parameters.select2Config);
591
+ var select2Config = $.extend({}, plugin.parameters.select2Config);
578
592
  var ajax_url = $el.attr('data-ajax-values');
579
593
 
580
594
  if (ajax_url !== undefined) {
@@ -609,7 +623,7 @@
609
623
  data: {init: initVal}
610
624
  }).done(function (data) {
611
625
  var row = $.isArray(data) ? data[0] : data;
612
- if (row!==undefined && row.id!==undefined && row.label!==undefined) {
626
+ if (row !== undefined && row.id !== undefined && row.label !== undefined) {
613
627
  callback({id: row.id, text: row.label});
614
628
  } else {
615
629
  callback({id: initVal, text: initVal});
@@ -628,7 +642,7 @@
628
642
  $.extend(select2Config, {placeholder: plugin.parameters.placeholder.values});
629
643
  }
630
644
  if (tags == true) {
631
- $.extend(select2Config, {tags: true, tokenSeparators: [',',';']});
645
+ $.extend(select2Config, {tags: true, tokenSeparators: [',', ';']});
632
646
  }
633
647
 
634
648
  $.fn.select2.defaults.set("theme", (select2Config.theme || 'bootstrap'));
@@ -685,16 +699,15 @@ $(document).on('click', '.add-condition-field', function (ev) {
685
699
  var container = $(this).closest('.add-condition').attr('data-target');
686
700
  var field_name = $(this).attr('data-field');
687
701
  var $conditionBuilder = $(container).data('conditionBuilder');
688
- console.log('a');
689
702
  $conditionBuilder.add_condition(field_name);
690
703
  });
691
704
 
692
705
  //DROPDOWN WITH SEARCH
693
- $(document).on('keyup','.dropdown-filter-control', function(ev){
706
+ $(document).on('keyup', '.dropdown-filter-control', function (ev) {
694
707
  var ulEl = $(this).closest('ul.dropdown-menu');
695
708
  var searchTerm = $(this).val().toLowerCase();
696
- ulEl.find('li.dropdown-menu-item').each(function(){
697
- var filter = $(this).filter(function() {
709
+ ulEl.find('li.dropdown-menu-item').each(function () {
710
+ var filter = $(this).filter(function () {
698
711
  return $(this).attr('data-search-term').toLowerCase().indexOf(searchTerm) > -1;
699
712
  });
700
713
  // $(this).filter('[data-search-term *= ' + searchTerm + ']')
@@ -1,3 +1,3 @@
1
1
  module VisualConditionBuilder
2
- VERSION = "2.1.3"
2
+ VERSION = "2.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: visual_condition_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Porto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-27 00:00:00.000000000 Z
11
+ date: 2017-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails