mirror of https://github.com/Radarr/Radarr
1 line
7.7 KiB
JavaScript
1 line
7.7 KiB
JavaScript
(function(c){var b=c.telerik;var e=/'/ig;var d=b.fx.slide.defaults();b.scripts.push("telerik.grid.filtering.js");function f(g){if(!g.format){return b.cultureInfo.shortDate}return/\{0(:([^\}]+))?\}/.exec(g.format)[2]}function a(h,g){if(h.type=="Date"){return b.formatString(h.format||"{0:G}",new Date(parseInt(g.replace(/\/Date\((.*?)\)\//,"$1"))))}return g}b.filtering={};b.filtering.initialize=function(g){c.extend(g,b.filtering.implementation);g.filterBy=g.filterExpr();c("> .t-grid-content",g.element).bind("scroll",function(){g.hideFilter()});c(document).click(function(h){if(h.which!=3){g.hideFilter()}});g.$header.find(".t-grid-filter").click(c.proxy(g.showFilter,g)).hover(function(){c(this).toggleClass("t-state-hover")})};b.filtering.implementation={createFilterCommands:function(h,g){var j={};c.each(this.localization,function(n,k){var l="filter"+g.type;var m=n.indexOf(l);if(m>-1){j[n.substring(m+l.length).toLowerCase()]=k}});if(g.type=="String"){var i=j.endswith;delete j.endswith;j.endswith=i}h.cat('<select class="t-filter-operator">');c.each(j,function(k,l){h.cat('<option value="').cat(k).cat('">').cat(l).cat("</option>")});h.cat("</select>")},createTypeSpecificInput:function(j,g,h,i){if(g.type=="Date"){j.cat('<div class="t-widget t-datepicker"><div class="t-picker-wrap">').cat('<input class="t-input" id="').cat(h).cat('" type="text" value="" />').cat('<span class="t-select"><label class="t-icon t-icon-calendar" for="').cat(h).cat('" title="').cat(this.localization.filterOpenPopupHint).cat('" /></span></div></div>')}else{if(g.type=="Boolean"){j.cat('<div><input type="radio" style="width:auto;display:inline" id="').cat(h+i).cat('" name="').cat(h).cat('" value="').cat(i).cat('" />').cat('<label style="display:inline" for="').cat(h+i).cat('">').cat(this.localization[i?"filterBoolIsTrue":"filterBoolIsFalse"]).cat("</label></div>")}else{if(g.type=="Enum"){j.cat("<div><select><option>").cat(this.localization.filterSelectValue).cat("</option>");c.each(g.values,function(k,l){j.cat('<option value="').cat(l).cat('">').cat(k).cat("</option>")});j.cat("</select></div>")}else{if(g.type=="Number"){j.cat('<div class="t-widget t-numerictextbox">').cat('<input class="t-input" name="').cat(h).cat('" id="').cat(h).cat('" type="text" value=""/>').cat("</div>")}else{j.cat('<input type="text" />')}}}}},createFilterMenu:function(g){var j=new b.stringBuilder();j.cat('<div class="t-animation-container"><div class="t-filter-options t-group t-popup" style="display:none">').cat('<button class="t-button t-button-icontext t-button-expand t-clear-button"><span class="t-icon t-clear-filter"></span>').cat(this.localization.filterClear).cat('</button><div class="t-filter-help-text">').cat(this.localization.filterShowRows).cat("</div>");var h=c(this.element).attr("id")+g.member;if(g.type=="Boolean"){this.createTypeSpecificInput(j,g,h,true);this.createTypeSpecificInput(j,g,h,false)}else{this.createFilterCommands(j,g);this.createTypeSpecificInput(j,g,h+"first");j.cat('<div class="t-filter-help-text">').cat(this.localization.filterAnd).cat("</div>");this.createFilterCommands(j,g);this.createTypeSpecificInput(j,g,h+"second")}j.cat('<button class="t-button t-button-icontext t-button-expand t-filter-button"><span class="t-icon t-filter"></span>').cat(this.localization.filter).cat("</button></div></div>");var i=c(j.string());c.each(g.filters||[],function(k){i.find(".t-filter-operator:eq("+k+")").val(this.operator).end().find(":text:eq("+k+"),select:not(.t-filter-operator):eq("+k+")").val(a(g,this.value));if(g.type=="Boolean"){i.find(":radio[id$="+this.value+"]").attr("checked",true)}});return i.appendTo(this.element).find(".t-datepicker .t-input").each(function(){c(this).tDatePicker({format:f(g)})}).end().find(".t-numerictextbox .t-input").each(function(){c(this).tTextBox({type:"numeric",minValue:null,maxValue:null,numFormat:"",groupSeparator:""})}).end()},showFilter:function(m){m.stopPropagation();var g=c(m.target).closest(".t-grid-filter");this.hideFilter(function(){return this.parentNode!=g[0]});var k=g.data("filter");if(!k){var h=this.columns[this.$columns().index(g.parent())];k=this.createFilterMenu(h).data("column",h).click(function(p){p.stopPropagation();if(c(p.target).parents(".t-datepicker").length==0){c(".t-datepicker .t-input",this).each(function(){c(this).data("tDatePicker").hidePopup()})}}).find(".t-filter-button").click(c.proxy(this.filterClick,this)).end().find(".t-clear-button").click(c.proxy(this.clearClick,this)).end().find("input[type=text]").keyup(c.proxy(function(p){if(p.keyCode==13){this.filterClick(p)}},this)).end();g.data("filter",k)}var l=0;c(this.element).find("> .t-grouping-header, > .t-grid-toolbar").add(this.$header).each(function(){l+=this.offsetHeight});var i={top:l};var n=-this.$headerWrap.scrollLeft()-1;g.parent().add(g.parent().prevAll("th")).each(function(){if(c(this).css("display")!="none"){n+=this.offsetWidth}});var j=n-g.outerWidth();var o=k.outerWidth()||k.find(".t-group").outerWidth();if(j+o>this.$header.outerWidth()){j=n-o+1}if(c(this.element).closest(".t-rtl").length){i.right=j+(c.browser.mozilla||c.browser.safari?18:0)}else{i.left=j}k.css(i);b.fx[k.find(".t-filter-options").is(":visible")?"rewind":"play"](d,k.find(".t-filter-options"),{direction:"bottom"})},hideFilter:function(g){g=g||function(){return true};c(".t-grid .t-animation-container").find(".t-datepicker .t-input").each(function(){c(this).data("tDatePicker").hidePopup()}).end().find(".t-filter-options").filter(g).each(function(){b.fx.rewind(d,c(this),{direction:"bottom"})})},clearClick:function(i){i.preventDefault();var h=c(i.target);var g=h.closest(".t-animation-container").data("column");g.filters=null;h.parent().find("input").removeAttr("checked").removeClass("t-state-error").not(":radio").val("").end().end().find("select").removeClass("t-state-error").find("option:first").attr("selected","selected");this.filter(this.filterExpr())},filterClick:function(j){j.preventDefault();var i=c(j.target);var g=i.closest(".t-animation-container").data("column");g.filters=[];var h=false;i.closest(".t-filter-options").find("input[type=text]:visible,select:not(.t-filter-operator)").each(c.proxy(function(p,n){var l=c(n);var k=c.trim(l.val());if(!k){l.removeClass("t-state-error");return true}var m=this.isValidFilterValue(g,k);l.toggleClass("t-state-error",!m);if(!m){h=true;return true}var o=l.prev("select").val()||l.parent().prev("select").val()||l.parent().parent().prev("select").val();if(k!=this.localization.filterSelectValue){g.filters.push({operator:o,value:k})}},this));i.parent().find("input:checked").each(c.proxy(function(m,l){var n=c(l);var k=c(l).attr("value");g.filters.push({operator:"eq",value:k})},this));if(!h){if(g.filters.length>0){this.filter(this.filterExpr())}else{g.filters=null}this.hideFilter()}},isValidFilterValue:function(g,h){if(g.type=="Date"){var i;if(h.indexOf("Date(")>-1){i=new Date(parseInt(h.replace(/^\/Date\((.*?)\)\/$/,"$1")))}else{i=b.datetime.parse({value:h,format:f(g)})}return i!=undefined}return true},encodeFilterValue:function(g,h){switch(g.type){case"String":return"'"+h.replace(e,"''")+"'";case"Date":var i;if(h.indexOf("Date(")>-1){i=new Date(parseInt(h.replace(/^\/Date\((.*?)\)\/$/,"$1")))}else{i=b.datetime.parse({value:h,format:f(g)}).toDate()}return"datetime'"+b.formatString("{0:yyyy-MM-ddTHH-mm-ss}",i)+"'"}return h},filterExpr:function(){var h=[];for(var g=0;g<this.columns.length;g++){var k=this.columns[g];if(k.filters){for(var j=0;j<k.filters.length;j++){var i=k.filters[j];h.push(new b.stringBuilder().cat(k.member).cat("~").cat(i.operator).cat("~").cat(this.encodeFilterValue(k,i.value)).string())}}}return h.join("~and~")},filter:function(g){this.currentPage=1;this.filterBy=g;if(this.isAjax()){this.$columns().each(c.proxy(function(i,h){c(".t-grid-filter",h).toggleClass("t-active-filter",!!this.columns[i].filters)},this));this.ajaxRequest()}else{this.serverRequest()}}}})(jQuery); |