forked from MoonStorm/trNgGrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrNgGrid.min.js
1 lines (1 loc) · 27.4 KB
/
trNgGrid.min.js
1
"use strict";var TrNgGrid;(function(n){function st(t){t.get(n.cellHeaderTemplateId)||t.put(n.cellHeaderTemplateId,'<div class="'+n.headerCellCssClass+'" ng-switch="isCustomized"> <div ng-switch-when="true"> <div ng-transclude=""><\/div> <\/div> <div ng-switch-default> <div class="'+n.columnTitleCssClass+'"> {{columnTitle |'+n.translateFilter+":gridOptions.locale}} <div "+n.columnSortDirectiveAttribute+'=""><\/div> <\/div> <div '+n.columnFilterDirectiveAttribute+'=""><\/div> <\/div><\/div>');t.get(n.cellBodyTemplateId)||t.put(n.cellBodyTemplateId,'<div ng-attr-class="'+n.bodyCellCssClass+' text-{{columnOptions.displayAlign}}" ng-switch="isCustomized"> <div ng-switch-when="true"> <div ng-transclude=""><\/div> <\/div> <div ng-switch-default>{{gridDisplayItem[columnOptions.displayFieldName]}}<\/div><\/div>');t.get(n.columnFilterTemplateId)||t.put(n.columnFilterTemplateId,'<div ng-show="(gridOptions.enableFiltering&&columnOptions.enableFiltering!==false)||columnOptions.enableFiltering" class="'+n.columnFilterCssClass+'"> <div class="'+n.columnFilterInputWrapperCssClass+'"> <input class="form-control input-sm" type="text" ng-model="columnOptions.filter" ng-keypress="speedUpAsyncDataRetrieval($event)"><\/input> <\/div><\/div>');t.get(n.columnSortTemplateId)||t.put(n.columnSortTemplateId,"<div ng-attr-title=\"{{'Sort'|"+n.translateFilter+':gridOptions.locale}}" ng-show="(gridOptions.enableSorting&&columnOptions.enableSorting!==false)||columnOptions.enableSorting" ng-click="toggleSorting(columnOptions.fieldName)" class="'+n.columnSortCssClass+'" > <div ng-class="{\''+n.columnSortActiveCssClass+"':gridOptions.orderBy==columnOptions.fieldName,'"+n.columnSortInactiveCssClass+"':gridOptions.orderBy!=columnOptions.fieldName,'"+n.columnSortNormalOrderCssClass+"':gridOptions.orderBy==columnOptions.fieldName&&!gridOptions.orderByReverse,'"+n.columnSortReverseOrderCssClass+"':gridOptions.orderBy==columnOptions.fieldName&&gridOptions.orderByReverse}\" > <\/div><\/div>");t.get(n.cellFooterTemplateId)||t.put(n.cellFooterTemplateId,'<div class="'+n.footerCssClass+'" ng-switch="isCustomized"> <div ng-switch-when="true"> <div ng-transclude=""><\/div> <\/div> <div ng-switch-default> <span '+n.globalFilterDirectiveAttribute+'=""><\/span> <span '+n.pagerDirectiveAttribute+'=""><\/span> <\/div><\/div>');t.get(n.footerGlobalFilterTemplateId)||t.put(n.footerGlobalFilterTemplateId,'<span ng-show="gridOptions.enableFiltering" class="pull-left form-group"> <input class="form-control" type="text" ng-model="gridOptions.filterBy" ng-keypress="speedUpAsyncDataRetrieval($event)" ng-attr-placeholder="{{\'Search\'|'+n.translateFilter+':gridOptions.locale}}"><\/input><\/span>');t.get(n.footerPagerTemplateId)||t.put(n.footerPagerTemplateId,'<span class="pull-right form-group"> <ul class="pagination"> <li ng-class="{disabled:!pageCanGoBack}" ng-if="extendedControlsActive"> <a href="" ng-click="pageCanGoBack&&navigateToPage(0)" ng-attr-title="{{\'First Page\'|'+n.translateFilter+':gridOptions.locale}}"> <span>«<\/span> <\/a> <\/li> <li ng-class="{disabled:!pageCanGoBack}" ng-if="extendedControlsActive"> <a href="" ng-click="pageCanGoBack&&navigateToPage(gridOptions.currentPage - 1)" ng-attr-title="{{\'Previous Page\'|'+n.translateFilter+':gridOptions.locale}}"> <span>‹<\/span> <\/a> <\/li> <li ng-if="pageSelectionActive" ng-repeat="pageIndex in pageIndexes track by $index" ng-class="{disabled:pageIndex===null, active:pageIndex===gridOptions.currentPage}"> <span ng-if="pageIndex===null">...<\/span> <a href="" ng-click="navigateToPage(pageIndex)" ng-if="pageIndex!==null" ng-attr-title="{{\'Page\'|'+n.translateFilter+':gridOptions.locale}}">{{pageIndex+1}}<\/a> <\/li> <li ng-class="{disabled:!pageCanGoForward}" ng-if="extendedControlsActive"> <a href="" ng-click="pageCanGoForward&&navigateToPage(gridOptions.currentPage + 1)" ng-attr-title="{{\'Next Page\'|'+n.translateFilter+':gridOptions.locale}}"> <span>›<\/span> <\/a> <\/li> <li ng-class="{disabled:!pageCanGoForward}" ng-if="extendedControlsActive"> <a href="" ng-click="pageCanGoForward&&navigateToPage(lastPageIndex)" ng-attr-title="{{\'Last Page\'|'+n.translateFilter+':gridOptions.locale}}"> <span>»<\/span> <\/a> <\/li> <li class="disabled" style="white-space: nowrap;"> <span ng-hide="totalItemsCount">{{\'No items to display\'|'+n.translateFilter+":gridOptions.locale}}<\/span> <span ng-show=\"totalItemsCount\"> {{startItemIndex+1}} - {{endItemIndex+1}} {{'displayed'|"+n.translateFilter+":gridOptions.locale}} <span>, {{totalItemsCount}} {{'in total'|"+n.translateFilter+":gridOptions.locale}}<\/span> <\/span > <\/li> <\/ul><\/span>")}var i,u,t,f,e,o,s;n.version="3.1.4",function(n){n[n.None=0]="None";n[n.SingleRow=1]="SingleRow";n[n.MultiRow=2]="MultiRow";n[n.MultiRowWithKeyModifiers=3]="MultiRowWithKeyModifiers"}(n.SelectionMode||(n.SelectionMode={}));i=n.SelectionMode;n.defaultColumnOptionsTemplate={cellWidth:null,cellHeight:null,displayAlign:null,displayFormat:null,displayName:null,filter:null,enableFiltering:null,enableSorting:null};n.defaultColumnOptions={};n.translations={};n.debugMode=!1;u=!1;t="trNgGrid";n.sortFilter=t+"SortFilter";n.dataPagingFilter=t+"DataPagingFilter";n.translateFilter=t+"TranslateFilter";n.translationDateFormat=t+"DateFormat";n.dataFormattingFilter=t+"DataFormatFilter";var l="tr-ng-grid-body",a="field-name",d="data-field-name",g="is-customized",nt="tr-ng-grid-footer-cell",v="trNgGridFooterCellTemplate",tt="tr-ng-grid-footer-cell-template";n.cellFooterTemplateId=v+".html";f="trNgGridGlobalFilter";n.globalFilterDirectiveAttribute="tr-ng-grid-global-filter";n.footerGlobalFilterTemplateId=f+".html";e="trNgGridPager";n.pagerDirectiveAttribute="tr-ng-grid-pager";n.footerPagerTemplateId=e+".html";var y="trNgGridHeaderCell",it="tr-ng-grid-header-cell",p="trNgGridHeaderCellTemplate",rt="tr-ng-grid-header-cell-template";n.cellHeaderTemplateId=p+".html";var w="trNgGridBodyCell",ut="tr-ng-grid-body-cell",b="trNgGridBodyCellTemplate",ft="tr-ng-grid-body-cell-template";n.cellBodyTemplateId=b+".html";o="trNgGridColumnSort";n.columnSortDirectiveAttribute="tr-ng-grid-column-sort";n.columnSortTemplateId=o+".html";s="trNgGridColumnFilter";n.columnFilterDirectiveAttribute="tr-ng-grid-column-filter";n.columnFilterTemplateId=s+".html";var k=function(n,t){var r,i,u;for(t=t.toUpperCase(),r=n.children(),i=0;i<r.length;i++)if(u=r[i],u.tagName==t)return angular.element(u);return null},ht=function(n,t){var r,u,i,f;for(t=t.toUpperCase(),r=[],u=n.children(),i=0;i<u.length;i++)f=u[i],f.tagName===t&&r.push(angular.element(f));return r},r=function(n,t,i,r){var u=[],f=t.slice(0);return angular.forEach(n,function(n){for(var t=null,i=0;!t&&i<f.length;i++)t=f[i],t.fieldName===n.fieldName?f.splice(i,1):t=null;t?u.push(t):u.push(n)}),(i||r)&&angular.forEach(f,function(n){(i&&n.fieldName||r&&!n.fieldName)&&u.push(n)}),u},h=function(n,t,i,r){var u,e,f;i?(u=n.children(),e=angular.element(u[0]),u.length===1&&e.attr(r)||(n.empty(),f=angular.element("<div><\/div>").attr(r,""),n.append(f),angular.forEach(u,function(n){f.append(angular.element(n))}))):(n.empty(),n.append(angular.element("<div><\/div>").attr(r,"")))},et=function(){function n(n,t){this.parent=n;this.cellElement=t;this.fieldName=t.attr(a)||t.attr(d);var i=t.children();this.isStandardColumn=i.length===0}return n}(),c=function(){function n(n,t,i,r,u){this.sectionTagName=n;this.sectionDirectiveAttribute=t;this.rowDirectiveAttribute=i;this.cellTagName=r;this.cellDirectiveAttribute=u;this.cellTagName=this.cellTagName.toUpperCase();this.cells=null}return n.prototype.configureSection=function(n,t){var i=this,u=this.getSectionElement(n,!0),f,e;return u.empty(),u.removeAttr("ng-non-bindable"),f=r(t,this.cells,!1,!1),e=this.getTemplatedRowElement(u,!0),angular.forEach(f,function(n,t){var r,u=n;r=u.parent===i&&u.cellElement?u.cellElement.clone(!0):angular.element("<table><"+i.cellTagName+"><\/"+i.cellTagName+"><\/table>").find(i.cellTagName);i.cellDirectiveAttribute&&r.attr(i.cellDirectiveAttribute,t);n.isStandardColumn||r.attr(g,"true");n.fieldName&&r.attr(a,n.fieldName);r.attr("ng-style","{'width':columnOptions.cellWidth,'height':columnOptions.cellHeight}");e.append(r)}),u},n.prototype.extractPartialColumnDefinitions=function(){return this.cells},n.prototype.discoverTemplates=function(n){var i=this,t;this.cells=[];this.cellRow=null;t=this.getTemplatedRowElement(this.getSectionElement(n,!1),!1);t&&(this.cellRow=angular.element(t.clone()),this.cellRow.empty(),angular.forEach(t.children(),function(n){if(n=angular.element(n),n[0].tagName===i.cellTagName.toUpperCase()){var t=n.clone();i.cells.push(new et(i,t))}}))},n.prototype.getSectionElement=function(n,t){var i=null;return n&&(i=k(n,this.sectionTagName)),!i&&t&&(i=angular.element("<table><"+this.sectionTagName+"><\/"+this.sectionTagName+"><\/table>").find(this.sectionTagName),n&&n.append(i)),i&&t&&this.sectionDirectiveAttribute&&i.attr(this.sectionDirectiveAttribute,""),i},n.prototype.getTemplatedRowElement=function(n,t){var i=null;return n&&(i=k(n,"tr")),!i&&t&&(i=this.cellRow?angular.element(this.cellRow.clone()):angular.element("<table><tr><\/tr><\/table>").find("tr"),n&&n.append(i)),i&&t&&this.rowDirectiveAttribute&&i.attr(this.rowDirectiveAttribute,""),i},n}(),ot=function(){function f(n,t,i,r){this.$compile=n;this.$parse=t;this.$timeout=i;u||(st(r),u=!0)}return f.prototype.setupGrid=function(t,r,u){return this.gridOptions=r,this.isInServerSideMode=u,t.gridOptions=r,t.TrNgGrid=n,r.gridColumnDefs=[],r.locale===undefined&&(r.locale="en"),r.selectionMode===undefined&&(r.selectionMode=i[2]),r.filterByFields===undefined&&(r.filterByFields={}),r.enableFiltering===undefined&&(r.enableFiltering=!0),r.enableSorting===undefined&&(r.enableSorting=!0),r.onDataRequiredDelay===undefined&&(r.onDataRequiredDelay=1e3),r.selectedItems===undefined&&(r.selectedItems=[]),r.currentPage===undefined&&(r.currentPage=0),this.setupServerSideModeTriggers(t),this.setupDataFilteringTriggers(t),this.setupDataFormattingTriggers(t),this.setupDataSelectionTriggers(t),t},f.prototype.setupDataFilteringTriggers=function(n){var t=this,i=!1,r;this.scheduleDataFiltering=function(){i||(n.$evalAsync(function(){i=!1;t.computeFilteredItems(n)}),i=!0)};this.isInServerSideMode||(r=!0,n.$watchCollection("[gridOptions.filterBy,gridOptions.filterByFields,gridOptions.orderBy,gridOptions.orderByReverse,gridOptions.pageItems]",function(){r?r=!1:(t.gridOptions.currentPage=0,t.scheduleDataFiltering())}),n.$watch("gridOptions.currentPage",function(n,i){n!==i&&t.scheduleDataFiltering()}))},f.prototype.setupDataFormattingTriggers=function(t){var u=this,r=!1,i;this.scheduleDataFormatting=function(){r||(t.$evalAsync(function(){r=!1;u.computeFormattedItems(t)}),r=!0)};i="[gridOptions.items,gridOptions.gridColumnDefs.length";angular.forEach(t.gridOptions.gridColumnDefs,function(n){if(n.displayFormat&&n.displayFormat[0]!="."){var t=n.displayFormat.split("|");angular.forEach(t,function(n){var t=n.split(":");t.length>1&&angular.forEach(t.slice(1),function(n){n=n.trim();n&&n!=="gridItem"&&n!=="gridDisplayItem"&&(i+=","+n)})})}});i+="]";n.debugMode&&this.log("re-formatting is set to watch for changes in "+i);t.$watch(i,function(){return u.scheduleDataFormatting()},!0)},f.prototype.setupServerSideModeTriggers=function(t){var i=this,s;if(this.isInServerSideMode){var r=null,u=!1,f=!1,e=!1,o=function(){r&&(i.$timeout.cancel(r),r=null)},h=function(){n.debugMode&&i.log("Preparing to request data - server side mode");o();var r=function(){t.$applyAsync(function(){u=!1;try{n.debugMode&&i.log("Requesting data - server side mode");i.gridOptions.onDataRequired(i.gridOptions)}catch(t){n.debugMode&&i.log("Data retrieval failed "+t);throw t;}})};e?t.$evalAsync(function(){n.debugMode&&i.log("Resetting the page index - server side mode");t.gridOptions.currentPage=0;e=!1;r()}):r()};this.scheduleServerSideModeDataRetrieval=function(){u||(o(),r=i.$timeout(function(){r=null;u=!0;h()},i.gridOptions.onDataRequiredDelay,!0),f&&i.speedUpServerSideModeDataRetrieval())};this.speedUpServerSideModeDataRetrieval=function(n){n&&n.keyCode!=13||(r?(f=!1,o(),u=!0,h()):f=!0)};t.$watch("gridOptions.currentPage",function(t,r){t!==r&&(n.debugMode&&i.log("Changes detected in the current page index in server-side mode. Scheduling data retrieval..."),i.scheduleServerSideModeDataRetrieval())});s=!0;t.$watchCollection("[gridOptions.filterBy, gridOptions.filterByFields, gridOptions.orderBy, gridOptions.orderByReverse, gridOptions.pageItems]",function(){s?s=!1:(i.gridOptions.currentPage!==0&&(n.debugMode&&i.log("Changes detected in parameters in server-side mode. Requesting a page index reset..."),e=!0),n.debugMode&&i.log("Changes detected in parameters in server-side mode. Scheduling data retrieval..."),i.scheduleServerSideModeDataRetrieval())});this.scheduleServerSideModeDataRetrieval();this.speedUpServerSideModeDataRetrieval()}else this.speedUpServerSideModeDataRetrieval=function(){};t.speedUpAsyncDataRetrieval=function(n){return i.speedUpServerSideModeDataRetrieval(n)}},f.prototype.setupDataSelectionTriggers=function(n){var t=this;n.$watch("gridOptions.selectionMode",function(n,r){if(n!==r)switch(n){case i[0]:t.gridOptions.selectedItems.splice(0);break;case i[1]:t.gridOptions.selectedItems.length>1&&t.gridOptions.selectedItems.splice(1)}})},f.prototype.setColumnOptions=function(n,t){var i=this.gridOptions.gridColumnDefs[n];if(!i)throw"Invalid grid column options found for column index "+n+". Please report this error.";t=angular.extend(t,i);this.gridOptions.gridColumnDefs[n]=t},f.prototype.toggleSorting=function(n){this.gridOptions.orderBy!=n?this.gridOptions.orderBy=n:this.gridOptions.orderByReverse=!this.gridOptions.orderByReverse;this.speedUpServerSideModeDataRetrieval()},f.prototype.toggleItemSelection=function(n,t,r){var h,f,c,e,l,o,s,u;if(this.gridOptions.selectionMode!==i[0])switch(this.gridOptions.selectionMode){case i[3]:if(r.ctrlKey||r.shiftKey||r.metaKey){if(r.ctrlKey||r.metaKey)u=this.gridOptions.selectedItems.indexOf(t),u>=0?this.gridOptions.selectedItems.splice(u,1):this.gridOptions.selectedItems.push(t);else if(r.shiftKey){for(document.selection&&document.selection.empty?document.selection.empty():window.getSelection&&(h=window.getSelection(),h.removeAllRanges()),c=this.gridOptions.selectedItems[this.gridOptions.selectedItems.length-1],f=0;f<n.length&&n[f].$$_gridItem!==c;f++);for(f>=n.length&&(f=0),e=0;e<n.length&&n[e].$$_gridItem!==t;e++);if(e>=n.length)throw"Invalid selection on a key modifier selection mode";for(e<f&&(l=f,f=e,e=l),o=f;o<=e;o++)s=n[o].$$_gridItem,this.gridOptions.selectedItems.indexOf(s)<0&&this.gridOptions.selectedItems.push(s)}}else u=this.gridOptions.selectedItems.indexOf(t),this.gridOptions.selectedItems.splice(0),u<0&&this.gridOptions.selectedItems.push(t);break;case i[1]:u=this.gridOptions.selectedItems.indexOf(t);this.gridOptions.selectedItems.splice(0);u<0&&this.gridOptions.selectedItems.push(t);break;case i[2]:u=this.gridOptions.selectedItems.indexOf(t);u>=0?this.gridOptions.selectedItems.splice(u,1):this.gridOptions.selectedItems.push(t)}},f.prototype.discoverTemplates=function(n){this.templatedHeader=new c("thead",null,null,"th",it);this.templatedBody=new c("tbody",l,null,"td",ut);this.templatedFooter=new c("tfoot",null,null,"td",nt);this.templatedHeader.discoverTemplates(n);this.templatedFooter.discoverTemplates(n);this.templatedBody.discoverTemplates(n)},f.prototype.getSafeFieldName=function(n){return n.replace(/[^a-zA-Z]/g,"_")},f.prototype.configureTableStructure=function(t,i,u){var h=this,p,e,w,s;try{i.empty();u&&(p=u,this.$timeout(function(){p.$destroy()}),u=null);e=t.$new();this.columnDefsItemsWatcherDeregistration&&(this.columnDefsItemsWatcherDeregistration(),this.columnDefsItemsWatcherDeregistration=null);this.columnDefsFieldsWatcherDeregistration&&(this.columnDefsFieldsWatcherDeregistration(),this.columnDefsFieldsWatcherDeregistration=null);this.columnDefsFieldsWatcherDeregistration=e.$watch("gridOptions.fields",function(n,r){angular.equals(n,r)||h.configureTableStructure(t,i,e)},!0);var c=this.templatedHeader.extractPartialColumnDefinitions(),a=this.templatedBody.extractPartialColumnDefinitions(),v=this.templatedFooter.extractPartialColumnDefinitions(),f=[],d=this.gridOptions.fields;if(d)angular.forEach(this.gridOptions.fields,function(n){n&&f.push({isStandardColumn:!0,fieldName:n})}),f=r(f,c,!1,!0),f=r(f,a,!1,!0);else if(c.length>0)f=r(c,a,!0,!0);else{if(!this.gridOptions.items||this.gridOptions.items.length==0){this.columnDefsItemsWatcherDeregistration=e.$watch("gridOptions.items.length",function(n){n&&h.configureTableStructure(t,i,e)});return}for(w in this.gridOptions.items[0])f.push({isStandardColumn:!0,fieldName:w});f=r(f,a,!0,!0)}v.length==0&&v.push({isStandardColumn:!0});angular.forEach(f,function(n){var t,i;n.fieldName&&(t=n.fieldName,n.displayFieldName=h.getSafeFieldName(t),i=t[0]==="["?t:t.replace(/^([^\.]+)/g,'["$1"]'),n.fieldExtractionExpression=i)});this.gridOptions.gridColumnDefs=f;var b=this.templatedHeader.configureSection(i,f),g=this.templatedFooter.configureSection(i,v),y=this.templatedBody.configureSection(i,f),o=this.templatedBody.getTemplatedRowElement(y),nt=this.templatedHeader.getTemplatedRowElement(b);y.attr(l,"");o.attr("ng-click","toggleItemSelection(gridItem, $event)");o.attr("ng-repeat","gridDisplayItem in filteredItems");o.attr("ng-init","gridItem=gridDisplayItem.$$_gridItem;"+o.attr("ng-init"));s=o.attr("ng-class");s=(s||"").replace(/^(\s*\{?)(.*?)(\}?\s*)$/,"{'"+n.rowSelectedCssClass+"':gridOptions.selectedItems.indexOf(gridItem) >= 0, $2}");o.attr("ng-class",s);this.$compile(b)(e);this.$compile(g)(e);this.$compile(y)(e)}catch(k){n.debugMode&&this.log("Fixing table structure failed with error "+k);throw k;}},f.prototype.computeFormattedItems=function(t){var e=t.gridOptions.items||[],i,c,r,o,u,a,h,v,s,f;n.debugMode&&this.log("formatting items of length "+e.length);try{for(i=t.formattedItems=t.formattedItems||[],c=t.gridOptions.gridColumnDefs,r=0;r<e.length;r++){for(o=e[r],a={gridItem:o};i.length>e.length&&(u=i[r]).$$_gridItem!==o;)i.splice(r,1);for(r<i.length?(u=i[r],u.$$_gridItem!==o&&(u={$$_gridItem:o},i[r]=u)):(u={$$_gridItem:o},i.push(u)),h=0;h<c.length;h++)try{s=c[h];s.displayFieldName&&s.fieldExtractionExpression&&(f=s.displayFormat,f&&f[0]!=="."&&f[0]!=="|"&&f[0]!=="["&&(f=" | "+f),u[s.displayFieldName]=t.$eval("gridItem"+s.fieldExtractionExpression+(f||""),a))}catch(l){n.debugMode&&this.log("Field evaluation failed for <"+(v||"unknown")+"> with error "+l)}}i.length>e.length&&i.splice(e.length,i.length-e.length);this.scheduleDataFiltering()}catch(l){n.debugMode&&this.log("Failed to format items "+l);throw l;}},f.prototype.extractDataItems=function(n){var i,t;if(n)for(i=new Array(n.length),t=0;t<n.length;t++)i[t]=n[t].$$_gridItem;else i=[];return i},f.prototype.computeFilteredItems=function(t){try{if(this.isInServerSideMode)t.filteredItems=t.formattedItems;else{if(t.filterByDisplayFields={},t.gridOptions.filterByFields)for(var i in t.gridOptions.filterByFields)t.filterByDisplayFields[this.getSafeFieldName(i)]=t.gridOptions.filterByFields[i];n.debugMode&&this.log("filtering items of length "+(t.formattedItems?t.formattedItems.length:0));t.filteredItems=t.$eval("formattedItems | filter:gridOptions.filterBy | filter:filterByDisplayFields | "+n.sortFilter+":gridOptions");t.gridOptions.filteredItems&&(t.gridOptions.filteredItems=this.extractDataItems(t.filteredItems));t.filteredItems=t.$eval("filteredItems | "+n.dataPagingFilter+":gridOptions")}t.gridOptions.filteredItemsPage&&(t.gridOptions.filteredItemsPage=this.extractDataItems(t.filteredItems))}catch(r){n.debugMode&&this.log("Failed to filter items "+r);throw r;}},f.prototype.linkAttrs=function(n,t){var r=function(n,i){if(typeof i!="undefined"){switch(i){case"true":i=!0;break;case"false":i=!1}t[n]=i}};for(var i in t)r(i,n[i]),function(t){n.$observe(t,function(n){return r(t,n)})}(i)},f.prototype.log=function(n){console.log(t+"("+(new Date).getTime()+"): "+n)},f}();angular.module("trNgGrid",[]).directive(t,[function(){return{restrict:"A",scope:{items:"=",selectedItems:"=?",filteredItems:"=?",filteredItemsPage:"=?",filterBy:"=?",filterByFields:"=?",orderBy:"=?",orderByReverse:"=?",pageItems:"=?",currentPage:"=?",totalItems:"=?",enableFiltering:"=?",enableSorting:"=?",selectionMode:"@",locale:"@",onDataRequired:"&",onDataRequiredDelay:"=?",fields:"=?"},controller:["$compile","$parse","$timeout","$templateCache",ot],compile:function(t){return angular.forEach(t.children(),function(n){n=angular.element(n);n.attr("ng-non-bindable","")}),{pre:function(n,t,i,r){r.discoverTemplates(t)},post:function(t,i,r,u){i.addClass(n.tableCssClass);var f=t.$parent.$new();u.setupGrid(f,t,!!r.onDataRequired);u.configureTableStructure(f,i);t.$on("$destroy",function(){f.$destroy();n.debugMode&&u.log("grid scope destroyed")})}}}}}]).directive(y,[function(){var i=function(n){if(n.columnOptions.displayName)n.columnTitle=n.columnOptions.displayName;else if(n.columnOptions.fieldName){var i=n.columnOptions.fieldName.replace(/^([^\a-zA-Z]*)([\a-zA-Z]*)(.*)/g,"$2"),t=i.split(/(?=[A-Z])/);t.length&&t[0].length&&(t[0]=t[0][0].toLocaleUpperCase()+t[0].substr(1));n.columnTitle=t.join(" ")}else n.columnTitle=""};return{restrict:"A",require:"^"+t,scope:!0,compile:function(t,r){var u=r.isCustomized=="true";return h(t,r,u,rt),{pre:function(t,r,f,e){var h=parseInt(f[y]),o=angular.extend(t.gridOptions.gridColumnDefs[h],n.defaultColumnOptionsTemplate,n.defaultColumnOptions),s;e.linkAttrs(f,o);t.columnOptions=o;t.isCustomized=u;t.toggleSorting=function(n){e.toggleSorting(n)};t.$watch("columnOptions.displayName",function(){i(t)});s=!1;t.$watch("gridOptions.filterByFields['"+o.fieldName+"']",function(n){o.filter!==n&&(o.filter=n);s||(t.$watch("columnOptions.filter",function(n){t.gridOptions.filterByFields[o.fieldName]!==n&&(n?t.gridOptions.filterByFields[o.fieldName]=n:delete t.gridOptions.filterByFields[o.fieldName],t.gridOptions.filterByFields=angular.extend({},t.gridOptions.filterByFields))}),s=!0)})}}}}}]).directive(p,[function(){return{restrict:"A",templateUrl:n.cellHeaderTemplateId,transclude:!0,replace:!0}}]).directive("trNgGridBody",[function(){return{restrict:"A",require:"^"+t,scope:!0,compile:function(){return{pre:function(n,t,i,r){n.toggleItemSelection=function(t,i){r.toggleItemSelection(n.filteredItems,t,i)}}}}}}]).directive(w,[function(){return{restrict:"A",require:"^"+t,scope:!0,compile:function(n,t){var i=t.isCustomized=="true";return h(n,t,i,ft),{pre:function(n,t,r){n.columnOptions=n.gridOptions.gridColumnDefs[parseInt(r[w])];n.gridItem=n.gridDisplayItem.$$_gridItem;n.isCustomized=i}}}}}]).directive(b,[function(){return{restrict:"A",templateUrl:n.cellBodyTemplateId,transclude:!0,replace:!0}}]).directive("trNgGridFooterCell",[function(){return{restrict:"A",require:"^"+t,scope:!0,compile:function(n,t){var i=t.isCustomized=="true";return h(n,t,i,tt),{pre:function(n,t){n.isCustomized=i;t.attr("colspan",n.gridOptions.gridColumnDefs.length)}}}}}]).directive(v,[function(){return{restrict:"A",templateUrl:n.cellFooterTemplateId,transclude:!0,replace:!0}}]).directive(o,[function(){return{restrict:"A",replace:!0,templateUrl:n.columnSortTemplateId}}]).directive(s,[function(){return{restrict:"A",replace:!0,templateUrl:n.columnFilterTemplateId}}]).directive(f,[function(){return{restrict:"A",scope:!1,templateUrl:n.footerGlobalFilterTemplateId}}]).directive(e,[function(){var i=function(t,i){var e,r;if(t.totalItemsCount=typeof t.gridOptions.totalItems!="undefined"&&t.gridOptions.totalItems!=null?t.gridOptions.totalItems:t.gridOptions.items?t.gridOptions.items.length:0,t.isPaged=!!t.gridOptions.pageItems&&t.gridOptions.pageItems<t.totalItemsCount,t.extendedControlsActive=!1,t.lastPageIndex=!t.totalItemsCount||!t.isPaged?0:Math.floor(t.totalItemsCount/t.gridOptions.pageItems)+(t.totalItemsCount%t.gridOptions.pageItems?0:-1),t.gridOptions.currentPage>t.lastPageIndex&&(n.debugMode&&i.log("The current page index falls outside of the range of items. Either the attached parameter has a wrong value or the total items count is not properly set in server side mode."),t.gridOptions.currentPage=t.lastPageIndex),t.startItemIndex=t.isPaged?t.gridOptions.pageItems*t.gridOptions.currentPage:0,t.endItemIndex=t.isPaged?t.startItemIndex+t.gridOptions.pageItems-1:t.totalItemsCount-1,t.endItemIndex>=t.totalItemsCount&&(t.endItemIndex=t.totalItemsCount-1),t.endItemIndex<t.startItemIndex&&(t.endItemIndex=t.startItemIndex),t.pageCanGoBack=t.isPaged&&t.gridOptions.currentPage>0,t.pageCanGoForward=t.isPaged&&t.gridOptions.currentPage<t.lastPageIndex,t.pageIndexes=t.pageIndexes||[],t.pageIndexes.splice(0),t.isPaged)if(t.lastPageIndex+1>n.defaultPagerMinifiedPageCountThreshold){t.extendedControlsActive=!0;var o=Math.floor(n.defaultPagerMinifiedPageCountThreshold/2),u=t.gridOptions.currentPage-o,f=t.gridOptions.currentPage+o;for(u<0?(f+=-u,u=0):f>t.lastPageIndex&&(u-=f-t.lastPageIndex,f=t.lastPageIndex),u>0&&(t.pageIndexes.push(null),u++),e=!1,f<t.lastPageIndex&&(e=!0,f--),r=u;r<=f;r++)t.pageIndexes.push(r);e&&t.pageIndexes.push(null)}else for(t.extendedControlsActive=!1,r=0;r<=t.lastPageIndex;r++)t.pageIndexes.push(r);t.pageSelectionActive=t.pageIndexes.length>1;t.navigateToPage=function(n){t.gridOptions.currentPage=n;t.speedUpAsyncDataRetrieval()};t.switchPageSelection=function(n,i){t.pageSelectionActive=i;n&&(n.preventDefault(),n.stopPropagation())}};return{restrict:"A",scope:!0,require:"^"+t,templateUrl:n.footerPagerTemplateId,replace:!0,compile:function(){return{pre:function(n,t,r,u){i(n,u)},post:function(n,t,r,u){n.$watchCollection("[gridOptions.currentPage, gridOptions.items.length, gridOptions.totalItems, gridOptions.pageItems]",function(){i(n,u)})}}}}}]).filter(n.sortFilter,["$filter","$parse",function(n,t){return function(i,r){var u,f;if(!r.orderBy||!r.gridColumnDefs)return i;for(u=null,f=0;f<r.gridColumnDefs.length&&(u=r.gridColumnDefs[f]).fieldName!==r.orderBy;u=null,f++);return u?n("orderBy")(i,function(n){var i=undefined;if(u.fieldExtractionExpression)try{i=t("item.$$_gridItem"+u.fieldExtractionExpression)({item:n})}catch(r){}if(i===undefined)try{i=t('item["'+u.displayFieldName+'"]')({item:n})}catch(r){}return i},r.orderByReverse):i}}]).filter(n.dataPagingFilter,function(){return function(n,t){var i,r;return(n&&(t.totalItems=n.length),!t.pageItems||!n||n.length==0)?n:(t.currentPage||(t.currentPage=0),i=t.currentPage*t.pageItems,i>=n.length&&(t.currentPage=0,i=0),r=t.currentPage*t.pageItems+t.pageItems,n.slice(i,r))}}).filter(n.translateFilter,["$filter","$injector",function(t,i){return function(r,u){var f=null,e,s,o,c,h;if(!u)throw"Language identifier is not set";if(r instanceof Date)return(e=t(n.translateFilter)(n.translationDateFormat,u),e&&e!==n.translationDateFormat)?t("date")(r,e):r;for(s=u.split(/[-_]/),o=s.length;o>0&&!f;o--)c=s.slice(0,o).join("-"),h=n.translations[c],h&&(f=h[r]);if(!f&&i.has("translateFilter"))try{f=t("translate")(r)}catch(l){}return f||(f=r),f}}]).run(function(){n.tableCssClass="tr-ng-grid table table-bordered table-hover";n.cellCssClass="tr-ng-cell";n.headerCellCssClass="tr-ng-column-header "+n.cellCssClass;n.bodyCellCssClass=n.cellCssClass;n.columnTitleCssClass="tr-ng-title";n.columnSortCssClass="tr-ng-sort";n.columnFilterCssClass="tr-ng-column-filter";n.columnFilterInputWrapperCssClass="";n.columnSortActiveCssClass="tr-ng-sort-active text-info";n.columnSortInactiveCssClass="tr-ng-sort-inactive text-muted glyphicon glyphicon-chevron-down";n.columnSortReverseOrderCssClass="tr-ng-sort-order-reverse glyphicon glyphicon-chevron-down";n.columnSortNormalOrderCssClass="tr-ng-sort-order-normal glyphicon glyphicon-chevron-up";n.rowSelectedCssClass="active";n.footerCssClass="tr-ng-grid-footer form-inline"}).run(function(){n.defaultColumnOptions.displayAlign="left";n.defaultPagerMinifiedPageCountThreshold=3})})(TrNgGrid||(TrNgGrid={}));