-
diff --git a/index.html b/index.html
index 8fa319f..a8a3967 100644
--- a/index.html
+++ b/index.html
@@ -12,6 +12,7 @@
+
@@ -37,6 +38,8 @@
+
+
diff --git a/js/main.js b/js/main.js
index 9307011..2279b3e 100755
--- a/js/main.js
+++ b/js/main.js
@@ -108,7 +108,7 @@
};
});
-require(["config", "events"], function(config, events) {
+require(["config", "events", "vendor/queryBuilder/query-builder.standalone-2.3.1.min"], function(config, events, queryBuilder) {
$(document).ready(function() {
$("#pager-prototype").contents().appendTo(".pager-placeholder");
@@ -220,4 +220,56 @@
}
});
});
+
+ $('#builder').queryBuilder({
+ plugins: ['bt-tooltip-errors'],
+
+ filters: [{
+ id: 'corpusName',
+ label: 'corpusName',
+ type: 'string',
+ input: 'select',
+ values: {
+ 1: 'elsevier',
+ 2: 'wiley',
+ 3: 'springer',
+ 4: 'oup',
+ 5: 'bmj',
+ 6: 'iop'
+ },
+ operators: ['equal', 'not_equal']
+ }, {
+ id: 'title',
+ label: 'title',
+ type: 'string',
+ input: 'text',
+ operators: ['equal', 'not_equal', 'contains', 'not_contains']
+ }, {
+ id: 'author',
+ label: 'author',
+ type: 'string',
+ input: 'text',
+ operators: ['equal', 'not_equal', 'contains', 'not_contains']
+ }, {
+ id: 'subject.value',
+ label: 'subject.value',
+ type: 'string',
+ input: 'text',
+ operators: ['equal', 'not_equal', 'contains', 'not_contains']
+ }],
+ lang_code: 'fr'
+ });
+
+ $('#btn-reset').on('click', function() {
+ $('#builder').queryBuilder('reset');
+ });
+
+ $('#btn-get').on('click', function() {
+ var result = $('#builder').queryBuilder('getRules');
+
+ if (!$.isEmptyObject(result)) {
+ alert(JSON.stringify(result, null, 2));
+ }
+ });
+
});
\ No newline at end of file
diff --git a/js/vendor/queryBuilder/query-builder.fr-2.3.1.js b/js/vendor/queryBuilder/query-builder.fr-2.3.1.js
new file mode 100644
index 0000000..89be8e1
--- /dev/null
+++ b/js/vendor/queryBuilder/query-builder.fr-2.3.1.js
@@ -0,0 +1,80 @@
+/*!
+ * jQuery QueryBuilder 2.3.1
+ * Locale: French (fr)
+ * Author: Damien "Mistic" Sorel, http://www.strangeplanet.fr
+ * Licensed under MIT (http://opensource.org/licenses/MIT)
+ */
+
+(function(root, factory) {
+ if (typeof define == 'function' && define.amd) {
+ define(['jquery', 'query-builder'], factory);
+ }
+ else {
+ factory(root.jQuery);
+ }
+}(this, function($) {
+"use strict";
+
+var QueryBuilder = $.fn.queryBuilder;
+
+QueryBuilder.regional['fr'] = {
+ "__locale": "French (fr)",
+ "__author": "Damien \"Mistic\" Sorel, http://www.strangeplanet.fr",
+ "add_rule": "Ajouter une règle",
+ "add_group": "Ajouter un groupe",
+ "delete_rule": "Supprimer",
+ "delete_group": "Supprimer",
+ "conditions": {
+ "AND": "ET",
+ "OR": "OU"
+ },
+ "operators": {
+ "equal": "égal",
+ "not_equal": "non égal",
+ "in": "dans",
+ "not_in": "pas dans",
+ "less": "inférieur",
+ "less_or_equal": "inférieur ou égal",
+ "greater": "supérieur",
+ "greater_or_equal": "supérieur ou égal",
+ "between": "est entre",
+ "not_between": "n'est pas entre",
+ "begins_with": "commence par",
+ "not_begins_with": "ne commence pas par",
+ "contains": "contient",
+ "not_contains": "ne contient pas",
+ "ends_with": "finit par",
+ "not_ends_with": "ne finit pas par",
+ "is_empty": "est vide",
+ "is_not_empty": "n'est pas vide",
+ "is_null": "est nul",
+ "is_not_null": "n'est pas nul"
+ },
+ "errors": {
+ "no_filter": "Aucun filtre sélectionné",
+ "empty_group": "Le groupe est vide",
+ "radio_empty": "Pas de valeur selectionnée",
+ "checkbox_empty": "Pas de valeur selectionnée",
+ "select_empty": "Pas de valeur selectionnée",
+ "string_empty": "Valeur vide",
+ "string_exceed_min_length": "Doit contenir au moins {0} caractères",
+ "string_exceed_max_length": "Ne doit pas contenir plus de {0} caractères",
+ "string_invalid_format": "Format invalide ({0})",
+ "number_nan": "N'est pas un nombre",
+ "number_not_integer": "N'est pas un entier",
+ "number_not_double": "N'est pas un nombre réel",
+ "number_exceed_min": "Doit être plus grand que {0}",
+ "number_exceed_max": "Doit être plus petit que {0}",
+ "number_wrong_step": "Doit être un multiple de {0}",
+ "datetime_empty": "Valeur vide",
+ "datetime_invalid": "Fomat de date invalide ({0})",
+ "datetime_exceed_min": "Doit être après {0}",
+ "datetime_exceed_max": "Doit être avant {0}",
+ "boolean_not_valid": "N'est pas un booléen",
+ "operator_not_multiple": "L'opérateur {0} ne peut utiliser plusieurs valeurs"
+ },
+ "invert": "Inverser"
+};
+
+QueryBuilder.defaults({ lang_code: 'fr' });
+}));
\ No newline at end of file
diff --git a/js/vendor/queryBuilder/query-builder.standalone-2.3.1.min.js b/js/vendor/queryBuilder/query-builder.standalone-2.3.1.min.js
new file mode 100644
index 0000000..41755b7
--- /dev/null
+++ b/js/vendor/queryBuilder/query-builder.standalone-2.3.1.min.js
@@ -0,0 +1,8 @@
+/*!
+ * jQuery QueryBuilder 2.3.1
+ * Copyright 2014-2016 Damien "Mistic" Sorel (http://www.strangeplanet.fr)
+ * Licensed under MIT (http://opensource.org/licenses/MIT)
+ */
+
+!function(a,b){"function"==typeof define&&define.amd?define("jQuery.extendext",["jquery"],b):b(a.jQuery)}(this,function($){"use strict";$.extendext=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1,k="default";for("boolean"==typeof g&&(j=g,g=arguments[h++]||{}),"string"==typeof g&&(k=$([g.toLowerCase(),"default"]).filter(["default","concat","replace","extend"])[0],g=arguments[h++]||{}),"object"==typeof g||$.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!==(a=arguments[h]))if($.isArray(a)&&"default"!==k)switch(f=g&&$.isArray(g)?g:[],k){case"concat":g=f.concat($.extend(j,[],a));break;case"replace":g=$.extend(j,[],a);break;case"extend":a.forEach(function(a,b){if("object"==typeof a){var c=$.isArray(a)?[]:{};f[b]=$.extendext(j,k,f[b]||c,a)}else-1===f.indexOf(a)&&f.push(a)}),g=f}else for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&($.isPlainObject(d)||(e=$.isArray(d)))?(e?(e=!1,f=c&&$.isArray(c)?c:[]):f=c&&$.isPlainObject(c)?c:{},g[b]=$.extendext(j,k,f,d)):void 0!==d&&(g[b]=d));return g}}),function(){"use strict";function a(b,c,d){return("string"==typeof c?c:c.toString()).replace(b.define||f,function(a,c,e,f){return 0===c.indexOf("def.")&&(c=c.substring(4)),c in d||(":"===e?(b.defineParams&&f.replace(b.defineParams,function(a,b,e){d[c]={arg:b,text:e}}),c in d||(d[c]=f)):new Function("def","def['"+c+"']="+f)(d)),""}).replace(b.use||f,function(c,e){b.useParams&&(e=e.replace(b.useParams,function(a,b,c,e){if(d[c]&&d[c].arg&&e){var f=(c+":"+e).replace(/'|\\/g,"_");return d.__exp=d.__exp||{},d.__exp[f]=d[c].text.replace(new RegExp("(^|[^\\w$])"+d[c].arg+"([^\\w$])","g"),"$1"+e+"$2"),b+"def.__exp['"+f+"']"}}));var f=new Function("def","return "+e)(d);return f?a(b,f,d):f})}function b(a){return a.replace(/\\('|\\)/g,"$1").replace(/[\r\t\n]/g," ")}var c,d={version:"1.0.3",templateSettings:{evaluate:/\{\{([\s\S]+?(\}?)+)\}\}/g,interpolate:/\{\{=([\s\S]+?)\}\}/g,encode:/\{\{!([\s\S]+?)\}\}/g,use:/\{\{#([\s\S]+?)\}\}/g,useParams:/(^|[^\w$])def(?:\.|\[[\'\"])([\w$\.]+)(?:[\'\"]\])?\s*\:\s*([\w$\.]+|\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})/g,define:/\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,defineParams:/^\s*([\w$]+):([\s\S]+)/,conditional:/\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g,iterate:/\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g,varname:"it",strip:!0,append:!0,selfcontained:!1,doNotSkipEncoded:!1},template:void 0,compile:void 0};d.encodeHTMLSource=function(a){var b={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},c=a?/[&<>"'\/]/g:/&(?!#?\w+;)|<|>|"|'|\//g;return function(a){return a?a.toString().replace(c,function(a){return b[a]||a}):""}},c=function(){return this||(0,eval)("this")}(),"undefined"!=typeof module&&module.exports?module.exports=d:"function"==typeof define&&define.amd?define("doT",function(){return d}):c.doT=d;var e={append:{start:"'+(",end:")+'",startencode:"'+encodeHTML("},split:{start:"';out+=(",end:");out+='",startencode:"';out+=encodeHTML("}},f=/$^/;d.template=function(g,h,i){h=h||d.templateSettings;var j,k,l=h.append?e.append:e.split,m=0,n=h.use||h.define?a(h,g,i||{}):g;n=("var out='"+(h.strip?n.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g," ").replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g,""):n).replace(/'|\\/g,"\\$&").replace(h.interpolate||f,function(a,c){return l.start+b(c)+l.end}).replace(h.encode||f,function(a,c){return j=!0,l.startencode+b(c)+l.end}).replace(h.conditional||f,function(a,c,d){return c?d?"';}else if("+b(d)+"){out+='":"';}else{out+='":d?"';if("+b(d)+"){out+='":"';}out+='"}).replace(h.iterate||f,function(a,c,d,e){return c?(m+=1,k=e||"i"+m,c=b(c),"';var arr"+m+"="+c+";if(arr"+m+"){var "+d+","+k+"=-1,l"+m+"=arr"+m+".length-1;while("+k+"
.rules-list",group_condition:".rules-group-header [name$=_cond]",rule_filter:".rule-filter-container [name$=_filter]",rule_operator:".rule-operator-container [name$=_operator]",rule_value:".rule-value-container [name*=_value_]",add_rule:"[data-add=rule]",delete_rule:"[data-delete=rule]",add_group:"[data-add=group]",delete_group:"[data-delete=group]"};f.templates={},f.regional={},f.OPERATORS={equal:{type:"equal",nb_inputs:1,multiple:!1,apply_to:["string","number","datetime","boolean"]},not_equal:{type:"not_equal",nb_inputs:1,multiple:!1,apply_to:["string","number","datetime","boolean"]},"in":{type:"in",nb_inputs:1,multiple:!0,apply_to:["string","number","datetime"]},not_in:{type:"not_in",nb_inputs:1,multiple:!0,apply_to:["string","number","datetime"]},less:{type:"less",nb_inputs:1,multiple:!1,apply_to:["number","datetime"]},less_or_equal:{type:"less_or_equal",nb_inputs:1,multiple:!1,apply_to:["number","datetime"]},greater:{type:"greater",nb_inputs:1,multiple:!1,apply_to:["number","datetime"]},greater_or_equal:{type:"greater_or_equal",nb_inputs:1,multiple:!1,apply_to:["number","datetime"]},between:{type:"between",nb_inputs:2,multiple:!1,apply_to:["number","datetime"]},not_between:{type:"not_between",nb_inputs:2,multiple:!1,apply_to:["number","datetime"]},begins_with:{type:"begins_with",nb_inputs:1,multiple:!1,apply_to:["string"]},not_begins_with:{type:"not_begins_with",nb_inputs:1,multiple:!1,apply_to:["string"]},contains:{type:"contains",nb_inputs:1,multiple:!1,apply_to:["string"]},not_contains:{type:"not_contains",nb_inputs:1,multiple:!1,apply_to:["string"]},ends_with:{type:"ends_with",nb_inputs:1,multiple:!1,apply_to:["string"]},not_ends_with:{type:"not_ends_with",nb_inputs:1,multiple:!1,apply_to:["string"]},is_empty:{type:"is_empty",nb_inputs:0,multiple:!1,apply_to:["string"]},is_not_empty:{type:"is_not_empty",nb_inputs:0,multiple:!1,apply_to:["string"]},is_null:{type:"is_null",nb_inputs:0,multiple:!1,apply_to:["string","number","datetime","boolean"]},is_not_null:{type:"is_not_null",nb_inputs:0,multiple:!1,apply_to:["string","number","datetime","boolean"]}},f.DEFAULTS={filters:[],plugins:[],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_delete:!1},templates:{group:null,rule:null,filterSelect:null,operatorSelect:null},lang_code:"en",lang:{},operators:["equal","not_equal","in","not_in","less","less_or_equal","greater","greater_or_equal","between","not_between","begins_with","not_begins_with","contains","not_contains","ends_with","not_ends_with","is_empty","is_not_empty","is_null","is_not_null"],icons:{add_group:"glyphicon glyphicon-plus-sign",add_rule:"glyphicon glyphicon-plus",remove_group:"glyphicon glyphicon-remove",remove_rule:"glyphicon glyphicon-remove",error:"glyphicon glyphicon-warning-sign"}},f.prototype.init=function(c,d){c[0].queryBuilder=this,this.$el=c,this.settings=$.extendext(!0,"replace",{},f.DEFAULTS,d),this.model=new b,this.status={group_id:0,rule_id:0,generated_id:!1,has_optgroup:!1,has_operator_oprgroup:!1,id:null,updating_value:!1},this.settings.allow_groups===!1?this.settings.allow_groups=0:this.settings.allow_groups===!0&&(this.settings.allow_groups=-1),this.filters=this.settings.filters,this.icons=this.settings.icons,this.operators=this.settings.operators,this.templates=this.settings.templates,this.plugins=this.settings.plugins,void 0===f.regional.en&&k.error("Config",'"i18n/en.js" not loaded.'),this.lang=$.extendext(!0,"replace",{},f.regional.en,f.regional[this.settings.lang_code],this.settings.lang),Object.keys(this.templates).forEach(function(b){this.templates[b]||(this.templates[b]=f.templates[b]),"string"==typeof this.templates[b]&&(this.templates[b]=a.template(this.templates[b]))},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(),this.trigger("afterInit"),d.rules?(this.setRules(d.rules),delete this.settings.rules):this.setRoot(!0)},f.prototype.checkFilters=function(a){var b=[];return a&&0!==a.length||k.error("Config","Missing filters list"),a.forEach(function(a,c){switch(a.id||k.error("Config","Missing filter {0} id",c),-1!=b.indexOf(a.id)&&k.error("Config",'Filter "{0}" already defined',a.id),b.push(a.id),a.type?f.types[a.type]||k.error("Config",'Invalid type "{0}"',a.type):a.type="string",a.input?"function"!=typeof a.input&&-1==f.inputs.indexOf(a.input)&&k.error("Config",'Invalid input "{0}"',a.input):a.input="text",a.field||(a.field=a.id),a.label||(a.label=a.field),a.optgroup?(this.status.has_optgroup=!0,this.settings.optgroups[a.optgroup]||(this.settings.optgroups[a.optgroup]=a.optgroup)):a.optgroup=null,a.input){case"radio":case"checkbox":(!a.values||a.values.length<1)&&k.error("Config",'Missing filter "{0}" values',a.id);break;case"select":a.placeholder&&(void 0===a.placeholder_value&&(a.placeholder_value=-1),k.iterateOptions(a.values,function(b){b==a.placeholder_value&&k.error("Config",'Placeholder of filter "{0}" overlaps with one of its values',a.id)}))}},this),this.status.has_optgroup&&(a=k.groupSort(a,"optgroup")),a},f.prototype.checkOperators=function(a){var b=[];return a.forEach(function(c,d){"string"==typeof c?(f.OPERATORS[c]||k.error("Config",'Unknown operator "{0}"',c),a[d]=c=$.extendext(!0,"replace",{},f.OPERATORS[c])):(c.type||k.error("Config",'Missing "type" for operator {0}',d),f.OPERATORS[c.type]&&(a[d]=c=$.extendext(!0,"replace",{},f.OPERATORS[c.type],c)),(void 0===c.nb_inputs||void 0===c.apply_to)&&k.error("Config",'Missing "nb_inputs" and/or "apply_to" for operator "{0}"',c.type)),-1!=b.indexOf(c.type)&&k.error("Config",'Operator "{0}" already defined',c.type),b.push(c.type),c.optgroup?(this.status.has_operator_optgroup=!0,this.settings.optgroups[c.optgroup]||(this.settings.optgroups[c.optgroup]=c.optgroup)):c.optgroup=null},this),this.status.has_operator_optgroup&&(a=k.groupSort(a,"optgroup")),a},f.prototype.bindEvents=function(){var a=this;this.$el.on("change.queryBuilder",g.group_condition,function(){if($(this).is(":checked")){var a=$(this).closest(g.group_container);b(a).condition=$(this).val()}}),this.$el.on("change.queryBuilder",g.rule_filter,function(){var c=$(this).closest(g.rule_container);b(c).filter=a.getFilterById($(this).val())}),this.$el.on("change.queryBuilder",g.rule_operator,function(){var c=$(this).closest(g.rule_container);b(c).operator=a.getOperatorByType($(this).val())}),this.$el.on("click.queryBuilder",g.add_rule,function(){var c=$(this).closest(g.group_container);a.addRule(b(c))}),this.$el.on("click.queryBuilder",g.delete_rule,function(){var c=$(this).closest(g.rule_container);a.deleteRule(b(c))}),0!==this.settings.allow_groups&&(this.$el.on("click.queryBuilder",g.add_group,function(){var c=$(this).closest(g.group_container);a.addGroup(b(c))}),this.$el.on("click.queryBuilder",g.delete_group,function(){var c=$(this).closest(g.group_container);a.deleteGroup(b(c))})),this.model.on({drop:function(a,b){b.$el.remove()},add:function(a,b,c){0===c?b.$el.prependTo(b.parent.$el.find(">"+g.rules_list)):b.$el.insertAfter(b.parent.rules[c-1].$el)},move:function(a,b,c,d){b.$el.detach(),0===d?b.$el.prependTo(c.$el.find(">"+g.rules_list)):b.$el.insertAfter(c.rules[d-1].$el)},update:function(b,c,d,e,f){if(c instanceof j)switch(d){case"error":a.displayError(c);break;case"flags":a.applyRuleFlags(c);break;case"filter":a.updateRuleFilter(c);break;case"operator":a.updateRuleOperator(c,f);break;case"value":a.updateRuleValue(c)}else switch(d){case"error":a.displayError(c);break;case"flags":a.applyGroupFlags(c);break;case"condition":a.updateGroupCondition(c)}}})},f.prototype.setRoot=function(a,b){a=void 0===a||a===!0;var c=this.nextGroupId(),d=$(this.getGroupTemplate(c,1));return this.$el.append(d),this.model.root=new i(null,d),this.model.root.model=this.model,this.model.root.condition=this.settings.default_condition,void 0!==b&&(this.model.root.data=b),a&&this.addRule(this.model.root),this.model.root},f.prototype.addGroup=function(a,b,c){b=void 0===b||b===!0;var d=a.level+1,e=this.trigger("beforeAddGroup",a,b,d);if(e.isDefaultPrevented())return null;var f=this.nextGroupId(),g=$(this.getGroupTemplate(f,d)),h=a.addGroup(g);return void 0!==c&&(h.data=c),this.trigger("afterAddGroup",h),h.condition=this.settings.default_condition,b&&this.addRule(h),h},f.prototype.deleteGroup=function(a){if(a.isRoot())return!1;var b=this.trigger("beforeDeleteGroup",a);if(b.isDefaultPrevented())return!1;var c=!0;return a.each("reverse",function(a){c&=this.deleteRule(a)},function(a){c&=this.deleteGroup(a)},this),c&&(a.drop(),this.trigger("afterDeleteGroup")),c},f.prototype.updateGroupCondition=function(a){a.$el.find(">"+g.group_condition).each(function(){var b=$(this);b.prop("checked",b.val()===a.condition),b.parent().toggleClass("active",b.val()===a.condition)}),this.trigger("afterUpdateGroupCondition",a)},f.prototype.addRule=function(a,b){var c=this.trigger("beforeAddRule",a);if(c.isDefaultPrevented())return null;var d=this.nextRuleId(),e=$(this.getRuleTemplate(d)),f=a.addRule(e);return void 0!==b&&(f.data=b),this.trigger("afterAddRule",f),this.createRuleFilters(f),(this.settings.default_filter||!this.settings.display_empty_filter)&&(f.filter=this.getFilterById(this.settings.default_filter||this.filters[0].id)),f},f.prototype.deleteRule=function(a){if(a.flags.no_delete)return!1;var b=this.trigger("beforeDeleteRule",a);return b.isDefaultPrevented()?!1:(a.drop(),this.trigger("afterDeleteRule"),!0)},f.prototype.createRuleFilters=function(a){var b=this.change("getRuleFilters",this.filters,a),c=$(this.getRuleFilterSelect(a,b));a.$el.find(g.filter_container).html(c),this.trigger("afterCreateRuleFilters",a)},f.prototype.createRuleOperators=function(a){var b=a.$el.find(g.operator_container).empty();if(a.filter){var c=this.getOperators(a.filter),d=$(this.getRuleOperatorSelect(a,c));b.html(d),a.__.operator=c[0],this.trigger("afterCreateRuleOperators",a,c)}},f.prototype.createRuleInput=function(a){var b=a.$el.find(g.value_container).empty();if(a.__.value=void 0,a.filter&&a.operator&&0!==a.operator.nb_inputs){for(var c=this,d=$(),e=a.filter,f=0;f0&&b.append(this.settings.inputs_separator),b.append(h),d=d.add(h)}b.show(),d.on("change "+(e.input_event||""),function(){c.status.updating_value=!0,a.value=c.getRuleValue(a),c.status.updating_value=!1}),e.plugin&&d[e.plugin](e.plugin_config||{}),this.trigger("afterCreateRuleInput",a),void 0!==e.default_value?a.value=e.default_value:(c.status.updating_value=!0,a.value=c.getRuleValue(a),c.status.updating_value=!1)}},f.prototype.updateRuleFilter=function(a){this.createRuleOperators(a),this.createRuleInput(a),a.$el.find(g.rule_filter).val(a.filter?a.filter.id:"-1"),this.trigger("afterUpdateRuleFilter",a)},f.prototype.updateRuleOperator=function(a,b){var c=a.$el.find(g.value_container);a.operator&&0!==a.operator.nb_inputs?(c.show(),(c.is(":empty")||a.operator.nb_inputs!==b.nb_inputs)&&this.createRuleInput(a)):(c.hide(),a.__.value=void 0),a.operator&&a.$el.find(g.rule_operator).val(a.operator.type),this.trigger("afterUpdateRuleOperator",a)},f.prototype.updateRuleValue=function(a){this.status.updating_value||this.setRuleValue(a,a.value),this.trigger("afterUpdateRuleValue",a)},f.prototype.applyRuleFlags=function(a){var b=a.flags;b.filter_readonly&&a.$el.find(g.rule_filter).prop("disabled",!0),b.operator_readonly&&a.$el.find(g.rule_operator).prop("disabled",!0),b.value_readonly&&a.$el.find(g.rule_value).prop("disabled",!0),b.no_delete&&a.$el.find(g.delete_rule).remove(),this.trigger("afterApplyRuleFlags",a)},f.prototype.applyGroupFlags=function(a){var b=a.flags;b.condition_readonly&&(a.$el.find(">"+g.condition_container+" .btn").addClass("disabled"),a.$el.find(">"+g.group_condition).prop("disabled",!0)),b.no_delete&&a.$el.find(g.delete_group).remove(),this.trigger("afterApplyGroupFlags",a)},f.prototype.clearErrors=function(a){a=a||this.model.root,a&&(a.error=null,a instanceof i&&a.each(function(a){a.error=null},function(a){this.clearErrors(a)},this))},f.prototype.displayError=function(a){if(this.settings.display_errors)if(null===a.error)a.$el.removeClass("has-error");else{var b=$.extend([],a.error,[this.lang.errors[a.error[0]]||a.error[0]]);a.$el.addClass("has-error").find(g.error_container).eq(0).attr("title",k.fmt.apply(null,b))}},f.prototype.triggerValidationError=function(a,b,c){$.isArray(b)||(b=[b]);var d=this.trigger("validationError",a,b,c);d.isDefaultPrevented()||(a.error=b)},f.prototype.destroy=function(){this.trigger("beforeDestroy"),this.status.generated_id&&this.$el.removeAttr("id"),this.clear(),this.model=null,this.$el.off(".queryBuilder").removeClass("query-builder").removeData("queryBuilder"),delete this.$el[0].queryBuilder},f.prototype.reset=function(){this.status.group_id=1,this.status.rule_id=0,this.model.root.empty(),this.addRule(this.model.root),this.trigger("afterReset")},f.prototype.clear=function(){this.status.group_id=0,this.status.rule_id=0,this.model.root&&(this.model.root.drop(),this.model.root=null),this.trigger("afterClear")},f.prototype.setOptions=function(a){$.makeArray($(Object.keys(a)).filter(f.modifiable_options)).forEach(function(b){this.settings[b]=a[b]},this)},f.prototype.getModel=function(a){return a?b(a):this.model.root},f.prototype.validate=function(){this.clearErrors();var a=this,b=function c(b){var d=0,e=0;return b.each(function(b){if(!b.filter)return a.triggerValidationError(b,"no_filter",null),void e++;if(0!==b.operator.nb_inputs){var c=a.validateValue(b,b.value);if(c!==!0)return a.triggerValidationError(b,c,b.value),void e++}d++},function(a){c(a)?d++:e++}),e>0?!1:0!==d||a.settings.allow_empty&&b.isRoot()?!0:(a.triggerValidationError(b,"empty_group",null),!1)}(this.model.root);return this.change("validate",b)},f.prototype.getRules=function(a){if(a=$.extend({get_flags:!1},a),!this.validate())return{};var b=this,c=function d(c){var e={condition:c.condition,rules:[]};if(c.data&&(e.data=$.extendext(!0,"replace",{},c.data)),a.get_flags){var f=b.getGroupFlags(c.flags,"all"===a.get_flags);$.isEmptyObject(f)||(e.flags=f)}return c.each(function(c){var d=null;0!==c.operator.nb_inputs&&(d=c.value);var f={id:c.filter.id,field:c.filter.field,type:c.filter.type,input:c.filter.input,operator:c.operator.type,value:d};if((c.filter.data||c.data)&&(f.data=$.extendext(!0,"replace",{},c.filter.data,c.data)),a.get_flags){var g=b.getRuleFlags(c.flags,"all"===a.get_flags);$.isEmptyObject(g)||(f.flags=g)}e.rules.push(f)},function(a){e.rules.push(d(a))}),e}(this.model.root);return this.change("getRules",c)},f.prototype.setRules=function(a){$.isArray(a)&&(a={condition:this.settings.default_condition,rules:a}),a&&a.rules&&(0!==a.rules.length||this.settings.allow_empty)||k.error("RulesParse","Incorrect data object passed"),this.clear(),this.setRoot(!1,a.data),this.model.root.flags=this.parseGroupFlags(a),a=this.change("setRules",a);var b=this;!function c(a,d){null!==d&&(void 0===a.condition?a.condition=b.settings.default_condition:-1==b.settings.conditions.indexOf(a.condition)&&k.error("UndefinedCondition",'Invalid condition "{0}"',a.condition),d.condition=a.condition,a.rules.forEach(function(a){var e;if(a.rules&&a.rules.length>0)if(-1!==b.settings.allow_groups&&b.settings.allow_groups1){h=["operator_not_multiple",e.type];break}break;case"select":if(d.multiple){if(void 0===b[i]||0===b[i].length||d.placeholder&&b[i]==d.placeholder_value){h=["select_empty"];break}if(!e.multiple&&b[i].length>1){h=["operator_not_multiple",e.type];break}}else if(void 0===b[i]||d.placeholder&&b[i]==d.placeholder_value){h=["select_empty"];break}break;default:switch(f.types[d.type]){case"string":if(void 0===b[i]||0===b[i].length){h=["string_empty"];break}if(void 0!==g.min&&b[i].lengthparseInt(g.max)){h=["string_exceed_max_length",g.max];break}if(g.format&&("string"==typeof g.format&&(g.format=new RegExp(g.format)),!g.format.test(b[i]))){h=["string_invalid_format",g.format];break}break;case"number":if(void 0===b[i]||isNaN(b[i])){h=["number_nan"];break}if("integer"==d.type){if(parseInt(b[i])!=b[i]){h=["number_not_integer"];break}}else if(parseFloat(b[i])!=b[i]){h=["number_not_double"];break}if(void 0!==g.min&&b[i]parseFloat(g.max)){h=["number_exceed_max",g.max];break}if(void 0!==g.step&&"any"!==g.step){var j=(b[i]/g.step).toPrecision(14);if(parseInt(j)!=j){h=["number_wrong_step",g.step];break}}break;case"datetime":if(void 0===b[i]||0===b[i].length){h=["datetime_empty"];break}if(g.format){"moment"in window||k.error("MissingLibrary","MomentJS is required for Date/Time validation. Get it here http://momentjs.com");var l=moment(b[i],g.format);if(!l.isValid()){h=["datetime_invalid",g.format];break}if(g.min&&lmoment(g.max,g.format)){h=["datetime_exceed_max",g.max];break}}break;case"boolean":if(c=b[i].trim().toLowerCase(),"true"!==c&&"false"!==c&&"1"!==c&&"0"!==c&&1!==b[i]&&0!==b[i]){h=["boolean_not_valid"];break}}}if(h!==!0)break}return h},f.prototype.nextGroupId=function(){return this.status.id+"_group_"+this.status.group_id++},f.prototype.nextRuleId=function(){return this.status.id+"_rule_"+this.status.rule_id++},f.prototype.getOperators=function(a){"string"==typeof a&&(a=this.getFilterById(a));for(var b=[],c=0,d=this.operators.length;d>c;c++){if(a.operators){if(-1==a.operators.indexOf(this.operators[c].type))continue}else if(-1==this.operators[c].apply_to.indexOf(f.types[a.type]))continue;b.push(this.operators[c])}return a.operators&&b.sort(function(b,c){return a.operators.indexOf(b.type)-a.operators.indexOf(c.type)}),this.change("getOperators",b,a)},f.prototype.getFilterById=function(a){if("-1"==a)return null;for(var b=0,c=this.filters.length;c>b;b++)if(this.filters[b].id==a)return this.filters[b];k.error("UndefinedFilter",'Undefined filter "{0}"',a)},f.prototype.getOperatorByType=function(a){if("-1"==a)return null;for(var b=0,c=this.operators.length;c>b;b++)if(this.operators[b].type==a)return this.operators[b];k.error("UndefinedOperator",'Undefined operator "{0}"',a)},f.prototype.getRuleValue=function(a){var b=a.filter,c=a.operator,d=[];if(b.valueGetter)d=b.valueGetter.call(this,a);else{for(var e=a.$el.find(g.value_container),f=0;f ',f.templates.rule=' {{? it.settings.display_errors }}
{{?}}
',f.templates.filterSelect='{{ var optgroup = null; }} {{? it.settings.display_empty_filter }} {{= it.settings.select_placeholder }} {{?}} {{~ it.filters: filter }} {{? optgroup !== filter.optgroup }} {{? optgroup !== null }}{{?}} {{? (optgroup = filter.optgroup) !== null }} {{?}} {{?}} {{= it.translate(filter.label) }} {{~}} {{? optgroup !== null }} {{?}} ',f.templates.operatorSelect='{{ var optgroup = null; }} {{~ it.operators: operator }} {{? optgroup !== operator.optgroup }} {{? optgroup !== null }}{{?}} {{? (optgroup = operator.optgroup) !== null }} {{?}} {{?}} {{= it.lang.operators[operator.type] || operator.type }} {{~}} {{? optgroup !== null }} {{?}} ',
+f.prototype.getGroupTemplate=function(a,b){var c=this.templates.group({builder:this,group_id:a,level:b,conditions:this.settings.conditions,icons:this.icons,lang:this.lang,settings:this.settings});return this.change("getGroupTemplate",c,b)},f.prototype.getRuleTemplate=function(a){var b=this.templates.rule({builder:this,rule_id:a,icons:this.icons,lang:this.lang,settings:this.settings});return this.change("getRuleTemplate",b)},f.prototype.getRuleFilterSelect=function(a,b){var c=this.templates.filterSelect({builder:this,rule:a,filters:b,icons:this.icons,lang:this.lang,settings:this.settings,translate:this.translateLabel});return this.change("getRuleFilterSelect",c,a)},f.prototype.getRuleOperatorSelect=function(a,b){var c=this.templates.operatorSelect({builder:this,rule:a,operators:b,icons:this.icons,lang:this.lang,settings:this.settings,translate:this.translateLabel});return this.change("getRuleOperatorSelect",c,a)},f.prototype.getRuleInput=function(a,b){var c=a.filter,d=a.filter.validation||{},e=a.id+"_value_"+b,g=c.vertical?" class=block":"",h="";if("function"==typeof c.input)h=c.input.call(this,a,e);else switch(c.input){case"radio":case"checkbox":k.iterateOptions(c.values,function(a,b){h+=" '+b+" "});break;case"select":h+='",c.placeholder&&(h+=''+c.placeholder+" "),k.iterateOptions(c.values,function(a,b){h+=''+b+" "}),h+=" ";break;case"textarea":h+='";break;default:switch(f.types[c.type]){case"number":h+=' ";break;default:h+=' "}}return this.change("getRuleInput",h,a,e)},$.extend(b.prototype,{trigger:function(a){return this.$.triggerHandler(a,Array.prototype.slice.call(arguments,1)),this},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.getModel=function(a){return a?a instanceof h?a:$(a).data("queryBuilderModel"):null};var h=function(a,b){return this instanceof h?(Object.defineProperty(this,"__",{value:{}}),b.data("queryBuilderModel",this),this.__.level=0,this.__.error=null,this.__.data=void 0,this.$el=b,this.id=b[0].id,this.model=null,void(this.parent=a)):new h};c(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(){null!==this.model&&this.model.trigger("drop",this),this.isRoot()||(this.parent._removeNode(this),this.parent=null)},h.prototype.moveAfter=function(a){return this.isRoot()?void 0:(this._move(a.parent,a.getPos()+1),this)},h.prototype.moveAtBegin=function(a){return this.isRoot()?void 0:(void 0===a&&(a=this.parent),this._move(a,0),this)},h.prototype.moveAtEnd=function(a){return this.isRoot()?void 0:(void 0===a&&(a=this.parent),this._move(a,a.length()),this)},h.prototype._move=function(a,b){this.parent._removeNode(this),a._appendNode(this,b,!1),null!==this.model&&this.model.trigger("move",this,a,b)};var i=function(a,b){return this instanceof i?(h.call(this,a,b),this.rules=[],void(this.__.condition=null)):new i(a,b)};i.prototype=Object.create(h.prototype),i.prototype.constructor=i,c(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._appendNode=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",a,b),a},i.prototype.addGroup=function(a,b){return this._appendNode(new i(this,a),b,!0)},i.prototype.addRule=function(a,b){return this._appendNode(new j(this,a),b,!0)},i.prototype._removeNode=function(a){var b=this.getNodePos(a);return-1!==b&&(a.parent=null,this.rules.splice(b,1)),this},i.prototype.getNodePos=function(a){return this.rules.indexOf(a)},i.prototype.each=function(a,b,c,d){"function"==typeof a&&(d=c,c=b,b=a,a=!1),d=void 0===d?null:d;for(var e=a?this.rules.length-1:0,f=a?0:this.rules.length-1,g=a?-1:1,h=function(){return a?e>=f:f>=e},j=!1;h()&&(this.rules[e]instanceof i?void 0!==c&&(j=c.call(d,this.rules[e])===!1):j=b.call(d,this.rules[e])===!1,!j);e+=g);return!j},i.prototype.contains=function(a,b){return-1!==this.getNodePos(a)?!0:b?!this.each(function(){return!0},function(b){return!b.contains(a,!0)}):!1};var j=function(a,b){return this instanceof j?(h.call(this,a,b),this.__.filter=null,this.__.operator=null,this.__.flags={},void(this.__.value=void 0)):new j(a,b)};j.prototype=Object.create(h.prototype),j.prototype.constructor=j,c(j,["filter","operator","value"]),f.Group=i,f.Rule=j;var k=f.utils={};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){var b=Array.prototype.slice.call(arguments,1);return a.replace(/{([0-9]+)}/g,function(a,c){return b[parseInt(c)]})},k.error=function(a){var b=new Error(k.fmt.apply(null,Array.prototype.slice.call(arguments,1)));throw b.name=a+"Error",b.args=Array.prototype.slice.call(arguments,2),b},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"\x00":return"\\0";case"\n":return"\\n";case"\r":return"\\r";case"\b":return"\\b";default:return"\\"+a}}).replace(/\t/g,"\\t").replace(/\x1a/g,"\\Z")},k.escapeRegExp=function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},k.groupSort=function(a,b){var c=[],d=[];return a.forEach(function(a){var e;a[b]?(e=c.lastIndexOf(a[b]),-1==e?e=c.length:e++):e=c.length,c.splice(e,0,a[b]),d.splice(e,0,a)}),d},$.fn.queryBuilder=function(a){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 f(this,c)),"string"==typeof a?b[a].apply(b,Array.prototype.slice.call(arguments,1)):this):this},$.fn.queryBuilder.constructor=f,$.fn.queryBuilder.defaults=f.defaults,$.fn.queryBuilder.extend=f.extend,$.fn.queryBuilder.define=f.define,$.fn.queryBuilder.regional=f.regional,f.define("bt-checkbox",function(a){if("glyphicons"==a.font){var b=document.createElement("style");b.innerHTML='.checkbox input[type=checkbox]:checked + label:after { font-family: "Glyphicons Halflings"; content: "\\e013"; } .checkbox label:after { padding-left: 4px; padding-top: 2px; font-size: 9px; }',document.body.appendChild(b)}this.on("getRuleInput.filter",function(b,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+=" '+h+"
"})}})},{font:"glyphicons",color:"default"}),f.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'),this.on("afterCreateRuleFilters",function(b,c){c.$el.find(g.rule_filter).removeClass("form-control").selectpicker(a)}),this.on("afterCreateRuleOperators",function(b,c){c.$el.find(g.rule_operator).removeClass("form-control").selectpicker(a)}),this.on("afterUpdateRuleFilter",function(a,b){b.$el.find(g.rule_filter).selectpicker("render")}),this.on("afterUpdateRuleOperator",function(a,b){b.$el.find(g.rule_operator).selectpicker("render")})},{container:"body",style:"btn-inverse btn-xs",width:"auto",showIcon:!1}),f.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.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.error_container).eq(0).tooltip(a).tooltip("hide").tooltip("fixTitle")})},{placement:"right"}),f.extend({setFilters:function(a,b){var c=this;void 0===b&&(b=a,a=!1),b=this.checkFilters(b),b=this.change("setFilters",b);var d=b.map(function(a){return a.id});if(a||!function f(a){a.each(function(a){a.filter&&-1===d.indexOf(a.filter.id)&&k.error("ChangeFilter",'A rule is using filter "{0}"',a.filter.id)},f)}(this.model.root),this.filters=b,function h(a){a.each(!0,function(a){a.filter&&-1===d.indexOf(a.filter.id)?a.drop():(c.createRuleFilters(a),a.$el.find(g.rule_filter).val(a.filter?a.filter.id:"-1"))},h)}(this.model.root),this.settings.plugins&&(this.settings.plugins["unique-filter"]&&this.updateDisabledFilters(),this.settings.plugins["bt-selectpicker"]&&this.$el.find(g.rule_filter).selectpicker("render")),this.settings.default_filter)try{this.getFilterById(this.settings.default_filter)}catch(e){this.settings.default_filter=null}this.trigger("afterSetFilters",b)},addFilter:function(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){return a.id==b?(b=c+1,!0):void 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-1===a.indexOf(b.id)}),this.setFilters(b,c)}}),f.define("filter-description",function(a){"inline"===a.mode?this.on("afterUpdateRuleFilter",function(b,c){var d=c.$el.find("p.filter-description");c.filter&&c.filter.description?(0===d.length?(d=$('
'),d.appendTo(c.$el)):d.show(),d.html(' '+c.filter.description)):d.hide()}):"popover"===a.mode?($.fn.popover&&$.fn.popover.Constructor&&$.fn.popover.Constructor.prototype.fixTitle||k.error("MissingLibrary",'Bootstrap Popover is required to use "filter-description" plugin. Get it here: http://getbootstrap.com'),this.on("afterUpdateRuleFilter",function(b,c){var d=c.$el.find("button.filter-description");c.filter&&c.filter.description?(0===d.length?(d=$(' '),d.prependTo(c.$el.find(g.rule_actions)),d.popover({placement:"left",container:"body",html:!0}),d.on("mouseout",function(){d.popover("hide")})):d.show(),d.data("bs.popover").options.content=c.filter.description,d.attr("aria-describedby")&&d.popover("show")):(d.hide(),d.data("bs.popover")&&d.popover("hide"))})):"bootbox"===a.mode&&("bootbox"in window||k.error("MissingLibrary",'Bootbox is required to use "filter-description" plugin. Get it here: http://bootboxjs.com'),this.on("afterUpdateRuleFilter",function(b,c){var d=c.$el.find("button.filter-description");c.filter&&c.filter.description?(0===d.length&&(d=$(' '),d.prependTo(c.$el.find(g.rule_actions)),d.on("click",function(){bootbox.alert(d.data("description"))})),d.data("description",c.filter.description)):d.hide()}))},{icon:"glyphicon glyphicon-info-sign",mode:"popover"}),f.defaults({operatorOpposites:{equal:"not_equal",not_equal:"equal","in":"not_in",not_in:"in",less:"greater_or_equal",less_or_equal:"greater",greater:"less_or_equal",greater_or_equal:"less",between:"not_between",not_between:"between",begins_with:"not_begins_with",not_begins_with:"begins_with",contains:"not_contains",not_contains:"contains",ends_with:"not_ends_with",not_ends_with:"ends_with",is_empty:"is_not_empty",is_not_empty:"is_empty",is_null:"is_not_null",is_not_null:"is_null"},conditionOpposites:{AND:"OR",OR:"AND"}}),f.define("invert",function(a){var c=this;this.on("afterInit",function(){c.$el.on("click.queryBuilder","[data-invert=group]",function(){var d=$(this).closest(g.group_container);c.invert(b(d),a)}),a.display_rules_button&&a.invert_rules&&c.$el.on("click.queryBuilder","[data-invert=rule]",function(){var d=$(this).closest(g.rule_container);c.invert(b(d),a)})}),this.on("getGroupTemplate.filter",function(b){var d=$(b.value);d.find(g.condition_container).after(' '+c.lang.invert+" "),b.value=d.prop("outerHTML")}),a.display_rules_button&&a.invert_rules&&this.on("getRuleTemplate.filter",function(b){var d=$(b.value);d.find(g.rule_actions).prepend(' '+c.lang.invert+" "),b.value=d.prop("outerHTML")})},{icon:"glyphicon glyphicon-random",recursive:!0,invert_rules:!0,display_rules_button:!1,silent_fail:!1}),f.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&&-1==a.filter.operators.indexOf(d)||(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)}}),f.defaults({mongoOperators:{equal:function(a){return a[0]},not_equal:function(a){return{$ne:a[0]}},"in":function(a){return{$in:a}},not_in:function(a){return{$nin:a}},less:function(a){return{$lt:a[0]}},less_or_equal:function(a){return{$lte:a[0]}},greater:function(a){return{$gt:a[0]}},greater_or_equal:function(a){return{$gte:a[0]}},between:function(a){return{$gte:a[0],$lte:a[1]}},not_between:function(a){return{$lt:a[0],$gt:a[1]}},begins_with:function(a){return{$regex:"^"+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(c(a));else{var e=b.settings.mongoOperators[a.operator],f=b.getOperatorByType(a.operator),g=[];void 0===e&&k.error("UndefinedMongoOperator",'Unknown MongoDB operation for operator "{0}"',a.operator),0!==f.nb_inputs&&(a.value instanceof Array||(a.value=[a.value]),a.value.forEach(function(b){g.push(k.changeType(b,a.type,!1))}));var h={};h[a.field]=e.call(b,g),d.push(h)}});var e={};return d.length>0&&(e["$"+a.condition.toLowerCase()]=d),e}(a)},getRulesFromMongo:function(a){if(void 0===a||null===a)return null;var b=this,c={$and:"AND",$or:"OR"};return function e(a){var f=Object.keys(a);f.length>1&&k.error("MongoParse","Invalid MongoDB query format"),c[f[0].toLowerCase()]||k.error("UndefinedMongoCondition",'Unable to build MongoDB query with condition "{0}"',f[0]);var g=a[f[0]],h=[];g.forEach(function(a){var f=Object.keys(a);if(c[f[0].toLowerCase()])h.push(e(a));else{var g=f[0],i=a[g],j=d(i,g);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);h.push({id:b.change("getMongoDBFieldID",g,i),field:g,operator:m.op,value:m.val})}});var i={};return h.length>0&&(i.condition=c[f[0].toLowerCase()],i.rules=h),i}(a)},setRulesFromMongo:function(a){this.setRules(this.getRulesFromMongo(a))}}),g.rule_and_group_containers=g.rule_container+", "+g.group_container,f.define("sortable",function(a){this.on("afterInit",function(a){$.event.props.push("dataTransfer");var c,d,f=a.builder;f.$el.on("mouseover.queryBuilder",".drag-handle",function(){f.$el.find(g.rule_and_group_containers).attr("draggable",!0)}),f.$el.on("mouseout.queryBuilder",".drag-handle",function(){f.$el.find(g.rule_and_group_containers).removeAttr("draggable")}),f.$el.on("dragstart.queryBuilder","[draggable]",function(a){a.stopPropagation(),a.dataTransfer.setData("text","drag"),d=b(a.target),setTimeout(function(){var a=$('
');a.css("min-height",d.$el.height()),c=d.parent.addRule(a,d.getPos()),d.$el.hide()},0)}),f.$el.on("dragenter.queryBuilder","[draggable]",function(a){a.preventDefault(),a.stopPropagation(),c&&e(c,$(a.target))}),f.$el.on("dragover.queryBuilder","[draggable]",function(a){a.preventDefault(),a.stopPropagation()}),f.$el.on("drop.queryBuilder",function(a){a.preventDefault(),a.stopPropagation(),e(d,$(a.target))}),f.$el.on("dragend.queryBuilder","[draggable]",function(a){a.preventDefault(),a.stopPropagation(),d.$el.show(),c.drop(),f.$el.find(g.rule_and_group_containers).removeAttr("draggable"),f.trigger("afterMove",d),d=c=null})}),this.on("parseRuleFlags.filter",function(b){void 0===b.value.no_sortable&&(b.value.no_sortable=a.default_no_sortable)}),this.on("afterApplyRuleFlags",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.condition_container).after('
'),b.value=d.prop("outerHTML")}}),this.on("getRuleTemplate.filter",function(b){var c=$(b.value);c.find(g.rule_header).after('
'),b.value=c.prop("outerHTML")})},{default_no_sortable:!1,icon:"glyphicon glyphicon-sort"}),f.defaults({sqlOperators:{equal:{op:"= ?"},not_equal:{op:"!= ?"},"in":{op:"IN(?)",sep:", "},not_in:{op:"NOT IN(?)",sep:", "},less:{op:"< ?"},less_or_equal:{op:"<= ?"},greater:{op:"> ?"},greater_or_equal:{op:">= ?"},between:{op:"BETWEEN ?",sep:" AND "},not_between:{op:"NOT BETWEEN ?",sep:" AND "},begins_with:{op:"LIKE(?)",mod:"{0}%"},not_begins_with:{op:"NOT LIKE(?)",mod:"{0}%"},contains:{op:"LIKE(?)",mod:"%{0}%"},not_contains:{op:"NOT LIKE(?)",mod:"%{0}%"},ends_with:{op:"LIKE(?)",mod:"%{0}"},not_ends_with:{op:"NOT LIKE(?)",mod:"%{0}"},is_empty:{op:"= ''"},is_not_empty:{op:"!= ''"},is_null:{op:"IS NULL"},is_not_null:{op:"IS NOT NULL"}},sqlRuleOperator:{"=":function(a){return{val:a,op:""===a?"is_empty":"equal"}},"!=":function(a){return{val:a,op:""===a?"is_not_empty":"not_equal"}},LIKE:function(a){return"%"==a.slice(0,1)&&"%"==a.slice(-1)?{val:a.slice(1,-1),op:"contains"}:"%"==a.slice(0,1)?{val:a.slice(1),op:"ends_with"}:"%"==a.slice(-1)?{val:a.slice(0,-1),op:"begins_with"}:void k.error("SQLParse",'Invalid value for 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(){var a=0,b=[];return{add:function(c,d){return b.push(d),a++,"$"+a},run:function(){return b}}},named:function(){var a={},b={};return{add:function(c,d){a[c.field]||(a[c.field]=1);var e=c.field+"_"+a[c.field]++;return b[e]=d,":"+e},run:function(){return b}}}},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){return{parse:function(b){return/^\$[0-9]+$/.test(b)?a[b.slice(1)-1]:b},esc:function(a){return a.replace(/\$([0-9]+)/g,"'$$$1'")}}},named:function(a){return{parse:function(b){return/^:/.test(b)?a[b.slice(1)]:b},esc:function(b){return b.replace(new RegExp(":("+Object.keys(a).join("|")+")","g"),"':$1'")}}}}}),f.extend({getSQL:function(a,b,c){c=void 0===c?this.getRules():c,b=b===!0?"\n":" ",(a===!0||void 0===a)&&(a="question_mark"),"string"==typeof a&&(a=this.settings.sqlStatements[a]());var d=this,e=function f(c){if(c.condition||(c.condition=d.settings.default_condition),-1===["AND","OR"].indexOf(c.condition.toUpperCase())&&k.error("UndefinedSQLCondition",'Unable to build SQL query with condition "{0}"',c.condition),!c.rules)return"";var e=[];return c.rules.forEach(function(c){if(c.rules&&c.rules.length>0)e.push("("+b+f(c)+b+")"+b);else{var g=d.settings.sqlOperators[c.operator],h=d.getOperatorByType(c.operator),i="";void 0===g&&k.error("UndefinedSQLOperator",'Unknown SQL operation for operator "{0}"',c.operator),0!==h.nb_inputs&&(c.value instanceof Array||(c.value=[c.value]),c.value.forEach(function(b,d){d>0&&(i+=g.sep),"integer"==c.type||"double"==c.type||"boolean"==c.type?b=k.changeType(b,c.type,!0):a||(b=k.escapeString(b)),g.mod&&(b=k.fmt(g.mod,b)),a?i+=a.add(c,b):("string"==typeof b&&(b="'"+b+"'"),i+=b)})),e.push(c.field+" "+g.op.replace(/\?/,i))}}),e.join(" "+c.condition+b)}(c);return a?{sql:e,params:a.run()}:{sql:e}},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;"string"==typeof a&&(a={sql:a}),"string"==typeof b&&(b=this.settings.sqlRuleStatement[b](a.params),a.sql=b.esc(a.sql)),0!==a.sql.toUpperCase().indexOf("SELECT")&&(a.sql="SELECT * FROM table WHERE "+a.sql);var d=SQLParser.parse(a.sql);d.where||k.error("SQLParse","No WHERE clause found");var e={condition:this.settings.default_condition,rules:[]},f=e;return function g(a,d){if(-1!==["AND","OR"].indexOf(a.operation.toUpperCase())){d>0&&f.condition!=a.operation.toUpperCase()&&(f.rules.push({condition:c.settings.default_condition,rules:[]}),f=f.rules[f.rules.length-1]),f.condition=a.operation.toUpperCase(),d++;var e=f;g(a.left,d),f=e,g(a.right,d)}else{(void 0===a.left.value||void 0===a.right.value)&&k.error("SQLParse","Missing field and/or value"),$.isPlainObject(a.right.value)&&k.error("SQLParse","Value format not supported for {0}.",a.left.value);var h;h=$.isArray(a.right.value)?a.right.value.map(function(a){return a.value}):a.right.value,b&&(h=$.isArray(h)?h.map(b.parse):b.parse(h));var i=a.operation.toUpperCase();"<>"==i&&(i="!=");var j;j="NOT LIKE"==i?c.settings.sqlRuleOperator.LIKE:c.settings.sqlRuleOperator[i],void 0===j&&k.error("UndefinedSQLOperator",'Invalid SQL operation "{0}".',a.operation);var l=j.call(this,h,a.operation);"NOT LIKE"==i&&(l.op="not_"+l.op);var m=a.left.values.join(".");f.rules.push({id:c.change("getSQLFieldID",m,h),field:m,operator:l.op,value:l.val})}}(d.where.conditions,0),e},setRulesFromSQL:function(a,b){this.setRules(this.getRulesFromSQL(a,b))}}),f.define("unique-filter",function(){this.status.used_filters={},this.on("afterUpdateRuleFilter",this.updateDisabledFilters),this.on("afterDeleteRule",this.updateDisabledFilters),this.on("afterCreateRuleFilters",this.applyDisabledFilters),this.on("afterReset",this.clearDisabledFilters),this.on("afterClear",this.clearDisabledFilters)}),f.extend({updateDisabledFilters:function(a){var b=a?a.builder:this;b.status.used_filters={},b.model&&(!function c(a){a.each(function(a){a.filter&&a.filter.unique&&(b.status.used_filters[a.filter.id]||(b.status.used_filters[a.filter.id]=[]),"group"==a.filter.unique&&b.status.used_filters[a.filter.id].push(a.parent))},function(a){c(a)})}(b.model.root),b.applyDisabledFilters(a))},clearDisabledFilters:function(a){var b=a?a.builder:this;b.status.used_filters={},b.applyDisabledFilters(a)},applyDisabledFilters:function(a){var b=a?a.builder:this;b.$el.find(g.filter_container+" option").prop("disabled",!1),$.each(b.status.used_filters,function(a,c){0===c.length?b.$el.find(g.filter_container+' option[value="'+a+'"]:not(:selected)').prop("disabled",!0):c.forEach(function(b){b.each(function(b){b.$el.find(g.filter_container+' option[value="'+a+'"]:not(:selected)').prop("disabled",!0)})})}),b.settings.plugins&&b.settings.plugins["bt-selectpicker"]&&b.$el.find(g.rule_filter).selectpicker("render")}}),f.regional.en={__locale:"English (en)",__author:'Damien "Mistic" Sorel, http://www.strangeplanet.fr',add_rule:"Add rule",add_group:"Add group",delete_rule:"Delete",delete_group:"Delete",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 {0} cannot accept multiple values"},invert:"Invert"},f.defaults({lang_code:"en"})});
\ No newline at end of file