12 |
- !function(t){"use strict";"function"==typeof define&&define.amd?define(["jquery","./grid.base"],t):"object"==typeof module&&module.exports?module.exports=function(e,r){return e||(e=window),void 0===r&&(r="undefined"!=typeof window?require("jquery"):require("jquery")(e)),require("./grid.base"),t(r),r}:t(jQuery)}(function(T){"use strict";var S=T.jgrid,u=S.getAccessor,f=S.stripPref,v=S.jqID,k=T.fn.jqGrid,n=function(){var e=T.makeArray(arguments);return e[0]="treeGrid"+e[0].charAt(0).toUpperCase()+e[0].substring(1),e.unshift(""),e.unshift(""),e.unshift(this.p),S.feedback.apply(this,e)},o=function(e,r){var t=r[e.treeReader.icon_field],a=e.treeIcons,i=a.plus+" tree-plus",d=a.minus+" tree-minus";return t&&"string"==typeof t&&2===(t=t.split(",")).length&&(d=t[0],i=t[1]),{expanded:d,collapsed:i,common:a.commonIconClass}};S.extend({setTreeNode:function(){return this.each(function(){var e=this,n=T(e),o=e.p;if(e.grid&&o.treeGrid){var s=o.treeReader.expanded_field,c=o.treeReader.leaf_field;n.off("jqGridBeforeSelectRow.setTreeNode"),n.on("jqGridBeforeSelectRow.setTreeNode",function(e,t,r){if(null!=r){var a=T(r.target),i=a.closest("tr.jqgrow>td"),d=i.parent(),l=function(){var e=o.data[o._index[f(o.idPrefix,t)]],r=e[s]?"collapse":"expand";e[c]||(k[r+"Row"].call(n,e,d),k[r+"Node"].call(n,e,d))};return a.is("div.treeclick")?l():o.ExpandColClick&&0<i.length&&0<a.closest("span.cell-wrapper",i).length&&l(),!0}})}})},setTreeGrid:function(){return this.each(function(){var e,r,t,a=this.p,i=[],d=["leaf_field","expanded_field","loaded"];if(a.treeGrid){for(r in a.treedatatype||T.extend(this.p,{treedatatype:a.datatype}),a.subGrid=!1,a.altRows=!1,a.pgbuttons=!1,a.pginput=!1,a.gridview=!0,null===a.rowTotal&&(a.rowNum=a.maxRowNum),a.rowList=[],a.treeIcons.plus="rtl"===a.direction?a.treeIcons.plusRtl:a.treeIcons.plusLtr,"nested"===a.treeGridModel?a.treeReader=T.extend({level_field:"level",left_field:"lft",right_field:"rgt",leaf_field:"isLeaf",expanded_field:"expanded",loaded:"loaded",icon_field:"icon"},a.treeReader):"adjacency"===a.treeGridModel&&(a.treeReader=T.extend({level_field:"level",parent_id_field:"parent",leaf_field:"isLeaf",expanded_field:"expanded",loaded:"loaded",icon_field:"icon"},a.treeReader)),a.colModel)if(a.colModel.hasOwnProperty(r))for(t in e=a.colModel[r].name,a.treeReader)a.treeReader.hasOwnProperty(t)&&a.treeReader[t]===e&&i.push(e);T.each(a.treeReader,function(e){var r=String(this);r&&-1===T.inArray(r,i)&&(0<=T.inArray(e,d)?a.additionalProperties.push({name:r,search:!1,convert:function(e){return!0===e||"true"===String(e).toLowerCase()||"1"===String(e)||e}}):a.additionalProperties.push(r))})}})},expandRow:function(l){this.each(function(){var e=this,r=T(e),t=e.p;if(e.grid&&t.treeGrid){var a=t.treeReader.expanded_field,i=l[t.localReader.id];if(n.call(e,"beforeExpandRow",{rowid:i,item:l})){var d=k.getNodeChildren.call(r,l);T(d).each(function(){var e=t.idPrefix+u(this,t.localReader.id);T(k.getGridRowById.call(r,e)).css("display",""),this[a]&&k.expandRow.call(r,this)}),n.call(e,"afterExpandRow",{rowid:i,item:l})}}})},collapseRow:function(l){this.each(function(){var e=this,r=T(e),t=e.p;if(e.grid&&t.treeGrid){var a=t.treeReader.expanded_field,i=l[t.localReader.id];if(n.call(e,"beforeCollapseRow",{rowid:i,item:l})){var d=k.getNodeChildren.call(r,l);T(d).each(function(){var e=t.idPrefix+u(this,t.localReader.id);T(k.getGridRowById.call(r,e)).css("display","none"),this[a]&&k.collapseRow.call(r,this)}),n.call(e,"afterCollapseRow",{rowid:i,item:l})}}})},getRootNodes:function(){var a=[];return this.each(function(){var e=this.p;if(this.grid&&e.treeGrid)switch(e.treeGridModel){case"nested":var r=e.treeReader.level_field;T(e.data).each(function(){parseInt(this[r],10)===parseInt(e.tree_root_level,10)&&a.push(this)});break;case"adjacency":var t=e.treeReader.parent_id_field;T(e.data).each(function(){null!==this[t]&&"null"!==String(this[t]).toLowerCase()||a.push(this)})}}),a},getNodeDepth:function(t){var a=null;return this.each(function(){var e=this.p;if(this.grid&&e.treeGrid)switch(e.treeGridModel){case"nested":var r=e.treeReader.level_field;a=parseInt(t[r],10)-parseInt(e.tree_root_level,10);break;case"adjacency":a=k.getNodeAncestors.call(T(this),t).length}}),a},getNodeParent:function(e){var r=this[0];if(!r||!r.grid||null==r.p||!r.p.treeGrid||null==e)return null;var t=r.p,a=t.treeReader,i=e[a.parent_id_field];if("nested"===t.treeGridModel){var d=null,l=a.left_field,n=a.right_field,o=a.level_field,s=parseInt(e[l],10),c=parseInt(e[n],10),f=parseInt(e[o],10);return T(t.data).each(function(){if(parseInt(this[o],10)===f-1&&parseInt(this[l],10)<s&&parseInt(this[n],10)>c)return d=this,!1}),d}if(null===i||"null"===i)return null;var h=t._index[i];return void 0!==h?t.data[h]:null},getNodeChildren:function(s){var c=[];return this.each(function(){var e=this.p;if(this.grid&&e.treeGrid)switch(e.treeGridModel){case"nested":var r=e.treeReader.left_field,t=e.treeReader.right_field,a=e.treeReader.level_field,i=parseInt(s[r],10),d=parseInt(s[t],10),l=parseInt(s[a],10);T(e.data).each(function(){parseInt(this[a],10)===l+1&&parseInt(this[r],10)>i&&parseInt(this[t],10)<d&&c.push(this)});break;case"adjacency":var n=e.treeReader.parent_id_field,o=e.localReader.id;T(e.data).each(function(){String(this[n])===String(s[o])&&c.push(this)})}}),c},getFullTreeNode:function(c){var f=[];return this.each(function(){var r,e=this.p;if(this.grid&&e.treeGrid)switch(e.treeGridModel){case"nested":var t=e.treeReader.left_field,a=e.treeReader.right_field,i=e.treeReader.level_field,d=parseInt(c[t],10),l=parseInt(c[a],10),n=parseInt(c[i],10);T(e.data).each(function(){parseInt(this[i],10)>=n&&parseInt(this[t],10)>=d&&parseInt(this[t],10)<=l&&f.push(this)});break;case"adjacency":if(c){f.push(c);var o=e.treeReader.parent_id_field,s=e.localReader.id;T(e.data).each(function(){var e;for(r=f.length,e=0;e<r;e++)if(String(f[e][s])===String(this[o])){f.push(this);break}})}}}),f},getNodeAncestors:function(a){var i=[];return this.each(function(){var e=T(this),r=k.getNodeParent;if(this.grid&&this.p.treeGrid)for(var t=r.call(e,a);t;)i.push(t),t=r.call(e,t)}),i},isVisibleNode:function(a){var i=!0;return this.each(function(){var e=this.p;if(this.grid&&e.treeGrid){var r=k.getNodeAncestors.call(T(this),a),t=e.treeReader.expanded_field;T(r).each(function(){if(!(i=i&&this[t]))return!1})}}),i},isNodeLoaded:function(a){var i;return this.each(function(){var e=this.p;if(this.grid&&e.treeGrid){var r=e.treeReader.leaf_field,t=e.treeReader.loaded;i=void 0!==a&&(void 0!==a[t]?a[t]:!!(a[r]||0<k.getNodeChildren.call(T(this),a).length))}}),i},expandNode:function(l){return this.each(function(){var e,r,t,a=this,i=a.p;if(a.grid&&i.treeGrid){var d=i.treeReader;if(!l[d.expanded_field]){if(e=u(l,i.localReader.id),!n.call(a,"beforeExpandNode",{rowid:e,item:l}))return;r=T("#"+i.idPrefix+v(e),a.grid.bDiv)[0],l[d.expanded_field]=!0,t=o(i,l),T("div.treeclick",r).removeClass(t.collapsed).addClass(t.common).addClass(t.expanded),"local"===i.treedatatype||k.isNodeLoaded.call(T(a),i.data[i._index[e]])||a.grid.hDiv.loading||(i.treeANode=r.rowIndex,i.datatype=i.treedatatype,k.setGridParam.call(T(a),{postData:"nested"===i.treeGridModel?{nodeid:e,n_level:l[d.level_field],n_left:l[d.left_field],n_right:l[d.right_field]}:{nodeid:e,n_level:l[d.level_field],parentid:l[d.parent_id_field]}}),T(a).trigger("reloadGrid"),l[d.loaded]=!0,k.setGridParam.call(T(a),{postData:"nested"===i.treeGridModel?{nodeid:"",n_level:"",n_left:"",n_right:""}:{nodeid:"",n_level:"",parentid:""}})),n.call(a,"afterExpandNode",{rowid:e,item:l})}}})},collapseNode:function(d){return this.each(function(){var e,r=this,t=r.p;if(r.grid&&t.treeGrid){var a=t.treeReader.expanded_field;if(d[a]){var i=u(d,t.localReader.id);if(!n.call(r,"beforeCollapseNode",{rowid:i,item:d}))return;d[a]=!1,e=o(t,d),T("#"+t.idPrefix+v(i),r.grid.bDiv).find("div.treeclick").removeClass(e.expanded).addClass(e.common).addClass(e.collapsed),(!0===t.unloadNodeOnCollapse||T.isFunction(t.unloadNodeOnCollapse)&&t.unloadNodeOnCollapse.call(r,d))&&(d[t.treeReader.loaded]=!1,T(r).jqGrid("delTreeNode",i,!0)),n.call(r,"afterCollapseNode",{rowid:i,item:d})}}})},SortTree:function(c,f,h,p){return this.each(function(){var t=this,a=t.p,i=T(t);if(t.grid&&a.treeGrid){var e,r,d,l=[],n=k.getRootNodes.call(i),o=S.from.call(t,n);o.orderBy(c,f,h,p);var s=o.select();for(e=0,r=s.length;e<r;e++)d=s[e],l.push(d),k.collectChildrenSortTree.call(i,l,d,c,f,h,p);T.each(l,function(e){var r=u(this,a.localReader.id);T(t.rows[e]).after(i.find(">tbody>tr#"+v(r)))})}})},collectChildrenSortTree:function(n,o,s,c,f,h){return this.each(function(){var e=T(this);if(this.grid&&this.p.treeGrid){var r,t,a,i=k.getNodeChildren.call(e,o),d=S.from.call(this,i);d.orderBy(s,c,f,h);var l=d.select();for(r=0,t=l.length;r<t;r++)a=l[r],n.push(a),k.collectChildrenSortTree.call(e,n,a,s,c,f,h)}})},setTreeRow:function(e,r){var t=!1;return this.each(function(){this.grid&&this.p.treeGrid&&(t=k.setRowData.call(T(this),e,r))}),t},delTreeNode:function(p,u){return this.each(function(){var e,r,t,a,i,d=this,l=d.p,n=l.localReader.id,o=T(d),s=l.treeReader.left_field,c=l.treeReader.right_field;if(d.grid&&l.treeGrid){var f=l._index[p];if(void 0!==f){r=(e=parseInt(l.data[f][c],10))-parseInt(l.data[f][s],10)+1;var h=k.getFullTreeNode.call(o,l.data[f]);if(0<h.length)for(i=0;i<h.length;i++)u&&p===h[i][n]||k.delRowData.call(o,h[i][n]);if("nested"===l.treeGridModel){if((t=S.from.call(d,l.data).greater(s,e,{stype:"integer"}).select()).length)for(a in t)t.hasOwnProperty(a)&&(t[a][s]=parseInt(t[a][s],10)-r);if((t=S.from.call(d,l.data).greater(c,e,{stype:"integer"}).select()).length)for(a in t)t.hasOwnProperty(a)&&(t[a][c]=parseInt(t[a][c],10)-r)}}}})},addChildNode:function(b,P,j,M){return this.each(function(){if(j){var e,r,t,a,i,d,l,n=this,o=n.p,s=T(n),c=k.getInd,f=o.treeIcons.minus+" tree-minus",h=P,p=o.treeReader.expanded_field,u=o.treeReader.leaf_field,v=o.treeReader.level_field,g=o.treeReader.parent_id_field,_=o.treeReader.left_field,R=o.treeReader.right_field,w=o.treeReader.loaded;void 0===M&&(M=!1),null==b&&(b=S.randId());var I,m,x=c.call(s,P);if(d=!1,null==P||""===P)h=P=null,e="last",a=o.tree_root_level;else{e="after",r=o._index[P],t=o.data[r],P=t[o.localReader.id],i=c.call(s,P),a=parseInt(t[v],10)+1;var y,G,N,C=k.getFullTreeNode.call(s,t);if(C.length)for(y=0;y<C.length;y++)N=C[y][o.localReader.id],i<(G=c.call(s,N))&&(i=G,h=N);t[u]&&(d=!0,t[p]=!0,T(n.rows[x]).find("span.cell-wrapperleaf").removeClass("cell-wrapperleaf").addClass("cell-wrapper").end().find("div.tree-leaf").removeClass(o.treeIcons.leaf+" tree-leaf").addClass(o.treeIcons.commonIconClass).addClass(f),o.data[r][u]=!1,t[w]=!0)}if(void 0===j[p]&&(j[p]=!1),void 0===j[w]&&(j[w]=!1),j[v]=a,void 0===j[u]&&(j[u]=!0),"adjacency"===o.treeGridModel&&(j[g]=P),"nested"===o.treeGridModel)if(null!==P){if(l=parseInt(t[R],10),(I=S.from.call(n,o.data).greaterOrEquals(R,l,{stype:"integer"}).select()).length)for(m in I)I.hasOwnProperty(m)&&(I[m][_]=I[m][_]>l?parseInt(I[m][_],10)+2:I[m][_],I[m][R]=I[m][R]>=l?parseInt(I[m][R],10)+2:I[m][R]);j[_]=l,j[R]=l+1}else{if(l=parseInt(k.getCol.call(s,R,!1,"max"),10),(I=S.from.call(n,o.data).greater(_,l,{stype:"integer"}).select()).length)for(m in I)I.hasOwnProperty(m)&&(I[m][_]=parseInt(I[m][_],10)+2);if((I=S.from.call(n,o.data).greater(R,l,{stype:"integer"}).select()).length)for(m in I)I.hasOwnProperty(m)&&(I[m][R]=parseInt(I[m][R],10)+2);j[_]=l+1,j[R]=l+2}(null===P||k.isNodeLoaded.call(s,t)||d)&&k.addRowData.call(s,b,j,e,h),t&&!t[p]&&M&&T(n.rows[x]).find("div.treeclick").click()}})}})});
- //# sourceMappingURL=grid.treegrid.js.map
|