| 1 |
- (function(f,b){function a(k){this.options=b.extend({button:null,table:null,url:"",perPage:"",showNextPage:"",pageQueryName:"",parentIdQueryName:"",tierQueryName:"",showIcon:"fa-angle-right",hideIcon:"fa-angle-down",loadMoreText:'<svg style="fill:currentColor" t="1582877365167" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="32874" width="24" height="24"><path d="M162.8 515m-98.3 0a98.3 98.3 0 1 0 196.6 0 98.3 98.3 0 1 0-196.6 0Z" p-id="32875"></path><path d="M511.9 515m-98.3 0a98.3 98.3 0 1 0 196.6 0 98.3 98.3 0 1 0-196.6 0Z" p-id="32876"></path><path d="M762.8 515a98.3 98.3 0 1 0 196.6 0 98.3 98.3 0 1 0-196.6 0Z" p-id="32877"></path></svg>',},k);this.key=this.tier=this.row=this.data=this._req=null;this._init()}a.prototype={_init:function(){this._bindClick()},_bindClick:function(){var l=this,k=l.options;b(k.button).off("click").click(function(){if(l._req){return}var p=b(this),o=b("i",this),n=o.hasClass(k.showIcon);l.key=p.data("key");l.tier=p.data("tier");l.row=p.closest("tr");if(p.data("inserted")=="0"){l._request(1);p.data("inserted",1)}o.toggleClass(k.showIcon+" "+k.hideIcon);var m=[];e(l.row.nextAll(),l.row).forEach(function(q){if(d(q)!==(l.tier+1)){return}m.push(q);n?b(q).show():b(q).hide()});m.forEach(function(q){if(n){return}var r=b(q).find("a[data-tier="+d(q)+"] i");if(r.hasClass(k.hideIcon)){r.parent().click()}})})},_request:function(n,q){var r=this,p=r.row,l=r.key,k=r.tier,o=r.options.table;if(r._req){return}r._req=1;LA.loading();var m={_token:LA.token,};m[r.options.parentIdQueryName]=l;m[r.options.tierQueryName]=k+1;m[r.options.pageQueryName.replace(":key",l)]=n;b.ajax({url:r.options.url,type:"GET",data:m,headers:{"X-PJAX":true},success:function(y){q&&q();LA.loading(false);r._req=0;var t=e(p.nextAll(),p);p=t.length?b(t.pop()):p;var x=b("<div>"+y+"</div>"),w=x.find(o+" tbody"),u=x.find("last-page").text(),s=x.find("next-page").text();w.find("tr").each(function(A,z){b(z).attr("data-tier",k+1)});if(r.options.showNextPage&&w.find("tr").length==r.options.perPage&&u>=n){var v=b("<tr data-tier='"+(k+1)+"' data-page='"+s+"'><td colspan='"+(p.find("td").length)+"' align='center' style='cursor: pointer'> <a>"+r.options.loadMoreText+"</a> </td></tr>");p.after(v);v.click(function(){var z=b(this);r._request(z.data("page"),function(){z.remove()})})}p.after(w.html());x.find("script").each(function(A,z){p.after(z)});b(document).trigger("pjax:script")},error:function(t,s,u){q&&q();LA.loading(false);r._req=0;if(t.status!=404){LA.ajaxError(t,s,u)}}})}};function j(k){this.options=b.extend({button:null,url:"",},k);this.direction=this.key=this.tier=this.row=this._req=null;this._init()}j.prototype={_init:function(){this._bindClick()},_bindClick:function(){var k=this;b(k.options.button).off("click").click(function(){if(k._req){return}k._req=1;LA.loading();var l=b(this);k.key=l.data("id");k.direction=l.data("direction");k.row=l.closest("tr");k.tier=d(k.row);k._request()})},_request:function(){var n=this,q=n.key,s=n.row,m=n.tier,p=n.direction,r=s.prevAll(),o=s.nextAll(),k=s.prevAll("tr").first(),l=s.nextAll("tr").first();b.ajax({type:"POST",url:n.options.url.replace(":key",q),data:{_method:"PUT",_token:LA.token,_orderable:p},success:function(w){LA.loading(false);n._req=0;if(!w.status){return w.message&&LA.warning(w.message,"rt")}LA.success(w.message);if(p){var x=g(r,m);if(h(x,m)&&k.length&&d(k)>=m){x.before(s);e(o,s).forEach(function(y){x.before(y)})}}else{var u=g(o,m),v=u?e(u.nextAll(),u):[];if(h(u,m)&&l.length&&d(l)>=m){o=s.nextAll();if(v.length){u=b(v.pop())}var t=[];e(o,s).forEach(function(y){t.unshift(y)});t.forEach(function(y){u.after(y)});u.after(s)}}},error:function(u,t,v){n._req=0;LA.loading(false);LA.ajaxError(u,t,v)}})},};function c(k){return b(k).prop("tagName").toLocaleLowerCase()==="tr"}function d(k){return parseInt(b(k).data("tier")||0)}function i(k,l){return d(l)>d(k)}function e(n,m){var k=[],o=false,l;n.each(function(q,p){if(!c(p)||o){return}l||(l=b(p));if(l&&!i(m,l)){return}if(i(m,p)){k.push(p)}else{o=true}});return k}function h(l,k){if(l&&l.length&&k===d(l)){return true}}function g(m,k){var l;m.each(function(o,n){if(d(n)===k&&!l&&c(n)){l=b(n)}});return l}f.LA.grid.tree=function(k){return new a(k)};f.LA.grid.orderable=function(k){return new j(k)}})(window,$);
|