1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-14 15:03:42 +01:00
Radarr/NzbDrone.Web/Scripts/2011.3.1115/telerik.grid.min.js
2011-11-22 17:51:44 -08:00

1 line
37 KiB
JavaScript

(function(a,m){var g={TAB:9,ENTER:13,ESC:27,LEFT:37,UP:38,RIGHT:39,DOWN:40,SPACEBAR:32,PAGEUP:33,PAGEDOWN:34,F12:123};var b=a.telerik;var i=/"+\\\/Date\((.*?)\)\\\/"+/g;var j="tr:not(.t-grouping-row,.t-group-footer,.t-detail-row,.t-no-data,.t-footer-template):visible",d=">td:not(.t-group-cell,.t-hierarchy-cell):visible",f=j+d+":first";FOCUSED="t-state-focused";b.scripts.push("telerik.grid.js");function l(n){return new Function("data",("var p=[];with(data){p.push('"+unescape(n).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 e(n){return(n!=null?n+"":"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function h(p,r,q){var n=a("<col />").css("width",r[q].width),s,t,o=0;for(s=0,t=r.length;s<t;s++){if(s>=q&&o){break}if(!r[s].hidden){o++}}if(s>q){p.eq(o-1).before(n)}else{p.eq(o-1).after(n)}}b.grid=function(o,u){this.element=o;this.groups=[];this.editing={};this.filterBy="";this.groupBy="";this.orderBy="";a.extend(this,u);this.sorted=a.grep(this.columns,function(x){return x.order});this.$tbody=a("> .t-grid-content > table > tbody",o);this.scrollable=this.$tbody.length>0;if(!this.scrollable){this.$tbody=a("> table > tbody",o);this.$header=a("> table > thead > tr",o);this.$footer=a("> table > tfoot",o)}else{a("> .t-grid-content",o).tScrollable();this.$header=a("> .t-grid-header > .t-grid-header-wrap > table > tbody > tr",o);this.$footer=a("> .t-grid-footer",o);var r=a(o).closest(".t-rtl").length;if(r){if(a.browser.webkit||(a.browser.mozilla&&parseInt(a.browser.version,10)<2)){a(o).addClass("t-grid-rightscroll")}}var s=(/iphone|ipad|android/gi).test(navigator.appVersion);if(s){a(".t-grid-header",o).css("padding","0").find(".t-grid-header-wrap").css("width","auto")}}this.$headerWrap=a("> .t-grid-header > .t-grid-header-wrap",o);this.$footerWrap=a("> .t-grid-footer > .t-grid-footer-wrap",o);var v=this.$headerWrap.add(this.$footerWrap);var p=this;a("> .t-grid-content",o).bind("scroll",function(){if(p.pageOnScroll){var x=this.scrollTop+this.clientHeight;if(x===this.scrollHeight&&p.currentPage<p.totalPages()&&!p._pagingInProgress){p._pagingInProgress=true;p.pageTo(p.currentPage+1)}}v.scrollLeft(this.scrollLeft)});if(this.rowTemplate){this.rowTemplate=l(this.rowTemplate)}this.$tbody.delegate(".t-hierarchy-cell .t-plus, .t-hierarchy-cell .t-minus","click",b.stopAll(function(A){var x=a(A.target);var C=x.hasClass("t-plus");x.toggleClass("t-minus",C).toggleClass("t-plus",!C);var y=x.closest("tr.t-master-row");if(this.detail&&!y.next().hasClass("t-detail-row")){var z=0;a.each(this.columns,function(){if(!this.hidden){z++}});a(new b.stringBuilder().cat('<tr class="t-detail-row').catIf(" t-alt",y.hasClass("t-alt")).cat('">').rep('<td class="t-group-cell"></td>',y.find(".t-group-cell").length).cat('<td class="t-hierarchy-cell"></td>').cat('<td class="t-detail-cell" colspan="').cat(z).cat('">').cat(this.displayDetails(this.dataItem(y))).cat("</td></tr>").string()).insertAfter(y)}b.trigger(this.element,C?"detailViewExpand":"detailViewCollapse",{masterRow:y[0],detailRow:y.next(".t-detail-row")[0]});y.next().toggle(C)},this));this.$pager=a("> .t-grid-pager .t-pager",o);var n=new b.dropDown({effects:b.fx.slide.defaults(),onClick:a.proxy(function(x){this.changePageSize(a(x.item).text());n.close()},this)});a(o).delegate(".t-button","click",a.proxy(function(x){this._command(x)},this));n.dataBind(u.pageSizesInDropDown||[]);a(document.documentElement).bind("mousedown",function(x){var y=n.$element[0];if(!a.contains(y,x.target)){n.close()}});this.$pager.delegate(".t-state-disabled","click",b.preventDefault).delegate(".t-link:not(.t-state-disabled)","mouseenter",b.hover).delegate(".t-link:not(.t-state-disabled)","mouseleave",b.leave).delegate("input[type=text]","keydown",a.proxy(this.pagerKeyDown,this)).delegate(".t-page-size .t-dropdown-wrap","click",function(){var x=a(this);n.open({offset:x.offset(),outerHeight:x.outerHeight(),outerWidth:x.outerWidth(),zIndex:b.getElementZIndex(this)})});a("> .t-grid-pager",o).delegate(".t-refresh","click",a.proxy(this.refreshClick,this));a(o).delegate(".t-button","hover",b.preventDefault);if(this.sort){this.$header.delegate("a.t-link","hover",function(){a(this).toggleClass("t-state-hover")})}var t="tr:not(.t-grouping-row,.t-detail-row,.t-no-data,.t-group-footer,:has(>.t-edit-container))";if(this.selectable){var w=this.$tbody[0];this.$tbody.delegate(t,"click",function(x){if(this.parentNode==w){p.rowClick(x)}}).delegate(t,"hover",function(x){if(this.parentNode==w){if(x.type=="mouseenter"){a(this).addClass("t-state-hover")}else{a(this).removeClass("t-state-hover")}}})}if(this.isAjax()||this.operationMode==="client"){this.$pager.delegate(".t-link:not(.t-state-disabled)","click",b.stop(this.pagerClick,this));if(this.sort){this.$header.delegate("a.t-link","click",b.stop(this.headerClick,this))}}for(var q=0;q<this.plugins.length;q++){b[this.plugins[q]].initialize(this)}b.bind(this,{columnResize:this.onColumnResize,columnReorder:this.onColumnReorder,command:this.onCommand,complete:this.onComplete,"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();if(this.keyboardNavigation){this.initializeNavigation()}if(this.isAjax()||this.operationMode==="client"){this._dataSource()}if(this.columnContextMenu){this.initializeContextMenu()}};b.grid.prototype={initializeNavigation:function(){var q=this,n=a(q.element).attr("tabIndex",0),o="keydown",p=a.proxy(q._keyDown,q);q._initNavigationMouseEvents();n.bind({focus:function(s){var r=q.current();if(r){r.addClass(FOCUSED)}else{if(r=q.$tbody.find("td."+FOCUSED).eq(0),r.length){q._current=r}else{q.current(n.find(f))}}},focusout:function(){if(q._current){q._current.removeClass(FOCUSED)}},keydown:p});if(q.editing&&q.editing.mode=="PopUp"){n.bind("edit",function(r){a(r.form).bind(o,p)});a("#"+q.formId()+":visible").bind(o,p)}if(q.pageOnScroll){n.bind("dataBinding",function(){var s=q.current(),t=s?s.parent().index(j)-1:0,r=s?s.index():0;n.one("dataBound",function(){var u=q.$tbody.find(j);q._focusGridElement();if(q._current){q._current.removeClass(FOCUSED)}q._current=u.eq(t).children().eq(r).addClass(FOCUSED)})})}},_onCommand:function(n){if(n.row){n.dataItem=this.dataItem(n.row)}return b.trigger(this.element,"command",n)},_onComplete:function(n){return b.trigger(this.element,"complete",n)},_command:function(p){var o=a(p.currentTarget);if(o.is(".t-ajax")){var q=/t-grid-([^\s]*)/.exec(o.attr("class"));if(q){q=q[1]}var n={name:q,row:o.closest("tr")[0]};p.preventDefault();if(this._onCommand(n)){return}a.ajax(this.ajaxOptions({url:o.attr("href"),data:n.data||{},success:a.proxy(function(r){try{r=eval("("+r+")")}catch(s){if(!b.ajaxError(this.element,"error",xhr,"parseeror")){alert("Error! The requested URL did not return JSON.")}return}this._onComplete({name:q,response:r})},this)}))}},_keyDown:function(t){var F=this,v=a(F.element),E=F.$tbody,y=v.closest(".t-rtl").length,z=t.keyCode,s="dataBound",r=a.proxy(F.current,F),q=r(),A=F.$pager.length>0,p=F.selectable,C=E.has("tr>td>.t-grid-select").length>0,D=a(t.target),n=!D.is(":button,a,:input,a>.t-icon"),u=F.editRow,x=false,o;if(!q){if(F.editing&&F.editing.mode=="PopUp"){q=F._current=v.find(f)}else{return}}o=q.index();if(!a.browser.msie){n=n&&D[0]===v[0]}if(n){if(A&&g.PAGEDOWN==z){if(!F.pageOnScroll){v.one(s,function(){r(v.find(f));F._focusGridElement()})}if(F.currentPage<F.totalPages()){F.pageTo(F.currentPage+1)}x=true}else{if(A&&g.PAGEUP==z){if(!F.pageOnScroll){v.one(s,function(){r(v.find(f));F._focusGridElement()});if(F.currentPage>1){F.pageTo(Math.max(F.currentPage-1,1))}}x=true}else{if(g.UP===z){r(q?q.parent().prevAll(j).last().children(":eq("+o+"),:eq(0)").last():v.find(f));x=true}else{if(g.DOWN===z){r(q?q.parent().nextAll(j).first().children(":eq("+o+"),:eq(0)").last():v.find(f));x=true}else{if(g.LEFT===z){if(q){if(y){q=q.nextAll(":visible:first")}else{q=q.prevAll(":not(.t-group-cell, .t-hierarchy-cell):visible:first")}}else{q=v.find(f)}r(q);x=true}else{if(g.RIGHT===z){if(q){if(y){q=q.prevAll(":not(.t-group-cell, .t-hierarchy-cell):visible:first")}else{q=q.nextAll(":visible:first")}}else{q=v.find(f)}r(q);x=true}else{if((p||C)&&g.SPACEBAR==z){x=true;var w=q.parent().find(".t-grid-select:first").andSelf();if(C&&w[1]){location.href=w[1].href}else{if(p){w.click()}}}}}}}}}}if(!x&&u&&!D.is(":button,a,a>.t-icon")){x=F._handleEditing(t)}if(x){t.preventDefault();t.stopPropagation()}},_handleEditing:function(q){var I=this,C=q.keyCode,G=q.shiftKey,D,p=a.proxy(I.current,I),n=a.proxy(I._clearInputSelection,I),u=a.proxy(I._focusGridElement,I),o=p(),s=a(I.element),H=I.$tbody,E=o.parent(),F=E.index(),J,v=false,r="td.t-grid-edit-cell",t=":input:visible:first",w=I.isAjax(),z=E.closest("tr.t-grid-new-row")[0],y=I.editing.mode==="InCell",A=I.editing.mode==="PopUp",x=E.closest("tr.t-grid-edit-row")[0]||(A&&a("#"+I.formId()+":visible").length);if(g.ENTER==C||g.F12==C){v=true;if(x){if(a(q.target).is("textarea")){v=false;return}n(o.find(t)[0]);if(y){J=I.validate();if(!J){o.find(t).focus();return}if(o.is(r)){I.saveCell(o[0])}else{E.find(r).each(function(){I.saveCell(this)});I.editCell(o[0])}if(I.valid){u()}}else{if(w){s.one("dataBound",function(){var K=a(this).data("tGrid");K._current=K.$tbody.children().eq(F).find(d).eq(0);u()});if(A){a(".t-grid-update,.t-grid-insert","#"+I.formId()).click()}else{if(z){I.insertRow(E)}else{I.updateRow(E)}}}else{if(I.validate()){if(A){E=a("#"+I.formId())}E.find(".t-grid-update,.t-grid-insert").click()}}}}else{if(y){H.find(r).each(function(){I.saveCell(this)});I.editCell(o[0])}else{if(w){I.editRow(E);p(E.children().eq(0));if(A){E=a("#"+I.formId())}E.find(t).focus()}else{location.href=E.find(".t-grid-edit:first").attr("href")}}}}else{if(g.ESC==C&&x){v=true;n(o.find(t)[0]);if(y&&o.is(r)){I.cancelCell(o);u()}else{if(w){if(A){a(".t-grid-cancel","#"+this.formId()).click()}else{I.cancelRow(E)}p(E.find(d).eq(0));u()}else{if(A){E=a("#"+I.formId())}location.href=E.find(".t-grid-cancel:first").attr("href")}}}else{if(y&&g.TAB==C){if(x){n(o.find(t)[0]);I.saveCell(o);if(I.valid){u()}else{o.find(t).focus();return true}v=true}D=G?o.prev():o.next();if(!D.length){D=o.parent()[G?"prev":"next"]().children(G?":last":":first")}p(D);if(I.keyboardNavigation.editOnTab&&D.length){I.editCell(D[0]);D.find(t).focus();v=true}}}}return v},_initNavigationMouseEvents:function(){var x=this,w=x.$tbody,u=j+d,n=a.browser,o="click",r="mousedown",p,v,q,s=".t-grid-edit-row",t=":button,a,:input,a>.t-icon";if(n.msie){w.delegate(u,o,function(y){v=a(y.target),q=a(y.currentTarget),p=x._current;if(q.closest("tbody")[0]!==w[0]){return}if(v.is(t)){if(!(p&&!q.parent().is(s))){if(p){p.removeClass(FOCUSED)}x._current=q}}else{if(p&&p[0]===q[0]){x._current=null}x.current(q);y.preventDefault()}})}else{w.delegate(u,r,function(y){v=a(y.target),q=a(y.currentTarget),p=x._current;if(q.closest("tbody")[0]!==w[0]){return}if(v.is(t)){if(!(p&&!q.parent().is(s))){if(p){p.removeClass(FOCUSED)}x._current=q}}else{x.current(q)}})}},_clearInputSelection:function(o){if(!o||a(o).is(":checkbox, :radio")){return}var n=a.browser,p;if(n.msie&&parseInt(n.version)==8){p=o.createTextRange();p.moveStart("textedit",1);p.select()}},_focusGridElement:function(){var n=a.browser;if(n.msie&&parseInt(n.version)<9){a("body",document).focus()}this.element.focus()},current:function(o){var p=this,n=p._current;if(o!==m&&o.length){if(!n||n[0]!==o[0]){o.addClass(FOCUSED);if(n){n.removeClass(FOCUSED)}p._current=o;p._scrollTo(o.parent()[0])}}else{return p._current}},_scrollTo:function(r){var o=this.$tbody.closest("div.t-grid-content")[0];if(!r||!o){return}var t=r.offsetTop,s=r.offsetHeight,q=o.scrollTop,p=o.clientHeight,n=t+s;o.scrollTop=q>t?t:n>(q+p)?n-p:q},_transformParams:function(n){var s=this,r=s._isServerOperation(),q={},o=s.filterBy||"",p=s.orderBy||"";if(r){if(n.page){q[s.queryString.page]=n.page}if(n.pageSize){q[s.queryString.size]=n.pageSize}if(p!==""){q[s.queryString.orderBy]=p}if(o!==""){q[s.queryString.filter]=o}if(s.groupBy){q[s.queryString.groupBy]=s.groupBy}if(n.aggregates&&n.aggregates.length){q.aggregates=a.map(s.columns,function(t){if(t.aggregates){return t.member+"-"+t.aggregates.join("-")}}).join("~")}}delete n.page;delete n.pageSize;delete n.sort;delete n.filter;delete n.group;delete n.aggregates;if(s.ws){q=b.toJson(a.extend(n,{state:q}))}else{q=a.extend(q,n)}return q},_dataSourceOptions:function(){var q=this,p=this.pageSize>0,o,n=q.data||[];remoteOperations=q._isServerOperation(),aggregates=a.map(q.columns||[],function(r){return a.map(r.aggregates||[],function(s){return{field:r.member,aggregate:s}})}),deserializer={translateGroup:function(r){return{value:r.Key,hasSubgroups:r.HasSubgroups,aggregates:r.Aggregates,items:r.HasSubgroups?a.map(r.Items,a.proxy(this.translateGroup,this)):r.Items}},flatGroups:function(r){if(r.HasSubgroups){return this.flatGroups(r.Items)}return r.Items},convert:function(r){return r.d||r},mergeChanges:function(r,z,t){var v,w,y,x=[],u,s=q.dataSource;a.each(t,function(C,A){for(w=0,y=r.length;w<y;w++){if(A===s.id(r[w])){r.splice(w,1);break}}});a.each(z,function(A,C){v=s.id(this);u=false;for(w=0,y=r.length;w<y;w++){if(v===s.id(r[w])){a.extend(true,r[w],C);u=true;break}}if(!u){x.push(C)}});return r.concat(x)},data:function(s){var t=q.dataSource,r=t.data(),v=t.page()-1,w=t.pageSize(),u=q.deletedIds||[];q.deletedIds=[];if(s){s=this.convert(s);s=!a.isArray(s)?s.data||s.Data:s;if(r&&r.length&&!remoteOperations&&t.id){if(s.length&&typeof s[0].HasSubgroups!="undefined"&&!remoteOperations){s=a.map(s,a.proxy(this.flatGroups,this))}return this.mergeChanges(r,s,u)}}return s},total:function(r){if(r){r=this.convert(r);return !a.isArray(r)?r.total||r.Total||0:r.length}return 0},groups:function(r){r=this.data(r);return a.map(r,a.proxy(this.translateGroup,this))},aggregates:function(r){r=this.convert(r);return r.aggregates||{}}};o={serverSorting:remoteOperations,serverPaging:remoteOperations,serverFiltering:remoteOperations,serverGrouping:remoteOperations,serverAggregates:remoteOperations,page:p?q.currentPage:m,pageSize:p?q.pageSize:m,aggregates:q.aggregates||aggregates,error:a.proxy(function(r){var t=r[0],s=r[1];if(b.ajaxError(this.element,"error",t,s)){return}},this),group:a.map(q.groups||[],function(r){return{field:r.member,dir:r.order,aggregates:aggregates}}),sort:a.map(q.sorted,function(r){return{field:r.member,dir:r.order}}),filter:a.map(a.grep(q.columns,function(r){return r.filters}),function(r){return a.map(r.filters,function(t){var v=t.value;if(r.type=="Number"){v=parseFloat(v)}else{if(r.type=="Date"){if(typeof v==="string"){var s=/^\/Date\((.*?)\)\/$/.exec(v);if(s){v=new Date(parseInt(s[1]))}else{var u=r.format?/\{0(:([^\}]+))?\}/.exec(r.format)[2]:b.cultureInfo.shortDate;v=b.datetime.parse({value:v,format:u}).toDate()}}}}return{field:r.member,operator:t.operator,value:v}})})};if(remoteOperations||(q.isAjax()&&!n.length)){a.extend(o,{transport:{dialect:{read:a.proxy(q._transformParams,this)},read:{type:"POST",dataType:"text",dataFilter:function(r,s){try{r=eval("("+r.replace(i,"new Date($1)")+")");q._onComplete({name:"dataBinding",response:r});return r}catch(t){if(!b.ajaxError(q.element,"error",{},"parseeror")){alert("Error! The requested URL did not return JSON.")}}},contentType:q.ws?"application/json; charset=utf-8":m,complete:a.proxy(q.hideBusy,q)}},deserializer:deserializer})}else{if(n.length){a.extend(o,{data:{data:q.data,total:q.total||n.length},deserializer:deserializer})}}return o},_dataSource:function(){var p=this,o=p._dataSourceOptions(),n=o.data;p.dataSource=new b.DataSource(o);if(n&&n.data){p._convertInitialData(n.data)}p.dataSource.bind("change",a.proxy(p._dataChange,p))},_convertInitialData:function(n){var s=this;if(!s._isServerOperation()&&n&&n.length){s.dataSource.read();var t=s.dataSource.view();if(t.length&&t[0].hasSubgroups!=m){var r=[],o=function(u){if(u.hasSubgroups){return o(u.items)}return u.items};for(var p=0,q=t.length;p<q;p++){r=r.concat(o(t[p]))}s.data=r}else{s.data=t}}},_mapAggregates:function(n){var p={};for(var o in n){p[o.replace(/^\w/,function(q){return q.toUpperCase()})]=n[o]}return p},rowClick:function(p){var o=a(p.target);if(!o.is(":button,a,input,select,textarea,option,a>.t-icon")){p.stopPropagation();var n=o.closest("tr").addClass("t-state-selected").siblings().removeClass("t-state-selected").end();b.trigger(this.element,"rowSelect",{row:n[0]})}},$rows:function(){return this.$tbody.find("> tr:not(.t-grouping-row,.t-detail-row)")},expandRow:function(n){a(n).find("> td .t-plus, > td .t-expand").click()},collapseRow:function(n){a(n).find("> td .t-minus, > td .t-collapse").click()},headerClick:function(n){n.preventDefault();this.toggleOrder(this.$columns().index(a(n.target).closest("th")));this.sort(this.sortExpr())},refreshClick:function(n,o){if(a(o).is(".t-loading")){return}if(this.isAjax()){n.preventDefault();if(!this._isServerOperation()){this.dataSource.data([])}this.ajaxRequest(true)}},sort:function(n){this.orderBy=n;this.ajaxRequest()},columnFromTitle:function(o){o=a.trim(o);var n=a.grep(this.$columns(),function(p){return a.trim(a(p).text())==o})[0];if(n){return this.columns[this.$columns().index(n)]}return a.grep(this.columns,function(p){return p.title==o})[0]},columnFromMember:function(o){var n=a.grep(this.columns,function(p){return p.member==o})[0];if(!n){n=a.grep(this.columns,function(p){var q="."+p.member;return o.substr(o.length-q.length)==q})[0]}return n},toggleOrder:function(n){n=typeof n=="number"?this.columns[n]:n;var o="asc";if(n.order=="asc"){o="desc"}else{if(n.order=="desc"){o=null}}n.order=o;var p=a.inArray(n,this.sorted);if(this.sortMode=="single"&&p<0){a.each(this.sorted,function(){this.order=null});this.sorted=[]}if(p<0&&o){this.sorted.push(n)}if(!o){this.sorted.splice(p,1)}},sortExpr:function(){return a.map(this.sorted,function(n){return n.member+"-"+n.order}).join("~")},pagerKeyDown:function(n){if(n.keyCode==13){var o=this.sanitizePage(a(n.target).val());if(o!=this.currentPage){this.pageTo(o)}else{a(n.target).val(o)}}},isAjax:function(){return this.ajax||this.ws||this.onDataBinding},url:function(n){return(this.ajax||this.ws)[n]},pagerClick:function(o){o.preventDefault();var n=a(o.target).closest(".t-link");var r=this.currentPage;var s=n.find(".t-icon");if(s.hasClass("t-arrow-next")){r++}else{if(s.hasClass("t-arrow-last")){r=this.totalPages()}else{if(s.hasClass("t-arrow-prev")){r--}else{if(s.hasClass("t-arrow-first")){r=1}else{var q=n.text();if(q=="..."){var p=n.parent().children().index(n);if(p==0){r=parseInt(n.next().text())-1}else{r=parseInt(n.prev().text())+1}}else{r=parseInt(q)}}}}}this.pageTo(isFinite(r)?r:this.currentPage)},changePageSize:function(o){var n=parseInt(o,10);if(isNaN(n)||n<1){return this.pageSize}n=Math.max(n,1);this.currentPage=1;this.pageSize=n;if(this.isAjax()){this.ajaxRequest()}else{this.serverRequest()}},pageTo:function(n){this.currentPage=n;if(this.isAjax()){this.ajaxRequest()}else{this.serverRequest()}},_dataChange:function(){var o=this.dataSource;if(!this._clientBindingInProgress){this.total=o.total()}this.aggregates=o.aggregates();var n=o.view();if(this.pageOnScroll&&this._pagingInProgress===true){n=(this.data||[]).concat(n);this._pagingInProgress=false}this._current=null;this._populate(n)},_populate:function(n){this.data=[];this.bindTo(n);this.bindFooter();this.updatePager();this.updateSorting();b.trigger(this.element,"dataBound");b.trigger(this.element,"repaint")},ajaxOptions:function(n){var o={type:"POST",dataType:"text",dataFilter:function(q,r){return q.replace(i,"new Date($1)")},error:a.proxy(function(r,q){if(b.ajaxError(this.element,"error",r,q)){return}},this),complete:a.proxy(this.hideBusy,this),success:a.proxy(function(q,s,t){try{q=eval("("+q+")")}catch(r){if(!b.ajaxError(this.element,"error",t,"parseeror")){alert("Error! The requested URL did not return JSON.")}return}if(n.commandName){this._onComplete({name:n.commandName,response:q})}q=q.d||q;if(n.hasErrors&&n.hasErrors(q)){if(!b.trigger(this.element,"error",{XMLHttpRequest:t,textStatus:"modelstateerror",modelState:q.modelState})){n.displayErrors(q)}return;B}this.dataSource.success(q)},this)};a.extend(o,n);var p=this.ws?o.data.state={}:o.data;if(this._isServerOperation()){p[this.queryString.page]=this.currentPage;p[this.queryString.size]=this.pageSize;p[this.queryString.groupBy]=this.groupBy;p[this.queryString.filter]=(this.filterBy||"").replace(/\"/g,'\\"')}p[this.queryString.orderBy]=this.orderBy||"";p[this.queryString.aggregates]=a.map(this.columns,function(q){if(q.aggregates){return q.member+"-"+q.aggregates.join("-")}}).join("~");if(this.ws){o.data=b.toJson(o.data);o.contentType="application/json; charset=utf-8"}return o},showBusy:function(){this.busyTimeout=setTimeout(a.proxy(function(){a("> .t-grid-pager .t-status .t-icon",this.element).addClass("t-loading")},this),100)},hideBusy:function(){clearTimeout(this.busyTimeout);a("> .t-grid-pager .t-status .t-icon",this.element).removeClass("t-loading")},serverRequest:function(){if(this.operationMode==="client"){this.ajaxRequest()}else{location.href=b.formatString(unescape(this.urlFormat),this.currentPage,this.orderBy||"~",this.groupBy||"~",encodeURIComponent(this.filterBy)||"~",this.pageSize||"~")}},_isServerOperation:function(){return this.operationMode!=="client"},ajaxRequest:function(n){var t=this,s=t.pageSize>0,r=t.pageSize,p=t.currentPage,o=a.map(t.columns,function(u){return a.map(u.aggregates||[],function(v){return{field:u.member,aggregate:v}})});if(p>1&&t.pageOnScroll&&!t._pagingInProgress){r=p*t.pageSize;p=1}var q={page:p,sortedColumns:t.sorted,filteredColumns:a.grep(t.columns,function(u){return u.filters})};if(b.trigger(t.element,"dataBinding",q)){return}if(!t.ajax&&!t.ws&&this.operationMode!=="client"){return}if(t.dataSource.transport.options&&t.dataSource.transport.options.read){t.dataSource.transport.options.read.url=this.url("selectUrl")}if(t._isServerOperation()){t.showBusy()}t.dataSource.query(a.extend({page:p,pageSize:s?r:m,sort:a.map(t.sorted,function(u){return{field:u.member,dir:u.order}}),filter:a.map(a.grep(t.columns,function(u){return u.filters}),function(u){return a.map(u.filters,function(w){var y=w.value;if(u.type=="Number"){y=parseFloat(y)}else{if(u.type=="Date"){if(typeof y==="string"){var v=/^\/Date\((.*?)\)\/$/.exec(y);if(v){y=new Date(parseInt(v[1]))}else{var x=u.format?/\{0(:([^\}]+))?\}/.exec(u.format)[2]:b.cultureInfo.shortDate;y=b.datetime.parse({value:y,format:x}).toDate()}}}}return{field:u.member,operator:w.operator,value:y}})}),group:a.map(t.groups,function(u){return{field:u.member,dir:u.order,aggregates:o}}),aggregates:o},a.extend({},q.data,n)))},valueFor:function(n){if(n.type=="Date"){return new Function("data","var value = data."+n.member+'; if (!value) return null; return value instanceof Date? value : new Date(parseInt(value.replace(/\\/Date\\((.*?)\\)\\//, "$1")));')}return new Function("data","return data"+(n.member?"."+n.member:"")+";")},displayFor:function(o){var r=this.localization,q=this;if(o.commands){var n=a.map(o.commands,function(t){return b.grid.ButtonBuilder.create(a.extend({text:r[t.name]},t))});return function(t){return a.map(n,function(u){return u.build(a.extend({},t,{__page:q.currentPage,__orderBy:q.orderBy||"",__filter:q.filterBy||"",__groupBy:q.groupBy||""}))}).join("")}}if(!o.template){var s=o.value||function(){return""};var p=s=!o.data?s:function(t){var v=o.value(t),x=o.data,y="",u,w;for(u=0,w=x.length;u<w;u++){if(v==x[u].Value){return x[u].Text}}return y};if(o.format||o.type=="Date"){s=function(t){var u=p(t);return u==null?"":b.formatString(o.format||"{0:G}",u)}}return o.encoded===false?s:function(t){return e(s(t))}}return l(o.template)},insertFor:function(n){return this.displayFor(n)},editFor:function(n){return this.displayFor(n)},initializeColumns:function(){a.each(this.columns,a.proxy(function(p,q){if(q.member!==m){q.value=this.valueFor(q)}else{q.readonly=true}q.insert=this.insertFor(q);q.edit=this.editFor(q);q.display=this.displayFor(q);if(q.footerTemplate){q.footer=l(q.footerTemplate)}if(q.groupFooterTemplate){this.showGroupFooter=true;q.groupFooter=l(q.groupFooterTemplate)}q.groupHeader=l("<#= Title #>: <#= Key #>");if(q.groupHeaderTemplate){q.groupHeader=l(q.groupHeaderTemplate)}},this));var o=this.columns.length-1;while(o>=0){var n=this.columns[o];if(n.hidden){o--;continue}if(!n.attr){n.attr=' class="t-last"';break}else{if(n.attr.indexOf("class")==-1){n.attr+=' class="t-last"';break}else{n.attr=n.attr.replace('class="','class="t-last ');break}}o--}if(this.detail){this.displayDetails=l(this.detail.template)}},bindData:function(q,t,s){Array.prototype.push.apply(this.data,q);var r=this.pageOnScroll?q.length:Math.min(this.pageSize,q.length);var o=this.columns.length;r=this.pageSize?r:q.length;if(a.browser.msie){a(this.element).find(".t-grid-content colgroup:first col").css("display","")}for(var w=0;w<r;w++){var n=a.trim((this.detail?"t-master-row":"")+(w%2==1?" t-alt":""));if(n){t.cat('<tr class="').cat(n).cat('">')}else{t.cat("<tr>")}t.rep('<td class="t-group-cell"></td>',s).catIf('<td class="t-hierarchy-cell"><a class="t-icon t-plus" href="#" /></td>',this.detail);if(this.rowTemplate){t.cat('<td colspan="').cat(o).cat('">').cat(this.rowTemplate(q[w])).cat("</td>")}else{for(var u=0,v=this.columns.length;u<v;u++){var p=this.columns[u];t.cat("<td").cat(p.attr).cat(">").cat(p.display(q[w]));t.cat("</td>")}}t.cat("</tr>")}},normalizeColumns:function(){},dataItem:function(n){return(this.data||[])[this.$tbody.find("> tr:not(.t-grouping-row,.t-detail-row,.t-grid-new-row,.t-group-footer)").index(a(n))]},_colspan:function(){return this.groups.length+a.grep(this.columns,function(n){return !n.hidden}).length+(this.detail?1:0)},bindTo:function(o){var p=new b.stringBuilder();var n=this._colspan();if(o&&o.length){this.normalizeColumns(n);if(typeof o[0].hasSubgroups!="undefined"){for(var q=0,r=o.length;q<r;q++){this.bindGroup(o[q],n,p,0)}}else{this.bindData(o,p)}}else{p.cat("<tr class='t-no-data'>").cat("<td colspan='").cat(n).cat("'>").cat(this.noRecordsTemplate?this.noRecordsTemplate:this.localization.noRecords).cat("</td></tr>")}this.$tbody.html(p.string());if(this.onRowDataBound){var s=jQuery.grep(this.$tbody[0].rows,function(t){return !a(t).is(".t-grouping-row, .t-group-footer, .t-footer-template")});for(var q=0,r=this.data.length;q<r;q++){b.trigger(this.element,"rowDataBound",{row:s[q],dataItem:this.data[q]})}}},updatePager:function(){var q=this.totalPages(this.total);var n=this.currentPage;var p=this.pageSize;this.$pager.find(".t-arrow-next").parent().add(this.$pager.find(".t-arrow-last").parent()).toggleClass("t-state-disabled",n>=q).removeClass("t-state-hover");this.$pager.find(".t-arrow-prev").parent().add(this.$pager.find(".t-arrow-first").parent()).toggleClass("t-state-disabled",n==1).removeClass("t-state-hover");var o=this.localization;this.$pager.find(".t-page-i-of-n").each(function(){this.innerHTML=new b.stringBuilder().cat(o.page).cat('<input type="text" value="').cat(n).cat('" /> ').cat(b.formatString(o.pageOf,q)).string()});this.$pager.find(".t-page-size").each(function(){var r='<div style="width: 50px;" class="t-dropdown t-header"><div class="t-dropdown-wrap t-state-default"><span class="t-input">'+p+'</span><span class="t-select"><span class="t-icon t-arrow-down">select</span></span></div></div>';this.innerHTML=r});this.$pager.find(".t-numeric").each(a.proxy(function(s,r){this.numericPager(r,n,q)},this));this.$pager.parent().find(".t-status-text").text(b.formatString(o.displayingItems,this.firstItemInPage(),this.lastItemInPage(),this.total))},numericPager:function(s,n,v){var p=10;var q=1;if(n>p){var u=(n%p);q=(u==0)?(n-p)+1:(n-u)+1}var o=(q+p)-1;o=Math.min(o,v);var t=new b.stringBuilder();if(q>1){t.cat('<a class="t-link">...</a>')}for(var r=q;r<=o;r++){if(r==n){t.cat('<span class="t-state-active">').cat(r).cat("</span>")}else{t.cat('<a class="t-link">').cat(r).cat("</a>")}}if(o<v){t.cat('<a class="t-link">...</a>')}s.innerHTML=t.string()},$columns:function(){return this.$header.find("th:not(.t-hierarchy-cell,.t-group-cell)")},updateSorting:function(){this.sorted=[];a.each(this.orderBy.split("~"),a.proxy(function(n,p){var q=p.split("-");var o=this.columnFromMember(q[0]);if(o){o.order=q[1];this.sorted.push(o)}},this));this.$columns().each(a.proxy(function(r,q){var p=this.columns[r].order;var o=a(q).children("a.t-link");var n=o.children(".t-icon");if(!p){n.hide()}else{if(n.length==0){n=a('<span class="t-icon"/>').appendTo(o)}n.toggleClass("t-arrow-up",p=="asc").toggleClass("t-arrow-down",p=="desc").html("("+(p=="asc"?this.localization.sortedAsc:this.localization.sortedDesc)+")").show()}},this))},sanitizePage:function(o){var n=parseInt(o,10);if(isNaN(n)||n<1){return this.currentPage}return Math.min(n,this.totalPages())},totalPages:function(){return Math.ceil(this.total/this.pageSize)},firstItemInPage:function(){var n=this;return n.total>0?n.pageOnScroll?1:(n.currentPage-1)*n.pageSize+1:0},lastItemInPage:function(){return Math.min(this.currentPage*this.pageSize,this.total)},dataBind:function(n){var o=this;if(!o.dataSource){o._dataSource()}else{if(n&&n.length){o.dataSource._group=a.map(o.groups,function(p){return{field:p.member,dir:p.order,aggregates:aggregates}})}}o._clientBindingInProgress=true;try{o.dataSource.success(n||[])}finally{o._clientBindingInProgress=false}},bindFooter:function(){var q=this,n=q.$footer.find("td:not(.t-group-cell,.t-hierarchy-cell)"),o=q.aggregates,p={Sum:0,Count:0,Average:0,Max:0,Min:0};a.each(q.columns,function(r){if(this.footer){n.eq(r).html(this.footer(q._mapAggregates(o[this.member]||p)))}})},rebind:function(n){var o=this;o.sorted=[];o.orderBy="";o.filterBy="";o.currentPage=1;a.each(o.columns,function(){this.order=null;this.filters=null});a(".t-filter-options",o.element).find('input[type="text"], select').val("").removeClass("t-state-error").end().find("div.t-formatted-value").html("");a(".t-grid-filter",o.element).removeClass("t-active-filter");if(this.isAjax()){o.data=[]}if(!o._isServerOperation()){o._dataSource()}o.ajaxRequest(n)},hideColumn:function(r){var D=this,t=D.columns,s,q,E,z=D.$tbody.children("tr"),x,y,p,v,C=0,o=a.browser,w=o.msie&&parseInt(o.version)===8,A,n,u=D.editing.mode;if(typeof r==="number"){r=t[r]}else{r=D.columnFromMember(r)}s=a.inArray(r,a.grep(t,function(F){return !F.hidden}));if(s<0||!r){return}q=a("col:not(.t-group-col,.t-hierarchy-col)",D.$header.parent().prev());if(D.scrollable){q.eq(s).remove();q=a("col:not(.t-group-col,.t-hierarchy-col)",D.$tbody.prev())}E=q.eq(s).remove()[0].style.width;D.$columns().filter(":visible").eq(s).hide();D.$footer.find("td:not(.t-group-cell):visible").eq(s).hide();for(v=0,x=z.length;v<x;v++){y=z.eq(v);if(y.is(".t-grouping-row,.t-detail-row")){p=y.children(":not(.t-group-cell):first,.t-detail-cell").last();p.attr("colspan",p.attr("colspan")-1)}else{if(y.hasClass("t-grid-edit-row")){if(u==="InLine"&&!D.isAjax()){p=y.children(".t-edit-container");p.attr("colspan",p.attr("colspan")-1);p.find("col").eq(s).remove();y=p.find("tr:first")}else{if(u==="InForm"){p=y.children().first();p.attr("colspan",p.attr("colspan")-1);continue}}}y.children("td:not(.t-group-cell,.t-hierarchy-cell):visible").eq(s).hide()}}for(v=0,x=q.length;v<x;v++){if(v!=s){if(q[v].style.width){C+=parseInt(q[v].style.width)}else{C=0;break}}}A=a(">table,>.t-grid-header table,>.t-grid-content>table",D.element);if(C){A.width(C)}if(w){A.css("display","inline-table");setTimeout(function(){A.css("display","table")},1)}r.hidden=true;r.width=E;n=r.attr;if(!n||n.indexOf("style")<0){n=(n||"")+' style="display:none" '}else{n=r.attr.replace(/(style="(.*)?display):([^;]*)/i,"$1:none");if(n===r.attr){n=n.replace(/(style=")/i,"$1display:none;")}}r.attr=n},showColumn:function(p){var w=this,q,r=w.columns,o,v=w.$tbody.children("tr"),u,n,s,t;if(typeof p==="number"){p=r[p]}else{p=w.columnFromMember(p)}q=a.inArray(p,r);if(!p||!p.hidden){return}o=a("col:not(.t-group-col,.t-hierarchy-col)",w.$header.parent().prev());h(o,r,q);if(w.scrollable){o=a("col:not(.t-group-col,.t-hierarchy-col)",w.$tbody.prev());h(o,r,q)}w.$columns().eq(q).show();w.$footer.find("td:not(.t-group-cell)").eq(q).show();for(s=0,t=v.length;s<t;s++){u=v.eq(s);if(u.is(".t-grouping-row,.t-detail-row")){n=u.children(":not(.t-group-cell):first,.t-detail-cell").last();n.attr("colspan",n.attr("colspan")+1)}else{if(u.hasClass("t-grid-edit-row")){if(w.editing.mode==="InLine"&&!w.isAjax()){n=u.children(".t-edit-container");n.attr("colspan",n.attr("colspan")+1);h(n.find(">form>table>colgroup>col"),r,q);u=n.find("tr:first")}else{if(w.editing.mode==="InForm"){n=u.children().first();n.attr("colspan",n.attr("colspan")+1);continue}}}u.children("td:not(.t-group-cell,.t-hierarchy-cell)").eq(q).show()}}if(!p.width){a(">table,>.t-grid-header table,>.t-grid-content>table",w.element).width("")}p.hidden=false;delete p.width;if(p.attr){p.attr=p.attr.replace(/(style="(.*)?)(display\s*:\s*none)\s*;?/i,"$1")}},initializeContextMenu:function(){var s=this,p,o=b.fx.slide.defaults(),n=a.grep(s.columns,function(t){return t.title!==""}),q=s.element.id+"_contextMenu",r;a(document).bind("mouseup",function(t){if(r&&t.which!=3&&a(t.target).closest("#"+q).length==0){b.fx.rewind(o,r.find(".t-group"),{direction:"bottom"},function(){r.remove()})}});s.$header.closest(".t-grid-header").bind("contextmenu",function(t){if(r&&r.is(":visible")){b.fx.rewind(o,r.find(".t-group"),{direction:"bottom"});r.remove()}p=new b.stringBuilder();p.cat('<div class="t-animation-container t-menu t-menu-context" id="'+q+'" style="display:none">').cat('<ul class="t-group">');a.each(n,function(){p.cat('<li class="t-item"><label class="t-link">').cat('<input type="checkbox" data-field="'+a.inArray(this,s.columns)+'"').catIf('checked="checked"',!this.hidden).cat("/>").cat(this.title).cat("</label></li>")});p.cat("</ul></div>");r=a(p.string()).delegate("[type=checkbox]","change",function(){var u=a(this),v;s[u.is(":checked")?"showColumn":"hideColumn"](u.data("field"));v=r.find(":checked");v.attr("disabled",v.length==1)}).appendTo(document.body);r.css({left:t.clientX+a(document).scrollLeft(),top:t.clientY+a(document).scrollTop()});b.fx.play(o,r.find(".t-group"),{direction:"bottom"});return false})}};b.grid.ButtonBuilder=function(n){var p=/class="([^"]*)"/i;this.classNames=["t-button"];var o=p.exec(n.attr);if(o){this.classNames.push(o[1]);n.attr=a.trim(n.attr.replace(p,""))}if(n.name){this.classNames.push("t-grid-"+n.name)}if(n.ajax){this.classNames.push("t-ajax")}this.url=n.url?l(unescape(n.url)):function(){return"#"};this.content=function(){return n.text||""};this.build=function(q){return'<a href="'+this.url(q)+'" class="'+this.classNames.join(" ")+'" '+(n.attr||"")+">"+this.content()+"</a>"}};b.grid.ButtonBuilder.create=function(n){return new (c[n.buttonType])(n)};function k(o,n){return'<span class="t-icon t-'+o+'"'+(n?n:"")+"></span>"}b.grid.ImageButtonBuilder=function(n){b.grid.ButtonBuilder.call(this,n);this.classNames.push("t-button-icon");this.content=function(){return k(n.name,n.imageAttr)}};b.grid.ImageTextButtonBuilder=function(n){b.grid.ButtonBuilder.call(this,n);this.classNames.push("t-button-icontext");this.content=function(){return'<span class="t-icon t-'+n.name+'"'+(n.imageAttr?n.imageAttr:"")+"></span>"+n.text}};b.grid.BareImageButtonBuilder=function(n,o){b.grid.ImageButtonBuilder.call(this,n,o);this.classNames.push("t-button-icon","t-button-bare")};var c={Text:b.grid.ButtonBuilder,ImageAndText:b.grid.ImageTextButtonBuilder,Image:b.grid.ImageButtonBuilder,BareImage:b.grid.BareImageButtonBuilder};a.fn.tGrid=function(n){return b.create(this,{name:"tGrid",init:function(o,p){return new b.grid(o,p)},options:n,success:function(o){if(o.$tbody.find("tr.t-no-data").length){o.ajaxRequest()}}})};a.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);