sonarr-repo-only/NzbDrone.Web/Scripts/2011.1.315/telerik.grid.min.js

1 line
18 KiB
JavaScript

(function(c){var g=c.telerik;var a=/"\\\/Date\((.*?)\)\\\/"/g;function d(h){return new Function("data",("var p=[];with(data){p.push('"+unescape(h).replace(/[\r\t\n]/g," ").replace(/'(?=[^#]*#>)/g,"\t").split("'").join("\\'").split("\t").join("'").replace(/<#=(.+?)#>/g,"',$1,'").split("<#").join("');").split("#>").join("p.push('")+"');}return p.join('');"))}function f(h){return(h!=null?h+"":"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}g.grid=function(h,j){this.element=h;this.groups=[];this.editing={};this.filterBy="";this.groupBy="";this.orderBy="";c.extend(this,j);this.sorted=c.grep(this.columns,function(i){return i.order});this.$tbody=c("> .t-grid-content > table > tbody",h);this.scrollable=this.$tbody.length>0;if(!this.scrollable){this.$tbody=c("> table > tbody",h);this.$header=c("> table > thead tr",h);this.$footer=c("> table > tfoot",h)}else{c("> .t-grid-content",h).tScrollable();this.$header=c("> .t-grid-header tr",h);this.$footer=c("> .t-grid-footer",h)}this.$headerWrap=c("> .t-grid-header > .t-grid-header-wrap",h);this.$footerWrap=c("> .t-grid-footer > .t-grid-footer-wrap",h);var o=this.$headerWrap.add(this.$footerWrap);c("> .t-grid-content",h).bind("scroll",function(){o.scrollLeft(this.scrollLeft)});this.$tbody.delegate(".t-hierarchy-cell .t-plus, .t-hierarchy-cell .t-minus","click",g.stopAll(function(s){var r=c(s.target);var q=r.hasClass("t-plus");r.toggleClass("t-minus",q).toggleClass("t-plus",!q);var i=r.closest("tr.t-master-row");if(this.detail&&!i.next().hasClass("t-detail-row")){c(new g.stringBuilder().cat('<tr class="t-detail-row">').rep('<td class="t-group-cell"></td>',i.find(".t-group-cell").length).cat('<td class="t-hierarchy-cell"></td>').cat('<td class="t-detail-cell" colspan="').cat(this.$header.find("th:not(.t-group-cell,.t-hierarchy-cell):visible").length).cat('">').cat(this.displayDetails(this.dataItem(i))).cat("</td></tr>").string()).insertAfter(i)}g.trigger(this.element,q?"detailViewExpand":"detailViewCollapse",{masterRow:i[0],detailRow:i.next(".t-detail-row")[0]});i.next().toggle(q)},this));this.$pager=c("> .t-grid-pager .t-pager",h);var n=new g.dropDown({effects:g.fx.slide.defaults(),onClick:c.proxy(function(i){this.changePageSize(c(i.item).text());n.close()},this)});n.dataBind(j.pageSizesInDropDown||[]);c(document.documentElement).bind("mousedown",function(q){var i=n.$element[0];if(!c.contains(i,q.target)){n.close()}});this.$pager.delegate(".t-state-disabled","click",g.preventDefault).delegate(".t-link:not(.t-state-disabled)","mouseenter",g.hover).delegate(".t-link:not(.t-state-disabled)","mouseleave",g.leave).delegate("input[type=text]","keydown",c.proxy(this.pagerKeyDown,this)).delegate(".t-page-size .t-dropdown-wrap","click",function(){var i=c(this);n.open({offset:i.offset(),outerHeight:i.outerHeight(),outerWidth:i.outerWidth(),zIndex:g.getElementZIndex(this)})});c("> .t-grid-pager",h).delegate(".t-refresh","click",c.proxy(this.refreshClick,this));c(h).delegate(".t-button","hover",g.preventDefault);if(this.sort){this.$header.delegate(".t-link","hover",function(){c(this).toggleClass("t-state-hover")})}var p="tr:not(.t-grouping-row,.t-detail-row,.t-no-data,:has(>.t-edit-container))";if(this.selectable){var m=this.$tbody[0];var l=this;this.$tbody.delegate(p,"click",function(i){if(this.parentNode==m){l.rowClick(i)}}).delegate(p,"hover",function(){if(this.parentNode==m){c(this).toggleClass("t-state-hover")}})}if(this.isAjax()){this.$pager.delegate(".t-link:not(.t-state-disabled)","click",g.stop(this.pagerClick,this));if(this.sort){this.$header.delegate(".t-link","click",g.stop(this.headerClick,this))}}for(var k=0;k<this.plugins.length;k++){g[this.plugins[k]].initialize(this)}g.bind(this,{columnResize:this.onColumnResize,columnReorder:this.onColumnReorder,"delete":this.onDelete,detailViewExpand:this.onDetailViewExpand,detailViewCollapse:this.onDetailViewCollapse,dataBinding:this.onDataBinding,dataBound:this.onDataBound,edit:this.onEdit,error:this.onError,load:this.onLoad,rowSelect:this.onRowSelect,rowDataBound:this.onRowDataBound,save:this.onSave,submitChanges:this.onSubmitChanges});this.initializeColumns()};g.grid.prototype={rowClick:function(j){var i=c(j.target);if(!i.is(":button,a,:input,a>.t-icon")){j.stopPropagation();var h=i.closest("tr").addClass("t-state-selected").siblings().removeClass("t-state-selected").end();g.trigger(this.element,"rowSelect",{row:h[0]})}},$rows:function(){return this.$tbody.find("> tr:not(.t-grouping-row,.t-detail-row)")},expandRow:function(h){c(h).find("> td .t-plus, > td .t-expand").click()},collapseRow:function(h){c(h).find("> td .t-minus, > td .t-collapse").click()},headerClick:function(h){h.preventDefault();this.toggleOrder(this.$columns().index(c(h.target).closest("th")));this.sort(this.sortExpr())},refreshClick:function(i,h){if(c(h).is(".t-loading")){return}if(this.isAjax()){i.preventDefault();this.ajaxRequest(true)}},sort:function(h){this.orderBy=h;this.ajaxRequest()},columnFromTitle:function(i){i=c.trim(i);var h=c.grep(this.$columns(),function(j){return c.trim(c(j).text())==i})[0];if(h){return this.columns[this.$columns().index(h)]}return c.grep(this.columns,function(j){return j.title==i})[0]},columnFromMember:function(h){var i=c.grep(this.columns,function(j){return j.member==h})[0];if(!i){i=c.grep(this.columns,function(k){var j="."+k.member;return h.substr(h.length-j.length)==j})[0]}return i},toggleOrder:function(h){h=typeof h=="number"?this.columns[h]:h;var j="asc";if(h.order=="asc"){j="desc"}else{if(h.order=="desc"){j=null}}h.order=j;var i=c.inArray(h,this.sorted);if(this.sortMode=="single"&&i<0){c.each(this.sorted,function(){this.order=null});this.sorted=[]}if(i<0&&j){this.sorted.push(h)}if(!j){this.sorted.splice(i,1)}},sortExpr:function(){return c.map(this.sorted,function(h){return h.member+"-"+h.order}).join("~")},pagerKeyDown:function(h){if(h.keyCode==13){var i=this.sanitizePage(c(h.target).val());if(i!=this.currentPage){this.pageTo(i)}else{c(h.target).val(i)}}},isAjax:function(){return this.ajax||this.ws||this.onDataBinding},url:function(h){return(this.ajax||this.ws)[h]},pagerClick:function(m){m.preventDefault();var i=c(m.target).closest(".t-link");var j=this.currentPage;var k=i.find(".t-icon");if(k.hasClass("t-arrow-next")){j++}else{if(k.hasClass("t-arrow-last")){j=this.totalPages()}else{if(k.hasClass("t-arrow-prev")){j--}else{if(k.hasClass("t-arrow-first")){j=1}else{var h=i.text();if(h=="..."){var l=i.parent().children().index(i);if(l==0){j=parseInt(i.next().text())-1}else{j=parseInt(i.prev().text())+1}}else{j=parseInt(h)}}}}}this.pageTo(isFinite(j)?j:this.currentPage)},changePageSize:function(i){var h=parseInt(i,10);if(isNaN(h)||h<1){return this.pageSize}h=Math.max(h,1);this.pageSize=h;if(this.isAjax()){this.ajaxRequest()}else{this.serverRequest()}},pageTo:function(h){this.currentPage=h;if(this.isAjax()){this.ajaxRequest()}else{this.serverRequest()}},ajaxOptions:function(i){var h={type:"POST",dataType:"text",dataFilter:function(k,l){return k.replace(a,"new Date($1)")},error:c.proxy(function(l,k){if(g.ajaxError(this.element,"error",l,k)){return}},this),complete:c.proxy(this.hideBusy,this),success:c.proxy(function(l,m,k){try{l=eval("("+l+")")}catch(n){if(!g.ajaxError(this.element,"error",k,"parseeror")){alert("Error! The requested URL did not return JSON.")}return}l=l.d||l;if(i.hasErrors&&i.hasErrors(l)){if(!g.trigger(this.element,"error",{XMLHttpRequest:k,textStatus:"modelstateerror",modelState:l.modelState})){i.displayErrors(l)}return}this.total=l.total||l.Total||0;this.aggregates=l.aggregates||{};this.dataBind(l.data||l.Data)},this)};c.extend(h,i);var j=this.ws?h.data.state={}:h.data;j[this.queryString.page]=this.currentPage;j[this.queryString.size]=this.pageSize;j[this.queryString.orderBy]=this.orderBy||"";j[this.queryString.groupBy]=this.groupBy;j[this.queryString.filter]=(this.filterBy||"").replace(/\"/g,'\\"');j[this.queryString.aggregates]=c.map(this.columns,function(k){if(k.aggregates){return k.member+"-"+k.aggregates.join("-")}}).join("~");if(this.ws){h.data=g.toJson(h.data);h.contentType="application/json; charset=utf-8"}return h},showBusy:function(){this.busyTimeout=setTimeout(c.proxy(function(){c("> .t-grid-pager .t-status .t-icon",this.element).addClass("t-loading")},this),100)},hideBusy:function(){clearTimeout(this.busyTimeout);c("> .t-grid-pager .t-status .t-icon",this.element).removeClass("t-loading")},serverRequest:function(){location.href=g.formatString(unescape(this.urlFormat),this.currentPage,this.orderBy||"~",this.groupBy||"~",encodeURIComponent(this.filterBy)||"~",this.pageSize||"~")},ajaxRequest:function(i){var h={page:this.currentPage,sortedColumns:this.sorted,filteredColumns:c.grep(this.columns,function(j){return j.filters})};if(g.trigger(this.element,"dataBinding",h)){return}if(!this.ajax&&!this.ws){return}this.showBusy();c.ajax(this.ajaxOptions({data:c.extend({},h.data,i),url:this.url("selectUrl")}))},valueFor:function(h){if(h.type=="Date"){return new Function("data","var value = data."+h.member+'; if (!value) return null; return value instanceof Date? value : new Date(parseInt(value.replace(/\\/Date\\((.*?)\\)\\//, "$1")));')}return new Function("data","return data"+(h.member?"."+h.member:"")+";")},displayFor:function(h){var j=this.localization;if(h.commands){var k=c.map(h.commands,function(l){var m=g.grid.ButtonBuilder.create(c.extend({text:j[l.name]},l));return m.build()}).join("");return function(){return k}}if(!h.template){var i=h.value||function(){return""};if(h.format||h.type=="Date"){i=function(l){var m=h.value(l);return m==null?"":g.formatString(h.format||"{0:G}",m)}}return h.encoded===false?i:function(l){return f(i(l))}}return d(h.template)},insertFor:function(h){return this.displayFor(h)},editFor:function(h){return this.displayFor(h)},initializeColumns:function(){c.each(this.columns,c.proxy(function(h,i){if(i.member!==undefined){i.value=this.valueFor(i)}else{i.readonly=true}i.insert=this.insertFor(i);i.edit=this.editFor(i);i.display=this.displayFor(i);if(i.footerTemplate){i.footer=d(i.footerTemplate)}if(i.groupFooterTemplate){this.showGroupFooter=true;i.groupFooter=d(i.groupFooterTemplate)}i.groupHeader=d("<#= Title #>: <#= Key #>");if(i.groupHeaderTemplate){i.groupHeader=d(i.groupHeaderTemplate)}},this));if(this.detail){this.displayDetails=d(this.detail.template)}},bindData:function(j,l,n){Array.prototype.push.apply(this.data,j);var p=Math.min(this.pageSize,j.length);p=this.pageSize?p:j.length;if(c.browser.msie){c(this.element).find(".t-grid-content colgroup:first col").css("display","")}for(var q=0;q<p;q++){var h=c.trim((this.detail?"t-master-row":"")+(q%2==1?" t-alt":""));if(h){l.cat('<tr class="').cat(h).cat('">')}else{l.cat("<tr>")}l.rep('<td class="t-group-cell"></td>',n).catIf('<td class="t-hierarchy-cell"><a class="t-icon t-plus" href="#" /></td>',this.detail);for(var k=0,m=this.columns.length;k<m;k++){var o=this.columns[k];l.cat("<td").cat(o.attr).catIf(' class="t-last"',k==m-1).cat(">").cat(o.display(j[q]));l.cat("</td>")}l.cat("</tr>")}},normalizeColumns:function(){},dataItem:function(h){return this.data[this.$tbody.find("> tr:not(.t-grouping-row,.t-detail-row,.t-grid-new-row)").index(c(h))]},bindTo:function(n){var k=new g.stringBuilder();var m=this.groups.length+this.columns.length+(this.detail?1:0);if(n&&n.length){this.normalizeColumns(m);if(typeof n[0].HasSubgroups!="undefined"){for(var h=0,j=n.length;h<j;h++){this.bindGroup(n[h],m,k,0)}}else{this.bindData(n,k)}}else{k.cat("<tr class='t-no-data'>").cat("<td colspan='").cat(m).cat("'>").cat(this.noRecordsTemplate?this.noRecordsTemplate:this.localization.noRecords).cat("</td></tr>")}this.$tbody.html(k.string());if(this.onRowDataBound){var o=jQuery.grep(this.$tbody[0].rows,function(i){return !c(i).hasClass("t-grouping-row")});for(var h=0,j=this.data.length;h<j;h++){g.trigger(this.element,"rowDataBound",{row:o[h],dataItem:this.data[h]})}}},updatePager:function(){var h=this.totalPages(this.total);var j=this.currentPage;var k=this.pageSize;this.$pager.find(".t-arrow-next").parent().add(this.$pager.find(".t-arrow-last").parent()).toggleClass("t-state-disabled",j>=h).removeClass("t-state-hover");this.$pager.find(".t-arrow-prev").parent().add(this.$pager.find(".t-arrow-first").parent()).toggleClass("t-state-disabled",j==1).removeClass("t-state-hover");var i=this.localization;this.$pager.find(".t-page-i-of-n").each(function(){this.innerHTML=new g.stringBuilder().cat(i.page).cat('<input type="text" value="').cat(j).cat('" /> ').cat(g.formatString(i.pageOf,h)).string()});this.$pager.find(".t-page-size").each(function(){var l='<div style="width: 50px;" class="t-dropdown t-header"><div class="t-dropdown-wrap t-state-default"><span class="t-input">'+k+'</span><span class="t-select"><span class="t-icon t-arrow-down">select</span></span></div></div>';this.innerHTML=l});this.$pager.find(".t-numeric").each(c.proxy(function(m,l){this.numericPager(l,j,h)},this));this.$pager.parent().find(".t-status-text").text(g.formatString(i.displayingItems,this.firstItemInPage(),this.lastItemInPage(),this.total))},numericPager:function(i,o,p){var m=10;var k=1;if(o>m){var h=(o%m);k=(h==0)?(o-m)+1:(o-h)+1}var l=(k+m)-1;l=Math.min(l,p);var j=new g.stringBuilder();if(k>1){j.cat('<a class="t-link">...</a>')}for(var n=k;n<=l;n++){if(n==o){j.cat('<span class="t-state-active">').cat(n).cat("</span>")}else{j.cat('<a class="t-link">').cat(n).cat("</a>")}}if(l<p){j.cat('<a class="t-link">...</a>')}i.innerHTML=j.string()},$columns:function(){return this.$header.find("th:not(.t-hierarchy-cell,.t-group-cell)")},updateSorting:function(){this.sorted=[];c.each(this.orderBy.split("~"),c.proxy(function(i,h){var j=h.split("-");var k=this.columnFromMember(j[0]);if(k){k.order=j[1];this.sorted.push(k)}},this));this.$columns().each(c.proxy(function(j,m){var k=this.columns[j].order;var h=c(m).children(".t-link");var l=h.children(".t-icon");if(!k){l.hide()}else{if(l.length==0){l=c('<span class="t-icon"/>').appendTo(h)}l.toggleClass("t-arrow-up",k=="asc").toggleClass("t-arrow-down",k=="desc").html("("+(k=="asc"?this.localization.sortedAsc:this.localization.sortedDesc)+")").show()}},this))},sanitizePage:function(i){var h=parseInt(i,10);if(isNaN(h)||h<1){return this.currentPage}return Math.min(h,this.totalPages())},totalPages:function(){return Math.ceil(this.total/this.pageSize)},firstItemInPage:function(){return this.total>0?(this.currentPage-1)*this.pageSize+1:0},lastItemInPage:function(){return Math.min(this.currentPage*this.pageSize,this.total)},dataBind:function(h){this.data=[];this.bindTo(h);this.bindFooter();this.updatePager();this.updateSorting();g.trigger(this.element,"dataBound");g.trigger(this.element,"repaint")},bindFooter:function(){var i=this.$footer.find("td:not(.t-group-cell,.t-hierarchy-cell)");var h=this.aggregates;c.each(this.columns,function(j){if(this.footer){i.eq(j).html(this.footer(h[this.member]))}})},rebind:function(h){this.sorted=[];this.orderBy="";this.filterBy="";this.currentPage=1;c.each(this.columns,function(){this.order=null;this.filters=null});c(".t-filter-options",this.element).find('input[type="text"], select').val("").removeClass("t-state-error").end().find("div.t-formatted-value").html("");c(".t-grid-filter",this.element).removeClass("t-active-filter");this.ajaxRequest(h)}};g.grid.ButtonBuilder=function(h){this.classNames=["t-button","t-grid-"+h.name];this.content=function(){return h.text};this.build=function(){return'<a href="#" class="'+this.classNames.join(" ")+'" '+(h.attr?h.attr:"")+">"+this.content()+"</a>"}};g.grid.ButtonBuilder.create=function(h){return new (e[h.buttonType])(h)};function b(i,h){return'<span class="t-icon t-'+i+'"'+(h?h:"")+"></span>"}g.grid.ImageButtonBuilder=function(h){g.grid.ButtonBuilder.call(this,h);this.classNames.push("t-button-icon");this.content=function(){return b(h.name,h.imageAttr)}};g.grid.ImageTextButtonBuilder=function(h){g.grid.ButtonBuilder.call(this,h);this.classNames.push("t-button-icontext");this.content=function(){return'<span class="t-icon t-'+h.name+'"'+(h.imageAttr?h.imageAttr:"")+"></span>"+h.text}};g.grid.BareImageButtonBuilder=function(h,i){g.grid.ImageButtonBuilder.call(this,h,i);this.classNames.push("t-button-icon","t-button-bare")};var e={Text:g.grid.ButtonBuilder,ImageAndText:g.grid.ImageTextButtonBuilder,Image:g.grid.ImageButtonBuilder,BareImage:g.grid.BareImageButtonBuilder};c.fn.tGrid=function(h){return g.create(this,{name:"tGrid",init:function(i,j){return new g.grid(i,j)},options:h,success:function(i){if(i.$tbody.find("tr.t-no-data").length){i.ajaxRequest()}}})};c.fn.tGrid.defaults={columns:[],plugins:[],currentPage:1,pageSize:10,localization:{addNew:"Add new record","delete":"Delete",cancel:"Cancel",insert:"Insert",update:"Update",select:"Select",pageOf:"of {0}",displayingItems:"Displaying items {0} - {1} of {2}",edit:"Edit",noRecords:"No records to display.",page:"Page ",filter:"Filter",filterClear:"Clear Filter",filterShowRows:"Show rows with value that",filterAnd:"And",filterStringEq:"Is equal to",filterStringNe:"Is not equal to",filterStringStartsWith:"Starts with",filterStringSubstringOf:"Contains",filterStringEndsWith:"Ends with",filterNumberEq:"Is equal to",filterNumberNe:"Is not equal to",filterNumberLt:"Is less than",filterNumberLe:"Is less than or equal to",filterNumberGt:"Is greater than",filterNumberGe:"Is greater than or equal to",filterDateEq:"Is equal to",filterDateNe:"Is not equal to",filterDateLt:"Is before",filterDateLe:"Is before or equal to",filterDateGt:"Is after",filterDateGe:"Is after or equal to",filterEnumEq:"Is equal to",filterEnumNe:"Is not equal to",filterBoolIsTrue:"is true",filterBoolIsFalse:"is false",filterSelectValue:"-Select value-",filterOpenPopupHint:"Open the calendar popup",groupHint:"Drag a column header and drop it here to group by that column",deleteConfirmation:"Are you sure you want to delete this record?",sortedAsc:"sorted ascending",sortedDesc:"sorted descending",ungroup:"ungroup"},queryString:{page:"page",size:"size",orderBy:"orderBy",groupBy:"groupBy",filter:"filter",aggregates:"aggregates"}}})(jQuery);