From f81d0d265e62eaf9a9a9a3f3ab0337c920a84a99 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Wed, 8 Apr 2015 10:00:57 +0200 Subject: [PATCH] next version is 2.0.1 --- bower.json | 2 +- composer.json | 2 +- dist/css/query-builder.dark.css | 2 +- dist/css/query-builder.dark.min.css | 2 +- dist/css/query-builder.default.css | 2 +- dist/css/query-builder.default.min.css | 2 +- dist/i18n/da.js | 2 +- dist/i18n/de.js | 2 +- dist/i18n/en.js | 2 +- dist/i18n/es.js | 2 +- dist/i18n/fr.js | 2 +- dist/i18n/it.js | 2 +- dist/i18n/nl.js | 2 +- dist/i18n/no.js | 2 +- dist/i18n/pl.js | 2 +- dist/i18n/pt-BR.js | 2 +- dist/i18n/ro.js | 2 +- dist/i18n/ru.js | 2 +- dist/js/query-builder.js | 25 ++++++++++++++----------- dist/js/query-builder.min.js | 6 +++--- dist/js/query-builder.standalone.js | 25 ++++++++++++++----------- dist/js/query-builder.standalone.min.js | 6 +++--- dist/scss/dark.scss | 2 +- dist/scss/default.scss | 2 +- package.json | 2 +- 25 files changed, 55 insertions(+), 49 deletions(-) diff --git a/bower.json b/bower.json index 4b3bbf0c..95a0f64e 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jQuery-QueryBuilder", - "version": "2.0.0", + "version": "2.0.1", "authors": [{ "name": "Damien \"Mistic\" Sorel", "email": "contact@git.strangeplanet.fr", diff --git a/composer.json b/composer.json index 3878145e..da280c6b 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "mistic100/jquery-querybuilder", - "version": "2.0.0", + "version": "2.0.1", "authors": [{ "name": "Damien \"Mistic\" Sorel", "email": "contact@git.strangeplanet.fr", diff --git a/dist/css/query-builder.dark.css b/dist/css/query-builder.dark.css index 17c41611..cf6e9874 100644 --- a/dist/css/query-builder.dark.css +++ b/dist/css/query-builder.dark.css @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Copyright 2014-2015 Damien "Mistic" Sorel (http://www.strangeplanet.fr) * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/css/query-builder.dark.min.css b/dist/css/query-builder.dark.min.css index 3487c49b..169024e5 100644 --- a/dist/css/query-builder.dark.min.css +++ b/dist/css/query-builder.dark.min.css @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Copyright 2014-2015 Damien "Mistic" Sorel (http://www.strangeplanet.fr) * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/css/query-builder.default.css b/dist/css/query-builder.default.css index 7211ab6e..efae555b 100644 --- a/dist/css/query-builder.default.css +++ b/dist/css/query-builder.default.css @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Copyright 2014-2015 Damien "Mistic" Sorel (http://www.strangeplanet.fr) * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/css/query-builder.default.min.css b/dist/css/query-builder.default.min.css index 288524e1..73599d9c 100644 --- a/dist/css/query-builder.default.min.css +++ b/dist/css/query-builder.default.min.css @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Copyright 2014-2015 Damien "Mistic" Sorel (http://www.strangeplanet.fr) * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/i18n/da.js b/dist/i18n/da.js index c080bd7a..1dec663c 100644 --- a/dist/i18n/da.js +++ b/dist/i18n/da.js @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Oversat af Jna Borup Coyle, github@coyle.dk * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/i18n/de.js b/dist/i18n/de.js index 0e197ba8..4c57d669 100644 --- a/dist/i18n/de.js +++ b/dist/i18n/de.js @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * German translation by "raimu" * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/i18n/en.js b/dist/i18n/en.js index 92a18b88..b98a13e8 100644 --- a/dist/i18n/en.js +++ b/dist/i18n/en.js @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Reference language file * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/i18n/es.js b/dist/i18n/es.js index caf2970a..e6539f0f 100644 --- a/dist/i18n/es.js +++ b/dist/i18n/es.js @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Spanish translation by "pyarza" * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/i18n/fr.js b/dist/i18n/fr.js index cdc8f704..b9e9c82b 100644 --- a/dist/i18n/fr.js +++ b/dist/i18n/fr.js @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * French translation by Damien "Mistic" Sorel * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/i18n/it.js b/dist/i18n/it.js index c205f4f3..ffdd513b 100644 --- a/dist/i18n/it.js +++ b/dist/i18n/it.js @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Italian translation * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/i18n/nl.js b/dist/i18n/nl.js index 549f2ba6..c4571cf5 100644 --- a/dist/i18n/nl.js +++ b/dist/i18n/nl.js @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Dutch translation by "Roywcm" * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/i18n/no.js b/dist/i18n/no.js index cba09ece..4cb671f3 100644 --- a/dist/i18n/no.js +++ b/dist/i18n/no.js @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Oversat af Jna Borup Coyle, github@coyle.dk * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/i18n/pl.js b/dist/i18n/pl.js index e83ea9ad..b02b029f 100644 --- a/dist/i18n/pl.js +++ b/dist/i18n/pl.js @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Polish translation by Artur Smolarek * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/i18n/pt-BR.js b/dist/i18n/pt-BR.js index f90e3466..4c04a7c4 100644 --- a/dist/i18n/pt-BR.js +++ b/dist/i18n/pt-BR.js @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Portuguese Brazilian translation by Leandro Gehlen (leandrogehlen@gmail.com) * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/i18n/ro.js b/dist/i18n/ro.js index 1aae8595..92e59a4e 100644 --- a/dist/i18n/ro.js +++ b/dist/i18n/ro.js @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Romanian translation by ArianServ * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/i18n/ru.js b/dist/i18n/ru.js index b3448f44..5266210e 100644 --- a/dist/i18n/ru.js +++ b/dist/i18n/ru.js @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Локализационный файл * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/js/query-builder.js b/dist/js/query-builder.js index e4b3dded..b159e8f7 100644 --- a/dist/js/query-builder.js +++ b/dist/js/query-builder.js @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Copyright 2014-2015 Damien "Mistic" Sorel (http://www.strangeplanet.fr) * Licensed under MIT (http://opensource.org/licenses/MIT) */ @@ -771,7 +771,9 @@ QueryBuilder.prototype.updateRuleOperator = function(rule, previousOperator) { if ($valueContainer.is(':empty') || rule.operator.nb_inputs !== previousOperator.nb_inputs) { this.createRuleInput(rule); } + } + if (rule.operator) { rule.$el.find('.rule-operator-container [name$=_operator]').val(rule.operator.type); } @@ -1076,9 +1078,6 @@ QueryBuilder.prototype.setRules = function(data) { if (rule.id === undefined) { error('Missing rule field id'); } - if (rule.value === undefined) { - rule.value = ''; - } if (rule.operator === undefined) { rule.operator = 'equal'; } @@ -1096,7 +1095,7 @@ QueryBuilder.prototype.setRules = function(data) { model.data = rule.data; } - if (model.operator.nb_inputs !== 0) { + if (model.operator.nb_inputs !== 0 && rule.value !== undefined) { that.setRuleValue(model, rule.value); } } @@ -2890,13 +2889,15 @@ QueryBuilder.define('sortable', function(options) { src = Model(e.target); - var ph = $('
 
'); - ph.css('min-height', src.$el.height()); + // Chrome glitchs + // - helper invisible if hidden immediately + // - "dragend" is called immediately if we modify the DOM directly + setTimeout(function() { + var ph = $('
 
'); + ph.css('min-height', src.$el.height()); - placeholder = src.parent.addRule(ph, src.getPos()); + placeholder = src.parent.addRule(ph, src.getPos()); - // Chrome glitch (helper invisible if hidden immediately) - setTimeout(function() { src.$el.hide(); }, 0); }); @@ -2906,7 +2907,9 @@ QueryBuilder.define('sortable', function(options) { e.preventDefault(); e.stopPropagation(); - moveSortableToTarget(placeholder, $(e.target)); + if (placeholder) { + moveSortableToTarget(placeholder, $(e.target)); + } }); // dragover: prevent glitches diff --git a/dist/js/query-builder.min.js b/dist/js/query-builder.min.js index 07e7ed2c..6eb5d79a 100644 --- a/dist/js/query-builder.min.js +++ b/dist/js/query-builder.min.js @@ -1,9 +1,9 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Copyright 2014-2015 Damien "Mistic" Sorel (http://www.strangeplanet.fr) * Licensed under MIT (http://opensource.org/licenses/MIT) */ -!function(a,b){"function"==typeof define&&define.amd?define(["jquery","jQuery.extendext"],b):b(a.jQuery)}(this,function($){"use strict";function a(b){return this instanceof a?(this.root=null,void(this.$=$(this))):a.getModel(b)}function b(a,b){b.forEach(function(b){Object.defineProperty(a.prototype,b,{enumerable:!0,get:function(){return this.__[b]},set:function(a){var c=null!==this.__[b]&&"object"==typeof this.__[b]?$.extend({},this.__[b]):this.__[b];this.__[b]=a,null!==this.model&&this.model.trigger("update",this,b,a,c)}})})}function c(a,b){a&&($.isArray(a)?a.forEach(function(a){$.isPlainObject(a)?$.each(a,function(a,c){return b(a,c),!1}):b(a,a)}):$.each(a,function(a,c){b(a,c)}))}function d(a,b){return b=Array.prototype.slice.call(arguments),a.replace(/{([0-9]+)}/g,function(a,c){return b[parseInt(c)+1]})}function e(){$.error(d.apply(null,arguments))}function f(a,b,c){switch(b){case"integer":return parseInt(a);case"double":return parseFloat(a);case"boolean":var d="true"===a.trim().toLowerCase()||"1"===a.trim()||1===a;return c?d?1:0:d;default:return a}}function g(a){return"string"!=typeof a?a:a.replace(/[\0\n\r\b\\\'\"]/g,function(a){switch(a){case"\x00":return"\\0";case"\n":return"\\n";case"\r":return"\\r";case"\b":return"\\b";default:return"\\"+a}}).replace(/\t/g,"\\t").replace(/\x1a/g,"\\Z")}function h(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function i(b,c){var d;return d=c.closest(".rule-container"),d.length?void b.moveAfter(a(d)):(d=c.closest(".rules-group-header"),d.length?(d=c.closest(".rules-group-container"),void b.moveAtBegin(a(d))):(d=c.closest(".rules-group-container"),d.length?void b.moveAtEnd(a(d)):void 0))}var j=function(a,b){this.init(a,b)},k=Array.prototype.slice;$.extend(j.prototype,{change:function(a,b){var c=new $.Event(a+".queryBuilder.filter",{builder:this,value:b});return this.$el.triggerHandler(c,k.call(arguments,2)),c.value},trigger:function(a){var b=new $.Event(a+".queryBuilder",{builder:this});return this.$el.triggerHandler(b,k.call(arguments,1)),b},on:function(a,b){return this.$el.on(a+".queryBuilder",b),this},off:function(a,b){return this.$el.off(a+".queryBuilder",b),this},once:function(a,b){return this.$el.one(a+".queryBuilder",b),this}}),j.plugins={},j.defaults=function(a){return"object"!=typeof a?"string"==typeof a?"object"==typeof j.DEFAULTS[a]?$.extend(!0,{},j.DEFAULTS[a]):j.DEFAULTS[a]:$.extend(!0,{},j.DEFAULTS):void $.extendext(!0,"replace",j.DEFAULTS,a)},j.define=function(a,b,c){j.plugins[a]={fct:b,def:c||{}}},j.extend=function(a){$.extend(j.prototype,a)},j.prototype.initPlugins=function(){if(this.plugins){if($.isArray(this.plugins)){var a={};this.plugins.forEach(function(b){a[b]=null}),this.plugins=a}Object.keys(this.plugins).forEach(function(a){a in j.plugins?(this.plugins[a]=$.extend(!0,{},j.plugins[a].def,this.plugins[a]||{}),j.plugins[a].fct.call(this,this.plugins[a])):e('Unable to find plugin "{0}"',a)},this)}},j.types={string:"string",integer:"number","double":"number",date:"datetime",time:"datetime",datetime:"datetime","boolean":"boolean"},j.inputs=["text","textarea","radio","checkbox","select"],j.modifiable_options=["display_errors","allow_groups","allow_empty"],j.DEFAULTS={filters:[],plugins:[],display_errors:!0,allow_groups:-1,allow_empty:!1,conditions:["AND","OR"],default_condition:"AND",inputs_separator:" , ",select_placeholder:"------",default_rule_flags:{filter_readonly:!1,operator_readonly:!1,value_readonly:!1,no_delete:!1},template:{group:null,rule:null},lang:{add_rule:"Add rule",add_group:"Add group",delete_rule:"Delete",delete_group:"Delete",conditions:{AND:"AND",OR:"OR"},operators:{equal:"equal",not_equal:"not equal","in":"in",not_in:"not in",less:"less",less_or_equal:"less or equal",greater:"greater",greater_or_equal:"greater or equal",between:"between",begins_with:"begins with",not_begins_with:"doesn't begin with",contains:"contains",not_contains:"doesn't contain",ends_with:"ends with",not_ends_with:"doesn't end with",is_empty:"is empty",is_not_empty:"is not empty",is_null:"is null",is_not_null:"is not null"},errors:{no_filter:"No filter selected",empty_group:"The group is empty",radio_empty:"No value selected",checkbox_empty:"No value selected",select_empty:"No value selected",string_empty:"Empty value",string_exceed_min_length:"Must contain at least {0} characters",string_exceed_max_length:"Must not contain more than {0} characters",string_invalid_format:"Invalid format ({0})",number_nan:"Not a number",number_not_integer:"Not an integer",number_not_double:"Not a real number",number_exceed_min:"Must be greater than {0}",number_exceed_max:"Must be lower than {0}",number_wrong_step:"Must be a multiple of {0}",datetime_empty:"Empty value",datetime_invalid:"Invalid date format ({0})",datetime_exceed_min:"Must be after {0}",datetime_exceed_max:"Must be before {0}",boolean_not_valid:"Not a boolean",operator_not_multiple:"Operator {0} cannot accept multiple values"}},operators:[{type:"equal",nb_inputs:1,multiple:!1,apply_to:["string","number","datetime","boolean"]},{type:"not_equal",nb_inputs:1,multiple:!1,apply_to:["string","number","datetime","boolean"]},{type:"in",nb_inputs:1,multiple:!0,apply_to:["string","number","datetime"]},{type:"not_in",nb_inputs:1,multiple:!0,apply_to:["string","number","datetime"]},{type:"less",nb_inputs:1,multiple:!1,apply_to:["number","datetime"]},{type:"less_or_equal",nb_inputs:1,multiple:!1,apply_to:["number","datetime"]},{type:"greater",nb_inputs:1,multiple:!1,apply_to:["number","datetime"]},{type:"greater_or_equal",nb_inputs:1,multiple:!1,apply_to:["number","datetime"]},{type:"between",nb_inputs:2,multiple:!1,apply_to:["number","datetime"]},{type:"begins_with",nb_inputs:1,multiple:!1,apply_to:["string"]},{type:"not_begins_with",nb_inputs:1,multiple:!1,apply_to:["string"]},{type:"contains",nb_inputs:1,multiple:!1,apply_to:["string"]},{type:"not_contains",nb_inputs:1,multiple:!1,apply_to:["string"]},{type:"ends_with",nb_inputs:1,multiple:!1,apply_to:["string"]},{type:"not_ends_with",nb_inputs:1,multiple:!1,apply_to:["string"]},{type:"is_empty",nb_inputs:0,multiple:!1,apply_to:["string"]},{type:"is_not_empty",nb_inputs:0,multiple:!1,apply_to:["string"]},{type:"is_null",nb_inputs:0,multiple:!1,apply_to:["string","number","datetime","boolean"]},{type:"is_not_null",nb_inputs:0,multiple:!1,apply_to:["string","number","datetime","boolean"]}],icons:{add_group:"glyphicon glyphicon-plus-sign",add_rule:"glyphicon glyphicon-plus",remove_group:"glyphicon glyphicon-remove",remove_rule:"glyphicon glyphicon-remove",error:"glyphicon glyphicon-warning-sign"}},j.prototype.init=function(b,c){b[0].queryBuilder=this,this.$el=b,this.settings=$.extendext(!0,"replace",{},j.DEFAULTS,c),this.model=new a,this.status={group_id:0,rule_id:0,generated_id:!1,has_optgroup:!1,id:null},this.settings.allow_groups===!1?this.settings.allow_groups=0:this.settings.allow_groups===!0&&(this.settings.allow_groups=-1),this.filters=this.settings.filters,this.lang=this.settings.lang,this.icons=this.settings.icons,this.operators=this.settings.operators,this.template=this.settings.template,this.plugins=this.settings.plugins,null===this.template.group&&(this.template.group=this.getGroupTemplate),null===this.template.rule&&(this.template.rule=this.getRuleTemplate),this.$el.attr("id")||(this.$el.attr("id","qb_"+Math.floor(99999*Math.random())),this.status.generated_id=!0),this.status.id=this.$el.attr("id"),this.$el.addClass("query-builder form-inline"),this.checkFilters(),this.bindEvents(),this.initPlugins(),this.trigger("afterInit"),c.rules?(this.setRules(c.rules),delete this.settings.rules):this.setRoot(!0)},j.prototype.checkFilters=function(){var a=[],b=this;if(this.filters&&0!==this.filters.length||e("Missing filters list"),this.filters.forEach(function(c,d){switch(c.id||e("Missing filter {0} id",d),-1!=a.indexOf(c.id)&&e('Filter "{0}" already defined',c.id),a.push(c.id),c.type?j.types[c.type]||e('Invalid type "{0}"',c.type):c.type="string",c.input?"function"!=typeof c.input&&-1==j.inputs.indexOf(c.input)&&e('Invalid input "{0}"',c.input):c.input="text",c.field||(c.field=c.id),c.label||(c.label=c.field),c.optgroup?b.status.has_optgroup=!0:c.optgroup=null,c.input){case"radio":case"checkbox":(!c.values||c.values.length<1)&&e('Missing filter "{0}" values',c.id)}}),this.status.has_optgroup){var c=[],d=[];this.filters.forEach(function(a){var b;a.optgroup?(b=c.lastIndexOf(a.optgroup),-1==b?b=c.length:b++):b=c.length,c.splice(b,0,a.optgroup),d.splice(b,0,a)}),this.filters=d}},j.prototype.bindEvents=function(){var b=this;this.$el.on("change.queryBuilder",".rules-group-header [name$=_cond]",function(){if($(this).is(":checked")){var b=$(this).closest(".rules-group-container");a(b).condition=$(this).val()}}),this.$el.on("change.queryBuilder",".rule-filter-container [name$=_filter]",function(){var c=$(this).closest(".rule-container");a(c).filter=b.getFilterById($(this).val())}),this.$el.on("change.queryBuilder",".rule-operator-container [name$=_operator]",function(){var c=$(this).closest(".rule-container");a(c).operator=b.getOperatorByType($(this).val())}),this.$el.on("click.queryBuilder","[data-add=rule]",function(){var c=$(this).closest(".rules-group-container");b.addRule(a(c))}),this.$el.on("click.queryBuilder","[data-delete=rule]",function(){var c=$(this).closest(".rule-container");b.deleteRule(a(c))}),0!==this.settings.allow_groups&&(this.$el.on("click.queryBuilder","[data-add=group]",function(){var c=$(this).closest(".rules-group-container");b.addGroup(a(c))}),this.$el.on("click.queryBuilder","[data-delete=group]",function(){var c=$(this).closest(".rules-group-container");b.deleteGroup(a(c))})),this.model.on({drop:function(a,b){b.$el.remove()},add:function(a,b,c){b.$el.detach(),0===c?b.$el.prependTo(b.parent.$el.find(">.rules-group-body>.rules-list")):b.$el.insertAfter(b.parent.rules[c-1].$el)},update:function(a,c,d,e,f){switch(d){case"error":b.displayError(c);break;case"condition":b.updateGroupCondition(c);break;case"filter":b.updateRuleFilter(c);break;case"operator":b.updateRuleOperator(c,f);break;case"flags":b.applyRuleFlags(c)}}})},j.prototype.setRoot=function(a){a=void 0===a||a===!0;var b=this.nextGroupId(),c=$(this.template.group.call(this,b,1));return this.$el.append(c),this.model.root=new m(null,c),this.model.root.model=this.model,this.model.root.condition=this.settings.default_condition,a&&this.addRule(this.model.root),this.model.root},j.prototype.addGroup=function(a,b){b=void 0===b||b===!0;var c=a.level+1,d=this.trigger("beforeAddGroup",a,b,c);if(d.isDefaultPrevented())return null;var e=this.nextGroupId(),f=$(this.template.group.call(this,e,c)),g=a.addGroup(f);return this.trigger("afterAddGroup",g),g.condition=this.settings.default_condition,b&&this.addRule(g),g},j.prototype.deleteGroup=function(a){if(a.isRoot())return!1;var b=this.trigger("beforeDeleteGroup",a);if(b.isDefaultPrevented())return!1;var c=!0;return a.each("reverse",function(a){c&=this.deleteRule(a)},function(a){c&=this.deleteGroup(a)},this),c&&(a.drop(),this.trigger("afterDeleteGroup")),c},j.prototype.updateGroupCondition=function(a){a.$el.find(">.rules-group-header [name$=_cond]").each(function(){var b=$(this);b.prop("checked",b.val()===a.condition),b.parent().toggleClass("active",b.val()===a.condition)})},j.prototype.addRule=function(a){var b=this.trigger("beforeAddRule",a);if(b.isDefaultPrevented())return null;var c=this.nextRuleId(),d=$(this.template.rule.call(this,c)),e=a.addRule(d);return this.trigger("afterAddRule",e),this.createRuleFilters(e),e},j.prototype.deleteRule=function(a){if(a.flags.no_delete)return!1;var b=this.trigger("beforeDeleteRule",a);return b.isDefaultPrevented()?!1:(a.drop(),this.trigger("afterDeleteRule"),!0)},j.prototype.createRuleFilters=function(a){var b=this.change("getRuleFilters",this.filters,a),c=$(this.getRuleFilterSelect(a,b));a.$el.find(".rule-filter-container").append(c),this.trigger("afterCreateRuleFilters",a)},j.prototype.createRuleOperators=function(a,b){var c=a.$el.find(".rule-operator-container").empty();if(a.filter){var d=this.getOperators(a.filter),e=$(this.getRuleOperatorSelect(a,d));c.html(e),b!==!1?a.operator=d[0]:a.__.operator=d[0],this.trigger("afterCreateRuleOperators",a,d)}},j.prototype.createRuleInput=function(a){var b=a.$el.find(".rule-value-container").empty();if(a.filter&&0!==a.operator.nb_inputs){for(var c=$(),d=a.filter,e=0;e0&&b.append(this.settings.inputs_separator),b.append(f),c=c.add(f)}b.show(),d.plugin&&c[d.plugin](d.plugin_config||{}),this.trigger("afterCreateRuleInput",a),void 0!==d.default_value&&this.setRuleValue(a,d.default_value)}},j.prototype.updateRuleFilter=function(a){this.createRuleOperators(a,!1),this.createRuleInput(a),a.$el.find(".rule-filter-container [name$=_filter]").val(a.filter?a.filter.id:"-1"),this.trigger("afterUpdateRuleFilter",a)},j.prototype.updateRuleOperator=function(a,b){var c=a.$el.find(".rule-value-container");a.operator&&0!==a.operator.nb_inputs?(c.show(),(c.is(":empty")||a.operator.nb_inputs!==b.nb_inputs)&&this.createRuleInput(a),a.$el.find(".rule-operator-container [name$=_operator]").val(a.operator.type)):c.hide(),this.trigger("afterUpdateRuleOperator",a)},j.prototype.applyRuleFlags=function(a){var b=a.flags;b.filter_readonly&&a.$el.find("[name$=_filter]").prop("disabled",!0),b.operator_readonly&&a.$el.find("[name$=_operator]").prop("disabled",!0),b.value_readonly&&a.$el.find("[name*=_value_]").prop("disabled",!0),b.no_delete&&a.$el.find("[data-delete=rule]").remove(),this.trigger("afterApplyRuleFlags",a)},j.prototype.clearErrors=function(a){a=a||this.model.root,a&&(a.error=null,a instanceof m&&a.each(function(a){a.error=null},function(a){this.clearErrors(a)},this))},j.prototype.displayError=function(a){if(this.settings.display_errors)if(null===a.error)a.$el.removeClass("has-error");else{var b=$.extend([],a.error,[this.lang.errors[a.error[0]]||a.error[0]]);a.$el.addClass("has-error").find(".error-container").eq(0).attr("title",d.apply(null,b))}},j.prototype.triggerValidationError=function(a,b,c){$.isArray(b)||(b=[b]);var d=this.trigger("validationError",a,b,c);d.isDefaultPrevented()||(a.error=b)},j.prototype.destroy=function(){this.trigger("beforeDestroy"),this.status.generated_id&&this.$el.removeAttr("id"),this.clear(),this.model=null,this.$el.off(".queryBuilder").removeClass("query-builder").removeData("queryBuilder"),delete this.$el[0].queryBuilder},j.prototype.reset=function(){this.status.group_id=1,this.status.rule_id=0,this.model.root.empty(),this.addRule(this.model.root),this.trigger("afterReset")},j.prototype.clear=function(){this.status.group_id=0,this.status.rule_id=0,this.model.root&&(this.model.root.drop(),this.model.root=null),this.trigger("afterClear")},j.prototype.setOptions=function(a){$.makeArray($(Object.keys(a)).filter(j.modifiable_options)).forEach(function(b){this.settings[b]=a[b]},this)},j.prototype.validate=function(){this.clearErrors();var a=this,b=function c(b){var d=0,e=0;return b.each(function(b){if(!b.filter)return a.triggerValidationError(b,"no_filter",null),void e++;if(0!==b.operator.nb_inputs){var c=a.getRuleValue(b),f=a.validateValue(b,c);if(f!==!0)return a.triggerValidationError(b,f,c),void e++}d++},function(a){c(a)?d++:e++}),e>0?!1:0!==d||a.settings.allow_empty&&b.isRoot()?!0:(a.triggerValidationError(b,"empty_group",null),!1)}(this.model.root);return this.change("validate",b)},j.prototype.getRules=function(){if(!this.validate())return{};var a=this,b=function c(b){var d={condition:b.condition,rules:[]};return b.each(function(b){var c=null;0!==b.operator.nb_inputs&&(c=a.getRuleValue(b));var e={id:b.filter.id,field:b.filter.field,type:b.filter.type,input:b.filter.input,operator:b.operator.type,value:c};(b.filter.data||b.data)&&(e.data=$.extendext(!0,"replace",{},b.filter.data,b.data)),d.rules.push(e)},function(a){d.rules.push(c(a))}),d}(this.model.root);return this.change("getRules",b)},j.prototype.setRules=function(a){this.clear(),this.setRoot(!1),a&&a.rules&&(0!==a.rules.length||this.settings.allow_empty)||e("Incorrect data object passed"),a=this.change("setRules",a);var b=this;!function c(a,d){null!==d&&(void 0===a.condition?a.condition=b.settings.default_condition:-1==b.settings.conditions.indexOf(a.condition)&&e('Invalid condition "{0}"',a.condition),d.condition=a.condition.toUpperCase(),a.rules.forEach(function(a){var f;if(a.rules&&a.rules.length>0)-1!=b.settings.allow_groups&&b.settings.allow_groups1){h=["operator_not_multiple",this.lang[f.type]||f.type];break}break;case"select":if(d.multiple){if(0===b[i].length){h=["select_empty"];break}if(!f.multiple&&b[i].length>1){h=["operator_not_multiple",this.lang[f.type]||f.type];break}}else if(void 0===b[i]){h=["select_empty"];break}break;default:switch(j.types[d.type]){case"string":if(0===b[i].length){h=["string_empty"];break}if(void 0!==g.min&&b[i].lengthparseInt(g.max)){h=["string_exceed_max_length",g.max];break}if(g.format&&("string"==typeof g.format&&(g.format=new RegExp(g.format)),!g.format.test(b[i]))){h=["string_invalid_format",g.format];break}break;case"number":if(isNaN(b[i])){h=["number_nan"];break}if("integer"==d.type){if(parseInt(b[i])!=b[i]){h=["number_not_integer"];break}}else if(parseFloat(b[i])!=b[i]){h=["number_not_double"];break}if(void 0!==g.min&&b[i]parseFloat(g.max)){h=["number_exceed_max",g.max];break}if(void 0!==g.step){var k=b[i]/g.step;if(parseInt(k)!=k){h=["number_wrong_step",g.step];break}}break;case"datetime":if(0===b[i].length){h=["datetime_empty"];break}if(g.format){"moment"in window||e("MomentJS is required for Date/Time validation");var l=moment(b[i],g.format);if(!l.isValid()){h=["datetime_invalid"];break}if(g.min&&lmoment(g.max,g.format)){h=["datetime_exceed_max",g.max];break}}break;case"boolean":if(c=b[i].trim().toLowerCase(),"true"!==c&&"false"!==c&&"1"!==c&&"0"!==c&&1!==b[i]&&0!==b[i]){h=["boolean_not_valid"];break}}}if(h!==!0)break}return h},j.prototype.nextGroupId=function(){return this.status.id+"_group_"+this.status.group_id++},j.prototype.nextRuleId=function(){return this.status.id+"_rule_"+this.status.rule_id++},j.prototype.getOperators=function(a){"string"==typeof a&&(a=this.getFilterById(a));for(var b=[],c=0,d=this.operators.length;d>c;c++){if(a.operators){if(-1==a.operators.indexOf(this.operators[c].type))continue}else if(-1==this.operators[c].apply_to.indexOf(j.types[a.type]))continue;b.push(this.operators[c])}return a.operators&&b.sort(function(b,c){return a.operators.indexOf(b.type)-a.operators.indexOf(c.type)}),this.change("getOperators",b,a)},j.prototype.getFilterById=function(a){if("-1"==a)return null;for(var b=0,c=this.filters.length;c>b;b++)if(this.filters[b].id==a)return this.filters[b];e('Undefined filter "{0}"',a)},j.prototype.getOperatorByType=function(a){if("-1"==a)return null;for(var b=0,c=this.operators.length;c>b;b++)if(this.operators[b].type==a)return this.operators[b];e('Undefined operator "{0}"',a)},j.prototype.getRuleValue=function(a){for(var b,c=a.filter,d=a.operator,e=a.$el.find(".rule-value-container"),f=[],g=0;g
"+(-1===this.settings.allow_groups||this.settings.allow_groups>=b?'":"")+" "+(b>1?'":"")+'
'+this.getGroupConditions(a,b)+"
"+(this.settings.display_errors?'
':"")+"
    ";return this.change("getGroupTemplate",c,b)},j.prototype.getGroupConditions=function(a,b){for(var c="",d=0,e=this.settings.conditions.length;e>d;d++){var f=this.settings.conditions[d],g=this.lang.conditions[f]||f;c+=' "}return this.change("getGroupConditions",c,b)},j.prototype.getRuleTemplate=function(a){var b='
  • "+(this.settings.display_errors?'
    ':"")+'
  • ';return this.change("getRuleTemplate",b)},j.prototype.getRuleFilterSelect=function(a,b){var c=null,d='",this.change("getRuleFilterSelect",d,a)},j.prototype.getRuleOperatorSelect=function(a,b){for(var c='",this.change("getRuleOperatorSelect",c,a)},j.prototype.getRuleInput=function(a,b){var d=a.filter,e=a.filter.validation||{},f=a.id+"_value_"+b,g=d.vertical?" class=block":"",h="";if("function"==typeof d.input)h=d.input.call(this,a,f);else switch(d.input){case"radio":c(d.values,function(a,b){h+=" '+b+" "});break;case"checkbox":c(d.values,function(a,b){h+=" '+b+" "});break;case"select":h+='";break;case"textarea":h+='";break;default:switch(j.types[d.type]){case"number":h+='=f:f>=e},i=!1;h()&&(this.rules[e]instanceof m?void 0!==c&&(i=c.call(d,this.rules[e])===!1):i=b.call(d,this.rules[e])===!1,!i);e+=g);return!i},m.prototype.contains=function(a,b){return-1!==this.getNodePos(a)?!0:b?!this.each(function(){return!0},function(b){return!b.contains(a,!0)}):!1};var n=function(a,b){return this instanceof n?(l.call(this,a,b),this.filter=null,this.operator=null,void(this.flags={})):new n(a,b)};n.prototype=Object.create(l.prototype),n.prototype.constructor=n,b(n,["filter","operator","flags"]),j.Group=m,j.Rule=n,$.fn.queryBuilder=function(a){this.length>1&&e("Unable to initialize on multiple target");var b=this.data("queryBuilder"),c="object"==typeof a&&a||{};return b||"destroy"!=a?(b||this.data("queryBuilder",new j(this,c)),"string"==typeof a?b[a].apply(b,Array.prototype.slice.call(arguments,1)):this):this},$.fn.queryBuilder.constructor=j,$.fn.queryBuilder.defaults=j.defaults,$.fn.queryBuilder.extend=j.extend,$.fn.queryBuilder.define=j.define,j.define("bt-checkbox",function(a){if("glyphicons"==a.font){var b=document.createElement("style");b.innerHTML='.checkbox input[type=checkbox]:checked + label:after { font-family: "Glyphicons Halflings"; content: "\\e013"; } .checkbox label:after { padding-left: 4px; padding-top: 2px; font-size: 9px; }',document.body.appendChild(b)}this.on("getRuleInput.filter",function(b,d,e){var f=d.filter;if(("radio"===f.input||"checkbox"===f.input)&&!f.plugin){b.value="",f.colors||(f.colors={}),f.color&&(f.colors._def_=f.color);var g,h,i=f.vertical?' style="display:block"':"",j=0;c(f.values,function(c,d){g=f.colors[c]||f.colors._def_||a.color,h=e+"_"+j++,b.value+=" "})}})},{font:"glyphicons",color:"default"}),j.define("bt-selectpicker",function(a){$.fn.selectpicker&&$.fn.selectpicker.Constructor||e('Bootstrap Select is required to use "bt-selectpicker" plugin. Get it here: http://silviomoreto.github.io/bootstrap-select'),this.on("afterCreateRuleFilters",function(b,c){c.$el.find(".rule-filter-container select").removeClass("form-control").selectpicker(a)}),this.on("afterCreateRuleOperators",function(b,c){c.$el.find(".rule-operator-container select").removeClass("form-control").selectpicker(a)}),this.on("afterUpdateRuleFilter",function(a,b){b.$el.find(".rule-filter-container select").selectpicker("render")}),this.on("afterUpdateRuleOperator",function(a,b){b.$el.find(".rule-operator-container select").selectpicker("render")})},{container:"body",style:"btn-inverse btn-xs",width:"auto",showIcon:!1}),j.define("bt-tooltip-errors",function(a){$.fn.tooltip&&$.fn.tooltip.Constructor&&$.fn.tooltip.Constructor.prototype.fixTitle||e('Bootstrap Tooltip is required to use "bt-tooltip-errors" plugin. Get it here: http://getbootstrap.com');var b=this;this.on("getRuleTemplate.filter",function(a){a.value=a.value.replace('class="error-container"','class="error-container" data-toggle="tooltip"')}),this.on("getGroupTemplate.filter",function(a){a.value=a.value.replace('class="error-container"','class="error-container" data-toggle="tooltip"'); -}),this.model.on("update",function(c,d,e){"error"==e&&b.settings.display_errors&&d.$el.find(".error-container").eq(0).tooltip(a).tooltip("hide").tooltip("fixTitle")})},{placement:"right"}),j.define("filter-description",function(a){"inline"===a.mode?this.on("afterUpdateRuleFilter",function(b,c){var d=c.$el.find("p.filter-description");c.filter&&c.filter.description?(0===d.length?(d=$('

    '),d.appendTo(c.$el)):d.show(),d.html(' '+c.filter.description)):d.hide()}):"popover"===a.mode?($.fn.popover&&$.fn.popover.Constructor&&$.fn.popover.Constructor.prototype.fixTitle||e('Bootstrap Popover is required to use "filter-description" plugin. Get it here: http://getbootstrap.com'),this.on("afterUpdateRuleFilter",function(b,c){var d=c.$el.find("button.filter-description");c.filter&&c.filter.description?(0===d.length?(d=$(''),d.prependTo(c.$el.find(".rule-actions")),d.popover({placement:"left",container:"body",html:!0}),d.on("mouseout",function(){d.popover("hide")})):d.show(),d.data("bs.popover").options.content=c.filter.description,d.attr("aria-describedby")&&d.popover("show")):(d.hide(),d.data("bs.popover")&&d.popover("hide"))})):"bootbox"===a.mode&&("bootbox"in window||e('Bootbox is required to use "filter-description" plugin. Get it here: http://bootboxjs.com'),this.on("afterUpdateRuleFilter",function(b,c){var d=c.$el.find("button.filter-description");c.filter&&c.filter.description?(0===d.length&&(d=$(''),d.prependTo(c.$el.find(".rule-actions")),d.on("click",function(){bootbox.alert(d.data("description"))})),d.data("description",c.filter.description)):d.hide()}))},{icon:"glyphicon glyphicon-info-sign",mode:"popover"}),j.defaults({loopbackOperators:{equal:function(a){return a[0]},not_equal:function(a){return{neq:a[0]}},"in":function(a){return{inq:a}},not_in:function(a){return{nin:a}},less:function(a){return{lt:a[0]}},less_or_equal:function(a){return{lte:a[0]}},greater:function(a){return{gt:a[0]}},greater_or_equal:function(a){return{gte:a[0]}},between:function(a){return{between:a}},begins_with:function(a){return{like:"^"+h(a[0])}},not_begins_with:function(a){return{nlike:"^"+h(a[0])}},contains:function(a){return{like:h(a[0])}},not_contains:function(a){return{nlike:h(a[0])}},ends_with:function(a){return{like:h(a[0])+"$"}},not_ends_with:function(a){return{nlike:h(a[0])+"$"}},is_empty:function(){return""},is_not_empty:function(){return{neq:""}},is_null:function(){return null},is_not_null:function(){return{neq:null}}}}),j.extend({getLoopback:function(a){a=void 0===a?this.getRules():a;var b=this;return function c(a){if(a.condition||(a.condition=b.settings.default_condition),-1===["AND","OR"].indexOf(a.condition.toUpperCase())&&e('Unable to build Loopback query with condition "{0}"',a.condition),!a.rules)return{};var d=[];a.rules.forEach(function(a){if(a.rules&&a.rules.length>0)d.push(c(a));else{var g=b.settings.loopbackOperators[a.operator],h=b.getOperatorByType(a.operator),i=[];void 0===g&&e('Unknown Loopback operation for operator "{0}"',a.operator),0!==h.nb_inputs&&(a.value instanceof Array||(a.value=[a.value]),a.value.forEach(function(b){i.push(f(b,a.type))}));var j={};j[a.field]=g.call(b,i),d.push(j)}});var g={};return d.length>0&&(g[a.condition.toLowerCase()]=d),g}(a)}}),j.defaults({mongoOperators:{equal:function(a){return a[0]},not_equal:function(a){return{$ne:a[0]}},"in":function(a){return{$in:a}},not_in:function(a){return{$nin:a}},less:function(a){return{$lt:a[0]}},less_or_equal:function(a){return{$lte:a[0]}},greater:function(a){return{$gt:a[0]}},greater_or_equal:function(a){return{$gte:a[0]}},between:function(a){return{$gte:a[0],$lte:a[1]}},begins_with:function(a){return{$regex:"^"+h(a[0])}},not_begins_with:function(a){return{$regex:"^(?!"+h(a[0])+")"}},contains:function(a){return{$regex:h(a[0])}},not_contains:function(a){return{$regex:"^((?!"+h(a[0])+").)*$",$options:"s"}},ends_with:function(a){return{$regex:h(a[0])+"$"}},not_ends_with:function(a){return{$regex:"(?0)d.push(c(a));else{var g=b.settings.mongoOperators[a.operator],h=b.getOperatorByType(a.operator),i=[];void 0===g&&e('Unknown MongoDB operation for operator "{0}"',a.operator),0!==h.nb_inputs&&(a.value instanceof Array||(a.value=[a.value]),a.value.forEach(function(b){i.push(f(b,a.type,!1))}));var j={};j[a.field]=g.call(b,i),d.push(j)}});var g={};return d.length>0&&(g["$"+a.condition.toLowerCase()]=d),g}(a)},getRulesFromMongo:function(a){if(void 0===a||null===a)return null;var b=this,c=["$and","$or"];return function d(a){var f=Object.keys(a);f.length>1&&e("Invalid MongoDB query format."),-1===c.indexOf(f[0].toLowerCase())&&e('Unable to build Rule from MongoDB query with condition "{0}"',f[0]);var g=f[0].toLowerCase()===c[0]?"AND":"OR",h=a[f[0]],i=[];h.forEach(function(a){var f=Object.keys(a);if(-1!==c.indexOf(f[0].toLowerCase()))i.push(d(a));else{var g=f[0],h=a[g],j=b.determineMongoOperator(h,g);void 0===j&&e("Invalid MongoDB query format.");var k=b.settings.mongoRuleOperators[j];void 0===k&&e('JSON Rule operation unknown for operator "{0}"',j);var l=k.call(b,h);i.push({id:b.change("getMongoDBFieldID",g,h),field:g,operator:l.op,value:l.val})}});var j={};return i.length>0&&(j.condition=g,j.rules=i),j}(a)},determineMongoOperator:function(a){if(null!==a&&"object"==typeof a){var b=Object.keys(a);return 1===b.length?b[0]:void 0!==a.$gte&&void 0!==a.$lte?"between":void 0!==a.$regex?"$regex":void 0}return"eq"},setRulesFromMongo:function(a){this.setRules(this.getRulesFromMongo(a))}}),j.define("sortable",function(b){this.on("afterInit",function(b){$.event.props.push("dataTransfer");var c,d,e=b.builder;e.$el.on("mouseover",".drag-handle",function(){e.$el.find(".rule-container, .rules-group-container").attr("draggable",!0)}),e.$el.on("mouseout",".drag-handle",function(){e.$el.find(".rule-container, .rules-group-container").removeAttr("draggable")}),e.$el.on("dragstart","[draggable]",function(b){b.stopPropagation(),b.dataTransfer.setData("text","drag"),d=a(b.target);var e=$('
     
    ');e.css("min-height",d.$el.height()),c=d.parent.addRule(e,d.getPos()),setTimeout(function(){d.$el.hide()},0)}),e.$el.on("dragenter","[draggable]",function(a){a.preventDefault(),a.stopPropagation(),i(c,$(a.target))}),e.$el.on("dragover","[draggable]",function(a){a.preventDefault(),a.stopPropagation()}),e.$el.on("drop",function(a){a.preventDefault(),a.stopPropagation(),i(d,$(a.target))}),e.$el.on("dragend","[draggable]",function(a){a.preventDefault(),a.stopPropagation(),d.$el.show(),c.drop(),d=c=null,e.$el.find(".rule-container, .rules-group-container").removeAttr("draggable")})}),this.on("parseRuleFlags.filter",function(a){void 0===a.value.no_sortable&&(a.value.no_sortable=b.default_no_sortable)}),this.on("afterApplyRuleFlags",function(a,b){b.flags.no_sortable&&b.$el.find(".drag-handle").remove()}),this.on("getGroupTemplate.filter",function(a,c){if(c>1){var d=$(a.value);d.find(".group-conditions").after('
    '),a.value=d.prop("outerHTML")}}),this.on("getRuleTemplate.filter",function(a){var c=$(a.value);c.find(".rule-header").after('
    '),a.value=c.prop("outerHTML")})},{default_no_sortable:!1,icon:"glyphicon glyphicon-sort"}),j.defaults({sqlOperators:{equal:"= ?",not_equal:"!= ?","in":{op:"IN(?)",sep:", "},not_in:{op:"NOT IN(?)",sep:", "},less:"< ?",less_or_equal:"<= ?",greater:"> ?",greater_or_equal:">= ?",between:{op:"BETWEEN ?",sep:" AND "},begins_with:{op:"LIKE(?)",fn:function(a){return a+"%"}},not_begins_with:{op:"NOT LIKE(?)",fn:function(a){return a+"%"}},contains:{op:"LIKE(?)",fn:function(a){return"%"+a+"%"}},not_contains:{op:"NOT LIKE(?)",fn:function(a){return"%"+a+"%"}},ends_with:{op:"LIKE(?)",fn:function(a){return"%"+a}},not_ends_with:{op:"NOT LIKE(?)",fn:function(a){return"%"+a}},is_empty:'== ""',is_not_empty:'!= ""',is_null:"IS NULL",is_not_null:"IS NOT NULL"},sqlStatements:{question_mark:function(){var a=[];return{add:function(b,c){return a.push(c),"?"},run:function(){return a}}},numbered:function(){var a=0,b=[];return{add:function(c,d){return b.push(d),a++,"$"+a},run:function(){return b}}},named:function(){var a={},b={};return{add:function(c,d){a[c.field]||(a[c.field]=0),a[c.field]++;var e=c.field+"_"+a[c.field];return b[e]=d,":"+e},run:function(){return b}}}}}),j.extend({getSQL:function(a,b,c){c=void 0===c?this.getRules():c,b=b===!0?"\n":" ",(a===!0||void 0===a)&&(a="question_mark"),"string"==typeof a&&(a=this.settings.sqlStatements[a]());var d=this,h=function i(c){if(c.condition||(c.condition=d.settings.default_condition),-1===["AND","OR"].indexOf(c.condition.toUpperCase())&&e('Unable to build SQL query with condition "{0}"',c.condition),!c.rules)return"";var h=[];return c.rules.forEach(function(c){if(c.rules&&c.rules.length>0)h.push("("+b+i(c)+b+")"+b);else{var j=d.getSqlOperator(c.operator),k=d.getOperatorByType(c.operator),l="";j===!1&&e('Unknown SQL operation for operator "{0}"',c.operator),0!==k.nb_inputs&&(c.value instanceof Array||(c.value=[c.value]),c.value.forEach(function(b,d){d>0&&(l+=j.sep),"integer"==c.type||"double"==c.type||"boolean"==c.type?b=f(b,c.type,!0):a||(b=g(b)),j.fn&&(b=j.fn(b)),a?l+=a.add(c,b):("string"==typeof b&&(b="'"+b+"'"),l+=b)})),h.push(c.field+" "+j.op.replace(/\?/,l))}}),h.join(" "+c.condition+b)}(c);return a?{sql:h,params:a.run()}:{sql:h}},getSqlOperator:function(a){var b=this.settings.sqlOperators[a];return void 0===b?!1:("string"==typeof b&&(b={op:b}),b.list&&!b.sep&&(b.sep=", "),b)}}),j.define("unique-filter",function(){this.status.used_filters={},this.on("afterUpdateRuleFilter",this.updateDisabledFilters),this.on("afterDeleteRule",this.updateDisabledFilters),this.on("afterCreateRuleFilters",this.applyDisabledFilters)}),j.extend({updateDisabledFilters:function(a){var b=a.builder;b.status.used_filters={},b.model&&(!function c(a){a.each(function(a){a.filter&&a.filter.unique&&(b.status.used_filters[a.filter.id]||(b.status.used_filters[a.filter.id]=[]),"group"==a.filter.unique&&b.status.used_filters[a.filter.id].push(a.parent))},function(a){c(a)})}(b.model.root),b.applyDisabledFilters(a))},applyDisabledFilters:function(a){var b=a.builder;b.$el.find(".rule-filter-container option").prop("disabled",!1),$.each(b.status.used_filters,function(a,c){0===c.length?b.$el.find(".rule-filter-container option[value="+a+"]:not(:selected)").prop("disabled",!0):c.forEach(function(b){b.each(function(b){b.$el.find(".rule-filter-container option[value="+a+"]:not(:selected)").prop("disabled",!0)})})}),b.settings.plugins&&b.settings.plugins["bt-selectpicker"]&&b.$el.find(".rule-filter-container select").selectpicker("render")}})}); \ No newline at end of file +}),this.model.on("update",function(c,d,e){"error"==e&&b.settings.display_errors&&d.$el.find(".error-container").eq(0).tooltip(a).tooltip("hide").tooltip("fixTitle")})},{placement:"right"}),j.define("filter-description",function(a){"inline"===a.mode?this.on("afterUpdateRuleFilter",function(b,c){var d=c.$el.find("p.filter-description");c.filter&&c.filter.description?(0===d.length?(d=$('

    '),d.appendTo(c.$el)):d.show(),d.html(' '+c.filter.description)):d.hide()}):"popover"===a.mode?($.fn.popover&&$.fn.popover.Constructor&&$.fn.popover.Constructor.prototype.fixTitle||e('Bootstrap Popover is required to use "filter-description" plugin. Get it here: http://getbootstrap.com'),this.on("afterUpdateRuleFilter",function(b,c){var d=c.$el.find("button.filter-description");c.filter&&c.filter.description?(0===d.length?(d=$(''),d.prependTo(c.$el.find(".rule-actions")),d.popover({placement:"left",container:"body",html:!0}),d.on("mouseout",function(){d.popover("hide")})):d.show(),d.data("bs.popover").options.content=c.filter.description,d.attr("aria-describedby")&&d.popover("show")):(d.hide(),d.data("bs.popover")&&d.popover("hide"))})):"bootbox"===a.mode&&("bootbox"in window||e('Bootbox is required to use "filter-description" plugin. Get it here: http://bootboxjs.com'),this.on("afterUpdateRuleFilter",function(b,c){var d=c.$el.find("button.filter-description");c.filter&&c.filter.description?(0===d.length&&(d=$(''),d.prependTo(c.$el.find(".rule-actions")),d.on("click",function(){bootbox.alert(d.data("description"))})),d.data("description",c.filter.description)):d.hide()}))},{icon:"glyphicon glyphicon-info-sign",mode:"popover"}),j.defaults({loopbackOperators:{equal:function(a){return a[0]},not_equal:function(a){return{neq:a[0]}},"in":function(a){return{inq:a}},not_in:function(a){return{nin:a}},less:function(a){return{lt:a[0]}},less_or_equal:function(a){return{lte:a[0]}},greater:function(a){return{gt:a[0]}},greater_or_equal:function(a){return{gte:a[0]}},between:function(a){return{between:a}},begins_with:function(a){return{like:"^"+h(a[0])}},not_begins_with:function(a){return{nlike:"^"+h(a[0])}},contains:function(a){return{like:h(a[0])}},not_contains:function(a){return{nlike:h(a[0])}},ends_with:function(a){return{like:h(a[0])+"$"}},not_ends_with:function(a){return{nlike:h(a[0])+"$"}},is_empty:function(){return""},is_not_empty:function(){return{neq:""}},is_null:function(){return null},is_not_null:function(){return{neq:null}}}}),j.extend({getLoopback:function(a){a=void 0===a?this.getRules():a;var b=this;return function c(a){if(a.condition||(a.condition=b.settings.default_condition),-1===["AND","OR"].indexOf(a.condition.toUpperCase())&&e('Unable to build Loopback query with condition "{0}"',a.condition),!a.rules)return{};var d=[];a.rules.forEach(function(a){if(a.rules&&a.rules.length>0)d.push(c(a));else{var g=b.settings.loopbackOperators[a.operator],h=b.getOperatorByType(a.operator),i=[];void 0===g&&e('Unknown Loopback operation for operator "{0}"',a.operator),0!==h.nb_inputs&&(a.value instanceof Array||(a.value=[a.value]),a.value.forEach(function(b){i.push(f(b,a.type))}));var j={};j[a.field]=g.call(b,i),d.push(j)}});var g={};return d.length>0&&(g[a.condition.toLowerCase()]=d),g}(a)}}),j.defaults({mongoOperators:{equal:function(a){return a[0]},not_equal:function(a){return{$ne:a[0]}},"in":function(a){return{$in:a}},not_in:function(a){return{$nin:a}},less:function(a){return{$lt:a[0]}},less_or_equal:function(a){return{$lte:a[0]}},greater:function(a){return{$gt:a[0]}},greater_or_equal:function(a){return{$gte:a[0]}},between:function(a){return{$gte:a[0],$lte:a[1]}},begins_with:function(a){return{$regex:"^"+h(a[0])}},not_begins_with:function(a){return{$regex:"^(?!"+h(a[0])+")"}},contains:function(a){return{$regex:h(a[0])}},not_contains:function(a){return{$regex:"^((?!"+h(a[0])+").)*$",$options:"s"}},ends_with:function(a){return{$regex:h(a[0])+"$"}},not_ends_with:function(a){return{$regex:"(?0)d.push(c(a));else{var g=b.settings.mongoOperators[a.operator],h=b.getOperatorByType(a.operator),i=[];void 0===g&&e('Unknown MongoDB operation for operator "{0}"',a.operator),0!==h.nb_inputs&&(a.value instanceof Array||(a.value=[a.value]),a.value.forEach(function(b){i.push(f(b,a.type,!1))}));var j={};j[a.field]=g.call(b,i),d.push(j)}});var g={};return d.length>0&&(g["$"+a.condition.toLowerCase()]=d),g}(a)},getRulesFromMongo:function(a){if(void 0===a||null===a)return null;var b=this,c=["$and","$or"];return function d(a){var f=Object.keys(a);f.length>1&&e("Invalid MongoDB query format."),-1===c.indexOf(f[0].toLowerCase())&&e('Unable to build Rule from MongoDB query with condition "{0}"',f[0]);var g=f[0].toLowerCase()===c[0]?"AND":"OR",h=a[f[0]],i=[];h.forEach(function(a){var f=Object.keys(a);if(-1!==c.indexOf(f[0].toLowerCase()))i.push(d(a));else{var g=f[0],h=a[g],j=b.determineMongoOperator(h,g);void 0===j&&e("Invalid MongoDB query format.");var k=b.settings.mongoRuleOperators[j];void 0===k&&e('JSON Rule operation unknown for operator "{0}"',j);var l=k.call(b,h);i.push({id:b.change("getMongoDBFieldID",g,h),field:g,operator:l.op,value:l.val})}});var j={};return i.length>0&&(j.condition=g,j.rules=i),j}(a)},determineMongoOperator:function(a){if(null!==a&&"object"==typeof a){var b=Object.keys(a);return 1===b.length?b[0]:void 0!==a.$gte&&void 0!==a.$lte?"between":void 0!==a.$regex?"$regex":void 0}return"eq"},setRulesFromMongo:function(a){this.setRules(this.getRulesFromMongo(a))}}),j.define("sortable",function(b){this.on("afterInit",function(b){$.event.props.push("dataTransfer");var c,d,e=b.builder;e.$el.on("mouseover",".drag-handle",function(){e.$el.find(".rule-container, .rules-group-container").attr("draggable",!0)}),e.$el.on("mouseout",".drag-handle",function(){e.$el.find(".rule-container, .rules-group-container").removeAttr("draggable")}),e.$el.on("dragstart","[draggable]",function(b){b.stopPropagation(),b.dataTransfer.setData("text","drag"),d=a(b.target),setTimeout(function(){var a=$('
     
    ');a.css("min-height",d.$el.height()),c=d.parent.addRule(a,d.getPos()),d.$el.hide()},0)}),e.$el.on("dragenter","[draggable]",function(a){a.preventDefault(),a.stopPropagation(),c&&i(c,$(a.target))}),e.$el.on("dragover","[draggable]",function(a){a.preventDefault(),a.stopPropagation()}),e.$el.on("drop",function(a){a.preventDefault(),a.stopPropagation(),i(d,$(a.target))}),e.$el.on("dragend","[draggable]",function(a){a.preventDefault(),a.stopPropagation(),d.$el.show(),c.drop(),d=c=null,e.$el.find(".rule-container, .rules-group-container").removeAttr("draggable")})}),this.on("parseRuleFlags.filter",function(a){void 0===a.value.no_sortable&&(a.value.no_sortable=b.default_no_sortable)}),this.on("afterApplyRuleFlags",function(a,b){b.flags.no_sortable&&b.$el.find(".drag-handle").remove()}),this.on("getGroupTemplate.filter",function(a,c){if(c>1){var d=$(a.value);d.find(".group-conditions").after('
    '),a.value=d.prop("outerHTML")}}),this.on("getRuleTemplate.filter",function(a){var c=$(a.value);c.find(".rule-header").after('
    '),a.value=c.prop("outerHTML")})},{default_no_sortable:!1,icon:"glyphicon glyphicon-sort"}),j.defaults({sqlOperators:{equal:"= ?",not_equal:"!= ?","in":{op:"IN(?)",sep:", "},not_in:{op:"NOT IN(?)",sep:", "},less:"< ?",less_or_equal:"<= ?",greater:"> ?",greater_or_equal:">= ?",between:{op:"BETWEEN ?",sep:" AND "},begins_with:{op:"LIKE(?)",fn:function(a){return a+"%"}},not_begins_with:{op:"NOT LIKE(?)",fn:function(a){return a+"%"}},contains:{op:"LIKE(?)",fn:function(a){return"%"+a+"%"}},not_contains:{op:"NOT LIKE(?)",fn:function(a){return"%"+a+"%"}},ends_with:{op:"LIKE(?)",fn:function(a){return"%"+a}},not_ends_with:{op:"NOT LIKE(?)",fn:function(a){return"%"+a}},is_empty:'== ""',is_not_empty:'!= ""',is_null:"IS NULL",is_not_null:"IS NOT NULL"},sqlStatements:{question_mark:function(){var a=[];return{add:function(b,c){return a.push(c),"?"},run:function(){return a}}},numbered:function(){var a=0,b=[];return{add:function(c,d){return b.push(d),a++,"$"+a},run:function(){return b}}},named:function(){var a={},b={};return{add:function(c,d){a[c.field]||(a[c.field]=0),a[c.field]++;var e=c.field+"_"+a[c.field];return b[e]=d,":"+e},run:function(){return b}}}}}),j.extend({getSQL:function(a,b,c){c=void 0===c?this.getRules():c,b=b===!0?"\n":" ",(a===!0||void 0===a)&&(a="question_mark"),"string"==typeof a&&(a=this.settings.sqlStatements[a]());var d=this,h=function i(c){if(c.condition||(c.condition=d.settings.default_condition),-1===["AND","OR"].indexOf(c.condition.toUpperCase())&&e('Unable to build SQL query with condition "{0}"',c.condition),!c.rules)return"";var h=[];return c.rules.forEach(function(c){if(c.rules&&c.rules.length>0)h.push("("+b+i(c)+b+")"+b);else{var j=d.getSqlOperator(c.operator),k=d.getOperatorByType(c.operator),l="";j===!1&&e('Unknown SQL operation for operator "{0}"',c.operator),0!==k.nb_inputs&&(c.value instanceof Array||(c.value=[c.value]),c.value.forEach(function(b,d){d>0&&(l+=j.sep),"integer"==c.type||"double"==c.type||"boolean"==c.type?b=f(b,c.type,!0):a||(b=g(b)),j.fn&&(b=j.fn(b)),a?l+=a.add(c,b):("string"==typeof b&&(b="'"+b+"'"),l+=b)})),h.push(c.field+" "+j.op.replace(/\?/,l))}}),h.join(" "+c.condition+b)}(c);return a?{sql:h,params:a.run()}:{sql:h}},getSqlOperator:function(a){var b=this.settings.sqlOperators[a];return void 0===b?!1:("string"==typeof b&&(b={op:b}),b.list&&!b.sep&&(b.sep=", "),b)}}),j.define("unique-filter",function(){this.status.used_filters={},this.on("afterUpdateRuleFilter",this.updateDisabledFilters),this.on("afterDeleteRule",this.updateDisabledFilters),this.on("afterCreateRuleFilters",this.applyDisabledFilters)}),j.extend({updateDisabledFilters:function(a){var b=a.builder;b.status.used_filters={},b.model&&(!function c(a){a.each(function(a){a.filter&&a.filter.unique&&(b.status.used_filters[a.filter.id]||(b.status.used_filters[a.filter.id]=[]),"group"==a.filter.unique&&b.status.used_filters[a.filter.id].push(a.parent))},function(a){c(a)})}(b.model.root),b.applyDisabledFilters(a))},applyDisabledFilters:function(a){var b=a.builder;b.$el.find(".rule-filter-container option").prop("disabled",!1),$.each(b.status.used_filters,function(a,c){0===c.length?b.$el.find(".rule-filter-container option[value="+a+"]:not(:selected)").prop("disabled",!0):c.forEach(function(b){b.each(function(b){b.$el.find(".rule-filter-container option[value="+a+"]:not(:selected)").prop("disabled",!0)})})}),b.settings.plugins&&b.settings.plugins["bt-selectpicker"]&&b.$el.find(".rule-filter-container select").selectpicker("render")}})}); \ No newline at end of file diff --git a/dist/js/query-builder.standalone.js b/dist/js/query-builder.standalone.js index 56a183e9..1f7bc4f0 100644 --- a/dist/js/query-builder.standalone.js +++ b/dist/js/query-builder.standalone.js @@ -124,7 +124,7 @@ })); /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Copyright 2014-2015 Damien "Mistic" Sorel (http://www.strangeplanet.fr) * Licensed under MIT (http://opensource.org/licenses/MIT) */ @@ -896,7 +896,9 @@ QueryBuilder.prototype.updateRuleOperator = function(rule, previousOperator) { if ($valueContainer.is(':empty') || rule.operator.nb_inputs !== previousOperator.nb_inputs) { this.createRuleInput(rule); } + } + if (rule.operator) { rule.$el.find('.rule-operator-container [name$=_operator]').val(rule.operator.type); } @@ -1201,9 +1203,6 @@ QueryBuilder.prototype.setRules = function(data) { if (rule.id === undefined) { error('Missing rule field id'); } - if (rule.value === undefined) { - rule.value = ''; - } if (rule.operator === undefined) { rule.operator = 'equal'; } @@ -1221,7 +1220,7 @@ QueryBuilder.prototype.setRules = function(data) { model.data = rule.data; } - if (model.operator.nb_inputs !== 0) { + if (model.operator.nb_inputs !== 0 && rule.value !== undefined) { that.setRuleValue(model, rule.value); } } @@ -3015,13 +3014,15 @@ QueryBuilder.define('sortable', function(options) { src = Model(e.target); - var ph = $('
     
    '); - ph.css('min-height', src.$el.height()); + // Chrome glitchs + // - helper invisible if hidden immediately + // - "dragend" is called immediately if we modify the DOM directly + setTimeout(function() { + var ph = $('
     
    '); + ph.css('min-height', src.$el.height()); - placeholder = src.parent.addRule(ph, src.getPos()); + placeholder = src.parent.addRule(ph, src.getPos()); - // Chrome glitch (helper invisible if hidden immediately) - setTimeout(function() { src.$el.hide(); }, 0); }); @@ -3031,7 +3032,9 @@ QueryBuilder.define('sortable', function(options) { e.preventDefault(); e.stopPropagation(); - moveSortableToTarget(placeholder, $(e.target)); + if (placeholder) { + moveSortableToTarget(placeholder, $(e.target)); + } }); // dragover: prevent glitches diff --git a/dist/js/query-builder.standalone.min.js b/dist/js/query-builder.standalone.min.js index d754162e..e171da2f 100644 --- a/dist/js/query-builder.standalone.min.js +++ b/dist/js/query-builder.standalone.min.js @@ -1,8 +1,8 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Copyright 2014-2015 Damien "Mistic" Sorel (http://www.strangeplanet.fr) * Licensed under MIT (http://opensource.org/licenses/MIT) */ -!function(a,b){"function"==typeof define&&define.amd?define("jQuery.extendext",["jquery"],b):b(a.jQuery)}(this,function($){"use strict";$.extendext=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1,k="default";for("boolean"==typeof g&&(j=g,g=arguments[h++]||{}),"string"==typeof g&&(k=$([g.toLowerCase(),"default"]).filter(["default","concat","replace","extend"])[0],g=arguments[h++]||{}),"object"==typeof g||$.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!==(a=arguments[h]))if($.isArray(a)&&"default"!==k)switch(f=g&&$.isArray(g)?g:[],k){case"concat":g=f.concat($.extend(j,[],a));break;case"replace":g=$.extend(j,[],a);break;case"extend":a.forEach(function(a,b){if("object"==typeof a){var c=$.isArray(a)?[]:{};f[b]=$.extendext(j,k,f[b]||c,a)}else-1===f.indexOf(a)&&f.push(a)}),g=f}else for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&($.isPlainObject(d)||(e=$.isArray(d)))?(e?(e=!1,f=c&&$.isArray(c)?c:[]):f=c&&$.isPlainObject(c)?c:{},g[b]=$.extendext(j,k,f,d)):void 0!==d&&(g[b]=d));return g}}),function(a,b){"function"==typeof define&&define.amd?define("query-builder",["jquery","jQuery.extendext"],b):b(a.jQuery)}(this,function($){"use strict";function a(b){return this instanceof a?(this.root=null,void(this.$=$(this))):a.getModel(b)}function b(a,b){b.forEach(function(b){Object.defineProperty(a.prototype,b,{enumerable:!0,get:function(){return this.__[b]},set:function(a){var c=null!==this.__[b]&&"object"==typeof this.__[b]?$.extend({},this.__[b]):this.__[b];this.__[b]=a,null!==this.model&&this.model.trigger("update",this,b,a,c)}})})}function c(a,b){a&&($.isArray(a)?a.forEach(function(a){$.isPlainObject(a)?$.each(a,function(a,c){return b(a,c),!1}):b(a,a)}):$.each(a,function(a,c){b(a,c)}))}function d(a,b){return b=Array.prototype.slice.call(arguments),a.replace(/{([0-9]+)}/g,function(a,c){return b[parseInt(c)+1]})}function e(){$.error(d.apply(null,arguments))}function f(a,b,c){switch(b){case"integer":return parseInt(a);case"double":return parseFloat(a);case"boolean":var d="true"===a.trim().toLowerCase()||"1"===a.trim()||1===a;return c?d?1:0:d;default:return a}}function g(a){return"string"!=typeof a?a:a.replace(/[\0\n\r\b\\\'\"]/g,function(a){switch(a){case"\x00":return"\\0";case"\n":return"\\n";case"\r":return"\\r";case"\b":return"\\b";default:return"\\"+a}}).replace(/\t/g,"\\t").replace(/\x1a/g,"\\Z")}function h(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}function i(b,c){var d;return d=c.closest(".rule-container"),d.length?void b.moveAfter(a(d)):(d=c.closest(".rules-group-header"),d.length?(d=c.closest(".rules-group-container"),void b.moveAtBegin(a(d))):(d=c.closest(".rules-group-container"),d.length?void b.moveAtEnd(a(d)):void 0))}var j=function(a,b){this.init(a,b)},k=Array.prototype.slice;$.extend(j.prototype,{change:function(a,b){var c=new $.Event(a+".queryBuilder.filter",{builder:this,value:b});return this.$el.triggerHandler(c,k.call(arguments,2)),c.value},trigger:function(a){var b=new $.Event(a+".queryBuilder",{builder:this});return this.$el.triggerHandler(b,k.call(arguments,1)),b},on:function(a,b){return this.$el.on(a+".queryBuilder",b),this},off:function(a,b){return this.$el.off(a+".queryBuilder",b),this},once:function(a,b){return this.$el.one(a+".queryBuilder",b),this}}),j.plugins={},j.defaults=function(a){return"object"!=typeof a?"string"==typeof a?"object"==typeof j.DEFAULTS[a]?$.extend(!0,{},j.DEFAULTS[a]):j.DEFAULTS[a]:$.extend(!0,{},j.DEFAULTS):void $.extendext(!0,"replace",j.DEFAULTS,a)},j.define=function(a,b,c){j.plugins[a]={fct:b,def:c||{}}},j.extend=function(a){$.extend(j.prototype,a)},j.prototype.initPlugins=function(){if(this.plugins){if($.isArray(this.plugins)){var a={};this.plugins.forEach(function(b){a[b]=null}),this.plugins=a}Object.keys(this.plugins).forEach(function(a){a in j.plugins?(this.plugins[a]=$.extend(!0,{},j.plugins[a].def,this.plugins[a]||{}),j.plugins[a].fct.call(this,this.plugins[a])):e('Unable to find plugin "{0}"',a)},this)}},j.types={string:"string",integer:"number","double":"number",date:"datetime",time:"datetime",datetime:"datetime","boolean":"boolean"},j.inputs=["text","textarea","radio","checkbox","select"],j.modifiable_options=["display_errors","allow_groups","allow_empty"],j.DEFAULTS={filters:[],plugins:[],display_errors:!0,allow_groups:-1,allow_empty:!1,conditions:["AND","OR"],default_condition:"AND",inputs_separator:" , ",select_placeholder:"------",default_rule_flags:{filter_readonly:!1,operator_readonly:!1,value_readonly:!1,no_delete:!1},template:{group:null,rule:null},lang:{add_rule:"Add rule",add_group:"Add group",delete_rule:"Delete",delete_group:"Delete",conditions:{AND:"AND",OR:"OR"},operators:{equal:"equal",not_equal:"not equal","in":"in",not_in:"not in",less:"less",less_or_equal:"less or equal",greater:"greater",greater_or_equal:"greater or equal",between:"between",begins_with:"begins with",not_begins_with:"doesn't begin with",contains:"contains",not_contains:"doesn't contain",ends_with:"ends with",not_ends_with:"doesn't end with",is_empty:"is empty",is_not_empty:"is not empty",is_null:"is null",is_not_null:"is not null"},errors:{no_filter:"No filter selected",empty_group:"The group is empty",radio_empty:"No value selected",checkbox_empty:"No value selected",select_empty:"No value selected",string_empty:"Empty value",string_exceed_min_length:"Must contain at least {0} characters",string_exceed_max_length:"Must not contain more than {0} characters",string_invalid_format:"Invalid format ({0})",number_nan:"Not a number",number_not_integer:"Not an integer",number_not_double:"Not a real number",number_exceed_min:"Must be greater than {0}",number_exceed_max:"Must be lower than {0}",number_wrong_step:"Must be a multiple of {0}",datetime_empty:"Empty value",datetime_invalid:"Invalid date format ({0})",datetime_exceed_min:"Must be after {0}",datetime_exceed_max:"Must be before {0}",boolean_not_valid:"Not a boolean",operator_not_multiple:"Operator {0} cannot accept multiple values"}},operators:[{type:"equal",nb_inputs:1,multiple:!1,apply_to:["string","number","datetime","boolean"]},{type:"not_equal",nb_inputs:1,multiple:!1,apply_to:["string","number","datetime","boolean"]},{type:"in",nb_inputs:1,multiple:!0,apply_to:["string","number","datetime"]},{type:"not_in",nb_inputs:1,multiple:!0,apply_to:["string","number","datetime"]},{type:"less",nb_inputs:1,multiple:!1,apply_to:["number","datetime"]},{type:"less_or_equal",nb_inputs:1,multiple:!1,apply_to:["number","datetime"]},{type:"greater",nb_inputs:1,multiple:!1,apply_to:["number","datetime"]},{type:"greater_or_equal",nb_inputs:1,multiple:!1,apply_to:["number","datetime"]},{type:"between",nb_inputs:2,multiple:!1,apply_to:["number","datetime"]},{type:"begins_with",nb_inputs:1,multiple:!1,apply_to:["string"]},{type:"not_begins_with",nb_inputs:1,multiple:!1,apply_to:["string"]},{type:"contains",nb_inputs:1,multiple:!1,apply_to:["string"]},{type:"not_contains",nb_inputs:1,multiple:!1,apply_to:["string"]},{type:"ends_with",nb_inputs:1,multiple:!1,apply_to:["string"]},{type:"not_ends_with",nb_inputs:1,multiple:!1,apply_to:["string"]},{type:"is_empty",nb_inputs:0,multiple:!1,apply_to:["string"]},{type:"is_not_empty",nb_inputs:0,multiple:!1,apply_to:["string"]},{type:"is_null",nb_inputs:0,multiple:!1,apply_to:["string","number","datetime","boolean"]},{type:"is_not_null",nb_inputs:0,multiple:!1,apply_to:["string","number","datetime","boolean"]}],icons:{add_group:"glyphicon glyphicon-plus-sign",add_rule:"glyphicon glyphicon-plus",remove_group:"glyphicon glyphicon-remove",remove_rule:"glyphicon glyphicon-remove",error:"glyphicon glyphicon-warning-sign"}},j.prototype.init=function(b,c){b[0].queryBuilder=this,this.$el=b,this.settings=$.extendext(!0,"replace",{},j.DEFAULTS,c),this.model=new a,this.status={group_id:0,rule_id:0,generated_id:!1,has_optgroup:!1,id:null},this.settings.allow_groups===!1?this.settings.allow_groups=0:this.settings.allow_groups===!0&&(this.settings.allow_groups=-1),this.filters=this.settings.filters,this.lang=this.settings.lang,this.icons=this.settings.icons,this.operators=this.settings.operators,this.template=this.settings.template,this.plugins=this.settings.plugins,null===this.template.group&&(this.template.group=this.getGroupTemplate),null===this.template.rule&&(this.template.rule=this.getRuleTemplate),this.$el.attr("id")||(this.$el.attr("id","qb_"+Math.floor(99999*Math.random())),this.status.generated_id=!0),this.status.id=this.$el.attr("id"),this.$el.addClass("query-builder form-inline"),this.checkFilters(),this.bindEvents(),this.initPlugins(),this.trigger("afterInit"),c.rules?(this.setRules(c.rules),delete this.settings.rules):this.setRoot(!0)},j.prototype.checkFilters=function(){var a=[],b=this;if(this.filters&&0!==this.filters.length||e("Missing filters list"),this.filters.forEach(function(c,d){switch(c.id||e("Missing filter {0} id",d),-1!=a.indexOf(c.id)&&e('Filter "{0}" already defined',c.id),a.push(c.id),c.type?j.types[c.type]||e('Invalid type "{0}"',c.type):c.type="string",c.input?"function"!=typeof c.input&&-1==j.inputs.indexOf(c.input)&&e('Invalid input "{0}"',c.input):c.input="text",c.field||(c.field=c.id),c.label||(c.label=c.field),c.optgroup?b.status.has_optgroup=!0:c.optgroup=null,c.input){case"radio":case"checkbox":(!c.values||c.values.length<1)&&e('Missing filter "{0}" values',c.id)}}),this.status.has_optgroup){var c=[],d=[];this.filters.forEach(function(a){var b;a.optgroup?(b=c.lastIndexOf(a.optgroup),-1==b?b=c.length:b++):b=c.length,c.splice(b,0,a.optgroup),d.splice(b,0,a)}),this.filters=d}},j.prototype.bindEvents=function(){var b=this;this.$el.on("change.queryBuilder",".rules-group-header [name$=_cond]",function(){if($(this).is(":checked")){var b=$(this).closest(".rules-group-container");a(b).condition=$(this).val()}}),this.$el.on("change.queryBuilder",".rule-filter-container [name$=_filter]",function(){var c=$(this).closest(".rule-container");a(c).filter=b.getFilterById($(this).val())}),this.$el.on("change.queryBuilder",".rule-operator-container [name$=_operator]",function(){var c=$(this).closest(".rule-container");a(c).operator=b.getOperatorByType($(this).val())}),this.$el.on("click.queryBuilder","[data-add=rule]",function(){var c=$(this).closest(".rules-group-container");b.addRule(a(c))}),this.$el.on("click.queryBuilder","[data-delete=rule]",function(){var c=$(this).closest(".rule-container");b.deleteRule(a(c))}),0!==this.settings.allow_groups&&(this.$el.on("click.queryBuilder","[data-add=group]",function(){var c=$(this).closest(".rules-group-container");b.addGroup(a(c))}),this.$el.on("click.queryBuilder","[data-delete=group]",function(){var c=$(this).closest(".rules-group-container");b.deleteGroup(a(c))})),this.model.on({drop:function(a,b){b.$el.remove()},add:function(a,b,c){b.$el.detach(),0===c?b.$el.prependTo(b.parent.$el.find(">.rules-group-body>.rules-list")):b.$el.insertAfter(b.parent.rules[c-1].$el)},update:function(a,c,d,e,f){switch(d){case"error":b.displayError(c);break;case"condition":b.updateGroupCondition(c);break;case"filter":b.updateRuleFilter(c);break;case"operator":b.updateRuleOperator(c,f);break;case"flags":b.applyRuleFlags(c)}}})},j.prototype.setRoot=function(a){a=void 0===a||a===!0;var b=this.nextGroupId(),c=$(this.template.group.call(this,b,1));return this.$el.append(c),this.model.root=new m(null,c),this.model.root.model=this.model,this.model.root.condition=this.settings.default_condition,a&&this.addRule(this.model.root),this.model.root},j.prototype.addGroup=function(a,b){b=void 0===b||b===!0;var c=a.level+1,d=this.trigger("beforeAddGroup",a,b,c);if(d.isDefaultPrevented())return null;var e=this.nextGroupId(),f=$(this.template.group.call(this,e,c)),g=a.addGroup(f);return this.trigger("afterAddGroup",g),g.condition=this.settings.default_condition,b&&this.addRule(g),g},j.prototype.deleteGroup=function(a){if(a.isRoot())return!1;var b=this.trigger("beforeDeleteGroup",a);if(b.isDefaultPrevented())return!1;var c=!0;return a.each("reverse",function(a){c&=this.deleteRule(a)},function(a){c&=this.deleteGroup(a)},this),c&&(a.drop(),this.trigger("afterDeleteGroup")),c},j.prototype.updateGroupCondition=function(a){a.$el.find(">.rules-group-header [name$=_cond]").each(function(){var b=$(this);b.prop("checked",b.val()===a.condition),b.parent().toggleClass("active",b.val()===a.condition)})},j.prototype.addRule=function(a){var b=this.trigger("beforeAddRule",a);if(b.isDefaultPrevented())return null;var c=this.nextRuleId(),d=$(this.template.rule.call(this,c)),e=a.addRule(d);return this.trigger("afterAddRule",e),this.createRuleFilters(e),e},j.prototype.deleteRule=function(a){if(a.flags.no_delete)return!1;var b=this.trigger("beforeDeleteRule",a);return b.isDefaultPrevented()?!1:(a.drop(),this.trigger("afterDeleteRule"),!0)},j.prototype.createRuleFilters=function(a){var b=this.change("getRuleFilters",this.filters,a),c=$(this.getRuleFilterSelect(a,b));a.$el.find(".rule-filter-container").append(c),this.trigger("afterCreateRuleFilters",a)},j.prototype.createRuleOperators=function(a,b){var c=a.$el.find(".rule-operator-container").empty();if(a.filter){var d=this.getOperators(a.filter),e=$(this.getRuleOperatorSelect(a,d));c.html(e),b!==!1?a.operator=d[0]:a.__.operator=d[0],this.trigger("afterCreateRuleOperators",a,d)}},j.prototype.createRuleInput=function(a){var b=a.$el.find(".rule-value-container").empty();if(a.filter&&0!==a.operator.nb_inputs){for(var c=$(),d=a.filter,e=0;e0&&b.append(this.settings.inputs_separator),b.append(f),c=c.add(f)}b.show(),d.plugin&&c[d.plugin](d.plugin_config||{}),this.trigger("afterCreateRuleInput",a),void 0!==d.default_value&&this.setRuleValue(a,d.default_value)}},j.prototype.updateRuleFilter=function(a){this.createRuleOperators(a,!1),this.createRuleInput(a),a.$el.find(".rule-filter-container [name$=_filter]").val(a.filter?a.filter.id:"-1"),this.trigger("afterUpdateRuleFilter",a)},j.prototype.updateRuleOperator=function(a,b){var c=a.$el.find(".rule-value-container");a.operator&&0!==a.operator.nb_inputs?(c.show(),(c.is(":empty")||a.operator.nb_inputs!==b.nb_inputs)&&this.createRuleInput(a),a.$el.find(".rule-operator-container [name$=_operator]").val(a.operator.type)):c.hide(),this.trigger("afterUpdateRuleOperator",a)},j.prototype.applyRuleFlags=function(a){var b=a.flags;b.filter_readonly&&a.$el.find("[name$=_filter]").prop("disabled",!0),b.operator_readonly&&a.$el.find("[name$=_operator]").prop("disabled",!0),b.value_readonly&&a.$el.find("[name*=_value_]").prop("disabled",!0),b.no_delete&&a.$el.find("[data-delete=rule]").remove(),this.trigger("afterApplyRuleFlags",a)},j.prototype.clearErrors=function(a){a=a||this.model.root,a&&(a.error=null,a instanceof m&&a.each(function(a){a.error=null},function(a){this.clearErrors(a)},this))},j.prototype.displayError=function(a){if(this.settings.display_errors)if(null===a.error)a.$el.removeClass("has-error");else{var b=$.extend([],a.error,[this.lang.errors[a.error[0]]||a.error[0]]);a.$el.addClass("has-error").find(".error-container").eq(0).attr("title",d.apply(null,b))}},j.prototype.triggerValidationError=function(a,b,c){$.isArray(b)||(b=[b]);var d=this.trigger("validationError",a,b,c);d.isDefaultPrevented()||(a.error=b)},j.prototype.destroy=function(){this.trigger("beforeDestroy"),this.status.generated_id&&this.$el.removeAttr("id"),this.clear(),this.model=null,this.$el.off(".queryBuilder").removeClass("query-builder").removeData("queryBuilder"),delete this.$el[0].queryBuilder},j.prototype.reset=function(){this.status.group_id=1,this.status.rule_id=0,this.model.root.empty(),this.addRule(this.model.root),this.trigger("afterReset")},j.prototype.clear=function(){this.status.group_id=0,this.status.rule_id=0,this.model.root&&(this.model.root.drop(),this.model.root=null),this.trigger("afterClear")},j.prototype.setOptions=function(a){$.makeArray($(Object.keys(a)).filter(j.modifiable_options)).forEach(function(b){this.settings[b]=a[b]},this)},j.prototype.validate=function(){this.clearErrors();var a=this,b=function c(b){var d=0,e=0;return b.each(function(b){if(!b.filter)return a.triggerValidationError(b,"no_filter",null),void e++;if(0!==b.operator.nb_inputs){var c=a.getRuleValue(b),f=a.validateValue(b,c);if(f!==!0)return a.triggerValidationError(b,f,c),void e++}d++},function(a){c(a)?d++:e++}),e>0?!1:0!==d||a.settings.allow_empty&&b.isRoot()?!0:(a.triggerValidationError(b,"empty_group",null),!1)}(this.model.root);return this.change("validate",b)},j.prototype.getRules=function(){if(!this.validate())return{};var a=this,b=function c(b){var d={condition:b.condition,rules:[]};return b.each(function(b){var c=null;0!==b.operator.nb_inputs&&(c=a.getRuleValue(b));var e={id:b.filter.id,field:b.filter.field,type:b.filter.type,input:b.filter.input,operator:b.operator.type,value:c};(b.filter.data||b.data)&&(e.data=$.extendext(!0,"replace",{},b.filter.data,b.data)),d.rules.push(e)},function(a){d.rules.push(c(a))}),d}(this.model.root);return this.change("getRules",b)},j.prototype.setRules=function(a){this.clear(),this.setRoot(!1),a&&a.rules&&(0!==a.rules.length||this.settings.allow_empty)||e("Incorrect data object passed"),a=this.change("setRules",a);var b=this;!function c(a,d){null!==d&&(void 0===a.condition?a.condition=b.settings.default_condition:-1==b.settings.conditions.indexOf(a.condition)&&e('Invalid condition "{0}"',a.condition),d.condition=a.condition.toUpperCase(),a.rules.forEach(function(a){var f;if(a.rules&&a.rules.length>0)-1!=b.settings.allow_groups&&b.settings.allow_groups1){h=["operator_not_multiple",this.lang[f.type]||f.type];break}break;case"select":if(d.multiple){if(0===b[i].length){h=["select_empty"];break}if(!f.multiple&&b[i].length>1){h=["operator_not_multiple",this.lang[f.type]||f.type];break}}else if(void 0===b[i]){h=["select_empty"];break}break;default:switch(j.types[d.type]){case"string":if(0===b[i].length){h=["string_empty"];break}if(void 0!==g.min&&b[i].lengthparseInt(g.max)){h=["string_exceed_max_length",g.max];break}if(g.format&&("string"==typeof g.format&&(g.format=new RegExp(g.format)),!g.format.test(b[i]))){h=["string_invalid_format",g.format];break}break;case"number":if(isNaN(b[i])){h=["number_nan"];break}if("integer"==d.type){if(parseInt(b[i])!=b[i]){h=["number_not_integer"];break}}else if(parseFloat(b[i])!=b[i]){h=["number_not_double"];break}if(void 0!==g.min&&b[i]parseFloat(g.max)){h=["number_exceed_max",g.max];break}if(void 0!==g.step){var k=b[i]/g.step;if(parseInt(k)!=k){h=["number_wrong_step",g.step];break}}break;case"datetime":if(0===b[i].length){h=["datetime_empty"];break}if(g.format){"moment"in window||e("MomentJS is required for Date/Time validation");var l=moment(b[i],g.format);if(!l.isValid()){h=["datetime_invalid"];break}if(g.min&&lmoment(g.max,g.format)){h=["datetime_exceed_max",g.max];break}}break;case"boolean":if(c=b[i].trim().toLowerCase(),"true"!==c&&"false"!==c&&"1"!==c&&"0"!==c&&1!==b[i]&&0!==b[i]){h=["boolean_not_valid"];break}}}if(h!==!0)break}return h},j.prototype.nextGroupId=function(){return this.status.id+"_group_"+this.status.group_id++},j.prototype.nextRuleId=function(){return this.status.id+"_rule_"+this.status.rule_id++},j.prototype.getOperators=function(a){"string"==typeof a&&(a=this.getFilterById(a));for(var b=[],c=0,d=this.operators.length;d>c;c++){if(a.operators){if(-1==a.operators.indexOf(this.operators[c].type))continue}else if(-1==this.operators[c].apply_to.indexOf(j.types[a.type]))continue;b.push(this.operators[c])}return a.operators&&b.sort(function(b,c){return a.operators.indexOf(b.type)-a.operators.indexOf(c.type)}),this.change("getOperators",b,a)},j.prototype.getFilterById=function(a){if("-1"==a)return null;for(var b=0,c=this.filters.length;c>b;b++)if(this.filters[b].id==a)return this.filters[b];e('Undefined filter "{0}"',a)},j.prototype.getOperatorByType=function(a){if("-1"==a)return null;for(var b=0,c=this.operators.length;c>b;b++)if(this.operators[b].type==a)return this.operators[b];e('Undefined operator "{0}"',a)},j.prototype.getRuleValue=function(a){for(var b,c=a.filter,d=a.operator,e=a.$el.find(".rule-value-container"),f=[],g=0;g
    "+(-1===this.settings.allow_groups||this.settings.allow_groups>=b?'":"")+" "+(b>1?'":"")+'
    '+this.getGroupConditions(a,b)+"
    "+(this.settings.display_errors?'
    ':"")+"
      ";return this.change("getGroupTemplate",c,b)},j.prototype.getGroupConditions=function(a,b){for(var c="",d=0,e=this.settings.conditions.length;e>d;d++){var f=this.settings.conditions[d],g=this.lang.conditions[f]||f;c+=' "}return this.change("getGroupConditions",c,b)},j.prototype.getRuleTemplate=function(a){var b='
    • "+(this.settings.display_errors?'
      ':"")+'
    • ';return this.change("getRuleTemplate",b)},j.prototype.getRuleFilterSelect=function(a,b){var c=null,d='",this.change("getRuleFilterSelect",d,a)},j.prototype.getRuleOperatorSelect=function(a,b){for(var c='",this.change("getRuleOperatorSelect",c,a)},j.prototype.getRuleInput=function(a,b){var d=a.filter,e=a.filter.validation||{},f=a.id+"_value_"+b,g=d.vertical?" class=block":"",h="";if("function"==typeof d.input)h=d.input.call(this,a,f);else switch(d.input){case"radio":c(d.values,function(a,b){h+=" '+b+" "});break;case"checkbox":c(d.values,function(a,b){h+=" '+b+" "});break;case"select":h+='";break;case"textarea":h+='";break;default:switch(j.types[d.type]){case"number":h+='=f:f>=e},i=!1;h()&&(this.rules[e]instanceof m?void 0!==c&&(i=c.call(d,this.rules[e])===!1):i=b.call(d,this.rules[e])===!1,!i);e+=g);return!i},m.prototype.contains=function(a,b){return-1!==this.getNodePos(a)?!0:b?!this.each(function(){return!0},function(b){return!b.contains(a,!0)}):!1};var n=function(a,b){return this instanceof n?(l.call(this,a,b),this.filter=null,this.operator=null,void(this.flags={})):new n(a,b)};n.prototype=Object.create(l.prototype),n.prototype.constructor=n,b(n,["filter","operator","flags"]),j.Group=m,j.Rule=n,$.fn.queryBuilder=function(a){this.length>1&&e("Unable to initialize on multiple target");var b=this.data("queryBuilder"),c="object"==typeof a&&a||{};return b||"destroy"!=a?(b||this.data("queryBuilder",new j(this,c)),"string"==typeof a?b[a].apply(b,Array.prototype.slice.call(arguments,1)):this):this},$.fn.queryBuilder.constructor=j,$.fn.queryBuilder.defaults=j.defaults,$.fn.queryBuilder.extend=j.extend,$.fn.queryBuilder.define=j.define,j.define("bt-checkbox",function(a){if("glyphicons"==a.font){var b=document.createElement("style");b.innerHTML='.checkbox input[type=checkbox]:checked + label:after { font-family: "Glyphicons Halflings"; content: "\\e013"; } .checkbox label:after { padding-left: 4px; padding-top: 2px; font-size: 9px; }',document.body.appendChild(b)}this.on("getRuleInput.filter",function(b,d,e){var f=d.filter;if(("radio"===f.input||"checkbox"===f.input)&&!f.plugin){b.value="",f.colors||(f.colors={}),f.color&&(f.colors._def_=f.color);var g,h,i=f.vertical?' style="display:block"':"",j=0;c(f.values,function(c,d){g=f.colors[c]||f.colors._def_||a.color,h=e+"_"+j++,b.value+=" "})}})},{font:"glyphicons",color:"default"}),j.define("bt-selectpicker",function(a){$.fn.selectpicker&&$.fn.selectpicker.Constructor||e('Bootstrap Select is required to use "bt-selectpicker" plugin. Get it here: http://silviomoreto.github.io/bootstrap-select'), +this.on("afterCreateRuleFilters",function(b,c){c.$el.find(".rule-filter-container select").removeClass("form-control").selectpicker(a)}),this.on("afterCreateRuleOperators",function(b,c){c.$el.find(".rule-operator-container select").removeClass("form-control").selectpicker(a)}),this.on("afterUpdateRuleFilter",function(a,b){b.$el.find(".rule-filter-container select").selectpicker("render")}),this.on("afterUpdateRuleOperator",function(a,b){b.$el.find(".rule-operator-container select").selectpicker("render")})},{container:"body",style:"btn-inverse btn-xs",width:"auto",showIcon:!1}),j.define("bt-tooltip-errors",function(a){$.fn.tooltip&&$.fn.tooltip.Constructor&&$.fn.tooltip.Constructor.prototype.fixTitle||e('Bootstrap Tooltip is required to use "bt-tooltip-errors" plugin. Get it here: http://getbootstrap.com');var b=this;this.on("getRuleTemplate.filter",function(a){a.value=a.value.replace('class="error-container"','class="error-container" data-toggle="tooltip"')}),this.on("getGroupTemplate.filter",function(a){a.value=a.value.replace('class="error-container"','class="error-container" data-toggle="tooltip"')}),this.model.on("update",function(c,d,e){"error"==e&&b.settings.display_errors&&d.$el.find(".error-container").eq(0).tooltip(a).tooltip("hide").tooltip("fixTitle")})},{placement:"right"}),j.define("filter-description",function(a){"inline"===a.mode?this.on("afterUpdateRuleFilter",function(b,c){var d=c.$el.find("p.filter-description");c.filter&&c.filter.description?(0===d.length?(d=$('

      '),d.appendTo(c.$el)):d.show(),d.html(' '+c.filter.description)):d.hide()}):"popover"===a.mode?($.fn.popover&&$.fn.popover.Constructor&&$.fn.popover.Constructor.prototype.fixTitle||e('Bootstrap Popover is required to use "filter-description" plugin. Get it here: http://getbootstrap.com'),this.on("afterUpdateRuleFilter",function(b,c){var d=c.$el.find("button.filter-description");c.filter&&c.filter.description?(0===d.length?(d=$(''),d.prependTo(c.$el.find(".rule-actions")),d.popover({placement:"left",container:"body",html:!0}),d.on("mouseout",function(){d.popover("hide")})):d.show(),d.data("bs.popover").options.content=c.filter.description,d.attr("aria-describedby")&&d.popover("show")):(d.hide(),d.data("bs.popover")&&d.popover("hide"))})):"bootbox"===a.mode&&("bootbox"in window||e('Bootbox is required to use "filter-description" plugin. Get it here: http://bootboxjs.com'),this.on("afterUpdateRuleFilter",function(b,c){var d=c.$el.find("button.filter-description");c.filter&&c.filter.description?(0===d.length&&(d=$(''),d.prependTo(c.$el.find(".rule-actions")),d.on("click",function(){bootbox.alert(d.data("description"))})),d.data("description",c.filter.description)):d.hide()}))},{icon:"glyphicon glyphicon-info-sign",mode:"popover"}),j.defaults({loopbackOperators:{equal:function(a){return a[0]},not_equal:function(a){return{neq:a[0]}},"in":function(a){return{inq:a}},not_in:function(a){return{nin:a}},less:function(a){return{lt:a[0]}},less_or_equal:function(a){return{lte:a[0]}},greater:function(a){return{gt:a[0]}},greater_or_equal:function(a){return{gte:a[0]}},between:function(a){return{between:a}},begins_with:function(a){return{like:"^"+h(a[0])}},not_begins_with:function(a){return{nlike:"^"+h(a[0])}},contains:function(a){return{like:h(a[0])}},not_contains:function(a){return{nlike:h(a[0])}},ends_with:function(a){return{like:h(a[0])+"$"}},not_ends_with:function(a){return{nlike:h(a[0])+"$"}},is_empty:function(){return""},is_not_empty:function(){return{neq:""}},is_null:function(){return null},is_not_null:function(){return{neq:null}}}}),j.extend({getLoopback:function(a){a=void 0===a?this.getRules():a;var b=this;return function c(a){if(a.condition||(a.condition=b.settings.default_condition),-1===["AND","OR"].indexOf(a.condition.toUpperCase())&&e('Unable to build Loopback query with condition "{0}"',a.condition),!a.rules)return{};var d=[];a.rules.forEach(function(a){if(a.rules&&a.rules.length>0)d.push(c(a));else{var g=b.settings.loopbackOperators[a.operator],h=b.getOperatorByType(a.operator),i=[];void 0===g&&e('Unknown Loopback operation for operator "{0}"',a.operator),0!==h.nb_inputs&&(a.value instanceof Array||(a.value=[a.value]),a.value.forEach(function(b){i.push(f(b,a.type))}));var j={};j[a.field]=g.call(b,i),d.push(j)}});var g={};return d.length>0&&(g[a.condition.toLowerCase()]=d),g}(a)}}),j.defaults({mongoOperators:{equal:function(a){return a[0]},not_equal:function(a){return{$ne:a[0]}},"in":function(a){return{$in:a}},not_in:function(a){return{$nin:a}},less:function(a){return{$lt:a[0]}},less_or_equal:function(a){return{$lte:a[0]}},greater:function(a){return{$gt:a[0]}},greater_or_equal:function(a){return{$gte:a[0]}},between:function(a){return{$gte:a[0],$lte:a[1]}},begins_with:function(a){return{$regex:"^"+h(a[0])}},not_begins_with:function(a){return{$regex:"^(?!"+h(a[0])+")"}},contains:function(a){return{$regex:h(a[0])}},not_contains:function(a){return{$regex:"^((?!"+h(a[0])+").)*$",$options:"s"}},ends_with:function(a){return{$regex:h(a[0])+"$"}},not_ends_with:function(a){return{$regex:"(?0)d.push(c(a));else{var g=b.settings.mongoOperators[a.operator],h=b.getOperatorByType(a.operator),i=[];void 0===g&&e('Unknown MongoDB operation for operator "{0}"',a.operator),0!==h.nb_inputs&&(a.value instanceof Array||(a.value=[a.value]),a.value.forEach(function(b){i.push(f(b,a.type,!1))}));var j={};j[a.field]=g.call(b,i),d.push(j)}});var g={};return d.length>0&&(g["$"+a.condition.toLowerCase()]=d),g}(a)},getRulesFromMongo:function(a){if(void 0===a||null===a)return null;var b=this,c=["$and","$or"];return function d(a){var f=Object.keys(a);f.length>1&&e("Invalid MongoDB query format."),-1===c.indexOf(f[0].toLowerCase())&&e('Unable to build Rule from MongoDB query with condition "{0}"',f[0]);var g=f[0].toLowerCase()===c[0]?"AND":"OR",h=a[f[0]],i=[];h.forEach(function(a){var f=Object.keys(a);if(-1!==c.indexOf(f[0].toLowerCase()))i.push(d(a));else{var g=f[0],h=a[g],j=b.determineMongoOperator(h,g);void 0===j&&e("Invalid MongoDB query format.");var k=b.settings.mongoRuleOperators[j];void 0===k&&e('JSON Rule operation unknown for operator "{0}"',j);var l=k.call(b,h);i.push({id:b.change("getMongoDBFieldID",g,h),field:g,operator:l.op,value:l.val})}});var j={};return i.length>0&&(j.condition=g,j.rules=i),j}(a)},determineMongoOperator:function(a){if(null!==a&&"object"==typeof a){var b=Object.keys(a);return 1===b.length?b[0]:void 0!==a.$gte&&void 0!==a.$lte?"between":void 0!==a.$regex?"$regex":void 0}return"eq"},setRulesFromMongo:function(a){this.setRules(this.getRulesFromMongo(a))}}),j.define("sortable",function(b){this.on("afterInit",function(b){$.event.props.push("dataTransfer");var c,d,e=b.builder;e.$el.on("mouseover",".drag-handle",function(){e.$el.find(".rule-container, .rules-group-container").attr("draggable",!0)}),e.$el.on("mouseout",".drag-handle",function(){e.$el.find(".rule-container, .rules-group-container").removeAttr("draggable")}),e.$el.on("dragstart","[draggable]",function(b){b.stopPropagation(),b.dataTransfer.setData("text","drag"),d=a(b.target),setTimeout(function(){var a=$('
       
      ');a.css("min-height",d.$el.height()),c=d.parent.addRule(a,d.getPos()),d.$el.hide()},0)}),e.$el.on("dragenter","[draggable]",function(a){a.preventDefault(),a.stopPropagation(),c&&i(c,$(a.target))}),e.$el.on("dragover","[draggable]",function(a){a.preventDefault(),a.stopPropagation()}),e.$el.on("drop",function(a){a.preventDefault(),a.stopPropagation(),i(d,$(a.target))}),e.$el.on("dragend","[draggable]",function(a){a.preventDefault(),a.stopPropagation(),d.$el.show(),c.drop(),d=c=null,e.$el.find(".rule-container, .rules-group-container").removeAttr("draggable")})}),this.on("parseRuleFlags.filter",function(a){void 0===a.value.no_sortable&&(a.value.no_sortable=b.default_no_sortable)}),this.on("afterApplyRuleFlags",function(a,b){b.flags.no_sortable&&b.$el.find(".drag-handle").remove()}),this.on("getGroupTemplate.filter",function(a,c){if(c>1){var d=$(a.value);d.find(".group-conditions").after('
      '),a.value=d.prop("outerHTML")}}),this.on("getRuleTemplate.filter",function(a){var c=$(a.value);c.find(".rule-header").after('
      '),a.value=c.prop("outerHTML")})},{default_no_sortable:!1,icon:"glyphicon glyphicon-sort"}),j.defaults({sqlOperators:{equal:"= ?",not_equal:"!= ?","in":{op:"IN(?)",sep:", "},not_in:{op:"NOT IN(?)",sep:", "},less:"< ?",less_or_equal:"<= ?",greater:"> ?",greater_or_equal:">= ?",between:{op:"BETWEEN ?",sep:" AND "},begins_with:{op:"LIKE(?)",fn:function(a){return a+"%"}},not_begins_with:{op:"NOT LIKE(?)",fn:function(a){return a+"%"}},contains:{op:"LIKE(?)",fn:function(a){return"%"+a+"%"}},not_contains:{op:"NOT LIKE(?)",fn:function(a){return"%"+a+"%"}},ends_with:{op:"LIKE(?)",fn:function(a){return"%"+a}},not_ends_with:{op:"NOT LIKE(?)",fn:function(a){return"%"+a}},is_empty:'== ""',is_not_empty:'!= ""',is_null:"IS NULL",is_not_null:"IS NOT NULL"},sqlStatements:{question_mark:function(){var a=[];return{add:function(b,c){return a.push(c),"?"},run:function(){return a}}},numbered:function(){var a=0,b=[];return{add:function(c,d){return b.push(d),a++,"$"+a},run:function(){return b}}},named:function(){var a={},b={};return{add:function(c,d){a[c.field]||(a[c.field]=0),a[c.field]++;var e=c.field+"_"+a[c.field];return b[e]=d,":"+e},run:function(){return b}}}}}),j.extend({getSQL:function(a,b,c){c=void 0===c?this.getRules():c,b=b===!0?"\n":" ",(a===!0||void 0===a)&&(a="question_mark"),"string"==typeof a&&(a=this.settings.sqlStatements[a]());var d=this,h=function i(c){if(c.condition||(c.condition=d.settings.default_condition),-1===["AND","OR"].indexOf(c.condition.toUpperCase())&&e('Unable to build SQL query with condition "{0}"',c.condition),!c.rules)return"";var h=[];return c.rules.forEach(function(c){if(c.rules&&c.rules.length>0)h.push("("+b+i(c)+b+")"+b);else{var j=d.getSqlOperator(c.operator),k=d.getOperatorByType(c.operator),l="";j===!1&&e('Unknown SQL operation for operator "{0}"',c.operator),0!==k.nb_inputs&&(c.value instanceof Array||(c.value=[c.value]),c.value.forEach(function(b,d){d>0&&(l+=j.sep),"integer"==c.type||"double"==c.type||"boolean"==c.type?b=f(b,c.type,!0):a||(b=g(b)),j.fn&&(b=j.fn(b)),a?l+=a.add(c,b):("string"==typeof b&&(b="'"+b+"'"),l+=b)})),h.push(c.field+" "+j.op.replace(/\?/,l))}}),h.join(" "+c.condition+b)}(c);return a?{sql:h,params:a.run()}:{sql:h}},getSqlOperator:function(a){var b=this.settings.sqlOperators[a];return void 0===b?!1:("string"==typeof b&&(b={op:b}),b.list&&!b.sep&&(b.sep=", "),b)}}),j.define("unique-filter",function(){this.status.used_filters={},this.on("afterUpdateRuleFilter",this.updateDisabledFilters),this.on("afterDeleteRule",this.updateDisabledFilters),this.on("afterCreateRuleFilters",this.applyDisabledFilters)}),j.extend({updateDisabledFilters:function(a){var b=a.builder;b.status.used_filters={},b.model&&(!function c(a){a.each(function(a){a.filter&&a.filter.unique&&(b.status.used_filters[a.filter.id]||(b.status.used_filters[a.filter.id]=[]),"group"==a.filter.unique&&b.status.used_filters[a.filter.id].push(a.parent))},function(a){c(a)})}(b.model.root),b.applyDisabledFilters(a))},applyDisabledFilters:function(a){var b=a.builder;b.$el.find(".rule-filter-container option").prop("disabled",!1),$.each(b.status.used_filters,function(a,c){0===c.length?b.$el.find(".rule-filter-container option[value="+a+"]:not(:selected)").prop("disabled",!0):c.forEach(function(b){b.each(function(b){b.$el.find(".rule-filter-container option[value="+a+"]:not(:selected)").prop("disabled",!0)})})}),b.settings.plugins&&b.settings.plugins["bt-selectpicker"]&&b.$el.find(".rule-filter-container select").selectpicker("render")}})}); \ No newline at end of file diff --git a/dist/scss/dark.scss b/dist/scss/dark.scss index 444419a7..346769c0 100644 --- a/dist/scss/dark.scss +++ b/dist/scss/dark.scss @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Copyright 2014-2015 Damien "Mistic" Sorel (http://www.strangeplanet.fr) * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/dist/scss/default.scss b/dist/scss/default.scss index d0c96beb..a872d4d6 100644 --- a/dist/scss/default.scss +++ b/dist/scss/default.scss @@ -1,5 +1,5 @@ /*! - * jQuery QueryBuilder 2.0.0 + * jQuery QueryBuilder 2.0.1 * Copyright 2014-2015 Damien "Mistic" Sorel (http://www.strangeplanet.fr) * Licensed under MIT (http://opensource.org/licenses/MIT) */ diff --git a/package.json b/package.json index a638dda6..6a34c909 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jQuery-QueryBuilder", - "version": "2.0.0", + "version": "2.0.1", "author": { "name": "Damien \"Mistic\" Sorel", "email": "contact@git.strangeplanet.fr",