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 | a7e64fd | 2016-04-14 14:59:09 -0700 | [diff] [blame^] | 27 | <th ng-if="vm.config.actions">Actions</th> |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 28 | </tr> |
| 29 | </thead> |
| 30 | <tbody> |
| 31 | <tr ng-repeat="item in vm.data"> |
Matteo Scandolo | dcc6524 | 2016-04-14 12:06:50 -0700 | [diff] [blame] | 32 | <td ng-repeat="col in vm.columns">{{item[col.prop]}}</td> |
Matteo Scandolo | a7e64fd | 2016-04-14 14:59:09 -0700 | [diff] [blame^] | 33 | <td ng-if="vm.config.actions"> |
| 34 | <i |
| 35 | ng-repeat="action in vm.config.actions" |
| 36 | ng-click="action.cb(item)" |
| 37 | class="glyphicon glyphicon-{{action.icon}}" |
| 38 | style="color: {{action.color}};"></i> |
| 39 | </td> |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 40 | </tr> |
| 41 | </tbody> |
| 42 | </table> |
| 43 | `, |
Matteo Scandolo | 6635143 | 2016-03-24 15:29:52 -0700 | [diff] [blame] | 44 | bindToController: true, |
| 45 | controllerAs: 'vm', |
| 46 | controller: function(){ |
Matteo Scandolo | dcc6524 | 2016-04-14 12:06:50 -0700 | [diff] [blame] | 47 | |
| 48 | if(!this.config){ |
| 49 | throw new Error('[xosTable] Please provide a configuration via the "config" attribute'); |
| 50 | } |
| 51 | |
| 52 | if(!this.config.columns){ |
| 53 | throw new Error('[xosTable] Please provide a columns list in the configuration'); |
| 54 | } |
| 55 | |
| 56 | this.columns = this.config.columns; |
| 57 | this.classes = this.config.classes || 'table table-striped table-bordered'; |
| 58 | |
Matteo Scandolo | a7e64fd | 2016-04-14 14:59:09 -0700 | [diff] [blame^] | 59 | if(this.config.actions){ |
| 60 | |
| 61 | } |
| 62 | |
Matteo Scandolo | 6635143 | 2016-03-24 15:29:52 -0700 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | }) |
| 66 | })(); |