-
Notifications
You must be signed in to change notification settings - Fork 254
/
Copy pathng.pqgrid.min.js
9 lines (9 loc) · 5.7 KB
/
ng.pqgrid.min.js
1
2
3
4
5
6
7
8
9
/*!
* Angularjs grid v2.0.5
*
* Copyright (c) 2016 Paramvir Dhindsa (http://paramquery.com)
* Released under GNU General Public License v3
* http://paramquery.com/license
*
*/
!function(e){"use strict";function t(e,t){return e.arr==t.arr&&e.len==t.len&&e.first==t.first&&e.last==t.last}function n(e){var t=e.length;return{arr:e,len:t,first:t?e[0]:null,last:t?e[t-1]:null}}function r(t,n,r,i,a,c){var l=this;l.$scope=t,l.$compile=i,l.$timeout=a,l.$parse=c,l.rowScopes=[],l.$ele=n;var s=r.cloneOptions,d=r.options,u=t.$eval(d),p=r.rebind,f=s?e.extend(!0,{},u):u,$=f.ngModel||{},h=l.readCellTemplates(f.colModel||[])||$.compileRows,g=f.dataModel,v="string"==typeof g.data?g.data:null,w=$.watch||1,m=l.detailTmpl=f.detailTemplate;l.timerDigest=o.timer(),p&&("all"==p?l.rebindAll(u,d):l.rebind(p,d)),m&&l.templateDetail(m,f),l.unregWatch=w&&v?function(){return w===!0?t.$watchCollection(v,l.watchCollListener(l)):t.$watch(l.watch(l,v))}():null,v&&(g.data=t.$eval(v)),f.render=l.onRender(l,f,f.render),$.compileHeader&&(f.refreshHeader=l.onRefreshHeader(l,f.refreshHeader)),$.compileToolbar&&(f.dataAvailable=l.oneDataReady(l,"dataAvailable")),f.beforeRefreshData=l.onDataReady(l,v,f.dataReady),h&&(f.refresh=l.onRefresh(l,f.refresh)),n.pqGrid(f).data("pqGrid"),n.on("pqgridcellsave",l.onRefreshRowCell(l,h)).on("destroy",l.onDestroy(l)),l.bindEvents(r),w===!0&&v&&l.digest(t)}var i=window.pq=window.pq||{};if(!i.ng){i.ng={};var o={timer:function(){var e;return{setTimeout:function(t){e&&clearTimeout(e),e=setTimeout(t)}}}};i.ng.cGrid=r;var a=r.prototype;a.onEvent=function(e,t){return function(n,r){var i=e.$scope.$new();i.evt=n,i.ui=r,i.$eval(t),i.$destroy(),e.digestAsync()}},a.bindEvents=function(e){var t,n,r=e.$attr,i=this;for(n in r)0===n.indexOf("on")&&(t=n.substring(2,3).toLowerCase()+n.substr(3),i.$ele.on("pqgrid"+t.toLowerCase(),i.onEvent(i,e[n])))},a.rebindWListen=function(e,t){return function(n,r){n!==r&&(e.grid.option(t,n),e.grid.refreshView())}},a.compareObj=function(t,n,r,i){var o,a,c,l;for(o in n)a=t[o],c=n[o],l=(i?i+".":"")+o,e.isPlainObject(a)?this.compareObj(a,c,r,l):a===c||e.isArray(a)||r(l,a)},a.copy=function(t,n){var r,i,o=this;for(var r in t)i=t[r],e.isPlainObject(i)?(n[r]={},o.copy(i,n[r])):n[r]=i;return n},a.rebindAll=function(e,t){var n=this,r=n.$scope,i=n.copy(e,{});r.$watch(function(){var e=!1,o=r.$eval(t);n.compareObj(o,i,function(t,r){e=!0,n.grid.option(t,r)}),e&&(i=n.copy(o,{}),n.grid.refreshView())})},a.rebind=function(e,t){for(var n=e.split(" "),r=this,i=r.$scope,o=0;o<n.length;o++){var a=n[o],c=t+"."+a;i.$watch(c,r.rebindWListen(r,a))}},a.templateDetail=function(e,t){var n=this;t.detailModel=t.detailModel||{},t.detailModel.init=function(t){var r,i=n.$scope.$new(!1);return i.ui=t,t.rowData.pq_scope_detail=i,e="function"==typeof e?e.call(this,t):e,r=n.$compile(e)(i),n.digest(i),r}},a.detailDestroyScopes=function(){if(this.detailTmpl)for(var e,t,n=this.grid.option("dataModel.data"),r=0,i=n.length;i>r;r++)t=n[r],(e=t.pq_scope_detail)&&e.$destroy()},a.onDataReady=function(e,t){return function(n){if(t){var r=e.grid.options.dataModel.data;e.updateObjInt(r),e.$parse(t).assign(e.$scope,r)}e.digestAsync()}},a.watchCollListener=function(e){return function(t,n){t!==n&&e.refreshGrid(t)}},a.watch=function(e,r){return function(){var i,o,a=e.$scope.$eval(r);o=n(a),i=e.objInt,i&&!t(i,o)&&e.refreshGrid(a)}},a.updateObjInt=function(e){this.objInt=n(e)},a.cleanRowScopes=function(){for(var e=0,t=this.rowScopes,n=t.length;n>e;e++)t[e].$destroy();t.length=0},a.onRefreshRowCell=function(e,t){return function(n,r){if(t){var i=e.grid.getRow(r);setTimeout(function(){try{e.rowScope(i,r.rowData,r.rowIndx)}catch(t){}})}}},a.onRefresh=function(t){return function(){var n,r,i,o,a,c=t.grid,l=0;for(t.cleanRowScopes(),n=c.$cont.children().children().children().children(".pq-grid-row:not('.pq-detail-child')"),i=n.length;i>l;l++)r=e(n[l]),o=c.getRowIndx({$tr:r}),a=c.getRowData(o),t.rowScope(r,a,o.rowIndx)}},a.onRefreshHeader=function(e){return function(){var t=e.grid,n=e.$scope;e.$compile(t.$header)(n),e.digest(n)}},a.oneDataReady=function(t,n){return function(){var r=t.grid,i=t.$scope;t.$compile(r.$toolbar)(i),t.digest(i),e(this).pqGrid("option",n,null)}},a.onRender=function(t,n,r){return function(i,o){var a=e(this).data("paramqueryPqGrid"),c=t.$scope;c.grid=a,t.grid=a,a.$scope=c,n.grid=a,r&&r.call(this,i,o)}},a.onDestroy=function(e){return function(){e.$scope.$destroy(),e.cleanRowScopes(),e.detailDestroyScopes(),e.unregWatch&&e.unregWatch()}},a.digestAsync=function(){var e=this,t=e.timerDigest,n=e.$scope.$root,r=n.$$phase;"$apply"!=r&&"$digest"!=r&&t.setTimeout(function(){r=n.$$phase,"$apply"!=r&&"$digest"!=r&&n.$digest()})},a.digest=function(e){var t=e.$root.$$phase;"$apply"!=t&&"$digest"!=t&&e.$digest()},a.rowScope=function(e,t,n){var r=this,i=r.$scope.$new(!1);r.rowScopes.push(i),i.rd=t,i.ri=n,r.$compile(e)(i),r.digest(i)},a.readCellTemplates=function(e){for(var t,n,r,i,o=0,a=e.length,c=this,l=c.$scope,s=c.$compile;a>o;o++)if(t=e[o],(n=t.template)&&(r=!0,t.render=c.templateCell(n)),(n=t.editorTemplate)&&(t.editor={type:c.templateEditor(c,t.editor,n,s,l)}),i=t.validations)for(var d=0;d<i.length;d++)(n=i[d].template)&&(i[o].type=c.templateValid(n,s,l));return r},a.templateValid=function(e,t,n){return function(r){var i,o=n.$new(!1);return o.ui=r,t(e)(o),i=o["return"],o.$destroy(),i}},a.templateEditor=function(e,t,n,r,i){return function(e){var t,o=i.$new(!1);o.ui=e,r(n)(o),t=o.editor,o.$destroy()}},a.templateCell=function(e){return function(){return e}},a.refreshGrid=function(e){var t=this.grid;t.option("dataModel.data",e),t.refreshView()},angular.module("pq.grid",[]).directive("pqGrid",["$compile","$timeout","$parse",function(e,t,n){return{restrict:"AE",scope:!0,replace:!0,link:function(i,o,a){new r(i,o,a,e,t,n)},template:"<div></div>"}}])}}(jQuery);