From 1738aeb455a741fdec60a2d1eb35ca78a54bf706 Mon Sep 17 00:00:00 2001 From: Olivier Giulieri Date: Sun, 8 Jan 2017 23:23:52 -0800 Subject: [PATCH] Version 1.1.0. --- bower.json | 2 +- css/structured-filter.css | 8 +++++--- index.html | 2 +- js/structured-filter.js | 2 +- js/structured-filter.min.js | 4 ++-- package.json | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/bower.json b/bower.json index eac0cb3..69e387c 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "structured-filter", - "version": "1.0.11", + "version": "1.1.0", "description": "jQuery UI widget for structured queries", "homepage": "http://evoluteur.github.io/structured-filter/", "main": [ diff --git a/css/structured-filter.css b/css/structured-filter.css index d5dc178..40407f3 100644 --- a/css/structured-filter.css +++ b/css/structured-filter.css @@ -1,5 +1,5 @@ /* - structured-filter 1.0.11 + structured-filter 1.1.0 http://evoluteur.github.io/structured-filter/ (c) 2017 Olivier Giulieri */ @@ -21,10 +21,9 @@ font-weight: normal; } .evo-searchFilters a { + border-radius: 14px; -moz-border-radius: 14px; -webkit-border-radius: 14px; - -khtml-border-radius: 14px; - border-radius: 14px; } .evo-searchFilters a span.ui-button-text { padding: 4px 33px 4px 12px; @@ -44,6 +43,7 @@ .evo-editFilter span#value { margin-right: 5px; } +.evo-editFilter #value input[type="radio"], .evo-editFilter #value input[type="checkbox"] { margin-left: 5px; } @@ -64,6 +64,8 @@ color: #555; border: 1px solid #ccc; border-radius: 4px; + -moz-border-radius: 4px; + -webkit-border-radius: 4px; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); } diff --git a/index.html b/index.html index 7c1c5e1..500ea4a 100644 --- a/index.html +++ b/index.html @@ -23,7 +23,7 @@

Structured-Filter

-

Structured-Filter (currently v1.0.11) is a Web UI for building structured search queries. It is a full jQuery UI widget, supporting various configurations and themes. +

Structured-Filter (currently v1.1.0) is a Web UI for building structured search queries. It is a full jQuery UI widget, supporting various configurations and themes.

diff --git a/js/structured-filter.js b/js/structured-filter.js index e0f8699..2460003 100644 --- a/js/structured-filter.js +++ b/js/structured-filter.js @@ -1,5 +1,5 @@ /*! - * structured-filter 1.0.11 + * structured-filter 1.1.0 * * (c) 2017 Olivier Giulieri * diff --git a/js/structured-filter.min.js b/js/structured-filter.min.js index f17b17e..ea535f8 100644 --- a/js/structured-filter.min.js +++ b/js/structured-filter.min.js @@ -1,6 +1,6 @@ /* - structured-filter 1.0.11 + structured-filter 1.1.0 http://evoluteur.github.io/structured-filter/ (c) 2017 Olivier Giulieri */ -!function(a,b){var c={sEqual:"equals",sNotEqual:"not equal",sStart:"starts with",sContain:"contains",sNotContain:"doesn't contain",sFinish:"finishes with",sInList:"any of",sIsNull:"is empty",sIsNotNull:"is not empty",sBefore:"before",sAfter:"after",sNumEqual:"=",sNumNotEqual:"!=",sGreater:">",sSmaller:"<",sOn:"on",sNotOn:"not on",sAt:"at",sNotAt:"not at",sBetween:"between",opAnd:"and",yes:"Yes",no:"No",bNewCond:"New filter condition",bAddCond:"Add condition",bUpdateCond:"Update condition",bSubmit:"Submit",bCancel:"Cancel"},d={sEqual:"eq",sNotEqual:"ne",sStart:"sw",sContain:"ct",sNotContain:"nct",sFinish:"fw",sInList:"in",sIsNull:"null",sIsNotNull:"nn",sGreater:"gt",sSmaller:"lt",sBetween:"bw"},e={text:"text",bool:"boolean",number:"number",date:"date",time:"time",list:"list"},f=navigator.userAgent.toLowerCase().indexOf("firefox")===-1;a.widget("evol.structFilter",{options:{fields:[],dateFormat:"mm/dd/yy",highlight:!0,buttonLabels:!1,submitButton:!1,submitReady:!1},_create:function(){var b=this.options.buttonLabels,f=this,g=this.element,h='

'+c.bNewCond+"";this.options.submitButton&&(h+=''+c.bSubmit+""),h+='
",this._step=0,g.addClass("structFilter ui-widget-content ui-corner-all").html(h),this.options.submitReady&&(this._hValues=a("").appendTo(g)),this.options.submitButton&&(this._bSubmit=g.find(".evo-bSubmit").button({text:b}).on("click",function(a){f.element.trigger("submit.search")})),this._bNew=g.find(".evo-bNew").button({text:b,icons:{secondary:"ui-icon-plusthick"}}).on("click",function(a){f._step<1&&(f._setEditorField(),f._step=1),f._bAdd.find(".ui-button-text").html(c.bAddCond)}),this._bAdd=g.find(".evo-bAdd").button({text:b,icons:{secondary:"ui-icon-check"}}).on("click",function(a){var b=f._getEditorData();f._cFilter?f._enableFilter(b,f.options.highlight):f.addCondition(b),f._removeEditor()}),this._bDel=g.find(".evo-bDel").button({text:b,icons:{secondary:"ui-icon-close"}}).on("click",function(a){f._removeEditor()}),this._editor=g.find(".evo-editFilter").on("change","#field",function(b){b.stopPropagation(),f._step>2&&f._editor.find("#value,#value2,.as-Txt").remove(),f._step>1&&(f._editor.find("#operator").remove(),f._bAdd.hide()),f._step=1;var c=a(b.currentTarget).val();if(""!==c){f._field=f._getFieldById(c);var d=f._type=f._field.type;f._setEditorOperator(),d!=e.list&&d!=e.bool||f._setEditorValue()}else f._field=f._type=null}).on("change","#operator",function(b){b.stopPropagation(),f._operator=a(this).val(),f._step>2&&(f._editor.find("#value,#value2,.as-Txt").remove(),f._bAdd.hide(),f._step=2),f._setEditorValue()}).on("change keyup","#value,#value2",function(b){b.stopPropagation();var c=f._type,g=a(this).val(),h=""!==g||c==e.list||c==e.bool;c==e.number?h=h&&!isNaN(g):f._operator==d.sBetween&&(h=""!==f._editor.find("#value").val()&&""!==f._editor.find("#value2").val()),h?(f._bAdd.button("enable"),13==b.which&&f._bAdd.trigger("click")):f._bAdd.button("disable")}).on("click","#checkAll",function(){var b=a(this),c=b.prop("checked");allChecks=b.siblings().prop("checked",c)}),this._filters=g.find(".evo-searchFilters").on("click","a",function(){f._editFilter(a(this))}).on("click","a .ui-button-icon-secondary",function(b){b.stopPropagation();var c=a(this).parent();c.hasClass("ui-state-disabled")||c.fadeOut("slow",function(){c.remove(),f._triggerChange()})})},_getFieldById:function(a){if(!this._hash){this._hash={};for(var b=this.options.fields,c=0,d=b.length;c'+this._htmlFilter(b)+"").prependTo(this._filters).button({icons:{secondary:"ui-icon-close"}}).data("filter",b).fadeIn();return this.options.highlight&&c.effect("highlight"),this._triggerChange(),this._bSubmit&&this._bSubmit.removeClass("ui-state-active").show(),this},removeCondition:function(a){return this._filters.children().eq(a).remove(),this._triggerChange(),this},_htmlFilter:function(a){var b=''+a.field.label+' '+a.operator.label+' '+a.value.label+"";return a.operator.value==d.sBetween&&(b+=' '+c.opAnd+' '+a.value.label2+""),b},_enableFilter:function(a,b){this._cFilter&&(this._cFilter.button("enable").removeClass("ui-state-hover ui-state-active"),b&&this._cFilter.effect("highlight"),a?(this._cFilter.data("filter",a).find(":first-child").html(this._htmlFilter(a)),this._cFilter=null,this._triggerChange()):this._cFilter=null)},_editFilter:function(a){var b=a.data("filter"),e=b.field.value,f=b.operator.value,g=b.value;this._enableFilter(null,!1),this._removeEditor(),this._cFilter=a.button("disable"),this._setEditorField(e),this._setEditorOperator(f),f==d.sBetween?this._setEditorValue(g.value,g.value2):this._setEditorValue(g.value),this._bAdd.find(".ui-button-text").html(c.bUpdateCond),this._step=3},_setEditorField:function(b){if(this._step<1){if(this._bNew.stop().hide(),this._bSubmit&&this._bSubmit.stop().hide(),this._bDel.show(),!this._fList){var c='",this._fList=c}a(this._fList).appendTo(this._editor).focus()}b&&(this._field=this._getFieldById(b),this._type=this._field.type,this._editor.find("#field").val(b)),this._step=1},_setEditorOperator:function(a){var b=this._type;if(this._step<2){var f="";switch(b){case e.list:f+=g.inputHidden("operator",d.sInList),this._operator=d.sInList;break;case e.bool:f+=g.inputHidden("operator",d.sEqual),this._operator=d.sEqual;break;default:switch(f+='"}this._editor.append(f)}a&&b!=e.list&&(this._editor.find("#operator").val(a),this._operator=a),this._step=2},_setEditorValue:function(a,b){var f=this._editor,h=this._type,i=f.find("#operator").val(),j=!1,k=!0;if(""!==i){if(h==e.list||i!=d.sIsNull&&i!=d.sIsNotNull){if(this._step<3){var l="";switch(j=i==d.sBetween,h){case e.list:l+=''+(this._field.list.length>7?'() ':"")+g.inputCheckboxes(this._field.list)+"";break;case e.bool:l+=''+g.inputRadio("value","1",c.yes,"0"!=a,"value1")+g.inputRadio("value","0",c.no,"0"==a,"value0")+"";break;case e.date:case e.time:case e.number:var m=h==e.date?"text":h;l+='',j&&(l+=''+c.opAnd+' '),k=!1;break;default:l+='',k=!1}f.append(l),h==e.date&&f.find("#value,#value2").datepicker({dateFormat:this.options.dateFormat})}if(a){var n=f.find("#value");switch(h){case e.list:n.find("#"+a.split(",").join(",#")).prop("checked","checked");break;case e.bool:n.find("#value"+a).prop("checked","checked");break;default:n.val(a),k=""!==a,j&&(n.next().next().val(b),k=""!==a&&""!==b)}}else k=h==e.list||h==e.bool}else f.append(g.inputHidden("value",""));this._bAdd.button(k?"enable":"disable").show(),this._step=3}},_getEditorData:function(){var a=this._editor,b=a.find("#field"),f=a.find("#value"),g={field:{label:b.find("option:selected").text(),value:b.val()},operator:{},value:{}},h=g.operator,i=g.value;if(this._type==e.list){var j=[],k=[];f.find("input:checked").not("#checkAll").each(function(){j.push(this.value),k.push(this.nextSibling.innerHTML)}),0===j.length?(h.label=c.sIsNull,h.value=d.sIsNull,i.label=i.value=""):1==j.length?(h.label=c.sEqual,h.value=d.sEqual,i.label='"'+k[0]+'"',i.value=j[0]):(h.label=c.sInList,h.value=d.sInList,i.label="("+k.join(", ")+")",i.value=j.join(","))}else if(this._type==e.bool){h.label=c.sEqual,h.value=d.sEqual;var l=f.find("#value1").prop("checked")?1:0;i.label=1==l?c.yes:c.no,i.value=l}else{var m=a.find("#operator"),n=m.val();h.label=m.find("option:selected").text(),h.value=n,n==d.sIsNull||n==d.sIsNotNull?i.label=i.value="":(this._type==e.number||this._type==e.date||this._type==e.time?i.label=f.val():i.label='"'+f.val()+'"',i.value=f.val(),n==d.sBetween&&(i.label2=i.value2=f.next().next().val()))}return g},_hiddenValue:function(a,b,c){a.push(g.inputHidden("fld-"+c,b.field.value)+g.inputHidden("op-"+c,b.operator.value)+g.inputHidden("val-"+c,b.value.value));var d=b.value.value2;d&&a.push(g.inputHidden("val2-"+c,d))},_setHiddenValues:function(){for(var a=this.val(),b=a.length,c=[g.inputHidden("elem",b)],d=0;d'+c+" "},inputHidden:function(a,b){return''},inputOption:function(a,b){return'"},optNull:'',inputCheckboxes:function(a){for(var b="",c=0;c "}return b}}}(jQuery); \ No newline at end of file +!function(a,b){var c={text:"text",bool:"boolean",number:"number",date:"date",time:"time",list:"list",listOpts:"list-options",listDropdown:"list-dropdown"},d={sEqual:"equals",sNotEqual:"not equal",sStart:"starts with",sContain:"contains",sNotContain:"doesn't contain",sFinish:"finishes with",sInList:"any of",sIsNull:"is empty",sIsNotNull:"is not empty",sBefore:"before",sAfter:"after",sNumEqual:"=",sNumNotEqual:"!=",sGreater:">",sSmaller:"<",sOn:"on",sNotOn:"not on",sAt:"at",sNotAt:"not at",sBetween:"between",opAnd:"and",yes:"Yes",no:"No",bNewCond:"New filter condition",bAddCond:"Add condition",bUpdateCond:"Update condition",bSubmit:"Submit",bCancel:"Cancel"},e={sEqual:"eq",sNotEqual:"ne",sStart:"sw",sContain:"ct",sNotContain:"nct",sFinish:"fw",sInList:"in",sIsNull:"null",sIsNotNull:"nn",sGreater:"gt",sSmaller:"lt",sBetween:"bw"},f=navigator.userAgent.toLowerCase().indexOf("firefox")===-1;a.widget("evol.structFilter",{options:{fields:[],dateFormat:"mm/dd/yy",highlight:!0,buttonLabels:!1,submitButton:!1,submitReady:!1},_create:function(){var b=this.options.buttonLabels,f=this,g=this.element,h=function(a,b,c){return'"},i='
'+h("evo-bNew",d.bNewCond);this.options.submitButton&&(i+=h("evo-bSubmit",d.bSubmit)),i+='
'+h("evo-bAdd",d.bAddCond,!0)+h("evo-bDel",d.bCancel,!0),this._step=0,g.addClass("structFilter ui-widget-content ui-corner-all").html(i),this.options.submitReady&&(this._hValues=a("").appendTo(g)),this.options.submitButton&&(this._bSubmit=g.find(".evo-bSubmit").button({text:b}).on("click",function(a){f.element.trigger("submit.search")})),this._bNew=g.find(".evo-bNew").button({text:b,icons:{secondary:"ui-icon-plusthick"}}).on("click",function(a){f._step<1&&(f._setEditorField(),f._step=1),f._bAdd.find(".ui-button-text").html(d.bAddCond)}),this._bAdd=g.find(".evo-bAdd").button({text:b,icons:{secondary:"ui-icon-check"}}).on("click",function(a){var b=f._getEditorData();f._cFilter?f._enableFilter(b,f.options.highlight):f.addCondition(b),f._removeEditor()}),this._bDel=g.find(".evo-bDel").button({text:b,icons:{secondary:"ui-icon-close"}}).on("click",function(a){f._removeEditor()}),this._editor=g.find(".evo-editFilter").on("change","#field",function(b){b.stopPropagation(),f._step>2&&f._editor.find("#value,#value2,.as-Txt").remove(),f._step>1&&(f._editor.find("#operator").remove(),f._bAdd.hide()),f._step=1;var d=a(b.currentTarget).val();if(""!==d){f._field=f._getFieldById(d);var e=f._type=f._field.type;f._setEditorOperator(),(e===c.bool||e.startsWith("list"))&&f._setEditorValue()}else f._field=f._type=null}).on("change","#operator",function(b){b.stopPropagation(),f._operator=a(this).val(),f._step>2&&(f._editor.find("#value,#value2,.as-Txt").remove(),f._bAdd.hide(),f._step=2),f._setEditorValue()}).on("change keyup","#value,#value2",function(b){b.stopPropagation();var d=f._type,g=a(this).val(),h=""!==g||d===c.bool||d.startsWith("list");d==c.number?h=h&&!isNaN(g):f._operator==e.sBetween&&(h=""!==f._editor.find("#value").val()&&""!==f._editor.find("#value2").val()),h?(f._bAdd.button("enable"),13==b.which&&f._bAdd.trigger("click")):f._bAdd.button("disable")}).on("click","#checkAll",function(){var b=a(this),c=b.prop("checked");allChecks=b.siblings().prop("checked",c)}),this._filters=g.find(".evo-searchFilters").on("click","a",function(){f._editFilter(a(this))}).on("click","a .ui-button-icon-secondary",function(b){b.stopPropagation();var c=a(this).parent();c.hasClass("ui-state-disabled")||c.fadeOut("slow",function(){c.remove(),f._triggerChange()})})},_getFieldById:function(a){if(!this._hash){this._hash={};for(var b=this.options.fields,c=0,d=b.length;c'+this._htmlFilter(b)+"").prependTo(this._filters).button({icons:{secondary:"ui-icon-close"}}).data("filter",b).fadeIn();return this.options.highlight&&c.effect("highlight"),this._triggerChange(),this._bSubmit&&this._bSubmit.removeClass("ui-state-active").show(),this},removeCondition:function(a){return this._filters.children().eq(a).remove(),this._triggerChange(),this},_htmlFilter:function(a){var b=''+a.field.label+' '+a.operator.label+' '+a.value.label+"";return a.operator.value==e.sBetween&&(b+=' '+d.opAnd+' '+a.value.label2+""),b},_enableFilter:function(a,b){this._cFilter&&(this._cFilter.button("enable").removeClass("ui-state-hover ui-state-active"),b&&this._cFilter.effect("highlight"),a?(this._cFilter.data("filter",a).find(":first-child").html(this._htmlFilter(a)),this._cFilter=null,this._triggerChange()):this._cFilter=null)},_editFilter:function(a){var b=a.data("filter"),c=b.field.value,f=b.operator.value,g=b.value;this._enableFilter(null,!1),this._removeEditor(),this._cFilter=a.button("disable"),this._setEditorField(c),this._setEditorOperator(f),f==e.sBetween?this._setEditorValue(g.value,g.value2):this._setEditorValue(g.value),this._bAdd.find(".ui-button-text").html(d.bUpdateCond),this._step=3},_setEditorField:function(b){if(this._step<1){if(this._bNew.stop().hide(),this._bSubmit&&this._bSubmit.stop().hide(),this._bDel.show(),!this._fList){var c='",this._fList=c}a(this._fList).appendTo(this._editor).focus()}b&&(this._field=this._getFieldById(b),this._type=this._field.type,this._editor.find("#field").val(b)),this._step=1},_setEditorOperator:function(a){var b=this._type;if(this._step<2){var f="",h=g.inputOption;switch(b){case c.list:f+=g.inputHidden("operator",e.sInList),this._operator=e.sInList;break;case c.listOpts:case c.listDropdown:case c.bool:f+=g.inputHidden("operator",e.sEqual),this._operator=e.sEqual;break;default:switch(f+='"}this._editor.append(f)}a&&b!=c.list&&(this._editor.find("#operator").val(a),this._operator=a),this._step=2},_setEditorValue:function(a,b){var f=this._editor,h=this._field,i=this._type,j=f.find("#operator").val(),k=!1,l=!0;if(""!==j){if(i==c.list||j!=e.sIsNull&&j!=e.sIsNotNull){if(this._step<3){var m="";switch(k=j==e.sBetween,i){case c.bool:m+=''+g.inputRadio("value","1",d.yes,"0"!=a,"value1")+g.inputRadio("value","0",d.no,"0"==a,"value0")+"";break;case c.list:m+=''+(h.list.length>7?'() ':"")+g.inputCheckboxes(h.list)+"";break;case c.listOpts:m+='',m+=h.list.map(function(b){return g.inputRadio(h.id,b.id,b.label,a==b.id,"value"+b.id)}).join(""),m+="";break;case c.listDropdown:m+='";break;case c.date:case c.time:case c.number:var n=i==c.date?"text":i;m+='',k&&(m+=''+d.opAnd+' '),l=!1;break;default:m+='',l=!1}f.append(m),i==c.date&&f.find("#value,#value2").datepicker({dateFormat:this.options.dateFormat})}if(a){var o=f.find("#value");switch(i){case c.list:o.find("#"+a.split(",").join(",#")).prop("checked","checked");break;case c.listOpts:case c.bool:o.find("#value"+a).prop("checked","checked");break;default:o.val(a),l=""!==a,k&&(o.next().next().val(b),l=""!==a&&""!==b)}}else l=i==c.list||i==c.listDropdown||i==c.bool}else f.append(g.inputHidden("value",""));this._bAdd.button(l?"enable":"disable").show(),this._step=3}},_getEditorData:function(){var a=this._editor,b=a.find("#field"),f=a.find("#value"),g={field:{label:b.find("option:selected").text(),value:b.val()},operator:{},value:{}},h=g.operator,i=g.value;if(this._type==c.list){var j=[],k=[];f.find("input:checked").not("#checkAll").each(function(){j.push(this.value),k.push(this.nextSibling.innerHTML)}),0===j.length?(h.label=d.sIsNull,h.value=e.sIsNull,i.label=i.value=""):1==j.length?(h.label=d.sEqual,h.value=e.sEqual,i.label='"'+k[0]+'"',i.value=j[0]):(h.label=d.sInList,h.value=e.sInList,i.label="("+k.join(", ")+")",i.value=j.join(","))}else if(this._type==c.bool){h.label=d.sEqual,h.value=e.sEqual;var l=f.find("#value1").prop("checked")?1:0;i.label=1==l?d.yes:d.no,i.value=l}else if(this._type==c.listOpts){h.label=d.sEqual,h.value=e.sEqual;var m=f.find("input:checked");i.label=m.parent().text(),i.value=m.prop("id").slice(5)}else if(this._type==c.listDropdown){h.label=d.sEqual,h.value=e.sEqual;var n=f.val();i.label=n?f.find("option[value="+n+"]").text():d.sIsNull,i.value=f.val()}else{var o=a.find("#operator"),p=o.val();h.label=o.find("option:selected").text(),h.value=p,p==e.sIsNull||p==e.sIsNotNull?i.label=i.value="":(this._type==c.number||this._type==c.date||this._type==c.time?i.label=f.val():i.label='"'+f.val()+'"',i.value=f.val(),p==e.sBetween&&(i.label2=i.value2=f.next().next().val()))}return g},_hiddenValue:function(a,b,c){a.push(g.inputHidden("fld-"+c,b.field.value)+g.inputHidden("op-"+c,b.operator.value)+g.inputHidden("val-"+c,b.value.value));var d=b.value.value2;d&&a.push(g.inputHidden("val2-"+c,d))},_setHiddenValues:function(){for(var a=this.val(),b=a.length,c=[g.inputHidden("elem",b)],d=0;d'+c+" "},inputHidden:function(a,b){return''},inputOption:function(a,b){return'"},optNull:'',inputCheckboxes:function(a){return a.map(function(a){return' "}).join("")}}}(jQuery); \ No newline at end of file diff --git a/package.json b/package.json index 2e6bc5c..0ea8ded 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "structured-filter", - "version": "1.0.11", + "version": "1.1.0", "description": "Generic Web UI for building structured search or filter queries. With it you can build structured search conditions like Firstname starts with 'A' and Birthday after 1/1/1990 and State in (CA, NY, FL)...", "copyright": "(c) 2017 Olivier Giulieri", "homepage": "http://evoluteur.github.io/structured-filter/",