blob: 6f4d045c66819b17da3d0a0ed336c46c568eee1c [file] [log] [blame]
Matteo Scandolo8cc22e42016-04-12 09:00:04 -07001'use strict';
2
3angular.module('xos.sampleView', [
4 'ngResource',
5 'ngCookies',
Matteo Scandolo8cc22e42016-04-12 09:00:04 -07006 'ui.router',
7 'xos.helpers'
8])
9.config(($stateProvider) => {
10 $stateProvider
11 .state('user-list', {
12 url: '/',
13 template: '<users-list></users-list>'
14 });
15})
16.config(function($httpProvider){
17 $httpProvider.interceptors.push('NoHyperlinks');
18})
19.directive('usersList', function(){
20 return {
21 restrict: 'E',
22 scope: {},
23 bindToController: true,
24 controllerAs: 'vm',
25 templateUrl: 'templates/users-list.tpl.html',
Matteo Scandolobd2e5cd2016-04-12 11:59:29 -070026 controller: function(Users){
Matteo Scandolo18adcb52016-04-14 12:06:50 -070027
28 this.tableConfig = {
29 columns: [
30 {
31 label: 'E-Mail',
32 prop: 'email'
33 },
34 {
Matteo Scandoloa6a9e612016-04-14 16:52:13 -070035 label: 'First Name',
Matteo Scandolo18adcb52016-04-14 12:06:50 -070036 prop: 'firstname'
37 },
38 {
Matteo Scandoloa6a9e612016-04-14 16:52:13 -070039 label: 'Last Name',
Matteo Scandolo18adcb52016-04-14 12:06:50 -070040 prop: 'lastname'
41 }
42 ],
Matteo Scandolo9e6c6fc2016-04-14 14:59:09 -070043 classes: 'table table-striped table-condensed',
44 actions: [
45 {
46 label: 'delete',
47 icon: 'remove',
48 cb: (user) => {
49 console.log(user);
50 },
51 color: 'red'
52 }
Matteo Scandoloa6a9e612016-04-14 16:52:13 -070053 ],
Matteo Scandolo03e59602016-04-14 17:19:08 -070054 filter: 'field',
Matteo Scandolocc6954e2016-04-15 12:20:14 -070055 order: true,
Matteo Scandolo7bc39c42016-04-20 11:38:42 -070056 pagination: {
57 pageSize: 3
58 }
Matteo Scandolo18adcb52016-04-14 12:06:50 -070059 };
60
Matteo Scandolo74b6ef72016-04-15 16:43:48 -070061 this.alertConfig = {
62 type: 'danger',
63 closeBtn: true
64 }
65
Matteo Scandolo7bc39c42016-04-20 11:38:42 -070066 this.formConfig = {
67 exclude: ['password'],
68 fields: {
69 last_login: {
70 type: 'date'
71 }
72 },
73 actions: [
74 {
75 label: 'Save',
76 icon: 'ok', // refers to bootstraps glyphicon
77 cb: (user) => { // receive the model
78 console.log(user);
79 },
80 class: 'success'
81 }
82 ]
83 }
Matteo Scandolo74b6ef72016-04-15 16:43:48 -070084
Matteo Scandolo8cc22e42016-04-12 09:00:04 -070085 // retrieving user list
Matteo Scandolobd2e5cd2016-04-12 11:59:29 -070086 Users.query().$promise
Matteo Scandolo8cc22e42016-04-12 09:00:04 -070087 .then((users) => {
Matteo Scandolo7bc39c42016-04-20 11:38:42 -070088 this.users = users.concat(users).concat(users);
Matteo Scandolo8cc22e42016-04-12 09:00:04 -070089 })
90 .catch((e) => {
91 throw new Error(e);
92 });
93 }
94 };
95});