',g.templates.rule=' {{? it.settings.display_errors }}
{{?}} ',g.templates.filterSelect='{{ var optgroup = null; }} ',g.templates.operatorSelect='{{? it.operators.length === 1 }} {{= it.translate("operators", it.operators[0].type) }} {{?}} {{ var optgroup = null; }} ',g.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)},g.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)},g.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)},g.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)},g.prototype.getRuleInput=function(a,b){var c=a.filter,d=a.filter.validation||{},e=a.id+"_value_"+b,f=c.vertical?" class=block":"",g="";if("function"==typeof c.input)g=c.input.call(this,a,e);else switch(c.input){case"radio":case"checkbox":k.iterateOptions(c.values,function(a,b){g+=" "});break;case"select":g+='";break;case"textarea":g+='";break;case"number":g+='";break;default:g+='"}return this.change("getRuleInput",g,a,e)},$.extend(b.prototype,{trigger:function(a){var b=new $.Event(a);return this.$.triggerHandler(b,Array.prototype.slice.call(arguments,1)),b},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}}),b.defineModelProperties=function(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)}})})};var h=function(a,b){if(!(this instanceof h))return new h(a,b);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,this.parent=a};b.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){if(!(this instanceof i))return new i(a,b);h.call(this,a,b),this.rules=[],this.__.condition=null};i.prototype=Object.create(h.prototype),i.prototype.constructor=i,b.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=!1;function(){return a?e>=f:e<=f}()&&(this.rules[e]instanceof i?c&&(h=c.call(d,this.rules[e])===!1):b&&(h=b.call(d,this.rules[e])===!1),!h);e+=g);return!h},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){if(!(this instanceof j))return new j(a,b);h.call(this,a,b),this._updating_value=!1,this._updating_input=!1,this.__.filter=null,this.__.operator=null,this.__.value=void 0};j.prototype=Object.create(h.prototype),j.prototype.constructor=j,b.defineModelProperties(j,["filter","operator","value"]),j.prototype.isRoot=function(){return!1},g.Group=i,g.Rule=j;var k={};g.utils=k,k.iterateOptions=function(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)}))},k.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)]})},k.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(k.fmt(d,e));throw f.name=c+"Error",f.args=e,f}console.error(c+"Error: "+k.fmt(d,e))},k.changeType=function(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}},k.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";default:return"\\"+a}}).replace(/\t/g,"\\t").replace(/\x1a/g,"\\Z")},k.escapeRegExp=function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},k.escapeElementId=function(a){return a?a.replace(/(\\)?([:.\[\],])/g,function(a,b,c){return b?a:"\\"+c}):a},k.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},$.fn.queryBuilder=function(a){0===this.length&&k.error("Config","No target defined"),this.length>1&&k.error("Config","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 g(this,c)),"string"==typeof a?b[a].apply(b,Array.prototype.slice.call(arguments,1)):this):this},$.fn.queryBuilder.constructor=g,$.fn.queryBuilder.defaults=g.defaults,$.fn.queryBuilder.extend=g.extend,$.fn.queryBuilder.define=g.define,$.fn.queryBuilder.regional=g.regional,g.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"':"",g=0;k.iterateOptions(e.values,function(c,h){var i=e.colors[c]||e.colors._def_||a.color,j=d+"_"+g++;b.value+="
"})}})},{font:"glyphicons",color:"default"}),g.define("bt-selectpicker",function(a){$.fn.selectpicker&&$.fn.selectpicker.Constructor||k.error("MissingLibrary",'Bootstrap Select is required to use "bt-selectpicker" plugin. Get it here: http://silviomoreto.github.io/bootstrap-select');var b=g.selectors;this.on("afterCreateRuleFilters",function(c,d){d.$el.find(b.rule_filter).removeClass("form-control").selectpicker(a)}),this.on("afterCreateRuleOperators",function(c,d){d.$el.find(b.rule_operator).removeClass("form-control").selectpicker(a)}),this.on("afterUpdateRuleFilter",function(a,c){c.$el.find(b.rule_filter).selectpicker("render")}),this.on("afterUpdateRuleOperator",function(a,c){c.$el.find(b.rule_operator).selectpicker("render")}),this.on("beforeDeleteRule",function(a,c){c.$el.find(b.rule_filter).selectpicker("destroy"),c.$el.find(b.rule_operator).selectpicker("destroy")})},{container:"body",style:"btn-inverse btn-xs",width:"auto",showIcon:!1}),g.define("bt-tooltip-errors",function(a){$.fn.tooltip&&$.fn.tooltip.Constructor&&$.fn.tooltip.Constructor.prototype.fixTitle||k.error("MissingLibrary",'Bootstrap Tooltip is required to use "bt-tooltip-errors" plugin. Get it here: http://getbootstrap.com');var b=this;this.on("getRuleTemplate.filter getGroupTemplate.filter",function(a){var b=$(a.value);b.find(g.selectors.error_container).attr("data-toggle","tooltip"),a.value=b.prop("outerHTML")}),this.model.on("update",function(c,d,e){"error"==e&&b.settings.display_errors&&d.$el.find(g.selectors.error_container).eq(0).tooltip(a).tooltip("hide").tooltip("fixTitle")})},{placement:"right"}),g.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 a(b){b.each(function(a){a.filter&&d.indexOf(a.filter.id)===-1&&k.error("ChangeFilter",'A rule is using filter "{0}"',a.filter.id)},a)}(this.model.root),this.filters=b,function a(b){b.each(!0,function(a){a.filter&&d.indexOf(a.filter.id)===-1?a.drop():(c.createRuleFilters(a),a.$el.find(g.selectors.rule_filter).val(a.filter?a.filter.id:"-1"),c.trigger("afterUpdateRuleFilter",a))},a)}(this.model.root),this.settings.plugins&&(this.settings.plugins["unique-filter"]&&this.updateDisabledFilters(),this.settings.plugins["bt-selectpicker"]&&this.$el.find(g.selectors.rule_filter).selectpicker("render")),this.settings.default_filter)try{this.getFilterById(this.settings.default_filter)}catch(a){this.settings.default_filter=null}this.trigger("afterSetFilters",b)},addFilter:function(a,b){void 0===b||"#end"==b?b=this.filters.length:"#start"==b&&(b=0),$.isArray(a)||(a=[a]);var c=$.extend(!0,[],this.filters);parseInt(b)==b?Array.prototype.splice.apply(c,[b,0].concat(a)):this.filters.some(function(a,c){if(a.id==b)return b=c+1,!0})?Array.prototype.splice.apply(c,[b,0].concat(a)):Array.prototype.push.apply(c,a),this.setFilters(c)},removeFilter:function(a,b){var c=$.extend(!0,[],this.filters);"string"==typeof a&&(a=[a]),c=c.filter(function(b){return a.indexOf(b.id)===-1}),this.setFilters(b,c)}}),g.define("filter-description",function(a){"inline"===a.mode?this.on("afterUpdateRuleFilter afterUpdateRuleOperator",function(b,c){var d=c.$el.find("p.filter-description"),e=b.builder.getFilterDescription(c.filter,c);e?(0===d.length?(d=$(''),d.appendTo(c.$el)):d.show(),d.html(' '+e)):d.hide()}):"popover"===a.mode?($.fn.popover&&$.fn.popover.Constructor&&$.fn.popover.Constructor.prototype.fixTitle||k.error("MissingLibrary",'Bootstrap Popover is required to use "filter-description" plugin. Get it here: http://getbootstrap.com'),this.on("afterUpdateRuleFilter afterUpdateRuleOperator",function(b,c){var d=c.$el.find("button.filter-description"),e=b.builder.getFilterDescription(c.filter,c);e?(0===d.length?(d=$(''),d.prependTo(c.$el.find(g.selectors.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=e,d.attr("aria-describedby")&&d.popover("show")):(d.hide(),d.data("bs.popover")&&d.popover("hide"))})):"bootbox"===a.mode&&("bootbox"in window||k.error("MissingLibrary",'Bootbox is required to use "filter-description" plugin. Get it here: http://bootboxjs.com'),this.on("afterUpdateRuleFilter afterUpdateRuleOperator",function(b,c){var d=c.$el.find("button.filter-description"),e=b.builder.getFilterDescription(c.filter,c);e?(0===d.length&&(d=$(''),d.prependTo(c.$el.find(g.selectors.rule_actions)),d.on("click",function(){bootbox.alert(d.data("description"))})),d.data("description",e)):d.hide()}))},{icon:"glyphicon glyphicon-info-sign",mode:"popover"}),g.extend({getFilterDescription:function(a,b){return a?"function"==typeof a.description?a.description.call(this,b):a.description:void 0}}),g.define("invert",function(a){var b=this,c=g.selectors;this.on("afterInit",function(){b.$el.on("click.queryBuilder","[data-invert=group]",function(){var d=$(this).closest(c.group_container);b.invert(b.getModel(d),a)}),a.display_rules_button&&a.invert_rules&&b.$el.on("click.queryBuilder","[data-invert=rule]",function(){var d=$(this).closest(c.rule_container);b.invert(b.getModel(d),a)})}),this.on("getGroupTemplate.filter",function(d,e){var f=$(d.value);f.find(c.condition_container).after('"),d.value=f.prop("outerHTML")}),a.display_rules_button&&a.invert_rules&&this.on("getRuleTemplate.filter",function(d){var e=$(d.value);e.find(c.rule_actions).prepend('"),d.value=e.prop("outerHTML")})},{icon:"glyphicon glyphicon-random",recursive:!0,invert_rules:!0,display_rules_button:!1,silent_fail:!1}),g.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"}}),g.extend({invert:function(a,b){if(!(a instanceof h)){if(!this.model.root)return;b=a,a=this.model.root}if("object"!=typeof b&&(b={}),void 0===b.recursive&&(b.recursive=!0),void 0===b.invert_rules&&(b.invert_rules=!0),void 0===b.silent_fail&&(b.silent_fail=!1),void 0===b.trigger&&(b.trigger=!0),a instanceof i){if(this.settings.conditionOpposites[a.condition]?a.condition=this.settings.conditionOpposites[a.condition]:b.silent_fail||k.error("InvertCondition",'Unknown inverse of condition "{0}"',a.condition),b.recursive){var c=$.extend({},b,{trigger:!1});a.each(function(a){b.invert_rules&&this.invert(a,c)},function(a){this.invert(a,c)},this)}}else if(a instanceof j&&a.operator&&!a.filter.no_invert)if(this.settings.operatorOpposites[a.operator.type]){var d=this.settings.operatorOpposites[a.operator.type];a.filter.operators&&a.filter.operators.indexOf(d)==-1||(a.operator=this.getOperatorByType(d))}else b.silent_fail||k.error("InvertOperator",'Unknown inverse of operator "{0}"',a.operator.type);b.trigger&&this.trigger("afterInvert",a,b)}}),g.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:"^"+k.escapeRegExp(a[0])}},not_begins_with:function(a){return{$regex:"^(?!"+k.escapeRegExp(a[0])+")"}},contains:function(a){return{$regex:k.escapeRegExp(a[0])}},not_contains:function(a){return{$regex:"^((?!"+k.escapeRegExp(a[0])+").)*$",$options:"s"}},ends_with:function(a){return{$regex:k.escapeRegExp(a[0])+"$"}},not_ends_with:function(a){return{$regex:"(?0)d.push(a(c));else{var e=b.settings.mongoOperators[c.operator],f=b.getOperatorByType(c.operator),g=[];void 0===e&&k.error("UndefinedMongoOperator",'Unknown MongoDB operation for operator "{0}"',c.operator),0!==f.nb_inputs&&(c.value instanceof Array||(c.value=[c.value]),c.value.forEach(function(a){g.push(k.changeType(a,c.type,!1))}));var h=b.change("getMongoDBField",c.field,c),i={};i[h]=e.call(b,g),d.push(b.change("ruleToMongo",i,c,g,e))}});var e={};return e["$"+c.condition.toLowerCase()]=d,b.change("groupToMongo",e,c)}(a)},getRulesFromMongo:function(a){if(void 0===a||null===a)return null;var b=this;if("rules"in(a=b.change("parseMongoNode",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 e=d(a);return e||k.error("MongoParse","Invalid MongoDB query format"),function a(e,f){var g=e[f],h=[];return g.forEach(function(e){if("rules"in(e=b.change("parseMongoNode",e))&&"condition"in e)return void h.push(e);if("id"in e&&"operator"in e&&"value"in e)return void h.push(e);var f=d(e);if(f)h.push(a(e,f));else{var g=Object.keys(e)[0],i=e[g],j=c(i);void 0===j&&k.error("MongoParse","Invalid MongoDB query format");var l=b.settings.mongoRuleOperators[j];void 0===l&&k.error("UndefinedMongoOperator",'JSON Rule operation unknown for operator "{0}"',j);var m=l.call(b,i),n=b.change("getMongoDBFieldID",g,i),o=b.change("mongoToRule",{id:n,field:g,operator:m.op,value:m.val},e);h.push(o)}}),b.change("mongoToGroup",{condition:f.replace("$","").toUpperCase(),rules:h},e)}(a,e)},setRulesFromMongo:function(a){this.setRules(this.getRulesFromMongo(a))}}),g.define("not-group",function(a){var b=this;this.on("afterInit",function(){b.$el.on("click.queryBuilder","[data-not=group]",function(){var a=$(this).closest(g.selectors.group_container),c=b.getModel(a);c.not=!c.not}),b.model.on("update",function(a,c,d){c instanceof i&&"not"===d&&b.updateGroupNot(c)})}),this.on("afterAddGroup",function(a,b){b.__.not=!1}),this.on("getGroupTemplate.filter",function(c,d){var e=$(c.value);e.find(g.selectors.condition_container).prepend('"),c.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],a.value.not=!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"}),b.defineModelProperties(i,["not"]),g.selectors.group_not=g.selectors.group_header+" [data-not=group]",g.extend({updateGroupNot:function(a){var b=this.plugins["not-group"];a.$el.find(">"+g.selectors.group_not).toggleClass("active",a.not).find("i").attr("class",a.not?b.icon_checked:b.icon_unchecked),this.trigger("afterUpdateGroupNot",a)}}),g.define("sortable",function(a){"interact"in window||k.error("MissingLibrary",'interact.js is required to use "sortable" plugin. Get it here: http://interactjs.io'),void 0!==a.default_no_sortable&&(k.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=a.default_no_sortable),interact.dynamicDrop(!0),interact.pointerMoveTolerance(10);var b,c,d;this.on("afterAddRule afterAddGroup",function(f,h){if(h!=b){var j=f.builder;a.inherit_no_sortable&&h.parent&&h.parent.flags.no_sortable&&(h.flags.no_sortable=!0),a.inherit_no_drop&&h.parent&&h.parent.flags.no_drop&&(h.flags.no_drop=!0),h.flags.no_sortable||interact(h.$el[0]).allowFrom(g.selectors.drag_handle).draggable({onstart:function(a){d=j.getModel(a.target),c=d.$el.clone().appendTo(d.$el.parent()).width(d.$el.outerWidth()).addClass("dragging");var e=$('
').height(d.$el.outerHeight());b=d.parent.addRule(e,d.getPos()),d.$el.hide()},onmove:function(a){c[0].style.top=a.clientY-15+"px",c[0].style.left=a.clientX-15+"px"},onend:function(){c.remove(),c=void 0,b.drop(),b=void 0,d.$el.show(),j.trigger("afterMove",d)}}),h.flags.no_drop||(interact(h.$el[0]).dropzone({accept:g.selectors.rule_and_group_containers,ondragenter:function(a){e(b,$(a.target))},ondrop:function(a){e(d,$(a.target),j)}}),h instanceof i&&interact(h.$el.find(g.selectors.group_header)[0]).dropzone({accept:g.selectors.rule_and_group_containers,ondragenter:function(a){e(b,$(a.target))},ondrop:function(a){e(d,$(a.target),j)}}))}}),this.on("beforeDeleteRule beforeDeleteGroup",function(a,b){a.isDefaultPrevented()||(interact(b.$el[0]).unset(),b instanceof i&&interact(b.$el.find(g.selectors.group_header)[0]).unset())}),this.on("afterApplyRuleFlags afterApplyGroupFlags",function(a,b){b.flags.no_sortable&&b.$el.find(".drag-handle").remove()}),this.on("getGroupTemplate.filter",function(b,c){if(c>1){var d=$(b.value);d.find(g.selectors.condition_container).after('
'),b.value=d.prop("outerHTML")}}),this.on("getRuleTemplate.filter",function(b){var c=$(b.value);c.find(g.selectors.rule_header).after('
'),b.value=c.prop("outerHTML")})},{inherit_no_sortable:!0,inherit_no_drop:!0,icon:"glyphicon glyphicon-sort"}),g.selectors.rule_and_group_containers=g.selectors.rule_container+", "+g.selectors.group_container,g.selectors.drag_handle=".drag-handle",g.defaults({default_rule_flags:{no_sortable:!1,no_drop:!1},default_group_flags:{no_sortable:!1,no_drop:!1}}),g.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 k.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 k.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&&k.error("SQLParse","Invalid value for IS operator"),{val:null,op:"is_null"}},"IS NOT":function(a){return null!==a&&k.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'")}}}}}),g.extend({getSQL:function(a,b,c){if(c=void 0===c?this.getRules():c,b=b?"\n":" ",a===!0&&(a="question_mark"),"string"==typeof a){var d=f(a);a=this.settings.sqlStatements[d[1]](d[2])}var e=this,g=function c(d){if(d.condition||(d.condition=e.settings.default_condition),["AND","OR"].indexOf(d.condition.toUpperCase())===-1&&k.error("UndefinedSQLCondition",'Unable to build SQL query with condition "{0}"',d.condition),!d.rules)return"";var f=[];d.rules.forEach(function(d){if(d.rules&&d.rules.length>0)f.push("("+b+c(d)+b+")"+b);else{var g=e.settings.sqlOperators[d.operator],h=e.getOperatorByType(d.operator),i="";void 0===g&&k.error("UndefinedSQLOperator",'Unknown SQL operation for operator "{0}"',d.operator),0!==h.nb_inputs&&(d.value instanceof Array||(d.value=[d.value]),d.value.forEach(function(b,c){c>0&&(i+=g.sep),"integer"==d.type||"double"==d.type||"boolean"==d.type?b=k.changeType(b,d.type,!0):a||(b=k.escapeString(b)),g.mod&&(b=k.fmt(g.mod,b)),a?i+=a.add(d,b):("string"==typeof b&&(b="'"+b+"'"),i+=b)}));var j=function(a){return g.op.replace(/\?/,a)},l=e.change("getSQLField",d.field,d),m=l+" "+j(i);f.push(e.change("ruleToSQL",m,d,i,j))}});var g=f.join(" "+d.condition+b);return e.change("groupToSQL",g,d)}(c);return a?{sql:g,params:a.run()}:{sql:g}},getRulesFromSQL:function(a,b){"SQLParser"in window||k.error("MissingLibrary","SQLParser is required to parse SQL queries. Get it here https://github.com/mistic100/sql-parser");var c=this;if("string"==typeof a&&(a={sql:a}),b===!0&&(b="question_mark"),"string"==typeof b){var d=f(b);b=this.settings.sqlRuleStatement[d[1]](a.params,d[2])}b&&(a.sql=b.esc(a.sql)),0!==a.sql.toUpperCase().indexOf("SELECT")&&(a.sql="SELECT * FROM table WHERE "+a.sql);var e=SQLParser.parse(a.sql);e.where||k.error("SQLParse","No WHERE clause found");var g=c.change("parseSQLNode",e.where.conditions);if("rules"in g&&"condition"in g)return g;if("id"in g&&"operator"in g&&"value"in g)return{condition:this.settings.default_condition,rules:[g]};var h=c.change("sqlToGroup",{condition:this.settings.default_condition,rules:[]},g),i=h;return function a(d,e){if("rules"in(d=c.change("parseSQLNode",d))&&"condition"in d)return void i.rules.push(d);if("id"in d&&"operator"in d&&"value"in d)return void i.rules.push(d);if("left"in d&&"right"in d&&"operation"in d||k.error("SQLParse","Unable to parse WHERE clause"),["AND","OR"].indexOf(d.operation.toUpperCase())!==-1){if(e>0&&i.condition!=d.operation.toUpperCase()){var f=c.change("sqlToGroup",{condition:c.settings.default_condition,rules:[]},d);i.rules.push(f),i=f}i.condition=d.operation.toUpperCase(),e++;var g=i;a(d.left,e),i=g,a(d.right,e)}else{$.isPlainObject(d.right.value)&&k.error("SQLParse","Value format not supported for {0}.",d.left.value);var h;h=$.isArray(d.right.value)?d.right.value.map(function(a){return a.value}):d.right.value,b&&(h=$.isArray(h)?h.map(b.parse):b.parse(h));var j=d.operation.toUpperCase();"<>"==j&&(j="!=");var l=c.settings.sqlRuleOperator[j];void 0===l&&k.error("UndefinedSQLOperator",'Invalid SQL operation "{0}".',d.operation);var m,n=l.call(this,h,d.operation);"values"in d.left?m=d.left.values.join("."):"value"in d.left?m=d.left.value:k.error("SQLParse","Cannot find field name in {0}",JSON.stringify(d.left));var o=c.change("getSQLFieldID",m,h),p=c.change("sqlToRule",{id:o,field:m,operator:n.op,value:n.val},d);i.rules.push(p)}}(g,0),h},setRulesFromSQL:function(a,b){this.setRules(this.getRulesFromSQL(a,b))}}),g.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){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})||(k.error(!1,"UniqueFilter","No more non-unique filters available"),a.value=void 0)}})}),g.extend({updateDisabledFilters:function(a){var b=a?a.builder:this;b.status.used_filters={},b.model&&(!function a(c){c.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(b){a(b)})}(b.model.root),b.applyDisabledFilters(a))},clearDisabledFilters:function(a){var b=a?a.builder:this;b.status.used_filters={},b.applyDisabledFilters(a)},applyDisabledFilters:function(a){var b=a?a.builder:this;b.$el.find(g.selectors.filter_container+" option").prop("disabled",!1),$.each(b.status.used_filters,function(a,c){0===c.length?b.$el.find(g.selectors.filter_container+' option[value="'+a+'"]:not(:selected)').prop("disabled",!0):c.forEach(function(b){b.each(function(b){b.$el.find(g.selectors.filter_container+' option[value="'+a+'"]:not(:selected)').prop("disabled",!0)})})}),b.settings.plugins&&b.settings.plugins["bt-selectpicker"]&&b.$el.find(g.selectors.rule_filter).selectpicker("render")}}),g.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",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}",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 "{1}" cannot accept multiple values'},invert:"Invert",NOT:"NOT"},g.defaults({lang_code:"en"})});
\ No newline at end of file
diff --git a/dist/scss/dark.scss b/dist/scss/dark.scss
index 8b72dbf2..dcd1a6f5 100644
--- a/dist/scss/dark.scss
+++ b/dist/scss/dark.scss
@@ -1,9 +1,8 @@
/*!
- * jQuery QueryBuilder 2.4.1
+ * jQuery QueryBuilder 2.4.2
* Copyright 2014-2017 Damien "Mistic" Sorel (http://www.strangeplanet.fr)
* Licensed under MIT (http://opensource.org/licenses/MIT)
*/
-
$theme-name: dark;
$group-background-color: rgba(50, 70, 80, .5);
diff --git a/dist/scss/default.scss b/dist/scss/default.scss
index cd2f82ff..4dad1088 100644
--- a/dist/scss/default.scss
+++ b/dist/scss/default.scss
@@ -1,9 +1,8 @@
/*!
- * jQuery QueryBuilder 2.4.1
+ * jQuery QueryBuilder 2.4.2
* Copyright 2014-2017 Damien "Mistic" Sorel (http://www.strangeplanet.fr)
* Licensed under MIT (http://opensource.org/licenses/MIT)
*/
-
$theme-name: default !default;
// common
@@ -176,8 +175,10 @@ $ticks-position: 5px, 10px !default;
}
}
-
-@import 'plugins/bt-tooltip-errors';
-@import 'plugins/filter-description';
-@import 'plugins/invert';
-@import 'plugins/sortable';
\ No newline at end of file
+// import
+@import "plugins/_bt-checkbox";
+@import "plugins/_bt-tooltip-errors";
+@import "plugins/_filter-description";
+@import "plugins/_invert";
+@import "plugins/_sortable";
+// endimport
diff --git a/dist/scss/plugins/_bt-checkbox.scss b/dist/scss/plugins/_bt-checkbox.scss
new file mode 100644
index 00000000..9b259265
--- /dev/null
+++ b/dist/scss/plugins/_bt-checkbox.scss
@@ -0,0 +1,12 @@
+.query-builder.bt-checkbox-glyphicons {
+ .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;
+ }
+}
diff --git a/dist/scss/plugins/_bt-tooltip-errors.scss b/dist/scss/plugins/_bt-tooltip-errors.scss
new file mode 100644
index 00000000..21323e5f
--- /dev/null
+++ b/dist/scss/plugins/_bt-tooltip-errors.scss
@@ -0,0 +1,9 @@
+$error-tooltip-color: #F99;
+
+@if $theme-name == 'dark' {
+ $error-tooltip-color: #F22;
+}
+
+.query-builder .error-container + .tooltip .tooltip-inner {
+ color: $error-tooltip-color !important;
+}
diff --git a/dist/scss/plugins/_filter-description.scss b/dist/scss/plugins/_filter-description.scss
new file mode 100644
index 00000000..80a2af71
--- /dev/null
+++ b/dist/scss/plugins/_filter-description.scss
@@ -0,0 +1,21 @@
+$description-background-color: #D9EDF7;
+$description-border-color: #BCE8F1;
+$description-text-color: #31708F;
+
+@if $theme-name == 'dark' {
+ $description-background-color: rgba(0, 170, 255, .2);
+ $description-text-color: #AAD1E4;
+ $description-border-color: #346F7B;
+}
+
+$description-border: 1px solid $description-border-color;
+
+.query-builder p.filter-description {
+ margin: $rule-padding 0 0 0;
+ background: $description-background-color;
+ border: $description-border;
+ color: $description-text-color;
+ border-radius: $item-border-radius;
+ padding: #{$rule-padding / 2} $rule-padding;
+ font-size: .8em;
+}
diff --git a/dist/scss/plugins/_invert.scss b/dist/scss/plugins/_invert.scss
new file mode 100644
index 00000000..5eb0458b
--- /dev/null
+++ b/dist/scss/plugins/_invert.scss
@@ -0,0 +1,5 @@
+.query-builder {
+ .rules-group-header [data-invert] {
+ margin-left: 5px;
+ }
+}
diff --git a/dist/scss/plugins/_sortable.scss b/dist/scss/plugins/_sortable.scss
new file mode 100644
index 00000000..cf57c795
--- /dev/null
+++ b/dist/scss/plugins/_sortable.scss
@@ -0,0 +1,27 @@
+$placeholder-border-color: #BBB;
+$placeholder-border: 1px dashed $placeholder-border-color;
+
+.query-builder {
+ .drag-handle {
+ @extend %rule-component;
+ cursor: move;
+ vertical-align: middle;
+ margin-left: 5px;
+ }
+
+ .dragging {
+ position: fixed;
+ opacity: .5;
+ z-index: 100;
+
+ &::before, &::after {
+ display: none;
+ }
+ }
+
+ .rule-placeholder {
+ @extend %base-container;
+ border: $placeholder-border;
+ opacity: .7;
+ }
+}
diff --git a/examples/index.html b/examples/index.html
index 2f232ee6..6704b236 100644
--- a/examples/index.html
+++ b/examples/index.html
@@ -16,7 +16,9 @@
@@ -28,47 +30,55 @@
- jQuery QueryBuilder Example
+ jQuery QueryBuilder
+ Example
+
-
+
You must execute bower install
in the example directory to run this demo.
-
-
+
+
@@ -76,7 +86,9 @@ jQuery QueryBuilder Example
-
+
@@ -112,479 +124,528 @@
Output
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+