mirror of https://github.com/Sonarr/Sonarr
1 line
8.2 KiB
JavaScript
1 line
8.2 KiB
JavaScript
(function(d){var b=d.telerik;var c=3;var a=0;b.scripts.push("telerik.grid.grouping.js");b.grouping={};b.grouping.initialize=function(f){d.extend(f,b.grouping.implementation);f.$groupDropCue=d('<div class="t-grouping-dropclue"/>');f.$groupHeader=d("> .t-grouping-header",f.element);function h(){var k=d.map(f.$groupHeader.find(".t-group-indicator"),function(l){var m=d(l);var n=m.offset().left;var o=m.outerWidth();return{left:n,right:n+o,width:o,$group:m}});return{first:k[0],all:k,last:k[k.length-1]}}function g(u){var l=u.$cue.text();if(!d.contains(f.element,u.target)||!d(u.target).closest(".t-grouping-header").length||(f.groupFromTitle(l)&&u.$draggable.closest(".t-header").length)){f.$groupDropCue.remove();return}var w=d(f.element),o=w.find("> .t-grid-toolbar"),m=o.outerHeight()+c,q=h(),p=w.closest(".t-rtl").length;if(!q.all.length){var r=p?o.width()-a:a;f.$groupDropCue.css({top:m,left:r}).appendTo(f.$groupHeader);return}var v=q.first;var t=q.last;var k=parseInt(v.$group.css("marginLeft"));var s=parseInt(v.$group.css("marginRight"));var n=d.grep(q.all,function(x){return u.pageX>=x.left-k-s&&u.pageX<=x.right})[0];if(!n&&v){if(!p&&u.pageX<v.left){n=v}else{if(p&&u.pageX<t.left){n=t}}}if(p){if(n){f.$groupDropCue.css({top:m,left:n.$group.position().left-k+a}).insertAfter(n.$group)}else{f.$groupDropCue.css({top:m,left:o.width()-a}).prependTo(f.$groupHeader)}}else{if(n){f.$groupDropCue.css({top:m,left:n.$group.position().left-k+a}).insertBefore(n.$group)}else{f.$groupDropCue.css({top:m,left:t.$group.position().left+t.$group.outerWidth()+s+a}).appendTo(f.$groupHeader)}}}function j(n){if(n.$draggable.hasClass("t-header")){var k=f.columnFromTitle(n.$draggable.text());return b.dragCue(k?k.title:"")}else{var m=d(".t-link",n.$draggable);var l=m.text().substr(d(".t-icon",m).text().length);var k=f.columnFromTitle(l);return b.dragCue(k?k.title:l)}}function i(k){var l=k.$cue.text();f.$groupDropCue.remove();if(k.$draggable.is(".t-group-indicator")&&k.keyCode!=27){f.unGroup(l);return false}}function e(k){k.$cue.remove()}new b.draggable({owner:f.$header,selector:".t-header:not(.t-group-cell,.t-hierarchy-cell)",scope:f.element.id+"-grouping",cue:j,start:function(k){var l=f.columnFromTitle(k.$draggable.text());return !!l.member&&l.groupable!==false},stop:i,drag:g,destroy:e});new b.draggable({owner:f.$groupingHeader,selector:".t-group-indicator",scope:f.element.id+"-grouping",cue:j,stop:i,drag:g,destroy:e});new b.droppable({owner:f.element,selector:".t-grouping-header",scope:f.element.id+"-grouping",over:function(k){b.dragCueStatus(k.$cue,"t-add")},out:function(k){b.dragCueStatus(k.$cue,"t-denied")},drop:function(o){var k=o.$cue.text();var l=f.groupFromTitle(k);var n=d.inArray(l,f.groups);var m=f.$groupHeader.find("div").index(f.$groupDropCue);var p=n-m;if(!l||(f.$groupDropCue.is(":visible")&&p!=0&&p!=-1)){f.group(k,m)}f.$groupDropCue.remove()}});if(f.isAjax()){f.$groupHeader.delegate(".t-button","click",function(m){m.preventDefault();var l=d(this).parent().find(".t-link");var k=l.text().substr(d(".t-icon",l).text().length);f.unGroup(k)}).delegate(".t-link","click",function(n){n.preventDefault();var m=d(this);var k=m.text().substr(d(".t-icon",m).text().length);var l=f.groupFromTitle(k);l.order=l.order=="asc"?"desc":"asc";f.group(l.title)})}f.$groupHeader.delegate(".t-group-indicator","mouseenter",function(){f.$currentGroupItem=d(this)}).delegate(".t-group-indicator","mouseleave",function(){f.$currentGroupItem=null});f.$tbody.delegate(".t-grouping-row .t-collapse, .t-grouping-row .t-expand","click",b.stop(function(l){l.preventDefault();var m=d(this),k=m.closest("tr");if(m.hasClass("t-collapse")){f.collapseGroup(k)}else{f.expandGroup(k)}}));f.groupFromTitle=function(k){return d.grep(f.groups,function(l){return l.title==k})[0]};f.expandGroup=function(l){var m=d(l);var k=m.find(".t-group-cell").length;m.nextAll("tr").each(function(o,p){var n=d(p);var q=n.find(".t-group-cell").length;if(q<=k){return false}if(q==k+1&&!n.hasClass("t-detail-row")){n.show();if(n.hasClass("t-grouping-row")&&n.find(".t-icon").hasClass("t-collapse")){f.expandGroup(n)}if(n.hasClass("t-master-row")&&n.find(".t-icon").hasClass("t-minus")){n.next().show()}}});m.find(".t-icon").addClass("t-collapse").removeClass("t-expand")};f.collapseGroup=function(l){var m=d(l);var k=m.find(".t-group-cell").length;m.nextAll("tr").each(function(){var n=d(this);var o=n.find(".t-group-cell").length;if(o<=k){return false}n.hide()});m.find(".t-icon").addClass("t-expand").removeClass("t-collapse")};f.group=function(l,o){if(this.groups.length==0&&this.isAjax()){f.$groupHeader.empty()}var m=d.grep(f.groups,function(q){return q.title==l})[0];if(!m){var n=f.columnFromTitle(l);m={order:"asc",member:n.member,title:l};f.groups.push(m)}if(o>=0){f.groups.splice(d.inArray(m,f.groups),1);f.groups.splice(o,0,m)}f.groupBy=d.map(f.groups,function(q){return q.member+"-"+q.order}).join("~");if(this.isAjax()){var p=this.$groupHeader.find('div:contains("'+l+'")');if(p.length==0){var k=new d.telerik.stringBuilder().cat('<div class="t-group-indicator">').cat('<a href="#" class="t-link"><span class="t-icon" />').cat(l).cat("</a>").cat('<a class="t-button t-button-icon t-button-bare"><span class="t-icon t-group-delete">').cat(f.localization.ungroup).cat("</span></a>").cat("</div>").string();p=d(k).appendTo(this.$groupHeader)}if(this.$groupDropCue.is(":visible")){p.insertBefore(this.$groupDropCue)}p.find(".t-link .t-icon").toggleClass("t-arrow-up-small",m.order=="asc").toggleClass("t-arrow-down-small",m.order=="desc").html("("+(m.order=="asc"?f.localization.sortedAsc:f.localization.sortedDesc)+")");this.ajaxRequest()}else{this.serverRequest()}};f.unGroup=function(l){var k=f.groupFromTitle(l);f.groups.splice(d.inArray(k,f.groups),1);if(f.groups.length==0){f.$groupHeader.html(f.localization.groupHint)}f.groupBy=d.map(f.groups,function(m){return m.member+"-"+m.order}).join("~");if(f.isAjax()){f.$groupHeader.find('div:contains("'+k.title+'")').remove();f.ajaxRequest()}else{f.serverRequest()}},f.normalizeColumns=function(n){var o=f.groups.length;var m=n-f.$tbody.parent().find(" > colgroup > col").length;if(m==0){return}var p=f.$tbody.parent().add(f.$headerWrap.find("table")).add(f.$footer.find("table"));if(d.browser.msie){if(m>0){d(new b.stringBuilder().rep('<col class="t-group-col" />',m).string()).prependTo(p.find("colgroup"));d(new b.stringBuilder().rep('<th class="t-group-cell t-header"> </th>',m).string()).insertBefore(p.find("th.t-header:first"));d(new b.stringBuilder().rep('<td class="t-group-cell"> </td>',m).string()).insertBefore(p.find("tr.t-footer-template > td:first"))}else{p.find("th:lt("+Math.abs(m)+"), tr.t-footer-template > td:lt("+Math.abs(m)+")").remove().end().find("col:lt("+Math.abs(m)+")").remove()}var k=[];var l=0;d("table, .t-grid-bottom",f.element).each(function(){k.push(this.parentNode)}).appendTo(d("<div />")).each(function(){k[l++].appendChild(this)})}else{p.find("col.t-group-col").remove();d(new b.stringBuilder().rep('<col class="t-group-col" />',o).string()).prependTo(p.find("colgroup"));p.find("th.t-group-cell").remove();p.find("tr.t-footer-template > td.t-group-cell").remove();d(new b.stringBuilder().rep('<th class="t-group-cell t-header"> </th>',o).string()).insertBefore(p.find("th.t-header:first"));d(new b.stringBuilder().rep('<td class="t-group-cell"> </td>',o).string()).insertBefore(p.find("tr.t-footer-template > td:first"))}},f.bindGroup=function(n,r,q,p){var o=f.groups[p];var t=n.value;var m=d.grep(f.columns,function(l){return o.member==l.member})[0];if(m&&(m.format||m.type=="Date")){t=b.formatString(m.format||"{0:G}",t)}q.cat('<tr class="t-grouping-row">').rep('<td class="t-group-cell"></td>',p).cat('<td colspan="').cat(r-p).cat('"><p class="t-reset"><a class="t-icon t-collapse" href="#"></a>');if(m){q.cat(m.groupHeader(d.extend({Title:o.title,Key:t},f._mapAggregates(n.aggregates[m.member]))))}else{q.cat(o.title+": "+t)}q.cat("</p></td></tr>");if(n.hasSubgroups){for(var k=0,s=n.items.length;k<s;k++){f.bindGroup(n.items[k],r,q,p+1)}}else{f.bindData(n.items,q,p+1)}if(f.showGroupFooter){q.cat('<tr class="t-group-footer">').rep('<td class="t-group-cell"></td>',f.groups.length);d.each(f.columns,function(){q.cat("<td>");if(this.groupFooter){q.cat(this.groupFooter(f._mapAggregates(n.aggregates[this.member])))}q.cat("</td>")});q.cat("</tr>")}}}})(jQuery); |