diff --git a/bower.json b/bower.json index dd38061..d7e61fd 100644 --- a/bower.json +++ b/bower.json @@ -22,7 +22,8 @@ "angular-translate": "~2.7.2", "angularjs-dropdown-multiselect": "mindsmash/angularjs-dropdown-multiselect#b86006bed471db66dd19e46a6e4129f2c3a3bd19", "checklist-model": "~0.6.0", - "mindsmash-angular-hotkeys": "~1.0.0" + "mindsmash-angular-hotkeys": "~1.0.0", + "angular-media-queries": "~0.4.1" }, "ignore": [ "**/.*", diff --git a/dist/mindsmash-angular-uxtable.js b/dist/mindsmash-angular-uxtable.js index 581335e..c7ee2ad 100644 --- a/dist/mindsmash-angular-uxtable.js +++ b/dist/mindsmash-angular-uxtable.js @@ -78,16 +78,14 @@ self.load = function() { var params = config.requestConverter(config, self); config.source(params).then(function(response) { - $timeout(function() { - var converted = config.responseConverter(response, self); - var facets = converted.meta.facets; - delete converted.meta.facets; - angular.extend(config, converted.meta); - self.setFacets(facets); - data = converted.data; - $rootScope.$emit('uxTable.dataChanged', data); - $rootScope.$emit('uxTable.configChanged', config); - }); + var converted = config.responseConverter(response, self); + var facets = converted.meta.facets; + delete converted.meta.facets; + angular.extend(config, converted.meta); + self.setFacets(facets); + data = converted.data; + $rootScope.$emit('uxTable.dataChanged', data); + $rootScope.$emit('uxTable.configChanged', config); }); }; @@ -347,7 +345,10 @@ keyboard: true, selection: true, selectionKey: 'id', - rowAction: angular.noop // function(row, idx, api, $event)... + rowAction: angular.noop, // function(row, idx, api, $event)... + mobileViewSize: undefined, // media size to display mobile view (xs,sm,...), multiple values as comma-separated list + mobileViewTemplate: undefined, // replacement template for mobile view (instead of table), + scope: {} // additions/overrides to the scope backing the table (additional action methods etc.) }, pagination: { ngClass: 'ux-table-pagination', @@ -454,7 +455,7 @@ }]; }) - .directive('uxTableView', ['$rootScope', 'hotkeys', 'ElementClickListener', function($rootScope, hotkeys, ElementClickListener) { + .directive('uxTableView', ['$rootScope', 'hotkeys', 'ElementClickListener', 'screenSize', function($rootScope, hotkeys, ElementClickListener, screenSize) { return { replace: true, restrict: 'AE', @@ -545,6 +546,16 @@ // initialize updateConf(null, api.getConfig()); updateData(null, api.getData()); + + var viewConf = $scope.conf.view; + if (!!viewConf.mobileViewTemplate && !!viewConf.mobileViewSize) { + $scope.mobile = screenSize.is(viewConf.mobileViewSize); + screenSize.on(viewConf.mobileViewSize, function (mobile) { + $scope.mobile = mobile; + }); + } + + angular.extend($scope, api.getConfig().view.scope); } }; }]) @@ -897,7 +908,7 @@ // ===== INTERNAL - .directive('uxTableCell', ['$compile', function($compile) { + .directive('uxTableCell', ['$compile', '$templateRequest', function($compile, $templateRequest) { return { scope: false, require: '^uxTableView', @@ -905,6 +916,12 @@ var template = $scope.column.template; if (angular.isString(template)) { elem.html($compile(template)($scope)); + } else { + if ($scope.column.templateUrl) { + $templateRequest($scope.column.templateUrl).then(function(result) { + elem.html($compile(result)($scope)); + }); + } } } }; diff --git a/dist/mindsmash-angular-uxtable.min.js b/dist/mindsmash-angular-uxtable.min.js index fb2d5de..5711487 100644 --- a/dist/mindsmash-angular-uxtable.min.js +++ b/dist/mindsmash-angular-uxtable.min.js @@ -1,7 +1,7 @@ /*! - * mindsmash-angular-uxtable v0.3.0 + * mindsmash-angular-uxtable v0.3.1 * https://github.com/mindsmash/mindsmash-angular-uxtable - * Copyright (c) 2015 mindsmash GmbH + * Copyright (c) 2016 mindsmash GmbH * License: MIT */ -!function(a){"use strict";function b(b,d,e){this.get=function(f,g){a.isUndefined(g)&&(g={});var h=a.merge({},e,g);return new c(b,d,f,h)}}function c(b,c,d,e){var f=this;f.getConfig=function(){return j},f.getData=function(){return n};for(var g="uxTable."+d,h=function(){var a=sessionStorage[g];return a?JSON.parse(sessionStorage[g]):{}},i=function(){sessionStorage[g]=JSON.stringify({page:j.page,pageSize:j.pageSize,orderBy:j.orderBy,columns:j.columns,filters:j.filters})},j=a.extend(a.extend({source:a.noop,columns:[],selection:[],active:null,filters:{}},e),h()),k=function(a){if(!a||0===a.indexOf(e.i18n.prefix))return a;var b=a.replace(/ /g,"");return e.i18n.prefix+b.toLowerCase()},l=0;l=0&&a!==j.page&&(j.page=a,d=!0),null!==c&&c>0&&c!==j.pageSize&&(j.pageSize=c,d=!0),d&&(b.$emit("uxTable.configChanged",j),i(),f.load())},f.getVisibility=function(a){for(var b=0;ba&&j.page>0?(f.prevPage(),j.active=j.pageSize-1):a>=j.pageSize&&j.page=0&&ad&&c!==!1?j.selection.push(b):d>=0&&c!==!0&&j.selection.splice(d,1)},f.setPageSelection=function(a){for(var b=0;b{{ conf.pageSize }} ',closeOnBlur:!0,closeOnSelect:!1,closeOnDeselect:!1,options:[10,25,50,100]},toggle:{ngClass:"ux-table-toggle",template:' ',closeOnBlur:!0,closeOnSelect:!1,closeOnDeselect:!1},counter:{ngClass:"ux-table-counter",template:''},selectionCounter:{ngClass:"ux-table-selection-counter",template:' (clear)'},facets:{ngClass:"ux-table-facets",maxFacetCount:5,minFacetSize:3,options:{}},requestConverter:function(b,c){for(var d=b.orderBy,e={_page:b.page,_pageSize:b.pageSize,_orderBy:d&&d.key?d.key+(d.asc?",asc":",desc"):null},f={},g=0;g0&&(d.meta.orderBy={key:b.sort[0].property,asc:b.sort[0].ascending}),d}};this.setConfig=function(a){return c=a,this},this.$get=["$rootScope","$timeout",function(a,d){return new b(a,d,c)}]}).directive("uxTableView",["$rootScope","hotkeys","ElementClickListener",function(a,b,c){return{replace:!0,restrict:"AE",templateUrl:"_uxTableView.html",scope:{api:"&"},controller:["$scope",function(a){this.api=a.api()}],link:function(d,e,f,g){var h=g.api;d.conf={},d.sortBy=h.setSorting,d.rowClick=function(a,b,c){h.toggleActive(b)};var i=function(a,b){d.conf=b},j=function(a,b){d.data=b};b.bindTo(d).add({combo:"shift+left",callback:h.firstPage}).add({combo:"left",callback:h.prevPage}).add({combo:"right",callback:h.nextPage}).add({combo:"shift+right",callback:h.lastPage}).add({combo:"space",callback:function(a){null!==d.conf.active&&(a.preventDefault(),h.toggleSelection(d.data[d.conf.active][d.conf.view.selectionKey]))}}).add({combo:"return",callback:function(a){if(null!==d.conf.active){a.preventDefault();var b=d.conf.active,c=d.data[b];d.conf.view.rowAction(c,b,h,a),d.conf.active=null}}}).add({combo:"up",callback:function(a){null!==d.conf.active&&(a.preventDefault(),h.prevActive())}}).add({combo:"down",callback:function(a){null!==d.conf.active&&(a.preventDefault(),h.nextActive())}}).add({combo:"esc",callback:function(a){null!==d.conf.active&&(a.preventDefault(),h.clearActive())}}),a.$on("uxTable.configChanged",i),a.$on("uxTable.dataChanged",j),c.register("uxTable.view",e,h.clearActive,!0),i(null,h.getConfig()),j(null,h.getData())}}}]).directive("uxTablePagination",["$rootScope","$timeout",function(a,b){return{replace:!0,restrict:"AE",templateUrl:"_uxTablePagination.html",scope:{api:"&"},controller:["$scope",function(a){var b=a.api();a.conf={},a.current={page:0},a.hasPrevious=function(b){return b=b?b:a.current.page,b>1},a.hasNext=function(b){return b=b?b:a.current.page,b=1&&c<=a.conf.pageCount&&b.setPage(c-1)}}],link:function(b,c,d){var e=b.api(),f=function(a,c){for(var d=[],e=a;c>=e;e++)d.push({number:e,active:b.current.page==e});return d},g=function(a){var c=1,d=a.pageCount;return d-c>a.pagination.maxSize-1&&(c=b.current.page-Math.floor((a.pagination.maxSize-1)/2)>0?b.current.page-Math.floor((a.pagination.maxSize-1)/2):1,d=c+(a.pagination.maxSize-1),d>a.pageCount&&(d=a.pageCount,c=d-(a.pagination.maxSize-1))),f(c,d)},h=function(a,c){b.conf=c,b.current.page=c.page+1,b.pages=g(c)};a.$on("uxTable.configChanged",h),h(null,e.getConfig())}}}]).directive("uxTablePaginationSize",["$rootScope","$compile","$filter",function(b,c,d){return{replace:!0,restrict:"AE",templateUrl:"_uxTablePaginationSize.html",scope:{api:"&"},link:{pre:function(e,f,g){var h=e.api();e.conf={},e.confLocal={ngModel:null,options:[],extraSettings:{dynamicTitle:!1,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:1,showCheckAll:!1,showUncheckAll:!1,groupByTextProvider:a.noop,scrollable:!0,scrollableHeight:"auto",smartButtonMaxItems:1,smartButtonTextConverter:a.noop},events:{onItemSelect:function(a){h.setPagination(0,a.id)}}};var i=function(b,g){for(var h=[],i=0;i"+k+""),a.isString(k)&&e.confLocal.template!==k&&(f.find("button.dropdown-toggle").html(c(k)(e)),e.confLocal.template=k)};b.$on("uxTable.configChanged",i),i(null,h.getConfig())}}}}]).directive("uxTableToggle",["$rootScope","$compile",function(b,c){return{replace:!0,restrict:"AE",templateUrl:"_uxTableToggle.html",scope:{api:"&"},link:{pre:function(d,e,f){var g=d.api();d.conf={},d.confLocal={ngModel:[],options:[],extraSettings:{dynamicTitle:!1,displayProp:"name",idProp:"key",externalIdProp:"key",enableSearch:!1,selectionLimit:0,showCheckAll:!1,showUncheckAll:!1,groupByTextProvider:a.noop,scrollable:!0,scrollableHeight:"auto",smartButtonMaxItems:0,smartButtonTextConverter:a.noop},events:{onItemSelect:function(a){g.setVisibility(a.key,!0)},onItemDeselect:function(a){0===d.confLocal.ngModel.length?d.confLocal.ngModel.push(a):g.setVisibility(a.key,!1)}}};var h=function(b,f){for(var g=[],h=[],i=0;i"+k+""),a.isString(k)&&d.confLocal.template!==k&&(e.find("button.dropdown-toggle").html(c(k)(d)),d.confLocal.template=k)};b.$on("uxTable.configChanged",h),h(null,g.getConfig())}}}}]).directive("uxTableCounter",["$rootScope","$compile",function(b,c){return{replace:!0,restrict:"AE",templateUrl:"_uxTableCounter.html",scope:{api:"&"},link:function(d,e,f){var g=d.api();d.conf={},d.confLocal={};var h=function(b,f){d.conf=f;var g=f.counter.template;0!==g.indexOf("<")&&(g=""+g+""),a.isString(g)&&d.confLocal.template!==g&&(e.html(c(g)(d)),d.confLocal.template=g)};b.$on("uxTable.configChanged",h),h(null,g.getConfig())}}}]).directive("uxTableSelectionCounter",["$rootScope","$compile",function(b,c){return{replace:!0,restrict:"AE",templateUrl:"_uxTableSelectionCounter.html",scope:{api:"&"},link:function(d,e,f){var g=d.api();d.conf={},d.confLocal={};var h=function(b,f){d.conf=f;var g=f.selectionCounter.template;0!==g.indexOf("<")&&(g=""+g+""),a.isString(g)&&d.confLocal.template!==g&&(e.html(c(g)(d)),d.confLocal.template=g)};d.clear=function(){g.clearSelection()},b.$on("uxTable.configChanged",h),h(null,g.getConfig())}}}]).directive("uxTableFacets",["$rootScope",function(a){return{replace:!0,restrict:"AE",templateUrl:"_uxTableFacets.html",scope:{api:"&"},link:function(b,c,d){var e=b.api();b.conf={};var f=function(a,c){b.conf=c};b.getFilter=function(a){return b.conf.filters[a]},b.setFilter=function(a,b){e.setFilter(a,b)},b.toggleFacet=function(a,b){e.toggleFacet(a,b)},a.$on("uxTable.configChanged",f),f(null,e.getConfig())}}}]).directive("uxTableCell",["$compile",function(b){return{scope:!1,require:"^uxTableView",link:function(c,d,e){var f=c.column.template;a.isString(f)&&d.html(b(f)(c))}}}]).directive("uxTableSelection",["$timeout",function(a){return{replace:!0,require:"^uxTableView",scope:{data:"=",selection:"=",selectionKey:"="},link:function(b,c,d,e){var f=e.api,g=function(a,d){if(a!==d){for(var e=0,f=0;f'),a.put("_uxTableFacets.html",'
  • ×
  • {{ term.count }}{{ term.term }}
'),a.put("_uxTablePagination.html",''),a.put("_uxTablePaginationSize.html",'
'),a.put("_uxTableSelectionCounter.html",'
'),a.put("_uxTableToggle.html",'
'),a.put("_uxTableView.html",'
{{ row[column.key] }}
')}]); \ No newline at end of file +!function(a){"use strict";function b(b,d,e){this.get=function(f,g){a.isUndefined(g)&&(g={});var h=a.merge({},e,g);return new c(b,d,f,h)}}function c(b,c,d,e){var f=this;f.getConfig=function(){return j},f.getData=function(){return n};for(var g="uxTable."+d,h=function(){var a=sessionStorage[g];return a?JSON.parse(sessionStorage[g]):{}},i=function(){sessionStorage[g]=JSON.stringify({page:j.page,pageSize:j.pageSize,orderBy:j.orderBy,columns:j.columns,filters:j.filters})},j=a.extend(a.extend({source:a.noop,columns:[],selection:[],active:null,filters:{}},e),h()),k=function(a){if(!a||0===a.indexOf(e.i18n.prefix))return a;var b=a.replace(/ /g,"");return e.i18n.prefix+b.toLowerCase()},l=0;l=0&&a!==j.page&&(j.page=a,d=!0),null!==c&&c>0&&c!==j.pageSize&&(j.pageSize=c,d=!0),d&&(b.$emit("uxTable.configChanged",j),i(),f.load())},f.getVisibility=function(a){for(var b=0;ba&&j.page>0?(f.prevPage(),j.active=j.pageSize-1):a>=j.pageSize&&j.page=0&&ad&&c!==!1?j.selection.push(b):d>=0&&c!==!0&&j.selection.splice(d,1)},f.setPageSelection=function(a){for(var b=0;b{{ conf.pageSize }} ',closeOnBlur:!0,closeOnSelect:!1,closeOnDeselect:!1,options:[10,25,50,100]},toggle:{ngClass:"ux-table-toggle",template:' ',closeOnBlur:!0,closeOnSelect:!1,closeOnDeselect:!1},counter:{ngClass:"ux-table-counter",template:''},selectionCounter:{ngClass:"ux-table-selection-counter",template:' (clear)'},facets:{ngClass:"ux-table-facets",maxFacetCount:5,minFacetSize:3,options:{}},requestConverter:function(b,c){for(var d=b.orderBy,e={_page:b.page,_pageSize:b.pageSize,_orderBy:d&&d.key?d.key+(d.asc?",asc":",desc"):null},f={},g=0;g0&&(d.meta.orderBy={key:b.sort[0].property,asc:b.sort[0].ascending}),d}};this.setConfig=function(a){return c=a,this},this.$get=["$rootScope","$timeout",function(a,d){return new b(a,d,c)}]}).directive("uxTableView",["$rootScope","hotkeys","ElementClickListener","screenSize",function(b,c,d,e){return{replace:!0,restrict:"AE",templateUrl:"_uxTableView.html",scope:{api:"&"},controller:["$scope",function(a){this.api=a.api()}],link:function(f,g,h,i){var j=i.api;f.conf={},f.sortBy=j.setSorting,f.rowClick=function(a,b,c){j.toggleActive(b)};var k=function(a,b){f.conf=b},l=function(a,b){f.data=b};c.bindTo(f).add({combo:"shift+left",callback:j.firstPage}).add({combo:"left",callback:j.prevPage}).add({combo:"right",callback:j.nextPage}).add({combo:"shift+right",callback:j.lastPage}).add({combo:"space",callback:function(a){null!==f.conf.active&&(a.preventDefault(),j.toggleSelection(f.data[f.conf.active][f.conf.view.selectionKey]))}}).add({combo:"return",callback:function(a){if(null!==f.conf.active){a.preventDefault();var b=f.conf.active,c=f.data[b];f.conf.view.rowAction(c,b,j,a),f.conf.active=null}}}).add({combo:"up",callback:function(a){null!==f.conf.active&&(a.preventDefault(),j.prevActive())}}).add({combo:"down",callback:function(a){null!==f.conf.active&&(a.preventDefault(),j.nextActive())}}).add({combo:"esc",callback:function(a){null!==f.conf.active&&(a.preventDefault(),j.clearActive())}}),b.$on("uxTable.configChanged",k),b.$on("uxTable.dataChanged",l),d.register("uxTable.view",g,j.clearActive,!0),k(null,j.getConfig()),l(null,j.getData());var m=f.conf.view;m.mobileViewTemplate&&m.mobileViewSize&&(f.mobile=e.is(m.mobileViewSize),e.on(m.mobileViewSize,function(a){f.mobile=a})),a.extend(f,j.getConfig().view.scope)}}}]).directive("uxTablePagination",["$rootScope","$timeout",function(a,b){return{replace:!0,restrict:"AE",templateUrl:"_uxTablePagination.html",scope:{api:"&"},controller:["$scope",function(a){var b=a.api();a.conf={},a.current={page:0},a.hasPrevious=function(b){return b=b?b:a.current.page,b>1},a.hasNext=function(b){return b=b?b:a.current.page,b=1&&c<=a.conf.pageCount&&b.setPage(c-1)}}],link:function(b,c,d){var e=b.api(),f=function(a,c){for(var d=[],e=a;c>=e;e++)d.push({number:e,active:b.current.page==e});return d},g=function(a){var c=1,d=a.pageCount;return d-c>a.pagination.maxSize-1&&(c=b.current.page-Math.floor((a.pagination.maxSize-1)/2)>0?b.current.page-Math.floor((a.pagination.maxSize-1)/2):1,d=c+(a.pagination.maxSize-1),d>a.pageCount&&(d=a.pageCount,c=d-(a.pagination.maxSize-1))),f(c,d)},h=function(a,c){b.conf=c,b.current.page=c.page+1,b.pages=g(c)};a.$on("uxTable.configChanged",h),h(null,e.getConfig())}}}]).directive("uxTablePaginationSize",["$rootScope","$compile","$filter",function(b,c,d){return{replace:!0,restrict:"AE",templateUrl:"_uxTablePaginationSize.html",scope:{api:"&"},link:{pre:function(e,f,g){var h=e.api();e.conf={},e.confLocal={ngModel:null,options:[],extraSettings:{dynamicTitle:!1,displayProp:"label",idProp:"id",externalIdProp:"id",enableSearch:!1,selectionLimit:1,showCheckAll:!1,showUncheckAll:!1,groupByTextProvider:a.noop,scrollable:!0,scrollableHeight:"auto",smartButtonMaxItems:1,smartButtonTextConverter:a.noop},events:{onItemSelect:function(a){h.setPagination(0,a.id)}}};var i=function(b,g){for(var h=[],i=0;i"+k+""),a.isString(k)&&e.confLocal.template!==k&&(f.find("button.dropdown-toggle").html(c(k)(e)),e.confLocal.template=k)};b.$on("uxTable.configChanged",i),i(null,h.getConfig())}}}}]).directive("uxTableToggle",["$rootScope","$compile",function(b,c){return{replace:!0,restrict:"AE",templateUrl:"_uxTableToggle.html",scope:{api:"&"},link:{pre:function(d,e,f){var g=d.api();d.conf={},d.confLocal={ngModel:[],options:[],extraSettings:{dynamicTitle:!1,displayProp:"name",idProp:"key",externalIdProp:"key",enableSearch:!1,selectionLimit:0,showCheckAll:!1,showUncheckAll:!1,groupByTextProvider:a.noop,scrollable:!0,scrollableHeight:"auto",smartButtonMaxItems:0,smartButtonTextConverter:a.noop},events:{onItemSelect:function(a){g.setVisibility(a.key,!0)},onItemDeselect:function(a){0===d.confLocal.ngModel.length?d.confLocal.ngModel.push(a):g.setVisibility(a.key,!1)}}};var h=function(b,f){for(var g=[],h=[],i=0;i"+k+""),a.isString(k)&&d.confLocal.template!==k&&(e.find("button.dropdown-toggle").html(c(k)(d)),d.confLocal.template=k)};b.$on("uxTable.configChanged",h),h(null,g.getConfig())}}}}]).directive("uxTableCounter",["$rootScope","$compile",function(b,c){return{replace:!0,restrict:"AE",templateUrl:"_uxTableCounter.html",scope:{api:"&"},link:function(d,e,f){var g=d.api();d.conf={},d.confLocal={};var h=function(b,f){d.conf=f;var g=f.counter.template;0!==g.indexOf("<")&&(g=""+g+""),a.isString(g)&&d.confLocal.template!==g&&(e.html(c(g)(d)),d.confLocal.template=g)};b.$on("uxTable.configChanged",h),h(null,g.getConfig())}}}]).directive("uxTableSelectionCounter",["$rootScope","$compile",function(b,c){return{replace:!0,restrict:"AE",templateUrl:"_uxTableSelectionCounter.html",scope:{api:"&"},link:function(d,e,f){var g=d.api();d.conf={},d.confLocal={};var h=function(b,f){d.conf=f;var g=f.selectionCounter.template;0!==g.indexOf("<")&&(g=""+g+""),a.isString(g)&&d.confLocal.template!==g&&(e.html(c(g)(d)),d.confLocal.template=g)};d.clear=function(){g.clearSelection()},b.$on("uxTable.configChanged",h),h(null,g.getConfig())}}}]).directive("uxTableFacets",["$rootScope",function(a){return{replace:!0,restrict:"AE",templateUrl:"_uxTableFacets.html",scope:{api:"&"},link:function(b,c,d){var e=b.api();b.conf={};var f=function(a,c){b.conf=c};b.getFilter=function(a){return b.conf.filters[a]},b.setFilter=function(a,b){e.setFilter(a,b)},b.toggleFacet=function(a,b){e.toggleFacet(a,b)},a.$on("uxTable.configChanged",f),f(null,e.getConfig())}}}]).directive("uxTableCell",["$compile","$templateRequest",function(b,c){return{scope:!1,require:"^uxTableView",link:function(d,e,f){var g=d.column.template;a.isString(g)?e.html(b(g)(d)):d.column.templateUrl&&c(d.column.templateUrl).then(function(a){e.html(b(a)(d))})}}}]).directive("uxTableSelection",["$timeout",function(a){return{replace:!0,require:"^uxTableView",scope:{data:"=",selection:"=",selectionKey:"="},link:function(b,c,d,e){var f=e.api,g=function(a,d){if(a!==d){for(var e=0,f=0;f'),a.put("_uxTableFacets.html",'
  • ×
  • {{ term.count }}{{ term.term }}
'),a.put("_uxTablePagination.html",''),a.put("_uxTablePaginationSize.html",'
'),a.put("_uxTableSelectionCounter.html",'
'),a.put("_uxTableToggle.html",'
'),a.put("_uxTableView.html",'
{{ row[column.key] }}
')}]); \ No newline at end of file diff --git a/dist/mindsmash-angular-uxtable.tpls.js b/dist/mindsmash-angular-uxtable.tpls.js index 5ef4674..f9aba33 100644 --- a/dist/mindsmash-angular-uxtable.tpls.js +++ b/dist/mindsmash-angular-uxtable.tpls.js @@ -32,7 +32,7 @@ angular.module('mindsmash.uxTable').run(['$templateCache', function($templateCac $templateCache.put('_uxTableView.html', - "
{{ row[column.key] }}
" + "
{{ row[column.key] }}
" ); }]); diff --git a/src/_uxTableView.html b/src/_uxTableView.html index 8cf702d..2b4a89d 100644 --- a/src/_uxTableView.html +++ b/src/_uxTableView.html @@ -1,22 +1,25 @@ - - - - - - - - - - - - - - - - -
-
{{ row[column.key] }}
\ No newline at end of file +
+ + + + + + + + + + + + + + + + +
+
{{ row[column.key] }}
+
+
\ No newline at end of file diff --git a/src/mindsmash-angular-uxtable.js b/src/mindsmash-angular-uxtable.js index 7a1cd17..21ab536 100644 --- a/src/mindsmash-angular-uxtable.js +++ b/src/mindsmash-angular-uxtable.js @@ -78,16 +78,14 @@ self.load = function() { var params = config.requestConverter(config, self); config.source(params).then(function(response) { - $timeout(function() { - var converted = config.responseConverter(response, self); - var facets = converted.meta.facets; - delete converted.meta.facets; - angular.extend(config, converted.meta); - self.setFacets(facets); - data = converted.data; - $rootScope.$emit('uxTable.dataChanged', data); - $rootScope.$emit('uxTable.configChanged', config); - }); + var converted = config.responseConverter(response, self); + var facets = converted.meta.facets; + delete converted.meta.facets; + angular.extend(config, converted.meta); + self.setFacets(facets); + data = converted.data; + $rootScope.$emit('uxTable.dataChanged', data); + $rootScope.$emit('uxTable.configChanged', config); }); }; @@ -347,7 +345,10 @@ keyboard: true, selection: true, selectionKey: 'id', - rowAction: angular.noop // function(row, idx, api, $event)... + rowAction: angular.noop, // function(row, idx, api, $event)... + mobileViewSize: undefined, // media size to display mobile view (xs,sm,...), multiple values as comma-separated list + mobileViewTemplate: undefined, // replacement template for mobile view (instead of table), + scope: {} // additions/overrides to the scope backing the table (additional action methods etc.) }, pagination: { ngClass: 'ux-table-pagination', @@ -454,7 +455,7 @@ }; }) - .directive('uxTableView', function($rootScope, hotkeys, ElementClickListener) { + .directive('uxTableView', function($rootScope, hotkeys, ElementClickListener, screenSize) { return { replace: true, restrict: 'AE', @@ -545,6 +546,16 @@ // initialize updateConf(null, api.getConfig()); updateData(null, api.getData()); + + var viewConf = $scope.conf.view; + if (!!viewConf.mobileViewTemplate && !!viewConf.mobileViewSize) { + $scope.mobile = screenSize.is(viewConf.mobileViewSize); + screenSize.on(viewConf.mobileViewSize, function (mobile) { + $scope.mobile = mobile; + }); + } + + angular.extend($scope, api.getConfig().view.scope); } }; }) @@ -897,7 +908,7 @@ // ===== INTERNAL - .directive('uxTableCell', function($compile) { + .directive('uxTableCell', function($compile, $templateRequest) { return { scope: false, require: '^uxTableView', @@ -905,6 +916,12 @@ var template = $scope.column.template; if (angular.isString(template)) { elem.html($compile(template)($scope)); + } else { + if ($scope.column.templateUrl) { + $templateRequest($scope.column.templateUrl).then(function(result) { + elem.html($compile(result)($scope)); + }); + } } } };