forked from lorenzofox3/Smart-Table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmart-Table.min.js
1 lines (1 loc) · 13.2 KB
/
Smart-Table.min.js
1
function ColumnProvider(a,b){function c(a){return this instanceof c?(angular.extend(this,a),void 0):new c(a)}this.setDefaultOption=function(a){angular.extend(c.prototype,a)},a.headerTemplateUrl=b.defaultHeader,this.setDefaultOption(a),this.$get=function(){return c}}var smartTableColumnModule=angular.module("smartTable.column",["smartTable.templateUrlList"]).constant("DefaultColumnConfiguration",{isSortable:!0,isEditable:!1,type:"text",headerTemplateUrl:"",map:"",label:"",sortPredicate:"",formatFunction:"",formatParameter:"",filterPredicate:"",cellTemplateUrl:"",headerClass:"",cellClass:""});ColumnProvider.$inject=["DefaultColumnConfiguration","templateUrlList"],smartTableColumnModule.provider("Column",ColumnProvider),angular.module("smartTable.directives",["smartTable.templateUrlList","smartTable.templates"]).directive("smartTable",["templateUrlList","DefaultTableConfiguration",function(a,b){return{restrict:"E",scope:{columnCollection:"=columns",dataCollection:"=rows",config:"="},replace:"true",templateUrl:a.smartTable,controller:"TableCtrl",link:function(c,d,e,f){var g;c.$watch("config",function(d){var e=angular.extend({},b,d),g=void 0!==c.columns?c.columns.length:0;if(f.setGlobalConfig(e),"multiple"!==e.selectionMode||e.displaySelectionCheckbox!==!0)for(var h=g-1;h>=0;h--)c.columns[h].isSelectionColumn===!0&&f.removeColumn(h);else f.insertColumn({cellTemplateUrl:a.selectionCheckbox,headerTemplateUrl:a.selectAllCheckbox,isSelectionColumn:!0},0)},!0),c.$watch("columnCollection",function(){if(c.columnCollection)for(var a=0,b=c.columnCollection.length;b>a;a++)f.insertColumn(c.columnCollection[a]);else c.dataCollection&&c.dataCollection.length>0&&(g=c.dataCollection[0],angular.forEach(g,function(a,b){"$"!=b[0]&&f.insertColumn({label:b,map:b})}))},!0),c.$watch("dataCollection.length",function(a,b){a!==b&&f.sortBy()})}}}]).directive("smartTableDataRow",function(){return{require:"^smartTable",restrict:"C",link:function(a,b,c,d){b.bind("click",function(){a.$apply(function(){d.toggleSelection(a.dataRow)})})}}}).directive("smartTableHeaderCell",function(){return{restrict:"C",require:"^smartTable",link:function(a,b,c,d){b.bind("click",function(){a.$apply(function(){d.sortBy(a.column)})})}}}).directive("smartTableSelectAll",function(){return{restrict:"C",require:"^smartTable",scope:{},link:function(a,b,c,d){a.isChecked=!1,a.$watch("isChecked",function(a,b){a!==b&&d.toggleSelectionAll(a)})}}}).directive("stopEvent",function(){return{restrict:"A",link:function(a,b,c){b.bind(c.stopEvent,function(a){a.stopPropagation()})}}}).directive("smartTableGlobalSearch",["templateUrlList",function(a){return{restrict:"C",require:"^smartTable",scope:{columnSpan:"@"},templateUrl:a.smartTableGlobalSearch,replace:!1,link:function(a,b,c,d){a.searchValue="",a.$watch("searchValue",function(a){d.search(a)})}}}]).directive("smartTableDataCell",["$filter","$http","$templateCache","$compile",function(a,b,c,d){return{restrict:"C",link:function(e,f){function g(){i.isEditable?(f.html('<editable-cell row="dataRow" column="column" type="column.type" value="dataRow[column.map]"></editable-cell>'),d(f.contents())(e)):f.text(e.formatedValue)}var h,i=e.column,j=e.dataRow,k=a("format");e.formatedValue=k(j[i.map],i.formatFunction,i.formatParameter),e.$watch("column.cellTemplateUrl",function(a){a?b.get(a,{cache:c}).success(function(a){h=e.$new(),f.html(a),d(f.contents())(h)}).error(g):g()})}}}]).directive("inputType",["$parse",function(a){return{restrict:"A",priority:1,link:function(b,c,d){var e=a(d.type),f=e(b);d.$set("type",f)}}}]).directive("editableCell",["templateUrlList",function(a){return{restrict:"E",require:"^smartTable",templateUrl:a.editableCell,scope:{row:"=",column:"=",type:"="},replace:!0,link:function(a,b,c,d){var e=angular.element(b.children()[1]),f=angular.element(e.children()[0]);a.isEditMode=!1,a.submit=function(){a.myForm.$valid===!0&&(a.row[a.column.map]=a.value,d.sortBy()),a.isEditMode=!1},a.toggleEditMode=function(){a.value=a.row[a.column.map],a.isEditMode=!0},a.$watch("isEditMode",function(a){a&&(f[0].select(),f[0].focus())}),f.bind("blur",function(){a.$apply(function(){a.submit()})})}}}]),angular.module("smartTable.filters",[]).constant("DefaultFilters",["currency","date","json","lowercase","number","uppercase"]).filter("format",["$filter","DefaultFilters",function(a,b){return function(c,d,e){var f;return f=d&&angular.isFunction(d)?d:-1!==b.indexOf(d)?a(d):function(a){return a},f(c,e)}}]),angular.module("smartTable.table",["smartTable.column","smartTable.utilities","smartTable.directives","smartTable.filters","ui.bootstrap.pagination"]).constant("DefaultTableConfiguration",{selectionMode:"none",isGlobalSearchActivated:!1,displaySelectionCheckbox:!1,isPaginationEnabled:!0,itemsByPage:10,maxSize:5,sortAlgorithm:"",filterAlgorithm:""}).controller("TableCtrl",["$scope","Column","$filter","ArrayUtility","DefaultTableConfiguration",function(a,b,c,d,e){function f(b){return angular.isArray(b)?0===b.length||a.itemsByPage<1?1:Math.ceil(b.length/a.itemsByPage):1}function g(b,e){var f=(a.sortAlgorithm&&angular.isFunction(a.sortAlgorithm))===!0?a.sortAlgorithm:c("orderBy");return e?d.sort(b,f,e.sortPredicate,e.reverse):b}function h(a,b,c,d){var e;if(angular.isArray(a)&&("multiple"===b||"single"===b)&&c>=0&&c<a.length)if(e=a[c],"single"===b){for(var f=0,g=a.length;g>f;f++)a[f].isSelected=!1;e.isSelected=d}else"multiple"===b&&(e.isSelected=d)}a.columns=[],a.dataCollection=a.dataCollection||[],a.displayedCollection=[],a.numberOfPages=f(a.dataCollection),a.currentPage=1;var i,j={};this.setGlobalConfig=function(b){angular.extend(a,e,b)},this.changePage=function(b){angular.isNumber(b.page)&&(a.currentPage=b.page,a.displayedCollection=this.pipe(a.dataCollection))},this.sortBy=function(b){var c=a.columns.indexOf(b);-1!==c&&b.isSortable===!0&&(i&&i!==b&&(i.reverse="none"),b.sortPredicate=b.sortPredicate||b.map,b.reverse=b.reverse!==!0,i=b),a.displayedCollection=this.pipe(a.dataCollection)},this.search=function(b,c){if(c&&-1!==a.columns.indexOf(c))j.$="",c.filterPredicate=b;else{for(var d=0,e=a.columns.length;e>d;d++)a.columns[d].filterPredicate="";j.$=b}for(var d=0,e=a.columns.length;e>d;d++)j[a.columns[d].map]=a.columns[d].filterPredicate;a.displayedCollection=this.pipe(a.dataCollection)},this.pipe=function(b){var e,h=(a.filterAlgorithm&&angular.isFunction(a.filterAlgorithm))===!0?a.filterAlgorithm:c("filter");return e=g(d.filter(b,h,j),i),a.numberOfPages=f(e),a.isPaginationEnabled?d.fromTo(e,(a.currentPage-1)*a.itemsByPage,a.itemsByPage):e},this.insertColumn=function(c,e){var f=new b(c);d.insertAt(a.columns,e,f)},this.removeColumn=function(b){d.removeAt(a.columns,b)},this.moveColumn=function(b,c){d.moveAt(a.columns,b,c)},this.toggleSelection=function(b){var c=a.displayedCollection.indexOf(b);-1!==c&&h(a.displayedCollection,a.selectionMode,c,b.isSelected!==!0)},this.toggleSelectionAll=function(b){var c=0,d=a.displayedCollection.length;if("multiple"===a.selectionMode)for(;d>c;c++)h(a.displayedCollection,a.selectionMode,c,b===!0)},this.removeDataRow=function(b){var c=d.removeAt(a.displayedCollection,b);d.removeAt(a.dataCollection,a.dataCollection.indexOf(c))},this.moveDataRow=function(b,c){d.moveAt(a.displayedCollection,b,c)}}]),angular.module("smartTable.templates",["partials/defaultCell.html","partials/defaultHeader.html","partials/editableCell.html","partials/globalSearchCell.html","partials/pagination.html","partials/selectAllCheckbox.html","partials/selectionCheckbox.html","partials/smartTable.html"]),angular.module("partials/defaultCell.html",[]).run(["$templateCache",function(a){a.put("partials/defaultCell.html","<span>{{row[column.map] | format:column.formatFunction:column.formatParameter}}</span>")}]),angular.module("partials/defaultHeader.html",[]).run(["$templateCache",function(a){a.put("partials/defaultHeader.html","<span class=\"header-content\" ng-class=\"{'sort-ascent':column.reverse==true,'sort-descent':column.reverse==false}\">{{column.label}}</span>")}]),angular.module("partials/editableCell.html",[]).run(["$templateCache",function(a){a.put("partials/editableCell.html",'<div ng-dblclick="toggleEditMode($event)">\n <span ng-hide="isEditMode">{{row[column.map] | format:column.formatFunction:column.formatParameter}}</span>\n\n <form ng-submit="submit()" ng-show="isEditMode" name="myForm">\n <input name="myInput" ng-model="value" type="type" input-type/>\n </form>\n</div>')}]),angular.module("partials/globalSearchCell.html",[]).run(["$templateCache",function(a){a.put("partials/globalSearchCell.html",'<label>Search :</label>\n<input type="text" ng-model="searchValue"/>')}]),angular.module("partials/pagination.html",[]).run(["$templateCache",function(a){a.put("partials/pagination.html",'<div class="pagination">\n <ul>\n <li ng-repeat="page in pages" ng-class="{active: page.active, disabled: page.disabled}"><a\n ng-click="selectPage(page.number)">{{page.text}}</a></li>\n </ul>\n</div> ')}]),angular.module("partials/selectAllCheckbox.html",[]).run(["$templateCache",function(a){a.put("partials/selectAllCheckbox.html",'<input class="smart-table-select-all" type="checkbox" ng-model="isChecked"/>')}]),angular.module("partials/selectionCheckbox.html",[]).run(["$templateCache",function(a){a.put("partials/selectionCheckbox.html",'<input type="checkbox" ng-model="dataRow.isSelected" stop-event="click"/>')}]),angular.module("partials/smartTable.html",[]).run(["$templateCache",function(a){a.put("partials/smartTable.html",'<div class="smart-table-container">\n <table class="smart-table">\n <thead>\n <tr class="smart-table-global-search-row" ng-show="isGlobalSearchActivated">\n <td class="smart-table-global-search" column-span="{{columns.length}}" colspan="{{columnSpan}}">\n </td>\n </tr>\n <tr class="smart-table-header-row">\n <th ng-repeat="column in columns" ng-include="column.headerTemplateUrl"\n class="smart-table-header-cell {{column.headerClass}}" scope="col">\n </th>\n </tr>\n </thead>\n <tbody>\n <tr ng-repeat="dataRow in displayedCollection" ng-class="{selected:dataRow.isSelected}"\n class="smart-table-data-row">\n <td ng-repeat="column in columns" class="smart-table-data-cell {{column.cellClass}}"></td>\n </tr>\n </tbody>\n <tfoot ng-show="isPaginationEnabled">\n <tr class="smart-table-footer-row">\n <td colspan="{{columns.length}}">\n <pagination num-pages="numberOfPages" max-size="maxSize" current-page="currentPage"></pagination>\n </td>\n </tr>\n </tfoot>\n </table>\n</div>\n')}]),angular.module("smartTable.templateUrlList",[]).constant("templateUrlList",{smartTable:"partials/smartTable.html",smartTableGlobalSearch:"partials/globalSearchCell.html",editableCell:"partials/editableCell.html",selectionCheckbox:"partials/selectionCheckbox.html",selectAllCheckbox:"partials/selectAllCheckbox.html",defaultHeader:"partials/defaultHeader.html",pagination:"partials/pagination.html"}),angular.module("smartTable.utilities",[]).factory("ArrayUtility",function(){var a=function(a,b){return b>=0&&b<a.length?a.splice(b,1)[0]:void 0},b=function(a,b,c){b>=0&&b<a.length?a.splice(b,0,c):a.push(c)},c=function(a,b,c){var d;b>=0&&b<a.length&&c>=0&&c<a.length&&(d=a.splice(b,1)[0],a.splice(c,0,d))},d=function(a,b,c,d){return b&&angular.isFunction(b)?b(a,c,d===!0):a},e=function(a,b,c){return b&&angular.isFunction(b)?b(a,c):a},f=function(a,b,c){var d,e,f=[];if(!angular.isArray(a))return a;e=Math.max(b,0),e=Math.min(e,a.length-1>0?a.length-1:0),c=Math.max(0,c),d=Math.min(e+c,a.length);for(var g=e;d>g;g++)f.push(a[g]);return f};return{removeAt:a,insertAt:b,moveAt:c,sort:d,filter:e,fromTo:f}}),angular.module("ui.bootstrap.pagination",["smartTable.templateUrlList"]).constant("paginationConfig",{boundaryLinks:!1,directionLinks:!0,firstText:"First",previousText:"❰",nextText:"❱",lastText:"Last"}).directive("pagination",["paginationConfig","templateUrlList",function(a,b){return{restrict:"EA",require:"^smartTable",scope:{numPages:"=",currentPage:"=",maxSize:"="},templateUrl:b.pagination,replace:!0,link:function(b,c,d,e){function f(a,b,c,d){return{number:a,text:b,active:c,disabled:d}}var g=angular.isDefined(d.boundaryLinks)?b.$eval(d.boundaryLinks):a.boundaryLinks,h=angular.isDefined(d.directionLinks)?b.$eval(d.directionLinks):a.directionLinks,i=angular.isDefined(d.firstText)?d.firstText:a.firstText,j=angular.isDefined(d.previousText)?d.previousText:a.previousText,k=angular.isDefined(d.nextText)?d.nextText:a.nextText,l=angular.isDefined(d.lastText)?d.lastText:a.lastText;b.$watch("numPages + currentPage + maxSize",function(){b.pages=[];var a=1,c=b.numPages;b.maxSize&&b.maxSize<b.numPages&&(a=Math.max(b.currentPage-Math.floor(b.maxSize/2),1),c=a+b.maxSize-1,c>b.numPages&&(c=b.numPages,a=c-b.maxSize+1));for(var d=a;c>=d;d++){var e=f(d,d,b.isActive(d),!1);b.pages.push(e)}if(h){var m=f(b.currentPage-1,j,!1,b.noPrevious());b.pages.unshift(m);var n=f(b.currentPage+1,k,!1,b.noNext());b.pages.push(n)}if(g){var o=f(1,i,!1,b.noPrevious());b.pages.unshift(o);var p=f(b.numPages,l,!1,b.noNext());b.pages.push(p)}b.currentPage>b.numPages&&b.selectPage(b.numPages)}),b.noPrevious=function(){return 1===b.currentPage},b.noNext=function(){return b.currentPage===b.numPages},b.isActive=function(a){return b.currentPage===a},b.selectPage=function(a){!b.isActive(a)&&a>0&&a<=b.numPages&&(b.currentPage=a,e.changePage({page:a}))}}}}]);