From 7d91b61678651e5283e64053618316e7dc7c9a20 Mon Sep 17 00:00:00 2001 From: Michele Monti Date: Mon, 14 Nov 2016 11:32:17 +0100 Subject: [PATCH 1/2] Added new type in filter rules --- Gruntfile.js | 2 +- bower.json | 7 +- examples/index.html | 20 +++++ package.json | 8 +- src/core.js | 79 ++++++++++++++++++ src/data.js | 180 ++++++++++++++++++++++++++++++++++++++++++ src/defaults.js | 56 ++++++++++++- src/scss/default.scss | 6 +- src/template.js | 96 ++++++++++++++++++++++ 9 files changed, 442 insertions(+), 12 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 36ab0d62..3704fcb6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -150,7 +150,7 @@ module.exports = function(grunt) { dev: { options: { host: '0.0.0.0', - port: 9000, + port: 9100, livereload: true } } diff --git a/bower.json b/bower.json index bf6b6519..ba495e77 100644 --- a/bower.json +++ b/bower.json @@ -1,10 +1,9 @@ { - "name": "jQuery-QueryBuilder", + "name": "bdt-jQuery-QueryBuilder", + "version": "0.1.0", "authors": [ { - "name": "Damien \"Mistic\" Sorel", - "email": "contact@git.strangeplanet.fr", - "homepage": "http://www.strangeplanet.fr" + "name": "Michele Monti" } ], "description": "jQuery plugin for user friendly query/filter creator", diff --git a/examples/index.html b/examples/index.html index 205d2a06..668ed90b 100644 --- a/examples/index.html +++ b/examples/index.html @@ -183,6 +183,26 @@

Output

size: 30, unique: true }, + /* + * result + */ + { + id: 'result', + label: 'Result', + type: 'integer', + input: 'select', + values: { + 1: 'Books', + 2: 'Movies', + 3: 'Music', + 4: 'Tools', + 5: 'Goodies', + 6: 'Clothes' + }, + operators: ['equal'], + type2: 'string', + operators2: ['equal', 'less', 'less_or_equal', 'greater', 'greater_or_equal'] + }, /* * textarea */ diff --git a/package.json b/package.json index c546cfad..7a62f282 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,8 @@ { - "name": "jQuery-QueryBuilder", - "version": "2.4.0", + "name": "bdt-jQuery-QueryBuilder", + "version": "0.1.0", "author": { - "name": "Damien \"Mistic\" Sorel", - "email": "contact@git.strangeplanet.fr", - "url": "http://www.strangeplanet.fr" + "name": "BDT" }, "description": "jQuery plugin for user friendly query/filter creator", "dependencies": { diff --git a/src/core.js b/src/core.js index 33138413..11faa071 100644 --- a/src/core.js +++ b/src/core.js @@ -30,6 +30,7 @@ QueryBuilder.prototype.init = function($el, options) { this.filters = this.settings.filters; this.icons = this.settings.icons; this.operators = this.settings.operators; + this.operators2 = this.settings.operators2; this.templates = this.settings.templates; this.plugins = this.settings.plugins; @@ -59,8 +60,10 @@ QueryBuilder.prototype.init = function($el, options) { // INIT this.$el.addClass('query-builder form-inline'); + console.log("init - this", this); this.filters = this.checkFilters(this.filters); this.operators = this.checkOperators(this.operators); + this.operators2 = this.checkOperators(this.operators2); this.bindEvents(); this.initPlugins(); @@ -574,6 +577,30 @@ QueryBuilder.prototype.createRuleOperators = function(rule) { this.trigger('afterCreateRuleOperators', rule, operators); }; +/** + * Create the operators '; +QueryBuilder.templates.operator2Select = '\ +{{? it.operators2.length === 1 }} \ + \ +{{= it.lang.operators[it.operators2[0].type] || it.operators2[0].type }} \ + \ +{{?}} \ +{{ var optgroup = null; }} \ +'; + /** * Returns group HTML * @param group_id {string} @@ -235,3 +257,77 @@ QueryBuilder.prototype.getRuleInput = function(rule, value_id) { return this.change('getRuleInput', h, rule, name); }; + +/** + * Return the rule value HTML + * @param rule {Rule} + * @param filter {object} + * @param value_id {int} + * @return {string} + */ +QueryBuilder.prototype.getRuleInput2 = function(rule, value_id) { + var filter = rule.filter; + var validation = rule.filter.validation || {}; + var name = rule.id + '_value2_' + value_id; + var c = filter.vertical ? ' class=block' : ''; + var h = ''; + + console.log("getRuleinput2 -", "filter", filter, "validation", validation, "name", name, "c", c, "h", h); + + if (typeof filter.input2 == 'function') { + h = filter.input.call(this, rule, name); + } + else { + switch (filter.input2) { + case 'radio': case 'checkbox': + Utils.iterateOptions(filter.values, function(key, val) { + h+= ' ' + val + ' '; + }); + break; + + case 'select': + h+= ''; + break; + + case 'textarea': + h+= ''; + break; + + default: + switch (QueryBuilder.types[filter.type2]) { + case 'number': + h+= '