blob: f1b6682650976671ce6852462a39b51d22d48d94 [file] [log] [blame]
Matteo Scandolo91fe03d2016-03-24 15:29:52 -07001/**
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 Scandolob7a86dc2016-04-14 11:46:30 -070012
Matteo Scandolo91fe03d2016-03-24 15:29:52 -070013 angular.module('xos.uiComponents.table', [])
14 .directive('xosTable', function(){
15 return {
16 restrict: 'E',
17 scope: {
18 data: '=',
Matteo Scandolo18adcb52016-04-14 12:06:50 -070019 config: '='
Matteo Scandolo91fe03d2016-03-24 15:29:52 -070020 },
Matteo Scandolob7a86dc2016-04-14 11:46:30 -070021 template: `
Matteo Scandolo18adcb52016-04-14 12:06:50 -070022 <!-- <pre>{{vm.data | json}}</pre> -->
23 <table ng-class="vm.classes" ng-show="vm.data.length > 0">
Matteo Scandolob7a86dc2016-04-14 11:46:30 -070024 <thead>
25 <tr>
Matteo Scandolo18adcb52016-04-14 12:06:50 -070026 <th ng-repeat="col in vm.columns">{{col.label}}</th>
Matteo Scandolo9e6c6fc2016-04-14 14:59:09 -070027 <th ng-if="vm.config.actions">Actions</th>
Matteo Scandolob7a86dc2016-04-14 11:46:30 -070028 </tr>
29 </thead>
30 <tbody>
31 <tr ng-repeat="item in vm.data">
Matteo Scandolo18adcb52016-04-14 12:06:50 -070032 <td ng-repeat="col in vm.columns">{{item[col.prop]}}</td>
Matteo Scandolo9e6c6fc2016-04-14 14:59:09 -070033 <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 Scandolob7a86dc2016-04-14 11:46:30 -070040 </tr>
41 </tbody>
42 </table>
43 `,
Matteo Scandolo91fe03d2016-03-24 15:29:52 -070044 bindToController: true,
45 controllerAs: 'vm',
46 controller: function(){
Matteo Scandolo18adcb52016-04-14 12:06:50 -070047
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 Scandolo9e6c6fc2016-04-14 14:59:09 -070059 if(this.config.actions){
60
61 }
62
Matteo Scandolo91fe03d2016-03-24 15:29:52 -070063 }
64 }
65 })
66})();