Sonarr/NzbDrone.Web/Scripts/2010.2.825/telerik.grid.grouping.min.js

1 line
6.9 KiB
JavaScript

(function(d){var b=d.telerik;var c=3;var a=0;b.grouping={};b.grouping.initialize=function(e){d.extend(e,b.grouping.implementation);e.$groupDropClue=d('<div class="t-grouping-dropclue"/>');e.$groupHeader=d("> .t-grouping-header",e.element);b.draganddrop(e.element.id,d.extend({useDragClue:true,draggables:[d(".t-link",e.$groupHeader[0]),d(".t-header:not(.t-group-cell,.t-hierarchy-cell)",e.$header[0])]},b.draganddrop.applyContext(b.draganddrop.grouping,e)));if(e.isAjax()){e.$groupHeader.delegate(".t-button","click",function(f){f.preventDefault();e.unGroup(d(this).parent().text())}).delegate(".t-link","click",function(g){g.preventDefault();var f=e.groupFromTitle(d(this).parent().text());f.order=f.order=="asc"?"desc":"asc";e.group(f.title)})}e.$groupHeader.delegate(".t-group-indicator","mouseenter",function(){e.$currentGroupItem=d(this)}).delegate(".t-group-indicator","mouseleave",function(){e.$currentGroupItem=null});e.$tbody.delegate(".t-grouping-row .t-collapse, .t-grouping-row .t-expand","click",b.stop(function(g){g.preventDefault();var f=d(this).closest("tr");if(d(this).hasClass("t-collapse")){e.collapseGroup(f)}else{e.expandGroup(f)}}))};b.grouping.implementation={columnFromTitle:function(e){return d.grep(this.columns,function(f){return f.title==e})[0]},groupFromTitle:function(e){return d.grep(this.groups,function(f){return f.title==e})[0]},expandGroup:function(f){var g=d(f);var e=g.find(".t-group-cell").length;g.find("~ tr").each(d.proxy(function(j,k){var h=d(k);var l=h.find(".t-group-cell").length;if(l<=e){return false}if(l==e+1&&!h.hasClass("t-detail-row")){h.show();if(h.hasClass("t-grouping-row")&&h.find(".t-icon").hasClass("t-collapse")){this.expandGroup(h)}if(h.hasClass("t-master-row")&&h.find(".t-icon").hasClass("t-minus")){h.next().show()}}},this));g.find(".t-icon").addClass("t-collapse").removeClass("t-expand")},collapseGroup:function(f){var g=d(f);var e=g.find(".t-group-cell").length;g.find("~ tr").each(function(){var h=d(this);var i=h.find(".t-group-cell").length;if(i<=e){return false}h.hide()});g.find(".t-icon").addClass("t-expand").removeClass("t-collapse")},group:function(f,i){if(this.groups.length==0&&this.isAjax()){this.$groupHeader.empty()}var g=d.grep(this.groups,function(k){return k.title==f})[0];if(!g){var h=this.columnFromTitle(f);g={order:"asc",member:h.member,title:f};this.groups.push(g)}if(i>=0){this.groups.splice(d.inArray(g,this.groups),1);this.groups.splice(i,0,g)}this.groupBy=d.map(this.groups,function(k){return k.member+"-"+k.order}).join("~");if(this.isAjax()){var j=this.$groupHeader.find('div:contains("'+f+'")');if(j.length==0){var e=new d.telerik.stringBuilder().cat('<div class="t-group-indicator">').cat('<a href="#" class="t-link"><span class="t-icon" />').cat(f).cat("</a>").cat('<a class="t-button t-state-default"><span class="t-icon t-group-delete" /></a>').cat("</div>").string();j=d(e).appendTo(this.$groupHeader)}if(this.$groupDropClue.is(":visible")){j.insertBefore(this.$groupDropClue)}j.find(".t-link .t-icon").toggleClass("t-arrow-up-small",g.order=="asc").toggleClass("t-arrow-down-small",g.order=="desc");this.ajaxRequest()}else{this.serverRequest()}},unGroup:function(f){var e=this.groupFromTitle(f);this.groups.splice(d.inArray(e,this.groups),1);if(this.groups.length==0){this.$groupHeader.html(this.localization.groupHint)}this.groupBy=d.map(this.groups,function(h){return h.member+"-"+h.order}).join("~");if(this.isAjax()){this.$groupHeader.find('div:contains("'+e.title+'")').remove();this.ajaxRequest()}else{this.serverRequest()}},normalizeColumns:function(g){var h=this.groups.length;var f=g-this.$tbody.parent().find("col").length;if(f==0){return}var i=this.$tbody.parent().add(this.$headerWrap.find("table"));if(d.browser.msie){if(f>0){d(new b.stringBuilder().rep('<col class="t-group-col" />',f).string()).prependTo(i.find("colgroup"));d(new b.stringBuilder().rep('<th class="t-group-cell t-header">&nbsp;</th>',f).string()).insertBefore(i.find("th.t-header:first"))}else{i.find("th:lt("+Math.abs(f)+")").remove().end().find("col:lt("+Math.abs(f)+")").remove()}if(document.documentMode==8){if(this.scrollable){i.css("table-layout","auto")}var j=this;var e=30;i.find("col").css("width",function(){return d(this).is(".t-group-col,.t-hierarchy-col")?e:(d(j.element).width()-h*e-16)/j.columns.length})}}else{i.find("col.t-group-col").remove();d(new b.stringBuilder().rep('<col class="t-group-col" />',h).string()).prependTo(i.find("colgroup"));i.find("th.t-group-cell").remove();d(new b.stringBuilder().rep('<th class="t-group-cell t-header">&nbsp;</th>',h).string()).insertBefore(i.find("th.t-header:first"))}this.$footer.attr("colspan",g)},bindGroup:function(g,m,k,j){var h=this.groups[j];var o=g.Key;var f=d.grep(this.columns,function(i){return h.member==i.member})[0];if(f&&(f.format||f.type=="Date")){o=b.formatString(f.format||"{0:G}",o)}k.cat('<tr class="t-grouping-row">').rep('<td class="t-group-cell"></td>',j).cat('<td colspan="').cat(m-j).cat('"><p class="t-reset"><a class="t-icon t-collapse" href="#"></a>').cat(h.title).cat(": ").cat(o).cat("</p></td></tr>");if(g.HasSubgroups){for(var e=0,n=g.Items.length;e<n;e++){this.bindGroup(g.Items[e],m,k,j+1)}}else{this.bindData(g.Items,k,j+1)}}};d.extend(b.draganddrop,{grouping:{shouldDrag:function(e){if(e.closest(".t-grid-filter, .t-filter").length){return false}if(e.closest(".t-grid")[0]!=this.element){return false}var f=this.columnFromTitle(e.text());if(f&&f.groupable===false){return false}return true},createDragClue:function(e){return e.text()},onDragStart:function(){return false},onDragMove:function(m,f){m.stopPropagation();if(!d.contains(this.element,m.target)||!d(m.target).closest(".t-grouping-header").length||(this.groupFromTitle(f.text())&&f.closest(".t-header").length)){this.$groupDropClue.remove();return"t-denied"}var i=d.map(this.$groupHeader.find(".t-group-indicator"),function(e){var o=d(e);var p=o.offset().left;return{left:p,right:p+o.outerWidth(),$group:o}});var l=d("> .t-grid-toolbar",this.element).outerHeight()+c;if(!i.length){this.$groupDropClue.css({top:l,left:a}).appendTo(this.$groupHeader);return"t-add"}var g=i[0];var n=i[i.length-1];var h=parseInt(g.$group.css("marginLeft"));var j=parseInt(g.$group.css("marginRight"));var k=d.grep(i,function(e){return m.pageX>=e.left-h-j&&m.pageX<=e.right})[0];if(!k&&g&&m.pageX<g.left){k=g}if(k){this.$groupDropClue.css({top:l,left:k.$group.position().left-h+a}).insertBefore(k.$group)}else{this.$groupDropClue.css({top:l,left:n.$group.position().left+n.$group.outerWidth()+j+a}).appendTo(this.$groupHeader)}return"t-add"},onDragCancelled:function(){this.$groupDropClue.remove()},onDrop:function(k,f){var m=d(k.target).closest(".t-grouping-header");var h=f.text();var g=this.groupFromTitle(h);var j=d.inArray(g,this.groups);if(m.length>0){var i=this.$groupHeader.find("div").index(this.$groupDropClue);var l=j-i;if(!g||(this.$groupDropClue.is(":visible")&&l!=0&&l!=-1)){this.group(h,i)}}else{if(f.parent().is(".t-group-indicator")){this.unGroup(h)}else{this.$groupDropClue.remove();return false}}this.$groupDropClue.remove();return true}}})})(jQuery);