text: /*!
   * jQuery QueryBuilder 2.5.2.16
   * Copyright 2014-2019 Damien "Mistic" Sorel (http://www.strangeplanet.fr)
   * Licensed under MIT (https://opensource.org/licenses/MIT)
   */
  !function(a,b){"function"==typeof define&&define.amd?define("jQuery.extendext",["jquery"],b):"object"==typeof module&&module.exports?module.exports=b(require("jquery")):b(a.jQuery)}(this,function(a){"use strict";a.extendext=function(){var b,c,d,e,f,g,h=arguments[0]||{},i=1,j=arguments.length,k=!1,l="default";for("boolean"==typeof h&&(k=h,h=arguments[i++]||{}),"string"==typeof h&&(l=h.toLowerCase(),"concat"!==l&&"replace"!==l&&"extend"!==l&&(l="default"),h=arguments[i++]||{}),"object"==typeof h||a.isFunction(h)||(h={}),i===j&&(h=this,i--);i<j;i++)if(null!==(b=arguments[i]))if(a.isArray(b)&&"default"!==l)switch(g=h&&a.isArray(h)?h:[],l){case"concat":h=g.concat(a.extend(k,[],b));break;case"replace":h=a.extend(k,[],b);break;case"extend":b.forEach(function(b,c){if("object"==typeof b){var d=a.isArray(b)?[]:{};g[c]=a.extendext(k,l,g[c]||d,b)}else g.indexOf(b)===-1&&g.push(b)}),h=g}else for(c in b)d=h[c],e=b[c],h!==e&&(k&&e&&(a.isPlainObject(e)||(f=a.isArray(e)))?(f?(f=!1,g=d&&a.isArray(d)?d:[]):g=d&&a.isPlainObject(d)?d:{},h[c]=a.extendext(k,l,g,e)):void 0!==e&&(h[c]=e));return h}}),function(){"use strict";function a(b,c,d){return("string"==typeof c?c:c.toString()).replace(b.define||f,function(a,c,e,f){return 0===c.indexOf("def.")&&(c=c.substring(4)),c in d||(":"===e?(b.defineParams&&f.replace(b.defineParams,function(a,b,e){d[c]={arg:b,text:e}}),c in d||(d[c]=f)):new Function("def","def['"+c+"']="+f)(d)),""}).replace(b.use||f,function(c,e){b.useParams&&(e=e.replace(b.useParams,function(a,b,c,e){if(d[c]&&d[c].arg&&e){var f=(c+":"+e).replace(/'|\\/g,"_");return d.__exp=d.__exp||{},d.__exp[f]=d[c].text.replace(new RegExp("(^|[^\\w$])"+d[c].arg+"([^\\w$])","g"),"$1"+e+"$2"),b+"def.__exp['"+f+"']"}}));var f=new Function("def","return "+e)(d);return f?a(b,f,d):f})}function b(a){return a.replace(/\\('|\\)/g,"$1").replace(/[\r\t\n]/g," ")}var c,d={name:"doT",version:"1.1.1",templateSettings:{evaluate:/\{\{([\s\S]+?(\}?)+)\}\}/g,interpolate:/\{\{=([\s\S]+?)\}\}/g,encode:/\{\{!([\s\S]+?)\}\}/g,use:/\{\{#([\s\S]+?)\}\}/g,useParams:/(^|[^\w$])def(?:\.|\[[\'\"])([\w$\.]+)(?:[\'\"]\])?\s*\:\s*([\w$\.]+|\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})/g,define:/\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,defineParams:/^\s*([\w$]+):([\s\S]+)/,conditional:/\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g,iterate:/\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g,varname:"it",strip:!0,append:!0,selfcontained:!1,doNotSkipEncoded:!1},template:void 0,compile:void 0,log:!0};d.encodeHTMLSource=function(a){var b={"&":"&#38;","<":"&#60;",">":"&#62;",'"':"&#34;","'":"&#39;","/":"&#47;"},c=a?/[&<>"'\/]/g:/&(?!#?\w+;)|<|>|"|'|\//g;return function(a){return a?a.toString().replace(c,function(a){return b[a]||a}):""}},c=function(){return this||(0,eval)("this")}(),"undefined"!=typeof module&&module.exports?module.exports=d:"function"==typeof define&&define.amd?define("doT",function(){return d}):c.doT=d;var e={append:{start:"'+(",end:")+'",startencode:"'+encodeHTML("},split:{start:"';out+=(",end:");out+='",startencode:"';out+=encodeHTML("}},f=/$^/;d.template=function(g,h,i){h=h||d.templateSettings;var j,k,l=h.append?e.append:e.split,m=0,n=h.use||h.define?a(h,g,i||{}):g;n=("var out='"+(h.strip?n.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g," ").replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g,""):n).replace(/'|\\/g,"\\$&").replace(h.interpolate||f,function(a,c){return l.start+b(c)+l.end}).replace(h.encode||f,function(a,c){return j=!0,l.startencode+b(c)+l.end}).replace(h.conditional||f,function(a,c,d){return c?d?"';}else if("+b(d)+"){out+='":"';}else{out+='":d?"';if("+b(d)+"){out+='":"';}out+='"}).replace(h.iterate||f,function(a,c,d,e){return c?(m+=1,k=e||"i"+m,c=b(c),"';var arr"+m+"="+c+";if(arr"+m+"){var "+d+","+k+"=-1,l"+m+"=arr"+m+".length-1;while("+k+"<l"+m+"){"+d+"=arr"+m+"["+k+"+=1];out+='"):"';} } out+='"}).replace(h.evaluate||f,function(a,c){return"';"+b(c)+"out+='"})+"';return out;").replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r").replace(/(\s|;|\}|^|\{)out\+='';/g,"$1").replace(/\+''/g,""),j&&(h.selfcontained||!c||c._encodeHTML||(c._encodeHTML=d.encodeHTMLSource(h.doNotSkipEncoded)),n="var encodeHTML = typeof _encodeHTML !== 'undefined' ? _encodeHTML : ("+d.encodeHTMLSource.toString()+"("+(h.doNotSkipEncoded||"")+"));"+n);try{return new Function(h.varname,n)}catch(o){throw"undefined"!=typeof console&&console.log("Could not create a template function: "+n),o}},d.compile=function(a,b){return d.template(a,null,b)}}(),function(a,b){"function"==typeof define&&define.amd?define("query-builder",["jquery","dot/doT","jquery-extendext"],b):"object"==typeof module&&module.exports?module.exports=b(require("jquery"),require("dot/doT"),require("jquery-extendext")):b(a.jQuery,a.doT)}(this,function(a,b){"use strict";function c(){this.root=null,this.$=a(this)}function d(a,b,c){var d,e,g=f.selectors;d=b.closest(g.rule_container),d.length&&(e="moveAfter"),e||(d=b.closest(g.group_header),d.length&&(d=b.closest(g.group_container),e="moveAtBegin")),e||(d=b.closest(g.group_container),d.length&&(e="moveAtEnd")),e&&(a[e](c.getModel(d)),c&&a instanceof j&&c.setRuleInputValue(a,a.value))}function e(a){var b=a.match(/(question_mark|numbered|named)(?:\((.)\))?/);return b||(b=[null,"question_mark",void 0]),b}var f=function(d,e){d[0].queryBuilder=this,this.$el=d,this.settings=a.extendext(!0,"replace",{},f.DEFAULTS,e),this.model=new c,this.status={id:null,generated_id:!1,group_id:0,rule_id:0,has_optgroup:!1,has_operator_optgroup:!1},this.filters=this.settings.filters,this.icons=this.settings.icons,this.operators=this.settings.operators,this.templates=this.settings.templates,this.plugins=this.settings.plugins,this.lang=null,void 0===f.regional.en&&g.error("Config",'"i18n/en.js" not loaded.'),this.lang=a.extendext(!0,"replace",{},f.regional.en,f.regional[this.settings.lang_code],this.settings.lang),this.settings.allow_groups===!1?this.settings.allow_groups=0:this.settings.allow_groups===!0&&(this.settings.allow_groups=-1),Object.keys(this.templates).forEach(function(a){this.templates[a]||(this.templates[a]=f.templates[a]),"string"==typeof this.templates[a]&&(this.templates[a]=b.template(this.templates[a]))},this),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.filters=this.checkFilters(this.filters),this.operators=this.checkOperators(this.operators),this.bindEvents(),this.initPlugins()};a.extend(f.prototype,{trigger:function(b){var c=new a.Event(this._tojQueryEvent(b),{builder:this});return this.$el.triggerHandler(c,Array.prototype.slice.call(arguments,1)),c},change:function(b,c){var d=new a.Event(this._tojQueryEvent(b,!0),{builder:this,value:c});return this.$el.triggerHandler(d,Array.prototype.slice.call(arguments,2)),d.value},on:function(a,b){return this.$el.on(this._tojQueryEvent(a),b),this},off:function(a,b){return this.$el.off(this._tojQueryEvent(a),b),this},once:function(a,b){return this.$el.one(this._tojQueryEvent(a),b),this},_tojQueryEvent:function(a,b){return a.split(" ").map(function(a){return a+".queryBuilder"+(b?".filter":"")}).join(" ")}}),f.types={string:"string",integer:"number","double":"number",date:"datetime",time:"datetime",datetime:"datetime","boolean":"boolean"},f.inputs=["text","number","textarea","radio","checkbox","select"],f.modifiable_options=["display_errors","allow_groups","allow_empty","default_condition","default_filter"],f.selectors={group_container:".rules-group-container",rule_container:".rule-container",filter_container:".rule-filter-container",operator_container:".rule-operator-container",value_container:".rule-value-container",error_container:".error-container",condition_container:".rules-group-header .group-conditions",rule_header:".rule-header",group_header:".rules-group-header",group_actions:".group-actions",rule_actions:".rule-actions",rules_list:".rules-group-body>.rules-list",group_condition:".rules-group-header [name$=_cond]",rule_filter:".rule-filter-container [name$=_filter]",rule_operator:".rule-operator-container [name$=_operator]",rule_value:".rule-value-container [name*=_value_]",add_rule:"[data-add=rule]",delete_rule:"[data-delete=rule]",add_group:"[data-add=group]",delete_group:"[data-delete=group]"},f.templates={},f.regional={},f.OPERATORS={equal:{type:"equal",nb_inputs:1,multiple:!1,apply_to:["string","number","datetime","boolean"]},not_equal:{type:"not_equal",nb_inputs:1,multiple:!1,apply_to:["string","number","datetime","boolean"]},"in":{type:"in",nb_inputs:1,multiple:!0,apply_to:["string","number","datetime"]},not_in:{type:"not_in",nb_inputs:1,multiple:!0,apply_to:["string","number","datetime"]},less:{type:"less",nb_inputs:1,multiple:!1,apply_to:["number","datetime"]},less_or_equal:{type:"less_or_equal",nb_inputs:1,multiple:!1,apply_to:["number","datetime"]},greater:{type:"greater",nb_inputs:1,multiple:!1,apply_to:["number","datetime"]},greater_or_equal:{type:"greater_or_equal",nb_inputs:1,multiple:!1,apply_to:["number","datetime"]},between:{type:"between",nb_inputs:2,multiple:!1,apply_to:["number","datetime"]},not_between:{type:"not_between",nb_inputs:2,multiple:!1,apply_to:["number","datetime"]},begins_with:{type:"begins_with",nb_inputs:1,multiple:!1,apply_to:["string"]},not_begins_with:{type:"not_begins_with",nb_inputs:1,multiple:!1,apply_to:["string"]},contains:{type:"contains",nb_inputs:1,multiple:!1,apply_to:["string"]},not_contains:{type:"not_contains",nb_inputs:1,multiple:!1,apply_to:["string"]},ends_with:{type:"ends_with",nb_inputs:1,multiple:!1,apply_to:["string"]},not_ends_with:{type:"not_ends_with",nb_inputs:1,multiple:!1,apply_to:["string"]},is_empty:{type:"is_empty",nb_inputs:0,multiple:!1,apply_to:["string"]},is_not_empty:{type:"is_not_empty",nb_inputs:0,multiple:!1,apply_to:["string"]},is_null:{type:"is_null",nb_inputs:0,multiple:!1,apply_to:["string","number","datetime","boolean"]},is_not_null:{type:"is_not_null",nb_inputs:0,multiple:!1,apply_to:["string","number","datetime","boolean"]}},f.DEFAULTS={filters:[],plugins:[],sort_filters:!1,display_errors:!0,allow_groups:-1,allow_empty:!1,conditions:["AND","OR"],default_condition:"AND",inputs_separator:" , ",select_placeholder:"------",display_empty_filter:!0,default_filter:null,optgroups:{},default_rule_flags:{filter_readonly:!1,operator_readonly:!1,value_readonly:!1,no_delete:!1},default_group_flags:{condition_readonly:!1,no_add_rule:!1,no_add_group:!1,no_delete:!1},templates:{group:null,rule:null,filterSelect:null,operatorSelect:null,ruleValueSelect:null},lang_code:"en",lang:{},operators:["equal","not_equal","in","not_in","less","less_or_equal","greater","greater_or_equal","between","not_between","begins_with","not_begins_with","contains","not_contains","ends_with","not_ends_with","is_empty","is_not_empty","is_null","is_not_null"],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"}},f.plugins={},f.defaults=function(b){return"object"!=typeof b?"string"==typeof b?"object"==typeof f.DEFAULTS[b]?a.extend(!0,{},f.DEFAULTS[b]):f.DEFAULTS[b]:a.extend(!0,{},f.DEFAULTS):void a.extendext(!0,"replace",f.DEFAULTS,b)},f.define=function(a,b,c){f.plugins[a]={fct:b,def:c||{}}},f.extend=function(b){a.extend(f.prototype,b)},f.prototype.initPlugins=function(){if(this.plugins){if(a.isArray(this.plugins)){var b={};this.plugins.forEach(function(a){b[a]=null}),this.plugins=b}Object.keys(this.plugins).forEach(function(b){b in f.plugins?(this.plugins[b]=a.extend(!0,{},f.plugins[b].def,this.plugins[b]||{}),f.plugins[b].fct.call(this,this.plugins[b])):g.error("Config",'Unable to find plugin "{0}"',b)},this)}},f.prototype.getPluginOptions=function(a,b){var c;return this.plugins&&this.plugins[a]?c=this.plugins[a]:f.plugins[a]&&(c=f.plugins[a].def),c?b?c[b]:c:void g.error("Config",'Unable to find plugin "{0}"',a)},f.prototype.init=function(a){this.trigger("afterInit"),a?(this.setRules(a),delete this.settings.rules):this.setRoot(!0)},f.prototype.checkFilters=function(a){var b=[];if(a&&0!==a.length||g.error("Config","Missing filters list"),a.forEach(function(a,c){switch(a.id||g.error("Config","Missing filter {0} id",c),b.indexOf(a.id)!=-1&&g.error("Config",'Filter "{0}" already defined',a.id),b.push(a.id),a.type?f.types[a.type]||g.error("Config",'Invalid type "{0}"',a.type):a.type="string",a.input?"function"!=typeof a.input&&f.inputs.indexOf(a.input)==-1&&g.error("Config",'Invalid input "{0}"',a.input):a.input="number"===f.types[a.type]?"number":"text",a.operators&&a.operators.forEach(function(a){"string"!=typeof a&&g.error("Config","Filter operators must be global operators types (string)")}),a.field||(a.field=a.id),a.label||(a.label=a.field),a.optgroup?(this.status.has_optgroup=!0,this.settings.optgroups[a.optgroup]||(this.settings.optgroups[a.optgroup]=a.optgroup)):a.optgroup=null,a.input){case"radio":case"checkbox":(!a.values||a.values.length<1)&&g.error("Config",'Missing filter "{0}" values',a.id);break;case"select":var d=[];a.has_optgroup=!1,g.iterateOptions(a.values,function(b,c,e){d.push({value:b,label:c,optgroup:e||null}),e&&(a.has_optgroup=!0,this.settings.optgroups[e]||(this.settings.optgroups[e]=e))}.bind(this)),a.has_optgroup?a.values=g.groupSort(d,"optgroup"):a.values=d,a.placeholder&&(void 0===a.placeholder_value&&(a.placeholder_value=-1),a.values.forEach(function(b){b.value==a.placeholder_value&&g.error("Config",'Placeholder of filter "{0}" overlaps with one of its values',a.id)}))}},this),this.settings.sort_filters)if("function"==typeof this.settings.sort_filters)a.sort(this.settings.sort_filters);else{var c=this;a.sort(function(a,b){return c.translate(a.label).localeCompare(c.translate(b.label))})}return this.status.has_optgroup&&(a=g.groupSort(a,"optgroup")),a},f.prototype.checkOperators=function(b){var c=[];return b.forEach(function(d,e){"string"==typeof d?(f.OPERATORS[d]||g.error("Config",'Unknown operator "{0}"',d),b[e]=d=a.extendext(!0,"replace",{},f.OPERATORS[d])):(d.type||g.error("Config",'Missing "type" for operator {0}',e),f.OPERATORS[d.type]&&(b[e]=d=a.extendext(!0,"replace",{},f.OPERATORS[d.type],d)),void 0!==d.nb_inputs&&void 0!==d.apply_to||g.error("Config",'Missing "nb_inputs" and/or "apply_to" for operator "{0}"',d.type)),c.indexOf(d.type)!=-1&&g.error("Config",'Operator "{0}" already defined',d.type),c.push(d.type),d.optgroup?(this.status.has_operator_optgroup=!0,this.settings.optgroups[d.optgroup]||(this.settings.optgroups[d.optgroup]=d.optgroup)):d.optgroup=null},this),this.status.has_operator_optgroup&&(b=g.groupSort(b,"optgroup")),b},f.prototype.bindEvents=function(){var b=this,c=f.selectors;this.$el.on("change.queryBuilder",c.group_condition,function(){if(a(this).is(":checked")){var d=a(this).closest(c.group_container);b.getModel(d).condition=a(this).val()}}),this.$el.on("change.queryBuilder",c.rule_filter,function(){var d=a(this).closest(c.rule_container);b.getModel(d).filter=b.getFilterById(a(this).val())}),this.$el.on("change.queryBuilder",c.rule_operator,function(){var d=a(this).closest(c.rule_container);b.getModel(d).operator=b.getOperatorByType(a(this).val())}),this.$el.on("click.queryBuilder",c.add_rule,function(){var d=a(this).closest(c.group_container);b.addRule(b.getModel(d))}),this.$el.on("click.queryBuilder",c.delete_rule,function(){var d=a(this).closest(c.rule_container);b.deleteRule(b.getModel(d))}),0!==this.settings.allow_groups&&(this.$el.on("click.queryBuilder",c.add_group,function(){var d=a(this).closest(c.group_container);b.addGroup(b.getModel(d))}),this.$el.on("click.queryBuilder",c.delete_group,function(){var d=a(this).closest(c.group_container);b.deleteGroup(b.getModel(d))})),this.model.on({drop:function(a,c){c.$el.remove(),b.refreshGroupsConditions()},add:function(a,c,d,e){0===e?d.$el.prependTo(c.$el.find(">"+f.selectors.rules_list)):d.$el.insertAfter(c.rules[e-1].$el),b.refreshGroupsConditions()},move:function(a,c,d,e){c.$el.detach(),0===e?c.$el.prependTo(d.$el.find(">"+f.selectors.rules_list)):c.$el.insertAfter(d.rules[e-1].$el),b.refreshGroupsConditions()},update:function(a,c,d,e,f){if(c instanceof j)switch(d){case"error":b.updateError(c);break;case"flags":b.applyRuleFlags(c);break;case"filter":b.updateRuleFilter(c,f);break;case"operator":b.updateRuleOperator(c,f);break;case"value":b.updateRuleValue(c,f)}else switch(d){case"error":b.updateError(c);break;case"flags":b.applyGroupFlags(c);break;case"condition":b.updateGroupCondition(c,f)}}})},f.prototype.setRoot=function(b,c,d){b=void 0===b||b===!0;var e=this.nextGroupId(),f=a(this.getGroupTemplate(e,1));return this.$el.append(f),this.model.root=new i(null,f),this.model.root.model=this.model,this.model.root.data=c,this.model.root.flags=a.extend({},this.settings.default_group_flags,d),this.model.root.condition=this.settings.default_condition,this.trigger("afterAddGroup",this.model.root),b&&this.addRule(this.model.root),this.model.root},f.prototype.addGroup=function(b,c,d,e){c=void 0===c||c===!0;var f=b.level+1,g=this.trigger("beforeAddGroup",b,c,f);if(g.isDefaultPrevented())return null;var h=this.nextGroupId(),i=a(this.getGroupTemplate(h,f)),j=b.addGroup(i);return j.data=d,j.flags=a.extend({},this.settings.default_group_flags,e),j.condition=this.settings.default_condition,this.trigger("afterAddGroup",j),this.trigger("rulesChanged"),c&&this.addRule(j),j},f.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"),this.trigger("rulesChanged")),c},f.prototype.updateGroupCondition=function(b,c){b.$el.find(">"+f.selectors.group_condition).each(function(){var c=a(this);c.prop("checked",c.val()===b.condition),c.parent().toggleClass("active",c.val()===b.condition)}),this.trigger("afterUpdateGroupCondition",b,c),this.trigger("rulesChanged")},f.prototype.refreshGroupsConditions=function(){!function a(b){(!b.flags||b.flags&&!b.flags.condition_readonly)&&b.$el.find(">"+f.selectors.group_condition).prop("disabled",b.rules.length<=1).parent().toggleClass("disabled",b.rules.length<=1),b.each(null,function(b){a(b)},this)}(this.model.root)},f.prototype.addRule=function(b,c,d){var e=this.trigger("beforeAddRule",b);if(e.isDefaultPrevented())return null;var f=this.nextRuleId(),g=a(this.getRuleTemplate(f)),h=b.addRule(g);return h.data=c,h.flags=a.extend({},this.settings.default_rule_flags,d),this.trigger("afterAddRule",h),this.trigger("rulesChanged"),this.createRuleFilters(h),!this.settings.default_filter&&this.settings.display_empty_filter||(h.filter=this.change("getDefaultFilter",this.getFilterById(this.settings.default_filter||this.filters[0].id),h)),h},f.prototype.deleteRule=function(a){if(a.flags.no_delete)return!1;var b=this.trigger("beforeDeleteRule",a);return!b.isDefaultPrevented()&&(a.drop(),this.trigger("afterDeleteRule"),this.trigger("rulesChanged"),!0)},f.prototype.createRuleFilters=function(b){var c=this.change("getRuleFilters",this.filters,b),d=a(this.getRuleFilterSelect(b,c));b.$el.find(f.selectors.filter_container).html(d),this.trigger("afterCreateRuleFilters",b),this.applyRuleFlags(b)},f.prototype.createRuleOperators=function(b){var c=b.$el.find(f.selectors.operator_container).empty();if(b.filter){var d=this.getOperators(b.filter),e=a(this.getRuleOperatorSelect(b,d));c.html(e),b.filter.default_operator?b.__.operator=this.getOperatorByType(b.filter.default_operator):b.__.operator=d[0],b.$el.find(f.selectors.rule_operator).val(b.operator.type),this.trigger("afterCreateRuleOperators",b,d),this.applyRuleFlags(b)}},f.prototype.createRuleInput=function(b){var c=b.$el.find(f.selectors.value_container).empty();if(b.__.value=void 0,b.filter&&b.operator&&0!==b.operator.nb_inputs){for(var d=this,e=a(),g=b.filter,h=0;h<b.operator.nb_inputs;h++){var i=a(this.getRuleInput(b,h));h>0&&c.append(this.settings.inputs_separator),c.append(i),e=e.add(i)}c.css("display",""),e.on("change "+(g.input_event||""),function(){b._updating_input||(b._updating_value=!0,b.value=d.getRuleInputValue(b),b._updating_value=!1)}),g.plugin&&e[g.plugin](g.plugin_config||{}),this.trigger("afterCreateRuleInput",b),void 0!==g.default_value?b.value=g.default_value:(b._updating_value=!0,b.value=d.getRuleInputValue(b),b._updating_value=!1),this.applyRuleFlags(b)}},f.prototype.updateRuleFilter=function(a,b){this.createRuleOperators(a),this.createRuleInput(a),a.$el.find(f.selectors.rule_filter).val(a.filter?a.filter.id:"-1"),b&&a.filter&&b.id!==a.filter.id&&(a.data=void 0),this.trigger("afterUpdateRuleFilter",a,b),this.trigger("rulesChanged")},f.prototype.updateRuleOperator=function(a,b){var c=a.$el.find(f.selectors.value_container);a.operator&&0!==a.operator.nb_inputs?(c.css("display",""),!c.is(":empty")&&b&&a.operator.nb_inputs===b.nb_inputs&&a.operator.optgroup===b.optgroup||this.createRuleInput(a)):(c.hide(),a.__.value=void 0),a.operator&&(a.$el.find(f.selectors.rule_operator).val(a.operator.type),a.__.value=this.getRuleInputValue(a)),this.trigger("afterUpdateRuleOperator",a,b),this.trigger("rulesChanged")},f.prototype.updateRuleValue=function(a,b){a._updating_value||this.setRuleInputValue(a,a.value),this.trigger("afterUpdateRuleValue",a,b),this.trigger("rulesChanged")},f.prototype.applyRuleFlags=function(a){var b=a.flags,c=f.selectors;a.$el.find(c.rule_filter).prop("disabled",b.filter_readonly),a.$el.find(c.rule_operator).prop("disabled",b.operator_readonly),a.$el.find(c.rule_value).prop("disabled",b.value_readonly),b.no_delete&&a.$el.find(c.delete_rule).remove(),this.trigger("afterApplyRuleFlags",a)},f.prototype.applyGroupFlags=function(a){var b=a.flags,c=f.selectors;a.$el.find(">"+c.group_condition).prop("disabled",b.condition_readonly).parent().toggleClass("readonly",b.condition_readonly),b.no_add_rule&&a.$el.find(c.add_rule).remove(),b.no_add_group&&a.$el.find(c.add_group).remove(),b.no_delete&&a.$el.find(c.delete_group).remove(),this.trigger("afterApplyGroupFlags",a)},f.prototype.clearErrors=function(a){a=a||this.model.root,a&&(a.error=null,a instanceof i&&a.each(function(a){a.error=null},function(a){this.clearErrors(a)},this))},f.prototype.updateError=function(a){if(this.settings.display_errors)if(null===a.error)a.$el.removeClass("has-error");else{var b=this.translate("errors",a.error[0]);b=g.fmt(b,a.error.slice(1)),b=this.change("displayError",b,a.error,a),a.$el.addClass("has-error").find(f.selectors.error_container).eq(0).attr("title",b)}},f.prototype.triggerValidationError=function(b,c,d){a.isArray(c)||(c=[c]);var e=this.trigger("validationError",b,c,d);e.isDefaultPrevented()||(b.error=c)},f.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},f.prototype.reset=function(){var b=this.trigger("beforeReset");b.isDefaultPrevented()||(this.status.group_id=1,this.status.rule_id=0,this.model.root.empty(),this.model.root.data=void 0,this.model.root.flags=a.extend({},this.settings.default_group_flags),this.model.root.condition=this.settings.default_condition,this.addRule(this.model.root),this.trigger("afterReset"),this.trigger("rulesChanged"))},f.prototype.clear=function(){var a=this.trigger("beforeClear");a.isDefaultPrevented()||(this.status.group_id=0,this.status.rule_id=0,this.model.root&&(this.model.root.drop(),this.model.root=null),this.trigger("afterClear"),this.trigger("rulesChanged"))},f.prototype.setOptions=function(b){a.each(b,function(a,b){f.modifiable_options.indexOf(a)!==-1&&(this.settings[a]=b)}.bind(this))},f.prototype.getModel=function(b){return b?b instanceof h?b:a(b).data("queryBuilderModel"):this.model.root},f.prototype.validate=function(b){b=a.extend({skip_empty:!1},b),this.clearErrors();var c=this,d=function e(a){var d=0,f=0;return a.each(function(a){if(a.filter||!b.skip_empty){if(!a.filter)return c.triggerValidationError(a,"no_filter",null),void f++;if(!a.operator)return c.triggerValidationError(a,"no_operator",null),void f++;if(0!==a.operator.nb_inputs){var e=c.validateValue(a,a.value);if(e!==!0)return c.triggerValidationError(a,e,a.value),void f++}d++}},function(a){var b=e(a);b===!0?d++:b===!1&&f++}),!(f>0)&&(0===d&&!a.isRoot()&&b.skip_empty?null:!!(0!==d||c.settings.allow_empty&&a.isRoot())||(c.triggerValidationError(a,"empty_group",null),!1))}(this.model.root);return this.change("validate",d)},f.prototype.getRules=function(b){b=a.extend({get_flags:!1,allow_invalid:!1,skip_empty:!1},b);var c=this.validate(b);if(!c&&!b.allow_invalid)return null;var d=this,e=function f(c){var e={condition:c.condition,rules:[]};if(c.data&&(e.data=a.extendext(!0,"replace",{},c.data)),b.get_flags){var g=d.getGroupFlags(c.flags,"all"===b.get_flags);a.isEmptyObject(g)||(e.flags=g)}return c.each(function(c){if(c.filter||!b.skip_empty){var f=null;c.operator&&0===c.operator.nb_inputs||(f=c.value);var g={id:c.filter?c.filter.id:null,field:c.filter?c.filter.field:null,type:c.filter?c.filter.type:null,input:c.filter?c.filter.input:null,operator:c.operator?c.operator.type:null,value:f};if((c.filter&&c.filter.data||c.data)&&(g.data=a.extendext(!0,"replace",{},c.filter.data,c.data)),b.get_flags){var h=d.getRuleFlags(c.flags,"all"===b.get_flags);a.isEmptyObject(h)||(g.flags=h)}e.rules.push(d.change("ruleToJson",g,c))}},function(a){var c=f(a);0===c.rules.length&&b.skip_empty||e.rules.push(c)},this),d.change("groupToJson",e,c)}(this.model.root);return e.valid=c,this.change("getRules",e)},f.prototype.setRules=function(b,c){c=a.extend({allow_invalid:!1},c),a.isArray(b)&&(b={condition:this.settings.default_condition,rules:b}),b&&b.rules&&(0!==b.rules.length||this.settings.allow_empty)||g.error("RulesParse","Incorrect data object passed"),this.clear(),this.setRoot(!1,b.data,this.parseGroupFlags(b)),b=this.change("setRules",b,c);var d=this;!function e(a,b){null!==b&&(void 0===a.condition?a.condition=d.settings.default_condition:d.settings.conditions.indexOf(a.condition)==-1&&(g.error(!c.allow_invalid,"UndefinedCondition",'Invalid condition "{0}"',a.condition),a.condition=d.settings.default_condition),b.condition=a.condition,a.rules.forEach(function(a){var f;if(void 0!==a.rules)if(d.settings.allow_groups!==-1&&d.settings.allow_groups<b.level)g.error(!c.allow_invalid,"RulesParse","No more than {0} groups are allowed",d.settings.allow_groups),d.reset();else{if(f=d.addGroup(b,!1,a.data,d.parseGroupFlags(a)),null===f)return;e(a,f)}else{if(a.empty||(void 0===a.id&&(g.error(!c.allow_invalid,"RulesParse","Missing rule field id"),a.empty=!0),void 0===a.operator&&(a.operator="equal")),f=d.addRule(b,a.data,d.parseRuleFlags(a)),null===f)return;a.empty||(f.filter=d.getFilterById(a.id,!c.allow_invalid)),f.filter&&(f.operator=d.getOperatorByType(a.operator,!c.allow_invalid),f.operator||(f.operator=d.getOperators(f.filter)[0])),f.operator&&0!==f.operator.nb_inputs&&(void 0!==a.value?f.value=a.value:void 0!==f.filter.default_value&&(f.value=f.filter.default_value)),d.change("jsonToRule",f,a)!=f&&g.error("RulesParse","Plugin tried to change rule reference")}}),d.change("jsonToGroup",b,a)!=b&&g.error("RulesParse","Plugin tried to change group reference"))}(b,this.model.root),this.trigger("afterSetRules")},f.prototype.validateValue=function(a,b){var c=a.filter.validation||{},d=!0;return d=c.callback?c.callback.call(this,b,a):this._validateValue(a,b),this.change("validateValue",d,b,a)},f.prototype._validateValue=function(b,c){var d,e,h=b.filter,i=b.operator,j=h.validation||{},k=!0;1!==b.operator.nb_inputs||Array.isArray(c)||(c=[c]);for(var l=0;l<i.nb_inputs;l++){if(!i.multiple&&a.isArray(c[l])&&c[l].length>1){k=["operator_not_multiple",i.type,this.translate("operators",i.type)];break}switch(h.input){case"radio":if(void 0===c[l]||0===c[l].length){j.allow_empty_value||(k=["radio_empty"]);break}break;case"checkbox":if(void 0===c[l]||0===c[l].length){j.allow_empty_value||(k=["checkbox_empty"]);break}break;case"select":if(void 0===c[l]||0===c[l].length||h.placeholder&&c[l]==h.placeholder_value){j.allow_empty_value||(k=["select_empty"]);break}break;default:e=a.isArray(c[l])?c[l]:[c[l]];for(var m=0;m<e.length;m++){switch(f.types[h.type]){case"string":if(void 0===e[m]||0===e[m].length){j.allow_empty_value||(k=["string_empty"]);break}if(void 0!==j.min&&e[m].length<parseInt(j.min)){k=[this.getValidationMessage(j,"min","string_exceed_min_length"),j.min];break}if(void 0!==j.max&&e[m].length>parseInt(j.max)){k=[this.getValidationMessage(j,"max","string_exceed_max_length"),j.max];break}if(j.format&&("string"==typeof j.format&&(j.format=new RegExp(j.format)),!j.format.test(e[m]))){k=[this.getValidationMessage(j,"format","string_invalid_format"),j.format];break}break;case"number":if(void 0===e[m]||0===e[m].length){j.allow_empty_value||(k=["number_nan"]);break}if(isNaN(e[m])){k=["number_nan"];break}if("integer"==h.type){if(parseInt(e[m])!=e[m]){k=["number_not_integer"];break}}else if(parseFloat(e[m])!=e[m]){k=["number_not_double"];break}if(void 0!==j.min&&e[m]<parseFloat(j.min)){k=[this.getValidationMessage(j,"min","number_exceed_min"),j.min];break}if(void 0!==j.max&&e[m]>parseFloat(j.max)){k=[this.getValidationMessage(j,"max","number_exceed_max"),j.max];break}if(void 0!==j.step&&"any"!==j.step){var n=(e[m]/j.step).toPrecision(14);if(parseInt(n)!=n){k=[this.getValidationMessage(j,"step","number_wrong_step"),j.step];break}}break;case"datetime":if(void 0===e[m]||0===e[m].length){j.allow_empty_value||(k=["datetime_empty"]);break}if(j.format){"moment"in window||g.error("MissingLibrary","MomentJS is required for Date/Time validation. Get it here http://momentjs.com");var o=moment(e[m],j.format);if(!o.isValid()){k=[this.getValidationMessage(j,"format","datetime_invalid"),j.format];break}if(j.min&&o<moment(j.min,j.format)){k=[this.getValidationMessage(j,"min","datetime_exceed_min"),j.min];break}if(j.max&&o>moment(j.max,j.format)){k=[this.getValidationMessage(j,"max","datetime_exceed_max"),j.max];break}}break;case"boolean":if(void 0===e[m]||0===e[m].length){j.allow_empty_value||(k=["boolean_not_valid"]);break}if(d=(""+e[m]).trim().toLowerCase(),"true"!==d&&"false"!==d&&"1"!==d&&"0"!==d&&1!==e[m]&&0!==e[m]){k=["boolean_not_valid"];break}}if(k!==!0)break}}if(k!==!0)break}if(("between"===b.operator.type||"not_between"===b.operator.type)&&2===c.length)switch(f.types[h.type]){case"number":c[0]>c[1]&&(k=["number_between_invalid",c[0],c[1]]);break;case"datetime":j.format&&("moment"in window||g.error("MissingLibrary","MomentJS is required for Date/Time validation. Get it here http://momentjs.com"),moment(c[0],j.format).isAfter(moment(c[1],j.format))&&(k=["datetime_between_invalid",c[0],c[1]]))}return k},f.prototype.nextGroupId=function(){return this.status.id+"_group_"+this.status.group_id++},f.prototype.nextRuleId=function(){return this.status.id+"_rule_"+this.status.rule_id++},f.prototype.getOperators=function(a){"string"==typeof a&&(a=this.getFilterById(a));for(var b=[],c=0,d=this.operators.length;c<d;c++){if(a.operators){if(a.operators.indexOf(this.operators[c].type)==-1)continue}else if(this.operators[c].apply_to.indexOf(f.types[a.type])==-1)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)},f.prototype.getFilterById=function(a,b){if("-1"==a)return null;for(var c=0,d=this.filters.length;c<d;c++)if(this.filters[c].id==a)return this.filters[c];return g.error(b!==!1,"UndefinedFilter",'Undefined filter "{0}"',a),null},f.prototype.getOperatorByType=function(a,b){if("-1"==a)return null;for(var c=0,d=this.operators.length;c<d;c++)if(this.operators[c].type==a)return this.operators[c];return g.error(b!==!1,"UndefinedOperator",'Undefined operator "{0}"',a),null},f.prototype.getRuleInputValue=function(b){var c=b.filter,d=b.operator,e=[];
  if(c.valueGetter)e=c.valueGetter.call(this,b);else{for(var h=b.$el.find(f.selectors.value_container),i=0;i<d.nb_inputs;i++){var j,k=g.escapeElementId(b.id+"_value_"+i);switch(c.input){case"radio":e.push(h.find("[name="+k+"]:checked").val());break;case"checkbox":j=[],h.find("[name="+k+"]:checked").each(function(){j.push(a(this).val())}),e.push(j);break;case"select":c.multiple?(j=[],h.find("[name="+k+"] option:selected").each(function(){j.push(a(this).val())}),e.push(j)):e.push(h.find("[name="+k+"] option:selected").val());break;default:e.push(h.find("[name="+k+"]").val())}}e=e.map(function(b){return d.multiple&&c.value_separator&&"string"==typeof b&&(b=b.split(c.value_separator)),a.isArray(b)?b.map(function(a){return g.changeType(a,c.type)}):g.changeType(b,c.type)}),1===d.nb_inputs&&(e=e[0]),c.valueParser&&(e=c.valueParser.call(this,b,e))}return this.change("getRuleValue",e,b)},f.prototype.setRuleInputValue=function(b,c){var d=b.filter,e=b.operator;if(d&&e){if(b._updating_input=!0,d.valueSetter)d.valueSetter.call(this,b,c);else{var h=b.$el.find(f.selectors.value_container);1==e.nb_inputs&&(c=[c]);for(var i=0;i<e.nb_inputs;i++){var j=g.escapeElementId(b.id+"_value_"+i);switch(d.input){case"radio":h.find("[name="+j+'][value="'+c[i]+'"]').prop("checked",!0).trigger("change");break;case"checkbox":a.isArray(c[i])||(c[i]=[c[i]]),c[i].forEach(function(a){h.find("[name="+j+'][value="'+a+'"]').prop("checked",!0).trigger("change")});break;default:e.multiple&&d.value_separator&&a.isArray(c[i])&&(c[i]=c[i].join(d.value_separator)),h.find("[name="+j+"]").val(c[i]).trigger("change")}}}b._updating_input=!1}},f.prototype.parseRuleFlags=function(b){var c=a.extend({},this.settings.default_rule_flags);return b.readonly&&a.extend(c,{filter_readonly:!0,operator_readonly:!0,value_readonly:!0,no_delete:!0}),b.flags&&a.extend(c,b.flags),this.change("parseRuleFlags",c,b)},f.prototype.getRuleFlags=function(b,c){if(c)return a.extend({},b);var d={};return a.each(this.settings.default_rule_flags,function(a,c){b[a]!==c&&(d[a]=b[a])}),d},f.prototype.parseGroupFlags=function(b){var c=a.extend({},this.settings.default_group_flags);return b.readonly&&a.extend(c,{condition_readonly:!0,no_add_rule:!0,no_add_group:!0,no_delete:!0}),b.flags&&a.extend(c,b.flags),this.change("parseGroupFlags",c,b)},f.prototype.getGroupFlags=function(b,c){if(c)return a.extend({},b);var d={};return a.each(this.settings.default_group_flags,function(a,c){b[a]!==c&&(d[a]=b[a])}),d},f.prototype.translate=function(a,b){b||(b=a,a=void 0);var c;return c="object"==typeof b?b[this.settings.lang_code]||b.en:(a?this.lang[a]:this.lang)[b]||b,this.change("translate",c,b,a)},f.prototype.getValidationMessage=function(a,b,c){return a.messages&&a.messages[b]||c},f.templates.group='<div id="{{= it.group_id }}" class="rules-group-container">   <div class="rules-group-header">     <div class="btn-group pull-right group-actions">       <button type="button" class="btn btn-xs btn-success" data-add="rule">         <i class="{{= it.icons.add_rule }}" title="{{= it.translate("add_rule_title") }}" ></i> {{= it.translate("add_rule") }}       </button>       {{? it.settings.allow_groups===-1 || it.settings.allow_groups>=it.level }}         <button type="button" class="btn btn-xs btn-success" data-add="group">           <i class="{{= it.icons.add_group }}" title="{{= it.translate("add_group_title") }}"></i> {{= it.translate("add_group") }}         </button>       {{?}}       {{? it.level>1 }}         <button type="button" class="btn btn-xs btn-danger" data-delete="group">           <i class="{{= it.icons.remove_group }}" title="{{= it.translate("delete_group_title") }}" ></i> {{= it.translate("delete_group") }}         </button>       {{?}}     </div>     <div class="btn-group group-conditions">       {{~ it.conditions: condition }}         <label class="btn btn-xs btn-primary">           <input type="radio" name="{{= it.group_id }}_cond" value="{{= condition }}"> {{= it.translate("conditions", condition) }}         </label>       {{~}}     </div>     {{? it.settings.display_errors }}       <div class="error-container"><i class="{{= it.icons.error }}"></i></div>     {{?}}   </div>   <div class=rules-group-body>     <div class=rules-list></div>   </div> </div>',f.templates.rule='<div id="{{= it.rule_id }}" class="rule-container">   <div class="rule-header">     <div class="btn-group pull-right rule-actions">       <button type="button" class="btn btn-xs btn-danger" data-delete="rule">         <i class="{{= it.icons.remove_rule }}" title="{{= it.translate("delete_rule_title") }}" ></i> {{= it.translate("delete_rule") }}       </button>     </div>   </div>   {{? it.settings.display_errors }}     <div class="error-container"><i class="{{= it.icons.error }}"></i></div>   {{?}}   <div class="rule-filter-container"></div>   <div class="rule-operator-container"></div>   <div class="rule-value-container"></div> </div>',f.templates.filterSelect='{{ var optgroup = null; }} <select class="form-control" name="{{= it.rule.id }}_filter">   {{? it.settings.display_empty_filter }}     <option value="-1">{{= it.settings.select_placeholder }}</option>   {{?}}   {{~ it.filters: filter }}     {{? optgroup !== filter.optgroup }}       {{? optgroup !== null }}</optgroup>{{?}}       {{? (optgroup = filter.optgroup) !== null }}         <optgroup label="{{= it.translate(it.settings.optgroups[optgroup]) }}">       {{?}}     {{?}}     <option value="{{= filter.id }}" {{? filter.icon}}data-icon="{{= filter.icon}}"{{?}}>{{= it.translate(filter.label) }}</option>   {{~}}   {{? optgroup !== null }}</optgroup>{{?}} </select>',f.templates.operatorSelect='{{? it.operators.length === 1 }} <span> {{= it.translate("operators", it.operators[0].type) }} </span> {{?}} {{ var optgroup = null; }} <select class="form-control {{? it.operators.length === 1 }}hide{{?}}" name="{{= it.rule.id }}_operator">   {{~ it.operators: operator }}     {{? optgroup !== operator.optgroup }}       {{? optgroup !== null }}</optgroup>{{?}}       {{? (optgroup = operator.optgroup) !== null }}         <optgroup label="{{= it.translate(it.settings.optgroups[optgroup]) }}">       {{?}}     {{?}}     <option value="{{= operator.type }}" {{? operator.icon}}data-icon="{{= operator.icon}}"{{?}}>{{= it.translate("operators", operator.type) }}</option>   {{~}}   {{? optgroup !== null }}</optgroup>{{?}} </select>',f.templates.ruleValueSelect='{{ var optgroup = null; }} <select class="form-control" name="{{= it.name }}" {{? it.rule.filter.multiple }}multiple{{?}}>   {{? it.rule.filter.placeholder }}     <option value="{{= it.rule.filter.placeholder_value }}" disabled selected>{{= it.rule.filter.placeholder }}</option>   {{?}}   {{~ it.rule.filter.values: entry }}     {{? optgroup !== entry.optgroup }}       {{? optgroup !== null }}</optgroup>{{?}}       {{? (optgroup = entry.optgroup) !== null }}         <optgroup label="{{= it.translate(it.settings.optgroups[optgroup]) }}">       {{?}}     {{?}}     <option value="{{= entry.value }}">{{= entry.label }}</option>   {{~}}   {{? optgroup !== null }}</optgroup>{{?}} </select>',f.prototype.getGroupTemplate=function(a,b){var c=this.templates.group({builder:this,group_id:a,level:b,conditions:this.settings.conditions,icons:this.icons,settings:this.settings,translate:this.translate.bind(this)});return this.change("getGroupTemplate",c,b)},f.prototype.getRuleTemplate=function(a){var b=this.templates.rule({builder:this,rule_id:a,icons:this.icons,settings:this.settings,translate:this.translate.bind(this)});return this.change("getRuleTemplate",b)},f.prototype.getRuleFilterSelect=function(a,b){var c=this.templates.filterSelect({builder:this,rule:a,filters:b,icons:this.icons,settings:this.settings,translate:this.translate.bind(this)});return this.change("getRuleFilterSelect",c,a,b)},f.prototype.getRuleOperatorSelect=function(a,b){var c=this.templates.operatorSelect({builder:this,rule:a,operators:b,icons:this.icons,settings:this.settings,translate:this.translate.bind(this)});return this.change("getRuleOperatorSelect",c,a,b)},f.prototype.getRuleValueSelect=function(a,b){var c=this.templates.ruleValueSelect({builder:this,name:a,rule:b,icons:this.icons,settings:this.settings,translate:this.translate.bind(this)});return this.change("getRuleValueSelect",c,a,b)},f.prototype.getRuleInput=function(a,b){var c=a.filter,d=a.filter.validation||{},e=a.id+"_value_"+b,f=c.vertical?" class=block":"",h="";if("function"==typeof c.input)h=c.input.call(this,a,e);else switch(c.input){case"radio":case"checkbox":g.iterateOptions(c.values,function(a,b){h+="<label"+f+'><input type="'+c.input+'" name="'+e+'" value="'+a+'"> '+b+"</label> "});break;case"select":h=this.getRuleValueSelect(e,a);break;case"textarea":h+='<textarea class="form-control" name="'+e+'"',c.size&&(h+=' cols="'+c.size+'"'),c.rows&&(h+=' rows="'+c.rows+'"'),void 0!==d.min&&(h+=' minlength="'+d.min+'"'),void 0!==d.max&&(h+=' maxlength="'+d.max+'"'),c.placeholder&&(h+=' placeholder="'+c.placeholder+'"'),h+="></textarea>";break;case"number":h+='<input class="form-control" type="number" name="'+e+'"',void 0!==d.step&&(h+=' step="'+d.step+'"'),void 0!==d.min&&(h+=' min="'+d.min+'"'),void 0!==d.max&&(h+=' max="'+d.max+'"'),c.placeholder&&(h+=' placeholder="'+c.placeholder+'"'),c.size&&(h+=' size="'+c.size+'"'),h+=">";break;default:h+='<input class="form-control" type="text" name="'+e+'"',c.placeholder&&(h+=' placeholder="'+c.placeholder+'"'),"string"===c.type&&void 0!==d.min&&(h+=' minlength="'+d.min+'"'),"string"===c.type&&void 0!==d.max&&(h+=' maxlength="'+d.max+'"'),c.size&&(h+=' size="'+c.size+'"'),h+=">"}return this.change("getRuleInput",h,a,e)};var g={};f.utils=g,g.iterateOptions=function(b,c){b&&(a.isArray(b)?b.forEach(function(b){a.isPlainObject(b)?"value"in b?c(b.value,b.label||b.value,b.optgroup):a.each(b,function(a,b){return c(a,b),!1}):c(b,b)}):a.each(b,function(a,b){c(a,b)}))},g.fmt=function(a,b){return Array.isArray(b)||(b=Array.prototype.slice.call(arguments,1)),a.replace(/{([0-9]+)}/g,function(a,c){return b[parseInt(c)]})},g.error=function(){var a=0,b="boolean"!=typeof arguments[a]||arguments[a++],c=arguments[a++],d=arguments[a++],e=Array.isArray(arguments[a])?arguments[a]:Array.prototype.slice.call(arguments,a);if(b){var f=new Error(g.fmt(d,e));throw f.name=c+"Error",f.args=e,f}console.error(c+"Error: "+g.fmt(d,e))},g.changeType=function(a,b){if(""!==a&&void 0!==a)switch(b){case"integer":return"string"!=typeof a||/^-?\d+$/.test(a)?parseInt(a):a;case"double":return"string"!=typeof a||/^-?\d+\.?\d*$/.test(a)?parseFloat(a):a;case"boolean":return"string"!=typeof a||/^(0|1|true|false){1}$/i.test(a)?a===!0||1===a||"true"===a.toLowerCase()||"1"===a:a;default:return a}},g.escapeString=function(a){return"string"!=typeof a?a:a.replace(/[\0\n\r\b\\\'\"]/g,function(a){switch(a){case"\0":return"\\0";case"\n":return"\\n";case"\r":return"\\r";case"\b":return"\\b";case"'":return"''";default:return"\\"+a}}).replace(/\t/g,"\\t").replace(/\x1a/g,"\\Z")},g.escapeRegExp=function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},g.escapeElementId=function(a){return a?a.replace(/(\\)?([:.\[\],])/g,function(a,b,c){return b?a:"\\"+c}):a},g.groupSort=function(a,b){var c=[],d=[];return a.forEach(function(a){var e;a[b]?(e=c.lastIndexOf(a[b]),e==-1?e=c.length:e++):e=c.length,c.splice(e,0,a[b]),d.splice(e,0,a)}),d},g.defineModelProperties=function(b,c){c.forEach(function(c){Object.defineProperty(b.prototype,c,{enumerable:!0,get:function(){return this.__[c]},set:function(b){var d=null!==this.__[c]&&"object"==typeof this.__[c]?a.extend({},this.__[c]):this.__[c];this.__[c]=b,null!==this.model&&this.model.trigger("update",this,c,b,d)}})})},a.extend(c.prototype,{trigger:function(b){var c=new a.Event(b);return this.$.triggerHandler(c,Array.prototype.slice.call(arguments,1)),c},on:function(){return this.$.on.apply(this.$,Array.prototype.slice.call(arguments)),this},off:function(){return this.$.off.apply(this.$,Array.prototype.slice.call(arguments)),this},once:function(){return this.$.one.apply(this.$,Array.prototype.slice.call(arguments)),this}});var h=function(a,b){return this instanceof h?(Object.defineProperty(this,"__",{value:{}}),b.data("queryBuilderModel",this),this.__.level=1,this.__.error=null,this.__.flags={},this.__.data=void 0,this.$el=b,this.id=b[0].id,this.model=null,void(this.parent=a)):new h(a,b)};g.defineModelProperties(h,["level","error","data","flags"]),Object.defineProperty(h.prototype,"parent",{enumerable:!0,get:function(){return this.__.parent},set:function(a){this.__.parent=a,this.level=null===a?1:a.level+1,this.model=null===a?null:a.model}}),h.prototype.isRoot=function(){return 1===this.level},h.prototype.getPos=function(){return this.isRoot()?-1:this.parent.getNodePos(this)},h.prototype.drop=function(){var a=this.model;this.parent&&this.parent.removeNode(this),this.$el.removeData("queryBuilderModel"),null!==a&&a.trigger("drop",this)},h.prototype.moveAfter=function(a){this.isRoot()||this.move(a.parent,a.getPos()+1)},h.prototype.moveAtBegin=function(a){this.isRoot()||(void 0===a&&(a=this.parent),this.move(a,0))},h.prototype.moveAtEnd=function(a){this.isRoot()||(void 0===a&&(a=this.parent),this.move(a,0===a.length()?0:a.length()-1))},h.prototype.move=function(a,b){this.isRoot()||("number"==typeof a&&(b=a,a=this.parent),this.parent.removeNode(this),a.insertNode(this,b,!1),null!==this.model&&this.model.trigger("move",this,a,b))};var i=function(a,b){return this instanceof i?(h.call(this,a,b),this.rules=[],void(this.__.condition=null)):new i(a,b)};i.prototype=Object.create(h.prototype),i.prototype.constructor=i,g.defineModelProperties(i,["condition"]),i.prototype.empty=function(){this.each("reverse",function(a){a.drop()},function(a){a.drop()})},i.prototype.drop=function(){this.empty(),h.prototype.drop.call(this)},i.prototype.length=function(){return this.rules.length},i.prototype.insertNode=function(a,b,c){return void 0===b&&(b=this.length()),this.rules.splice(b,0,a),a.parent=this,c&&null!==this.model&&this.model.trigger("add",this,a,b),a},i.prototype.addGroup=function(a,b){return this.insertNode(new i(this,a),b,!0)},i.prototype.addRule=function(a,b){return this.insertNode(new j(this,a),b,!0)},i.prototype.removeNode=function(a){var b=this.getNodePos(a);b!==-1&&(a.parent=null,this.rules.splice(b,1))},i.prototype.getNodePos=function(a){return this.rules.indexOf(a)},i.prototype.each=function(a,b,c,d){"boolean"!=typeof a&&"string"!=typeof a&&(d=c,c=b,b=a,a=!1),d=void 0===d?null:d;for(var e=a?this.rules.length-1:0,f=a?0:this.rules.length-1,g=a?-1:1,h=function(){return a?e>=f:e<=f},j=!1;h()&&(this.rules[e]instanceof i?c&&(j=c.call(d,this.rules[e])===!1):b&&(j=b.call(d,this.rules[e])===!1),!j);e+=g);return!j},i.prototype.contains=function(a,b){return this.getNodePos(a)!==-1||!!b&&!this.each(function(){return!0},function(b){return!b.contains(a,!0)})};var j=function(a,b){return this instanceof j?(h.call(this,a,b),this._updating_value=!1,this._updating_input=!1,this.__.filter=null,this.__.operator=null,void(this.__.value=void 0)):new j(a,b)};return j.prototype=Object.create(h.prototype),j.prototype.constructor=j,g.defineModelProperties(j,["filter","operator","value"]),j.prototype.isRoot=function(){return!1},f.Group=i,f.Rule=j,a.fn.queryBuilder=function(a){0===this.length&&g.error("Config","No target defined"),this.length>1&&g.error("Config","Unable to initialize on multiple target");var b=this.data("queryBuilder"),c="object"==typeof a&&a||{};if(!b&&"destroy"==a)return this;if(!b){var d=new f(this,c);this.data("queryBuilder",d),d.init(c.rules)}return"string"==typeof a?b[a].apply(b,Array.prototype.slice.call(arguments,1)):this},a.fn.queryBuilder.constructor=f,a.fn.queryBuilder.defaults=f.defaults,a.fn.queryBuilder.extend=f.extend,a.fn.queryBuilder.define=f.define,a.fn.queryBuilder.regional=f.regional,f.define("bt-checkbox",function(a){"glyphicons"==a.font&&this.$el.addClass("bt-checkbox-glyphicons"),this.on("getRuleInput.filter",function(b,c,d){var e=c.filter;if(("radio"===e.input||"checkbox"===e.input)&&!e.plugin){b.value="",e.colors||(e.colors={}),e.color&&(e.colors._def_=e.color);var f=e.vertical?' style="display:block"':"",h=0;g.iterateOptions(e.values,function(c,g){var i=e.colors[c]||e.colors._def_||a.color,j=d+"_"+h++;b.value+="<div"+f+' class="'+e.input+" "+e.input+"-"+i+'">   <input type="'+e.input+'" name="'+d+'" id="'+j+'" value="'+c+'">   <label for="'+j+'">'+g+"</label> </div>"})}})},{font:"glyphicons",color:"default"}),f.define("bt-selectpicker",function(b){a.fn.selectpicker&&a.fn.selectpicker.Constructor||g.error("MissingLibrary",'Bootstrap Select is required to use "bt-selectpicker" plugin. Get it here: http://silviomoreto.github.io/bootstrap-select');var c=f.selectors;this.on("afterCreateRuleFilters",function(a,d){d.$el.find(c.rule_filter).removeClass("form-control").selectpicker(b)}),this.on("afterCreateRuleOperators",function(a,d){d.$el.find(c.rule_operator).removeClass("form-control").selectpicker(b)}),this.on("afterUpdateRuleFilter",function(a,b){b.$el.find(c.rule_filter).selectpicker("render")}),this.on("afterUpdateRuleOperator",function(a,b){b.$el.find(c.rule_operator).selectpicker("render")}),this.on("beforeDeleteRule",function(a,b){b.$el.find(c.rule_filter).selectpicker("destroy"),b.$el.find(c.rule_operator).selectpicker("destroy")})},{container:"body",style:"btn-inverse btn-xs",width:"auto",showIcon:!1}),f.define("bt-tooltip-errors",function(b){a.fn.tooltip&&a.fn.tooltip.Constructor&&a.fn.tooltip.Constructor.prototype.fixTitle||g.error("MissingLibrary",'Bootstrap Tooltip is required to use "bt-tooltip-errors" plugin. Get it here: http://getbootstrap.com');var c=this;this.on("getRuleTemplate.filter getGroupTemplate.filter",function(b){var c=a(b.value);c.find(f.selectors.error_container).attr("data-toggle","tooltip"),b.value=c.prop("outerHTML")}),this.model.on("update",function(a,d,e){"error"==e&&c.settings.display_errors&&d.$el.find(f.selectors.error_container).eq(0).tooltip(b).tooltip("hide").tooltip("fixTitle")})},{placement:"right"}),f.extend({setFilters:function(a,b){var c=this;void 0===b&&(b=a,a=!1),b=this.checkFilters(b),b=this.change("setFilters",b);var d=b.map(function(a){return a.id});if(a||!function h(a){a.each(function(a){a.filter&&d.indexOf(a.filter.id)===-1&&g.error("ChangeFilter",'A rule is using filter "{0}"',a.filter.id)},h)}(this.model.root),this.filters=b,function i(a){a.each(!0,function(a){a.filter&&d.indexOf(a.filter.id)===-1?(a.drop(),c.trigger("rulesChanged")):(c.createRuleFilters(a),a.$el.find(f.selectors.rule_filter).val(a.filter?a.filter.id:"-1"),c.trigger("afterUpdateRuleFilter",a))},i)}(this.model.root),this.settings.plugins&&(this.settings.plugins["unique-filter"]&&this.updateDisabledFilters(),this.settings.plugins["bt-selectpicker"]&&this.$el.find(f.selectors.rule_filter).selectpicker("render")),this.settings.default_filter)try{this.getFilterById(this.settings.default_filter)}catch(e){this.settings.default_filter=null}this.trigger("afterSetFilters",b)},addFilter:function(b,c){void 0===c||"#end"==c?c=this.filters.length:"#start"==c&&(c=0),a.isArray(b)||(b=[b]);var d=a.extend(!0,[],this.filters);parseInt(c)==c?Array.prototype.splice.apply(d,[c,0].concat(b)):this.filters.some(function(a,b){if(a.id==c)return c=b+1,!0})?Array.prototype.splice.apply(d,[c,0].concat(b)):Array.prototype.push.apply(d,b),this.setFilters(d)},removeFilter:function(b,c){var d=a.extend(!0,[],this.filters);"string"==typeof b&&(b=[b]),d=d.filter(function(a){return b.indexOf(a.id)===-1}),this.setFilters(c,d)}}),f.define("chosen-selectpicker",function(b){a.fn.chosen||g.error("MissingLibrary",'chosen is required to use "chosen-selectpicker" plugin. Get it here: https://github.com/harvesthq/chosen'),this.settings.plugins["bt-selectpicker"]&&g.error("Conflict","bt-selectpicker is already selected as the dropdown plugin. Please remove chosen-selectpicker from the plugin list");var c=f.selectors;this.on("afterCreateRuleFilters",function(a,d){d.$el.find(c.rule_filter).removeClass("form-control").chosen(b)}),this.on("afterCreateRuleOperators",function(a,d){d.$el.find(c.rule_operator).removeClass("form-control").chosen(b)}),this.on("afterUpdateRuleFilter",function(a,b){b.$el.find(c.rule_filter).trigger("chosen:updated")}),this.on("afterUpdateRuleOperator",function(a,b){b.$el.find(c.rule_operator).trigger("chosen:updated")}),this.on("beforeDeleteRule",function(a,b){b.$el.find(c.rule_filter).chosen("destroy"),b.$el.find(c.rule_operator).chosen("destroy")})}),f.define("collapse-groups",function(b){var c=this,d=f.selectors;this.on("afterInit",function(){c.$el.on("click.queryBuilder","[data-collapse=group]",function(){a(this).closest(d.group_container);c.collapse(a(this),b),c.toggleCollapseValue(a(this))}),c.$el.on("change.queryBuilder",".group-name",function(){c.setGroupName(a(this))})}),this.on("afterSetRules",function(){a.each(c.$el.find(d.group_container),function(d,e){var f=c.getModel(a(e));f.collapsed&&c.collapse(a(e).find('[data-collapse="group"]:first'),b),f.name&&a(e).find(".group-name:first").val(f.name)})}),this.on("getGroupTemplate.filter",function(e,f){var g=a(e.value);g.find(d.group_header).append('<button type="button" class="btn btn-xs btn-default" data-collapse="group"><i class="'+b.iconUp+'"></i> '+c.translate("collapse")+"</button>"),e.value=g.prop("outerHTML")}),b.namedGroups&&this.on("getGroupTemplate.filter",function(b,c){var e=a(b.value);e.find(d.group_header).append('<input type="text" maxlength="32" class="group-name">'),b.value=e.prop("outerHTML")}),this.on("groupToJson.filter",function(a,b){a.value.collapsed=b.collapsed,a.value.name=b.name}),this.on("jsonToGroup.filter",function(a,b){a.value.collapsed=b.collapsed,a.value.name=b.name})},{iconUp:"glyphicon glyphicon-chevron-up",iconDown:"glyphicon glyphicon-chevron-down",namedGroups:!0}),g.defineModelProperties(i,["name","collapsed"]),f.extend({collapse:function(a,b){var c=f.selectors,d=a.find("i");a.closest(c.group_container).find(c.rules_list+":first").slideToggle("fast"),a.parent().parent().find(c.group_condition+":first").parent().parent().toggleClass("collapsed"),a.parent().parent().find(c.add_rule+":first").toggleClass("collapsed"),a.parent().parent().find(c.add_group+":first").toggleClass("collapsed"),d.toggleClass(b.iconUp).toggleClass(b.iconDown)},toggleCollapseValue:function(a){var b=this.getModel(a.closest(f.selectors.group_container));b.collapsed=!b.collapsed},setGroupName:function(a){var b=a.val(),c=f.selectors,d=this.getModel(a.closest(c.group_container));d.name=b}}),f.define("filter-description",function(b){"inline"===b.mode?this.on("afterUpdateRuleFilter afterUpdateRuleOperator",function(c,d){var e=d.$el.find("p.filter-description"),f=c.builder.getFilterDescription(d.filter,d);f?(0===e.length?(e=a('<p class="filter-description"></p>'),e.appendTo(d.$el)):e.css("display",""),e.html('<i class="'+b.icon+'"></i> '+f)):e.hide()}):"popover"===b.mode?(a.fn.popover&&a.fn.popover.Constructor&&a.fn.popover.Constructor.prototype.fixTitle||g.error("MissingLibrary",'Bootstrap Popover is required to use "filter-description" plugin. Get it here: http://getbootstrap.com'),this.on("afterUpdateRuleFilter afterUpdateRuleOperator",function(c,d){var e=d.$el.find("button.filter-description"),g=c.builder.getFilterDescription(d.filter,d);g?(0===e.length?(e=a('<button type="button" class="btn btn-xs btn-info filter-description" data-toggle="popover"><i class="'+b.icon+'"></i></button>'),e.prependTo(d.$el.find(f.selectors.rule_actions)),e.popover({placement:"left",container:"body",html:!0}),e.on("mouseout",function(){e.popover("hide")})):e.css("display",""),e.data("bs.popover").options.content=g,e.attr("aria-describedby")&&e.popover("show")):(e.hide(),e.data("bs.popover")&&e.popover("hide"))})):"bootbox"===b.mode&&("bootbox"in window||g.error("MissingLibrary",'Bootbox is required to use "filter-description" plugin. Get it here: http://bootboxjs.com'),this.on("afterUpdateRuleFilter afterUpdateRuleOperator",function(c,d){var e=d.$el.find("button.filter-description"),g=c.builder.getFilterDescription(d.filter,d);g?(0===e.length?(e=a('<button type="button" class="btn btn-xs btn-info filter-description" data-toggle="bootbox"><i class="'+b.icon+'"></i></button>'),e.prependTo(d.$el.find(f.selectors.rule_actions)),e.on("click",function(){bootbox.alert(e.data("description"))})):e.css("display",""),e.data("description",g)):e.hide()}))},{icon:"glyphicon glyphicon-info-sign",mode:"popover"}),f.extend({getFilterDescription:function(a,b){return a?"function"==typeof a.description?a.description.call(this,b):a.description:void 0}}),f.define("invert",function(b){var c=this,d=f.selectors;this.on("afterInit",function(){c.$el.on("click.queryBuilder","[data-invert=group]",function(){var e=a(this).closest(d.group_container);c.invert(c.getModel(e),b)}),b.display_rules_button&&b.invert_rules&&c.$el.on("click.queryBuilder","[data-invert=rule]",function(){var e=a(this).closest(d.rule_container);c.invert(c.getModel(e),b)})}),b.disable_template||(this.on("getGroupTemplate.filter",function(e){var f=a(e.value);f.find(d.condition_container).after('<button type="button" class="btn btn-xs btn-default" data-invert="group"><i class="'+b.icon+'"></i> '+c.translate("invert")+"</button>"),e.value=f.prop("outerHTML")}),b.display_rules_button&&b.invert_rules&&this.on("getRuleTemplate.filter",function(e){var f=a(e.value);f.find(d.rule_actions).prepend('<button type="button" class="btn btn-xs btn-default" data-invert="rule"><i class="'+b.icon+'"></i> '+c.translate("invert")+"</button>"),e.value=f.prop("outerHTML")}))},{icon:"glyphicon glyphicon-random",recursive:!0,invert_rules:!0,display_rules_button:!1,silent_fail:!1,disable_template:!1}),f.defaults({operatorOpposites:{equal:"not_equal",not_equal:"equal","in":"not_in",not_in:"in",less:"greater_or_equal",less_or_equal:"greater",greater:"less_or_equal",greater_or_equal:"less",between:"not_between",not_between:"between",begins_with:"not_begins_with",not_begins_with:"begins_with",contains:"not_contains",not_contains:"contains",ends_with:"not_ends_with",not_ends_with:"ends_with",is_empty:"is_not_empty",is_not_empty:"is_empty",is_null:"is_not_null",is_not_null:"is_null"},conditionOpposites:{AND:"OR",OR:"AND"}}),f.extend({invert:function(b,c){if(!(b instanceof h)){if(!this.model.root)return;c=b,b=this.model.root}if("object"!=typeof c&&(c={}),void 0===c.recursive&&(c.recursive=!0),void 0===c.invert_rules&&(c.invert_rules=!0),void 0===c.silent_fail&&(c.silent_fail=!1),void 0===c.trigger&&(c.trigger=!0),b instanceof i){if(this.settings.conditionOpposites[b.condition]?b.condition=this.settings.conditionOpposites[b.condition]:c.silent_fail||g.error("InvertCondition",'Unknown inverse of condition "{0}"',b.condition),c.recursive){var d=a.extend({},c,{trigger:!1});b.each(function(a){c.invert_rules&&this.invert(a,d)},function(a){this.invert(a,d)},this)}}else if(b instanceof j&&b.operator&&!b.filter.no_invert)if(this.settings.operatorOpposites[b.operator.type]){var e=this.settings.operatorOpposites[b.operator.type];b.filter.operators&&b.filter.operators.indexOf(e)==-1||(b.operator=this.getOperatorByType(e))}else c.silent_fail||g.error("InvertOperator",'Unknown inverse of operator "{0}"',b.operator.type);c.trigger&&(this.trigger("afterInvert",b,c),this.trigger("rulesChanged"))}}),f.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]}},not_between:function(a){return{$lt:a[0],$gt:a[1]}},begins_with:function(a){return{$regex:"^"+g.escapeRegExp(a[0])}},not_begins_with:function(a){return{$regex:"^(?!"+g.escapeRegExp(a[0])+")"}},contains:function(a){return{$regex:g.escapeRegExp(a[0])}},not_contains:function(a){return{$regex:"^((?!"+g.escapeRegExp(a[0])+").)*$",$options:"s"}},ends_with:function(a){return{$regex:g.escapeRegExp(a[0])+"$"}},not_ends_with:function(a){return{$regex:"(?<!"+g.escapeRegExp(a[0])+")$"}},is_empty:function(a){return""},is_not_empty:function(a){return{$ne:""}},is_null:function(a){return null},is_not_null:function(a){return{$ne:null}}},mongoRuleOperators:{$eq:function(a){return{val:a,op:null===a?"is_null":""===a?"is_empty":"equal"}},$ne:function(a){return a=a.$ne,{val:a,op:null===a?"is_not_null":""===a?"is_not_empty":"not_equal"}},$regex:function(a){return a=a.$regex,"^(?!"==a.slice(0,4)&&")"==a.slice(-1)?{val:a.slice(4,-1),op:"not_begins_with"}:"^((?!"==a.slice(0,5)&&").)*$"==a.slice(-5)?{val:a.slice(5,-5),op:"not_contains"}:"(?<!"==a.slice(0,4)&&")$"==a.slice(-2)?{val:a.slice(4,-2),op:"not_ends_with"}:"$"==a.slice(-1)?{val:a.slice(0,-1),op:"ends_with"}:"^"==a.slice(0,1)?{val:a.slice(1),op:"begins_with"}:{val:a,op:"contains"}},between:function(a){return{val:[a.$gte,a.$lte],op:"between"}},not_between:function(a){return{val:[a.$lt,a.$gt],op:"not_between"}},$in:function(a){return{val:a.$in,op:"in"}},$nin:function(a){return{val:a.$nin,op:"not_in"}},$lt:function(a){return{val:a.$lt,op:"less"}},$lte:function(a){return{val:a.$lte,op:"less_or_equal"}},$gt:function(a){return{val:a.$gt,op:"greater"}},$gte:function(a){return{val:a.$gte,op:"greater_or_equal"}}}}),f.extend({getMongo:function(a){if(a=void 0===a?this.getRules():a,!a)return null;var b=this;return function c(a){if(a.condition||(a.condition=b.settings.default_condition),["AND","OR"].indexOf(a.condition.toUpperCase())===-1&&g.error("UndefinedMongoCondition",'Unable to build MongoDB 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 e=b.settings.mongoOperators[a.operator],f=b.getOperatorByType(a.operator);void 0===e&&g.error("UndefinedMongoOperator",'Unknown MongoDB operation for operator "{0}"',a.operator),0!==f.nb_inputs&&(a.value instanceof Array||(a.value=[a.value]));var h=b.change("getMongoDBField",a.field,a),i={};i[h]=e.call(b,a.value),d.push(b.change("ruleToMongo",i,a,a.value,e))}});var e={};return e["$"+a.condition.toLowerCase()]=d,b.change("groupToMongo",e,a)}(a)},getRulesFromMongo:function(a){if(void 0===a||null===a)return null;var b=this;if(a=b.change("parseMongoNode",a),"rules"in a&&"condition"in a)return a;if("id"in a&&"operator"in a&&"value"in a)return{condition:this.settings.default_condition,rules:[a]};var c=b.getMongoCondition(a);return c||g.error("MongoParse","Invalid MongoDB query format"),function d(a,c){var e=a[c],f=[];return e.forEach(function(a){if(a=b.change("parseMongoNode",a),"rules"in a&&"condition"in a)return void f.push(a);if("id"in a&&"operator"in a&&"value"in a)return void f.push(a);var c=b.getMongoCondition(a);if(c)f.push(d(a,c));else{var e=Object.keys(a)[0],h=a[e],i=b.getMongoOperator(h);void 0===i&&g.error("MongoParse","Invalid MongoDB query format");var j=b.settings.mongoRuleOperators[i];void 0===j&&g.error("UndefinedMongoOperator",'JSON Rule operation unknown for operator "{0}"',i);var k=j.call(b,h),l=b.getMongoDBFieldID(e,h),m=b.change("mongoToRule",{id:l,field:e,operator:k.op,value:k.val},a);f.push(m)}}),b.change("mongoToGroup",{condition:c.replace("$","").toUpperCase(),rules:f},a)}(a,c)},setRulesFromMongo:function(a){this.setRules(this.getRulesFromMongo(a))},getMongoDBFieldID:function(a,b){var c,d=this.filters.filter(function(b){return b.field===a});return c=1===d.length?d[0].id:this.change("getMongoDBFieldID",a,b)},getMongoOperator:function(a){if(null===a||"object"!=typeof a)return"$eq";if(void 0!==a.$gte&&void 0!==a.$lte)return"between";if(void 0!==a.$lt&&void 0!==a.$gt)return"not_between";var b=Object.keys(a).filter(function(a){return!!this.settings.mongoRuleOperators[a]}.bind(this));return 1===b.length?b[0]:void 0},getMongoCondition:function(a){for(var b=Object.keys(a),c=0,d=b.length;c<d;c++)if("$or"===b[c].toLowerCase()||"$and"===b[c].toLowerCase())return b[c]}}),f.define("not-group",function(b){
  var c=this;this.on("afterInit",function(){c.$el.on("click.queryBuilder","[data-not=group]",function(){var b=a(this).closest(f.selectors.group_container),d=c.getModel(b);d.not=!d.not}),c.model.on("update",function(a,b,d){b instanceof i&&"not"===d&&c.updateGroupNot(b)})}),this.on("afterAddGroup",function(a,b){b.__.not=!1}),b.disable_template||this.on("getGroupTemplate.filter",function(d){var e=a(d.value);e.find(f.selectors.condition_container).prepend('<button type="button" class="btn btn-xs btn-default" data-not="group"><i class="'+b.icon_unchecked+'"></i> '+c.translate("NOT")+"</button>"),d.value=e.prop("outerHTML")}),this.on("groupToJson.filter",function(a,b){a.value.not=b.not}),this.on("jsonToGroup.filter",function(a,b){a.value.not=!!b.not}),this.on("groupToSQL.filter",function(a,b){b.not&&(a.value="NOT ( "+a.value+" )")}),this.on("parseSQLNode.filter",function(a){a.value.name&&"NOT"==a.value.name.toUpperCase()&&(a.value=a.value.arguments.value[0],["AND","OR"].indexOf(a.value.operation.toUpperCase())===-1&&(a.value=new SQLParser.nodes.Op(c.settings.default_condition,a.value,null)),a.value.not=!0)}),this.on("sqlGroupsDistinct.filter",function(a,b,c,d){c.not&&d>0&&(a.value=!0)}),this.on("sqlToGroup.filter",function(a,b){a.value.not=!!b.not}),this.on("groupToMongo.filter",function(a,b){var c="$"+b.condition.toLowerCase();b.not&&a.value[c]&&(a.value={$nor:[a.value]})}),this.on("parseMongoNode.filter",function(a){var b=Object.keys(a.value);"$nor"==b[0]&&(a.value=a.value[b[0]][0],a.value.not=!0)}),this.on("mongoToGroup.filter",function(a,b){a.value.not=!!b.not})},{icon_unchecked:"glyphicon glyphicon-unchecked",icon_checked:"glyphicon glyphicon-check",disable_template:!1}),g.defineModelProperties(i,["not"]),f.selectors.group_not=f.selectors.group_header+" [data-not=group]",f.extend({updateGroupNot:function(a){var b=this.plugins["not-group"];a.$el.find(">"+f.selectors.group_not).toggleClass("active",a.not).find("i").attr("class",a.not?b.icon_checked:b.icon_unchecked),this.trigger("afterUpdateGroupNot",a),this.trigger("rulesChanged")}}),f.define("sortable",function(b){"interact"in window||g.error("MissingLibrary",'interact.js is required to use "sortable" plugin. Get it here: http://interactjs.io'),void 0!==b.default_no_sortable&&(g.error(!1,"Config",'Sortable plugin : "default_no_sortable" options is deprecated, use standard "default_rule_flags" and "default_group_flags" instead'),this.settings.default_rule_flags.no_sortable=this.settings.default_group_flags.no_sortable=b.default_no_sortable),interact.dynamicDrop(!0),interact.pointerMoveTolerance(10);var c,e,h,j,k=b.autoScrollContainer||this.$el[0],l=k!==this.$el[0];this.on("afterAddRule afterAddGroup",function(g,m){if(m!=c){var n=g.builder;b.inherit_no_sortable&&m.parent&&m.parent.flags.no_sortable&&(m.flags.no_sortable=!0),b.inherit_no_drop&&m.parent&&m.parent.flags.no_drop&&(m.flags.no_drop=!0),m.flags.no_sortable||interact(m.$el[0]).draggable({allowFrom:f.selectors.drag_handle,autoScroll:{container:k},onstart:function(b){j=!1,h=n.getModel(b.target),e=h.$el.clone().appendTo(h.$el.parent()).width(h.$el.outerWidth()).addClass("dragging").css("position","fixed");var d=a('<div class="rule-placeholder">&nbsp;</div>').height(h.$el.outerHeight());c=h.parent.addRule(d,h.getPos()),h.$el.hide()},onmove:function(a){if(e&&e[0]){var b=a.clientX-15,c=a.clientY-15;l&&(c+=k.scrollTop,b+=k.scrollLeft),e[0].style.top=c+"px",e[0].style.left=b+"px"}},onend:function(b){b.dropzone&&(d(h,a(b.relatedTarget),n),j=!0),e&&e.remove(),e=void 0,c.drop(),c=void 0,h.$el.css("display",""),n.trigger("afterMove",h),n.trigger("rulesChanged")}}),m.flags.no_drop||(interact(m.$el[0]).dropzone({accept:f.selectors.rule_and_group_containers,ondragenter:function(b){d(c,a(b.target),n)},ondrop:function(b){j||d(h,a(b.target),n)}}),m instanceof i&&interact(m.$el.find(f.selectors.group_header)[0]).dropzone({accept:f.selectors.rule_and_group_containers,ondragenter:function(b){d(c,a(b.target),n)},ondrop:function(b){j||d(h,a(b.target),n)}}))}}),this.on("beforeDeleteRule beforeDeleteGroup",function(a,b){a.isDefaultPrevented()||(interact(b.$el[0]).unset(),b instanceof i&&interact(b.$el.find(f.selectors.group_header)[0]).unset())}),this.on("afterApplyRuleFlags afterApplyGroupFlags",function(a,b){b.flags.no_sortable&&b.$el.find(f.selectors.drag_handle).remove()}),b.disable_template||(this.on("getGroupTemplate.filter",function(c,d){if(d>1){var e=a(c.value);e.find(f.selectors.condition_container).after('<div class="drag-handle"><i class="'+b.icon+'"></i></div>'),c.value=e.prop("outerHTML")}}),this.on("getRuleTemplate.filter",function(c){var d=a(c.value);d.find(f.selectors.rule_header).after('<div class="drag-handle"><i class="'+b.icon+'"></i></div>'),c.value=d.prop("outerHTML")}))},{inherit_no_sortable:!0,inherit_no_drop:!0,icon:"glyphicon glyphicon-sort",disable_template:!1}),f.selectors.rule_and_group_containers=f.selectors.rule_container+", "+f.selectors.group_container,f.selectors.drag_handle=".drag-handle",f.defaults({default_rule_flags:{no_sortable:!1,no_drop:!1},default_group_flags:{no_sortable:!1,no_drop:!1}}),f.define("sql-support",function(a){},{boolean_as_integer:!0}),f.defaults({sqlOperators:{equal:{op:"= ?"},not_equal:{op:"!= ?"},"in":{op:"IN(?)",sep:", "},not_in:{op:"NOT IN(?)",sep:", "},less:{op:"< ?"},less_or_equal:{op:"<= ?"},greater:{op:"> ?"},greater_or_equal:{op:">= ?"},between:{op:"BETWEEN ?",sep:" AND "},not_between:{op:"NOT BETWEEN ?",sep:" AND "},begins_with:{op:"LIKE(?)",mod:"{0}%"},not_begins_with:{op:"NOT LIKE(?)",mod:"{0}%"},contains:{op:"LIKE(?)",mod:"%{0}%"},not_contains:{op:"NOT LIKE(?)",mod:"%{0}%"},ends_with:{op:"LIKE(?)",mod:"%{0}"},not_ends_with:{op:"NOT LIKE(?)",mod:"%{0}"},is_empty:{op:"= ''"},is_not_empty:{op:"!= ''"},is_null:{op:"IS NULL"},is_not_null:{op:"IS NOT NULL"}},sqlRuleOperator:{"=":function(a){return{val:a,op:""===a?"is_empty":"equal"}},"!=":function(a){return{val:a,op:""===a?"is_not_empty":"not_equal"}},LIKE:function(a){return"%"==a.slice(0,1)&&"%"==a.slice(-1)?{val:a.slice(1,-1),op:"contains"}:"%"==a.slice(0,1)?{val:a.slice(1),op:"ends_with"}:"%"==a.slice(-1)?{val:a.slice(0,-1),op:"begins_with"}:void g.error("SQLParse",'Invalid value for LIKE operator "{0}"',a)},"NOT LIKE":function(a){return"%"==a.slice(0,1)&&"%"==a.slice(-1)?{val:a.slice(1,-1),op:"not_contains"}:"%"==a.slice(0,1)?{val:a.slice(1),op:"not_ends_with"}:"%"==a.slice(-1)?{val:a.slice(0,-1),op:"not_begins_with"}:void g.error("SQLParse",'Invalid value for NOT LIKE operator "{0}"',a)},IN:function(a){return{val:a,op:"in"}},"NOT IN":function(a){return{val:a,op:"not_in"}},"<":function(a){return{val:a,op:"less"}},"<=":function(a){return{val:a,op:"less_or_equal"}},">":function(a){return{val:a,op:"greater"}},">=":function(a){return{val:a,op:"greater_or_equal"}},BETWEEN:function(a){return{val:a,op:"between"}},"NOT BETWEEN":function(a){return{val:a,op:"not_between"}},IS:function(a){return null!==a&&g.error("SQLParse","Invalid value for IS operator"),{val:null,op:"is_null"}},"IS NOT":function(a){return null!==a&&g.error("SQLParse","Invalid value for IS operator"),{val:null,op:"is_not_null"}}},sqlStatements:{question_mark:function(){var a=[];return{add:function(b,c){return a.push(c),"?"},run:function(){return a}}},numbered:function(a){(!a||a.length>1)&&(a="$");var b=0,c=[];return{add:function(d,e){return c.push(e),b++,a+b},run:function(){return c}}},named:function(a){(!a||a.length>1)&&(a=":");var b={},c={};return{add:function(d,e){b[d.field]||(b[d.field]=1);var f=d.field+"_"+b[d.field]++;return c[f]=e,a+f},run:function(){return c}}}},sqlRuleStatement:{question_mark:function(a){var b=0;return{parse:function(c){return"?"==c?a[b++]:c},esc:function(a){return a.replace(/\?/g,"'?'")}}},numbered:function(a,b){(!b||b.length>1)&&(b="$");var c=new RegExp("^\\"+b+"[0-9]+$"),d=new RegExp("\\"+b+"([0-9]+)","g");return{parse:function(b){return c.test(b)?a[b.slice(1)-1]:b},esc:function(a){return a.replace(d,"'"+("$"==b?"$$":b)+"$1'")}}},named:function(a,b){(!b||b.length>1)&&(b=":");var c=new RegExp("^\\"+b),d=new RegExp("\\"+b+"("+Object.keys(a).join("|")+")","g");return{parse:function(b){return c.test(b)?a[b.slice(1)]:b},esc:function(a){return a.replace(d,"'"+("$"==b?"$$":b)+"$1'")}}}}}),f.extend({getSQL:function(a,b,c){if(c=void 0===c?this.getRules():c,!c)return null;b=b?"\n":" ";this.getPluginOptions("sql-support","boolean_as_integer");if(a===!0&&(a="question_mark"),"string"==typeof a){var d=e(a);a=this.settings.sqlStatements[d[1]](d[2])}var f=this,h=function i(c){if(c.condition||(c.condition=f.settings.default_condition),["AND","OR"].indexOf(c.condition.toUpperCase())===-1&&g.error("UndefinedSQLCondition",'Unable to build SQL query with condition "{0}"',c.condition),!c.rules)return"";var d=[];c.rules.forEach(function(c){if(c.rules&&c.rules.length>0)d.push("("+b+i(c)+b+")"+b);else{var e=f.settings.sqlOperators[c.operator],h=f.getOperatorByType(c.operator),j="";void 0===e&&g.error("UndefinedSQLOperator",'Unknown SQL operation for operator "{0}"',c.operator);var k;"function"==typeof e.sqlFn?k=function(a){return e.sqlFn(c.value)}:(0!==h.nb_inputs&&(c.value instanceof Array||(c.value=[c.value]),c.value.forEach(function(b,d){d>0&&(j+=e.sep),"integer"==c.type||"double"==c.type||"boolean"==c.type?b=g.changeType(b,c.type,!0):a||"datetime"==c.type||(b=g.escapeString(b)),e.mod&&(b=g.fmt(e.mod,b)),a?j+=a.add(c,b):(e.ic||c.data.ignore_case===!0?e.sep?"string"==typeof b?b=b.split(",").map(function(a){return"'"+a.trim().toLowerCase()+"'"}):Array.isArray(b)&&(b=b.map(function(a){return a.toString().trim().toLowerCase()})):"string"==typeof b&&(b=b.toLowerCase(),b="'"+b+"'"):e.sep?"datetime"!=c.type?"string"==typeof b?b=b.split(",").map(function(a){return"'"+a.trim()+"'"}):Array.isArray(b)&&(b=b.map(function(a){return a.toString().trim()})):b.indexOf("SYSDATE")>-1?"string"==typeof b?b="("+b.trim()+")":Array.isArray(b)&&(b=b.map(function(a){return a.toString().trim()})):"string"==typeof b?b=b.split(",").map(function(a){return"TO_TIMESTAMP('"+a+"', 'YYYY-MM-DD HH24:MI:SS')"}):Array.isArray(b)&&(b=b.map(function(a){return"TO_TIMESTAMP('"+a.toString().trim()+"', 'YYYY-MM-DD HH24:MI:SS')"})):"datetime"==c.type?b.indexOf("SYSDATE")>-1?"string"==typeof b&&(b="("+b.trim()+")"):"string"==typeof b&&(b="TO_TIMESTAMP('"+b+"', 'YYYY-MM-DD HH24:MI:SS')"):"string"==typeof b&&(b="'"+b+"'"),j+=b)})),k=function(a){return e.op.replace("?",function(){return a})});var l=f.change("getSQLField",c.field,c);(e.ic||c.data.ignore_case===!0)&&(l="LOWER("+l+")");var m;m="function"==typeof e.sqlFullFn?e.sqlFullFn(l,j,c.value):l+" "+k(j),d.push(f.change("ruleToSQL",m,c,j,k))}});var e=d.join(" "+c.condition+b);return f.change("groupToSQL",e,c)}(c);return a?{sql:h,params:a.run()}:{sql:h}},getRulesFromSQL:function(b,c){"SQLParser"in window||g.error("MissingLibrary","SQLParser is required to parse SQL queries. Get it here https://github.com/mistic100/sql-parser");var d=this;if("string"==typeof b&&(b={sql:b}),c===!0&&(c="question_mark"),"string"==typeof c){var f=e(c);c=this.settings.sqlRuleStatement[f[1]](b.params,f[2])}c&&(b.sql=c.esc(b.sql)),0!==b.sql.toUpperCase().indexOf("SELECT")&&(b.sql="SELECT * FROM table WHERE "+b.sql);var h=SQLParser.parse(b.sql);h.where||g.error("SQLParse","No WHERE clause found");var i=d.change("parseSQLNode",h.where.conditions);if("rules"in i&&"condition"in i)return i;if("id"in i&&"operator"in i&&"value"in i)return{condition:this.settings.default_condition,rules:[i]};var j=d.change("sqlToGroup",{condition:this.settings.default_condition,rules:[]},i),k=j;return function l(b,e){if(null!==b){if(b=d.change("parseSQLNode",b),"rules"in b&&"condition"in b)return void k.rules.push(b);if("id"in b&&"operator"in b&&"value"in b)return void k.rules.push(b);if("left"in b&&"right"in b&&"operation"in b||g.error("SQLParse","Unable to parse WHERE clause"),["AND","OR"].indexOf(b.operation.toUpperCase())!==-1){var f=d.change("sqlGroupsDistinct",e>0&&k.condition!=b.operation.toUpperCase(),k,b,e);if(f){var h=d.change("sqlToGroup",{condition:d.settings.default_condition,rules:[]},b);k.rules.push(h),k=h}k.condition=b.operation.toUpperCase(),e++;var i=k;l(b.left,e),k=i,l(b.right,e)}else{a.isPlainObject(b.right.value)&&g.error("SQLParse","Value format not supported for {0}.",b.left.value);var j;j=a.isArray(b.right.value)?b.right.value.map(function(a){return a.value}):b.right.value,c&&(j=a.isArray(j)?j.map(c.parse):c.parse(j));var m=b.operation.toUpperCase();"<>"==m&&(m="!=");var n=d.settings.sqlRuleOperator[m];void 0===n&&g.error("UndefinedSQLOperator",'Invalid SQL operation "{0}".',b.operation);var o,p=n.call(this,j,b.operation);"values"in b.left?o=b.left.values.join("."):"value"in b.left?o=b.left.value:g.error("SQLParse","Cannot find field name in {0}",JSON.stringify(b.left));var q=d.getSQLFieldID(o,j),r=d.change("sqlToRule",{id:q,field:o,operator:p.op,value:p.val},b);k.rules.push(r)}}}(i,0),j},setRulesFromSQL:function(a,b){this.setRules(this.getRulesFromSQL(a,b))},getSQLFieldID:function(a,b){var c,d=this.filters.filter(function(b){return b.field.toLowerCase()===a.toLowerCase()});return c=1===d.length?d[0].id:this.change("getSQLFieldID",a,b)}}),f.define("unique-filter",function(){this.status.used_filters={},this.on("afterUpdateRuleFilter",this.updateDisabledFilters),this.on("afterDeleteRule",this.updateDisabledFilters),this.on("afterCreateRuleFilters",this.applyDisabledFilters),this.on("afterReset",this.clearDisabledFilters),this.on("afterClear",this.clearDisabledFilters),this.on("getDefaultFilter.filter",function(a,b){var c=a.builder;if(c.updateDisabledFilters(),a.value.id in c.status.used_filters){var d=c.filters.some(function(d){if(!(d.id in c.status.used_filters)||c.status.used_filters[d.id].length>0&&c.status.used_filters[d.id].indexOf(b.parent)===-1)return a.value=d,!0});d||(g.error(!1,"UniqueFilter","No more non-unique filters available"),a.value=void 0)}})}),f.extend({updateDisabledFilters:function(a){var b=a?a.builder:this;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))},clearDisabledFilters:function(a){var b=a?a.builder:this;b.status.used_filters={},b.applyDisabledFilters(a)},applyDisabledFilters:function(b){var c=b?b.builder:this;c.$el.find(f.selectors.filter_container+" option").prop("disabled",!1),a.each(c.status.used_filters,function(a,b){0===b.length?c.$el.find(f.selectors.filter_container+' option[value="'+a+'"]:not(:selected)').prop("disabled",!0):b.forEach(function(b){b.each(function(b){b.$el.find(f.selectors.filter_container+' option[value="'+a+'"]:not(:selected)').prop("disabled",!0)})})}),c.settings.plugins&&c.settings.plugins["bt-selectpicker"]&&c.$el.find(f.selectors.rule_filter).selectpicker("render")}}),f.regional.en={__locale:"English (en)",__author:'Damien "Mistic" Sorel, http://www.strangeplanet.fr',add_rule:"Add rule",add_group:"Add group",delete_rule:"Delete",delete_group:"Delete",add_rule_title:"Add rule",add_group_title:"Add group",delete_rule_title:"Delete rule",delete_group_title:"Delete group",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",not_between:"not 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}",number_between_invalid:"Invalid values, {0} is greater than {1}",datetime_empty:"Empty value",datetime_invalid:"Invalid date format ({0})",datetime_exceed_min:"Must be after {0}",datetime_exceed_max:"Must be before {0}",datetime_between_invalid:"Invalid values, {0} is greater than {1}",boolean_not_valid:"Not a boolean",operator_not_multiple:'Operator "{1}" cannot accept multiple values'},invert:"Invert",NOT:"NOT"},f.defaults({lang_code:"en"}),f});