Matteo Scandolo | 6635143 | 2016-03-24 15:29:52 -0700 | [diff] [blame] | 1 | /** |
| 2 | * © OpenCORD |
| 3 | * |
| 4 | * Visit http://guide.xosproject.org/devguide/addview/ for more information |
| 5 | * |
| 6 | * Created by teone on 3/24/16. |
| 7 | */ |
| 8 | |
| 9 | (function () { |
| 10 | 'use strict'; |
| 11 | |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 12 | |
Matteo Scandolo | 6635143 | 2016-03-24 15:29:52 -0700 | [diff] [blame] | 13 | angular.module('xos.uiComponents.table', []) |
| 14 | .directive('xosTable', function(){ |
| 15 | return { |
| 16 | restrict: 'E', |
| 17 | scope: { |
| 18 | data: '=', |
Matteo Scandolo | dcc6524 | 2016-04-14 12:06:50 -0700 | [diff] [blame^] | 19 | config: '=' |
Matteo Scandolo | 6635143 | 2016-03-24 15:29:52 -0700 | [diff] [blame] | 20 | }, |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 21 | template: ` |
Matteo Scandolo | dcc6524 | 2016-04-14 12:06:50 -0700 | [diff] [blame^] | 22 | <!-- <pre>{{vm.data | json}}</pre> --> |
| 23 | <table ng-class="vm.classes" ng-show="vm.data.length > 0"> |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 24 | <thead> |
| 25 | <tr> |
Matteo Scandolo | dcc6524 | 2016-04-14 12:06:50 -0700 | [diff] [blame^] | 26 | <th ng-repeat="col in vm.columns">{{col.label}}</th> |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 27 | </tr> |
| 28 | </thead> |
| 29 | <tbody> |
| 30 | <tr ng-repeat="item in vm.data"> |
Matteo Scandolo | dcc6524 | 2016-04-14 12:06:50 -0700 | [diff] [blame^] | 31 | <td ng-repeat="col in vm.columns">{{item[col.prop]}}</td> |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 32 | </tr> |
| 33 | </tbody> |
| 34 | </table> |
| 35 | `, |
Matteo Scandolo | 6635143 | 2016-03-24 15:29:52 -0700 | [diff] [blame] | 36 | bindToController: true, |
| 37 | controllerAs: 'vm', |
| 38 | controller: function(){ |
Matteo Scandolo | dcc6524 | 2016-04-14 12:06:50 -0700 | [diff] [blame^] | 39 | |
| 40 | if(!this.config){ |
| 41 | throw new Error('[xosTable] Please provide a configuration via the "config" attribute'); |
| 42 | } |
| 43 | |
| 44 | if(!this.config.columns){ |
| 45 | throw new Error('[xosTable] Please provide a columns list in the configuration'); |
| 46 | } |
| 47 | |
| 48 | this.columns = this.config.columns; |
| 49 | this.classes = this.config.classes || 'table table-striped table-bordered'; |
| 50 | |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 51 | console.log('Bella dello zio, RELOAD'); |
Matteo Scandolo | 6635143 | 2016-03-24 15:29:52 -0700 | [diff] [blame] | 52 | } |
| 53 | } |
| 54 | }) |
| 55 | })(); |