Cloudlog/assets/js/query-builder.min.js

7 wiersze
71 KiB
JavaScript

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