visual_condition_builder 2.1.2 → 2.1.3

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: 258bcbf53cb35fa5811d80ab924d2a5a08e4196b
4
- data.tar.gz: 09385020d82b9437dbb18a3e010242d87eb2b681
3
+ metadata.gz: c7bd746c4a51174047bd1f502175d0c7ec290d5f
4
+ data.tar.gz: 085a8891eb6e9463723e88ada7acaee3237785d6
5
5
  SHA512:
6
- metadata.gz: 983e3adc63c7e4ecb00b2f55191d7b6cb980287f26141765f964bf9f43ff2afd582f3d87f3c08225a5fdb1404c89e4b85034893f8ace6b0dbf228cdb7ea847fd
7
- data.tar.gz: d4abea958cd6b65a1414b30754b3dafe33fa670240782cd71e60bba8b6a7e07cd6e074f61015547b47a725e82b8a0dd5c8a8cc4464c193516a51703b8652faed
6
+ metadata.gz: b1c8e5a9583dbd1b38763be95cf4af04e0bc3bb39cd63c1893893b726d05ca6f24dc633e6b2ff26153f0ba6a4cebb4e753610cf5b1103f4daeaef342c2a54d07
7
+ data.tar.gz: 3b4fcdbf826ab6844ab500464cf23412f3a93fdf7f1d058734fc19207c928c9d602a2738b21dbe1befcbf10cef243f95d08269d2b01b5b018ecc8a252176e6dd
data/README.md CHANGED
@@ -260,15 +260,14 @@ end
260
260
  #### (view) conditions_fields(name_of_dictionary)
261
261
 
262
262
  Creates a field selector in a dropdown element (bootstrap).
263
- Cria um seletor de campos em um elemento dropdown (bootstrap).
264
-
265
263
  ```haml
266
264
  = conditions_fields :example
267
265
  -# with context:
268
266
  = conditions_fields({:dictionary_name => :context_name})
269
267
  ```
270
268
 
271
- Mas você pode fazer a geração da lista de campos manualmente através do método `ExampleDictionary.fields(dictionary_name)` *(example_dictionary.rb)*, nesse caso você deve ter elementos "clicáveis" com a classe `add-condition-field` e atributo `data-field: field_name`
269
+ You can create the list item manually `ExampleDictionary.fields (dictionary_name)` *(example_dictionary.rb)*,
270
+ you must have 'clickable' elements with an `add-condition-field` class and `data-field: field_name` attribute
272
271
  ```haml
273
272
  %a.add-condition-field{href: '#', data: {field: 'name'}} Name
274
273
  %a.add-condition-field{href: '#', data: {field: 'age'}} Age
@@ -287,14 +286,20 @@ How create condition builder in you view:
287
286
  -# Conditions Element
288
287
  = build_conditions :example, input: '#my_conditions', select2Config: {allowClear: true}
289
288
  ```
289
+ Default element id: dictionary_name + context_name + condition_container: `example_default_condition_container`
290
290
 
291
- Por padrão será gerado um elemento com o id no padrão dictionary_name + context_name + condition_container: `example_default_condition_container`
292
-
293
- Para criar baseado em um dicionário de contexto específico use:
291
+ To create based on a specific context dictionary use:
294
292
  ```haml
295
293
  = build_conditions({:dictionary_name => :context_name}, input: '#my_conditions', select2Config: {allowClear: true})
296
294
  ```
297
- Os argumentos possíveis para o build_conditions são:
295
+
296
+ Its possible change `conditions_fields` title:
297
+ ```haml
298
+ = conditions_fields :example, title: 'Click here to select a field'
299
+ ```
300
+
301
+
302
+ Possible arguments for build_conditions are:
298
303
 
299
304
  Param | Description
300
305
  --- | ---
@@ -305,7 +310,7 @@ debug | to see debugs flags. default: false
305
310
  numericConfig | When the field is decimal type then the generator will create an input with numeric mask. Default {aSep: '', aDec: '.', aSign: ''}. See [Auto Numeric Plugin](https://github.com/BobKnothe/autoNumeric#default-settings--supported-options)
306
311
  select2Config: | Select2 Configuration. Default {theme: "bootstrap", width: 'auto', placeholder: '', allowClear: false, dropdownAutoWidth: 'true', tags: false, language: "en"}, but some parameters can be overwritten by condition builder. See [Select2 Plugin](https://github.com/select2/select2)
307
312
 
308
- Também é possível criar o builder manualmente chamando o plugin jquery diretamente:
313
+ You can also create the builder manually by calling the jquery plugin:
309
314
  ```javascript
310
315
  //my_dictionary_json = ExampleDictionary.dictionary(:example).to_json
311
316
  //my_initial_values = [['name','eq','My Name']]
@@ -10,6 +10,7 @@
10
10
  values: [],
11
11
  input: '',
12
12
  debug: false,
13
+ show: false,
13
14
  numericConfig: {
14
15
  aSep: '',
15
16
  aDec: '.',
@@ -51,6 +52,7 @@
51
52
  if (!is_blank(fieldObj.group)) {
52
53
  field_label = Object.values(fieldObj.group)[0] + ' : ' + field_label;
53
54
  }
55
+
54
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 + '" />');
55
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>');
56
58
  block.append('<select id="operators_'+new_id+'" data-group-id="'+new_id+'" class="operators hide form-control"></select>');
@@ -158,7 +160,11 @@
158
160
  } else {
159
161
  plugin.parameters.values = values;
160
162
  }
161
- build_rows();
163
+ if (plugin.parameters.show==true) {
164
+ show_rows();
165
+ } else {
166
+ build_rows();
167
+ }
162
168
  }; //END load_values
163
169
 
164
170
  plugin.load_values_from_input = function (element_input) {
@@ -209,6 +215,24 @@
209
215
  return f;
210
216
  }; //END getFieldByName
211
217
 
218
+ var getOperatorFromField = function (operator_name, field_name_or_operators) {
219
+ if (jQuery.isArray(field_name_or_operators)) {
220
+ var operators = field_name_or_operators;
221
+ } else {
222
+ var fieldObj = getFieldByName(field_name);
223
+ var operators = fieldObj.operators;
224
+ }
225
+ var f = $.map(operators, function (h, i) {
226
+ if (h.operator == operator_name) {
227
+ return h;
228
+ }
229
+ });
230
+ if (jQuery.isArray(f)) {
231
+ f = f[0];
232
+ }
233
+ return f;
234
+ }; //END getFieldByName
235
+
212
236
  var getLabel = function (obj) {
213
237
  if (!is_blank(obj.label)) {
214
238
  return String(obj.label);
@@ -319,6 +343,24 @@
319
343
  plugin.getResult();
320
344
  }; //END event_build_expression
321
345
 
346
+ /* UNDER CONSTRUCTION */
347
+ var show_rows = function () {
348
+ $element.find('.conditions').html('');
349
+ if (!is_blank(plugin.parameters.values) && plugin.parameters.values.length > 0) {
350
+ var $listUl = $('<ul class="list-unstyled"></ul>');
351
+ $.each(plugin.parameters.values, function (i, data) {
352
+ var fieldObj = getFieldByName(data[0]);
353
+ 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>');
358
+ $listItem.appendTo($listUl);
359
+ });
360
+ $element.append($listUl);
361
+ }
362
+ };
363
+
322
364
  var build_rows = function () {
323
365
  $element.find('.conditions').html('');
324
366
  if (!is_blank(plugin.parameters.values) && plugin.parameters.values.length > 0) {
@@ -16,12 +16,14 @@ module VisualConditionBuilder
16
16
  render partial: 'visual_condition_builder/builder_conditions', locals: {container_name: container_name, builder_options: builder_options.to_json.html_safe}
17
17
  end
18
18
 
19
- def conditions_fields(dictionary)
19
+ def conditions_fields(dictionary, title: nil)
20
20
  dictionary_name = get_dictionary_name(dictionary)
21
21
  dictionary_klass = get_dictionary_klass(dictionary)
22
- @container_name = "##{dictionary_name}_condition_container"
23
- @fields = dictionary_klass.fields(get_dictionary_context(dictionary))
24
- render partial: 'visual_condition_builder/conditions_fields'
22
+ container_id = "##{dictionary_name}_condition_container"
23
+ fields = dictionary_klass.fields(get_dictionary_context(dictionary))
24
+ title = I18n.t(:dropdown, default: ['Fields'], scope: [:condition_builder]) if title.blank?
25
+ render partial: 'visual_condition_builder/conditions_fields',
26
+ locals: {container_id: container_id, fields: fields, title: title}
25
27
  end
26
28
 
27
29
  private
@@ -1,6 +1,6 @@
1
- <div class="dropdown add-condition" data-target="<%= @container_name %>">
1
+ <div class="dropdown add-condition" data-target="<%= container_id %>">
2
2
  <button class="btn btn-default dropdown-toggle" data-toggle="dropdown", data-type="button">
3
- <%= I18n.t(:dropdown, default: ['Fields'], scope: [:condition_builder]) %>
3
+ <%= title %>
4
4
  <span class="caret"></span>
5
5
  </button>
6
6
  <ul class="dropdown-menu dropdown-menu-scrollable add-condition-menu">
@@ -8,6 +8,6 @@
8
8
  <input type="text" class="form-control dropdown-filter-control" autocomplete="off" role="textbox" aria-label="Search">
9
9
  </li>
10
10
  <li role="separator" class="divider"></li>
11
- <%= render partial: 'visual_condition_builder/conditions_fields_item', locals: {fields: @fields} %>
11
+ <%= render partial: 'visual_condition_builder/conditions_fields_item', locals: {fields: fields} %>
12
12
  </ul>
13
13
  </div>
@@ -1,3 +1,3 @@
1
1
  module VisualConditionBuilder
2
- VERSION = "2.1.2"
2
+ VERSION = "2.1.3"
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.2
4
+ version: 2.1.3
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-26 00:00:00.000000000 Z
11
+ date: 2017-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails